Index: palm/trunk/SOURCE/data_output_profiles.f90
===================================================================
--- palm/trunk/SOURCE/data_output_profiles.f90	(revision 4901)
+++ palm/trunk/SOURCE/data_output_profiles.f90	(revision 1)
@@ -1,34 +1,68 @@
-!> @file data_output_profiles.f90
-!--------------------------------------------------------------------------------------------------!
-! This file is part of the PALM model system.
-!
-! PALM is free software: you can redistribute it and/or modify it under the terms of the GNU General
-! Public License as published by the Free Software Foundation, either version 3 of the License, or
-! (at your option) any later version.
-!
-! PALM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
-! implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
-! Public License for more details.
-!
-! You should have received a copy of the GNU General Public License along with PALM. If not, see
-! <http://www.gnu.org/licenses/>.
-!
-! Copyright 1997-2021 Leibniz Universitaet Hannover
-!--------------------------------------------------------------------------------------------------!
-!
-! Current revisions:
+ SUBROUTINE data_output_profiles
+
+!------------------------------------------------------------------------------!
+! Actual revisions:
 ! -----------------
 ! 
-! 
+!
 ! Former revisions:
 ! -----------------
-! $Id$
-! file re-formatted to follow the PALM coding standard
-!
-! 4360 2020-01-07 11:25:50Z suehring
-! Corrected "Former revisions" section
-!
-! 3655 2019-01-07 16:51:22Z knoop
-! add variable description
+! $Log: data_output_profiles.f90,v $
+! Revision 1.18  2006/08/16 14:27:04  raasch
+! PRINT* statements for testing removed
+!
+! Revision 1.17  2006/08/08 12:45:47  raasch
+! Immediate return in case of average_count_pr = 0.
+!
+! Revision 1.16  2006/02/23 10:26:53  raasch
+! Former routine plot_1d renamed data_output_profiles
+! pl.. renamed do.., .._anz renamed .._no
+! error number argument for handle_netcdf_error
+!
+! Revision 1.15  2005/05/18 15:44:44  raasch
+! Extensions for NetCDF output
+!
+! Revision 1.14  2001/03/30 07:44:12  raasch
+! Translation of remaining German identifiers (variables, subroutines, etc.)
+!
+! Revision 1.13  2001/03/02 14:21:17  letzel
+! All comments translated into English.
+!
+! Revision 1.12  2001/01/22 07:36:55  raasch
+! Module test_variables removed
+!
+! Revision 1.11  1998/07/06 12:25:36  raasch
+! + USE test_variables
+!
+! Revision 1.10  1998/04/15 11:22:02  raasch
+! zeitlich gemittelte Profile werden jetzt auch mit zeitlich gemittelten
+! Groessen normiert
+!
+! Revision 1.9  1998/04/06 14:33:53  raasch
+! Implementierung weiterer Normierungsmethoden
+!
+! Revision 1.8  1998/03/30 11:37:30  raasch
+! Erweiterungen fuer Gebietsstatistiken korrigiert
+!
+! Revision 1.7  1998/03/25 13:55:45  raasch
+! Erweiterungen fuer Gebietsstatistiken
+!
+! Revision 1.6  1998/03/09 16:24:04  raasch
+! Ueberpruefung der Normierungsfaktoren auf 0.0 und evtl.
+! Abschaltung der Normalisierung
+!
+! Revision 1.5  1998/03/03 07:58:11  raasch
+! Aufruf von flow_statistics erfolgt jetzt gegebenenfalls hier
+! Ausgabe von zeitlich gemittelten Profilen, Abspeichern von Normierungsgroessen
+!
+! Revision 1.4  1998/02/19 07:10:04  raasch
+! x-Wertebereichsermittelung nur bezueglich des auszugebenden Hoehenbereiches,
+! x-Wertebereichsermittelung auch fuer Anfangsprofile
+!
+! Revision 1.3  1998/02/04 16:09:11  raasch
+! x-Wertebereiche fuer die einzelnen Koordinatenkreuze ermitteln
+!
+! Revision 1.2  1997/09/16 06:38:20  raasch
+! style- und color-Indexberechnung korrigiert
 !
 ! Revision 1.1  1997/09/12 06:28:48  raasch
@@ -38,41 +72,22 @@
 ! Description:
 ! ------------
