Index: /palm/trunk/SOURCE/nesting_offl_mod.f90
===================================================================
--- /palm/trunk/SOURCE/nesting_offl_mod.f90	(revision 4794)
+++ /palm/trunk/SOURCE/nesting_offl_mod.f90	(revision 4795)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Bugfix in obtaining the correct timestamp in case of restart runs
+!
+! 4724 2020-10-06 17:20:39Z suehring
 ! - Enable LOD=1 input of boundary conditions
 ! - Minor bugfix - add missing initialization of the top boundary
@@ -300,6 +303,6 @@
        INTEGER(iwp) ::  nzu               !< number of vertical levels on scalar grid in dynamic input file
        INTEGER(iwp) ::  nzw               !< number of vertical levels on w grid in dynamic input file
-       INTEGER(iwp) ::  tind              !< time index for reference time in mesoscale-offline nesting
-       INTEGER(iwp) ::  tind_p            !< time index for following time in mesoscale-offline nesting
+       INTEGER(iwp) ::  tind = 0          !< time index for reference time in mesoscale-offline nesting
+       INTEGER(iwp) ::  tind_p = 0        !< time index for following time in mesoscale-offline nesting
 
        LOGICAL      ::  init = .FALSE.    !< flag indicating that offline nesting is already initialized
@@ -502,7 +505,6 @@
        ENDIF
 !
-!--    CPU measurement
+!--    Start of CPU measurement
        CALL cpu_log( log_point_s(86), 'NetCDF input forcing', 'start' )
-
 !
 !--    Obtain time index for current point in time. Note, the time coordinate
@@ -511,7 +513,13 @@
 !--    7200.0. Further, since time_since_reference_point is negativ here when 
 !--    spinup is applied, use MAX function to obtain correct time index. 
-       nest_offl%tind = MINLOC( ABS( nest_offl%time -                                              &
-                                     MAX( time_since_reference_point, 0.0_wp)                      &
-                                   ), DIM = 1 ) - 1
+       nest_offl%tind = MINLOC( ABS( nest_offl%time - MAX( time_since_reference_point, 0.0_wp) ),  &
+                                DIM = 1 ) - 1
+!
+!--    Note, in case of restart runs, the time index for the boundary data may indicate a time
+!--    in the future. This needs to be checked and corrected.
+       IF ( TRIM( initializing_actions ) == 'read_restart_data'  .AND.                             &
+            nest_offl%time(nest_offl%tind) > time_since_reference_point )  THEN
+          nest_offl%tind = nest_offl%tind - 1
+       ENDIF
        nest_offl%tind_p = nest_offl%tind + 1
 !
Index: /palm/trunk/SOURCE/salsa_mod.f90
===================================================================
--- /palm/trunk/SOURCE/salsa_mod.f90	(revision 4794)
+++ /palm/trunk/SOURCE/salsa_mod.f90	(revision 4795)
@@ -26,4 +26,7 @@
 ! -----------------
 ! $Id$
+! Bugfix in obtaining the correct timestamp in case of restart runs
+!
+! 4785 2020-11-15 20:11:14Z monakurppa
 ! Fixing a segmentation fault in initialising aerosol and gas emissions
 !
@@ -328,5 +331,7 @@
         ONLY:  air_chemistry, bc_dirichlet_l, bc_dirichlet_n, bc_dirichlet_r, bc_dirichlet_s,      &
                bc_lr, bc_lr_cyc, bc_ns, bc_ns_cyc, bc_radiation_l, bc_radiation_n, bc_radiation_r, &
-               bc_radiation_s, coupling_char, debug_output, dt_3d, intermediate_timestep_count,    &
+               bc_radiation_s, coupling_char, debug_output, dt_3d,                                 &
+               initializing_actions,                                                               &
+               intermediate_timestep_count,                                                        &
                intermediate_timestep_count_max, land_surface, max_pr_salsa, message_string,        &
                monotonic_limiter_z, plant_canopy, pt_surface, restart_data_format_output, salsa,   &
@@ -779,6 +784,6 @@
        INTEGER(iwp) ::  nt          !< number of time levels in dynamic input file
        INTEGER(iwp) ::  nzu         !< number of vertical levels on scalar grid in dynamic input file
-       INTEGER(iwp) ::  tind        !< time index for reference time in mesoscale-offline nesting
-       INTEGER(iwp) ::  tind_p      !< time index for following time in mesoscale-offline nesting
+       INTEGER(iwp) ::  tind = 0    !< time index for reference time in mesoscale-offline nesting
+       INTEGER(iwp) ::  tind_p = 0  !< time index for following time in mesoscale-offline nesting
 
        INTEGER(iwp), DIMENSION(maxspec) ::  cc_in2mod = 0  !< to transfer chemical composition from input to model
