Index: flexpart_code/fpmetbinary_mod.F90
===================================================================
--- flexpart_code/fpmetbinary_mod.F90	(revision 89ad9c35395075cd521cce29e393b0d604f0dbcc)
+++ flexpart_code/fpmetbinary_mod.F90	(revision 5f50284edd2756b2281689ed836a9a1f50391c1f)
@@ -99,10 +99,12 @@
         ! Create and open NC4 file for writing
         PRINT *, 'Opening NC4 file...'
-        ncretval = nf90_create(filename // ".nc4", &
+        ncretval = nf90_create(filename, &
 &                              OR(NF90_CLOBBER, NF90_HDF5), &
 &                              ncid)
 
+
+#ifdef RAWBIN
         OPEN(IOUNIT_DUMP, file=filename, action='WRITE', status='REPLACE', form="unformatted", access="stream")
-
+#endif
 
 
@@ -111,5 +113,8 @@
 
         CALL fpio(IOUNIT_DUMP, ncid, 'DUMP', cm_index)
+
+#ifdef RAWBIN
         CLOSE(IOUNIT_DUMP)
+#endif
 
         PRINT *, 'Closing NC4 file...'
@@ -133,12 +138,23 @@
         CALL SYSTEM_CLOCK(millisecs_start, count_rate, count_max)
 
-        print *, "Opening nc file for reading"
-        ncretval = nf90_open(filename // ".nc4", NF90_NOWRITE, ncid)
-
-
-
+PRINT *, "filename: ", filename
+PRINT *, "Opening nc file for reading: ", filename
+        ncretval = nf90_open(filename, NF90_NOWRITE, ncid)
+        call handle_nf90_err(ncretval)
+PRINT *, 'OPENED NC4 FILE FOR READING...'
+
+
+
+#ifdef RAWBIN
         OPEN(IOUNIT_LOAD, file=filename, action='READ', status='OLD', form="unformatted", access="stream")
+#endif
+
         CALL fpio(IOUNIT_LOAD, ncid, 'LOAD', cm_index)
+
+#ifdef RAWBIN
         CLOSE(IOUNIT_LOAD)
+#endif
+
+
         CALL SYSTEM_CLOCK(millisecs_stop, count_rate, count_max)
         !PRINT *, 'Load walltime secs: ', (millisecs_stop-millisecs_start)/1000.0
@@ -352,10 +368,20 @@
 
             ! Write the preprocessing format version string
+            !  NEED TO FILL THIS IN FOR NC4
+
+
+#ifdef RAWBIN
             WRITE (iounit) PREPROC_FORMAT_VERSION_STR
+
+#endif
 
             ! Write the compiled max dimensions from par_mod - these are
             ! not meant to be reassigned during a LOAD, but used as "header"
             ! information to provide the structure of arrays
+
+#ifdef RAWBIN
             WRITE (iounit) nxmax, nymax, nzmax, nuvzmax, nwzmax
+#endif
+
 
             ncret = nf90_def_dim(ncid, 'nxmax', nxmax, nxmax_dimid)
@@ -392,7 +418,11 @@
 
             ! Scalar values
+
+
+#ifdef RAWBIN
             WRITE(iounit) nx, ny, nxmin1, nymin1, nxfield
             WRITE(iounit) nuvz, nwz, nz, nmixz, nlev_ec
             WRITE(iounit) dx, dy, xlon0, ylat0, dxconst, dyconst
+#endif
 
             ncret = nf90_def_var(ncid, 'nx', NF90_INT, ncvarid)
@@ -479,5 +509,9 @@
 
             ! Fixed fields, static in time
+
+
+#ifdef RAWBIN
             WRITE(iounit) oro, excessoro, lsm, xlanduse, height
+#endif
 
             dim2dids = (/nxmax_dimid, nymax_dimid/)
@@ -550,4 +584,8 @@
 
             ! 3d fields
+
+
+
+#ifdef RAWBIN
             WRITE(iounit) uu(:,:,:,cm_index)
             WRITE(iounit) vv(:,:,:,cm_index)
@@ -565,4 +603,7 @@
             WRITE(iounit) clouds(:,:,:,cm_index)
             WRITE(iounit) cloudsh(:,:,cm_index)
+#endif
+
+
 
             dim3dids = (/nxmax_dimid, nymax_dimid, nzmax_dimid/)
@@ -766,4 +807,7 @@
 
             ! 2d fields
+
+
+#ifdef RAWBIN
             WRITE(iounit) ps(:,:,:,cm_index)
             WRITE(iounit) sd(:,:,:,cm_index)
@@ -786,4 +830,7 @@
             WRITE(iounit) diffk(:,:,:,cm_index)
             WRITE(iounit) vdep(:,:,:,cm_index)
+#endif
+
+
 
             dim2dids = (/nxmax_dimid, nymax_dimid/)
@@ -1043,4 +1090,8 @@
 
             ! 1d fields
+
+
+
+#ifdef RAWBIN
             WRITE(iounit) z0(:)
             WRITE(iounit) akm(:)
@@ -1050,4 +1101,5 @@
             WRITE(iounit) aknew(:)
             WRITE(iounit) bknew(:)
+#endif
 
             dim1dids = (/numclass_dimid/)
@@ -1161,4 +1213,6 @@
             call handle_nf90_err(ncret)
 
+
+#ifdef RAWBIN
             WRITE(iounit) nxn(:)
             WRITE(iounit) nyn(:)
@@ -1167,4 +1221,5 @@
             WRITE(iounit) xlon0n(:)
             WRITE(iounit) ylat0n(:)
+#endif
 
             ! Nested, scalar values (for each nest)
@@ -1307,4 +1362,8 @@
 
             ! 3d nested fields
+
+
+
+#ifdef RAWBIN
             WRITE(iounit) uun(:,:,:,cm_index,:)
             WRITE(iounit) vvn(:,:,:,cm_index,:)
@@ -1319,5 +1378,5 @@
             WRITE(iounit) tthn(:,:,:,cm_index,:)
             WRITE(iounit) qvhn(:,:,:,cm_index,:)
-
+#endif
 
             dim4dids = (/nxmaxn_dimid, nymaxn_dimid, nzmax_dimid, maxnests_dimid/)
@@ -1492,4 +1551,7 @@
 
             ! 2d nested fields
+
+
+#ifdef RAWBIN
             WRITE(iounit) psn(:,:,:,cm_index,:)
             WRITE(iounit) sdn(:,:,:,cm_index,:)
@@ -1512,4 +1574,6 @@
             WRITE(iounit) diffkn(:,:,:,cm_index,:)
             WRITE(iounit) vdepn(:,:,:,cm_index,:)
+#endif
+
 
             dim3dids = (/nxmaxn_dimid, nymaxn_dimid, maxnests_dimid/)
@@ -1771,4 +1835,6 @@
 
             ! Auxiliary variables for nests
+
+#ifdef RAWBIN
             WRITE(iounit) xresoln(:)
             WRITE(iounit) yresoln(:)
@@ -1777,4 +1843,6 @@
             WRITE(iounit) xrn(:)
             WRITE(iounit) yrn(:)
+#endif
+
 
             dim1dids = (/zero_to_maxnests_dimid/)
@@ -1860,9 +1928,13 @@
 
             ! Variables for polar stereographic projection
+
+
+
+#ifdef RAWBIN
             WRITE(iounit) xglobal, sglobal, nglobal
             WRITE(iounit) switchnorthg, switchsouthg
             WRITE(iounit) southpolemap(:)
             WRITE(iounit) northpolemap(:)
-
+#endif
 
 
@@ -1925,4 +1997,7 @@
 
             ! Variables declared in conv_mod (convection)
+
+
+#ifdef RAWBIN
             WRITE(iounit) pconv(:)
             WRITE(iounit) phconv(:)
@@ -1942,4 +2017,5 @@
             WRITE(iounit) psconv, tt2conv, td2conv
             WRITE(iounit) nconvlev, nconvtop
+#endif
 
 
@@ -2133,4 +2209,7 @@
             ! Read the preprocessed format version string and insure it
             ! matches this version
+
+
+#ifdef RAWBIN
             READ (iounit) temp_preproc_format_version_str
             PRINT *, 'Reading preprocessed file format version: ', &
@@ -2148,4 +2227,8 @@
                 STOP
             END IF
+#endif
+
+
+
 
             ! Read the compiled max dimensions that were dumped from par_mod 
@@ -2153,10 +2236,20 @@
             ! current FLEXPART dimensions - they need to be the same, or else
             ! we abort.
+
+
+
+#ifdef RAWBIN
             READ (iounit) temp_nxmax, temp_nymax, temp_nzmax, &
 &                         temp_nuvzmax, temp_nwzmax
-
+#endif
+
+
+
+
+PRINT *, 'GET DIMENSIONS'
             ! Get dimensions
             ncret = nf90_inq_dimid(ncid, 'nxmax', nxmax_dimid)
             call handle_nf90_err(ncret)
+PRINT *, 'GOT nxmax_dimid'            
             ncret = nf90_inquire_dimension(ncid, nxmax_dimid, nxmax_dimname, &
 &                                                temp_nxmax)
@@ -2164,4 +2257,6 @@
             PRINT *, 'temp_nxmax: ', temp_nxmax
 
+PRINT *, 'GOT temp_nxmax'
+
             ncret = nf90_inq_dimid(ncid, 'nymax', nymax_dimid)
             call handle_nf90_err(ncret)
@@ -2207,4 +2302,6 @@
 
 
+
+PRINT *, 'CHECK DIMENSIONS'
 
             IF ( (temp_nxmax == nxmax) .AND. (temp_nymax == nymax) .AND. &
@@ -2234,9 +2331,16 @@
 
             ! Scalar values
+
+
+#ifdef RAWBIN
             READ(iounit) nx, ny, nxmin1, nymin1, nxfield
             READ(iounit) nuvz, nwz, nz, nmixz, nlev_ec
             READ(iounit) dx, dy, xlon0, ylat0, dxconst, dyconst
-
-
+#endif
+
+
+
+
+PRINT *, 'GET SCALARS'
 
             ! Get the varid , then read into scalar variable
@@ -2327,5 +2431,8 @@
 
             ! Fixed fields, static in time
+            
+#ifdef RAWBIN            
             READ(iounit) oro, excessoro, lsm, xlanduse, height
+#endif
 
             ncret = nf90_inq_varid(ncid, 'oro', ncvarid)
@@ -2358,4 +2465,8 @@
 
             ! 3d fields
+
+
+
+#ifdef RAWBIN
             READ(iounit) uu(:,:,:,cm_index)
             READ(iounit) vv(:,:,:,cm_index)
@@ -2373,5 +2484,5 @@
             READ(iounit) clouds(:,:,:,cm_index)
             READ(iounit) cloudsh(:,:,cm_index)
-
+#endif
 
 
@@ -2430,5 +2541,5 @@
             ncret = nf90_inq_varid(ncid, 'clouds', ncvarid)
             call handle_nf90_err(ncret)
-            ncret = nf90_get_var(ncid, ncvarid, clouds(0:nxmax-1,0:nzmax-1,1:nzmax,cm_index))
+            ncret = nf90_get_var(ncid, ncvarid, clouds(0:nxmax-1,0:nymax-1,1:nzmax,cm_index))
             call handle_nf90_err(ncret)
 
@@ -2466,4 +2577,7 @@
 
             ! 2d fields
+
+
+#ifdef RAWBIN
             READ(iounit) ps(:,:,:,cm_index)
             READ(iounit) sd(:,:,:,cm_index)
@@ -2486,4 +2600,7 @@
             READ(iounit) diffk(:,:,:,cm_index)
             READ(iounit) vdep(:,:,:,cm_index)
+#endif
+
+
 
             ! Get the varid and read the variable into the array
@@ -2603,4 +2720,6 @@
 
             ! 1d fields
+
+#ifdef RAWBIN
             READ(iounit) z0(:)
             READ(iounit) akm(:)
@@ -2610,5 +2729,5 @@
             READ(iounit) aknew(:)
             READ(iounit) bknew(:)
-
+#endif
 
             ncret = nf90_inq_varid(ncid, 'z0', ncvarid)
@@ -2701,4 +2820,9 @@
 
             ! Nested, scalar values (for each nest)
+
+
+
+
+#ifdef RAWBIN
             READ(iounit) nxn(:)
             READ(iounit) nyn(:)
@@ -2707,4 +2831,5 @@
             READ(iounit) xlon0n(:)
             READ(iounit) ylat0n(:)
+#endif
 
 
@@ -2742,5 +2867,8 @@
 
             ! Nested fields, static over time
+
+#ifdef RAWBIN
             READ(iounit) oron, excessoron, lsmn, xlandusen 
+#endif
 
             ncret = nf90_inq_varid(ncid, 'oron', ncvarid)
@@ -2771,4 +2899,6 @@
 
             ! 3d nested fields
+
+#ifdef RAWBIN
             READ(iounit) uun(:,:,:,cm_index,:)
             READ(iounit) vvn(:,:,:,cm_index,:)
@@ -2783,5 +2913,5 @@
             READ(iounit) tthn(:,:,:,cm_index,:)
             READ(iounit) qvhn(:,:,:,cm_index,:)
-
+#endif
 
             ncret = nf90_inq_varid(ncid, 'uun', ncvarid)
@@ -2856,4 +2986,7 @@
 
             ! 2d nested fields
+
+
+#ifdef RAWBIN
             READ(iounit) psn(:,:,:,cm_index,:)
             READ(iounit) sdn(:,:,:,cm_index,:)
@@ -2876,4 +3009,6 @@
             READ(iounit) diffkn(:,:,:,cm_index,:)
             READ(iounit) vdepn(:,:,:,cm_index,:)
+#endif
+
 
             ncret = nf90_inq_varid(ncid, 'psn', ncvarid)
@@ -2987,4 +3122,7 @@
 
             ! Auxiliary variables for nests
+
+
+#ifdef RAWBIN
             READ(iounit) xresoln(:)
             READ(iounit) yresoln(:)
@@ -2993,4 +3131,6 @@
             READ(iounit) xrn(:)
             READ(iounit) yrn(:)
+#endif
+
 
             ncret = nf90_inq_varid(ncid, 'xresoln', ncvarid)
@@ -3032,9 +3172,12 @@
 
             ! Variables for polar stereographic projection
+
+
+#ifdef RAWBIN
             READ(iounit) xglobal, sglobal, nglobal
             READ(iounit) switchnorthg, switchsouthg
             READ(iounit) southpolemap(:)
             READ(iounit) northpolemap(:)
-
+#endif
 
             ncret = nf90_inq_varid(ncid, 'southpolemap', ncvarid)
@@ -3089,4 +3232,7 @@
 
             ! Variables declared in conv_mod (convection)
+
+
+#ifdef RAWBIN
             READ(iounit) pconv(:)
             READ(iounit) phconv(:)
@@ -3106,4 +3252,7 @@
             READ(iounit) psconv, tt2conv, td2conv
             READ(iounit) nconvlev, nconvtop
+#endif
+
+
 
             ncret = nf90_inq_varid(ncid, 'pconv', ncvarid)
