Index: /palm/trunk/SOURCE/average_3d_data.f90
===================================================================
--- /palm/trunk/SOURCE/average_3d_data.f90	(revision 3932)
+++ /palm/trunk/SOURCE/average_3d_data.f90	(revision 3933)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Bugfix in CASE theta_2m*, removal of redundant code
+! 
+! 3773 2019-03-01 08:56:57Z maronga
 ! Added output of theta_2m*_xy_av
 ! 
@@ -440,5 +443,5 @@
 
          CASE ( 'theta_2m*' )
-             IF ( ALLOCATED( tsurf_av ) ) THEN
+             IF ( ALLOCATED( pt_2m_av ) ) THEN
                 DO  i = nxlg, nxrg
                    DO  j = nysg, nyng
@@ -448,5 +451,5 @@
                 CALL exchange_horiz_2d( pt_2m_av, nbgp )
              ENDIF
-             
+
           CASE ( 't*' )
              IF ( ALLOCATED( ts_av ) ) THEN
@@ -512,14 +515,4 @@
              ENDIF
 
-          CASE ( 'theta_2m' )
-             IF ( ALLOCATED( pt_2m_av ) ) THEN
-                DO  i = nxlg, nxrg
-                   DO  j = nysg, nyng
-                      pt_2m_av(j,i) = pt_2m_av(j,i) / REAL( average_count_3d, KIND=wp )
-                   ENDDO
-                ENDDO
-                CALL exchange_horiz_2d( pt_2m_av, nbgp )
-             ENDIF
-             
           CASE ( 'w' )
              IF ( ALLOCATED( w_av ) ) THEN
Index: /palm/trunk/SOURCE/check_parameters.f90
===================================================================
--- /palm/trunk/SOURCE/check_parameters.f90	(revision 3932)
+++ /palm/trunk/SOURCE/check_parameters.f90	(revision 3933)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Alphabetical resorting in CASE, condense settings for theta_2m* into one IF clause
+! 
+! 3885 2019-04-11 11:29:34Z kanani
 ! Changes related to global restructuring of location messages and introduction 
 ! of additional debug messages
@@ -3077,6 +3080,7 @@
              CONTINUE
 
-          CASE ( 'ghf*', 'lwp*', 'ol*', 'qsws*', 'r_a*', 'theta_2m*',          &
-                 'shf*', 'ssws*', 't*', 'tsurf*', 'us*', 'z0*', 'z0h*', 'z0q*' )
+          CASE ( 'ghf*', 'lwp*', 'ol*', 'qsws*', 'r_a*',                       &
+                 'shf*', 'ssws*', 't*', 'theta_2m*', 'tsurf*', 'us*',          &
+                 'z0*', 'z0h*', 'z0q*' )
              IF ( k == 0  .OR.  data_output(i)(ilen-2:ilen) /= '_xy' )  THEN
                 message_string = 'illegal value for data_output: "' //         &
@@ -3117,23 +3121,20 @@
                 CALL message( 'check_parameters', 'PA0361', 1, 2, 0, 6, 0 )
              ENDIF
-
-            
 !
 !--          Activate calculation of 2m temperature if output is requested
              IF ( TRIM( var ) == 'theta_2m*' )  THEN
                 do_output_at_2m = .TRUE.
-             ENDIF             
-
+                unit = 'K'
+             ENDIF
 
              IF ( TRIM( var ) == 'ghf*'   )  unit = 'W/m2'
              IF ( TRIM( var ) == 'lwp*'   )  unit = 'kg/m2'
              IF ( TRIM( var ) == 'ol*'    )  unit = 'm'
-             IF ( TRIM( var ) == 'theta_2m*' )  unit = 'K'            
              IF ( TRIM( var ) == 'qsws*'  )  unit = 'kgm/kgs'
-             IF ( TRIM( var ) == 'r_a*'   )  unit = 's/m'     
+             IF ( TRIM( var ) == 'r_a*'   )  unit = 's/m'
              IF ( TRIM( var ) == 'shf*'   )  unit = 'K*m/s'
              IF ( TRIM( var ) == 'ssws*'  )  unit = 'kg/m2*s'
              IF ( TRIM( var ) == 't*'     )  unit = 'K'
-             IF ( TRIM( var ) == 'tsurf*' )  unit = 'K'  
+             IF ( TRIM( var ) == 'tsurf*' )  unit = 'K'
              IF ( TRIM( var ) == 'us*'    )  unit = 'm/s'
              IF ( TRIM( var ) == 'z0*'    )  unit = 'm'
Index: /palm/trunk/SOURCE/land_surface_model_mod.f90
===================================================================
--- /palm/trunk/SOURCE/land_surface_model_mod.f90	(revision 3932)
+++ /palm/trunk/SOURCE/land_surface_model_mod.f90	(revision 3933)
@@ -25,4 +25,8 @@
 ! -----------------
 ! $Id$
+! Remove unused subroutine and allocation of pt_2m, this is done in surface_mod
+! now (surfaces%pt_2m)
+! 
+! 
 ! Changes related to global restructuring of location messages and introduction 
 ! of additional debug messages
@@ -1017,5 +1021,5 @@
 !-- Public functions
     PUBLIC lsm_boundary_condition, lsm_check_data_output,                      &
-           lsm_check_data_output_pr, lsm_calc_pt_near_surface,                 &
+           lsm_check_data_output_pr,                                           &
            lsm_check_parameters, lsm_define_netcdf_grid, lsm_3d_data_averaging,& 
            lsm_data_output_2d, lsm_data_output_3d, lsm_energy_balance,         &
