Index: palm/trunk/SOURCE/Makefile
===================================================================
--- palm/trunk/SOURCE/Makefile	(revision 3578)
+++ palm/trunk/SOURCE/Makefile	(revision 3579)
@@ -25,4 +25,7 @@
 # -----------------
 # $Id$
+# Dependency for check_parameters on nesting_offl_mod added
+# 
+# 3569 2018-11-27 17:03:40Z kanani
 # dom_dwd_user, Schrempf:
 # New dependencies for biometeorology_mod,
@@ -847,4 +850,5 @@
 	mod_kinds.o \
 	modules.o \
+	nesting_offl_mod.o \
 	netcdf_data_input_mod.o \
 	netcdf_interface_mod.o \
Index: palm/trunk/SOURCE/check_parameters.f90
===================================================================
--- palm/trunk/SOURCE/check_parameters.f90	(revision 3578)
+++ palm/trunk/SOURCE/check_parameters.f90	(revision 3579)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Call nesting_offl_check_parameters
+! 
+! 3575 2018-11-28 15:06:32Z kanani
 ! Bugfix for output time levels in parallel NetCDF output with spinup
 ! 
@@ -777,4 +780,7 @@
         ONLY:  damp_level_1d, damp_level_ind_1d
 
+    USE nesting_offl_mod,                                                      &
+        ONLY:  nesting_offl_check_parameters
+        
     USE netcdf_data_input_mod,                                                 &
         ONLY:  init_model, input_pids_static, netcdf_data_input_check_dynamic, &
@@ -1525,4 +1531,5 @@
                                 CALL lsf_nudging_check_parameters
     IF ( land_surface )         CALL lsm_check_parameters
+    IF ( nesting_offline )      CALL nesting_offl_check_parameters    
     IF ( ocean_mode )           CALL ocean_check_parameters
     IF ( plant_canopy )         CALL pcm_check_parameters
Index: palm/trunk/SOURCE/init_3d_model.f90
===================================================================
--- palm/trunk/SOURCE/init_3d_model.f90	(revision 3578)
+++ palm/trunk/SOURCE/init_3d_model.f90	(revision 3579)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Bugfix in initialization of turbulence generator
+! 
+! 3569 2018-11-27 17:03:40Z kanani
 ! dom_dwd_user, Schrempf:
 ! Remove uv exposure model code, this is now part of biometeorology_mod,
@@ -1359,4 +1362,7 @@
 !--       fluxes, etc. 
           CALL init_surfaces
+!
+!--       Initialize synthetic turbulence generator if required 
+          IF( use_syn_turb_gen )  CALL stg_init
 
           CALL location_message( 'finished', .TRUE. )
@@ -1366,7 +1372,4 @@
 
           CALL location_message( 'initializing with constant profiles', .FALSE. )
-!
-!--       Overwrite initial profiles in case of synthetic turbulence generator
-          IF( use_syn_turb_gen )  CALL stg_init
 
 !
@@ -1430,5 +1433,8 @@
 !--       fluxes, etc. 
           CALL init_surfaces
-
+!
+!--       Initialize synthetic turbulence generator if required 
+          IF( use_syn_turb_gen )  CALL stg_init
+          
           CALL location_message( 'finished', .TRUE. )
 
Index: palm/trunk/SOURCE/nesting_offl_mod.f90
===================================================================
--- palm/trunk/SOURCE/nesting_offl_mod.f90	(revision 3578)
+++ palm/trunk/SOURCE/nesting_offl_mod.f90	(revision 3579)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Check implemented for offline nesting in child domain 
+! 
+! 3413 2018-10-24 10:28:44Z suehring
 ! Keyword ID set
 ! 
@@ -79,6 +82,6 @@
 !
 !-- Public subroutines
