Index: palm/trunk/SOURCE/netcdf.f90
===================================================================
--- palm/trunk/SOURCE/netcdf.f90	(revision 292)
+++ palm/trunk/SOURCE/netcdf.f90	(revision 359)
@@ -7,4 +7,11 @@
 ! Current revisions:
 ! ------------------
+! For extended NetCDF files, the updated title attribute includes an update of
+! time_average_text where appropriate.
+! Bugfix for extended NetCDF files: In order to avoid 'data mode' errors if 
+! updated attributes are larger than their original size, NF90_PUT_ATT is called
+! in 'define mode' enclosed by NF90_REDEF and NF90_ENDDEF calls. This implies a
+! possible performance loss; an alternative strategy would be to ensure equal
+! attribute size in a job chain.
 ! NetCDF unit attribute in timeseries output in case of statistic
 ! regions added.
@@ -650,8 +657,24 @@
 
 !
-!--       Change the title attribute on file
+!--       Update the title attribute on file
+!--       In order to avoid 'data mode' errors if updated attributes are larger 
+!--       than their original size, NF90_PUT_ATT is called in 'define mode' 
+!--       enclosed by NF90_REDEF and NF90_ENDDEF calls. This implies a possible 
+!--       performance loss due to data copying; an alternative strategy would be 
+!--       to ensure equal attribute size. Maybe revise later.
+          IF ( av == 0 )  THEN
+             time_average_text = ' '
+          ELSE
+             WRITE (time_average_text, '('', '',F7.1,'' s average'')') &
+                                                            averaging_interval
+          ENDIF
+          nc_stat = NF90_REDEF( id_set_3d(av) )
+          CALL handle_netcdf_error( 'netcdf', 429 )
           nc_stat = NF90_PUT_ATT( id_set_3d(av), NF90_GLOBAL, 'title', &
-                                  TRIM( run_description_header ) )
+                                  TRIM( run_description_header ) //    &
+                                  TRIM( time_average_text ) )
           CALL handle_netcdf_error( 'netcdf', 96 )
+          nc_stat = NF90_ENDDEF( id_set_3d(av) )
+          CALL handle_netcdf_error( 'netcdf', 430 )
           message_string = 'NetCDF file for volume data ' //             &
                            TRIM( var ) // ' from previous run found.' // &
@@ -1276,8 +1299,24 @@
 
 !
-!--       Change the title attribute on file
+!--       Update the title attribute on file
+!--       In order to avoid 'data mode' errors if updated attributes are larger 
+!--       than their original size, NF90_PUT_ATT is called in 'define mode' 
+!--       enclosed by NF90_REDEF and NF90_ENDDEF calls. This implies a possible 
+!--       performance loss due to data copying; an alternative strategy would be 
+!--       to ensure equal attribute size in a job chain. Maybe revise later.
+          IF ( av == 0 )  THEN
+             time_average_text = ' '
+          ELSE
+             WRITE (time_average_text, '('', '',F7.1,'' s average'')') &
+                                                            averaging_interval
+          ENDIF
+          nc_stat = NF90_REDEF( id_set_xy(av) )
+          CALL handle_netcdf_error( 'netcdf', 431 )
           nc_stat = NF90_PUT_ATT( id_set_xy(av), NF90_GLOBAL, 'title', &
-                                  TRIM( run_description_header ) )
+                                  TRIM( run_description_header ) //    &
+                                  TRIM( time_average_text ) )
           CALL handle_netcdf_error( 'netcdf', 139 )
+          nc_stat = NF90_ENDDEF( id_set_xy(av) )
+          CALL handle_netcdf_error( 'netcdf', 432 )
           message_string = 'NetCDF file for cross-sections ' //           & 
                             TRIM( var ) // ' from previous run found.' // &
@@ -1798,8 +1837,24 @@
 
 !
-!--       Change the title attribute on file
+!--       Update the title attribute on file
+!--       In order to avoid 'data mode' errors if updated attributes are larger 
+!--       than their original size, NF90_PUT_ATT is called in 'define mode' 
+!--       enclosed by NF90_REDEF and NF90_ENDDEF calls. This implies a possible 
+!--       performance loss due to data copying; an alternative strategy would be 
+!--       to ensure equal attribute size in a job chain. Maybe revise later.
+          IF ( av == 0 )  THEN
+             time_average_text = ' '
+          ELSE
+             WRITE (time_average_text, '('', '',F7.1,'' s average'')') &
+                                                            averaging_interval
+          ENDIF
+          nc_stat = NF90_REDEF( id_set_xz(av) )
+          CALL handle_netcdf_error( 'netcdf', 433 )
           nc_stat = NF90_PUT_ATT( id_set_xz(av), NF90_GLOBAL, 'title', &
-                                  TRIM( run_description_header ) )
+                                  TRIM( run_description_header ) //    &
+                                  TRIM( time_average_text ) )
           CALL handle_netcdf_error( 'netcdf', 178 )
+          nc_stat = NF90_ENDDEF( id_set_xz(av) )
+          CALL handle_netcdf_error( 'netcdf', 434 )
           message_string = 'NetCDF file for cross-sections ' //           & 
                             TRIM( var ) // ' from previous run found.' // &
@@ -2318,8 +2373,24 @@
 
 !
