Index: palm/trunk/SOURCE/check_open.f90
===================================================================
--- palm/trunk/SOURCE/check_open.f90	(revision 449)
+++ palm/trunk/SOURCE/check_open.f90	(revision 493)
@@ -4,5 +4,5 @@
 ! Current revisions:
 ! -----------------
-! 
+! NetCDF4 support (parallel output)
 !
 ! Former revisions:
@@ -125,8 +125,15 @@
     SELECT CASE ( file_id )
 
-       CASE ( 15, 16, 17, 18, 19, 40:49, 50:59, 81:84, 101:107, 109, 111:113, &
-              116, 121:160 )
+       CASE ( 15, 16, 17, 18, 19, 40:49, 50:59, 81:84, 104:105, 107, 109 )
 	      
-	  IF ( .NOT. format_parallel_io) THEN
+          IF ( myid /= 0 )  THEN
+             WRITE( message_string, * ) 'opening file-id ',file_id, &
+                                        ' not allowed for PE ',myid
+             CALL message( 'check_open', 'PA0167', 2, 2, -1, 6, 1 )
+          ENDIF
+
+       CASE ( 101:103, 106, 111:113, 116, 121:160 )
+
+          IF ( netcdf_data_format < 3 )  THEN
           
              IF ( myid /= 0 )  THEN
@@ -136,5 +143,5 @@
              ENDIF
 	     
-	  ENDIF
+          ENDIF
 
        CASE ( 21, 22, 23 )
@@ -705,6 +712,11 @@
           IF ( netcdf_extend )  THEN
 !
-!--          Open an existing NetCDF file for output 
+!--          Open an existing NetCDF file for output
+#if defined( __netcdf4 )
+             nc_stat = NF90_OPEN( filename, NF90_WRITE, id_set_xy(av), &
+                                  COMM = comm2d, INFO = MPI_INFO_NULL )
+#else
              nc_stat = NF90_OPEN( filename, NF90_WRITE, id_set_xy(av) )
+#endif
 
              CALL handle_netcdf_error( 'check_open', 20 )
@@ -720,5 +732,5 @@
                 nc_stat = NF90_CLOSE( id_set_xy(av) )
                 CALL handle_netcdf_error( 'check_open', 21 )
-                CALL local_system( 'rm ' // TRIM( filename ) )
+                IF ( myid == 0 )  CALL local_system( 'rm ' // TRIM( filename ) )
              ENDIF
 
@@ -727,24 +739,51 @@
           IF ( .NOT. netcdf_extend )  THEN
 !
-!--          Create a new NetCDF output file
-             IF ( netcdf_64bit )  THEN
-#if defined( __netcdf_64bit )
+!--          Create a new NetCDF output file with requested NetCDF format
+             IF ( netcdf_data_format == 1 )  THEN
+!
+!--             Classic NetCDF format
+                nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, id_set_xy(av) )
+
+             ELSEIF ( netcdf_data_format == 2 )  THEN
+!
+!--             64bit-offset format
                 nc_stat = NF90_CREATE( filename,                               &
                                        OR( NF90_NOCLOBBER, NF90_64BIT_OFFSET ),&
                                        id_set_xy(av) )
-#else
-                message_string = 'NetCDF: no 64-bit offset allowed ' // &
-                                 'on this machine'
-                CALL message( 'check_open', 'PA0171', 0, 1, 0, 6, 0 )
-
-                nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, id_set_xy(av) )
-#endif
-             ELSE
-                nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, id_set_xy(av) )
-             ENDIF
+
+#if defined( __netcdf4 )
+             ELSEIF ( netcdf_data_format == 3 )  THEN
+!
+!--             NetCDF4/HDF5 format
+                nc_stat = NF90_CREATE( filename,                               &
+                                       OR( NF90_NOCLOBBER, NF90_NETCDF4 ),     &
+                                       id_set_xy(av), COMM = comm2d,           &
+                                       INFO = MPI_INFO_NULL )
+
+             ELSEIF ( netcdf_data_format == 4 )  THEN
+!
+!--             NetCDF4/HDF5 format with classic model flag
+                nc_stat = NF90_CREATE( filename,                               &
+                                       OR( NF90_NOCLOBBER,                     &
+                                        OR( NF90_CLASSIC_MODEL, NF90_HDF5 ) ), &
+                                       id_set_xy(av), COMM = comm2d,           &
+                                       INFO = MPI_INFO_NULL )
+#endif
+             ENDIF
+
              CALL handle_netcdf_error( 'check_open', 22 )
