Index: /palm/trunk/DOC/app/appendix_a.html
===================================================================
--- /palm/trunk/DOC/app/appendix_a.html	(revision 518)
+++ /palm/trunk/DOC/app/appendix_a.html	(revision 519)
@@ -1,4 +1,5 @@
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 <html><head>
+
 
 
@@ -1876,6 +1877,18 @@
          <td style="vertical-align: top;">
       maximum_number_of_particles needs to be increased 
-                       but this is not allowed with NetCDF output switched on
-      </td><td style="vertical-align: top;"><br>
+                       but this is not allowed with netcdf_data_format &lt; 3
+      </td><td style="vertical-align: top;">NetCDF output is switched on (<a href="chapter_4.2.html#data_output_format">data_output_format</a> = <span style="font-style: italic;">'netcdf'</span>) and a NetCDF3 format is used (<a href="chapter_4.2.html#netcdf_data_format">netcdf_data_format </a>&lt; <span style="font-style: italic;">3</span>).<br>
+      <br>
+If output of particle data is switched on (see <a href="chapter_4.2.html#dt_write_particle_data">dt_write_particle_data</a>), the size of the particle array, given on each processor by <a href="chapter_4.2.html#maximum_number_of_particles">maximum_number_of_particles</a>,
+is not allowed to increase during the run, when the NetCDF3 data format
+is used, because NetCDF3 allows only one unlimited dimension, which is
+the time dimension. Anyhow, PALM tries to increase the size of the
+particle array, if the number of particles in a subdomain becomes
+larger than the size of this array. This may happen because of a flow
+convergence or because new sets of particles are released (see <a href="chapter_4.2.html#dt_prel">dt_prel</a>).<br>
+      <br>
+This problem can be avoided by using the NetCDF4 data format (<a href="chapter_4.2.html#netcdf_data_format">netcdf_data_format</a> &gt; <span style="font-style: italic;">2</span>), which allows more than one unlimited dimension.<br>
+      <br>
+Alternatively, <a href="chapter_4.2.html#maximum_number_of_particles">maximum_number_of_particles</a> can be given a sufficiently large value.<br>
       </td>
 
@@ -1889,6 +1902,24 @@
          <td style="vertical-align: top;">
       maximum_number_of_tails needs to be increased 
-                       but this is not allowed with NetCDF output switched on
-      </td><td style="vertical-align: top;"><br>
+                       but this is not allowed with netcdf_data_format &lt; 3
+      </td><td style="vertical-align: top;">NetCDF output is switched on (<a href="chapter_4.2.html#data_output_format">data_output_format</a> = <span style="font-style: italic;">'netcdf'</span>) and a NetCDF3 format is used (<a href="chapter_4.2.html#netcdf_data_format">netcdf_data_format</a> &lt; <span style="font-style: italic;">3</span>).<br>
+
+      <br>
+
+If output of particle data is switched on (see <a href="chapter_4.2.html#dt_write_particle_data">dt_write_particle_data</a>), the size of the particle tail array, given on each processor by <a href="chapter_4.2.html#maximum_number_of_tails">maximum_number_of_tails</a>,
+is not allowed to increase during the run, when the NetCDF3 data format
+is used, because NetCDF3 allows only one unlimited dimension, which is
+the time dimension. Anyhow, PALM tries to increase the size of the
+particle tail array, if the number of particle tails in a subdomain becomes
+larger than the size of this array. This may happen because of a flow
+convergence or because new sets of particles are released (see <a href="chapter_4.2.html#dt_prel">dt_prel</a>).<br>
+
+      <br>
+
+This problem can be avoided by using the NetCDF4 data format (<a href="chapter_4.2.html#netcdf_data_format">netcdf_data_format</a> &gt; <span style="font-style: italic;">2</span>), which allows more than one unlimited dimension.<br>
+
+      <br>
+
+Alternatively, <a href="chapter_4.2.html#maximum_number_of_tails">maximum_number_of_tails</a> can be given a sufficiently large value.
       </td>
 
