Index: src/makefile
===================================================================
--- src/makefile	(revision d1a8707797c5c3fabdbd530210b84b85fb18b258)
+++ src/makefile	(revision 61e07bac31955a83b2f343eb477aac0514ec1b8d)
@@ -12,29 +12,38 @@
 #       'make -j ecmwf gcc=4.9',
 #    also set environment variable LD_LIBRARY_PATH to point to compiler libraries
+#
+#    Makefile was modified to produce unified executable for both ECMWF and GFS meteo data formats
+#    gributils were included to detect format of meteo data
+#
+#    Cpp directives USE_MPIINPLACE were added to three source files. The effect of these directives 
+#    are to enable the MPI_IN_PLACE option only if compiled with a -DUSE_MPIINPLACE directive. 
+#    Otherwise, a safer option (which requires the allocation of another array) is used by default. 
+#    In makefile added the -x f95-cpp-input flag for compiling of cpp directives.
 # 
 #  USAGE
-#    Compile serial FLEXPART (ECMWF)
-#      make [-j] ecmwf
-#
-#    Compile parallel FLEXPART (ECMWF)
-#      make [-j] ecmwf-mpi
+#    Compile serial FLEXPART 
+#      make [-j] serial
+#
+#    Compile parallel FLEXPART 
+#      make [-j] mpi
 #     
-#    Compile for debugging parallel FLEXPART (ECMWF)
-#      make [-j] ecmwf-mpi-dbg
-#
-#    Compile serial FLEXPART (GFS)
-#      make [-j] gfs
-#
-#    Compile parallel FLEXPART (GFS)
-#      make [-j] gfs-mpi
+#    Compile for debugging parallel FLEXPART
+#      make [-j] mpi-dbg
 #
 ################################################################################
 
 ## PROGRAMS
-FLEXPART-ECMWF-MPI 	= FP_ecmwf_MPI
-FLEXPART-ECMWF-MPI-DBG 	= DBG_FP_ecmwf_MPI
-FLEXPART-ECMWF 		= FP_ecmwf_gfortran
-FLEXPART-GFS 		= FP_gfs_gfortran
-FLEXPART-GFS-MPI 	= FP_gfs_MPI
+# Unified executable names
+# The same executable is used for both ECMWF and GFS metdata
+
+# Parallel processing executable
+FLEXPART-MPI = FLEXPART_MPI
+
+# Parallel processing executable with debugging info
+FLEXPART-MPI-DBG = DBG_FLEXPART_MPI
+
+# Serial processing executable
+FLEXPART-SERIAL = FLEXPART
+
 
 ifeq ($(gcc), 4.9)
@@ -59,4 +68,8 @@
 	LIBPATH1 = /xnilu_wrk/flex_wrk/bin64/grib_api/lib
 endif
+
+
+# path to gributils used to detect meteodata format
+VPATH = gributils/
 
 
@@ -82,5 +95,6 @@
 xmass_mod.o             flux_mod.o \
 point_mod.o             outg_mod.o \
-mean_mod.o	 	random_mod.o
+mean_mod.o	 	random_mod.o \
+class_gribfile_mod.o
 
 MPI_MODOBJS = \
@@ -99,5 +113,6 @@
 	redist.o		\
 	concoutput_surf.o	concoutput_surf_nest.o	\
-	getfields.o
+	getfields.o \
+        readwind_ecmwf.o
 
 ## For MPI version 
@@ -112,32 +127,6 @@
 	redist_mpi.o		\
 	concoutput_surf_mpi.o	concoutput_surf_nest_mpi.o	\