+
 !
 !--          Define the header
              CALL define_netcdf_header( 'xy', netcdf_extend, av )
+
+!
+!--          In case of parallel NetCDF output, create flag file which tells
+!--          combine_plot_fields that nothing is to do.
+             IF ( myid == 0  .AND.  netcdf_data_format > 2 )  THEN
+                OPEN( 99, FILE='NO_COMBINE_PLOT_FIELDS_XY' )
+                WRITE ( 99, '(A)' )  'no combine_plot_fields.x neccessary'
+                CLOSE( 99 )
+             ENDIF
 
           ENDIF
@@ -769,5 +808,10 @@
 !
 !--          Open an existing NetCDF file for output 
+#if defined( __netcdf4 )
+             nc_stat = NF90_OPEN( filename, NF90_WRITE, id_set_xz(av), &
+                                  COMM = comm2d, INFO = MPI_INFO_NULL )
+#else
              nc_stat = NF90_OPEN( filename, NF90_WRITE, id_set_xz(av) )
+#endif
              CALL handle_netcdf_error( 'check_open', 23 )
 !
@@ -782,5 +826,5 @@
                 nc_stat = NF90_CLOSE( id_set_xz(av) )
                 CALL handle_netcdf_error( 'check_open', 24 )
-                CALL local_system( 'rm ' // TRIM( filename ) )
+                IF ( myid == 0 )  CALL local_system( 'rm ' // TRIM( filename ) )
              ENDIF
 
@@ -789,24 +833,51 @@
           IF ( .NOT. netcdf_extend )  THEN
 !
-!--          Create a new NetCDF output file
-             IF ( netcdf_64bit )  THEN
-#if defined( __netcdf_64bit )
+!--          Create a new NetCDF output file with requested NetCDF format
+             IF ( netcdf_data_format == 1 )  THEN
+!
+!--             Classic NetCDF format
+                nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, id_set_xz(av) )
+
+             ELSEIF ( netcdf_data_format == 2 )  THEN
+!
+!--             64bit-offset format
                 nc_stat = NF90_CREATE( filename,                               &
                                        OR( NF90_NOCLOBBER, NF90_64BIT_OFFSET ),&
                                        id_set_xz(av) )
-#else
-                message_string = 'NetCDF: no 64-bit offset allowed ' // & 
-                                 'on this machine'
-                CALL message( 'check_open', 'PA0171', 0, 1, 0, 6, 0 )
-         
-                nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, id_set_xz(av) )
-#endif
-             ELSE
-                nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, id_set_xz(av) )
-             ENDIF
+
+#if defined( __netcdf4 )
+             ELSEIF ( netcdf_data_format == 3 )  THEN
+!
+!--             NetCDF4/HDF5 format
+                nc_stat = NF90_CREATE( filename,                               &
+                                       OR( NF90_NOCLOBBER, NF90_NETCDF4 ),     &
+                                       id_set_xz(av), COMM = comm2d,           &
+                                       INFO = MPI_INFO_NULL )
+
+             ELSEIF ( netcdf_data_format == 4 )  THEN
+!
+!--             NetCDF4/HDF5 format with classic model flag
+                nc_stat = NF90_CREATE( filename,                               &
+                                       OR( NF90_NOCLOBBER,                     &
+                                        OR( NF90_CLASSIC_MODEL, NF90_HDF5 ) ), &
+                                       id_set_xz(av), COMM = comm2d,           &
+                                       INFO = MPI_INFO_NULL )
+#endif
+             ENDIF
+
              CALL handle_netcdf_error( 'check_open', 25 )
