Index: palm/trunk/SOURCE/Makefile
===================================================================
--- palm/trunk/SOURCE/Makefile	(revision 1379)
+++ palm/trunk/SOURCE/Makefile	(revision 1380)
@@ -20,6 +20,7 @@
 # Current revisions:
 # ------------------
-# 
-# 
+# bugfix: mod_particle_attributes  added to check_open
+# nudging added to time_integration 
+#
 # Former revisions:
 # -----------------
@@ -28,5 +29,5 @@
 # 1374 2014-04-25 12:55:07Z raasch
 # bugfix: missing dependency added for check_open
-# 
+#
 # 1365 2014-04-22 15:03:56Z boeske
 # Added new module calc_mean_profile, previously in module buoyancy,
@@ -393,5 +394,5 @@
 time_integration.o: modules.o advec_ws.o buoyancy.o calc_mean_profile.o \
 	cpulog.o interaction_droplets_ptq.o ls_forcing.o mod_kinds.o \
-	production_e.o prognostic_equations.o user_actions.o
+	nudging.o production_e.o prognostic_equations.o user_actions.o
 time_to_string.o: mod_kinds.o
 timestep.o: modules.o cpulog.o mod_kinds.o
Index: palm/trunk/SOURCE/boundary_conds.f90
===================================================================
--- palm/trunk/SOURCE/boundary_conds.f90	(revision 1379)
+++ palm/trunk/SOURCE/boundary_conds.f90	(revision 1380)
@@ -20,5 +20,5 @@
 ! Current revisions:
 ! -----------------
-! 
+! Adjust Dirichlet-condition at the top for pt in case of nudging
 ! 
 ! Former revisions:
@@ -101,5 +101,6 @@
                u, ug, u_init, u_m_l, u_m_n, u_m_r, u_m_s, u_p,                 &
                v, vg, v_init, v_m_l, v_m_n, v_m_r, v_m_s, v_p,                 &
-               w, w_p, w_m_l, w_m_n, w_m_r, w_m_s
+               w, w_p, w_m_l, w_m_n, w_m_r, w_m_s,&
+               pt_init
 
     USE control_parameters,                                                    &
@@ -110,5 +111,6 @@
                intermediate_timestep_count, large_scale_forcing, ocean,        &
                outflow_l, outflow_n, outflow_r, outflow_s, passive_scalar,     &
-               precipitation, tsc, use_cmax
+               precipitation, tsc, use_cmax, &
+               nudging
 
     USE grid_variables,                                                        &
@@ -203,4 +205,10 @@
        !$acc kernels present( pt, pt_p )
         pt_p(nzt+1,:,:) = pt(nzt+1,:,:)
+!
+!--     In case of nudging adjust top boundary to pt which is
+!--     read in from NUDGING-DATA
+        IF ( nudging )  THEN
+           pt_p(nzt+1,:,:) = pt_init(nzt+1)
+        ENDIF
        !$acc end kernels
     ELSEIF ( ibc_pt_t == 1 )  THEN
Index: palm/trunk/SOURCE/nudging.f90
===================================================================
--- palm/trunk/SOURCE/nudging.f90	(revision 1379)
+++ palm/trunk/SOURCE/nudging.f90	(revision 1380)
@@ -20,5 +20,6 @@
 ! Current revisions:
 ! ------------------
-! 
+! Subroutine nudge_ref added to account for proper upper scalar boundary 
+! conditions in case of nudging
 ! 
 ! Former revisions:
@@ -72,5 +73,5 @@
 
     PRIVATE
-    PUBLIC init_nudge, calc_tnudge, nudge 
+    PUBLIC init_nudge, calc_tnudge, nudge, nudge_ref
     SAVE
 
@@ -515,3 +516,39 @@
     END SUBROUTINE nudge_ij
 
