Index: palm/trunk/UTIL/combine_plot_fields.f90
===================================================================
--- palm/trunk/UTIL/combine_plot_fields.f90	(revision 226)
+++ palm/trunk/UTIL/combine_plot_fields.f90	(revision 493)
@@ -4,5 +4,6 @@
 ! Actual revisions:
 ! -----------------
-! 
+! Exit in case of already complete NetCDF data (due to parallel output in PALM)
+! cpu measurements included
 !
 ! Former revisions:
@@ -47,37 +48,4 @@
 ! Output format is NetCDF. Additionally, a data are output in a binary format
 ! readable by ISO2D-software (cross-sections) and by AVS (3D-data).
-!
-! This routine must be compiled with:
-! decalpha:
-!    f95 -cpp -D__netcdf -fast -r8 -I/usr/local/netcdf-3.5.1/include
-!    -L/usr/local/netcdf-3.5.1/lib -lnetcdf
-! IBM-Regatta:
-!    xlf95 -qsuffix=cpp=f90 -WF,-D__netcdf -qrealsize=8 -q64 -qmaxmem=-1 -Q
-!    -I /aws/dataformats/netcdf-3.6.0-p1/64-32/include-64
-!    -L/aws/dataformats/netcdf-3.6.0-p1/64-32/lib -lnetcdf -O3
-! IBM-Regatta KISTI:
-!    xlf95 -qsuffix=cpp=f90 -WF,-D__netcdf -qrealsize=8 -q64 -qmaxmem=-1 -Q
-!    -I /applic/netcdf64/src/f90
-!    -L/applic/lib/NETCDF64 -lnetcdf -O3
-! IBM-Regatta Yonsei (gfdl5):
-!    xlf95 -qsuffix=cpp=f90 -WF,-D__netcdf -qrealsize=8 -q64 -qmaxmem=-1 -Q
-!    -I /usr1/users/raasch/pub/netcdf-3.6.0-p1/include
-!    -L/usr1/users/raasch/pub/netcdf-3.6.0-p1/lib -lnetcdf -O3
-! IMUK:
-!    ifort combine...f90 -o combine...x
-!    -cpp -D__netcdf -I /muksoft/packages/netcdf/linux/include -axW -r8 -nbs
-!    -Vaxlib -L /muksoft/packages/netcdf/linux/lib -lnetcdf
-! NEC-SX6:
-!    sxf90 combine...f90 -o combine...x 
-!    -I /pool/SX-6/netcdf/netcdf-3.6.0-p1/include  -C hopt -Wf '-A idbl4'
-!    -D__netcdf -L/pool/SX-6/netcdf/netcdf-3.6.0-p1/lib -lnetcdf
-! Sun Fire X4600
-!    pgf95 combine...f90 -o combine...x
-!    -Mpreprocess -D__netcdf -I /home/usr5/mkanda/netcdf-3.6.1/src/f90 -r8
-!    -fast -L/home/usr5/mkanda/netcdf-3.6.1/src/libsrc -lnetcdf
-! FIMM:
-!    ifort combine...f90 -o combine...x
-!    -axW -cpp -openmp -r8 -nbs -convert little_endian -D__netcdf 
-!    -I /local/netcdf/include -Vaxlib -L/local/netcdf/lib -lnetcdf
 !------------------------------------------------------------------------------!
 
@@ -104,4 +72,12 @@
                 xxa, xxe, ya, ye, yya, yye, za, ze, zza, zze
 
+#if defined( __lc ) || defined( __decalpha )
+    INTEGER(8)                  ::  count, count_rate
+#elif defined( __nec )
+    INTEGER                     ::  count, count_rate
+#elif defined( __ibm )
+    INTEGER(8)                  ::  IRTC
+#endif
+
     INTEGER, DIMENSION(0:1) ::  current_level, current_var, fanz, id_set, &
          id_var_time, num_var
@@ -114,7 +90,7 @@
 
     LOGICAL ::  avs_output, compressed, found, iso2d_output, netcdf_output, &