+
 !
 !--          Define the header
              CALL define_netcdf_header( 'xz', netcdf_extend, av )
+
+!
+!--          In case of parallel NetCDF output, create flag file which tells
+!--          combine_plot_fields that nothing is to do.
+             IF ( myid == 0  .AND.  netcdf_data_format > 2 )  THEN
+                OPEN( 99, FILE='NO_COMBINE_PLOT_FIELDS_XZ' )
+                WRITE ( 99, '(A)' )  'no combine_plot_fields.x neccessary'
+                CLOSE( 99 )
+             ENDIF
 
           ENDIF
@@ -831,5 +902,10 @@
 !
 !--          Open an existing NetCDF file for output 
+#if defined( __netcdf4 )
+             nc_stat = NF90_OPEN( filename, NF90_WRITE, id_set_yz(av), &
+                                  COMM = comm2d, INFO = MPI_INFO_NULL )
+#else
              nc_stat = NF90_OPEN( filename, NF90_WRITE, id_set_yz(av) )
+#endif
              CALL handle_netcdf_error( 'check_open', 26 )
 !
@@ -844,5 +920,5 @@
                 nc_stat = NF90_CLOSE( id_set_yz(av) )
                 CALL handle_netcdf_error( 'check_open', 27 )
-                CALL local_system( 'rm ' // TRIM( filename ) )
+                IF ( myid == 0 )  CALL local_system( 'rm ' // TRIM( filename ) )
              ENDIF
 
@@ -851,24 +927,51 @@
           IF ( .NOT. netcdf_extend )  THEN
 !
-!--          Create a new NetCDF output file
-             IF ( netcdf_64bit )  THEN
-#if defined( __netcdf_64bit )
-                nc_stat = NF90_CREATE( filename,                               &
-                                       OR( NF90_NOCLOBBER, NF90_64BIT_OFFSET), &
+!--          Create a new NetCDF output file with requested NetCDF format
+             IF ( netcdf_data_format == 1 )  THEN
+!
+!--             Classic NetCDF format
+                nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, id_set_yz(av) )
+
+             ELSEIF ( netcdf_data_format == 2 )  THEN
+!
+!--             64bit-offset format
+                nc_stat = NF90_CREATE( filename,                               &
+                                       OR( NF90_NOCLOBBER, NF90_64BIT_OFFSET ),&
                                        id_set_yz(av) )
-#else
-                message_string = 'NetCDF: no 64-bit offset allowed ' // & 
-                                 'on this machine'
-                CALL message( 'check_open', 'PA0171', 0, 1, 0, 6, 0 )
-                
-                nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, id_set_yz(av) )
-#endif
-             ELSE
-                nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, id_set_yz(av) )
-             ENDIF
+
+#if defined( __netcdf4 )
+             ELSEIF ( netcdf_data_format == 3 )  THEN
+!
+!--             NetCDF4/HDF5 format
+                nc_stat = NF90_CREATE( filename,                               &
+                                       OR( NF90_NOCLOBBER, NF90_NETCDF4 ),     &
+                                       id_set_yz(av), COMM = comm2d,           &
+                                       INFO = MPI_INFO_NULL )
+
+             ELSEIF ( netcdf_data_format == 4 )  THEN
+!
+!--             NetCDF4/HDF5 format with classic model flag
+                nc_stat = NF90_CREATE( filename,                               &
+                                       OR( NF90_NOCLOBBER,                     &
+                                        OR( NF90_CLASSIC_MODEL, NF90_HDF5 ) ), &
+                                       id_set_yz(av), COMM = comm2d,           &
+                                       INFO = MPI_INFO_NULL )
+#endif
+             ENDIF
+
              CALL handle_netcdf_error( 'check_open', 28 )
+
 !
 !--          Define the header
              CALL define_netcdf_header( 'yz', netcdf_extend, av )
+
+!
+!--          In case of parallel NetCDF output, create flag file which tells
+!--          combine_plot_fields that nothing is to do.
+             IF ( myid == 0  .AND.  netcdf_data_format > 2 )  THEN
+                OPEN( 99, FILE='NO_COMBINE_PLOT_FIELDS_YZ' )
+                WRITE ( 99, '(A)' )  'no combine_plot_fields.x neccessary'
+                CLOSE( 99 )
+             ENDIF
 
           ENDIF
