Index: palm/trunk/SOURCE/flow_statistics.f90
===================================================================
--- palm/trunk/SOURCE/flow_statistics.f90	(revision 3001)
+++ palm/trunk/SOURCE/flow_statistics.f90	(revision 3003)
@@ -25,4 +25,8 @@
 ! -----------------
 ! $Id$
+! The inversion height will not be calcuated before the first timestep in 
+! case of restarts.
+! 
+! 2968 2018-04-13 11:52:24Z suehring
 ! Bugfix in output of timeseries quantities in case of elevated model surfaces.
 ! 
@@ -277,8 +281,9 @@
     USE control_parameters,                                                    &
         ONLY:   average_count_pr, cloud_droplets, cloud_physics, do_sum,       &
-                dt_3d, g, humidity, kappa, land_surface, large_scale_forcing,  &
-                large_scale_subsidence, max_pr_user, message_string, neutral,  &
-                microphysics_morrison, microphysics_seifert, ocean,            &
-                passive_scalar, simulated_time, use_subsidence_tendencies,     &
+                dt_3d, g, humidity, initializing_actions, kappa, land_surface, &
+                large_scale_forcing, large_scale_subsidence, max_pr_user,      &
+                message_string, neutral, microphysics_morrison,                &
+                microphysics_seifert, ocean, passive_scalar, simulated_time,   &
+                simulated_time_at_begin, use_subsidence_tendencies,            & 
                 use_surface_fluxes, use_top_fluxes, ws_scheme_mom,             &
                 ws_scheme_sca
@@ -357,5 +362,4 @@
     REAL(wp) ::  v2               !<
     REAL(wp) ::  w2               !<
-    REAL(wp) ::  z_i(2)           !<
     
     REAL(wp) ::  dptdz(nzb+1:nzt+1)    !<
@@ -2004,73 +2008,78 @@
 !--    is less than 1.5 times the height where the heat flux becomes negative
 !--    (positive) for the first time.