-	getfields_mpi.o
-
-### WINDFIELDS
-## For ECMWF (serial) version:
-OBJECTS_ECMWF = \
-	calcpar.o          readwind.o \
-	richardson.o       verttransform.o \
-	obukhov.o          gridcheck.o  \
-	convmix.o          calcmatrix.o \
-	ecmwf_mod.o
-
-
-## For ECMWF MPI version:
-OBJECTS_ECMWF_MPI = \
-	gridcheck.o	   readwind_mpi.o \
-	calcpar.o          \
-	richardson.o       verttransform.o \
-	obukhov.o          \
-	convmix.o	   calcmatrix.o \
-	ecmwf_mod.o
-
-## For GFS (serial) version:
-OBJECTS_GFS = \
-	calcpar_gfs.o          readwind_gfs.o \
-	richardson_gfs.o       verttransform_gfs.o \
-	obukhov_gfs.o          gridcheck_gfs.o  \
-	convmix_gfs.o          calcmatrix_gfs.o \
-	gfs_mod.o
+	getfields_mpi.o \
+        readwind_ecmwf_mpi.o 
 
 OBJECTS = \
@@ -201,62 +190,28 @@
 %.o: %.mod
 
-ecmwf: $(FLEXPART-ECMWF)
-ecmwf: FC := $(F90)
-
-ecmwf-mpi: $(FLEXPART-ECMWF-MPI)
-ecmwf-mpi: FC := $(MPIF90)
-
-ecmwf-mpi-dbg: $(FLEXPART-ECMWF-MPI-DBG)
-ecmwf-mpi-dbg: FFLAGS := $(DBGFLAGS) 
-ecmwf-mpi-dbg: LDFLAGS:= $(LDDEBUG) 
-ecmwf-mpi-dbg: FC := $(MPIF90)
-
-gfs: $(FLEXPART-GFS)
-gfs: FC := $(F90)
-
-gfs-mpi: $(FLEXPART-GFS-MPI)
-gfs-mpi: FC := $(MPIF90)
-
-#all: $(FLEXPART-ECMWF)
-#all: $(FLEXPART-ECMWF-MPI)
-
-## This allows for switching between ECMWF/GFS without editing source code.
-wind_mod = ecmwf_mod.o # default wind
-# ifeq ($(MAKECMDGOALS),ecmwf)
-# wind_mod = ecmwf_mod.o
-# endif
-# ifeq ($(MAKECMDGOALS),ecmwf-mpi)
-# wind_mod = ecmwf_mod.o
-# endif
-# ifeq ($(MAKECMDGOALS),ecmwf-mpi-dbg)
-# wind_mod = ecmwf_mod.o
-# endif
-
-ifeq ($(MAKECMDGOALS),gfs)
-wind_mod = gfs_mod.o
-endif
-ifeq ($(MAKECMDGOALS),gfs-mpi)
-wind_mod = gfs_mod.o
-endif
-
-$(FLEXPART-ECMWF): $(MODOBJS) $(OBJECTS) $(OBJECTS_SERIAL) $(OBJECTS_ECMWF)
-	+$(FC) -o $@ $(MODOBJS) $(OBJECTS) $(OBJECTS_SERIAL) $(OBJECTS_ECMWF) $(LDFLAGS)
-
-$(FLEXPART-ECMWF-MPI): $(MODOBJS) $(MPI_MODOBJS) $(OBJECTS) $(OBJECTS_MPI) $(OBJECTS_ECMWF_MPI)
+# serial executable
+serial: $(FLEXPART-SERIAL)
+serial: FC := $(F90)
+
+# parallel processing executable
+mpi: $(FLEXPART-MPI)
+mpi: FC := $(MPIF90)
+
+# parallel processing with debugging info
+mpi-dbg: $(FLEXPART-MPI-DBG)
+mpi-dbg: FFLAGS := $(DBGFLAGS)
+mpi-dbg: LDFLAGS:= $(LDDEBUG)
+mpi-dbg: FC := $(MPIF90)
+
+$(FLEXPART-SERIAL): $(MODOBJS) $(OBJECTS) $(OBJECTS_SERIAL)
+	+$(FC) -o $@ $(MODOBJS) $(OBJECTS) $(OBJECTS_SERIAL) $(LDFLAGS)
+
+$(FLEXPART-MPI): $(MODOBJS) $(MPI_MODOBJS) $(OBJECTS) $(OBJECTS_MPI)
 	+$(FC) -o $@ $(MODOBJS) $(MPI_MODOBJS) $(OBJECTS) $(OBJECTS_MPI) \
