Index: palm/trunk/SOURCE/land_surface_model_mod.f90
===================================================================
--- palm/trunk/SOURCE/land_surface_model_mod.f90	(revision 2876)
+++ palm/trunk/SOURCE/land_surface_model_mod.f90	(revision 2881)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Bugfix: wrong loop structure for soil moisture calculation
+! 
+! 2805 2018-02-14 17:00:09Z suehring
 ! Bugfix in initialization of roughness over water surfaces
 ! 
@@ -4779,79 +4782,74 @@
              ENDDO
 
-          ENDIF
-
-       ENDDO
-
-
-       DO  m = 1, surf%ns
-
-          IF (  .NOT.  surf%water_surface(m)  .AND.  calc_soil_moisture )  THEN
-
-
-!
-!--          Prognostic equation for soil moisture content. Only performed,
-!--          when humidity is enabled in the atmosphere.
-             IF ( humidity )  THEN
-!
-!--             Calculate soil diffusivity (lambda_w) at the _layer level 
-!--             using linear interpolation. To do: replace this with
-!--             ECMWF-IFS Eq. 8.81
-                DO  k = nzb_soil, nzt_soil-1
-                   surf%lambda_w(k,m) = ( lambda_temp(k+1) + lambda_temp(k) )  &
-                                        * 0.5_wp
-                   surf%gamma_w(k,m)  = ( gamma_temp(k+1)  +  gamma_temp(k) )  &
-                                        * 0.5_wp
-                ENDDO
-!
-!
-!--             In case of a closed bottom (= water content is conserved), 
-!--             set hydraulic conductivity to zero to that no water will be 
-!--             lost in the bottom layer. As gamma_w is always a positive value,
-!--             it cannot be set to zero in case of purely dry soil since this
-!--             would cause accumulation of (non-existing) water in the lowest
-!--             soil layer
-                IF ( conserve_water_content .AND.                              &
-                     surf_m_soil%var_2d(nzt_soil,m) /= 0.0_wp )  THEN
-
-                   surf%gamma_w(nzt_soil,m) = 0.0_wp
-                ELSE
-                   surf%gamma_w(nzt_soil,m) = gamma_temp(nzt_soil)
-                ENDIF     
-
-!--             The root extraction (= root_extr * qsws_veg / (rho_l     
-!--             * l_v)) ensures the mass conservation for water. The         
-!--             transpiration of plants equals the cumulative withdrawals by 
-!--             the roots in the soil. The scheme takes into account the 
-!--             availability of water in the soil layers as well as the root 
-!--             fraction in the respective layer. Layer with moisture below 
-!--             wilting point will not contribute, which reflects the 
-!--             preference of plants to take water from moister layers.
-!
-!--             Calculate the root extraction (ECMWF 7.69, the sum of 
-!--             root_extr = 1). The energy balance solver guarantees a 
-!--             positive transpiration, so that there is no need for an 
-!--             additional check.
-                m_total = 0.0_wp
-                DO  k = nzb_soil, nzt_soil
-                    IF ( surf_m_soil%var_2d(k,m) > surf%m_wilt(k,m) )  THEN
-                       m_total = m_total + surf%root_fr(k,m)                   &
-                                         * surf_m_soil%var_2d(k,m)
-                    ENDIF
-                ENDDO  
-                 IF ( m_total > 0.0_wp )  THEN
+
+             IF (  calc_soil_moisture )  THEN
+
+!
+!--             Prognostic equation for soil moisture content. Only performed,
+!--             when humidity is enabled in the atmosphere.
+                IF ( humidity )  THEN
+!
+!--                Calculate soil diffusivity (lambda_w) at the _layer level 
+!--                using linear interpolation. To do: replace this with
+!--                ECMWF-IFS Eq. 8.81
+                   DO  k = nzb_soil, nzt_soil-1
+                
+                      surf%lambda_w(k,m) = ( lambda_temp(k+1) + lambda_temp(k) )  &
+                                           * 0.5_wp
+                      surf%gamma_w(k,m)  = ( gamma_temp(k+1)  +  gamma_temp(k) )  &
+                                           * 0.5_wp
+                                            
+                   ENDDO
+!
+!
+!--                In case of a closed bottom (= water content is conserved), 
+!--                set hydraulic conductivity to zero to that no water will be 
+!--                lost in the bottom layer. As gamma_w is always a positive value,
+!--                it cannot be set to zero in case of purely dry soil since this
+!--                would cause accumulation of (non-existing) water in the lowest
+!--                soil layer
+                   IF ( conserve_water_content .AND.                           &
+                        surf_m_soil%var_2d(nzt_soil,m) /= 0.0_wp )  THEN
+
+                      surf%gamma_w(nzt_soil,m) = 0.0_wp
+                   ELSE
+                      surf%gamma_w(nzt_soil,m) = gamma_temp(nzt_soil)
+                   ENDIF     
+
+!--                The root extraction (= root_extr * qsws_veg / (rho_l     
+!--                * l_v)) ensures the mass conservation for water. The         
+!--                transpiration of plants equals the cumulative withdrawals by 
+!--                the roots in the soil. The scheme takes into account the 
+!--                availability of water in the soil layers as well as the root 
+!--                fraction in the respective layer. Layer with moisture below 
+!--                wilting point will not contribute, which reflects the 
+!--                preference of plants to take water from moister layers.
+!
+!--                Calculate the root extraction (ECMWF 7.69, the sum of 
+!--                root_extr = 1). The energy balance solver guarantees a 
+!--                positive transpiration, so that there is no need for an 
+!--                additional check.
+                   m_total = 0.0_wp
                    DO  k = nzb_soil, nzt_soil
                       IF ( surf_m_soil%var_2d(k,m) > surf%m_wilt(k,m) )  THEN
