Index: palm/trunk/SOURCE/Makefile
===================================================================
--- palm/trunk/SOURCE/Makefile	(revision 1238)
+++ palm/trunk/SOURCE/Makefile	(revision 1239)
@@ -20,5 +20,5 @@
 # Current revisions:
 # ------------------
-# 
+# +nudging, ls_forcing
 #
 # Former revisions:
@@ -158,6 +158,7 @@
 	lpm_set_attributes.f90 lpm_sort_arrays.f90 \
 	lpm_write_exchange_statistics.f90 lpm_write_restart_file.f90 \
-	message.f90 microphysics.f90 modules.f90 netcdf.f90 package_parin.f90 \
-	palm.f90 parin.f90 plant_canopy_model.f90 poisfft.f90 \
+        ls_forcing.f90 \
+	message.f90 microphysics.f90 modules.f90 netcdf.f90 nudging.f90 \
+        package_parin.f90 palm.f90 parin.f90 plant_canopy_model.f90 poisfft.f90 \
 	poismg.f90 prandtl_fluxes.f90 pres.f90 print_1d.f90 \
 	production_e.f90 prognostic_equations.f90 random_function.f90 \
@@ -303,15 +304,17 @@
 lpm_write_exchange_statistics.o: modules.o
 lpm_write_restart_file.o: modules.o
+ls_forcing.o: modules.o
 message.o: modules.o
 microphysics.o: modules.o
 modules.o: modules.f90
 netcdf.o: modules.o
+nudging.o: modules.o
 package_parin.o: modules.o
-palm.o: modules.o
+palm.o: modules.o nudging.o ls_forcing.o
 parin.o: modules.o
 plant_canopy_model.o: modules.o
 poisfft.o: modules.o fft_xy.o tridia_solver.o
 poismg.o: modules.o
-prandtl_fluxes.o: modules.o
+prandtl_fluxes.o: modules.o ls_forcing.o
 pres.o: modules.o poisfft.o
 print_1d.o: modules.o
@@ -322,5 +325,5 @@
 	diffusion_e.o diffusion_s.o diffusion_u.o diffusion_v.o diffusion_w.o \
 	eqn_state_seawater.o impact_of_latent_heat.o microphysics.o \
-        plant_canopy_model.o production_e.o subsidence.o user_actions.o
+        nudging.o plant_canopy_model.o production_e.o subsidence.o user_actions.o
 random_gauss.o: random_function.o
 read_3d_binary.o: modules.o random_function.o
@@ -336,5 +339,5 @@
 temperton_fft.o: modules.o
 time_integration.o: modules.o advec_ws.o buoyancy.o interaction_droplets_ptq.o \
-	production_e.o prognostic_equations.o user_actions.o
+	ls_forcing.o production_e.o prognostic_equations.o user_actions.o
 timestep.o: modules.o
 timestep_scheme_steering.o: modules.o
Index: palm/trunk/SOURCE/boundary_conds.f90
===================================================================
--- palm/trunk/SOURCE/boundary_conds.f90	(revision 1238)
+++ palm/trunk/SOURCE/boundary_conds.f90	(revision 1239)
@@ -20,5 +20,5 @@
 ! Current revisions:
 ! -----------------
-!
+! Adjust ug and vg at each timestep in case of large_scale_forcing
 !  
 ! Former revisions:
@@ -147,4 +147,8 @@
         u_p(nzt+1,:,:) = u_init(nzt+1)
         v_p(nzt+1,:,:) = v_init(nzt+1)
+        IF ( large_scale_forcing) THEN
+           u_p(nzt+1,:,:) = ug(nzt+1)
+           v_p(nzt+1,:,:) = vg(nzt+1)
+        END IF
        !$acc end kernels
     ELSE
Index: palm/trunk/SOURCE/buoyancy.f90
===================================================================
--- palm/trunk/SOURCE/buoyancy.f90	(revision 1238)
+++ palm/trunk/SOURCE/buoyancy.f90	(revision 1239)
@@ -20,4 +20,6 @@
 ! Currrent revisions:
 ! ------------------
+! Generalize calc_mean_profile for wider use: use additional steering 
+! character loc
 !
 !
@@ -344,5 +346,5 @@
 
 
-    SUBROUTINE calc_mean_profile( var, pr )
+    SUBROUTINE calc_mean_profile( var, pr, loc )
 
 !------------------------------------------------------------------------------!
@@ -363,4 +365,5 @@
 
        INTEGER ::  i, j, k, omp_get_thread_num, pr, tn
+       CHARACTER (LEN=*) ::  loc
 #if defined( __nopointer )
        REAL, DIMENSION(:,:,:) ::  var
@@ -414,5 +417,22 @@
        ENDIF
 
-       ref_state(:)  = hom(:,1,pr,0)   ! this is used in the buoyancy term
+       SELECT CASE ( loc )
+
+          CASE ( 'time_int' )
+
+             ref_state(:)  = hom(:,1,pr,0)   ! this is used in the buoyancy term
+
+
+          CASE ( 'nudging' )
+             !nothing to be done
+
+
+          CASE DEFAULT
+             message_string = 'unknown location "' // loc // '"'
+             CALL message( 'calc_mean_profile', 'PA0379', 1, 2, 0, 6, 0 )
+
+       END SELECT
+
+
 
     END SUBROUTINE calc_mean_profile
Index: palm/trunk/SOURCE/check_parameters.f90
===================================================================
--- palm/trunk/SOURCE/check_parameters.f90	(revision 1238)
+++ palm/trunk/SOURCE/check_parameters.f90	(revision 1239)
@@ -20,5 +20,6 @@
 ! Current revisions:
 ! -----------------
-!
+! profiles of ug and vg added
+! checks for nudging and large scale forcing from external file
 !
 ! Former revisions:
@@ -311,4 +312,5 @@
     USE statistics
     USE subsidence_mod
+    USE statistics
     USE transpose_indices
 
@@ -1606,5 +1608,21 @@
     ENDIF
 
-    IF ( surface_heatflux == 9999999.9 )  constant_heatflux     = .FALSE.
+    IF (myid == 0 )THEN
+      PRINT*, "vorher surface_heatflux: ", surface_heatflux 
+    END IF
+
+    IF ( surface_heatflux == 9999999.9  .AND.  .NOT. large_scale_forcing )  THEN
+        constant_heatflux     = .FALSE.
+    ELSE
+        constant_heatflux     = .TRUE.
+        IF ( TRIM( initializing_actions ) /= 'read_restart_data' ) THEN
+           surface_heatflux      = shf_surf(1)
+        ENDIF
+    ENDIF
+
+    IF (myid == 0 )THEN
+      PRINT*, "nachher surface_heatflux: ", surface_heatflux 
+    END IF
+
     IF ( top_heatflux     == 9999999.9 )  constant_top_heatflux = .FALSE.
 
@@ -1726,5 +1744,13 @@
        ENDIF
 
-       IF ( surface_waterflux == 9999999.9 )  constant_waterflux = .FALSE.
+       IF ( surface_waterflux == 9999999.9  .AND.  &
+                             .NOT. large_scale_forcing )  THEN
+           constant_waterflux     = .FALSE.
+       ELSE
+           constant_waterflux     = .TRUE.
+           IF ( TRIM( initializing_actions ) /= 'read_restart_data' ) THEN
+              surface_waterflux      = qsws_surf(1)
+           ENDIF
+       ENDIF
 
 !
@@ -2666,4 +2692,14 @@
              ENDIF
 