@@ -908,16 +1011,8 @@
 !
 !--          Create a new NetCDF output file
-             IF ( netcdf_64bit )  THEN
-#if defined( __netcdf_64bit )
+             IF ( netcdf_data_format > 1 )  THEN
                 nc_stat = NF90_CREATE( filename,                               &
                                        OR( NF90_NOCLOBBER, NF90_64BIT_OFFSET ),&
                                        id_set_pr )
-#else 
-                message_string = 'NetCDF: no 64-bit offset allowed ' // & 
-                                 'on this machine'
-                CALL message( 'check_open', 'PA0171', 0, 1, 0, 6, 0 )
-                
-                nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, id_set_pr )
-#endif
              ELSE
                 nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, id_set_pr )
@@ -964,16 +1059,8 @@
 !
 !--          Create a new NetCDF output file
-             IF ( netcdf_64bit )  THEN
-#if defined( __netcdf_64bit )
+             IF ( netcdf_data_format > 1 )  THEN
                 nc_stat = NF90_CREATE( filename,                               &
                                        OR( NF90_NOCLOBBER, NF90_64BIT_OFFSET ),&
                                        id_set_ts )
-#else 
-                message_string = 'NetCDF: no 64-bit offset allowed ' // &
-                                 'on this machine'
-                CALL message( 'check_open', 'PA0171', 0, 1, 0, 6, 0 )
-                
-                nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, id_set_ts )
-#endif
              ELSE
                 nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, id_set_ts )
@@ -998,5 +1085,5 @@
           ENDIF
 !
-!--       Inquire, if there is a NetCDF file from a previuos run. This should
+!--       Inquire, if there is a NetCDF file from a previous run. This should
 !--       be opened for extension, if its dimensions and variables match the
 !--       actual run.
@@ -1005,6 +1092,11 @@
           IF ( netcdf_extend )  THEN
 !
-!--          Open an existing NetCDF file for output 
+!--          Open an existing NetCDF file for output
+#if defined( __netcdf4 )
+             nc_stat = NF90_OPEN( filename, NF90_WRITE, id_set_3d(av), &
+                                  COMM = comm2d, INFO = MPI_INFO_NULL )
+#else
              nc_stat = NF90_OPEN( filename, NF90_WRITE, id_set_3d(av) )
+#endif
              CALL handle_netcdf_error( 'check_open', 35 )
 !
@@ -1026,24 +1118,51 @@
           IF ( .NOT. netcdf_extend )  THEN
 !
-!--          Create a new NetCDF output file
-             IF ( netcdf_64bit_3d )  THEN
-#if defined( __netcdf_64bit )
+!--          Create a new NetCDF output file with requested NetCDF format
+             IF ( netcdf_data_format == 1 )  THEN
+!
+!--             Classic NetCDF format
+                nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, id_set_3d(av) )
+
+             ELSEIF ( netcdf_data_format == 2 )  THEN
+!
+!--             64bit-offset format
                 nc_stat = NF90_CREATE( filename,                               &
                                        OR( NF90_NOCLOBBER, NF90_64BIT_OFFSET ),&
                                        id_set_3d(av) )
-#else 
-                message_string = 'NetCDF: no 64-bit offset allowed ' // &
-                                 'on this machine'
-                CALL message( 'check_open', 'PA0171', 0, 1, 0, 6, 0 )
-                
-                nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, id_set_3d(av) )
-#endif
-             ELSE
-                nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, id_set_3d(av) )
-             ENDIF
+
+#if defined( __netcdf4 )
+             ELSEIF ( netcdf_data_format == 3 )  THEN
+!
+!--             NetCDF4/HDF5 format
+                nc_stat = NF90_CREATE( filename,                               &
+                                       OR( NF90_NOCLOBBER, NF90_NETCDF4 ),     &
+                                       id_set_3d(av), COMM = comm2d,           &
+                                       INFO = MPI_INFO_NULL )
+
+             ELSEIF ( netcdf_data_format == 4 )  THEN
+!
+!--             NetCDF4/HDF5 format with classic model flag
+                nc_stat = NF90_CREATE( filename,                               &
+                                       OR( NF90_NOCLOBBER,                     &
+                                        OR( NF90_CLASSIC_MODEL, NF90_HDF5 ) ), &
+                                       id_set_3d(av), COMM = comm2d,           &
+                                       INFO = MPI_INFO_NULL )
+#endif
+             ENDIF
+
              CALL handle_netcdf_error( 'check_open', 37 )