-!> Plot output of 1D-profiles for PROFIL
-!--------------------------------------------------------------------------------------------------!
- SUBROUTINE data_output_profiles
-
-
-    USE control_parameters,                                                                        &
-        ONLY:  average_count_pr, averaging_interval_pr, coupling_start_time,                       &
-               dopr_n, dopr_time_count, normalizing_region, time_since_reference_point
-
-    USE cpulog,                                                                                    &
-        ONLY:  cpu_log, log_point
-
-    USE indices,                                                                                   &
-        ONLY:  nzb, nzt
-
-    USE kinds
-
-#if defined( __netcdf )
-    USE NETCDF
-#endif
-
-    USE netcdf_interface,                                                                          &
-        ONLY:  id_set_pr, id_var_dopr, id_var_norm_dopr, id_var_time_pr, nc_stat,                  &
-               netcdf_handle_error, output_for_t0
-
+! Plot output of 1D-profiles for PROFIL
+!------------------------------------------------------------------------------!
+
+    USE control_parameters
+    USE cpulog
+    USE indices
+    USE interfaces
+    USE netcdf_control
     USE pegrid
-
     USE profil_parameter
-
-    USE statistics,                                                                                &
-        ONLY:  flow_statistics_called, hom, hom_sum, pr_palm, statistic_regions
+    USE statistics
 
     IMPLICIT NONE
 
 
-    INTEGER(iwp) ::  i  !< loop index
-    INTEGER(iwp) ::  sr !< statistic region index
+    INTEGER ::  i, id, ilc, ils, j, k, sr
+    REAL    ::  uxma, uxmi
+
 
 !
@@ -86,17 +101,18 @@
 !
 !-- If required, compute temporal average
-    IF ( averaging_interval_pr == 0.0_wp )  THEN
+    IF ( averaging_interval_pr == 0.0 )  THEN
        hom_sum(:,:,:) = hom(:,1,:,:)
     ELSE
        IF ( average_count_pr > 0 )  THEN
-          hom_sum = hom_sum / REAL( average_count_pr, KIND=wp )
+          hom_sum = hom_sum / REAL( average_count_pr )
        ELSE
 !
-!--       This case may happen if dt_dopr is changed in the runtime_parameters-list of a restart run
+!--       This case may happen if dt_dopr is changed in the d3par-list of
+!--       a restart run
           RETURN
        ENDIF
     ENDIF
 
-
+    
     IF ( myid == 0 )  THEN
 
@@ -106,5 +122,15 @@
 !
 !--    Open file for profile output in NetCDF format
-       CALL check_open( 104 )
+       IF ( netcdf_output )  THEN
+          CALL check_open( 104 )
+       ENDIF
+
+!
+!--    Open PROFIL-output files for each (sub-)region
+       IF ( profil_output )  THEN
+          DO  sr = 0, statistic_regions
+             CALL check_open( 40 + sr )
+          ENDDO
+       ENDIF
 
 !
@@ -113,152 +139,306 @@
 
 !
+!--    Re-set to zero the counter for the number of profiles already written
+!--    at the current output time into the respective crosses
+       cross_pnc_local = 0
+
+!
 !--    Output of initial profiles
        IF ( dopr_time_count == 1 )  THEN
 
-          IF ( .NOT. output_for_t0 ) THEN
-
+          IF ( netcdf_output )  THEN
 #if defined( __netcdf )
 !
-!--          Store initial time to time axis, but only if an output is required for at least one of
-!--          the profiles. The initial time is either 0, or, in case of a prerun for coupled
-!--          atmosphere-ocean runs, has a negative value
-             DO  i = 1, dopr_n
-                IF ( dopr_initial_index(i) /= 0 )  THEN
-                   nc_stat = NF90_PUT_VAR( id_set_pr, id_var_time_pr,                              &
-                                           (/ -coupling_start_time /),                             &
-                                           start = (/ 1 /), count = (/ 1 /) )
-                   CALL netcdf_handle_error( 'data_output_profiles', 329 )
-                   output_for_t0 = .TRUE.
-                   EXIT
-                ENDIF
-             ENDDO
+!--          Store initial time (t=0) to time axis          
+             nc_stat = NF90_PUT_VAR( id_set_pr, id_var_time_pr, (/ 0.0 /), &
+                                     start = (/ 1 /), count = (/ 1 /) )
+             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 329 )
 
 !
 !--          Store normalization factors