+          CASE ( 'ug' )
+             dopr_index(i) = 78
+             dopr_unit(i)  = 'm/s'
+             hom(:,2,78,:) = SPREAD( zu, 2, statistic_regions+1 )
+
+          CASE ( 'vg' )
+             dopr_index(i) = 79
+             dopr_unit(i)  = 'm/s'
+             hom(:,2,79,:) = SPREAD( zu, 2, statistic_regions+1 )
+
           CASE DEFAULT
 
@@ -3597,4 +3633,37 @@
 
 !
+!-- Check nudging and large scale forcing from external file
+    IF ( nudging .AND. ( .NOT. large_scale_forcing ) )  THEN
+       message_string = 'Nudging requires large_scale_forcing = .T.. &'// &
+                        'Surface fluxes and geostrophic wind should be &'// &
+                        'prescribed in file LSF_DATA'
+       CALL message( 'check_parameters', 'PA0374', 1, 2, 0, 6, 0 )
+    ENDIF
+
+    IF ( large_scale_forcing .AND. ( bc_lr /= 'cyclic'  .OR. &
+                                    bc_ns /= 'cyclic' ) )  THEN
+       message_string = 'Non-cyclic lateral boundaries do not allow for &' // &
+                        'the usage of large scale forcing from external file.'
+       CALL message( 'check_parameters', 'PA0375', 1, 2, 0, 6, 0 )
+     ENDIF
+
+    IF ( large_scale_forcing .AND. ( .NOT. humidity ) )  THEN
+       message_string = 'The usage of large scale forcing from external &'//& 
+                        'file LSF_DATA requires humidity = .T..'
+       CALL message( 'check_parameters', 'PA0376', 1, 2, 0, 6, 0 )
+     ENDIF
+
+    IF ( large_scale_forcing .AND. topography /= 'flat' )  THEN
+       message_string = 'The usage of large scale forcing from external &'//& 
+                        'file LSF_DATA is not implemented for non-flat topography'
+       CALL message( 'check_parameters', 'PA0377', 1, 2, 0, 6, 0 )
+    ENDIF
+
+    IF ( large_scale_forcing .AND.  ocean  )  THEN
+       message_string = 'The usage of large scale forcing from external &'//& 
+                        'file LSF_DATA is not implemented for ocean runs'
+       CALL message( 'check_parameters', 'PA0378', 1, 2, 0, 6, 0 )
+    ENDIF
+!
 !-- Check &userpar parameters
     CALL user_check_parameters
Index: palm/trunk/SOURCE/flow_statistics.f90
===================================================================
--- palm/trunk/SOURCE/flow_statistics.f90	(revision 1238)
+++ palm/trunk/SOURCE/flow_statistics.f90	(revision 1239)
@@ -21,5 +21,5 @@
 ! Current revisions:
 ! -----------------
-!
+! Output of ug and vg
 !
 ! Former revisions:
@@ -563,4 +563,5 @@
           ENDDO
        ENDIF
+
 !
 !--    Horizontally averaged profiles of the vertical fluxes
@@ -886,5 +887,4 @@
 
        ENDIF
-
 
 !
@@ -1156,4 +1156,6 @@
        hom(:,1,76,sr) = sums(:,76)     ! prr (precipitation rate)
                                        ! 77 is initial density profile
+       hom(:,1,78,sr) = ug             ! ug
+       hom(:,1,79,sr) = vg             ! vg
 
        hom(:,1,pr_palm-1,sr) = sums(:,pr_palm-1)
@@ -2774,4 +2776,6 @@
        hom(:,1,76,sr) = sums(:,76)     ! prr (precipitation rate)
                                        ! 77 is initial density profile
+       hom(:,1,78,sr) = ug             ! ug
+       hom(:,1,79,sr) = vg             ! vg
 
        hom(:,1,pr_palm-1,sr) = sums(:,pr_palm-1)
Index: palm/trunk/SOURCE/header.f90
===================================================================
--- palm/trunk/SOURCE/header.f90	(revision 1238)
+++ palm/trunk/SOURCE/header.f90	(revision 1239)
@@ -20,5 +20,5 @@
 ! Current revisions:
 ! -----------------
-!
+! output for nudging + large scale forcing from external file
 !
 ! Former revisions:
@@ -428,4 +428,12 @@
         WRITE ( io, 154 )
     ENDIF
+    IF ( nudging )  THEN
+        WRITE ( io, 155 )
+        WRITE ( io, 156 )
+    ENDIF
+    IF ( large_scale_forcing )  THEN
+        WRITE ( io, 157 )
+        WRITE ( io, 158 )
+    ENDIF
     WRITE ( io, 99 )
 
@@ -706,9 +714,17 @@
        WRITE ( io, 303 )
        IF ( constant_heatflux )  THEN
-          WRITE ( io, 306 )  surface_heatflux
+          IF ( large_scale_forcing .AND. lsf_surf ) THEN
+             WRITE ( io, 306 )  shf(0,0)
+          ELSE
+             WRITE ( io, 306 )  surface_heatflux
+          ENDIF
           IF ( random_heatflux )  WRITE ( io, 307 )
        ENDIF
        IF ( humidity  .AND.  constant_waterflux )  THEN
-          WRITE ( io, 311 ) surface_waterflux
+          IF ( large_scale_forcing .AND. lsf_surf ) THEN
+             WRITE ( io, 311 ) qsws(0,0)
+          ELSE
+             WRITE ( io, 311 ) surface_waterflux
+          ENDIF
        ENDIF
        IF ( passive_scalar  .AND.  constant_waterflux )  THEN
@@ -1288,6 +1304,10 @@
     ENDDO
 
-    WRITE ( io, 423 )  TRIM( coordinates ), TRIM( ugcomponent ), &
-                       TRIM( gradients ), TRIM( slices )
+    IF ( .NOT. large_scale_forcing ) THEN
+       WRITE ( io, 423 )  TRIM( coordinates ), TRIM( ugcomponent ), &
+                          TRIM( gradients ), TRIM( slices )
+    ELSE
+       WRITE ( io, 429 ) 
+    ENDIF
 
 !-- Profile of the geostrophic wind (component vg)
@@ -1320,6 +1340,8 @@
     ENDDO
 
-    WRITE ( io, 424 )  TRIM( coordinates ), TRIM( vgcomponent ), &
-                       TRIM( gradients ), TRIM( slices )
+    IF ( .NOT. large_scale_forcing ) THEN
+       WRITE ( io, 424 )  TRIM( coordinates ), TRIM( vgcomponent ), &
+                          TRIM( gradients ), TRIM( slices )
+    ENDIF
 
 !
@@ -1357,6 +1379,10 @@
     ENDDO
 
-    WRITE ( io, 420 )  TRIM( coordinates ), TRIM( temperatures ), &
-                       TRIM( gradients ), TRIM( slices )
+    IF ( .NOT. nudging ) THEN
+       WRITE ( io, 420 )  TRIM( coordinates ), TRIM( temperatures ), &
+                          TRIM( gradients ), TRIM( slices )
+    ELSE
+       WRITE ( io, 428 ) 
+    ENDIF
 
 !
@@ -1392,6 +1418,8 @@
 
        IF ( humidity )  THEN
-          WRITE ( io, 421 )  TRIM( coordinates ), TRIM( temperatures ), &
-                             TRIM( gradients ), TRIM( slices )
+          IF ( .NOT. nudging ) THEN
+             WRITE ( io, 421 )  TRIM( coordinates ), TRIM( temperatures ), &
+                                TRIM( gradients ), TRIM( slices )
+          ENDIF
        ELSE
           WRITE ( io, 422 )  TRIM( coordinates ), TRIM( temperatures ), &
@@ -1705,4 +1733,9 @@
                   'prognostic equation for')
 154 FORMAT ('     the potential temperature')