@@ -13759,5 +13764,12 @@
 !-- Obtain time index for current point in time.
     salsa_nest_offl%tind = MINLOC( ABS( salsa_nest_offl%time -                                     &
-                                   MAX( time_since_reference_point, 0.0_wp ) ), DIM = 1 ) - 1
+                                        MAX( time_since_reference_point, 0.0_wp ) ), DIM = 1 ) - 1
+!
+!-- Note, in case of restart runs, the time index for the boundary data may indicate a time
+!-- in the future. This needs to be checked and corrected.
+    IF ( TRIM( initializing_actions ) == 'read_restart_data'  .AND.                                &
+         salsa_nest_offl%time(salsa_nest_offl%tind) > time_since_reference_point )  THEN
+       salsa_nest_offl%tind = salsa_nest_offl%tind - 1
+    ENDIF
     salsa_nest_offl%tind_p = salsa_nest_offl%tind + 1
 !
Index: /palm/trunk/SOURCE/virtual_measurement_mod.f90
===================================================================
--- /palm/trunk/SOURCE/virtual_measurement_mod.f90	(revision 4794)
+++ /palm/trunk/SOURCE/virtual_measurement_mod.f90	(revision 4795)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! - Add control flags
+!
+! 4764 2020-10-30 12:50:36Z suehring
 ! Missing variable declaration and directives for netcdf4 added
 !
@@ -206,4 +209,5 @@
                end_time,                                                                           &
                humidity,                                                                           &
+               land_surface,                                                                       &
                message_string,                                                                     &
                neutral,                                                                            &
@@ -2426,26 +2430,32 @@
 
               CASE ( 'utheta' )
-                 DO  m = 1, vmea(l)%ns
-                    k = vmea(l)%k(m)
-                    j = vmea(l)%j(m)
-                    i = vmea(l)%i(m)
-                    vmea(l)%measured_vars(m,n) = 0.5_wp * ( u(k,j,i) + u(k,j,i+1) ) * pt(k,j,i)
-                 ENDDO
+                 IF ( .NOT. neutral )  THEN
+                    DO  m = 1, vmea(l)%ns
+                       k = vmea(l)%k(m)
+                       j = vmea(l)%j(m)
+                       i = vmea(l)%i(m)
+                       vmea(l)%measured_vars(m,n) = 0.5_wp * ( u(k,j,i) + u(k,j,i+1) ) * pt(k,j,i)
+                    ENDDO
+                 ENDIF
 
               CASE ( 'vtheta' )
-                 DO  m = 1, vmea(l)%ns
-                    k = vmea(l)%k(m)
-                    j = vmea(l)%j(m)
-                    i = vmea(l)%i(m)
-                    vmea(l)%measured_vars(m,n) = 0.5_wp * ( v(k,j,i) + v(k,j+1,i) ) * pt(k,j,i)
-                 ENDDO
+                 IF ( .NOT. neutral )  THEN
+                    DO  m = 1, vmea(l)%ns
+                       k = vmea(l)%k(m)
+                       j = vmea(l)%j(m)
+                       i = vmea(l)%i(m)
+                       vmea(l)%measured_vars(m,n) = 0.5_wp * ( v(k,j,i) + v(k,j+1,i) ) * pt(k,j,i)
+                    ENDDO
+                 ENDIF
 
               CASE ( 'wtheta' )
-                 DO  m = 1, vmea(l)%ns
-                    k = MAX ( 1, vmea(l)%k(m) )
-                    j = vmea(l)%j(m)
-                    i = vmea(l)%i(m)
-                    vmea(l)%measured_vars(m,n) = 0.5_wp * ( w(k-1,j,i) + w(k,j,i) ) * pt(k,j,i)
-                 ENDDO
+                 IF ( .NOT. neutral )  THEN
+                    DO  m = 1, vmea(l)%ns
+                       k = MAX ( 1, vmea(l)%k(m) )
+                       j = vmea(l)%j(m)
+                       i = vmea(l)%i(m)
+                       vmea(l)%measured_vars(m,n) = 0.5_wp * ( w(k-1,j,i) + w(k,j,i) ) * pt(k,j,i)
+                    ENDDO
+                 ENDIF
 
               CASE ( 'uqv' )
@@ -2555,80 +2565,88 @@
 
               CASE ( 'thetas' ) ! scaling parameter temperature