-                netcdf_0, netcdf_1
-
-    REAL ::  dx, simulated_time
+                netcdf_parallel, netcdf_0, netcdf_1
+
+    REAL ::  cpu_start_time, cpu_end_time, dx, simulated_time
     REAL, DIMENSION(:),   ALLOCATABLE   ::  eta, ho, hu
     REAL, DIMENSION(:,:), ALLOCATABLE   ::  pf, pf_tmp
@@ -162,4 +138,16 @@
        DO  WHILE ( modus == 'XY'  .OR.  modus == 'XZ'  .OR.  modus == 'YZ' )
 !
+!--       Take current time
+#if defined( __lc ) || defined( __decalpha ) || defined( __nec )
+          CALL SYSTEM_CLOCK( count, count_rate )
+          cpu_start_time = REAL( count ) / REAL( count_rate )
+#elif defined( __ibm )
+          cpu_start_time = IRTC( ) * 1E-9
+#else
+          PRINT*,  '+++ INFORMATIVE: no time measurement defined on this host'
+#endif
+
+          netcdf_parallel = .FALSE.
+!
 !--       Check, if file from PE0 exists. If it does not exist, PALM did not
 !--       create any output for this cross-section.
@@ -202,4 +190,14 @@
           IF ( netcdf_0  .OR.  netcdf_1 )  THEN
              netcdf_output = .TRUE.
+!
+!--          Inquire whether the NetCDF file is already complete (parallel
+!--          output)
+             INQUIRE( FILE='NO_COMBINE_PLOT_FIELDS_'//modus, &
+                      EXIST=netcdf_parallel )
+             IF ( netcdf_parallel )  THEN
+                netcdf_parallel = .TRUE.
+             ELSE
+                netcdf_parallel = .FALSE.
+             ENDIF
           ELSE
              netcdf_output = .FALSE.
@@ -211,5 +209,12 @@
           PRINT*, '*** combine_plot_fields ***'
 #if defined( __netcdf )
-          IF ( netcdf_output )  PRINT*, '    NetCDF output enabled'
+          IF ( netcdf_output )  THEN
+             IF ( netcdf_parallel )  THEN
+             PRINT*, '    NetCDF ' // modus // '-data are in one file ', &
+                          '(NetCDF4-format) - merging not neccessary'
+             ELSE
+                PRINT*, '    NetCDF output enabled'
+             ENDIF 
+          ENDIF
 #else
           IF ( netcdf_output )  THEN
@@ -218,11 +223,14 @@
           ENDIF
 #endif
-          IF ( danz /= 0 )  THEN
-             PRINT*, '    ',modus,'-section:  ', danz, ' file(s) found'
-          ELSE
-             PRINT*, '    no ', modus, '-section data available'
-          ENDIF
-
-          IF ( netcdf_output  .AND.  danz /= 0 )  THEN
+          IF ( .NOT. netcdf_parallel )  THEN
+             IF ( danz /= 0 )  THEN
+                PRINT*, '    ',modus,'-section:  ', danz, ' file(s) found'
+             ELSE
+                PRINT*, '    no ', modus, '-section data available'
+             ENDIF
+          ENDIF
+
+          IF ( netcdf_output  .AND. .NOT. netcdf_parallel  .AND.  danz /= 0 ) &
+          THEN
 #if defined( __netcdf )
              DO  av = 0, 1
@@ -312,130 +320,141 @@
 !
 !--       Read the arrays, as long as the end of the file is reached