Index: /palm/trunk/SOURCE/advec_particles.f90
===================================================================
--- /palm/trunk/SOURCE/advec_particles.f90	(revision 518)
+++ /palm/trunk/SOURCE/advec_particles.f90	(revision 519)
@@ -5,4 +5,5 @@
 ! -----------------
 ! TEST: PRINT statements on unit 9 (commented out)
+! NetCDF4 output format allows size of particle array to be extended
 !
 ! Former revisions:
@@ -1978,9 +1979,9 @@
           IF ( number_of_particles + number_of_initial_particles > &
                maximum_number_of_particles  )  THEN
-             IF ( netcdf_output )  THEN
+             IF ( netcdf_output  .AND.  netcdf_data_format < 3 )  THEN
                 message_string = 'maximum_number_of_particles ' //   &
                                  'needs to be increased ' //         &
                                  '&but this is not allowed with ' // &
-                                 'NetCDF output switched on'
+                                 'netcdf_data_format < 3'
                 CALL message( 'advec_particles', 'PA0146', 2, 2, -1, 6, 1 )
              ELSE
@@ -1998,9 +1999,9 @@
              IF ( number_of_tails + number_of_initial_tails > &
                   maximum_number_of_tails  )  THEN
-                IF ( netcdf_output )  THEN
+                IF ( netcdf_output  .AND.  netcdf_data_format < 3 )  THEN
                    message_string = 'maximum_number_of_tails ' //    &
                                     'needs to be increased ' //      &
                                     '&but this is not allowed wi' // &
-                                    'th NetCDF output switched on'
+                                    'th netcdf_data_format < 3'
                    CALL message( 'advec_particles', 'PA0147', 2, 2, -1, 6, 1 )
                 ELSE
@@ -2389,9 +2390,9 @@
                maximum_number_of_particles )           &
           THEN
-             IF ( netcdf_output )  THEN
+             IF ( netcdf_output  .AND.  netcdf_data_format < 3 )  THEN
                  message_string = 'maximum_number_of_particles ' //    &
                                   'needs to be increased ' //          &
                                   '&but this is not allowed with ' //  &
-                                  'NetCDF output switched on'
+                                  'netcdf-data_format < 3'
                 CALL message( 'advec_particles', 'PA0146', 2, 2, -1, 6, 1 )
              ELSE
@@ -2417,9 +2418,9 @@
              IF ( number_of_tails+trrpt_count_recv > maximum_number_of_tails ) &
              THEN
-                IF ( netcdf_output )  THEN
+                IF ( netcdf_output  .AND.  netcdf_data_format < 3 )  THEN
                    message_string = 'maximum_number_of_tails ' //   &
                                     'needs to be increased ' //     &
                                     '&but this is not allowed wi'// &
-                                    'th NetCDF output switched on'
+                                    'th netcdf_data_format < 3'
                    CALL message( 'advec_particles', 'PA0147', 2, 2, -1, 6, 1 )
                 ELSE
@@ -2466,9 +2467,9 @@
                maximum_number_of_particles )           &
           THEN
-             IF ( netcdf_output )  THEN
+             IF ( netcdf_output  .AND.  netcdf_data_format < 3 )  THEN
                 message_string = 'maximum_number_of_particles ' //  &
                                  'needs to be increased ' //        &
                                  '&but this is not allowed with '// &
-                                 'NetCDF output switched on'
+                                 'netcdf_data_format < 3'
                 CALL message( 'advec_particles', 'PA0146', 2, 2, -1, 6, 1 )
              ELSE
@@ -2494,9 +2495,9 @@
              IF ( number_of_tails+trlpt_count_recv > maximum_number_of_tails ) &
              THEN
-                IF ( netcdf_output )  THEN
+                IF ( netcdf_output  .AND.  netcdf_data_format < 3 )  THEN
                    message_string = 'maximum_number_of_tails ' //   &
                                     'needs to be increased ' //     &
                                     '&but this is not allowed wi'// &
-                                    'th NetCDF output switched on'
+                                    'th netcdf_data_format < 3'
                    CALL message( 'advec_particles', 'PA0147', 2, 2, -1, 6, 1 ) 
                 ELSE