-                 DO  m = 1, vmea(l)%ns
-!
-!--                 Surface data is only available on inner subdomains, not on ghost points. Hence,
-!-                  limit the indices.
-                    j = MERGE( vmea(l)%j(m), nys, vmea(l)%j(m) > nys )
-                    j = MERGE( j           , nyn, j            < nyn )
-                    i = MERGE( vmea(l)%i(m), nxl, vmea(l)%i(m) > nxl )
-                    i = MERGE( i           , nxr, i            < nxr )
-
-                    DO  mm = surf_def_h(0)%start_index(j,i), surf_def_h(0)%end_index(j,i)
-                       vmea(l)%measured_vars(m,n) = surf_def_h(0)%ts(mm)
-                    ENDDO
-                    DO  mm = surf_lsm_h(0)%start_index(j,i), surf_lsm_h(0)%end_index(j,i)
-                       vmea(l)%measured_vars(m,n) = surf_lsm_h(0)%ts(mm)
-                    ENDDO
-                    DO  mm = surf_usm_h(0)%start_index(j,i), surf_usm_h(0)%end_index(j,i)
-                       vmea(l)%measured_vars(m,n) = surf_usm_h(0)%ts(mm)
-                    ENDDO
-                 ENDDO
+                 IF ( .NOT. neutral )  THEN
+                    DO  m = 1, vmea(l)%ns
+!
+!--                    Surface data is only available on inner subdomains, not on ghost points. Hence,
+!-                     limit the indices.
+                       j = MERGE( vmea(l)%j(m), nys, vmea(l)%j(m) > nys )
+                       j = MERGE( j           , nyn, j            < nyn )
+                       i = MERGE( vmea(l)%i(m), nxl, vmea(l)%i(m) > nxl )
+                       i = MERGE( i           , nxr, i            < nxr )
+
+                       DO  mm = surf_def_h(0)%start_index(j,i), surf_def_h(0)%end_index(j,i)
+                          vmea(l)%measured_vars(m,n) = surf_def_h(0)%ts(mm)
+                       ENDDO
+                       DO  mm = surf_lsm_h(0)%start_index(j,i), surf_lsm_h(0)%end_index(j,i)
+                          vmea(l)%measured_vars(m,n) = surf_lsm_h(0)%ts(mm)
+                       ENDDO
+                       DO  mm = surf_usm_h(0)%start_index(j,i), surf_usm_h(0)%end_index(j,i)
+                          vmea(l)%measured_vars(m,n) = surf_usm_h(0)%ts(mm)
+                       ENDDO
+                    ENDDO
+                 ENDIF
 
               CASE ( 'hfls' ) ! surface latent heat flux
-                 DO  m = 1, vmea(l)%ns
-!
-!--                 Surface data is only available on inner subdomains, not on ghost points. Hence,
-!--                 limit the indices.
-                    j = MERGE( vmea(l)%j(m), nys, vmea(l)%j(m) > nys )
-                    j = MERGE( j           , nyn, j            < nyn )
-                    i = MERGE( vmea(l)%i(m), nxl, vmea(l)%i(m) > nxl )
-                    i = MERGE( i           , nxr, i            < nxr )
-
-                    DO  mm = surf_def_h(0)%start_index(j,i), surf_def_h(0)%end_index(j,i)
-                       vmea(l)%measured_vars(m,n) = surf_def_h(0)%qsws(mm)
-                    ENDDO
-                    DO  mm = surf_lsm_h(0)%start_index(j,i), surf_lsm_h(0)%end_index(j,i)
-                       vmea(l)%measured_vars(m,n) = surf_lsm_h(0)%qsws(mm)
-                    ENDDO
-                    DO  mm = surf_usm_h(0)%start_index(j,i), surf_usm_h(0)%end_index(j,i)
-                       vmea(l)%measured_vars(m,n) = surf_usm_h(0)%qsws(mm)
-                    ENDDO
-                 ENDDO
+                 IF ( humidity )  THEN
+                    DO  m = 1, vmea(l)%ns
+!
+!--                    Surface data is only available on inner subdomains, not on ghost points. Hence,
+!--                    limit the indices.
+                       j = MERGE( vmea(l)%j(m), nys, vmea(l)%j(m) > nys )
+                       j = MERGE( j           , nyn, j            < nyn )
+                       i = MERGE( vmea(l)%i(m), nxl, vmea(l)%i(m) > nxl )
+                       i = MERGE( i           , nxr, i            < nxr )
+
+                       DO  mm = surf_def_h(0)%start_index(j,i), surf_def_h(0)%end_index(j,i)
+                          vmea(l)%measured_vars(m,n) = surf_def_h(0)%qsws(mm)
+                       ENDDO
+                       DO  mm = surf_lsm_h(0)%start_index(j,i), surf_lsm_h(0)%end_index(j,i)
+                          vmea(l)%measured_vars(m,n) = surf_lsm_h(0)%qsws(mm)
+                       ENDDO
+                       DO  mm = surf_usm_h(0)%start_index(j,i), surf_usm_h(0)%end_index(j,i)
+                          vmea(l)%measured_vars(m,n) = surf_usm_h(0)%qsws(mm)
+                       ENDDO
+                    ENDDO
+                 ENDIF
 
               CASE ( 'hfss' ) ! surface sensible heat flux