-          fanz          =         0
-          current_level =         1
-          current_var   = 999999999
-
-          DO  WHILE ( danz /= 0 )
-
-!
-!--          Loop over all files (reading data of the subdomains)
-             DO  id = 0, danz-1
-!
-!--             File from PE0 contains special information at the beginning,
-!--             concerning the lower and upper indices of the total-domain used
-!--             in PALM (nxag, nxeg, nyag, nyeg) and the lower and upper indices
-!--             of the array to be writte by this routine (nxa, nxe, nya,
-!--             nye). Usually in the horizontal directions nxag=-1 and nxa=0
-!--             while all other variables have the same value (i.e. nxeg=nxe).
-!--             Allocate necessary arrays, open the output file and write
-!--             the coordinate informations needed by ISO2D.
-                IF ( id == 0  .AND.  fanz(0) == 0  .AND.  fanz(1) == 0 )  THEN
-                   READ ( id+110 )  nxag, nxeg, nyag, nyeg
-                   READ ( id+110 )  nxa, nxe, nya, nye
-                   ALLOCATE ( eta(nya:nye), ho(nxa:nxe), hu(nxa:nxe), &
-                        pf(nxag:nxeg,nyag:nyeg) )
-                   READ ( id+110 )  dx, eta, hu, ho
-
-                   IF ( iso2d_output )  THEN
-                      OPEN ( 2, FILE='PLOT2D_'//modus//TRIM( model_string ), &
-                           FORM='UNFORMATTED' )
-                      WRITE ( 2 )  dx, eta, hu, ho
+          IF ( .NOT. netcdf_parallel )  THEN
+
+             fanz          =         0
+             current_level =         1
+             current_var   = 999999999
+
+             DO  WHILE ( danz /= 0 )
+
+!
+!--             Loop over all files (reading data of the subdomains)
+                DO  id = 0, danz-1
+!
+!--                File from PE0 contains special information at the beginning,
+!--                concerning the lower and upper indices of the total-domain
+!--                used in PALM (nxag, nxeg, nyag, nyeg) and the lower and
+!--                upper indices of the array to be writte by this routine
+!--                (nxa, nxe, nya, nye). Usually in the horizontal directions
+!--                nxag=-1 and nxa=0 while all other variables have the same
+!--                value (i.e. nxeg=nxe).
+!--                Allocate necessary arrays, open the output file and write
+!--                the coordinate informations needed by ISO2D.
+                   IF ( id == 0  .AND.  fanz(0) == 0  .AND.  fanz(1) == 0 ) THEN
+                      READ ( id+110 )  nxag, nxeg, nyag, nyeg
+                      READ ( id+110 )  nxa, nxe, nya, nye
+                      ALLOCATE ( eta(nya:nye), ho(nxa:nxe), hu(nxa:nxe), &
+                                 pf(nxag:nxeg,nyag:nyeg) )
+                      READ ( id+110 )  dx, eta, hu, ho
+
+                      IF ( iso2d_output )  THEN
+                         OPEN ( 2, FILE='PLOT2D_'//modus//TRIM( model_string ),&
+                                   FORM='UNFORMATTED' )
+                         WRITE ( 2 )  dx, eta, hu, ho
+                      ENDIF
                    ENDIF
-                ENDIF
-!
-!--             Read output time
-                IF ( netcdf_output  .AND.  id == 0 )  THEN
-                   IF ( netcdf_1 )  THEN
-                      READ ( id+110, END=998 )  simulated_time, time_step, av
-                   ELSE
-!
-!--                   For compatibility with earlier PALM versions
-                      READ ( id+110, END=998 )  simulated_time, time_step
-                      av = 0
+!
+!--                Read output time
+                   IF ( netcdf_output  .AND.  id == 0 )  THEN
+                      IF ( netcdf_1 )  THEN
+                         READ ( id+110, END=998 )  simulated_time, time_step, av
+                      ELSE
+!
+!--                      For compatibility with earlier PALM versions
+                         READ ( id+110, END=998 )  simulated_time, time_step
+                         av = 0
+                      ENDIF
                    ENDIF