-             nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(1), & ! wpt0
-                                     (/ hom_sum(nzb,18,normalizing_region) /),                     &
-                                     start = (/ 1 /), count = (/ 1 /) )
-             CALL netcdf_handle_error( 'data_output_profiles', 330 )
-
-             nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(2), & ! ws2
-                                     (/ hom_sum(nzb+8,pr_palm,normalizing_region)**2 /),           &
-                                     start = (/ 1 /), count = (/ 1 /) )
-             CALL netcdf_handle_error( 'data_output_profiles', 331 )
-             nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(3), & ! tsw2
-                                     (/ hom_sum(nzb+3,pr_palm,normalizing_region)**2 /),           &
-                                      start = (/ 1 /), count = (/ 1 /) )
-             CALL netcdf_handle_error( 'data_output_profiles', 332 )
-             nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(4), & ! ws3
-                                     (/ hom_sum(nzb+8,pr_palm,normalizing_region)**3 /),           &
-                                     start = (/ 1 /), count = (/ 1 /) )
-             CALL netcdf_handle_error( 'data_output_profiles', 333 )
-
-             nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(5), & ! ws2tsw
-                                     (/ hom_sum(nzb+8,pr_palm,normalizing_region)**3 *             &
-                                        hom_sum(nzb+3,pr_palm,normalizing_region)    /),           &
-                                     start = (/ 1 /), count = (/ 1 /) )
-             CALL netcdf_handle_error( 'data_output_profiles', 334 )
-
-             nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(6), & ! wstsw2
-                                     (/ hom_sum(nzb+8,pr_palm,normalizing_region) *                &
-                                        hom_sum(nzb+3,pr_palm,normalizing_region)**2 /),           &
-                                     start = (/ 1 /), count = (/ 1 /) )
-             CALL netcdf_handle_error( 'data_output_profiles', 335 )
-
-             nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(7), & ! z_i
-                                     (/ hom_sum(nzb+6,pr_palm,normalizing_region) /),              &
-                                     start = (/ 1 /), count = (/ 1 /) )
-             CALL netcdf_handle_error( 'data_output_profiles', 336 )
-
+             nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(1), &  ! wpt0
+                                  (/ hom_sum(nzb,18,normalizing_region) /), &
+                                     start = (/ 1 /), count = (/ 1 /) )
+             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 330 )
+
+             nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(2), &  ! ws2
+                        (/ hom_sum(nzb+8,var_hom,normalizing_region)**2 /), &
+                                     start = (/ 1 /), count = (/ 1 /) )
+             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 331 )
+
+             nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(3), &  ! tsw2
+                        (/ hom_sum(nzb+3,var_hom,normalizing_region)**2 /), &
+                                     start = (/ 1 /), count = (/ 1 /) )
+             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 332 )
+
+             nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(4), &  ! ws3
+                        (/ hom_sum(nzb+8,var_hom,normalizing_region)**3 /), &
+                                     start = (/ 1 /), count = (/ 1 /) )
+             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 333 )
+
+             nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(5), &  ! ws2tsw
+                        (/ hom_sum(nzb+8,var_hom,normalizing_region)**3 *   &
+                           hom_sum(nzb+3,var_hom,normalizing_region)    /), &
+                                     start = (/ 1 /), count = (/ 1 /) )
+             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 334 )
+
+             nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(6), &  ! wstsw2
+                        (/ hom_sum(nzb+8,var_hom,normalizing_region) *      &
+                           hom_sum(nzb+3,var_hom,normalizing_region)**2 /), &
+                                     start = (/ 1 /), count = (/ 1 /) )
+             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 335 )
+
+             nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(7), &  ! z_i
+                           (/ hom_sum(nzb+6,var_hom,normalizing_region) /), &
+                                     start = (/ 1 /), count = (/ 1 /) )
+             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 336 )
 #endif