-       z_i(1) = 0.0_wp
-       first = .TRUE.
-
-       IF ( ocean )  THEN
-          DO  k = nzt, nzb+1, -1
-             IF ( first  .AND.  hom(k,1,18,sr) < -1.0E-8_wp )  THEN
-                first = .FALSE.
-                height = zw(k)
-             ENDIF
-             IF ( hom(k,1,18,sr) < -1.0E-8_wp  .AND.                           &
-                  hom(k-1,1,18,sr) > hom(k,1,18,sr) )  THEN
-                IF ( zw(k) < 1.5_wp * height )  THEN
-                   z_i(1) = zw(k)
-                ELSE
-                   z_i(1) = height
-                ENDIF
-                EXIT
-             ENDIF
-          ENDDO
-       ELSE
-          DO  k = nzb, nzt-1
-             IF ( first  .AND.  hom(k,1,18,sr) < -1.0E-8_wp )  THEN
-                first = .FALSE.
-                height = zw(k)
-             ENDIF
-             IF ( hom(k,1,18,sr) < -1.0E-8_wp  .AND.                           &
-                  hom(k+1,1,18,sr) > hom(k,1,18,sr) )  THEN
-                IF ( zw(k) < 1.5_wp * height )  THEN
-                   z_i(1) = zw(k)
-                ELSE
-                   z_i(1) = height
-                ENDIF
-                EXIT
-             ENDIF
-          ENDDO
-       ENDIF
-
-!
-!--    Second scheme: Gradient scheme from Sullivan et al. (1998), modified 
-!--    by Uhlenbrock(2006). The boundary layer height is the height with the 
-!--    maximal local temperature gradient: starting from the second (the last
-!--    but one) vertical gridpoint, the local gradient must be at least 
-!--    0.2K/100m and greater than the next four gradients.
-!--    WARNING: The threshold value of 0.2K/100m must be adjusted for the
-!--             ocean case! 
-       z_i(2) = 0.0_wp
-       DO  k = nzb+1, nzt+1
-          dptdz(k) = ( hom(k,1,4,sr) - hom(k-1,1,4,sr) ) * ddzu(k)
-       ENDDO
-       dptdz_threshold = 0.2_wp / 100.0_wp
-
-       IF ( ocean )  THEN
-          DO  k = nzt+1, nzb+5, -1
-             IF ( dptdz(k) > dptdz_threshold  .AND.                           &
-                  dptdz(k) > dptdz(k-1)  .AND.  dptdz(k) > dptdz(k-2)  .AND.  &
-                  dptdz(k) > dptdz(k-3)  .AND.  dptdz(k) > dptdz(k-4) )  THEN
-                z_i(2) = zw(k-1)
-                EXIT
-             ENDIF
-          ENDDO
-       ELSE
-          DO  k = nzb+1, nzt-3
-             IF ( dptdz(k) > dptdz_threshold  .AND.                           &
-                  dptdz(k) > dptdz(k+1)  .AND.  dptdz(k) > dptdz(k+2)  .AND.  &
-                  dptdz(k) > dptdz(k+3)  .AND.  dptdz(k) > dptdz(k+4) )  THEN
-                z_i(2) = zw(k-1)
-                EXIT
-             ENDIF
-          ENDDO
+       IF ( TRIM( initializing_actions ) /= 'read_restart_data' .OR.           &
+            simulated_time_at_begin /= simulated_time ) THEN
+
+          z_i(1) = 0.0_wp
+          first = .TRUE.
+
+          IF ( ocean )  THEN
+             DO  k = nzt, nzb+1, -1
+                IF ( first  .AND.  hom(k,1,18,sr) < -1.0E-8_wp )  THEN
+                   first = .FALSE.
+                   height = zw(k)
+                ENDIF
+                IF ( hom(k,1,18,sr) < -1.0E-8_wp  .AND.                        &
+                     hom(k-1,1,18,sr) > hom(k,1,18,sr) )  THEN
+                   IF ( zw(k) < 1.5_wp * height )  THEN
+                      z_i(1) = zw(k)
+                   ELSE
+                      z_i(1) = height
+                   ENDIF
+                   EXIT
+                ENDIF
+             ENDDO
+          ELSE
+             DO  k = nzb, nzt-1
+                IF ( first  .AND.  hom(k,1,18,sr) < -1.0E-8_wp )  THEN
+                   first = .FALSE.
+                   height = zw(k)
+                ENDIF
+                IF ( hom(k,1,18,sr) < -1.0E-8_wp  .AND.                        &
+                     hom(k+1,1,18,sr) > hom(k,1,18,sr) )  THEN
+                   IF ( zw(k) < 1.5_wp * height )  THEN
+                      z_i(1) = zw(k)
+                   ELSE
+                      z_i(1) = height
+                   ENDIF
+                   EXIT
+                ENDIF
+             ENDDO
+          ENDIF
+
+!
+!--       Second scheme: Gradient scheme from Sullivan et al. (1998), modified 
+!--       by Uhlenbrock(2006). The boundary layer height is the height with the 
+!--       maximal local temperature gradient: starting from the second (the
+!--       last but one) vertical gridpoint, the local gradient must be at least 
+!--       0.2K/100m and greater than the next four gradients.
+!--       WARNING: The threshold value of 0.2K/100m must be adjusted for the
+!--       ocean case! 
+          z_i(2) = 0.0_wp
+          DO  k = nzb+1, nzt+1
+             dptdz(k) = ( hom(k,1,4,sr) - hom(k-1,1,4,sr) ) * ddzu(k)
+          ENDDO
+          dptdz_threshold = 0.2_wp / 100.0_wp
+
+          IF ( ocean )  THEN
+             DO  k = nzt+1, nzb+5, -1
+                IF ( dptdz(k) > dptdz_threshold  .AND.                         &
+                     dptdz(k) > dptdz(k-1)  .AND.  dptdz(k) > dptdz(k-2)  .AND.&
+                     dptdz(k) > dptdz(k-3)  .AND.  dptdz(k) > dptdz(k-4) )  THEN
+                   z_i(2) = zw(k-1)
+                   EXIT
+                ENDIF
+             ENDDO
+          ELSE
+             DO  k = nzb+1, nzt-3
+                IF ( dptdz(k) > dptdz_threshold  .AND.                         &
+                     dptdz(k) > dptdz(k+1)  .AND.  dptdz(k) > dptdz(k+2)  .AND.&
+                     dptdz(k) > dptdz(k+3)  .AND.  dptdz(k) > dptdz(k+4) )  THEN
+                   z_i(2) = zw(k-1)
+                   EXIT
+                ENDIF
+             ENDDO
+          ENDIF
+
        ENDIF
 