-                ENDIF
-!
-!--             Read subdomain indices
-                READ ( id+110, END=998 )  xa, xe, ya, ye
-!
-!--             IF the PE made no output (in case that no part of the
-!--             cross-section is situated on this PE), indices have the
-!--             value -1
-                IF ( .NOT. ( xa == -1  .AND.  xe == -1  .AND. &
-                             ya == -1  .AND.  ye == -1 ) )  THEN
-!
-!--                Read the subdomain grid-point values
-                   ALLOCATE( pf_tmp(xa:xe,ya:ye) )
-                   READ ( id+110 )  pf_tmp
-                   pf(xa:xe,ya:ye) = pf_tmp
-                   DEALLOCATE( pf_tmp )
-                ENDIF
-                IF ( id == 0 )  fanz(av) = fanz(av) + 1
-
-             ENDDO
-!
-!--          Write the data of the total domain cross-section
-             IF ( iso2d_output )  WRITE ( 2 )  pf(nxa:nxe,nya:nye)
+!
+!--                Read subdomain indices
+                   READ ( id+110, END=998 )  xa, xe, ya, ye
+!
+!--                IF the PE made no output (in case that no part of the
+!--                cross-section is situated on this PE), indices have the
+!--                value -1
+                   IF ( .NOT. ( xa == -1  .AND.  xe == -1  .AND. &
+                                ya == -1  .AND.  ye == -1 ) )  THEN
+!
+!--                   Read the subdomain grid-point values
+                      ALLOCATE( pf_tmp(xa:xe,ya:ye) )
+                      READ ( id+110 )  pf_tmp
+                      pf(xa:xe,ya:ye) = pf_tmp
+                      DEALLOCATE( pf_tmp )
+                   ENDIF
+                   IF ( id == 0 )  fanz(av) = fanz(av) + 1
+
+                ENDDO
+!
+!--             Write the data of the total domain cross-section
+                IF ( iso2d_output )  WRITE ( 2 )  pf(nxa:nxe,nya:nye)
        
 !
-!--          Write same data in NetCDF format
-             IF ( netcdf_output )  THEN
-#if defined( __netcdf )
-!
-!--             Check if a new time step has begun; if yes write data to time 
-!--             axis
-                IF ( current_var(av) > num_var(av) )  THEN
-                   current_var(av) = 1
-                   nc_stat = NF90_PUT_VAR( id_set(av), id_var_time(av), &
-                        (/ simulated_time /),        &
-                        start = (/ time_step /),     &
-                        count = (/ 1 /) )
-                   IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 7 )
-                ENDIF
-
-!
-!--             Now write the data; this is mode dependent
-                SELECT CASE ( modus )
-
-                   CASE ( 'XY' )
-                      nc_stat = NF90_PUT_VAR( id_set(av),                      &
+!--             Write same data in NetCDF format
+                IF ( netcdf_output )  THEN
+#if defined( __netcdf )
+!
+!--                Check if a new time step has begun; if yes write data to
+!--                time axis
+                   IF ( current_var(av) > num_var(av) )  THEN
+                      current_var(av) = 1
+                      nc_stat = NF90_PUT_VAR( id_set(av), id_var_time(av), &
+                                              (/ simulated_time /),        &
+                                              start = (/ time_step /),     &
+                                              count = (/ 1 /) )
+                      IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 7 )
+                   ENDIF
+
+!
+!--                Now write the data; this is mode dependent
+                   SELECT CASE ( modus )
+
+                      CASE ( 'XY' )
+                         nc_stat = NF90_PUT_VAR( id_set(av),                   &
                                            id_var(av,current_var(av)),         &
                                            pf(nxa:nxe,nya:nye),                &
                              start = (/ 1, 1, current_level(av), time_step /), &
                                       count = (/ nxe-nxa+1, nye-nya+1, 1, 1 /) )
-                      IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 8)
+                         IF ( nc_stat /= NF90_NOERR )  THEN
+                            CALL handle_netcdf_error( 8 )
+                         ENDIF
                   