-!
-!--          Loop over all 1D variables
-             DO  i = 1, dopr_n
-
-                IF ( dopr_initial_index(i) /= 0 )  THEN
-
-!
-!--                Output for the individual (sub-)regions
-                   DO  sr = 0, statistic_regions
-
+          ENDIF
+!
+!--       Loop over all 1D variables
+          DO  i = 1, dopr_n
+
+             IF ( dopr_initial_index(i) /= 0 )  THEN
+
+!
+!--             Output for the individual (sub-)regions
+                DO  sr = 0, statistic_regions
+
+                   IF ( profil_output )  THEN
+                      id = 40 + sr
+!
+!--                   Write Label-Header
+                      WRITE ( id, 100 )  TRIM( data_output_pr(i) ), '(t=0)'
+!
+!--                   Write total profile
+                      DO  k = nzb, nzt+1
+                         WRITE ( id, 101 )  hom(k,2,dopr_initial_index(i),sr), &
+                                            hom(k,1,dopr_initial_index(i),sr)
+                      ENDDO
+!
+!--                   Write separation label
+                      WRITE ( id, 102 )
+                   ENDIF
+
+                   IF ( netcdf_output )  THEN
 #if defined( __netcdf )
 !
 !--                   Write data to netcdf file
-                      nc_stat = NF90_PUT_VAR( id_set_pr, id_var_dopr(i,sr),                        &
-                                              hom(nzb:nzt+1,1,dopr_initial_index(i),sr),           &
-                                              start = (/ 1, 1 /),                                  &
+                      nc_stat = NF90_PUT_VAR( id_set_pr, id_var_dopr(i,sr),    &
+                                    hom(nzb:nzt+1,1,dopr_initial_index(i),sr), &
+                                              start = (/ 1, 1 /),              &
                                               count = (/ nzt-nzb+2, 1 /) )
-                      CALL netcdf_handle_error( 'data_output_profiles', 337 )
+                      IF ( nc_stat /= NF90_NOERR )  &
+                                                CALL handle_netcdf_error( 337 )
 #endif
-
-                   ENDDO
-
-                ENDIF   ! Initial profile available
-
-             ENDDO   ! Loop over dopr_n for initial profiles
-
-             IF ( output_for_t0 )  THEN
-                dopr_time_count = dopr_time_count + 1
-             ENDIF
-
-          END IF
+                   ENDIF
+
+                ENDDO
+
+                IF ( profil_output )  THEN
+!
+!--                Determine indices for later NAMELIST-output (s. below)
+                   profile_number = profile_number + 1
+                   j = dopr_crossindex(i)
+                   IF ( j /= 0 )  THEN
+                      cross_profile_number_count(j) = &
+                                               cross_profile_number_count(j) + 1
+                      k = cross_profile_number_count(j)
+                      cross_profile_numbers(k,j) = profile_number
+!
+!--                   Initial profiles are always drawn as solid lines in 
+!--                   anti-background colour.
+                      cross_linecolors(k,j) = 1
+                      cross_linestyles(k,j) = 0
+!
+!--                   If required, extend x-value range of the respective
+!--                   cross, provided it has not been specified in &
+!--                   check_parameters. Determination over all (sub-)regions.
+                      IF ( cross_uxmin(j) == 0.0  .AND. &
+                           cross_uxmax(j) == 0.0 )  THEN
+
+                         DO  sr = 0, statistic_regions
+
+                            uxmi = &
+                            MINVAL( hom(:nz_do1d,1,dopr_initial_index(i),sr) )
+
+                            uxma = &
+                            MAXVAL( hom(:nz_do1d,1,dopr_initial_index(i),sr) )
+!
+!--                         When the value range of the first line in the
+!--                         corresponding cross is determined, its value range
+!--                         is simply adopted.
+                            IF ( cross_uxmin_computed(j) > &
+                                 cross_uxmax_computed(j) )  THEN
+                               cross_uxmin_computed(j) = uxmi
+                               cross_uxmax_computed(j) = uxma
+                            ELSE
+                               cross_uxmin_computed(j) = &
+                                            MIN( cross_uxmin_computed(j), uxmi )
+                               cross_uxmax_computed(j) = &
+                                            MAX( cross_uxmax_computed(j), uxma )
+                            ENDIF
+
+                         ENDDO
+
+                      ENDIF
+!
+!--                   If required, determine and note normalizing factors
+                      SELECT CASE ( cross_normalized_x(j) )
+
+                         CASE ( 'ts2' )
+                            cross_normx_factor(k,j) = &
+                             ( hom_sum(nzb+3,var_hom,normalizing_region) )**2
+                         CASE ( 'wpt0' )
+                            cross_normx_factor(k,j) = &
+                             hom_sum(nzb,18,normalizing_region)
+                         CASE ( 'wsts2' )
+                            cross_normx_factor(k,j) = &
+                             hom_sum(nzb+8,var_hom,normalizing_region)  &
+                           * ( hom_sum(nzb+3,var_hom,normalizing_region) )**2
+                         CASE ( 'ws2' )
+                            cross_normx_factor(k,j) = &
+                             ( hom_sum(nzb+8,var_hom,normalizing_region) )**2
+                         CASE ( 'ws2ts' )
+                            cross_normx_factor(k,j) = &
+                           ( hom_sum(nzb+8,var_hom,normalizing_region) )**2 &
+                           * hom_sum(nzb+3,var_hom,normalizing_region)
+                         CASE ( 'ws3' )
+                            cross_normx_factor(k,j) = &
+                             ( hom_sum(nzb+8,var_hom,normalizing_region) )**3
+
+                      END SELECT
+
+                      SELECT CASE ( cross_normalized_y(j) )
+
+                         CASE ( 'z_i' )
+                            cross_normy_factor(k,j) = &
+                                    hom_sum(nzb+6,var_hom,normalizing_region)
+
+                      END SELECT
+
+!
+!--                   Check the normalizing factors for zeros and deactivate
+!--                   the normalization, if required.
+                      IF ( cross_normx_factor(k,j) == 0.0  .OR. &
+                           cross_normy_factor(k,j) == 0.0 )  THEN
+                         PRINT*,'+++ WARNING data_output_profiles: normalizi', &
+                                'ng cross ',j, ' is not possible since one o', &
+                                'f the'
+                         PRINT*,'                     normalizing factors is ',&
+                                'zero!'
+                         PRINT*,'    cross_normx_factor(',k,',',j,') = ', &
+                                cross_normx_factor(k,j)
+                         PRINT*,'    cross_normy_factor(',k,',',j,') = ', &
+                                cross_normy_factor(k,j)
+                         cross_normx_factor(k,j) = 1.0
+                         cross_normy_factor(k,j) = 1.0
+                         cross_normalized_x(j) = ' '
+                         cross_normalized_y(j) = ' '
+                      ENDIF
+
+!
+!--                   If required, extend normalized x-value range of the
+!--                   respective cross, provided it has not been specified in
+!--                   check_parameters. Determination over all (sub-)regions.
+                      IF ( cross_uxmin_normalized(j) == 0.0  .AND. &
+                           cross_uxmax_normalized(j) == 0.0 )  THEN
+
+                         DO  sr = 0, statistic_regions
+
+                            uxmi = MINVAL( hom(:nz_do1d,1,             &
+                                           dopr_initial_index(i),sr) ) / &
+                                   cross_normx_factor(k,j)
+                            uxma = MAXVAL( hom(:nz_do1d,1,             &
+                                           dopr_initial_index(i),sr) ) / &
+                                   cross_normx_factor(k,j)
+!
+!--                         When the value range of the first line in the
+!--                         corresponding cross is determined, its value range
+!--                         is simply adopted.
+                            IF ( cross_uxmin_normalized_computed(j) > &
+                                 cross_uxmax_normalized_computed(j) )  THEN
+                               cross_uxmin_normalized_computed(j) = uxmi
+                               cross_uxmax_normalized_computed(j) = uxma
+                            ELSE
+                               cross_uxmin_normalized_computed(j) = &
+                                 MIN( cross_uxmin_normalized_computed(j), uxmi )
+                               cross_uxmax_normalized_computed(j) = &
+                                 MAX( cross_uxmax_normalized_computed(j), uxma )
+                            ENDIF
+
+                         ENDDO
+
+                      ENDIF
+
+                   ENDIF   ! Index determination
+
+                ENDIF   ! profil output
+
+             ENDIF   ! Initial profile available
+
+          ENDDO   ! Loop over dopr_n for initial profiles
+
+          IF ( netcdf_output )  dopr_time_count = dopr_time_count + 1
+
        ENDIF   ! Initial profiles
 
+       IF ( netcdf_output )  THEN
 #if defined( __netcdf )
-
-!
-!--    Store time to time axis
-       nc_stat = NF90_PUT_VAR( id_set_pr, id_var_time_pr,                                          &
-                               (/ time_since_reference_point /),                                   &
-                               start = (/ dopr_time_count /),                                      &
-                               count = (/ 1 /) )
-       CALL netcdf_handle_error( 'data_output_profiles', 338 )
-
-!
-!--    Store normalization factors
-       nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(1), &  ! wpt0
-                               (/ hom_sum(nzb,18,normalizing_region) /),                           &
-                               start = (/ dopr_time_count /),                                      &
-                               count = (/ 1 /) )
-       CALL netcdf_handle_error( 'data_output_profiles', 339 )
-
-       nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(2), &  ! ws2
-                               (/ hom_sum(nzb+8,pr_palm,normalizing_region)**2 /),                 &
-                               start = (/ dopr_time_count /),                                      &
-                               count = (/ 1 /) )
-       CALL netcdf_handle_error( 'data_output_profiles', 340 )
-
-       nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(3), &  ! tsw2
-                               (/ hom_sum(nzb+3,pr_palm,normalizing_region)**2 /),                 &
-                               start = (/ dopr_time_count /),                                      &
-                               count = (/ 1 /) )
-       CALL netcdf_handle_error( 'data_output_profiles', 341 )
-
-       nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(4), &  ! ws3
-                               (/ hom_sum(nzb+8,pr_palm,normalizing_region)**3 /),                 &
-                               start = (/ dopr_time_count /),                                      &
-                               count = (/ 1 /) )
-       CALL netcdf_handle_error( 'data_output_profiles', 342 )
-
-       nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(5), &  ! ws2tsw
-                               (/ hom_sum(nzb+8,pr_palm,normalizing_region)**3 *                   &
-                                  hom_sum(nzb+3,pr_palm,normalizing_region) /),                    &
-                               start = (/ dopr_time_count /),               &
-                               count = (/ 1 /) )
-       CALL netcdf_handle_error( 'data_output_profiles', 343 )
-
-       nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(6), &  ! wstsw2
-                               (/ hom_sum(nzb+8,pr_palm,normalizing_region) *                      &
-                                  hom_sum(nzb+3,pr_palm,normalizing_region)**2 /),                 &
-                               start = (/ dopr_time_count /),                                      &
-                               count = (/ 1 /) )
-       CALL netcdf_handle_error( 'data_output_profiles', 344 )
-
-       nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(7), &  ! z_i
-                               (/ hom_sum(nzb+6,pr_palm,normalizing_region) /),                    &
-                               start = (/ dopr_time_count /),                                      &
-                               count = (/ 1 /) )
-       CALL netcdf_handle_error( 'data_output_profiles', 345 )
+!
+!--       Store time to time axis          
+          nc_stat = NF90_PUT_VAR( id_set_pr, id_var_time_pr,     &
+                                  (/ simulated_time /),          &
+                                  start = (/ dopr_time_count /), &
+                                  count = (/ 1 /) )
+          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 338 )
+
+!
+!--       Store normalization factors
+          nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(1), &  ! wpt0
+                                  (/ hom_sum(nzb,18,normalizing_region) /), &
+                                  start = (/ dopr_time_count /),               &
+                                  count = (/ 1 /) )
+          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 339 )
+
+          nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(2), &  ! ws2
+                        (/ hom_sum(nzb+8,var_hom,normalizing_region)**2 /), &
+                                  start = (/ dopr_time_count /),               &
+                                  count = (/ 1 /) )
+          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 340 )
+
+          nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(3), &  ! tsw2
+                        (/ hom_sum(nzb+3,var_hom,normalizing_region)**2 /), &
+                                  start = (/ dopr_time_count /),               &
+                                  count = (/ 1 /) )
+          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 341 )
+
+          nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(4), &  ! ws3
+                        (/ hom_sum(nzb+8,var_hom,normalizing_region)**3 /), &
+                                  start = (/ dopr_time_count /),               &
+                                  count = (/ 1 /) )
+          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 342 )
+
+          nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(5), &  ! ws2tsw
+                        (/ hom_sum(nzb+8,var_hom,normalizing_region)**3 *   &
+                           hom_sum(nzb+3,var_hom,normalizing_region)    /), &
+                                  start = (/ dopr_time_count /),               &
+                                  count = (/ 1 /) )
+          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 343 )
+
+          nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(6), &  ! wstsw2
+                        (/ hom_sum(nzb+8,var_hom,normalizing_region) *      &
+                           hom_sum(nzb+3,var_hom,normalizing_region)**2 /), &
+                                  start = (/ dopr_time_count /),               &
+                                  count = (/ 1 /) )
+          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 344 )
+
+          nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(7), &  ! z_i
+                           (/ hom_sum(nzb+6,var_hom,normalizing_region) /), &
+                                  start = (/ dopr_time_count /),               &
+                                  count = (/ 1 /) )
+          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 345 )
 #endif