-                 DO  m = 1, vmea(l)%ns
-!
-!--                 Surface data is only available on inner subdomains, not on ghost points. Hence,
-!--                 limit the indices.
-                    j = MERGE( vmea(l)%j(m), nys, vmea(l)%j(m) > nys )
-                    j = MERGE( j           , nyn, j            < nyn )
-                    i = MERGE( vmea(l)%i(m), nxl, vmea(l)%i(m) > nxl )
-                    i = MERGE( i           , nxr, i            < nxr )
-
-                    DO  mm = surf_def_h(0)%start_index(j,i), surf_def_h(0)%end_index(j,i)
-                       vmea(l)%measured_vars(m,n) = surf_def_h(0)%shf(mm)
-                    ENDDO
-                    DO  mm = surf_lsm_h(0)%start_index(j,i), surf_lsm_h(0)%end_index(j,i)
-                       vmea(l)%measured_vars(m,n) = surf_lsm_h(0)%shf(mm)
-                    ENDDO
-                    DO  mm = surf_usm_h(0)%start_index(j,i), surf_usm_h(0)%end_index(j,i)
-                       vmea(l)%measured_vars(m,n) = surf_usm_h(0)%shf(mm)
-                    ENDDO
-                 ENDDO
+                 IF ( .NOT. neutral )  THEN
+                    DO  m = 1, vmea(l)%ns
+!
+!--                    Surface data is only available on inner subdomains, not on ghost points. Hence,
+!--                    limit the indices.
+                       j = MERGE( vmea(l)%j(m), nys, vmea(l)%j(m) > nys )
+                       j = MERGE( j           , nyn, j            < nyn )
+                       i = MERGE( vmea(l)%i(m), nxl, vmea(l)%i(m) > nxl )
+                       i = MERGE( i           , nxr, i            < nxr )
+
+                       DO  mm = surf_def_h(0)%start_index(j,i), surf_def_h(0)%end_index(j,i)
+                          vmea(l)%measured_vars(m,n) = surf_def_h(0)%shf(mm)
+                       ENDDO
+                       DO  mm = surf_lsm_h(0)%start_index(j,i), surf_lsm_h(0)%end_index(j,i)
+                          vmea(l)%measured_vars(m,n) = surf_lsm_h(0)%shf(mm)
+                       ENDDO
+                       DO  mm = surf_usm_h(0)%start_index(j,i), surf_usm_h(0)%end_index(j,i)
+                          vmea(l)%measured_vars(m,n) = surf_usm_h(0)%shf(mm)
+                       ENDDO
+                    ENDDO
+                 ENDIF
 
               CASE ( 'hfdg' ) ! ground heat flux
-                 DO  m = 1, vmea(l)%ns
-!
-!--                 Surface data is only available on inner subdomains, not on ghost points. Hence,
-!--                 limit the indices.
-                    j = MERGE( vmea(l)%j(m), nys, vmea(l)%j(m) > nys )
-                    j = MERGE( j           , nyn, j            < nyn )
-                    i = MERGE( vmea(l)%i(m), nxl, vmea(l)%i(m) > nxl )
-                    i = MERGE( i           , nxr, i            < nxr )
-
-                    DO  mm = surf_lsm_h(0)%start_index(j,i), surf_lsm_h(0)%end_index(j,i)
-                       vmea(l)%measured_vars(m,n) = surf_lsm_h(0)%ghf(mm)
-                    ENDDO
-                 ENDDO
+                 IF ( land_surface )  THEN
+                    DO  m = 1, vmea(l)%ns
+!
+!--                    Surface data is only available on inner subdomains, not on ghost points. Hence,
+!--                    limit the indices.
+                       j = MERGE( vmea(l)%j(m), nys, vmea(l)%j(m) > nys )
+                       j = MERGE( j           , nyn, j            < nyn )
+                       i = MERGE( vmea(l)%i(m), nxl, vmea(l)%i(m) > nxl )
+                       i = MERGE( i           , nxr, i            < nxr )
+
+                       DO  mm = surf_lsm_h(0)%start_index(j,i), surf_lsm_h(0)%end_index(j,i)
+                          vmea(l)%measured_vars(m,n) = surf_lsm_h(0)%ghf(mm)
+                       ENDDO
+                    ENDDO
+                 ENDIF
 
               CASE ( 'rnds' ) ! surface net radiation