-                   CASE ( 'XZ' )
-                      nc_stat = NF90_PUT_VAR( id_set(av),                      &
+                      CASE ( 'XZ' )
+                         nc_stat = NF90_PUT_VAR( id_set(av),                   &
                                            id_var(av,current_var(av)),         &
                                            pf(nxa:nxe,nya:nye),                &
                              start = (/ 1, current_level(av), 1, time_step /), &
                                       count = (/ nxe-nxa+1, 1, nye-nya+1, 1 /) )
-                      IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 9)
-
-                   CASE ( 'YZ' )
-                      nc_stat = NF90_PUT_VAR( id_set(av),                      &
+                         IF ( nc_stat /= NF90_NOERR )  THEN
+                            CALL handle_netcdf_error( 9 )
+                         ENDIF
+
+                      CASE ( 'YZ' )
+                         nc_stat = NF90_PUT_VAR( id_set(av),                   &
                                            id_var(av,current_var(av)),         &
                                            pf(nxa:nxe,nya:nye),                &
                              start = (/ current_level(av), 1, 1, time_step /), &
                                       count = (/ 1, nxe-nxa+1, nye-nya+1, 1 /) )
-                      IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error(10)
-
-                END SELECT
-
-!
-!--             Data is written, check if max level is reached
-                current_level(av) = current_level(av) + 1
-                IF ( current_level(av) > levels(av,current_var(av)) )  THEN
-                   current_level(av) = 1
-                   current_var(av)   = current_var(av) + 1
+                         IF ( nc_stat /= NF90_NOERR )  THEN
+                            CALL handle_netcdf_error( 10 )
+                         ENDIF
+
+                   END SELECT
+
+!
+!--                Data is written, check if max level is reached
+                   current_level(av) = current_level(av) + 1
+                   IF ( current_level(av) > levels(av,current_var(av)) )  THEN
+                      current_level(av) = 1
+                      current_var(av)   = current_var(av) + 1
+                   ENDIF
+
+#endif
                 ENDIF
 
-#endif
-             ENDIF
-
-          ENDDO
-
-998       IF ( danz /= 0 )  THEN
+             ENDDO
+
+          ENDIF
+
+998       IF ( danz /= 0  .AND.  .NOT. netcdf_parallel )  THEN
 !
 !--          Print the number of the arrays processed
@@ -452,18 +471,35 @@
              CLOSE ( 2 )
              DEALLOCATE ( eta, ho, hu, pf )
-          ENDIF
-
-!
-!--       Close the NetCDF file
-          IF ( netcdf_output  .AND.  danz /= 0 )  THEN
-#if defined( __netcdf )
-             IF ( netcdf_0 )  THEN
-                nc_stat = NF90_CLOSE( id_set(0) )
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 11 )
+
+!
+!--          Close the NetCDF file
+             IF ( netcdf_output )  THEN
+#if defined( __netcdf )
+                IF ( netcdf_0 )  THEN
+                   nc_stat = NF90_CLOSE( id_set(0) )
+                   IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 11 )
+                ENDIF
+                IF ( netcdf_1 )  THEN
+                   nc_stat = NF90_CLOSE( id_set(1) )
+                   IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 12 )
+                ENDIF
+#endif
              ENDIF
-             IF ( netcdf_1 )  THEN
-                nc_stat = NF90_CLOSE( id_set(1) )
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 12 )
-             ENDIF
+          ENDIF
+
+!
+!--       Output required cpu time
+          IF ( danz /= 0  .AND.  .NOT. netcdf_parallel )  THEN
+#if defined( __lc ) || defined( __decalpha ) || defined( __nec )
+             CALL SYSTEM_CLOCK( count, count_rate )
+             cpu_end_time = REAL( count ) / REAL( count_rate )
+             WRITE (*,'(5X,A,F9.3,A)')  'Required cpu-time: ', &
+                                        cpu_end_time-cpu_start_time, ' sec'
+#elif defined( __ibm )
+             cpu_end_time = IRTC( ) * 1E-9
+             WRITE (*,'(5X,A,F9.3,A)')  'Required cpu-time: ', &
+                                        cpu_end_time-cpu_start_time, ' sec'
+#else
+             CONTINUE
 #endif
           ENDIF
@@ -485,4 +521,21 @@
 !
 !--    Combine the 3D-arrays
+       netcdf_parallel = .FALSE.
+
+!
+!--    Info-output
+       PRINT*, ' '
+       PRINT*, '*** combine_plot_fields ***'
+
+!
+!--    Take current time
+#if defined( __lc ) || defined( __decalpha ) || defined( __nec )
+       CALL SYSTEM_CLOCK( count, count_rate )
+       cpu_start_time = REAL( count ) / REAL( count_rate )
+#elif defined( __ibm )
+       cpu_start_time = IRTC( ) * 1E-9
+#else
+       PRINT*,  '+++ INFORMATIVE: no time measurement defined on this host'
+#endif
 
 !