+155 FORMAT (' --> Nudging is used - initial profiles for u, v, pt and q ',& 
+                  'correspond to the')
+156 FORMAT ('     first profiles in NUDGING_DATA')
+157 FORMAT (' --> Large scale forcing from external file (LSF_DATA) is used: ')
+158 FORMAT ('     prescribed surfaces fluxes and geostrophic wind components')
 200 FORMAT (//' Run time and time step information:'/ &
              ' ----------------------------------'/)
@@ -1957,4 +1990,8 @@
 427 FORMAT (/'    Initial wind profiles (u,v) are interpolated from given'// &
                   ' profiles')
+428 FORMAT (/'    Initial profiles (u, v, pt, q) are taken from file '/ &
+             '    NUDGING_DATA')
+429 FORMAT (/'    Geostrophic wind profiles (ug, vg) are are taken from file '/ &
+             '    LSF_DATA_DATA')
 430 FORMAT (//' Cloud physics quantities / methods:'/ &
               ' ----------------------------------'/)
Index: palm/trunk/SOURCE/init_3d_model.f90
===================================================================
--- palm/trunk/SOURCE/init_3d_model.f90	(revision 1238)
+++ palm/trunk/SOURCE/init_3d_model.f90	(revision 1239)
@@ -23,5 +23,6 @@
 ! Current revisions:
 ! ------------------
-!
+! Overwrite initial profiles in case of nudging
+! Inititialize shf and qsws in case of large_scale_forcing
 !
 ! Former revisions:
@@ -260,4 +261,5 @@
     USE indices
     USE interfaces
+    USE ls_forcing_mod
     USE model_1d
     USE netcdf_control
@@ -780,4 +782,20 @@
        ELSEIF ( INDEX(initializing_actions, 'set_constant_profiles') /= 0 ) &
        THEN