+
 !
 !--          Define the header
              CALL define_netcdf_header( '3d', netcdf_extend, av )
+
+!
+!--          In case of parallel NetCDF output, create flag file which tells
+!--          combine_plot_fields that nothing is to do.
+             IF ( myid == 0  .AND.  netcdf_data_format > 2 )  THEN
+                OPEN( 99, FILE='NO_COMBINE_PLOT_FIELDS_3D' )
+                WRITE ( 99, '(A)' )  'no combine_plot_fields.x neccessary'
+                CLOSE( 99 )
+             ENDIF
 
           ENDIF
@@ -1085,16 +1204,8 @@
 !
 !--          Create a new NetCDF output file
-             IF ( netcdf_64bit )  THEN
-#if defined( __netcdf_64bit )
+             IF ( netcdf_data_format > 1 )  THEN
                 nc_stat = NF90_CREATE( filename,                               &
                                        OR( NF90_NOCLOBBER, NF90_64BIT_OFFSET ),&
                                        id_set_sp )
-#else 
-                message_string = 'NetCDF: no 64-bit offset allowed ' // & 
-                                 'on this machine'
-                CALL message( 'check_open', 'PA0171', 0, 1, 0, 6, 0 )
-               
-                nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, id_set_sp )
-#endif
              ELSE
                 nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, id_set_sp )
@@ -1162,16 +1273,8 @@
 !
 !--          Create a new NetCDF output file
-             IF ( netcdf_64bit )  THEN
-#if defined( __netcdf_64bit )
+             IF ( netcdf_data_format > 1 )  THEN
                 nc_stat = NF90_CREATE( filename,                               &
                                        OR( NF90_NOCLOBBER, NF90_64BIT_OFFSET ),&
                                        id_set_prt )
-#else
-                message_string = 'NetCDF: no 64-bit offset allowed ' // & 
-                                 'on this machine'
-                CALL message( 'check_open', 'PA0171', 0, 1, 0, 6, 0 )
-                
-                nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, id_set_prt )
-#endif
              ELSE
                 nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, id_set_prt )
@@ -1219,16 +1322,8 @@
 !
 !--          Create a new NetCDF output file
-             IF ( netcdf_64bit )  THEN
-#if defined( __netcdf_64bit )
+             IF ( netcdf_data_format > 1 )  THEN
                 nc_stat = NF90_CREATE( filename,                               &
                                        OR( NF90_NOCLOBBER, NF90_64BIT_OFFSET ),&
                                        id_set_pts )
-#else
-                message_string = 'NetCDF: no 64-bit offset allowed ' // & 
-                                 'on this machine'
-                CALL message( 'check_open', 'PA0171', 0, 1, 0, 6, 0 )
-                
-                nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, id_set_pts )
-#endif
              ELSE
                 nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, id_set_pts )
@@ -1266,6 +1361,6 @@
 !--          Open an existing NetCDF file for output 
 #if defined( __netcdf4 )
-             nc_stat = NF90_OPEN_PAR( filename, NF90_WRITE, comm2d, &
-                                      MPI_INFO_NULL, id_set_mask(mid,av) )
+             nc_stat = NF90_OPEN( filename, NF90_WRITE, id_set_mask(mid,av), &
+                                  COMM = comm2d, INFO = MPI_INFO_NULL )
 #else
              nc_stat = NF90_OPEN( filename, NF90_WRITE, id_set_mask(mid,av) )
