Index: /palm/trunk/DOC/app/appendix_a.html
===================================================================
--- /palm/trunk/DOC/app/appendix_a.html	(revision 358)
+++ /palm/trunk/DOC/app/appendix_a.html	(revision 359)
@@ -1,5 +1,4 @@
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
-<html>
-<head>
+<html><head>
 
     
@@ -7,9 +6,7 @@
 
     
-  <title>PALM Appendix A</title>
-</head>
-
-
-  <body>
+  <title>PALM Appendix A</title></head>
+
+<body>
 
     
@@ -3665,5 +3662,5 @@
 
          <td>
-      <p>**** contains numbers in the range from 1-428</p>
+      <p>**** contains numbers in the range from 1-444</p>
       </td>
 
@@ -3681,4 +3678,3 @@
 
   
-</body>
-</html>
+</body></html>
Index: /palm/trunk/DOC/app/chapter_3.4.html
===================================================================
--- /palm/trunk/DOC/app/chapter_3.4.html	(revision 358)
+++ /palm/trunk/DOC/app/chapter_3.4.html	(revision 359)
@@ -3349,5 +3349,5 @@
 the&nbsp;subroutine <span style="font-family: Cumberland AMT;">init_grid</span>&nbsp;reads
 the topography height information (in m above ground) for each grid point in
-a free floating point format. The data on file are laid out naturally,
+a free floating point format. <font color="#000000">The ascii file format is <a href="http://en.wikipedia.org/wiki/ESRI_grid#ASCII" target="_blank">ESRI grid</a> - also known as <a href="http://en.wikipedia.org/wiki/ESRI_grid#ASCII" target="_blank">ARC/INFO ASCII GRID</a> <span style="font-style: italic;">- without the header</span>. </font>The data on file are laid out naturally,
 i.e. in W-E orientation horizontally and in S-N orientation vertically,
 they must thus be organized as follows:<br>
@@ -3372,8 +3372,5 @@
 
       
-      </ul>
-
-
-Layout sketch:<br>
+      </ul>Layout sketch:<br>
 
 
Index: /palm/trunk/SCRIPTS/mrun
===================================================================
--- /palm/trunk/SCRIPTS/mrun	(revision 358)
+++ /palm/trunk/SCRIPTS/mrun	(revision 359)
@@ -185,4 +185,5 @@
      # 08/07/09 - Siggi  - default value for email_notification is none,
      #                     option -e added to subjob
+     # 19/08/09 - Marcus - MPI debug option
 
  
@@ -2866,4 +2867,11 @@
     PATH=$PATH:$TEMPDIR
 
+       # MPI debug option (argument checking, slows down execution due to increased latency)
+    if [[ "$mpi_debug" = true ]]
+    then
+       export MPI_CHECK_ARGS=1
+       printf "\n  +++ MPI_CHECK_ARGS=$MPI_CHECK_ARGS"
+    fi
+
     if [[ "$cond1" = debug  ||  "$cond2" = debug ]]
     then
Index: /palm/trunk/SOURCE/CURRENT_MODIFICATIONS
===================================================================
--- /palm/trunk/SOURCE/CURRENT_MODIFICATIONS	(revision 358)
+++ /palm/trunk/SOURCE/CURRENT_MODIFICATIONS	(revision 359)
@@ -51,4 +51,7 @@
 Changed:
 -------
+For extended NetCDF files, the updated title attribute includes an update of
+time_average_text where appropriate. (netcdf)
+
 In case of restart runs without extension, initial profiles are not written 
 to NetCDF-file anymore. (data_output_profiles, modules, read_var_list, write_var_list)
@@ -110,4 +113,13 @@
 Errors:
 ------
+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)
+
+Bugfix: correction of initial volume flow for non-flat topography (init_3d_model)
+Bugfix: zero initialization of arrays within buildings for 'cyclic_fill' (init_3d_model)
+
 Bugfix: to_be_resorted => s_av for time-averaged scalars (data_output_2d, data_output_3d)
 
Index: /palm/trunk/SOURCE/init_3d_model.f90
===================================================================
--- /palm/trunk/SOURCE/init_3d_model.f90	(revision 358)
+++ /palm/trunk/SOURCE/init_3d_model.f90	(revision 359)
@@ -7,4 +7,6 @@
 ! Current revisions:
 ! -----------------
+! bugfix: correction of initial volume flow for non-flat topography
+! bugfix: zero initialization of arrays within buildings for 'cyclic_fill'
 ! bugfix: avoid that ngp_2dh_s_inner becomes zero
 ! initializing_actions='read_data_for_recycling' renamed to 'cyclic_fill', now
@@ -485,5 +487,6 @@
                    DO  j = nys, nyn
                       DO  k = nzb + 1, nzb_u_inner(j,nx)
-                         u_nzb_p1_for_vfc(j) = u1d(k) * dzu(k)
+                         u_nzb_p1_for_vfc(j) = u_nzb_p1_for_vfc(j) + &
+                                               u1d(k) * dzu(k)
                       ENDDO
                    ENDDO
@@ -492,5 +495,6 @@
                    DO  i = nxl, nxr
                       DO  k = nzb + 1, nzb_v_inner(ny,i)
-                         v_nzb_p1_for_vfc(i) = v1d(k) * dzu(k)
+                         v_nzb_p1_for_vfc(i) = v_nzb_p1_for_vfc(i) + &
+                                               v1d(k) * dzu(k)
                       ENDDO
                    ENDDO
@@ -558,5 +562,6 @@
                 DO  j = nys, nyn
                    DO  k = nzb + 1, nzb_u_inner(j,nx) + 1