@@ -2087,4 +2096,5 @@
           ENDIF
        ENDDO
+
 !
 !--    Computation of both the characteristic vertical velocity and
Index: palm/trunk/SOURCE/modules.f90
===================================================================
--- palm/trunk/SOURCE/modules.f90	(revision 3001)
+++ palm/trunk/SOURCE/modules.f90	(revision 3003)
@@ -25,4 +25,8 @@
 ! -----------------
 ! $Id$
+! The inversion height is defined as a global variable now which belongs to the 
+! module statistics 
+! 
+! 2968 2018-04-13 11:52:24Z suehring
 ! +topo_min_level
 ! 
@@ -2041,4 +2045,6 @@
     REAL(wp) ::  v_max  !< maximum of absolute v-veloctiy in entire domain
     REAL(wp) ::  w_max  !< maximum of absolute w-veloctiy in entire domain
+
+    REAL(wp), DIMENSION(2) ::  z_i  !< inversion height
     
     REAL(wp), DIMENSION(:), ALLOCATABLE ::  mean_surface_level_height  !< mean surface level height for the different statistic regions
Index: palm/trunk/SOURCE/read_restart_data_mod.f90
===================================================================
--- palm/trunk/SOURCE/read_restart_data_mod.f90	(revision 3001)
+++ palm/trunk/SOURCE/read_restart_data_mod.f90	(revision 3003)
@@ -25,4 +25,9 @@
 ! -----------------
 ! $Id$
+! z_i is also read to use the last known inversion height from the 
+! initial run as the first inversion height which is written into the
+! run control file 
+! 
+! 2956 2018-04-10 11:01:03Z Giersch
 ! spectrum_x and spectrum_y have been moved to global data
 ! 
@@ -124,5 +129,5 @@
        USE statistics,                                                         &
            ONLY:  statistic_regions, hom, hom_sum, pr_palm, u_max, u_max_ijk,  &
-                  v_max, v_max_ijk, w_max, w_max_ijk
+                  v_max, v_max_ijk, w_max, w_max_ijk, z_i
 
        USE synthetic_turbulence_generator_mod,                                 &
@@ -748,4 +753,7 @@
              CASE ( 'zeta_min' )
                 READ ( 13 )  zeta_min
+             CASE ( 'z_i' )
+                READ ( 13 )  z_i
+
 
              CASE DEFAULT
Index: palm/trunk/SOURCE/write_restart_data_mod.f90
===================================================================
--- palm/trunk/SOURCE/write_restart_data_mod.f90	(revision 3001)
+++ palm/trunk/SOURCE/write_restart_data_mod.f90	(revision 3003)
@@ -25,4 +25,9 @@
 ! -----------------
 ! $Id$
+! z_i is also written out to use the last known inversion height from the 
+! initial run as the first inversion height which is written into the
+! run control file 
+! 
+! 2956 2018-04-10 11:01:03Z Giersch
 ! spectrum_x and spectrum_y have been moved to global data
 ! 
@@ -126,5 +131,5 @@
        USE statistics,                                                         &
            ONLY:  statistic_regions, hom, hom_sum, u_max, u_max_ijk, v_max,    &
-                  v_max_ijk, w_max, w_max_ijk
+                  v_max_ijk, w_max, w_max_ijk, z_i
 
        USE user_write_restart_data_mod,                                        &
@@ -900,4 +905,7 @@
        WRITE ( 14 )  zeta_min
 
+       CALL wrd_write_string( 'z_i' ) 
+       WRITE ( 14 )  z_i
+
 
 !    
@@ -915,4 +923,5 @@
 !-- If required, write restart data for turbulence generator.
        IF ( syn_turb_gen )  CALL stg_wrd_global
+
 !
 !-- If required, write restart data for gust module.