+
+    SUBROUTINE nudge_ref ( time )
+
+       USE arrays_3d,                                                          &
+           ONLY:  time_vert, ptnudge, pt_init, qnudge, q_init
+
+       USE kinds
+
+
+       IMPLICIT NONE
+
+       INTEGER(iwp) ::  nt                    !:
+
+       REAL(wp)             ::  fac           !:
+       REAL(wp), INTENT(in) ::  time          !:
+
+!
+!--    Interpolation in time of NUDGING_DATA for pt_init and q_init. This is 
+!--    needed for correct upper boundary conditions for pt and q and in case that 
+!      large scale subsidence as well as scalar Rayleigh-damping are used
+       nt = 1
+       DO WHILE ( time > time_vert(nt) )
+          nt = nt + 1
+       ENDDO
+       IF ( time /= time_vert(nt) )  THEN
+        nt = nt - 1
+       ENDIF
+
+       fac = ( time-time_vert(nt) ) / ( time_vert(nt+1)-time_vert(nt) )
+
+       pt_init = ptnudge(:,nt) + fac * ( ptnudge(:,nt+1) - ptnudge(:,nt) )
+       q_init  = qnudge(:,nt) + fac * ( qnudge(:,nt+1) - qnudge(:,nt) )
+
+    END SUBROUTINE nudge_ref
+
+
  END MODULE nudge_mod
Index: palm/trunk/SOURCE/prognostic_equations.f90
===================================================================
--- palm/trunk/SOURCE/prognostic_equations.f90	(revision 1379)
+++ palm/trunk/SOURCE/prognostic_equations.f90	(revision 1380)
@@ -20,5 +20,6 @@
 ! Current revisions:
 ! ------------------
-! 
+! Change order of calls for scalar prognostic quantities: 
+! ls_advec -> nudging -> subsidence since initial profiles 
 ! 
 ! Former revisions:
@@ -559,4 +560,8 @@
 
 !