-	$(OBJECTS_ECMWF_MPI) $(LDFLAGS)
-#	+$(FC) -o $@ *.o $(LDFLAGS)
-
-$(FLEXPART-ECMWF-MPI-DBG): $(MODOBJS) $(MPI_MODOBJS) $(OBJECTS) $(OBJECTS_MPI) \
-	$(OBJECTS_ECMWF_MPI)
+	$(LDFLAGS)
+
+$(FLEXPART-MPI-DBG): $(MODOBJS) $(MPI_MODOBJS) $(OBJECTS) $(OBJECTS_MPI)
 	+$(FC) -o $@ $(MODOBJS) $(MPI_MODOBJS) $(OBJECTS) $(OBJECTS_MPI) \
-	$(OBJECTS_ECMWF_MPI) $(LDFLAGS)
-
-$(FLEXPART-GFS): $(MODOBJS) $(OBJECTS) $(OBJECTS_SERIAL) $(OBJECTS_GFS)
-	+$(FC) -o $@ $(MODOBJS) $(OBJECTS) $(OBJECTS_SERIAL) $(OBJECTS_GFS) $(LDFLAGS)
-
-$(FLEXPART-GFS-MPI): $(MODOBJS) $(MPI_MODOBJS) $(OBJECTS) $(OBJECTS_MPI) $(OBJECTS_GFS)
-	+$(FC) -o $@ $(MODOBJS) $(MPI_MODOBJS) $(OBJECTS) $(OBJECTS_MPI) \
-	$(OBJECTS_GFS) $(LDFLAGS)
+	$(LDFLAGS)
 
 %.o: %.f90
@@ -267,6 +222,6 @@
 
 cleanall:
-	\rm -f *.o *.mod $(FLEXPART-ECMWF-MPI) $(FLEXPART-ECMWF-MPI-DBG) $(FLEXPART-ECMWF) \
-	$(FLEXPART-GFS-MPI) $(FLEXPART-GFS)
+	\rm -f *.o *.mod $(FLEXPART-MPI) $(FLEXPART-MPI-DBG) $(FLEXPART-SERIAL)
+
 
 .SUFFIXES = $(SUFFIXES) .f90
@@ -282,8 +237,6 @@
 	random_mod.o
 calcfluxes.o: com_mod.o flux_mod.o outg_mod.o par_mod.o
-calcmatrix.o: com_mod.o conv_mod.o par_mod.o
-calcmatrix_gfs.o: com_mod.o conv_mod.o par_mod.o
-calcpar.o: com_mod.o par_mod.o
-calcpar_gfs.o: com_mod.o par_mod.o
+calcmatrix.o: com_mod.o conv_mod.o par_mod.o class_gribfile_mod.o
+calcpar.o: com_mod.o par_mod.o class_gribfile_mod.o
 calcpar_nests.o: com_mod.o par_mod.o
 calcpv.o: com_mod.o par_mod.o
@@ -311,7 +264,7 @@
 conv_mod.o: par_mod.o
 convect43c.o: conv_mod.o par_mod.o
-convmix.o: com_mod.o conv_mod.o flux_mod.o par_mod.o
-convmix_gfs.o: com_mod.o conv_mod.o par_mod.o
+convmix.o: com_mod.o conv_mod.o flux_mod.o par_mod.o class_gribfile_mod.o
 coordtrafo.o: com_mod.o par_mod.o point_mod.o
+detectformat.o: com_mod.o par_mod.o class_gribfile_mod.o
 distance.o: par_mod.o
 distance2.o: par_mod.o