@@ -500,4 +553,12 @@
        IF ( netcdf_0  .OR.  netcdf_1 )  THEN
           netcdf_output = .TRUE.
+!
+!--       Inquire whether the NetCDF file is already complete (parallel output)
+          INQUIRE( FILE='NO_COMBINE_PLOT_FIELDS_3D', EXIST=netcdf_parallel )
+          IF ( netcdf_parallel )  THEN
+             netcdf_parallel = .TRUE.
+          ELSE
+             netcdf_parallel = .FALSE.
+          ENDIF
        ELSE
           netcdf_output = .FALSE.
@@ -505,10 +566,15 @@
 
 !
-!--    Check, if file from PE0 exists
-       danz = 0
-       WRITE (id_string,'(I4.4)')  danz
-       INQUIRE ( &
-            FILE='PLOT3D_DATA'//TRIM( model_string )//'_'//TRIM( id_string ),  &
-            EXIST=found )
+!--    Check, if file from PE0 exists; not neccessary in case of parallel
+!--    PALM output
+       IF ( .NOT. netcdf_parallel )  THEN
+          danz = 0
+          WRITE (id_string,'(I4.4)')  danz
+          INQUIRE ( &
+               FILE='PLOT3D_DATA'//TRIM( model_string )//'_'//TRIM( id_string ),  &
+               EXIST=found )
+       ELSE
+          found = .FALSE.
+       ENDIF
 
 !
@@ -533,10 +599,13 @@
        ENDDO
 
-!
-!--    Info-output
-       PRINT*, ' '
-       PRINT*, '*** combine_plot_fields ***'
-#if defined( __netcdf )
-       IF ( netcdf_output )  PRINT*, '    NetCDF output enabled'
+#if defined( __netcdf )
+       IF ( netcdf_output )  THEN
+          IF ( netcdf_parallel )  THEN
+             PRINT*, '    NetCDF data are in one file (NetCDF4-format)', &
+                          ' - merging not neccessary'
+          ELSE
+             PRINT*, '    NetCDF output enabled'
+          ENDIF
+       ENDIF
 #else
        IF ( netcdf_output )  THEN
@@ -545,15 +614,17 @@
        ENDIF
 #endif
-       IF ( danz /= 0 )  THEN
-          PRINT*, '    3D-data:     ', danz, ' file(s) found'
-       ELSE
-          IF ( found .AND. compressed )  THEN
-             PRINT*, '+++ no 3D-data processing, since data are compressed'
+       IF ( .NOT. netcdf_parallel )  THEN
+          IF ( danz /= 0 )  THEN
+             PRINT*, '    3D-data:     ', danz, ' file(s) found'
           ELSE
-             PRINT*, '    no 3D-data file available'
-          ENDIF
-       ENDIF
-
-       IF ( netcdf_output  .AND.  danz /= 0 )  THEN
+             IF ( found .AND. compressed )  THEN
+                PRINT*, '+++ no 3D-data processing, since data are compressed'
+             ELSE
+                PRINT*, '    no 3D-data file available'
+             ENDIF
+          ENDIF
+       ENDIF
+
+       IF ( netcdf_output  .AND. .NOT. netcdf_parallel  .AND.  danz /= 0 )  THEN
 #if defined( __netcdf )
           DO  av = 0, 1
@@ -623,100 +694,105 @@
 !
 !--    Read arrays, until the end of the file is reached