-    PUBLIC nesting_offl_bc, nesting_offl_header, nesting_offl_init,            &
-           nesting_offl_mass_conservation, nesting_offl_parin 
+    PUBLIC nesting_offl_bc, nesting_offl_check_parameters, nesting_offl_header,&
+           nesting_offl_init, nesting_offl_mass_conservation, nesting_offl_parin 
 !
 !-- Public variables
@@ -88,4 +91,8 @@
        MODULE PROCEDURE nesting_offl_bc
     END INTERFACE nesting_offl_bc
+    
+    INTERFACE nesting_offl_check_parameters
+       MODULE PROCEDURE nesting_offl_check_parameters
+    END INTERFACE nesting_offl_check_parameters
     
     INTERFACE nesting_offl_header
@@ -879,8 +886,15 @@
 !------------------------------------------------------------------------------!
     SUBROUTINE nesting_offl_check_parameters 
+    
+       USE control_parameters,                                                    &
+        ONLY:  child_domain, message_string, nesting_offline
 
        IMPLICIT NONE
 !
 !--    Perform checks
+       IF ( nesting_offline  .AND.  child_domain )  THEN
+          message_string = 'Offline nesting is only applicable in root model.'
+          CALL message( 'stg_check_parameters', 'PA0622', 1, 2, 0, 6, 0 )       
+       ENDIF
 
 
Index: palm/trunk/SOURCE/synthetic_turbulence_generator_mod.f90
===================================================================
--- palm/trunk/SOURCE/synthetic_turbulence_generator_mod.f90	(revision 3578)
+++ palm/trunk/SOURCE/synthetic_turbulence_generator_mod.f90	(revision 3579)
@@ -25,4 +25,10 @@
 ! -----------------
 ! $Id$
+! - Bugfix in calculation of turbulence scaling parameters for turbulence 
+!   generator in case of topography
+! - Additional checks implemented - no STG in RANS-RANS nesting or LES-LES
+!   nesting
+! 
+! 3376 2018-10-19 10:15:32Z suehring
 ! Error messages and numbers reivsed. 
 ! 
@@ -408,4 +414,20 @@
     IF ( use_syn_turb_gen )  THEN
 
+       IF ( child_domain  .AND.  .NOT. rans_mode  .AND.                        &
+                                 .NOT. rans_mode_parent )  THEN
+          message_string = 'Using synthetic turbulence generator ' //          &
+                           'is not allowed in LES-LES nesting.'
+          CALL message( 'stg_check_parameters', 'PA0620', 1, 2, 0, 6, 0 )
+       
+       ENDIF
+       
+       IF ( child_domain  .AND.  rans_mode  .AND.                              &
+                                 rans_mode_parent )  THEN
+          message_string = 'Using synthetic turbulence generator ' //          &
+                           'is not allowed in RANS-RANS nesting.'
+          CALL message( 'stg_check_parameters', 'PA0621', 1, 2, 0, 6, 0 )
+       
+       ENDIF
+    
        IF ( .NOT. nesting_offline  .AND.  .NOT. child_domain )  THEN 
        
@@ -413,7 +435,7 @@
         .AND.  INDEX( initializing_actions, 'read_restart_data' ) == 0 )  THEN
              message_string = 'Using synthetic turbulence generator ' //       &
-                              'requires %initializing_actions = '         //   &
-                              '"set_constant_profiles" or "read_restart_data"' //&
-                              ', if not offline nesting is applied.'
+                            'requires %initializing_actions = '         //     &
+                            '"set_constant_profiles" or "read_restart_data"' //&
+                            ', if not offline nesting is applied.'
              CALL message( 'stg_check_parameters', 'PA0015', 1, 2, 0, 6, 0 )
           ENDIF
@@ -427,5 +449,5 @@
           IF ( bc_ns /= 'cyclic' )  THEN
              message_string = 'Using synthetic turbulence generator ' //       &
-                              'requires &bc_ns = "cyclic", ' //               &
+                              'requires &bc_ns = "cyclic", ' //                &
                               'if not offline nesting is applied.'
              CALL message( 'stg_check_parameters', 'PA0037', 1, 2, 0, 6, 0 )