-!--       Change the title attribute on file
+!--       Update the title attribute on file
+!--       In order to avoid 'data mode' errors if updated attributes are larger 
+!--       than their original size, NF90_PUT_ATT is called in 'define mode' 
+!--       enclosed by NF90_REDEF and NF90_ENDDEF calls. This implies a possible 
+!--       performance loss due to data copying; an alternative strategy would be 
+!--       to ensure equal attribute size in a job chain. Maybe revise later.
+          IF ( av == 0 )  THEN
+             time_average_text = ' '
+          ELSE
+             WRITE (time_average_text, '('', '',F7.1,'' s average'')') &
+                                                            averaging_interval
+          ENDIF
+          nc_stat = NF90_REDEF( id_set_yz(av) )
+          CALL handle_netcdf_error( 'netcdf', 435 )
           nc_stat = NF90_PUT_ATT( id_set_yz(av), NF90_GLOBAL, 'title', &
-                                  TRIM( run_description_header ) )
+                                  TRIM( run_description_header ) //    &
+                                  TRIM( time_average_text ) )
           CALL handle_netcdf_error( 'netcdf', 217 )
+          nc_stat = NF90_ENDDEF( id_set_yz(av) )
+          CALL handle_netcdf_error( 'netcdf', 436 )
           message_string = 'NetCDF file for cross-sections ' //           & 
                             TRIM( var ) // ' from previous run found.' // &
@@ -2611,8 +2682,24 @@
 
 !
-!--       Change the title attribute on file
+!--       Update the title attribute on file
+!--       In order to avoid 'data mode' errors if updated attributes are larger 
+!--       than their original size, NF90_PUT_ATT is called in 'define mode' 
+!--       enclosed by NF90_REDEF and NF90_ENDDEF calls. This implies a possible 
+!--       performance loss due to data copying; an alternative strategy would be 
+!--       to ensure equal attribute size in a job chain. Maybe revise later.
+          IF ( averaging_interval_pr == 0.0 )  THEN
+             time_average_text = ' '
+          ELSE
+             WRITE (time_average_text, '('', '',F7.1,'' s average'')') &
+                                                            averaging_interval_pr
+          ENDIF
+          nc_stat = NF90_REDEF( id_set_pr )
+          CALL handle_netcdf_error( 'netcdf', 437 )
           nc_stat = NF90_PUT_ATT( id_set_pr, NF90_GLOBAL, 'title', &
-                                  TRIM( run_description_header ) )
+                                  TRIM( run_description_header ) //    &
+                                  TRIM( time_average_text ) )
           CALL handle_netcdf_error( 'netcdf', 248 )
+          nc_stat = NF90_ENDDEF( id_set_pr )
+          CALL handle_netcdf_error( 'netcdf', 438 )
           message_string = 'NetCDF file for vertical profiles ' // & 
                            'from previous run found.' //           &
@@ -2817,8 +2904,17 @@
 
 !
-!--       Change the title attribute on file
+!--       Update the title attribute on file
+!--       In order to avoid 'data mode' errors if updated attributes are larger 
+!--       than their original size, NF90_PUT_ATT is called in 'define mode' 
+!--       enclosed by NF90_REDEF and NF90_ENDDEF calls. This implies a possible 
+!--       performance loss due to data copying; an alternative strategy would be 
+!--       to ensure equal attribute size in a job chain. Maybe revise later.
+          nc_stat = NF90_REDEF( id_set_ts )
+          CALL handle_netcdf_error( 'netcdf', 439 )
           nc_stat = NF90_PUT_ATT( id_set_ts, NF90_GLOBAL, 'title', &
                                   TRIM( run_description_header ) )
           CALL handle_netcdf_error( 'netcdf', 267 )
+          nc_stat = NF90_ENDDEF( id_set_ts )
+          CALL handle_netcdf_error( 'netcdf', 440 )
           message_string = 'NetCDF file for time series ' // & 
                            'from previous run found.' //     &
@@ -3230,5 +3326,12 @@
 
 !
-!--       Change the title attribute on file
+!--       Update the title attribute on file
+!--       In order to avoid 'data mode' errors if updated attributes are larger 
+!--       than their original size, NF90_PUT_ATT is called in 'define mode' 
+!--       enclosed by NF90_REDEF and NF90_ENDDEF calls. This implies a possible 
+!--       performance loss due to data copying; an alternative strategy would be 
+!--       to ensure equal attribute size in a job chain. Maybe revise later.
+          nc_stat = NF90_REDEF( id_set_sp )
+          CALL handle_netcdf_error( 'netcdf', 441 )
           IF ( averaging_interval_sp /= 0.0 )  THEN
              WRITE (time_average_text,'('', '',F7.1,'' s average'')') &
@@ -3247,4 +3350,6 @@
           ENDIF
           CALL handle_netcdf_error( 'netcdf', 309 )
+          nc_stat = NF90_ENDDEF( id_set_sp )
+          CALL handle_netcdf_error( 'netcdf', 442 )
           message_string = 'NetCDF file for spectra ' //     & 
                            'from previous run found.' //     &
@@ -3586,8 +3691,17 @@
 
 !
-!--       Change the title attribute on file
+!--       Update the title attribute on file
+!--       In order to avoid 'data mode' errors if updated attributes are larger 
+!--       than their original size, NF90_PUT_ATT is called in 'define mode' 
+!--       enclosed by NF90_REDEF and NF90_ENDDEF calls. This implies a possible 
+!--       performance loss due to data copying; an alternative strategy would be 
+!--       to ensure equal attribute size in a job chain. Maybe revise later.
+          nc_stat = NF90_REDEF( id_set_pts )
+          CALL handle_netcdf_error( 'netcdf', 443 )
           nc_stat = NF90_PUT_ATT( id_set_pts, NF90_GLOBAL, 'title', &
                                   TRIM( run_description_header ) )
           CALL handle_netcdf_error( 'netcdf', 411 )
+          nc_stat = NF90_ENDDEF( id_set_pts )
+          CALL handle_netcdf_error( 'netcdf', 444 )
           message_string = 'NetCDF file for particle time series ' // & 
                            'from previous run found.' //              &