+
+!
+!--       Overwrite initial profiles in case of nudging
+          IF ( nudging ) THEN
+             pt_init = ptnudge(:,1)
+             u_init  = unudge(:,1)
+             v_init  = vnudge(:,1)
+             IF ( humidity  .OR.  passive_scalar )  THEN
+                q_init = qnudge(:,1)
+             ENDIF
+
+             WRITE( message_string, * ) 'Initial profiles of u, v and ', &
+                 'scalars from NUDGING_DATA are used.'
+             CALL message( 'init_3d_model', 'PA0370', 0, 0, 0, 6, 0 )
+          ENDIF
+
 !
 !--       Use constructed initial profiles (velocity constant with height,
@@ -873,4 +891,11 @@
           IF ( sloping_surface )  CALL init_slope
 
+          IF(myid==0) THEN
+            PRINT*,"initial profiles from init_3d_model"
+            DO k=nzb, nzt+1
+                PRINT*, k, u(k,0,0), v(k,0,0), pt(k,0,0), q(k,0,0)
+            ENDDO
+          ENDIF
+
        ELSEIF ( INDEX(initializing_actions, 'by_user') /= 0 ) &
        THEN
@@ -948,4 +973,10 @@
              ELSE
                 shf = surface_heatflux
+!
+!--             Initialize shf with data from external file LSF_DATA
+                IF ( large_scale_forcing .AND. lsf_surf ) THEN
+                   CALL ls_forcing_surf ( simulated_time )
+                ENDIF
+
 !
 !--             Over topography surface_heatflux is replaced by wall_heatflux(0)
Index: palm/trunk/SOURCE/ls_forcing.f90
===================================================================
--- palm/trunk/SOURCE/ls_forcing.f90	(revision 1239)
+++ palm/trunk/SOURCE/ls_forcing.f90	(revision 1239)
@@ -0,0 +1,281 @@
+ MODULE ls_forcing_mod
+
+!--------------------------------------------------------------------------------!
+! This file is part of PALM.
+!
+! PALM is free software: you can redistribute it and/or modify it under the terms
+! of the GNU General Public License as published by the Free Software Foundation,
+! either version 3 of the License, or (at your option) any later version.
+!
+! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
+! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+!
+! You should have received a copy of the GNU General Public License along with
+! PALM. If not, see <http://www.gnu.org/licenses/>.
+!
+! Copyright 1997-2012  Leibniz University Hannover
+!--------------------------------------------------------------------------------!
+!
+! Current revisions:
+! ------------------
+!
+!
+! Former revisions:
+! -----------------
+! $Id$
+!
+!
+! Description:
+! ------------
+! Calculates large scale forcings (geostrophic wind and subsidence velocity) as 
+! well as surfaces fluxes dependend on time given in an external file (LSF_DATA).
+! Code is based in parts on DALES and UCLA-LES.
+!--------------------------------------------------------------------------------!
+
+    PRIVATE
+    PUBLIC init_ls_forcing, ls_forcing_surf, ls_forcing_vert 
+    SAVE
+
+
+ CONTAINS
+
+    SUBROUTINE init_ls_forcing
+
+       USE arrays_3d
+       USE control_parameters
+       USE cpulog
+       USE indices
+       USE interfaces
+       USE pegrid
+       USE user
+
+       IMPLICIT NONE
+
+       INTEGER :: finput = 90, ierrn, k, t 
+       CHARACTER (100):: chmess
+       CHARACTER(1) :: hash
+       REAL :: r_dummy, fac
+       REAL :: highheight, highug_vert, highvg_vert, highwsubs_vert
+       REAL :: lowheight, lowug_vert, lowvg_vert, lowwsubs_vert
+
+       ALLOCATE( p_surf(0:nlsf), pt_surf(0:nlsf), q_surf(0:nlsf),         &
+                 qsws_surf(0:nlsf), shf_surf(0:nlsf), time_vert(0:nlsf),  &
+                 time_surf(0:nlsf), ug_vert(nzb:nzt+1,0:nlsf),            &
+                 vg_vert(nzb:nzt+1,0:nlsf), wsubs_vert(nzb:nzt+1,0:nlsf) )
+
+       p_surf = 0.0; pt_surf = 0.0; q_surf = 0.0; qsws_surf = 0.0
+       shf_surf = 0.0; time_vert = 0.0; time_surf = 0.0; ug_vert = 0.0
+       vg_vert = 0.0; wsubs_vert = 0.0
+
+
+       OPEN (finput, FILE='LSF_DATA', STATUS='OLD', &
+              FORM='FORMATTED', IOSTAT=ierrn)
+
+       IF (ierrn /= 0 ) THEN
+          message_string = 'file LSF_DATA does not exist'
+          CALL message( 'ls_forcing', 'PA0368', 1, 2, 0, 6, 0 )
+       ENDIF
+
+       ierrn = 0
+!
+!--    First three lines of LSF_DATA contain header
+       READ( finput, FMT='(a100)', IOSTAT=ierrn ) chmess
+       READ( finput, FMT='(a100)', IOSTAT=ierrn ) chmess
+       READ( finput, FMT='(a100)', IOSTAT=ierrn ) chmess
+
+       IF (ierrn /= 0 ) THEN
+          message_string = 'errors in file LSF_DATA'
+          CALL message( 'ls_forcing', 'PA0369', 1, 2, 0, 6, 0 )
+       ENDIF
+
+!
+!--    Surface values are read in
+       t     = 0
+       ierrn = 0
+
+       DO WHILE ( time_surf(t) < end_time )
+          t = t + 1
+          READ( finput, *, IOSTAT = ierrn ) time_surf(t), shf_surf(t), &
+                                             qsws_surf(t), pt_surf(t),  &
+                                             q_surf(t), p_surf(t)
+
+          IF ( ierrn < 0 ) THEN
+            WRITE( message_string, * ) 'No time dependend surface variables ',&
+                              'in&LSF_DATA for end of run found'
+
+             CALL message( 'ls_forcing', 'PA0370', 1, 2, 0, 6, 0 )
+          ENDIF
+       ENDDO
+
+
+       IF ( time_surf(1) > end_time ) THEN
+          WRITE( message_string, * ) 'No time dependend surface variables in ',  &
+                                     '&LSF_DATA for end of run found - ',  &
+                                     'lsf_surf is set to FALSE'
+          CALL message( 'ls_forcing', 'PA0371', 0, 0, 0, 6, 0 )
+          lsf_surf = .FALSE.
+       ENDIF
+
+!
+!--    Go to the end of the list with surface variables
+       DO WHILE ( ierrn == 0 )
+          READ (finput, *, IOSTAT = ierrn) r_dummy
+       ENDDO
+
+!
+!--    Profiles of ug, vg and w_subs are read in (large scale forcing)
+
+       t = 0
+       DO WHILE (time_vert(t) < end_time)
+          t = t + 1
+          hash = "#"
+          ierrn = 1 ! not zero
+!
+!--       Search for the next line consisting of "# time", 
+!--       from there onwards the profiles will be read
+          DO WHILE ( .NOT. ( hash == "#" .AND. ierrn == 0 ) ) 
+             READ( finput, *, IOSTAT=ierrn ) hash, time_vert(t)
+             IF ( ierrn < 0 ) THEN 
+                WRITE( message_string, * ) 'No time dependend vertical profiles',&
+                                 ' in&LSF_DATA for end of run found'
+                CALL message( 'ls_forcing', 'PA0372', 1, 2, 0, 6, 0 )
+             ENDIF
+          ENDDO
+
+          IF ( t == 1 .AND. time_vert(t) > end_time ) EXIT
+
+          READ( finput, *, IOSTAT=ierrn ) lowheight, lowug_vert, lowvg_vert, &
+                                          lowwsubs_vert
+          IF (ierrn /= 0 ) THEN
+             message_string = 'errors in file LSF_DATA'
+             CALL message( 'nudging', 'PA0369', 1, 2, 0, 6, 0 )
+          ENDIF
+
+          READ( finput, *, IOSTAT=ierrn ) highheight, highug_vert, highvg_vert, &
+                                          highwsubs_vert
+      
+          IF (ierrn /= 0 ) THEN
+             message_string = 'errors in file LSF_DATA'
+             CALL message( 'nudging', 'PA0369', 1, 2, 0, 6, 0 )
+          ENDIF
+
+          DO  k = nzb, nzt+1
+             IF ( highheight < zu(k) ) THEN
+                lowheight     = highheight
+                lowug_vert    = highug_vert
+                lowvg_vert    = highvg_vert
+                lowwsubs_vert = highwsubs_vert
+
+                ierrn = 0
+                READ( finput, *, IOSTAT=ierrn ) highheight, highug_vert, &
+                                                highvg_vert, highwsubs_vert
+
+                IF (ierrn /= 0 ) THEN
+                   message_string = 'errors in file LSF_DATA'
+                   CALL message( 'nudging', 'PA0369', 1, 2, 0, 6, 0 )
+                ENDIF
+
+             ENDIF
+
+!
+!--          Interpolation of prescribed profiles in space 
+             fac = (highheight-zu(k))/(highheight - lowheight)
+
+             ug_vert(k,t)    = fac*lowug_vert    + (1-fac)*highug_vert
+             vg_vert(k,t)    = fac*lowvg_vert    + (1-fac)*highvg_vert
+             wsubs_vert(k,t) = fac*lowwsubs_vert + (1-fac)*highwsubs_vert
+
+          ENDDO
+
+       ENDDO 
+
+       IF ( time_vert(1) > end_time ) THEN
+          WRITE( message_string, * ) 'Time dependent large scale profile ',&
+                            'forcing from&LSF_DATA sets in after end of ' ,&
+                            'simulation - lsf_vert is set to FALSE'
+          CALL message( 'ls_forcing', 'PA0373', 0, 0, 0, 6, 0 )
+          lsf_vert = .FALSE.
+       ENDIF
+
+       CLOSE( finput )
+
+
+    END SUBROUTINE init_ls_forcing 
+
+
+    SUBROUTINE ls_forcing_surf ( time )
+
+       USE arrays_3d
+       USE control_parameters
+       USE cpulog
+       USE indices
+       USE interfaces
+       USE pegrid
+       USE user
+
+       IMPLICIT NONE
+
+       REAL, INTENT(in)  :: time
+       REAL :: fac
+       INTEGER :: t
+
+!
+!--    Interpolation in time of LSF_DATA at the surface
+       t = 1
+       DO WHILE ( time > time_surf(t) )
+          t = t + 1
+       ENDDO
+       IF ( time /= time_surf(t) ) THEN
+         t = t - 1
+       ENDIF
+
+       fac = ( time -time_surf(t) ) / ( time_surf(t+1) - time_surf(t) )
+
+       shf              = shf_surf(t) + fac * ( shf_surf(t+1) - shf_surf(t) )
+       qsws             = qsws_surf(t) + fac * ( qsws_surf(t+1) - qsws_surf(t) )
+       pt_surface       = pt_surf(t) + fac * ( pt_surf(t+1) - pt_surf(t) )
+       surface_pressure = p_surf(t) + fac * ( p_surf(t+1) - p_surf(t) )
+
+    END SUBROUTINE ls_forcing_surf 
+
+
+    SUBROUTINE ls_forcing_vert ( time )
+
+       USE arrays_3d
+       USE control_parameters
+       USE cpulog
+       USE indices
+       USE interfaces
+       USE pegrid
+       USE user
+
+       IMPLICIT NONE
+
+       REAL, INTENT(in)  :: time
+       REAL :: fac
+       INTEGER :: t
+
+!
+!--    Interpolation in time of LSF_DATA for ug, vg and w_subs
+       t = 1
+       DO WHILE ( time > time_vert(t) )
+          t = t + 1
+       ENDDO
+       IF ( time /= time_vert(t) ) THEN
+         t = t - 1
+       ENDIF
+
+       fac = (time-time_vert(t)) / (time_vert(t+1)-time_vert(t))
+
+       ug     = ug_vert(:,t) + fac * ( ug_vert(:,t+1) - ug_vert(:,t) )
+       vg     = vg_vert(:,t) + fac * ( vg_vert(:,t+1) - vg_vert(:,t) )
+
+       IF ( large_scale_subsidence ) THEN
+          w_subs = wsubs_vert(:,t) + fac * ( wsubs_vert(:,t+1) - wsubs_vert(:,t) )
+       ENDIF
+
+    END SUBROUTINE ls_forcing_vert
+
+
+ END MODULE ls_forcing_mod
Index: palm/trunk/SOURCE/microphysics.f90
===================================================================
--- palm/trunk/SOURCE/microphysics.f90	(revision 1238)
+++ palm/trunk/SOURCE/microphysics.f90	(revision 1239)
@@ -20,5 +20,6 @@
 ! Current revisions:
 ! ------------------
-!
+! hyp and rho have to be calculated at each time step if data from external
+! file LSF_DATA are used
 !
 ! Former revisions:
@@ -103,5 +104,7 @@
 
        USE arrays_3d
-       USE control_parameters
+       USE cloud_parameters
+       USE control_parameters
+       USE grid_variables
        USE indices
        USE statistics
@@ -296,9 +299,32 @@
        USE cloud_parameters
        USE control_parameters
+       USE grid_variables
+       USE indices
        USE statistics
 
        IMPLICIT NONE
 
-       INTEGER ::  i, j
+       INTEGER ::  i, j, k 
+       REAL    ::  t_surface
+
+       IF ( large_scale_forcing .AND. lsf_surf ) THEN
+!
+!--       Calculate:
+!--       pt / t : ratio of potential and actual temperature (pt_d_t)
+!--       t / pt : ratio of actual and potential temperature (t_d_pt)
+!--       p_0(z) : vertical profile of the hydrostatic pressure (hyp)
+          t_surface = pt_surface * ( surface_pressure / 1000.0 )**0.286
+          DO  k = nzb, nzt+1
+             hyp(k)    = surface_pressure * 100.0 * &
+                         ( (t_surface - g/cp * zu(k)) / t_surface )**(1.0/0.286)
+             pt_d_t(k) = ( 100000.0 / hyp(k) )**0.286
+             t_d_pt(k) = 1.0 / pt_d_t(k)
+             hyrho(k)  = hyp(k) / ( r_d * t_d_pt(k) * pt_init(k) )       
+          ENDDO
+!
+!--       Compute reference density
+          rho_surface = surface_pressure * 100.0 / ( r_d * t_surface )
+       ENDIF
+
 
        dt_micro = dt_3d * weight_pres(intermediate_timestep_count)
Index: palm/trunk/SOURCE/modules.f90
===================================================================
--- palm/trunk/SOURCE/modules.f90	(revision 1238)
+++ palm/trunk/SOURCE/modules.f90	(revision 1239)
@@ -20,5 +20,12 @@
 ! Current revisions:
 ! ------------------
-!
+! Usage of nudging enabled 
+! +nudging, ntnudge, ptnudge, qnudge, tnudge, unudge, vnudge, wnudge
+! increase pr_palm from 80 to 90 to allow for more standard profiles
+!
+! Enable prescribed time depenend surface fluxes and geostrophic wind read in
+! from external file LSF_DATA
+! +large_scale_forcing, lsf_surf, lsf_vert, nlsf, time_surf, shf_surf, qsws_surf,
+!  pt_surf, q_surf, p_surf, time_vert, ug_vert, vg_vert, wsubs_vert
 !
 ! Former revisions:
@@ -434,7 +441,8 @@
           c_u_m, c_u_m_l, c_v_m, c_v_m_l, c_w_m, c_w_m_l, ddzu, ddzu_pres,     &
           dd2zu, dzu, ddzw, dzw, hyp, inflow_damping_factor, lad, l_grid,      &
-          nc_1d, nr_1d, ptdf_x, ptdf_y, pt_1d, pt_init, q_1d, q_init, qc_1d,   &
-          qr_1d, rdf, rdf_sc, ref_state, sa_init, ug, u_init,                  &
-          u_nzb_p1_for_vfc, vg, v_init, v_nzb_p1_for_vfc, w_subs, zu, zw
+          nc_1d, nr_1d, ptdf_x, ptdf_y, p_surf, pt_surf, pt_1d, pt_init,       &
+          qsws_surf, q_1d, q_init, q_surf, qc_1d, qr_1d, rdf, rdf_sc,          & 
+          ref_state, sa_init, shf_surf, timenudge, time_surf, time_vert, ug,   &
+          u_init, u_nzb_p1_for_vfc, vg, v_init, v_nzb_p1_for_vfc, w_subs, zu, zw
 
     REAL, DIMENSION(:,:), ALLOCATABLE ::                                       &
@@ -443,8 +451,9 @@
           flux_s_e, flux_s_nr, flux_s_pt, flux_s_q, flux_s_qr, flux_s_sa,      &
           flux_s_u, flux_s_v, flux_s_w, f1_mg, f2_mg, f3_mg,                   &
-          mean_inflow_profiles, nrs, nrsws, nrswst, pt_slope_ref, qs, qsws,    &
-          qswst, qswst_remote, qrs, qrsws, qrswst, rif, saswsb, saswst, shf,   &
-          total_2d_a, total_2d_o, ts, tswst, us, usws, uswst, vsws, vswst, z0, &
-          z0h
+          mean_inflow_profiles, nrs, nrsws, nrswst, ptnudge, pt_slope_ref,     &
+          qnudge, qs, qsws, qswst, qswst_remote, qrs, qrsws, qrswst, rif,      &
+          saswsb, saswst, shf, tnudge, total_2d_a, total_2d_o, ts, tswst,      &
+          ug_vert, unudge, us, usws, uswst, vnudge, vg_vert, vsws, vswst,      &
+          wnudge, wsubs_vert, z0, z0h
 
     REAL, DIMENSION(:,:,:), ALLOCATABLE ::                                     &
@@ -478,4 +487,5 @@
     REAL, DIMENSION(:,:,:), ALLOCATABLE :: var_x, var_y, var_z, gamma_x,       &
                                            gamma_y, gamma_z
+
 
     SAVE
@@ -715,5 +725,6 @@
                 maximum_parallel_io_streams = -1, max_pr_user = 0, &
                 mgcycles = 0, mg_cycles = -1, mg_switch_to_pe0_level = 0, mid, &
-                netcdf_data_format = 2, ngsrb = 2, nr_timesteps_this_run = 0, &
+                nlsf = 1000, ntnudge = 100, netcdf_data_format = 2, ngsrb = 2, &
+                nr_timesteps_this_run = 0, &
                 nsor = 20, nsor_ini = 100, n_sor, normalizing_region = 0, &
                 nz_do3d = -9999, pch_index = 0, prt_time_count = 0, &
@@ -772,8 +783,11 @@
                 inflow_l = .FALSE., inflow_n = .FALSE., &
                 inflow_r = .FALSE., inflow_s = .FALSE., &
-                iso2d_output = .FALSE., large_scale_subsidence = .FALSE., &
+                iso2d_output = .FALSE., large_scale_forcing = .FALSE., &
+                large_scale_subsidence = .FALSE., lsf_surf = .TRUE., &
+                lsf_vert = .TRUE., lptnudge = .FALSE., lqnudge = .FALSE., &
+                lunudge = .FALSE., lvnudge = .FALSE., lwnudge = .FALSE., &
                 masking_method = .FALSE., mg_switch_to_pe0 = .FALSE., &
-                netcdf_output = .FALSE., neutral = .FALSE., ocean = .FALSE., &
-                on_device = .FALSE., &
+                netcdf_output = .FALSE., neutral = .FALSE., nudging = .FALSE., &
+                ocean = .FALSE., on_device = .FALSE., &
                 outflow_l = .FALSE., outflow_n = .FALSE., outflow_r = .FALSE., &
                 outflow_s = .FALSE., passive_scalar = .FALSE., &
@@ -1661,5 +1675,5 @@
 
     CHARACTER (LEN=40) ::  region(0:9)
-    INTEGER ::  pr_palm = 80, statistic_regions = 0
+    INTEGER ::  pr_palm = 90, statistic_regions = 0
     INTEGER ::  u_max_ijk(3), v_max_ijk(3), w_max_ijk(3)
     LOGICAL ::  flow_statistics_called = .FALSE.
Index: palm/trunk/SOURCE/nudging.f90
===================================================================
--- palm/trunk/SOURCE/nudging.f90	(revision 1239)
+++ palm/trunk/SOURCE/nudging.f90	(revision 1239)
@@ -0,0 +1,383 @@
+ MODULE nudge_mod
+
+!--------------------------------------------------------------------------------!
+! This file is part of PALM.
+!
+! PALM is free software: you can redistribute it and/or modify it under the terms
+! of the GNU General Public License as published by the Free Software Foundation,
+! either version 3 of the License, or (at your option) any later version.
+!
+! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
+! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+!
+! You should have received a copy of the GNU General Public License along with
+! PALM. If not, see <http://www.gnu.org/licenses/>.
+!
+! Copyright 1997-2012  Leibniz University Hannover
+!--------------------------------------------------------------------------------!
+!
+! Current revisions:
+! ------------------
+!
+!
+! Former revisions:
+! -----------------
+! $Id$
+!
+!
+! Description:
+! ------------
+! Nudges u, v, pt and q to given profiles on a relaxation timescale tnudge. 
+! Profiles are read in from NUDGIN_DATA. Code is based on Neggers et al. (2012) 
+! and also part of DALES and UCLA-LES.
+!--------------------------------------------------------------------------------!
+
+    PRIVATE
+    PUBLIC init_nudge, nudge 
+    SAVE
+
+    INTERFACE nudge
+       MODULE PROCEDURE nudge
+       MODULE PROCEDURE nudge_ij
+    END INTERFACE nudge
+
+ CONTAINS
+
+    SUBROUTINE init_nudge
+
+       USE arrays_3d
+       USE control_parameters
+       USE cpulog
+       USE indices
+       USE interfaces
+       USE pegrid
+       USE user
+
+       IMPLICIT NONE
+
+       INTEGER :: finput = 90, ierrn, k, t 
+
+       CHARACTER(1) :: hash
+       REAL :: highheight, highqnudge, highptnudge, highunudge, highvnudge, &
+               highwnudge, hightnudge
+       REAL :: lowheight, lowqnudge, lowptnudge, lowunudge, lowvnudge, &
+               lowwnudge, lowtnudge
+       REAL :: fac
+
+       ALLOCATE( ptnudge(nzb:nzt+1,1:ntnudge), qnudge(nzb:nzt+1,1:ntnudge), &
+                 tnudge(nzb:nzt+1,1:ntnudge), unudge(nzb:nzt+1,1:ntnudge),  &
+                 vnudge(nzb:nzt+1,1:ntnudge), wnudge(nzb:nzt+1,1:ntnudge)  )
+
+       ALLOCATE( timenudge(0:ntnudge) )
+
+
+       ptnudge = 0.0; qnudge = 0.0; tnudge = 0.0; unudge = 0.0
+       vnudge = 0.0; wnudge = 0.0; timenudge = 0.0
+
+       t = 0
+       OPEN (finput, FILE='NUDGING_DATA', STATUS='OLD', &
+              FORM='FORMATTED', IOSTAT=ierrn)
+
+       IF (ierrn /= 0 ) THEN
+          message_string = 'file NUDGING_DATA does not exist'
+          CALL message( 'nudging', 'PA0365', 1, 2, 0, 6, 0 )
+       ENDIF
+
+       ierrn = 0
+
+ rloop:DO
+          t = t + 1
+          hash = "#"
+          ierrn = 1 ! not zero        
+!
+!--       Search for the next line consisting of "# time", 
+!--       from there onwards the profiles will be read
+          DO WHILE ( .NOT. ( hash == "#" .AND. ierrn == 0 ) ) 
+          
+            READ( finput, *, IOSTAT=ierrn ) hash, timenudge(t)
+            IF ( ierrn < 0 ) EXIT rloop
+
+          ENDDO
+
+          ierrn = 0
+          READ( finput, *, IOSTAT=ierrn ) lowheight, lowtnudge, lowunudge,   &
+                                          lowvnudge, lowwnudge , lowptnudge, &
+                                          lowqnudge
+
+          IF (ierrn /= 0 ) THEN
+             message_string = 'errors in file NUDGING_DATA'
+             CALL message( 'nudging', 'PA0366', 1, 2, 0, 6, 0 )
+          ENDIF
+
+          ierrn = 0
+          READ( finput, *, IOSTAT=ierrn ) highheight, hightnudge, highunudge,   &
+                                          highvnudge, highwnudge , highptnudge, &
+                                          highqnudge
+
+          IF (ierrn /= 0 ) THEN
+             message_string = 'errors in file NUDGING_DATA'
+             CALL message( 'nudging', 'PA0366', 1, 2, 0, 6, 0 )
+          ENDIF
+
+          DO  k = nzb, nzt+1
+             IF ( highheight < zu(k) ) THEN
+                lowheight  = highheight
+                lowtnudge  = hightnudge
+                lowunudge  = highunudge
+                lowvnudge  = highvnudge
+                lowwnudge  = highwnudge
+                lowptnudge = highptnudge
+                lowqnudge  = highqnudge
+ 
+                ierrn = 0
+                READ( finput, *, IOSTAT=ierrn )  highheight , hightnudge , &
+                                                 highunudge , highvnudge , &
+                                                 highwnudge , highptnudge, &
+                                                 highqnudge
+                IF (ierrn /= 0 ) THEN
+                   message_string = 'errors in file NUDGING_DATA'
+                   CALL message( 'nudging', 'PA0366', 1, 2, 0, 6, 0 )
+                ENDIF
+             ENDIF
+
+!
+!--          Interpolation of prescribed profiles in space 
+
+             fac = (highheight-zu(k))/(highheight - lowheight)
+
+             tnudge(k,t)  = fac * lowtnudge + (1-fac) * hightnudge
+             unudge(k,t)  = fac * lowunudge + (1-fac) * highunudge
+             vnudge(k,t)  = fac * lowvnudge + (1-fac) * highvnudge
+             wnudge(k,t)  = fac * lowwnudge + (1-fac) * highwnudge
+             ptnudge(k,t) = fac * lowptnudge + (1-fac) * highptnudge
+             qnudge(k,t)  = fac * lowqnudge + (1-fac) * highqnudge
+          ENDDO
+
+       ENDDO rloop
+
+       CLOSE( finput )
+
+!
+!--    Prevent nudging if nudging profiles exhibt too small values
+       lptnudge  = ANY( ABS( ptnudge ) > 1e-8 )
+       lqnudge   = ANY( ABS( qnudge ) > 1e-8 )
+       lunudge   = ANY( ABS( unudge ) > 1e-8 )
+       lvnudge   = ANY( ABS( vnudge ) > 1e-8 )
+       lwnudge   = ANY( ABS( wnudge ) > 1e-8 )
+
+    END SUBROUTINE init_nudge
+
+!------------------------------------------------------------------------------!
+! Call for all grid points
+!------------------------------------------------------------------------------!
+    SUBROUTINE nudge ( time, prog_var )
+
+       USE arrays_3d
+       USE buoyancy_mod
+       USE control_parameters
+       USE cpulog
+       USE indices
+       USE interfaces
+       USE pegrid
+       USE statistics 
+       USE user
+
+       IMPLICIT NONE
+
+       CHARACTER (LEN=*) ::  prog_var
+
+       REAL :: currtnudge, dtm, dtp, time
+
+       INTEGER ::  i, j, k, t
+
+
+       SELECT CASE ( prog_var )
+
+          CASE ( 'u' )
+
+             CALL calc_mean_profile( u, 1, 'nudging' )
+
+             DO  i = nxl, nxr
+                DO  j = nys, nyn
+                   DO  k = nzb_u_inner(j,i)+1, nzt
+
+                      currtnudge = MAX( dt_3d, tnudge(k,t) * dtp +  &
+                                               tnudge(k,t+1) * dtm )
+
+
+                      tend(k,j,i) = tend(k,j,i) - ( hom(k,1,1,0) - &
+                                    ( unudge(k,t) * dtp + &
+                                       unudge(k,t+1) * dtm ) ) / currtnudge
+                   ENDDO
+                ENDDO
+            ENDDO
+
+          CASE ( 'v' )
+
+             CALL calc_mean_profile( v, 2, 'nudging' )
+
+             DO  i = nxl, nxr
+                DO  j = nys, nyn
+                   DO  k = nzb_u_inner(j,i)+1, nzt
+
+                      currtnudge = MAX( dt_3d, tnudge(k,t) * dtp +  &
+                                               tnudge(k,t+1) * dtm )
+
+
+                      tend(k,j,i) = tend(k,j,i) - ( hom(k,1,2,0) - &
+                                    ( vnudge(k,t) * dtp + &
+                                       vnudge(k,t+1) * dtm ) ) / currtnudge
+                   ENDDO
+                ENDDO
+            ENDDO
+
+          CASE ( 'pt' )
+
+             CALL calc_mean_profile( v, 4, 'nudging' )
+
+             DO  i = nxl, nxr
+                DO  j = nys, nyn
+                   DO  k = nzb_u_inner(j,i)+1, nzt
+
+                      currtnudge = MAX( dt_3d, tnudge(k,t) * dtp +  &
+                                               tnudge(k,t+1) * dtm )
+
+
+                      tend(k,j,i) = tend(k,j,i) - ( hom(k,1,4,0) - &
+                                    ( ptnudge(k,t) * dtp + &
+                                       ptnudge(k,t+1) * dtm ) ) / currtnudge
+                   ENDDO
+                ENDDO
+            ENDDO
+
+          CASE ( 'q' )
+
+             CALL calc_mean_profile( v, 41, 'nudging' )
+
+             DO  i = nxl, nxr
+                DO  j = nys, nyn
+                   DO  k = nzb_u_inner(j,i)+1, nzt
+
+                      currtnudge = MAX( dt_3d, tnudge(k,t) * dtp +  &
+                                               tnudge(k,t+1) * dtm )
+
+
+                      tend(k,j,i) = tend(k,j,i) - ( hom(k,1,41,0) - &
+                                    ( qnudge(k,t) * dtp + &
+                                       qnudge(k,t+1) * dtm ) ) / currtnudge
+                   ENDDO
+                ENDDO
+            ENDDO
+
+          CASE DEFAULT
+             message_string = 'unknown prognostic variable "' // prog_var // '"'
+             CALL message( 'nudge', 'PA0367', 1, 2, 0, 6, 0 )
+
+       END SELECT
+
+    END SUBROUTINE nudge
+
+
+!------------------------------------------------------------------------------!
+! Call for grid point i,j
+!------------------------------------------------------------------------------!
+
+    SUBROUTINE nudge_ij( i, j, time, prog_var )
+
+       USE arrays_3d
+       USE buoyancy_mod
+       USE control_parameters
+       USE cpulog
+       USE indices
+       USE interfaces
+       USE pegrid
+       USE statistics 
+       USE user
+
+       IMPLICIT NONE
+
+       CHARACTER (LEN=*) ::  prog_var
+
+       REAL :: currtnudge, dtm, dtp, time
+
+       INTEGER ::  i, j, k, t
+
+
+       t = 1
+       DO WHILE ( time > timenudge(t) )
+         t = t+1
+       ENDDO
+       IF ( time /= timenudge(1) ) THEN
+         t = t-1
+       ENDIF
+
+       dtm = ( time - timenudge(t) ) / ( timenudge(t+1) - timenudge(t) )
+       dtp = ( timenudge(t+1) - time ) / ( timenudge(t+1) - timenudge(t) )
+
+       SELECT CASE ( prog_var )
+
+          CASE ( 'u' )
+
+             CALL calc_mean_profile( u, 1, 'nudging' )
+
+             DO  k = nzb_u_inner(j,i)+1, nzt
+
+                currtnudge = MAX( dt_3d, tnudge(k,t) * dtp + tnudge(k,t+1) * dtm )
+
+                tend(k,j,i) = tend(k,j,i) - ( hom(k,1,1,0) - &
+                               ( unudge(k,t) * dtp + &
+                                 unudge(k,t+1) * dtm ) ) / currtnudge
+             ENDDO
+
+          CASE ( 'v' )
+
+             CALL calc_mean_profile( v, 2, 'nudging' )
+
+             DO  k = nzb_u_inner(j,i)+1, nzt
+
+                currtnudge = MAX( dt_3d, tnudge(k,t) * dtp + tnudge(k,t+1) * dtm )
+
+                tend(k,j,i) = tend(k,j,i) - ( hom(k,1,2,0) - &
+                               ( vnudge(k,t) * dtp + &
+                                 vnudge(k,t+1) * dtm ) ) / currtnudge
+             ENDDO
+
+
+          CASE ( 'pt' )
+
+             CALL calc_mean_profile( pt, 4, 'nudging' )
+
+             DO  k = nzb_u_inner(j,i)+1, nzt
+
+                currtnudge = MAX( dt_3d, tnudge(k,t) * dtp + tnudge(k,t+1) * dtm )
+
+                tend(k,j,i) = tend(k,j,i) - ( hom(k,1,4,0) - &
+                               ( ptnudge(k,t) * dtp + &
+                                 ptnudge(k,t+1) * dtm ) ) / currtnudge
+             ENDDO
+
+
+          CASE ( 'q' )
+
+             CALL calc_mean_profile( q, 41, 'nudging' )
+
+             DO  k = nzb_u_inner(j,i)+1, nzt
+
+                currtnudge = MAX( dt_3d, tnudge(k,t) * dtp + tnudge(k,t+1) * dtm )
+
+                tend(k,j,i) = tend(k,j,i) - ( hom(k,1,41,0) - &
+                               ( qnudge(k,t) * dtp + &
+                                 qnudge(k,t+1) * dtm ) ) / currtnudge
+             ENDDO
+
+          CASE DEFAULT
+             message_string = 'unknown prognostic variable "' // prog_var // '"'
+             CALL message( 'nudge', 'PA0367', 1, 2, 0, 6, 0 )
+
+       END SELECT
+
+
+    END SUBROUTINE nudge_ij
+
+ END MODULE nudge_mod
Index: palm/trunk/SOURCE/palm.f90
===================================================================
--- palm/trunk/SOURCE/palm.f90	(revision 1238)
+++ palm/trunk/SOURCE/palm.f90	(revision 1239)
@@ -20,5 +20,5 @@
 ! Current revisions:
 ! -----------------
-!
+! initialization of nudging and large scale forcing from external file
 !
 ! Former revisions:
@@ -110,5 +110,7 @@
     USE indices
     USE interfaces
+    USE ls_forcing_mod
     USE model_1d
+    USE nudge_mod
     USE particle_attributes
     USE pegrid
@@ -217,7 +219,18 @@
 
 !
+!-- Initialize Nudging if required
+    IF ( nudging )  THEN
+       CALL init_nudge
+    ENDIF
+
+!
+!-- Initialize reading of large scale forcing from external file - if required
+    IF ( large_scale_forcing )  THEN
+       CALL init_ls_forcing
+    ENDIF
+
+!
 !-- Check control parameters and deduce further quantities
     CALL check_parameters
-
 
 !
Index: palm/trunk/SOURCE/parin.f90
===================================================================
--- palm/trunk/SOURCE/parin.f90	(revision 1238)
+++ palm/trunk/SOURCE/parin.f90	(revision 1239)
@@ -20,5 +20,6 @@
 ! Current revisions:
 ! -----------------
-!
+! +nudging
+! +large_scale_forcing
 !
 ! Former revisions:
@@ -239,9 +240,10 @@
              initializing_actions, km_constant, lad_surface, &
              lad_vertical_gradient, lad_vertical_gradient_level, &
+             large_scale_forcing, &
              leaf_surface_concentration, limiter_sedimentation, &
              loop_optimization, masking_method, mg_cycles, &
              mg_switch_to_pe0_level, mixing_length_1d, momentum_advec, &
              nc_const, netcdf_precision, neutral, ngsrb, &
-             nsor, nsor_ini, nx, ny, nz, ocean, omega, omega_sor, &
+             nsor, nsor_ini, nudging, nx, ny, nz, ocean, omega, omega_sor, &
              passive_scalar, pch_index, phi, plant_canopy, prandtl_layer, &
              prandtl_number, precipitation, psolver, pt_damping_factor, &
Index: palm/trunk/SOURCE/prognostic_equations.f90
===================================================================
--- palm/trunk/SOURCE/prognostic_equations.f90	(revision 1238)
+++ palm/trunk/SOURCE/prognostic_equations.f90	(revision 1239)
@@ -20,5 +20,5 @@
 ! Current revisions:
 ! ------------------
-!
+! usage of nudging enabled (not for accelerator version so far)
 !
 ! Former revisions:
@@ -182,4 +182,5 @@
     USE impact_of_latent_heat_mod
     USE microphysics_mod
+    USE nudge_mod
     USE plant_canopy_model_mod
     USE production_e_mod
@@ -285,4 +286,8 @@
              ENDIF
 
+!
+!--          Nudging
+             IF ( nudging )  CALL nudge( i, j, simulated_time, 'u' ) 
+
              CALL user_actions( i, j, 'u-tendency' )
 !
@@ -340,4 +345,8 @@
              ENDIF
 
+!
+!--          Nudging
+             IF ( nudging )  CALL nudge( i, j, simulated_time, 'v' ) 
+
              CALL user_actions( i, j, 'v-tendency' )
 !
@@ -471,4 +480,8 @@
                 CALL subsidence( i, j, tend, pt, pt_init )
              ENDIF
+
+!
+!--          Nudging
+             IF ( nudging )  CALL nudge( i, j, simulated_time, 'pt' ) 
 
              CALL user_actions( i, j, 'pt-tendency' )
@@ -594,4 +607,8 @@
                 CALL subsidence( i, j, tend, q, q_init )
              ENDIF
+
+!
+!--          Nudging
+             IF ( nudging )  CALL nudge( i, j, simulated_time, 'q' ) 
 
              CALL user_actions( i, j, 'q-tendency' )
@@ -847,4 +864,8 @@
     ENDIF
 
+!
+!-- Nudging
+    IF ( nudging )  CALL nudge( simulated_time, 'u' ) 
+
     CALL user_actions( 'u-tendency' )
 
@@ -919,4 +940,8 @@
     ENDIF
 
+!
+!-- Nudging
+    IF ( nudging )  CALL nudge( simulated_time, 'v' ) 
+
     CALL user_actions( 'v-tendency' )
 
@@ -1092,4 +1117,8 @@
           CALL subsidence( tend, pt, pt_init )
        ENDIF
+
+!
+!--    Nudging
+       IF ( nudging )  CALL nudge( simulated_time, 'pt' ) 
 
        CALL user_actions( 'pt-tendency' )
@@ -1278,4 +1307,8 @@
          CALL subsidence( tend, q, q_init )
        ENDIF
+
+!
+!--    Nudging
+       IF ( nudging )  CALL nudge( simulated_time, 'q' ) 
 
        CALL user_actions( 'q-tendency' )
Index: palm/trunk/SOURCE/read_var_list.f90
===================================================================
--- palm/trunk/SOURCE/read_var_list.f90	(revision 1238)
+++ palm/trunk/SOURCE/read_var_list.f90	(revision 1239)
@@ -20,5 +20,6 @@
 ! Current revisions:
 ! ------------------
-! 
+! +nudging
+! +large_scale_forcing
 !
 ! Former revisions:
@@ -448,4 +449,6 @@
           CASE ( 'lad_vertical_gradient_level_in' )
              READ ( 13 )  lad_vertical_gradient_level_ind
+          CASE ( 'large_scale_forcing' )
+             READ ( 13 )  large_scale_forcing
            CASE ( 'large_scale_subsidence' )
              READ ( 13 )  large_scale_subsidence
@@ -483,4 +486,6 @@
           CASE ( 'nsor_ini' )
              READ ( 13 )  nsor_ini
+          CASE ( 'nudging' )
+             READ ( 13 )  nudging
           CASE ( 'nx' )
              READ ( 13 )  nx
Index: palm/trunk/SOURCE/time_integration.f90
===================================================================
--- palm/trunk/SOURCE/time_integration.f90	(revision 1238)
+++ palm/trunk/SOURCE/time_integration.f90	(revision 1239)
@@ -20,5 +20,7 @@
 ! Current revisions:
 ! ------------------
-!
+! Generalize calc_mean_profile for wider use
+! Determine shf and qsws in dependence on data from LSF_DATA
+! Determine ug and vg in dependence on data from LSF_DATA
 !
 ! Former revisions:
@@ -165,4 +167,5 @@
     USE interaction_droplets_ptq_mod
     USE interfaces
+    USE ls_forcing_mod
     USE particle_attributes
     USE pegrid
@@ -223,4 +226,11 @@
 
 !
+!--    Determine ug, vg and w_subs in dependence on data from external file 
+!--    LSF_DATA
+       IF ( large_scale_forcing .AND. lsf_vert ) THEN
+           CALL ls_forcing_vert ( simulated_time )
+       ENDIF
+
+!
 !--    Execute the user-defined actions
        CALL user_actions( 'before_timestep' )
@@ -248,7 +258,7 @@
 !--          buoyancy terms (WARNING: only the respective last call of
 !--          calc_mean_profile defines the reference state!)
-             IF ( .NOT. neutral )  CALL calc_mean_profile( pt, 4 )
-             IF ( ocean         )  CALL calc_mean_profile( rho, 64 )
-             IF ( humidity      )  CALL calc_mean_profile( vpt, 44 )
+             IF ( .NOT. neutral )  CALL calc_mean_profile( pt, 4, 'time_int' )
+             IF ( ocean         )  CALL calc_mean_profile( rho, 64, 'time_int' )
+             IF ( humidity      )  CALL calc_mean_profile( vpt, 44, 'time_int' )
           ENDIF
 
@@ -566,4 +576,14 @@
                 CALL cpu_log( log_point(19), 'prandtl_fluxes', 'stop' )
              ENDIF
+
+!
+!--          Determine shf and qsws in dependence on data from external file 
+!--          LSF_DATA
+             IF ( ( large_scale_forcing .AND. lsf_surf ) .AND. &
+                 intermediate_timestep_count == intermediate_timestep_count_max )&
+             THEN
+                CALL ls_forcing_surf ( simulated_time )
+             ENDIF
+
 !
 !--          Compute the diffusion coefficients
Index: palm/trunk/SOURCE/write_var_list.f90
===================================================================
--- palm/trunk/SOURCE/write_var_list.f90	(revision 1238)
+++ palm/trunk/SOURCE/write_var_list.f90	(revision 1239)
@@ -20,5 +20,6 @@
 ! Current revisions:
 ! -----------------
-!
+! +nudging
+! +large_scale_forcing
 !
 ! Former revisions:
@@ -365,4 +366,6 @@
     WRITE ( 14 )  'lad_vertical_gradient_level_in'
     WRITE ( 14 )  lad_vertical_gradient_level_ind
+    WRITE ( 14 )  'large_scale_forcing           '
+    WRITE ( 14 )  large_scale_forcing
     WRITE ( 14 )  'large_scale_subsidence        '
     WRITE ( 14 )  large_scale_subsidence
@@ -399,4 +402,6 @@
     WRITE ( 14 )  'nsor_ini                      '
     WRITE ( 14 )  nsor_ini
+    WRITE ( 14 )  'nudging                       '
+    WRITE ( 14 )  nudging
     WRITE ( 14 )  'nx                            '
     WRITE ( 14 )  nx