@@ -1038,8 +1042,4 @@
     END INTERFACE lsm_boundary_condition
 
-    INTERFACE lsm_calc_pt_near_surface
-       MODULE PROCEDURE lsm_calc_pt_near_surface
-    END INTERFACE lsm_calc_pt_near_surface
-    
     INTERFACE lsm_check_data_output
        MODULE PROCEDURE lsm_check_data_output
@@ -5057,5 +5057,4 @@
        ALLOCATE ( surf_lsm_h%r_s(1:surf_lsm_h%ns)                 )
        ALLOCATE ( surf_lsm_h%r_canopy_min(1:surf_lsm_h%ns)        )
-       ALLOCATE ( surf_lsm_h%pt_2m(1:surf_lsm_h%ns)               )
        ALLOCATE ( surf_lsm_h%vegetation_surface(1:surf_lsm_h%ns)  )
        ALLOCATE ( surf_lsm_h%water_surface(1:surf_lsm_h%ns)       )
@@ -7322,34 +7321,4 @@
     END SUBROUTINE calc_z0_water_surface
 
-    
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Calculates 2m temperature for data output at coarse resolution
-!------------------------------------------------------------------------------!
-    SUBROUTINE lsm_calc_pt_near_surface
-
-       IMPLICIT NONE
-
-       INTEGER(iwp)                          :: i, j, k, m   !< running indices
-
-
-       DO  m = 1, surf_lsm_h%ns
-
-          i = surf_lsm_h%i(m)
-          j = surf_lsm_h%j(m)
-          k = surf_lsm_h%k(m)
-
-          surf_lsm_h%pt_2m(m) = surf_lsm_h%pt_surface(m) + surf_lsm_h%ts(m) / kappa &
-                             * ( log( 2.0_wp /  surf_lsm_h%z0h(m) )                 &
-                               - psi_h( 2.0_wp / surf_lsm_h%ol(m) )                 &
-                               + psi_h( surf_lsm_h%z0h(m) / surf_lsm_h%ol(m) ) )
-
-       ENDDO
-
-    END SUBROUTINE lsm_calc_pt_near_surface
-
-    
-    
 !
 !-- Integrated stability function for heat and moisture
Index: /palm/trunk/SOURCE/sum_up_3d_data.f90
===================================================================
--- /palm/trunk/SOURCE/sum_up_3d_data.f90	(revision 3932)
+++ /palm/trunk/SOURCE/sum_up_3d_data.f90	(revision 3933)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Formatting
+! 
+! 3773 2019-03-01 08:56:57Z maronga
 ! Added output of theta_2m*_xy_av
 ! 
@@ -940,5 +943,5 @@
                       ELSEIF ( match_lsm  .AND.  .NOT. match_usm )  THEN
                          m = surf_lsm_h%end_index(j,i)
-                        pt_2m_av(j,i) = pt_2m_av(j,i) +                       &
+                         pt_2m_av(j,i) = pt_2m_av(j,i) +                       &
                                          surf_lsm_h%pt_2m(m)
                       ELSEIF ( match_usm )  THEN
Index: /palm/trunk/SOURCE/surface_mod.f90
===================================================================
--- /palm/trunk/SOURCE/surface_mod.f90	(revision 3932)
+++ /palm/trunk/SOURCE/surface_mod.f90	(revision 3933)
@@ -26,4 +26,8 @@
 ! -----------------
 ! $Id$
+! Add (de)allocation of pt_2m,
+! bugfix: initialize pt_2m
+! 
+! 3833 2019-03-28 15:04:04Z forkel
 ! added USE chem_gasphase_mod (chem_modules will not transport nvar and nspec anymore)
 ! 
@@ -1321,4 +1325,7 @@
 !--    Salinity surface flux
        IF ( ocean_mode )  DEALLOCATE ( surfaces%sasws )
+!
+!--    2-m potential temperature (for output quantity theta_2m*)
+       IF ( do_output_at_2m )  DEALLOCATE ( surfaces%pt_2m )
 
     END SUBROUTINE deallocate_surface_attributes_h
@@ -1449,4 +1456,11 @@
 !--    Salinity surface flux
        IF ( ocean_mode )  ALLOCATE ( surfaces%sasws(1:surfaces%ns) )
+!
+!--    2-m potential temperature (for output quantity theta_2m*)
+       IF ( do_output_at_2m )  THEN
+          ALLOCATE ( surfaces%pt_2m(1:surfaces%ns) )
+          surfaces%pt_2m = -9999.0_wp  !< output array (for theta_2m*) must be initialized here,
+                                       !< otherwise simulation crash at do2d_at_begin with spinup=.F.
+       ENDIF
 
     END SUBROUTINE allocate_surface_attributes_h
Index: /palm/trunk/SOURCE/urban_surface_mod.f90
===================================================================
--- /palm/trunk/SOURCE/urban_surface_mod.f90	(revision 3932)
+++ /palm/trunk/SOURCE/urban_surface_mod.f90	(revision 3933)
@@ -28,4 +28,7 @@
 ! -----------------
 ! $Id$
+! Remove allocation of pt_2m, this is done in surface_mod now (surfaces%pt_2m)
+! 
+! 3921 2019-04-18 14:21:10Z suehring
 ! Undo accidentally commented initialization  
 ! 
@@ -1160,5 +1163,4 @@
         ALLOCATE ( surf_usm_h%qsws_eb(1:surf_usm_h%ns)          )
         ALLOCATE ( surf_usm_h%pt_10cm(1:surf_usm_h%ns)          ) 
-        ALLOCATE ( surf_usm_h%pt_2m(1:surf_usm_h%ns)            ) 
 
 !