+!--          Nudging
+             IF ( nudging )  CALL nudge( i, j, simulated_time, 'pt' ) 
+
+!
 !--          If required, compute effect of large-scale subsidence/ascent
              IF ( large_scale_subsidence  .AND.                                &
@@ -564,8 +569,4 @@
                 CALL subsidence( i, j, tend, pt, pt_init, 2 )
              ENDIF
-
-!
-!--          Nudging
-             IF ( nudging )  CALL nudge( i, j, simulated_time, 'pt' ) 
 
              CALL user_actions( i, j, 'pt-tendency' )
@@ -691,4 +692,8 @@
 
 !
+!--          Nudging
+             IF ( nudging )  CALL nudge( i, j, simulated_time, 'q' ) 
+
+!
 !--          If required compute influence of large-scale subsidence/ascent
              IF ( large_scale_subsidence  .AND.                                &
@@ -696,8 +701,4 @@
                 CALL subsidence( i, j, tend, q, q_init, 3 )
              ENDIF
-
-!
-!--          Nudging
-             IF ( nudging )  CALL nudge( i, j, simulated_time, 'q' ) 
 
              CALL user_actions( i, j, 'q-tendency' )
@@ -1213,4 +1214,8 @@
 
 !
+!--    Nudging
+       IF ( nudging )  CALL nudge( simulated_time, 'pt' ) 
+
+!
 !--    If required compute influence of large-scale subsidence/ascent
        IF ( large_scale_subsidence  .AND.                                      &
@@ -1218,8 +1223,4 @@
           CALL subsidence( tend, pt, pt_init, 2 )
        ENDIF
-
-!
-!--    Nudging
-       IF ( nudging )  CALL nudge( simulated_time, 'pt' ) 
 
        CALL user_actions( 'pt-tendency' )
@@ -1410,4 +1411,8 @@
 
 !
+!--    Nudging
+       IF ( nudging )  CALL nudge( simulated_time, 'q' ) 
+
+!
 !--    If required compute influence of large-scale subsidence/ascent
        IF ( large_scale_subsidence  .AND.                                      &
@@ -1415,8 +1420,4 @@
          CALL subsidence( tend, q, q_init, 3 )
        ENDIF
-
-!
-!--    Nudging
-       IF ( nudging )  CALL nudge( simulated_time, 'q' ) 
 
        CALL user_actions( 'q-tendency' )
@@ -2028,4 +2029,8 @@
 
 !
+!--    Nudging
+       IF ( nudging )  CALL nudge( simulated_time, 'pt' ) 
+
+!
 !--    If required compute influence of large-scale subsidence/ascent
        IF ( large_scale_subsidence  .AND.                                      &
@@ -2033,8 +2038,4 @@
           CALL subsidence( tend, pt, pt_init, 2 )
        ENDIF
-
-!
-!--    Nudging
-       IF ( nudging )  CALL nudge( simulated_time, 'pt' ) 
 
        CALL user_actions( 'pt-tendency' )
@@ -2199,4 +2200,8 @@
 
 !
+!--    Nudging
+       IF ( nudging )  CALL nudge( simulated_time, 'q' ) 
+
+!
 !--    If required compute influence of large-scale subsidence/ascent
        IF ( large_scale_subsidence  .AND.                                      &
@@ -2204,8 +2209,4 @@
          CALL subsidence( tend, q, q_init, 3 )
        ENDIF
-
-!
-!--    Nudging
-       IF ( nudging )  CALL nudge( simulated_time, 'q' ) 
 
        CALL user_actions( 'q-tendency' )
Index: palm/trunk/SOURCE/subsidence.f90
===================================================================
--- palm/trunk/SOURCE/subsidence.f90	(revision 1379)
+++ palm/trunk/SOURCE/subsidence.f90	(revision 1380)
@@ -20,5 +20,5 @@
 ! Current revisions:
 ! -----------------
-! 
+! Shifting only necessary in case of scalar Rayleigh damping
 ! 
 ! Former revisions:
@@ -150,5 +150,6 @@
 
        USE control_parameters,                                                 &
-           ONLY:  dt_3d, intermediate_timestep_count, large_scale_forcing
+           ONLY:  dt_3d, intermediate_timestep_count, large_scale_forcing,     &
+                  scalar_rayleigh_damping
 
        USE indices,                                                            &
@@ -204,35 +205,36 @@
 !--    Shifting of the initial profile is especially necessary with Rayleigh 
 !--    damping switched on
-
-       DO  k = nzb, nzt
-          IF ( w_subs(k) < 0.0_wp )  THEN      ! large-scale subsidence
-             var_mod(k) = var_init(k) - dt_3d * w_subs(k) *  &
-                               ( var_init(k+1) - var_init(k) ) * ddzu(k+1)
-          ENDIF
-       ENDDO
-!
-!--   At the upper boundary, the initial profile is shifted with aid of 
-!--   the gradient tmp_grad. (This is ok if the gradients are linear.)
-      IF ( w_subs(nzt) < 0.0_wp )  THEN
-         tmp_grad = ( var_init(nzt+1) - var_init(nzt) ) * ddzu(nzt+1)
-         var_mod(nzt+1) = var_init(nzt+1) -  &
-                              dt_3d * w_subs(nzt+1) * tmp_grad
+       IF ( scalar_rayleigh_damping ) THEN
+          DO  k = nzb, nzt
+             IF ( w_subs(k) < 0.0_wp )  THEN      ! large-scale subsidence
+                var_mod(k) = var_init(k) - dt_3d * w_subs(k) *  &
+                                  ( var_init(k+1) - var_init(k) ) * ddzu(k+1)
+             ENDIF
+          ENDDO
+!
+!--      At the upper boundary, the initial profile is shifted with aid of 
+!--      the gradient tmp_grad. (This is ok if the gradients are linear.)
+         IF ( w_subs(nzt) < 0.0_wp )  THEN
+            tmp_grad = ( var_init(nzt+1) - var_init(nzt) ) * ddzu(nzt+1)
+            var_mod(nzt+1) = var_init(nzt+1) -  &
+                                 dt_3d * w_subs(nzt+1) * tmp_grad
+         ENDIF
+       
+
+         DO  k = nzt+1, nzb+1, -1
+            IF ( w_subs(k) >= 0.0_wp )  THEN  ! large-scale ascent
+               var_mod(k) = var_init(k) - dt_3d * w_subs(k) *  &
+                                  ( var_init(k) - var_init(k-1) ) * ddzu(k) 
+            ENDIF
+         ENDDO
+!
+!--      At the lower boundary shifting is not necessary because the 
+!--      subsidence velocity w_subs(nzb) vanishes.
+         IF ( w_subs(nzb+1) >= 0.0_wp )  THEN
+            var_mod(nzb) = var_init(nzb)
+         ENDIF
+
+         var_init = var_mod
       ENDIF
-       
-
-      DO  k = nzt+1, nzb+1, -1
-         IF ( w_subs(k) >= 0.0_wp )  THEN  ! large-scale ascent
-            var_mod(k) = var_init(k) - dt_3d * w_subs(k) *  &
-                               ( var_init(k) - var_init(k-1) ) * ddzu(k) 
-         ENDIF
-      ENDDO
-!
-!--   At the lower boundary shifting is not necessary because the 
-!--   subsidence velocity w_subs(nzb) vanishes.
-      IF ( w_subs(nzb+1) >= 0.0_wp )  THEN
-         var_mod(nzb) = var_init(nzb)
-      ENDIF
-
-      var_init = var_mod
 
 
@@ -245,5 +247,6 @@
 
        USE control_parameters,                                                 &
-           ONLY:  dt_3d, intermediate_timestep_count, large_scale_forcing
+           ONLY:  dt_3d, intermediate_timestep_count, large_scale_forcing,     &
+                  scalar_rayleigh_damping
 
        USE indices,                                                            &
@@ -293,37 +296,39 @@
 !--    Shifting of the initial profile is especially necessary with Rayleigh 
 !--    damping switched on
-       IF ( i == nxl .AND. j == nys )  THEN ! shifting only once per PE 
-
-          DO  k = nzb, nzt
-             IF ( w_subs(k) < 0.0_wp )  THEN      ! large-scale subsidence
-                var_mod(k) = var_init(k) - dt_3d * w_subs(k) *  &
-                                  ( var_init(k+1) - var_init(k) ) * ddzu(k+1)
+       IF ( scalar_rayleigh_damping ) THEN
+          IF ( i == nxl .AND. j == nys )  THEN ! shifting only once per PE 
+
+             DO  k = nzb, nzt
+                IF ( w_subs(k) < 0.0_wp )  THEN      ! large-scale subsidence
+                   var_mod(k) = var_init(k) - dt_3d * w_subs(k) *  &
+                                     ( var_init(k+1) - var_init(k) ) * ddzu(k+1)
+                ENDIF
+             ENDDO
+!
+!--          At the upper boundary, the initial profile is shifted with aid of 
+!--          the gradient tmp_grad. (This is ok if the gradients are linear.)
+             IF ( w_subs(nzt) < 0.0_wp )  THEN
+                tmp_grad = ( var_init(nzt+1) - var_init(nzt) ) * ddzu(nzt+1)
+                var_mod(nzt+1) = var_init(nzt+1) -  &
+                                     dt_3d * w_subs(nzt+1) * tmp_grad
              ENDIF
-          ENDDO
-!
-!--       At the upper boundary, the initial profile is shifted with aid of 
-!--       the gradient tmp_grad. (This is ok if the gradients are linear.)
-          IF ( w_subs(nzt) < 0.0_wp )  THEN
-             tmp_grad = ( var_init(nzt+1) - var_init(nzt) ) * ddzu(nzt+1)
-             var_mod(nzt+1) = var_init(nzt+1) -  &
-                                  dt_3d * w_subs(nzt+1) * tmp_grad
+       
+
+             DO  k = nzt+1, nzb+1, -1
+                IF ( w_subs(k) >= 0.0_wp )  THEN  ! large-scale ascent
+                   var_mod(k) = var_init(k) - dt_3d * w_subs(k) *  &
+                                      ( var_init(k) - var_init(k-1) ) * ddzu(k)
+                ENDIF
+             ENDDO
+!
+!--          At the lower boundary shifting is not necessary because the 
+!--          subsidence velocity w_subs(nzb) vanishes.
+             IF ( w_subs(nzb+1) >= 0.0_wp )  THEN
+                var_mod(nzb) = var_init(nzb)
+             ENDIF
+
+             var_init = var_mod 
+
           ENDIF
-       
-
-          DO  k = nzt+1, nzb+1, -1
-             IF ( w_subs(k) >= 0.0_wp )  THEN  ! large-scale ascent
-                var_mod(k) = var_init(k) - dt_3d * w_subs(k) *  &
-                                   ( var_init(k) - var_init(k-1) ) * ddzu(k)
-             ENDIF
-          ENDDO
-!
-!--       At the lower boundary shifting is not necessary because the 
-!--       subsidence velocity w_subs(nzb) vanishes.
-          IF ( w_subs(nzb+1) >= 0.0_wp )  THEN
-             var_mod(nzb) = var_init(nzb)
-          ENDIF
-
-          var_init = var_mod 
-
        ENDIF
 
Index: palm/trunk/SOURCE/time_integration.f90
===================================================================
--- palm/trunk/SOURCE/time_integration.f90	(revision 1379)
+++ palm/trunk/SOURCE/time_integration.f90	(revision 1380)
@@ -20,5 +20,6 @@
 ! Current revisions:
 ! ------------------
-! 
+! CALL of nudge_ref added 
+! bc_pt_t_val and bc_q_t_val are updated in case nudging is used
 ! 
 ! Former revisions:
@@ -131,6 +132,7 @@
 
     USE arrays_3d,                                                             &
-        ONLY:  diss, e_p, nr_p, prho, pt, pt_p, q, ql, ql_c, ql_v, ql_vp, qr_p,&
-               q_p, ref_state, rho, sa_p, tend, u, u_p, v, vpt, v_p, w_p
+        ONLY:  diss, dzu, e_p, nr_p, prho, pt, pt_p, pt_init, q_init, q, ql,   &
+               ql_c, ql_v, ql_vp, qr_p, q_p, ref_state, rho, sa_p, tend, u,    &
+               u_p, v, vpt, v_p, w_p
 
     USE calc_mean_profile_mod,                                                 &
@@ -140,7 +142,7 @@
         ONLY:  advected_distance_x, advected_distance_y, average_count_3d,     &
                average_count_sp, averaging_interval, averaging_interval_pr,    &
-               averaging_interval_sp, bc_lr_cyc, bc_ns_cyc,                    &
-               call_psolver_at_all_substeps, cloud_droplets, cloud_physics,    &
-               constant_heatflux, create_disturbances, dopr_n,                 &
+               averaging_interval_sp, bc_lr_cyc, bc_ns_cyc, bc_pt_t_val,       &
+               bc_q_t_val, call_psolver_at_all_substeps, cloud_droplets,       &
+               cloud_physics, constant_heatflux, create_disturbances, dopr_n,  &
                constant_diffusion, coupling_mode, coupling_start_time,         &
                current_timestep_number, disturbance_created,                   &
@@ -176,5 +178,5 @@
     USE indices,                                                               &
         ONLY:  i_left, i_right, j_north, j_south, nbgp, nx, nxl, nxlg, nxr,    &
-               nxrg, nyn, nys, nzb, nzb_u_inner, nzb_v_inner 
+               nxrg, nyn, nys, nzb, nzt, nzb_u_inner, nzb_v_inner 
 
     USE interaction_droplets_ptq_mod,                                          &
@@ -187,5 +189,5 @@
 
     USE nudge_mod,                                                             &
-        ONLY:  calc_tnudge
+        ONLY:  calc_tnudge, nudge_ref
 
     USE particle_attributes,                                                   &
@@ -267,4 +269,16 @@
 
 !
+!--    Set pt_init and q_init to the current profiles taken from 
+!--    NUDGING_DATA 
+       IF ( nudging )  THEN
+           CALL nudge_ref ( simulated_time )
+!
+!--        Store temperature gradient at the top boundary for possible Neumann
+!--        boundary condition
+           bc_pt_t_val = ( pt_init(nzt+1) - pt_init(nzt) ) / dzu(nzt+1)
+           bc_q_t_val  = ( q_init(nzt+1) - q_init(nzt) ) / dzu(nzt+1)
+       ENDIF
+
+!
 !--    Execute the user-defined actions
        CALL user_actions( 'before_timestep' )
@@ -312,5 +326,5 @@
 !
 !--       In case of nudging calculate current nudging time scale and horizontal
-!--       means of u,v,pt and q
+!--       means of u, v, pt and q
           IF ( nudging )  THEN
              CALL calc_tnudge( simulated_time )