+       ENDIF
 
 !
@@ -270,17 +450,171 @@
           DO  sr = 0, statistic_regions
 
+             IF ( profil_output )  THEN
+                id = 40 + sr
+!
+!--             Write Label-Header
+                WRITE ( id, 100 )  TRIM( dopr_label(i) ), simulated_time_chr
+!
+!--             Output of total profile
+                DO  k = nzb, nzt+1
+                   WRITE ( id, 101 )  hom(k,2,dopr_index(i),sr), &
+                                      hom_sum(k,dopr_index(i),sr)
+                ENDDO
+!
+!--             Write separation label
+                WRITE ( id, 102 )
+             ENDIF
+
+             IF ( netcdf_output )  THEN
 #if defined( __netcdf )
 !
-!--          Write data to netcdf file
-             nc_stat = NF90_PUT_VAR( id_set_pr, id_var_dopr(i,sr),                                 &
-                                     hom_sum(nzb:nzt+1,dopr_index(i),sr),                          &
-                                     start = (/ 1, dopr_time_count /),                             &
-                                     count = (/ nzt-nzb+2, 1 /) )
-             CALL netcdf_handle_error( 'data_output_profiles', 346 )
+!--             Write data to netcdf file
+                nc_stat = NF90_PUT_VAR( id_set_pr, id_var_dopr(i,sr),          &
+                                        hom_sum(nzb:nzt+1,dopr_index(i),sr),&
+                                        start = (/ 1, dopr_time_count /),      &
+                                        count = (/ nzt-nzb+2, 1 /) )
+                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 346 )
 #endif