@@ -1290,56 +1385,39 @@
           IF ( .NOT. netcdf_extend )  THEN
 !
-!--          Create a new NetCDF output file
-             SELECT CASE ( nc_format_mask(mid,av) )
-
-                CASE ( 1 )
-                   nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, &
-                        id_set_mask(mid,av) )
-
-                CASE ( 2 )
-#if defined( __netcdf_64bit )
-                   nc_stat = NF90_CREATE( filename, OR( NF90_NOCLOBBER, &
-                        NF90_64BIT_OFFSET ), id_set_mask(mid,av) )
-#else
-                   WRITE( message_string, * ) 'NetCDF: no 64-bit ', &
-                        'offset format allowed on this machine'
-                   CALL message( 'check_open', 'PA9998', 0, 1, 0, 6, 0 )
-                   nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, &
-                        id_set_mask(mid,av) )
-#endif
-
-                CASE ( 3 )
+!--          Create a new NetCDF output file with requested NetCDF format
+             IF ( netcdf_data_format == 1 )  THEN
+!
+!--             Classic NetCDF format
+                nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, &
+                                       id_set_mask(mid,av) )
+
+             ELSEIF ( netcdf_data_format == 2 )  THEN
+!
+!--             64bit-offset format
+                nc_stat = NF90_CREATE( filename,                               &
+                                       OR( NF90_NOCLOBBER, NF90_64BIT_OFFSET ),&
+                                       id_set_mask(mid,av) )
+
+
 #if defined( __netcdf4 )
-                   nc_stat = NF90_CREATE_PAR( filename, OR( NF90_NOCLOBBER, &
-                        NF90_NETCDF4 ), comm2d, MPI_INFO_NULL, &
-                        id_set_mask(mid,av) )
-#else
-                   WRITE( message_string, * ) 'NetCDF: no NetCDF 4 ', &
-                        'format allowed on this machine'
-                   CALL message( 'check_open', 'PA9998', 0, 1, 0, 6, 0 )
-                   nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, &
-                        id_set_mask(mid,av) )
-#endif
-
-                CASE ( 4 )
-#if defined( __netcdf4 )
-                   nc_stat = NF90_CREATE_PAR( filename, OR( NF90_NOCLOBBER, &
-                      NF90_CLASSIC_MODEL ), comm2d, &
-                      MPI_INFO_NULL, id_set_mask(mid,av) )
-#else
-                   WRITE( message_string, * ) 'NetCDF: no NetCDF 4 (Classic ', &
-                        'model) format allowed on this machine'
-                   CALL message( 'check_open', 'PA9998', 0, 1, 0, 6, 0 )
-                   nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, &
-                        id_set_mask(mid,av) )
-#endif
-
-                CASE DEFAULT
-                   WRITE( message_string, * ) 'illegal NetCDF file format: ', &
-                        'nc_format_mask(mid=',mid,',av=',av,')=', &
-                        nc_format_mask(mid,av)
-                   CALL message( 'check_open', 'PA9998', 2, 2, 0, 6, 0 )
-
-             END SELECT
+             ELSEIF ( netcdf_data_format == 3 )  THEN
+!
+!--             NetCDF4/HDF5 format
+                nc_stat = NF90_CREATE( filename,                               &
+                                       OR( NF90_NOCLOBBER, NF90_NETCDF4 ),     &
+                                       id_set_mask(mid,av), COMM = comm2d,     &
+                                       INFO = MPI_INFO_NULL )
+
+             ELSEIF ( netcdf_data_format == 4 )  THEN
+!
+!--             NetCDF4/HDF5 format with classic model flag
+                nc_stat = NF90_CREATE( filename,                               &
+                                       OR( NF90_NOCLOBBER,                     &
+                                        OR( NF90_CLASSIC_MODEL, NF90_HDF5 ) ), &
+                                       id_set_mask(mid,av), COMM = comm2d,     &
+                                       INFO = MPI_INFO_NULL )
+#endif
+             ENDIF
+
              CALL handle_netcdf_error( 'check_open', 9998 )
 !
