Index: palm/trunk/SOURCE/check_open.f90
===================================================================
--- palm/trunk/SOURCE/check_open.f90	(revision 392)
+++ palm/trunk/SOURCE/check_open.f90	(revision 410)
@@ -5,4 +5,8 @@
 ! -----------------
 ! 
+!
+! Branch revisions:
+! -----------------
+! masked data output
 !
 ! Former revisions:
@@ -60,5 +64,5 @@
     IMPLICIT NONE
 
-    CHARACTER (LEN=2)   ::  suffix
+    CHARACTER (LEN=2)   ::  mask_char, suffix
     CHARACTER (LEN=20)  ::  xtext = 'time in s'
     CHARACTER (LEN=30)  ::  filename
@@ -123,11 +127,15 @@
 
        CASE ( 15, 16, 17, 18, 19, 40:49, 50:59, 81:84, 101:107, 109, 111:113, &
-              116 )
+              116, 121:160 )
+	      
+	  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
+             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
+	     
+	  ENDIF
 
        CASE ( 21, 22, 23 )
@@ -1233,7 +1241,117 @@
 
           ENDIF
+
+       CASE ( 121:160 )
+!
+!--       Set filename depending on unit number
+          IF ( file_id <= 140 )  THEN
+             mid = file_id - 120
+             WRITE ( mask_char,'(I2.2)')  mid
+             filename = 'DATA_MASK_' // mask_char // '_NETCDF' // coupling_char
+             av = 0
+          ELSE
+             mid = file_id - 140
+             WRITE ( mask_char,'(I2.2)')  mid
+             filename = 'DATA_MASK_' // mask_char // '_AV_NETCDF' // &
+                  coupling_char
+             av = 1
+          ENDIF
+!
+!--       Inquire, if there is a NetCDF file from a previuos run. This should
+!--       be opened for extension, if its dimensions and variables match the
+!--       actual run.
+          INQUIRE( FILE=filename, EXIST=netcdf_extend )
+
+          IF ( netcdf_extend )  THEN
+!
+!--          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) )
 #else
-
-       CASE ( 101:109, 111:113, 116 )
+             nc_stat = NF90_OPEN( filename, NF90_WRITE, id_set_mask(mid,av) )
+#endif
+             CALL handle_netcdf_error( 'check_open', 9998 )
+!
+!--          Read header information and set all ids. If there is a mismatch
+!--          between the previuos and the actual run, netcdf_extend is returned
+!--          as .FALSE.
+             CALL define_netcdf_header( 'ma', netcdf_extend, file_id )
+
+!
+!--          Remove the local file, if it can not be extended
+             IF ( .NOT. netcdf_extend )  THEN
+                nc_stat = NF90_CLOSE( id_set_mask(mid,av) )
+                CALL handle_netcdf_error( 'check_open', 9998 )
+                CALL local_system('rm ' // TRIM( filename ) )
+             ENDIF
+
+          ENDIF          
+
+          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 )
+#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
+             CALL handle_netcdf_error( 'check_open', 9998 )
+!
+!--          Define the header
+             CALL define_netcdf_header( 'ma', netcdf_extend, file_id )
+
+          ENDIF
+
+
+#else
+
+       CASE ( 101:109, 111:113, 116, 121:160 )
 
 !