@@ -1726,5 +1748,4 @@
           r32(k) = 10E-8_wp
        ENDIF
-!        write(9,*) zu(k), r11(k), r33(k), r31(k), zi_ribulk, scale_us, scale_wm, scale_l
     ENDDO
 
@@ -1970,5 +1991,5 @@
         
     USE surface_mod,                                                           &
-        ONLY:  surf_def_h, surf_lsm_h, surf_usm_h
+        ONLY:  get_topography_top_index_ji, surf_def_h, surf_lsm_h, surf_usm_h
 
     IMPLICIT NONE
@@ -1977,5 +1998,6 @@
     INTEGER(iwp) :: j            !< loop index in y-direction
     INTEGER(iwp) :: k            !< loop index in z-direction
-    INTEGER(iwp) :: k_ref        !< index in z-direction for reference height 
+    INTEGER(iwp) :: k_ref        !< index in z-direction for COSMO reference height 
+    INTEGER(iwp) :: k_topo       !< topography top index 
     INTEGER(iwp) :: m            !< surface element index
 
@@ -2030,5 +2052,9 @@
 !-- However, friction velocity is used for turbulence 
 !-- parametrization, so that more physically meaningful values are important.
-!-- Hence, derive friction velocity from wind speed at a reference height.
+!-- Hence, derive friction velocity from wind speed at a reference height, 
+!-- which is 10 m, according to the height of the 1st vertical grid level 
+!-- in the COSMO level. However, in case of topography that is higher than
+!-- the reference level, the k index is determined from the 1st vertical 
+!-- PALM grid level instead. 
 !-- For a first guess use 20 m, which is in the range of the first 
 !-- COSMO vertical level. 
@@ -2042,10 +2068,15 @@
        DO  j = nys, nyn
 !
+!--       Determine the k index and topography top index
+          k_topo = MAX( get_topography_top_index_ji( j, i, 'u' ),              &
+                        get_topography_top_index_ji( j, i, 'v' ) )
+          k      = MAX( k_ref, k_topo + 1 )
+!
 !--       Note, in u- and v- component the imposed perturbations 
 !--       from the STG are already included. Check whether this 
 !--       makes any difference compared to using the pure-mean 
 !--       inflow profiles. 
-          u_int = MERGE( u(k_ref,j,i+1), u(k_ref,j,i), bc_dirichlet_l )
-          v_int = v(k_ref,j,i)
+          u_int = MERGE( u(k,j,i+1), u(k,j,i), bc_dirichlet_l )
+          v_int = v(k,j,i) 
 !
 !--       Calculate friction velocity and sum-up. Therefore, assume 
@@ -2053,5 +2084,5 @@
           friction_vel_l = friction_vel_l + kappa *                            &
                             SQRT( u_int * u_int + v_int * v_int )  /           &
-                            LOG( zu(k_ref) / z0_mean )
+                            LOG( ( zu(k) - zu(k_topo) ) / z0_mean )
           
        ENDDO
@@ -2065,10 +2096,14 @@
        DO  i = nxl, nxr
           
-          u_int = u(k_ref,j,i)
-          v_int = MERGE( v(k_ref,j+1,i), v(k_ref,j,i), bc_dirichlet_s )
+          k_topo = MAX( get_topography_top_index_ji( j, i, 'u' ),              &
+                        get_topography_top_index_ji( j, i, 'v' ) )
+          k      = MAX( k_ref, k_topo + 1 )
+          
+          u_int = u(k,j,i)
+          v_int = MERGE( v(k,j+1,i), v(k,j,i), bc_dirichlet_s )
  
           friction_vel_l = friction_vel_l + kappa *                            &
                             SQRT( u_int * u_int + v_int * v_int )  /           &
-                            LOG( zu(k_ref) / z0_mean )                       
+                            LOG( ( zu(k) - zu(k_topo) ) / z0_mean )                       
           
        ENDDO