@@ -2836,9 +2837,9 @@
                maximum_number_of_particles )           &
           THEN
-             IF ( netcdf_output )  THEN
+             IF ( netcdf_output  .AND.  netcdf_data_format < 3 )  THEN
                 message_string = 'maximum_number_of_particles ' //  &
                                  'needs to be increased ' //        &
                                  '&but this is not allowed with '// &
-                                 'NetCDF output switched on'
+                                 'netcdf_data_format < 3'
                 CALL message( 'advec_particles', 'PA0146', 2, 2, -1, 6, 1 ) 
              ELSE
@@ -2864,9 +2865,9 @@
              IF ( number_of_tails+trnpt_count_recv > maximum_number_of_tails ) &
              THEN
-                IF ( netcdf_output )  THEN
+                IF ( netcdf_output  .AND.  netcdf_data_format < 3 )  THEN
                    message_string = 'maximum_number_of_tails ' //    &
                                     'needs to be increased ' //      &
                                     '&but this is not allowed wi' // &
-                                    'th NetCDF output switched on'
+                                    'th netcdf_data_format < 3'
                    CALL message( 'advec_particles', 'PA0147', 2, 2, -1, 6, 1 ) 
                 ELSE
@@ -2914,9 +2915,9 @@
                maximum_number_of_particles )           &
           THEN
-             IF ( netcdf_output )  THEN
+             IF ( netcdf_output  .AND.  netcdf_data_format < 3 )  THEN
                 message_string = 'maximum_number_of_particles ' //   &
                                  'needs to be increased ' //         &
                                  '&but this is not allowed with ' // &
-                                 'NetCDF output switched on'
+                                 'netcdf_data_format < 3'
                CALL message( 'advec_particles', 'PA0146', 2, 2, -1, 6, 1 )  
              ELSE
@@ -2942,5 +2943,5 @@
              IF ( number_of_tails+trspt_count_recv > maximum_number_of_tails ) &
              THEN
-                IF ( netcdf_output )  THEN
+                IF ( netcdf_output  .AND.  netcdf_data_format < 3 )  THEN
                    message_string = 'maximum_number_of_tails ' //   &
                                     'needs to be increased ' //     &
Index: /palm/trunk/SOURCE/check_open.f90
===================================================================
--- /palm/trunk/SOURCE/check_open.f90	(revision 518)
+++ /palm/trunk/SOURCE/check_open.f90	(revision 519)
@@ -4,5 +4,5 @@
 ! Current revisions:
 ! -----------------
-! 
+! NetCDF4 support for particle data
 !
 ! Former revisions:
@@ -1275,12 +1275,36 @@
 
 !
-!--          Create a new NetCDF output file
-             IF ( netcdf_data_format > 1 )  THEN
+!--          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_prt )
+
+             ELSEIF ( netcdf_data_format == 2 )  THEN
+!
+!--             64bit-offset format
                 nc_stat = NF90_CREATE( filename,                               &
                                        OR( NF90_NOCLOBBER, NF90_64BIT_OFFSET ),&
                                        id_set_prt )
-             ELSE
-                nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, id_set_prt )
-             ENDIF
+
+#if defined( __netcdf4 )
+             ELSEIF ( netcdf_data_format == 3 )  THEN
+!
+!--             NetCDF4/HDF5 format, but no parallel output into a single file!
+                nc_stat = NF90_CREATE( filename,                               &
+                                       OR( NF90_NOCLOBBER, NF90_NETCDF4 ),     &
+                                       id_set_prt )
+
+             ELSEIF ( netcdf_data_format == 4 )  THEN
+!
+!--             NetCDF4/HDF5 format with classic model flag, but no parallel
+!--             output into a single file!
+                nc_stat = NF90_CREATE( filename,                               &
+                                       OR( NF90_NOCLOBBER,                     &
+                                        OR( NF90_CLASSIC_MODEL, NF90_HDF5 ) ), &
+                                       id_set_prt )
+#endif
+             ENDIF
+
              CALL handle_netcdf_error( 'check_open', 43 )  
 