-       current_var = 999999999
-       fanz = 0
-       DO  WHILE ( danz /= 0 )
-
-!
-!--       Loop over all files
-          DO  id = 0, danz-1
-!
-!--          File from PE0 contains special information at the beginning,
-!--          concerning the lower and upper indices of the total-domain used in
-!--          PALM (nxag, nxeg, nyag, nyeg, nzag, nzeg) and the lower and upper
-!--          indices of the array to be written by this routine (nxa, nxe, nya,
-!--          nye, nza, nze). Usually nxag=-1 and nxa=0, nyag=-1 and nya=0,
-!--          nzeg=nz and nze=nz_plot3d.
-!--          Allocate necessary array and open the output file.
-             IF ( id == 0  .AND.  fanz(0) == 0  .AND.  fanz(1) == 0 )  THEN
-                READ ( id+110 )  nxag, nxeg, nyag, nyeg, nzag, nzeg
-                READ ( id+110 )  nxa, nxe, nya, nye, nza, nze
-                ALLOCATE ( pf3d(nxa:nxe,nya:nye,nza:nze) )
-                IF ( avs_output )  THEN
-                   OPEN ( 2, FILE='PLOT3D_DATA'//TRIM( model_string ), &
-                        FORM='UNFORMATTED' )
+       IF ( .NOT. netcdf_parallel )  THEN
+
+          current_var = 999999999
+          fanz = 0
+          DO  WHILE ( danz /= 0 )
+
+!
+!--          Loop over all files
+             DO  id = 0, danz-1
+!
+!--             File from PE0 contains special information at the beginning,
+!--             concerning the lower and upper indices of the total-domain used
+!--             in PALM (nxag, nxeg, nyag, nyeg, nzag, nzeg) and the lower and
+!--             upper indices of the array to be written by this routine (nxa,
+!--             nxe, nya, nye, nza, nze). Usually nxag=-1 and nxa=0, nyag=-1
+!--             and nya=0, nzeg=nz and nze=nz_plot3d.
+!--             Allocate necessary array and open the output file.
+                IF ( id == 0  .AND.  fanz(0) == 0  .AND.  fanz(1) == 0 )  THEN
+                   READ ( id+110 )  nxag, nxeg, nyag, nyeg, nzag, nzeg
+                   READ ( id+110 )  nxa, nxe, nya, nye, nza, nze
+                   ALLOCATE ( pf3d(nxa:nxe,nya:nye,nza:nze) )
+                   IF ( avs_output )  THEN
+                      OPEN ( 2, FILE='PLOT3D_DATA'//TRIM( model_string ), &
+                             FORM='UNFORMATTED' )
+                   ENDIF
                 ENDIF
-             ENDIF
-
-!
-!--          Read output time
-             IF ( netcdf_output  .AND.  id == 0 )  THEN
-                IF ( netcdf_1 )  THEN
-                   READ ( id+110, END=999 )  simulated_time, time_step, av
-                ELSE
-!
-!--                For compatibility with earlier PALM versions
-                   READ ( id+110, END=999 )  simulated_time, time_step
-                   av = 0
+
+!
+!--             Read output time
+                IF ( netcdf_output  .AND.  id == 0 )  THEN
+                   IF ( netcdf_1 )  THEN
+                      READ ( id+110, END=999 )  simulated_time, time_step, av
+                   ELSE
+!
+!--                   For compatibility with earlier PALM versions
+                      READ ( id+110, END=999 )  simulated_time, time_step
+                      av = 0
+                   ENDIF
                 ENDIF
-             ENDIF
-
-!
-!--          Read subdomain indices and grid point values
-             READ ( id+110, END=999 )  xa, xe, ya, ye, za, ze
-             ALLOCATE( pf3d_tmp(xa:xe,ya:ye,za:ze) )
-             READ ( id+110 )  pf3d_tmp
-
-             xxa = MAX( nxa, xa )
-             xxe = MIN( nxe, xe )
-             yya = MAX( nya, ya )
-             yye = MIN( nye, ye )
-             zza = MAX( nza, za )
-             zze = MIN( nze, ze )
-             DO  k = zza, zze
-                DO  j = yya, yye
-                   DO  i = xxa, xxe
-                      pf3d(i,j,k) = pf3d_tmp(i,j,k)
+
+!
+!--             Read subdomain indices and grid point values
+                READ ( id+110, END=999 )  xa, xe, ya, ye, za, ze
+                ALLOCATE( pf3d_tmp(xa:xe,ya:ye,za:ze) )
+                READ ( id+110 )  pf3d_tmp
+
+                xxa = MAX( nxa, xa )
+                xxe = MIN( nxe, xe )
+                yya = MAX( nya, ya )
+                yye = MIN( nye, ye )
+                zza = MAX( nza, za )
+                zze = MIN( nze, ze )
+                DO  k = zza, zze
+                   DO  j = yya, yye
+                      DO  i = xxa, xxe
+                         pf3d(i,j,k) = pf3d_tmp(i,j,k)
+                      ENDDO
                    ENDDO
                 ENDDO