+             ENDIF
 
           ENDDO
 
-       ENDDO
+          IF ( profil_output )  THEN
+!
+!--          Determine profile number on file and note the data for later
+!--          NAMELIST output, if the respective profile is to be drawn by
+!--          PROFIL (if it shall not be drawn, the variable dopr_crossindex has
+!--          the value 0, otherwise the number of the coordinate cross)
+             profile_number = profile_number + 1
+             j = dopr_crossindex(i)
+
+             IF ( j /= 0 )  THEN
+                cross_profile_number_count(j) = cross_profile_number_count(j) +1
+                k = cross_profile_number_count(j)
+                cross_pnc_local(j)            = cross_pnc_local(j)            +1
+                cross_profile_numbers(k,j) = profile_number
+                ilc = MOD( dopr_time_count, 10 )
+                IF ( ilc == 0 )  ilc = 10
+                cross_linecolors(k,j) = linecolors(ilc)
+                ils = MOD( cross_pnc_local(j), 11 )
+                IF ( ils == 0 )  ils = 11
+                cross_linestyles(k,j) = linestyles(ils)
+!
+!--             If required, extend x-value range of the respective coordinate 
+!--             cross, provided it has not been specified in check_parameters.
+!--             Determination over all (sub-)regions.
+                IF ( cross_uxmin(j) == 0.0  .AND.  cross_uxmax(j) == 0.0 )  THEN
+
+                   DO  sr = 0, statistic_regions
+
+                      uxmi = MINVAL( hom_sum(:nz_do1d,dopr_index(i),sr) )
+                      uxma = MAXVAL( hom_sum(:nz_do1d,dopr_index(i),sr) )
+!
+!--                   When the value range of the first line in the
+!--                   corresponding cross is determined, its value range is
+!--                   simply adopted.
+                      IF ( cross_uxmin_computed(j) > cross_uxmax_computed(j) ) &
+                      THEN
+                         cross_uxmin_computed(j) = uxmi
+                         cross_uxmax_computed(j) = uxma
+                      ELSE
+                         cross_uxmin_computed(j) = &
+                                           MIN( cross_uxmin_computed(j), uxmi )
+                         cross_uxmax_computed(j) = &
+                                           MAX( cross_uxmax_computed(j), uxma )
+                      ENDIF
+
+                   ENDDO
+
+                ENDIF
+!
+!--             If required, store the normalizing factors
+                SELECT CASE ( cross_normalized_x(j) )
+
+                   CASE ( 'tsw2' )
+                      cross_normx_factor(k,j) = &
+                            ( hom_sum(nzb+11,var_hom,normalizing_region) )**2
+                   CASE ( 'wpt0' )
+                      cross_normx_factor(k,j) = &
+                              hom_sum(nzb,18,normalizing_region)
+                   CASE ( 'wstsw2' )
+                      cross_normx_factor(k,j) = &
+                              hom_sum(nzb+8,var_hom,normalizing_region)  &
+                          * ( hom_sum(nzb+11,var_hom,normalizing_region) )**2
+                   CASE ( 'ws2' )
+                      cross_normx_factor(k,j) = &
+                            ( hom_sum(nzb+8,var_hom,normalizing_region) )**2
+                   CASE ( 'ws2tsw' )
+                      cross_normx_factor(k,j) = &
+                            ( hom_sum(nzb+8,var_hom,normalizing_region) )**2&
+                            * hom_sum(nzb+11,var_hom,normalizing_region)
+                   CASE ( 'ws3' )
+                      cross_normx_factor(k,j) = &
+                            ( hom_sum(nzb+8,var_hom,normalizing_region) )**3
+
+                END SELECT
+                SELECT CASE ( cross_normalized_y(j) )
+
+                   CASE ( 'z_i' )
+                      cross_normy_factor(k,j) = &
+                                   hom_sum(nzb+6,var_hom,normalizing_region)
+
+                END SELECT
+
+!
+!--             Check the normalizing factors for zeros and deactivate the 
+!--             normalization, if required.
+                IF ( cross_normx_factor(k,j) == 0.0  .OR. &
+                     cross_normy_factor(k,j) == 0.0 )  THEN
+                   PRINT*,'+++ WARNING data_output_profiles: normalizing ',j, &
+                          ' cross is not possible since one of the'
+                   PRINT*,'                     normalizing factors is zero!'
+                   PRINT*,'    cross_normx_factor(',k,',',j,') = ', &
+                           cross_normx_factor(k,j)
+                   PRINT*,'    cross_normy_factor(',k,',',j,') = ', &
+                           cross_normy_factor(k,j)
+                   cross_normx_factor(k,j) = 1.0
+                   cross_normy_factor(k,j) = 1.0
+                   cross_normalized_x(j) = ' '
+                   cross_normalized_y(j) = ' '
+                ENDIF
+
+!
+!--             If required, extend normalized x-value range of the respective  
+!--             cross, provided it has not been specified in check_parameters.
+!--             Determination over all (sub-)regions.
+                IF ( cross_uxmin_normalized(j) == 0.0  .AND. &
+                     cross_uxmax_normalized(j) == 0.0 )  THEN
+
+                   DO  sr = 0, statistic_regions
+
+                      uxmi = MINVAL( hom(:nz_do1d,1,dopr_index(i),sr) ) / &
+                             cross_normx_factor(k,j)
+                      uxma = MAXVAL( hom(:nz_do1d,1,dopr_index(i),sr) ) / &
+                             cross_normx_factor(k,j)
+!
+!--                   When the value range of the first line in the
+!--                   corresponding cross is determined, its value range is
+!--                   simply adopted.
+                      IF ( cross_uxmin_normalized_computed(j) > &
+                           cross_uxmax_normalized_computed(j) )  THEN
+                         cross_uxmin_normalized_computed(j) = uxmi
+                         cross_uxmax_normalized_computed(j) = uxma
+                      ELSE
+                         cross_uxmin_normalized_computed(j) = &
+                                MIN( cross_uxmin_normalized_computed(j), uxmi )
+                         cross_uxmax_normalized_computed(j) = &
+                                MAX( cross_uxmax_normalized_computed(j), uxma )
+                      ENDIF
+
+                   ENDDO
+
+                ENDIF
+
+             ENDIF   ! Index determination
+
+          ENDIF   ! profil output
+
+       ENDDO   ! Loop over dopr_n
 
     ENDIF  ! Output on PE0
@@ -288,9 +622,15 @@
 !
 !-- If averaging has been done above, the summation counter must be re-set.
-    IF ( averaging_interval_pr /= 0.0_wp )  THEN
+    IF ( averaging_interval_pr /= 0.0 )  THEN
        average_count_pr = 0
     ENDIF
 
-    CALL cpu_log( log_point(15), 'data_output_profiles','stop' )
+    CALL cpu_log( log_point(15), 'data_output_profiles','stop', 'nobarrier' )
+
+!
+!-- Formats
+100 FORMAT ('#1 ',A,1X,A)
+101 FORMAT (E15.7,1X,E15.7)
+102 FORMAT ('NEXT')
 
  END SUBROUTINE data_output_profiles