@@ -2847,19 +2865,21 @@
 
               CASE ( 'm_soil', 'lwcs' ) ! soil moisture
-                 DO  m = 1, vmea(l)%ns_soil
-                    j = MERGE( vmea(l)%j_soil(m), nys, vmea(l)%j_soil(m) > nys )
-                    j = MERGE( j                , nyn, j                 < nyn )
-                    i = MERGE( vmea(l)%i_soil(m), nxl, vmea(l)%i_soil(m) > nxl )
-                    i = MERGE( i                , nxr, i                 < nxr )
-                    k = vmea(l)%k_soil(m)
-
-                    match_lsm = surf_lsm_h(0)%start_index(j,i) <= surf_lsm_h(0)%end_index(j,i)
-
-                    IF ( match_lsm )  THEN
-                       mm = surf_lsm_h(0)%start_index(j,i)
-                       vmea(l)%measured_vars_soil(m,n) = m_soil_h(0)%var_2d(k,mm)
-                    ENDIF
-
-                 ENDDO
+                 IF ( land_surface )  THEN
+                    DO  m = 1, vmea(l)%ns_soil
+                       j = MERGE( vmea(l)%j_soil(m), nys, vmea(l)%j_soil(m) > nys )
+                       j = MERGE( j                , nyn, j                 < nyn )
+                       i = MERGE( vmea(l)%i_soil(m), nxl, vmea(l)%i_soil(m) > nxl )
+                       i = MERGE( i                , nxr, i                 < nxr )
+                       k = vmea(l)%k_soil(m)
+
+                       match_lsm = surf_lsm_h(0)%start_index(j,i) <= surf_lsm_h(0)%end_index(j,i)
+
+                       IF ( match_lsm )  THEN
+                          mm = surf_lsm_h(0)%start_index(j,i)
+                          vmea(l)%measured_vars_soil(m,n) = m_soil_h(0)%var_2d(k,mm)
+                       ENDIF
+
+                    ENDDO
+                 ENDIF
 
               CASE ( 'ts', 'tb' ) ! surface temperature and brighness temperature
@@ -2899,19 +2919,21 @@
 
               CASE ( 't_lw' ) ! water temperature
-                 DO  m = 1, vmea(l)%ns
-!
-!--                 Surface data is only available on inner subdomains, not
-!--                 on ghost points. Hence, limit the indices.
-                    j = MERGE( vmea(l)%j(m), nys, vmea(l)%j(m) > nys )
-                    j = MERGE( j           , nyn, j            < nyn )
-                    i = MERGE( vmea(l)%i(m), nxl, vmea(l)%i(m) > nxl )
-                    i = MERGE( i           , nxr, i            < nxr )
-
-                    DO  mm = surf_lsm_h(0)%start_index(j,i), surf_lsm_h(0)%end_index(j,i)
-                       IF ( surf_lsm_h(0)%water_surface(m) )                                          &
-                            vmea(l)%measured_vars(m,n) = t_soil_h(0)%var_2d(nzt,m)
-                    ENDDO
-
-                 ENDDO
+                 IF ( land_surface )  THEN
+                    DO  m = 1, vmea(l)%ns
+!
+!--                    Surface data is only available on inner subdomains, not
+!--                    on ghost points. Hence, limit the indices.
+                       j = MERGE( vmea(l)%j(m), nys, vmea(l)%j(m) > nys )
+                       j = MERGE( j           , nyn, j            < nyn )
+                       i = MERGE( vmea(l)%i(m), nxl, vmea(l)%i(m) > nxl )
+                       i = MERGE( i           , nxr, i            < nxr )
+
+                       DO  mm = surf_lsm_h(0)%start_index(j,i), surf_lsm_h(0)%end_index(j,i)
+                          IF ( surf_lsm_h(0)%water_surface(m) )                                          &
+                               vmea(l)%measured_vars(m,n) = t_soil_h(0)%var_2d(nzt,m)
+                       ENDDO
+
+                    ENDDO
+                 ENDIF
 !
 !--           No match found - just set a fill value