Index: /palm/trunk/SOURCE/modules.f90
===================================================================
--- /palm/trunk/SOURCE/modules.f90	(revision 518)
+++ /palm/trunk/SOURCE/modules.f90	(revision 519)
@@ -5,5 +5,5 @@
 ! Current revisions:
 ! -----------------
-! 
+! -replace_char, replace_by
 !
 ! Former revisions:
@@ -976,12 +976,7 @@
 #endif
 
-    INTEGER, PARAMETER ::  dopr_norm_num = 7, dopts_num = 26, dots_max = 100, &
-                           replace_num = 6
+    INTEGER, PARAMETER ::  dopr_norm_num = 7, dopts_num = 26, dots_max = 100
 
     INTEGER ::  dots_num = 23
-
-    CHARACTER, DIMENSION( replace_num ) :: &
-                           replace_char = (/ '''', '"', '*', '/', '(', ')' /), &
-                           replace_by   = (/ 'p' , 'p', 's', 'o', '_', '_' /)
 
     CHARACTER (LEN=6), DIMENSION(dopr_norm_num) ::  dopr_norm_names =   &
Index: /palm/trunk/SOURCE/netcdf.f90
===================================================================
--- /palm/trunk/SOURCE/netcdf.f90	(revision 518)
+++ /palm/trunk/SOURCE/netcdf.f90	(revision 519)
@@ -7,5 +7,8 @@
 ! Current revisions:
 ! ------------------
-! 
+! Particle number defined as unlimited dimension in case of NetCDF4 output,
+! special characters like * and " are now allowed for NetCDF variable names,
+! replacement of these characters removed, routine clean_netcdf_varname
+! removed
 !
 ! Former revisions:
@@ -95,6 +98,5 @@
     CHARACTER (LEN=4)              ::  grid_x, grid_y, grid_z
     CHARACTER (LEN=6)              ::  mode
-    CHARACTER (LEN=10)             ::  netcdf_var_name, netcdf_var_name_base, &
-                                       precision, var
+    CHARACTER (LEN=10)             ::  netcdf_var_name, precision, var
     CHARACTER (LEN=80)             ::  time_average_text
     CHARACTER (LEN=2000)           ::  var_list, var_list_old
@@ -1556,10 +1558,6 @@
 !--             surface variable. Define it with id_dim_zu1_xy.
                 IF ( INDEX( do2d(av,i), '*' ) /= 0 )  THEN
-!
-!--                First, remove those characters not allowed by NetCDF
-                   netcdf_var_name = do2d(av,i)
-                   CALL clean_netcdf_varname( netcdf_var_name )
-
-                   nc_stat = NF90_DEF_VAR( id_set_xy(av), netcdf_var_name,     &
+
+                   nc_stat = NF90_DEF_VAR( id_set_xy(av),  do2d(av,i),         &
                                            nc_precision(1),                    &
                                            (/ id_dim_x_xy(av), id_dim_y_xy(av),&
@@ -1568,5 +1566,5 @@
                                            id_var_do2d(av,i) )
 
-                   var_list = TRIM(var_list) // TRIM(netcdf_var_name) // ';'
+                   var_list = TRIM(var_list) // TRIM( do2d(av,i) ) // ';'
 
                 ELSE
@@ -1827,7 +1825,5 @@
           DO WHILE ( do2d(av,i)(1:1) /= ' ' )
              IF ( INDEX( do2d(av,i), 'xy' ) /= 0 )  THEN
-                netcdf_var_name = do2d(av,i)
-                CALL clean_netcdf_varname( netcdf_var_name )
-                var_list = TRIM(var_list) // TRIM(netcdf_var_name) // ';'
+                var_list = TRIM( var_list ) // TRIM( do2d(av,i) ) // ';'
              ENDIF
              i = i + 1
@@ -1967,7 +1963,5 @@
           DO WHILE ( do2d(av,i)(1:1) /= ' ' )
              IF ( INDEX( do2d(av,i), 'xy' ) /= 0 )  THEN
-                netcdf_var_name = do2d(av,i)
-                CALL clean_netcdf_varname( netcdf_var_name )
-                nc_stat = NF90_INQ_VARID( id_set_xy(av), netcdf_var_name, &
+                nc_stat = NF90_INQ_VARID( id_set_xy(av), do2d(av,i), &
                                           id_var_do2d(av,i) )
                 CALL handle_netcdf_error( 'netcdf', 138 )
@@ -2401,7 +2395,5 @@
           DO WHILE ( do2d(av,i)(1:1) /= ' ' )
              IF ( INDEX( do2d(av,i), 'xz' ) /= 0 )  THEN
-                netcdf_var_name = do2d(av,i)
-                CALL clean_netcdf_varname( netcdf_var_name )
-                var_list = TRIM(var_list) // TRIM(netcdf_var_name) // ';'
+                var_list = TRIM( var_list ) // TRIM( do2d(av,i) ) // ';'
              ENDIF
              i = i + 1
@@ -2541,7 +2533,5 @@
           DO WHILE ( do2d(av,i)(1:1) /= ' ' )
              IF ( INDEX( do2d(av,i), 'xz' ) /= 0 )  THEN
-                netcdf_var_name = do2d(av,i)
-                CALL clean_netcdf_varname( netcdf_var_name )
-                nc_stat = NF90_INQ_VARID( id_set_xz(av), netcdf_var_name, &
+                nc_stat = NF90_INQ_VARID( id_set_xz(av), do2d(av,i), &
                                           id_var_do2d(av,i) )
                 CALL handle_netcdf_error( 'netcdf', 177 )
@@ -2989,7 +2979,5 @@
           DO WHILE ( do2d(av,i)(1:1) /= ' ' )
              IF ( INDEX( do2d(av,i), 'yz' ) /= 0 )  THEN
-                netcdf_var_name = do2d(av,i)
-                CALL clean_netcdf_varname( netcdf_var_name )
-                var_list = TRIM(var_list) // TRIM(netcdf_var_name) // ';'
+                var_list = TRIM( var_list ) // TRIM( do2d(av,i) ) // ';'
              ENDIF
              i = i + 1
@@ -3129,7 +3117,5 @@
           DO WHILE ( do2d(av,i)(1:1) /= ' ' )
              IF ( INDEX( do2d(av,i), 'yz' ) /= 0 )  THEN
-                netcdf_var_name = do2d(av,i)
-                CALL clean_netcdf_varname( netcdf_var_name )
-                nc_stat = NF90_INQ_VARID( id_set_yz(av), netcdf_var_name, &
+                nc_stat = NF90_INQ_VARID( id_set_yz(av), do2d(av,i), &
                                           id_var_do2d(av,i) )
                 CALL handle_netcdf_error( 'netcdf', 216 )
@@ -3229,8 +3215,4 @@
           var_list = ';'
           DO  i = 1, dopr_n
-!
-!--          First, remove those characters not allowed by NetCDF
-             netcdf_var_name = data_output_pr(i)
-             CALL clean_netcdf_varname( netcdf_var_name )
 
              IF ( statistic_regions == 0 )  THEN
@@ -3238,10 +3220,12 @@
 !
 !--             Define the z-axes (each variable gets its own z-axis)
-                nc_stat = NF90_DEF_DIM( id_set_pr, 'z'//TRIM(netcdf_var_name), &
+                nc_stat = NF90_DEF_DIM( id_set_pr,                        &
+                                        'z' // TRIM( data_output_pr(i) ), &
                                         nzt+2-nzb, id_dim_z_pr(i,0) )
                 CALL handle_netcdf_error( 'netcdf', 223 )
 
-                nc_stat = NF90_DEF_VAR( id_set_pr, 'z'//TRIM(netcdf_var_name), &
-                                        NF90_DOUBLE, id_dim_z_pr(i,0),         &
+                nc_stat = NF90_DEF_VAR( id_set_pr,                        &
+                                        'z' // TRIM( data_output_pr(i) ), &
+                                        NF90_DOUBLE, id_dim_z_pr(i,0),    &
                                         id_var_z_pr(i,0) )
                 CALL handle_netcdf_error( 'netcdf', 224 )
@@ -3252,5 +3236,5 @@
 !
 !--             Define the variable
-                nc_stat = NF90_DEF_VAR( id_set_pr, netcdf_var_name,           &
+                nc_stat = NF90_DEF_VAR( id_set_pr, data_output_pr(i),         &
                                         nc_precision(5), (/ id_dim_z_pr(i,0), &
                                         id_dim_time_pr /), id_var_dopr(i,0) )
@@ -3265,5 +3249,5 @@
                 CALL handle_netcdf_error( 'netcdf', 228 )
 
-                var_list = TRIM(var_list) // TRIM(netcdf_var_name) // ';'
+                var_list = TRIM( var_list ) // TRIM( data_output_pr(i) ) //  ';'
 
              ELSE
@@ -3277,10 +3261,10 @@
 !--                Define the z-axes (each variable gets it own z-axis)
                    nc_stat = NF90_DEF_DIM( id_set_pr,                          &
-                                           'z'//TRIM(netcdf_var_name)//suffix, &
+                                         'z'//TRIM(data_output_pr(i))//suffix, &
                                            nzt+2-nzb, id_dim_z_pr(i,j) )
                    CALL handle_netcdf_error( 'netcdf', 229 )
 
                    nc_stat = NF90_DEF_VAR( id_set_pr,                          &
-                                           'z'//TRIM(netcdf_var_name)//suffix, &
+                                         'z'//TRIM(data_output_pr(i))//suffix, &
                                            nc_precision(5), id_dim_z_pr(i,j),  &
                                            id_var_z_pr(i,j) )
@@ -3294,5 +3278,5 @@
 !--                Define the variable
                    nc_stat = NF90_DEF_VAR( id_set_pr,                         &
-                                           TRIM( netcdf_var_name ) // suffix, &
+                                           TRIM(data_output_pr(i)) // suffix, &
                                            nc_precision(5),                   &
                                            (/ id_dim_z_pr(i,j),               &
@@ -3310,5 +3294,5 @@
                    CALL handle_netcdf_error( 'netcdf', 234 )
 
-                   var_list = TRIM(var_list) // TRIM(netcdf_var_name) // &
+                   var_list = TRIM( var_list ) // TRIM( data_output_pr(i) ) // &
                               suffix // ';'
 
@@ -3376,13 +3360,10 @@
           DO  i = 1, dopr_n
 
-             netcdf_var_name = data_output_pr(i)
-             CALL clean_netcdf_varname( netcdf_var_name )
-
              IF ( statistic_regions == 0 )  THEN
-                var_list = TRIM(var_list) // TRIM(netcdf_var_name) // ';'
+                var_list = TRIM( var_list ) // TRIM( data_output_pr(i) ) // ';'
              ELSE
                 DO  j = 0, statistic_regions
                    WRITE ( suffix, '(''_'',I1)' )  j
-                   var_list = TRIM(var_list) // TRIM(netcdf_var_name) // &
+                   var_list = TRIM( var_list ) // TRIM( data_output_pr(i) ) // &
                               suffix // ';'
                 ENDDO
@@ -3445,9 +3426,6 @@
           DO  i = 1, dopr_n
  
-             netcdf_var_name_base = data_output_pr(i)
-             CALL clean_netcdf_varname( netcdf_var_name_base )
-
              IF ( statistic_regions == 0 )  THEN
-                nc_stat = NF90_INQ_VARID( id_set_pr, netcdf_var_name_base, &
+                nc_stat = NF90_INQ_VARID( id_set_pr, data_output_pr(i), &
                                           id_var_dopr(i,0) )
                 CALL handle_netcdf_error( 'netcdf', 245 )
@@ -3455,5 +3433,5 @@
                 DO  j = 0, statistic_regions
                    WRITE ( suffix, '(''_'',I1)' )  j
-                   netcdf_var_name = TRIM( netcdf_var_name_base ) // suffix
+                   netcdf_var_name = TRIM( data_output_pr(i) ) // suffix
                    nc_stat = NF90_INQ_VARID( id_set_pr, netcdf_var_name, &
                                              id_var_dopr(i,j) )
@@ -3525,12 +3503,8 @@
           var_list = ';'
           DO  i = 1, dots_num
-!
-!--          First, remove those characters not allowed by NetCDF
-             netcdf_var_name = dots_label(i)
-             CALL clean_netcdf_varname( netcdf_var_name )
 
              IF ( statistic_regions == 0 )  THEN
 
-                nc_stat = NF90_DEF_VAR( id_set_ts, netcdf_var_name,            &
+                nc_stat = NF90_DEF_VAR( id_set_ts, dots_label(i),              &
                                         nc_precision(6), (/ id_dim_time_ts /), &
                                         id_var_dots(i,0) )
@@ -3545,5 +3519,5 @@
                 CALL handle_netcdf_error( 'netcdf', 255 )
 
-                var_list = TRIM(var_list) // TRIM(netcdf_var_name) // ';'
+                var_list = TRIM( var_list ) // TRIM( dots_label(i) ) // ';'
 
              ELSE
@@ -3555,5 +3529,5 @@
 
                    nc_stat = NF90_DEF_VAR( id_set_ts,                         &
-                                           TRIM( netcdf_var_name ) // suffix, &
+                                           TRIM( dots_label(i) ) // suffix,   &
                                            nc_precision(6),                   &
                                            (/ id_dim_time_ts /),              &
@@ -3571,5 +3545,5 @@
                    CALL handle_netcdf_error( 'netcdf', 347 )
 
-                   var_list = TRIM(var_list) // TRIM(netcdf_var_name) // &
+                   var_list = TRIM( var_list ) // TRIM( dots_label(i) ) // &
                               suffix // ';'
 
@@ -3607,13 +3581,10 @@
           DO  i = 1, dots_num
 
-             netcdf_var_name = dots_label(i)
-             CALL clean_netcdf_varname( netcdf_var_name )
-
              IF ( statistic_regions == 0 )  THEN
-                var_list = TRIM(var_list) // TRIM(netcdf_var_name) // ';'
+                var_list = TRIM( var_list ) // TRIM( dots_label(i) ) // ';'
              ELSE
                 DO  j = 0, statistic_regions
                    WRITE ( suffix, '(''_'',I1)' )  j
-                   var_list = TRIM(var_list) // TRIM(netcdf_var_name) // &
+                   var_list = TRIM( var_list ) // TRIM( dots_label(i) ) // &
                               suffix // ';'
                 ENDDO
@@ -3676,9 +3647,6 @@
           DO  i = 1, dots_num
  
-             netcdf_var_name_base = dots_label(i)
-             CALL clean_netcdf_varname( netcdf_var_name_base )
-
              IF ( statistic_regions == 0 )  THEN
-                nc_stat = NF90_INQ_VARID( id_set_ts, netcdf_var_name_base, &
+                nc_stat = NF90_INQ_VARID( id_set_ts, dots_label(i), &
                                           id_var_dots(i,0) )
                 CALL handle_netcdf_error( 'netcdf', 265 )
@@ -3686,5 +3654,5 @@
                 DO  j = 0, statistic_regions
                    WRITE ( suffix, '(''_'',I1)' )  j
-                   netcdf_var_name = TRIM( netcdf_var_name_base ) // suffix
+                   netcdf_var_name = TRIM( dots_label(i) ) // suffix
                    nc_stat = NF90_INQ_VARID( id_set_ts, netcdf_var_name, &
                                              id_var_dots(i,j) )
@@ -3842,5 +3810,4 @@
 !--             Define the variable
                 netcdf_var_name = TRIM( data_output_sp(i) ) // '_x'
-                CALL clean_netcdf_varname( netcdf_var_name )
                 IF ( TRIM( grid_z ) == 'zw' )  THEN
                    nc_stat = NF90_DEF_VAR( id_set_sp, netcdf_var_name,      &
@@ -3873,5 +3840,4 @@
 !--             Define the variable
                 netcdf_var_name = TRIM( data_output_sp(i) ) // '_y'
-                CALL clean_netcdf_varname( netcdf_var_name )
                 IF ( TRIM( grid_z ) == 'zw' )  THEN
                    nc_stat = NF90_DEF_VAR( id_set_sp, netcdf_var_name,      &
@@ -4174,6 +4140,13 @@
 !
 !--       Define particle coordinate (maximum particle number)
-          nc_stat = NF90_DEF_DIM( id_set_prt, 'particle_number', &
-                                  maximum_number_of_particles, id_dim_prtnum )
+          IF ( netcdf_data_format < 3 )  THEN
+             nc_stat = NF90_DEF_DIM( id_set_prt, 'particle_number', &
+                                     maximum_number_of_particles, id_dim_prtnum)
+          ELSE
+!
+!--          NetCDF4 allows more than one unlimited dimension
+             nc_stat = NF90_DEF_DIM( id_set_prt, 'particle_number', &
+                                     NF90_UNLIMITED, id_dim_prtnum)
+          ENDIF
           CALL handle_netcdf_error( 'netcdf', 314 )
 
@@ -4311,9 +4284,4 @@
           DO  i = 1, dopts_num
 
-!
-!--          First, remove those characters not allowed by NetCDF
-             netcdf_var_name = dopts_label(i)
-             CALL clean_netcdf_varname( netcdf_var_name )
-
              DO  j = 0, number_of_particle_groups
 
@@ -4325,5 +4293,5 @@
 
                 nc_stat = NF90_DEF_VAR( id_set_pts,                         &
-                                        TRIM( netcdf_var_name ) // suffix1, &
+                                        TRIM( dopts_label(i) ) // suffix1,  &
                                         nc_precision(6),                    &
                                         (/ id_dim_time_pts /),              &
@@ -4347,5 +4315,5 @@
                 CALL handle_netcdf_error( 'netcdf', 402 )
 
-                var_list = TRIM(var_list) // TRIM(netcdf_var_name) // &
+                var_list = TRIM( var_list ) // TRIM( dopts_label(i) ) // &
                            suffix1 // ';'
 
@@ -4385,7 +4353,4 @@
           DO  i = 1, dopts_num
 
-             netcdf_var_name = dopts_label(i)
-             CALL clean_netcdf_varname( netcdf_var_name )
-
              DO  j = 0, number_of_particle_groups
 
@@ -4396,5 +4361,5 @@
                 ENDIF
 
-                var_list = TRIM(var_list) // TRIM(netcdf_var_name) // &
+                var_list = TRIM( var_list ) // TRIM( dopts_label(i) ) // &
                            suffix1 // ';'
 
@@ -4459,7 +4424,4 @@
           DO  i = 1, dopts_num
  
-             netcdf_var_name_base = dopts_label(i)
-             CALL clean_netcdf_varname( netcdf_var_name_base )
-
              DO  j = 0, number_of_particle_groups
 
@@ -4470,5 +4432,5 @@
                 ENDIF
 
-                netcdf_var_name = TRIM( netcdf_var_name_base ) // suffix1
+                netcdf_var_name = TRIM( dopts_label(i) ) // suffix1
 
                 nc_stat = NF90_INQ_VARID( id_set_pts, netcdf_var_name, &
@@ -4546,36 +4508,2 @@
 #endif
  END SUBROUTINE handle_netcdf_error
-
-
-
- SUBROUTINE clean_netcdf_varname( string )
-#if defined( __netcdf )
-
-!------------------------------------------------------------------------------!
-!
-! Description:
-! ------------
-! Replace those characters in string which are not allowed by NetCDF.
-!------------------------------------------------------------------------------!
-
-    USE netcdf_control
-
-    IMPLICIT NONE
-
-    CHARACTER (LEN=10), INTENT(INOUT) ::  string
-
-    INTEGER ::  i, ic
-
-    DO  i = 1, replace_num
-       DO
-          ic = INDEX( string, replace_char(i) )
-          IF ( ic /= 0 )  THEN
-             string(ic:ic) = replace_by(i)
-          ELSE
-             EXIT
-          ENDIF
-       ENDDO
-    ENDDO
-
-#endif
- END SUBROUTINE clean_netcdf_varname