@@ -319,11 +272,11 @@
 drydepokernel_nest.o: com_mod.o par_mod.o unc_mod.o
 erf.o: par_mod.o
-FLEXPART.o: com_mod.o conv_mod.o par_mod.o point_mod.o random_mod.o netcdf_output_mod.o
+FLEXPART.o: com_mod.o conv_mod.o par_mod.o point_mod.o random_mod.o netcdf_output_mod.o class_gribfile_mod.o
 FLEXPART_MPI.o: com_mod.o conv_mod.o mpi_mod.o par_mod.o point_mod.o \
-	random_mod.o netcdf_output_mod.o
+	random_mod.o netcdf_output_mod.o class_gribfile_mod.o
 fluxoutput.o: com_mod.o flux_mod.o outg_mod.o par_mod.o
 get_settling.o: com_mod.o par_mod.o
-getfields.o: com_mod.o par_mod.o
-getfields_mpi.o: com_mod.o par_mod.o mpi_mod.o
+getfields.o: com_mod.o par_mod.o class_gribfile_mod.o
+getfields_mpi.o: com_mod.o par_mod.o mpi_mod.o class_gribfile_mod.o
 gethourlyOH.o: com_mod.o oh_mod.o par_mod.o
 getrb.o: par_mod.o
@@ -331,5 +284,5 @@
 getvdep.o: com_mod.o par_mod.o
 getvdep_nests.o: com_mod.o par_mod.o
-gridcheck.o: cmapf_mod.o com_mod.o conv_mod.o par_mod.o
+gridcheck_ecmwf.o: cmapf_mod.o com_mod.o conv_mod.o par_mod.o
 gridcheck_emos.o: com_mod.o conv_mod.o par_mod.o
 gridcheck_fnl.o: cmapf_mod.o com_mod.o conv_mod.o par_mod.o
@@ -374,5 +327,5 @@
 outgrid_init.o: com_mod.o flux_mod.o oh_mod.o outg_mod.o par_mod.o unc_mod.o
 outgrid_init_nest.o: com_mod.o outg_mod.o par_mod.o unc_mod.o
-par_mod.o : $(wind_mod)
+par_mod.o :
 part0.o: par_mod.o
 partdep.o: par_mod.o
@@ -402,9 +355,9 @@
 readreleases.o: com_mod.o par_mod.o point_mod.o xmass_mod.o
 readspecies.o: com_mod.o par_mod.o
-readwind.o: com_mod.o par_mod.o
+readwind_ecmwf.o: com_mod.o par_mod.o
 readwind_emos.o: com_mod.o par_mod.o
 readwind_gfs.o: com_mod.o par_mod.o
 readwind_gfs_emos.o: com_mod.o par_mod.o
-readwind_mpi.o: com_mod.o mpi_mod.o par_mod.o
+readwind_ecmwf_mpi.o: com_mod.o mpi_mod.o par_mod.o
 readwind_nests.o: com_mod.o par_mod.o
 readwind_nests_emos.o: com_mod.o par_mod.o
@@ -415,6 +368,5 @@
 releaseparticles_mpi.o: com_mod.o mpi_mod.o par_mod.o point_mod.o \
 	random_mod.o xmass_mod.o
-richardson.o: par_mod.o
-richardson_gfs.o: par_mod.o
+richardson.o: par_mod.o class_gribfile_mod.o
 scalev.o: par_mod.o
 shift_field.o: par_mod.o
@@ -425,5 +377,5 @@
 	par_mod.o point_mod.o unc_mod.o xmass_mod.o netcdf_output_mod.o	
 unc_mod.o: par_mod.o
-verttransform.o: cmapf_mod.o com_mod.o par_mod.o 
+verttransform_ecmwf.o: cmapf_mod.o com_mod.o par_mod.o 
 verttransform_gfs.o: cmapf_mod.o com_mod.o par_mod.o
 verttransform_nests.o: com_mod.o par_mod.o