-                         root_extr(k) = surf%root_fr(k,m)                      &
-                                      * surf_m_soil%var_2d(k,m) / m_total
-                      ELSE
-                         root_extr(k) = 0.0_wp
+                         m_total = m_total + surf%root_fr(k,m)                 &
+                                * surf_m_soil%var_2d(k,m)
                       ENDIF
-                   ENDDO
-                ENDIF
-!
-!--             Prognostic equation for soil water content m_soil_h.
-                tend(:) = 0.0_wp
-
-                tend(nzb_soil) = ( surf%lambda_w(nzb_soil,m) *   (             &
+                   ENDDO  
+                   IF ( m_total > 0.0_wp )  THEN
+                      DO  k = nzb_soil, nzt_soil
+                         IF ( surf_m_soil%var_2d(k,m) > surf%m_wilt(k,m) )  THEN
+                            root_extr(k) = surf%root_fr(k,m)                   &
+                                           * surf_m_soil%var_2d(k,m) / m_total
+                         ELSE
+                            root_extr(k) = 0.0_wp
+                         ENDIF
+                      ENDDO
+                   ENDIF
+!
+!--                Prognostic equation for soil water content m_soil_h.
+                   tend(:) = 0.0_wp
+
+                   tend(nzb_soil) = ( surf%lambda_w(nzb_soil,m) *   (          &
                          surf_m_soil%var_2d(nzb_soil+1,m)                      &
                          - surf_m_soil%var_2d(nzb_soil,m) )                    &
@@ -4861,7 +4859,6 @@
                             * ddz_soil(nzb_soil)
 
-
-                DO  k = nzb_soil+1, nzt_soil-1
-                   tend(k) = ( surf%lambda_w(k,m) * ( surf_m_soil%var_2d(k+1,m)  &
+                   DO  k = nzb_soil+1, nzt_soil-1
+                      tend(k) = ( surf%lambda_w(k,m) * ( surf_m_soil%var_2d(k+1,m)  &
                              - surf_m_soil%var_2d(k,m) ) * ddz_soil_center(k)    &
                              - surf%gamma_w(k,m)                                 &
@@ -4871,6 +4868,6 @@
                              * surf%qsws_veg(m) * drho_l_lv)                     &
                              ) * ddz_soil(k)
-                ENDDO
-                tend(nzt_soil) = ( - surf%gamma_w(nzt_soil,m)                  &
+                   ENDDO
+                   tend(nzt_soil) = ( - surf%gamma_w(nzt_soil,m)               &
                                    - surf%lambda_w(nzt_soil-1,m)               &
                                    * ( surf_m_soil%var_2d(nzt_soil,m)          &
@@ -4882,5 +4879,5 @@
                                   ) * ddz_soil(nzt_soil)             
 
-                surf_m_soil_p%var_2d(nzb_soil:nzt_soil,m) =                    &
+                   surf_m_soil_p%var_2d(nzb_soil:nzt_soil,m) =                 &
                                        surf_m_soil%var_2d(nzb_soil:nzt_soil,m) &
                                          + dt_3d * ( tsc(2) * tend(:)          &
@@ -4888,26 +4885,30 @@
    
 !
-!--             Account for dry soils (find a better solution here!)
-                DO  k = nzb_soil, nzt_soil
-                   IF ( surf_m_soil_p%var_2d(k,m) < 0.0_wp )  surf_m_soil_p%var_2d(k,m) = 0.0_wp
-                ENDDO
-
-!
-!--             Calculate m_soil tendencies for the next Runge-Kutta step
-                IF ( timestep_scheme(1:5) == 'runge' )  THEN
-                   IF ( intermediate_timestep_count == 1 )  THEN
-                      DO  k = nzb_soil, nzt_soil
-                         surf_tm_soil_m%var_2d(k,m) = tend(k)
-                      ENDDO
-                   ELSEIF ( intermediate_timestep_count <                      &
-                            intermediate_timestep_count_max )  THEN
-                      DO  k = nzb_soil, nzt_soil
-                         surf_tm_soil_m%var_2d(k,m) = -9.5625_wp * tend(k)     &
+!--                Account for dry soils (find a better solution here!)
+                   DO  k = nzb_soil, nzt_soil
+                      IF ( surf_m_soil_p%var_2d(k,m) < 0.0_wp )  surf_m_soil_p%var_2d(k,m) = 0.0_wp
+                   ENDDO
+  
+!
+!--                Calculate m_soil tendencies for the next Runge-Kutta step
+                   IF ( timestep_scheme(1:5) == 'runge' )  THEN
+                      IF ( intermediate_timestep_count == 1 )  THEN
+                         DO  k = nzb_soil, nzt_soil
+                            surf_tm_soil_m%var_2d(k,m) = tend(k)
+                         ENDDO
+                      ELSEIF ( intermediate_timestep_count <                   &
+                               intermediate_timestep_count_max )  THEN
+                         DO  k = nzb_soil, nzt_soil
+                            surf_tm_soil_m%var_2d(k,m) = -9.5625_wp * tend(k)  &
                                                     + 5.3125_wp                &
                                                     * surf_tm_soil_m%var_2d(k,m)
-                      ENDDO
-
+                         ENDDO
+
+                      ENDIF
+                      
                    ENDIF
+                   
                 ENDIF
+
              ENDIF
 
Index: palm/trunk/SOURCE/modules.f90
===================================================================
--- palm/trunk/SOURCE/modules.f90	(revision 2876)
+++ palm/trunk/SOURCE/modules.f90	(revision 2881)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Added flag for switching on/off calculation of soil moisture
+! 
+! 2797 2018-02-08 13:24:35Z suehring
 ! +ghf_av
 ! 
@@ -1214,4 +1217,5 @@
     LOGICAL ::  bc_ns_dirrad = .FALSE.                           !< north-south boundary condition dirichlet/radiation?
     LOGICAL ::  bc_ns_raddir = .FALSE.                           !< north-south boundary condition radiation/dirichlet?
+    LOGICAL ::  calc_soil_moisture_during_spinup = .FALSE.       !< namelist parameter
     LOGICAL ::  call_microphysics_at_all_substeps = .FALSE.      !< namelist parameter
     LOGICAL ::  call_psolver_at_all_substeps = .TRUE.            !< namelist parameter
Index: palm/trunk/SOURCE/parin.f90
===================================================================
--- palm/trunk/SOURCE/parin.f90	(revision 2876)
+++ palm/trunk/SOURCE/parin.f90	(revision 2881)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Added flag for switching on/off calculation of soil moisture
+! 
+! 2849 2018-03-05 10:49:33Z Giersch
 ! Position of d3par namelist in parameter file is unimportant now 
 ! 
@@ -443,4 +446,5 @@
              bottom_salinityflux, building_height, building_length_x,          &
              building_length_y, building_wall_left, building_wall_south,       &
+             calc_soil_moisture_during_spinup,                                 &
              call_psolver_at_all_substeps, call_microphysics_at_all_substeps,  &
              canyon_height,                                                    &
Index: palm/trunk/SOURCE/time_integration_spinup.f90
===================================================================
--- palm/trunk/SOURCE/time_integration_spinup.f90	(revision 2876)
+++ palm/trunk/SOURCE/time_integration_spinup.f90	(revision 2881)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Added flag for switching on/off calculation of soil moisture
+! 
+! 2818 2018-02-19 16:42:36Z maronga
 ! Velocity components near walls/ground are now set to the profiles stored in
 ! u_init and v_init. Activated soil moisture calculation during spinup.
@@ -83,5 +86,6 @@
 
     USE control_parameters,                                                    &
-        ONLY:  averaging_interval_pr, constant_diffusion, constant_flux_layer, &
+        ONLY:  averaging_interval_pr, calc_soil_moisture_during_spinup,        &
+               constant_diffusion, constant_flux_layer,                        &
                coupling_start_time, current_timestep_number,                   &
                data_output_during_spinup, disturbance_created, dopr_n, do_sum, &
@@ -348,21 +352,21 @@
 !--             Call for horizontal upward-facing surfaces
                 CALL lsm_energy_balance( .TRUE., -1 )
-                CALL lsm_soil_model( .TRUE., -1, .TRUE. )
+                CALL lsm_soil_model( .TRUE., -1, calc_soil_moisture_during_spinup )
 !
 !--             Call for northward-facing surfaces
                 CALL lsm_energy_balance( .FALSE., 0 )
-                CALL lsm_soil_model( .FALSE., 0, .TRUE. )
+                CALL lsm_soil_model( .FALSE., 0, calc_soil_moisture_during_spinup )
 !
 !--             Call for southward-facing surfaces
                 CALL lsm_energy_balance( .FALSE., 1 )
-                CALL lsm_soil_model( .FALSE., 1, .TRUE. )
+                CALL lsm_soil_model( .FALSE., 1, calc_soil_moisture_during_spinup )
 !
 !--             Call for eastward-facing surfaces
                 CALL lsm_energy_balance( .FALSE., 2 )
-                CALL lsm_soil_model( .FALSE., 2, .TRUE. )
+                CALL lsm_soil_model( .FALSE., 2, calc_soil_moisture_during_spinup )
 !
 !--             Call for westward-facing surfaces
                 CALL lsm_energy_balance( .FALSE., 3 )
-                CALL lsm_soil_model( .FALSE., 3, .TRUE. )
+                CALL lsm_soil_model( .FALSE., 3, calc_soil_moisture_during_spinup )
 
                 CALL cpu_log( log_point(54), 'land_surface', 'stop' )