+
+                DEALLOCATE( pf3d_tmp )
+                IF ( id == 0 )  fanz(av) = fanz(av) + 1
+
              ENDDO
 
-             DEALLOCATE( pf3d_tmp )
-             IF ( id == 0 )  fanz(av) = fanz(av) + 1
+!
+!--          Write data of the total domain
+             IF ( avs_output )  WRITE ( 2 )  pf3d(nxa:nxe,nya:nye,nza:nze)
+       
+!
+!--          Write same data in NetCDF format
+             IF ( netcdf_output )  THEN
+#if defined( __netcdf )
+!
+!--             Check if a new time step has begun; if yes write data to time
+!--             axis
+                IF ( current_var(av) > num_var(av) )  THEN
+                   current_var(av) = 1
+                   nc_stat = NF90_PUT_VAR( id_set(av), id_var_time(av), &
+                                      (/ simulated_time /),&
+                                      start = (/ time_step /), count = (/ 1 /) )
+                   IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 17 )
+                ENDIF
+
+!
+!--             Now write the data
+                nc_stat = NF90_PUT_VAR( id_set(av), id_var(av,current_var(av)),&
+                                        pf3d, start = (/ 1, 1, 1, time_step /),&
+                              count = (/ nxe-nxa+1, nye-nya+1, nze-nza+1, 1 /) )
+                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 18 )
+
+                current_var(av) = current_var(av) + 1
+
+#endif
+             ENDIF
 
           ENDDO
 
-!
-!--       Write data of the total domain
-          IF ( avs_output )  WRITE ( 2 )  pf3d(nxa:nxe,nya:nye,nza:nze)
-       
-!
-!--       Write same data in NetCDF format
-          IF ( netcdf_output )  THEN
-#if defined( __netcdf )
-!
-!--          Check if a new time step has begun; if yes write data to time axis
-             IF ( current_var(av) > num_var(av) )  THEN
-                current_var(av) = 1
-                nc_stat = NF90_PUT_VAR( id_set(av), id_var_time(av), &
-                                     (/ simulated_time /),&
-                                     start = (/ time_step /), count = (/ 1 /) )
-                IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 17 )
-             ENDIF
-
-!
-!--          Now write the data
-             nc_stat = NF90_PUT_VAR( id_set(av), id_var(av,current_var(av)), &
-                                     pf3d, start = (/ 1, 1, 1, time_step /), &
-                              count = (/ nxe-nxa+1, nye-nya+1, nze-nza+1, 1 /) )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 18 )
-
-             current_var(av) = current_var(av) + 1
-
-#endif
-          ENDIF
-
-       ENDDO
-
-999    IF ( danz /= 0 )  THEN
+       ENDIF
+
+999    IF ( danz /= 0  .AND.  .NOT. netcdf_parallel )  THEN
 !
 !--       Print the number of arrays processed
@@ -746,4 +822,18 @@
 #endif
           ENDIF
+
+!
+!--       Output required cpu time
+#if defined( __lc ) || defined( __decalpha ) || defined( __nec )
+          CALL SYSTEM_CLOCK( count, count_rate )
+          cpu_end_time = REAL( count ) / REAL( count_rate )
+          WRITE (*,'(5X,A,F9.3,A)')  'Required cpu-time: ', &
+                                     cpu_end_time-cpu_start_time, ' sec'
+#elif defined( __ibm )
+          cpu_end_time = IRTC( ) * 1E-9
+          WRITE (*,'(5X,A,F9.3,A)')  'Required cpu-time: ', &
+                                     cpu_end_time-cpu_start_time, ' sec'
+#endif
+
        ENDIF
 