-                      u_nzb_p1_for_vfc(j) = u_init(k) * dzu(k)
+                      u_nzb_p1_for_vfc(j) = u_nzb_p1_for_vfc(j) + &
+                                            u_init(k) * dzu(k)
                    ENDDO
                 ENDDO
@@ -565,5 +570,6 @@
                 DO  i = nxl, nxr
                    DO  k = nzb + 1, nzb_v_inner(ny,i) + 1
-                      v_nzb_p1_for_vfc(i) = v_init(k) * dzu(k)
+                      v_nzb_p1_for_vfc(i) = v_nzb_p1_for_vfc(i) + &
+                                            v_init(k) * dzu(k)
                    ENDDO
                 ENDDO
@@ -1028,4 +1034,72 @@
 
 !
+!--    Inside buildings set velocities and TKE back to zero
+       IF ( TRIM( initializing_actions ) == 'cyclic_fill' .AND.  &
+            topography /= 'flat' )  THEN
+!
+!--       Correction of initial volume flow
+          IF ( conserve_volume_flow )  THEN
+             IF ( nxr == nx )  THEN
+                DO  j = nys, nyn
+                   DO  k = nzb + 1, nzb_u_inner(j,nx)
+                      u_nzb_p1_for_vfc(j) = u_nzb_p1_for_vfc(j) + &
+                                            u(k,j,nx) * dzu(k)
+                   ENDDO
+                ENDDO
+             ENDIF
+             IF ( nyn == ny )  THEN
+                DO  i = nxl, nxr
+                   DO  k = nzb + 1, nzb_v_inner(ny,i)
+                      v_nzb_p1_for_vfc(i) = v_nzb_p1_for_vfc(i) + &
+                                            v(k,ny,i) * dzu(k)
+                   ENDDO
+                ENDDO
+             ENDIF
+          ENDIF
+
+!
+!--       Inside buildings set velocities and TKE back to zero.
+!--       Other scalars (pt, q, s, km, kh, p, sa, ...) are ignored at present,
+!--       maybe revise later.
+          IF ( timestep_scheme(1:5) == 'runge' )  THEN
+             DO  i = nxl-1, nxr+1
+                DO  j = nys-1, nyn+1
+                   u  (nzb:nzb_u_inner(j,i),j,i) = 0.0
+                   v  (nzb:nzb_v_inner(j,i),j,i) = 0.0
+                   w  (nzb:nzb_w_inner(j,i),j,i) = 0.0
+                   e  (nzb:nzb_w_inner(j,i),j,i) = 0.0
+                   u_m(nzb:nzb_u_inner(j,i),j,i) = 0.0
+                   v_m(nzb:nzb_v_inner(j,i),j,i) = 0.0
+                   w_m(nzb:nzb_w_inner(j,i),j,i) = 0.0
+                   e_m(nzb:nzb_w_inner(j,i),j,i) = 0.0
+                   tu_m(nzb:nzb_u_inner(j,i),j,i) = 0.0
+                   tv_m(nzb:nzb_v_inner(j,i),j,i) = 0.0
+                   tw_m(nzb:nzb_w_inner(j,i),j,i) = 0.0
+                   te_m(nzb:nzb_w_inner(j,i),j,i) = 0.0
+                   tpt_m(nzb:nzb_w_inner(j,i),j,i) = 0.0
+                ENDDO
+             ENDDO
+          ELSE
+             DO  i = nxl-1, nxr+1
+                DO  j = nys-1, nyn+1
+                   u  (nzb:nzb_u_inner(j,i),j,i) = 0.0
+                   v  (nzb:nzb_v_inner(j,i),j,i) = 0.0
+                   w  (nzb:nzb_w_inner(j,i),j,i) = 0.0
+                   e  (nzb:nzb_w_inner(j,i),j,i) = 0.0
+                   u_m(nzb:nzb_u_inner(j,i),j,i) = 0.0
+                   v_m(nzb:nzb_v_inner(j,i),j,i) = 0.0
+                   w_m(nzb:nzb_w_inner(j,i),j,i) = 0.0
+                   e_m(nzb:nzb_w_inner(j,i),j,i) = 0.0
+                   u_p(nzb:nzb_u_inner(j,i),j,i) = 0.0
+                   v_p(nzb:nzb_v_inner(j,i),j,i) = 0.0
+                   w_p(nzb:nzb_w_inner(j,i),j,i) = 0.0
+                   e_p(nzb:nzb_w_inner(j,i),j,i) = 0.0
+                ENDDO
+             ENDDO
+          ENDIF
+
+       ENDIF
+
+!
 !--    Calculate the initial volume flow at the right and north boundary
        IF ( conserve_volume_flow  .AND.  &
@@ -1043,6 +1117,6 @@
                 ENDDO
 !
-!--             Correction if velocity at nzb+1 has been set zero further above
-!--             Note: at present, u_nzb_p1_for_vfc is zero (maybe revise later)
+!--             Correction if velocity inside buildings has been set to zero
+!--             further above
                 volume_flow_initial_l(1) = volume_flow_initial_l(1) + &
                                            u_nzb_p1_for_vfc(j)
@@ -1058,6 +1132,6 @@
                 ENDDO
 !
-!--             Correction if velocity at nzb+1 has been set zero further above
-!--             Note: at present, v_nzb_p1_for_vfc is zero (maybe revise later)
+!--             Correction if velocity inside buildings has been set to zero
+!--             further above
                 volume_flow_initial_l(2) = volume_flow_initial_l(2) + &
                                            v_nzb_p1_for_vfc(i)
Index: /palm/trunk/SOURCE/netcdf.f90
===================================================================
--- /palm/trunk/SOURCE/netcdf.f90	(revision 358)
+++ /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.' //              &
