Index: palm/trunk/SOURCE/surface_layer_fluxes_mod.f90
===================================================================
--- palm/trunk/SOURCE/surface_layer_fluxes_mod.f90	(revision 4258)
+++ palm/trunk/SOURCE/surface_layer_fluxes_mod.f90	(revision 4298)
@@ -26,4 +26,8 @@
 ! -----------------
 ! $Id$
+! Calculation of 2-m temperature adjusted to the case the 2-m level is above 
+! the first grid point.
+! 
+! 4258 2019-10-07 13:29:08Z suehring
 ! Initialization of Obukhov lenght also at vertical surfaces (if allocated).
 ! 
@@ -105,9 +109,8 @@
                debug_output_timestep,                                          &
                do_output_at_2m, humidity,                                      &
-               ibc_e_b, ibc_pt_b, indoor_model, initializing_actions,          &
-               intermediate_timestep_count, intermediate_timestep_count_max,   &
+               ibc_e_b, ibc_pt_b, indoor_model,                                &
                land_surface, large_scale_forcing, lsf_surf, message_string,    &
                neutral, passive_scalar, pt_surface, q_surface,                 &
-               run_coupled, surface_pressure, simulated_time, terminate_run,   &
+               run_coupled, surface_pressure, simulated_time,                  &
                time_since_reference_point, urban_surface,                      &
                use_free_convection_scaling, zeta_max, zeta_min
@@ -117,5 +120,5 @@
 
     USE indices,                                                               &
-        ONLY:  nxl, nxr, nys, nyn, nzb
+        ONLY:  nzt
 
     USE kinds
@@ -1856,6 +1859,10 @@
        IMPLICIT NONE
 
-       CHARACTER (LEN = *), INTENT(IN)       :: z_char       !< string identifier to identify z level
-       INTEGER(iwp)                          :: i, j, k, m   !< running indices
+       CHARACTER (LEN = *), INTENT(IN) :: z_char !< string identifier to identify z level
+       INTEGER(iwp)                    :: i      !< grid index x-dimension
+       INTEGER(iwp)                    :: j      !< grid index y-dimension 
+       INTEGER(iwp)                    :: k      !< grid index z-dimension
+       INTEGER(iwp)                    :: kk     !< running index along the z-dimension
+       INTEGER(iwp)                    :: m      !< running index for surface elements
 
        
@@ -1873,10 +1880,12 @@
                 surf%pt_10cm(m) = surf%pt_surface(m) + surf%ts(m) / kappa      &
                                    * ( LOG( 0.1_wp /  surf%z0h(m) )            &
-                                  - psi_h( 0.1_wp / surf%ol(m) )               &
+                                     - psi_h( 0.1_wp / surf%ol(m) )            &
                                      + psi_h( surf%z0h(m) / surf%ol(m) ) )
                                     
              ENDDO
 
-
+!
+!--       2-m temperature. Note, this is only calculated for output reasons at
+!--       horizontal upward-facing surfaces. 
           CASE ( '2m' )
       
@@ -1886,9 +1895,32 @@
                 j = surf%j(m)
                 k = surf%k(m)
-
-                surf%pt_2m(m) = surf%pt_surface(m) + surf%ts(m) / kappa        &
+!
+!--             If 2-m level is below the first grid level, MOST is 
+!--             used for calculation of 2-m temperature.
+                IF ( surf%z_mo(m) > 2.0_wp )  THEN
+                   surf%pt_2m(m) = surf%pt_surface(m) + surf%ts(m) / kappa     &
                                    * ( LOG( 2.0_wp /  surf%z0h(m) )            &
                                      - psi_h( 2.0_wp / surf%ol(m) )            &
                                      + psi_h( surf%z0h(m) / surf%ol(m) ) )
+!
+!--             If 2-m level is above the first grid level, 2-m temperature
+!--             is linearly interpolated between the two nearest vertical grid
+!--             levels. Note, since 2-m temperature is only computed for
+!--             horizontal upward-facing surfaces, only a vertical 
+!--             interpolation is necessary. 
+                ELSE
+!
+!--                zw(k-1) defines the height of the surface. 
+                   kk = k
+                   DO WHILE ( zu(kk) - zw(k-1) < 2.0_wp  .AND.  kk <= nzt )
+                      kk = kk + 1 
+                   ENDDO               
+!
+!--                kk defines the index of the first grid level >= 2m. 
+                   surf%pt_2m(m) = pt(kk-1,j,i) +                              &
+                                 ( zw(k-1) + 2.0_wp - zu(kk-1)     ) *         &
+                                 ( pt(kk,j,i)       - pt(kk-1,j,i) ) /         &
+                                 ( zu(kk)           - zu(kk-1)     )
+                ENDIF
 
              ENDDO
