Index: palm/trunk/SOURCE/init_3d_model.f90
===================================================================
--- palm/trunk/SOURCE/init_3d_model.f90	(revision 760)
+++ palm/trunk/SOURCE/init_3d_model.f90	(revision 767)
@@ -7,5 +7,6 @@
 ! Current revisions:
 ! ------------------
-! 
+! adjustments for prescribed u,v-profiles
+! bugfix: dirichlet_0 conditions for ug/vg moved to check_parameters
 !
 ! Former revisions:
@@ -694,13 +695,6 @@
 !--    Apply channel flow boundary condition
        IF ( TRIM( bc_uv_t ) == 'dirichlet_0' )  THEN
-
           u(nzt+1,:,:) = 0.0
           v(nzt+1,:,:) = 0.0
-
-!--       For the Dirichlet condition to be correctly applied at the top, set
-!--       ug and vg to zero there
-          ug(nzt+1)    = 0.0
-          vg(nzt+1)    = 0.0
-
        ENDIF
 
@@ -937,6 +931,7 @@
     THEN
 !
-!--    When reading data for cyclic fill of 3D prerun data, first read
-!--    some of the global variables from restart file
+!--    When reading data for cyclic fill of 3D prerun data files, read
+!--    some of the global variables from the restart file which are required
+!--    for initializing the inflow
        IF ( TRIM( initializing_actions ) == 'cyclic_fill' )  THEN
 
@@ -951,79 +946,4 @@
           ENDDO
 
-!
-!--       Initialization of the turbulence recycling method
-          IF ( turbulent_inflow )  THEN
-!
-!--          Store temporally and horizontally averaged vertical profiles to be
-!--          used as mean inflow profiles
-             ALLOCATE( mean_inflow_profiles(nzb:nzt+1,5) )
-
-             mean_inflow_profiles(:,1) = hom_sum(:,1,0)    ! u
-             mean_inflow_profiles(:,2) = hom_sum(:,2,0)    ! v
-             mean_inflow_profiles(:,4) = hom_sum(:,4,0)    ! pt
-             mean_inflow_profiles(:,5) = hom_sum(:,8,0)    ! e
-
-!
-!--          Use these mean profiles for the inflow (provided that Dirichlet
-!--          conditions are used)
-             IF ( inflow_l )  THEN
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      u(k,j,nxlg:-1)  = mean_inflow_profiles(k,1)
-                      v(k,j,nxlg:-1)  = mean_inflow_profiles(k,2)
-                      w(k,j,nxlg:-1)  = 0.0
-                      pt(k,j,nxlg:-1) = mean_inflow_profiles(k,4)
-                      e(k,j,nxlg:-1)  = mean_inflow_profiles(k,5)
-                   ENDDO
-                ENDDO
-             ENDIF
-
-!
-!--          Calculate the damping factors to be used at the inflow. For a
-!--          turbulent inflow the turbulent fluctuations have to be limited
-!--          vertically because otherwise the turbulent inflow layer will grow
-!--          in time.
-             IF ( inflow_damping_height == 9999999.9 )  THEN
-!
-!--             Default: use the inversion height calculated by the prerun; if
-!--             this is zero, inflow_damping_height must be explicitly
-!--             specified.
-                IF ( hom_sum(nzb+6,pr_palm,0) /= 0.0 )  THEN
-                   inflow_damping_height = hom_sum(nzb+6,pr_palm,0)
-                ELSE
-                   WRITE( message_string, * ) 'inflow_damping_height must be ',&
-                        'explicitly specified because&the inversion height ', &
-                        'calculated by the prerun is zero.'
-                   CALL message( 'init_3d_model', 'PA0318', 1, 2, 0, 6, 0 )
-                ENDIF
-
-             ENDIF
-
-             IF ( inflow_damping_width == 9999999.9 )  THEN
-!
-!--             Default for the transition range: one tenth of the undamped
-!--             layer
-                inflow_damping_width = 0.1 * inflow_damping_height
-
-             ENDIF
-
-             ALLOCATE( inflow_damping_factor(nzb:nzt+1) )
-
-             DO  k = nzb, nzt+1
-
-                IF ( zu(k) <= inflow_damping_height )  THEN
-                   inflow_damping_factor(k) = 1.0
-                ELSEIF ( zu(k) <= inflow_damping_height +  &
-                                  inflow_damping_width )  THEN
-                   inflow_damping_factor(k) = 1.0 -                            &
-                                           ( zu(k) - inflow_damping_height ) / &
-                                           inflow_damping_width
-                ELSE
-                   inflow_damping_factor(k) = 0.0
-                ENDIF
-
-             ENDDO
-          ENDIF
-
        ENDIF
 
@@ -1038,4 +958,102 @@
 #endif
        ENDDO
+
+!
+!--    Initialization of the turbulence recycling method
+       IF ( TRIM( initializing_actions ) == 'cyclic_fill'  .AND.  &
+            turbulent_inflow )  THEN
+!
+!--       First store the profiles to be used at the inflow.
+!--       These profiles are the (temporally) and horizontally averaged vertical
+!--       profiles from the prerun. Alternatively, prescribed profiles
+!--       for u,v-components can be used.
+          ALLOCATE( mean_inflow_profiles(nzb:nzt+1,5) )
+
+          IF ( use_prescribed_profile_data )  THEN
+             mean_inflow_profiles(:,1) = u_init            ! u
+             mean_inflow_profiles(:,2) = v_init            ! v
+          ELSE
+             mean_inflow_profiles(:,1) = hom_sum(:,1,0)    ! u
+             mean_inflow_profiles(:,2) = hom_sum(:,2,0)    ! v
+          ENDIF
+          mean_inflow_profiles(:,4) = hom_sum(:,4,0)       ! pt
+          mean_inflow_profiles(:,5) = hom_sum(:,8,0)       ! e
+
+!
+!--       If necessary, adjust the horizontal flow field to the prescribed
+!--       profiles
+          IF ( use_prescribed_profile_data )  THEN
+             DO  i = nxlg, nxrg
+                DO  j = nysg, nyng
+                   DO  k = nzb, nzt+1
+                      u(k,j,i) = u(k,j,i) - hom_sum(k,1,0) + u_init(k)
+                      v(k,j,i) = v(k,j,i) - hom_sum(k,2,0) + v_init(k)
+                   ENDDO
+                ENDDO
+             ENDDO
+          ENDIF
+
+!
+!--       Use these mean profiles at the inflow (provided that Dirichlet
+!--       conditions are used)
+          IF ( inflow_l )  THEN
+             DO  j = nysg, nyng
+                DO  k = nzb, nzt+1
+                   u(k,j,nxlg:-1)  = mean_inflow_profiles(k,1)
+                   v(k,j,nxlg:-1)  = mean_inflow_profiles(k,2)
+                   w(k,j,nxlg:-1)  = 0.0
+                   pt(k,j,nxlg:-1) = mean_inflow_profiles(k,4)
+                   e(k,j,nxlg:-1)  = mean_inflow_profiles(k,5)
+                ENDDO
+             ENDDO
+          ENDIF
+
+!
+!--       Calculate the damping factors to be used at the inflow. For a
+!--       turbulent inflow the turbulent fluctuations have to be limited
+!--       vertically because otherwise the turbulent inflow layer will grow
+!--       in time.
+          IF ( inflow_damping_height == 9999999.9 )  THEN
+!
+!--          Default: use the inversion height calculated by the prerun; if
+!--          this is zero, inflow_damping_height must be explicitly
+!--          specified.
+             IF ( hom_sum(nzb+6,pr_palm,0) /= 0.0 )  THEN
+                inflow_damping_height = hom_sum(nzb+6,pr_palm,0)
+             ELSE
+                WRITE( message_string, * ) 'inflow_damping_height must be ',&
+                     'explicitly specified because&the inversion height ', &
+                     'calculated by the prerun is zero.'
+                CALL message( 'init_3d_model', 'PA0318', 1, 2, 0, 6, 0 )
+             ENDIF
+
+          ENDIF
+
+          IF ( inflow_damping_width == 9999999.9 )  THEN
+!
+!--          Default for the transition range: one tenth of the undamped
+!--          layer
+             inflow_damping_width = 0.1 * inflow_damping_height
+
+          ENDIF
+
+          ALLOCATE( inflow_damping_factor(nzb:nzt+1) )
+
+          DO  k = nzb, nzt+1
+
+             IF ( zu(k) <= inflow_damping_height )  THEN
+                inflow_damping_factor(k) = 1.0
+             ELSEIF ( zu(k) <= inflow_damping_height +  &
+                               inflow_damping_width )  THEN
+                inflow_damping_factor(k) = 1.0 -                            &
+                                        ( zu(k) - inflow_damping_height ) / &
+                                        inflow_damping_width
+             ELSE
+                inflow_damping_factor(k) = 0.0
+             ENDIF
+
+          ENDDO
+
+       ENDIF
 
 !
@@ -1146,5 +1164,41 @@
     IF ( conserve_volume_flow )  THEN
 
-       IF  ( TRIM( initializing_actions ) == 'cyclic_fill' )  THEN
+       IF ( use_prescribed_profile_data )  THEN
+
+          volume_flow_initial_l = 0.0
+          volume_flow_area_l    = 0.0
+
+          IF ( nxr == nx )  THEN
+             DO  j = nys, nyn
+                DO  k = nzb_2d(j,nx)+1, nzt
+                   volume_flow_initial_l(1) = volume_flow_initial_l(1) + &
+                                              u_init(k) * dzw(k)
+                   volume_flow_area_l(1)    = volume_flow_area_l(1) + dzw(k)
+                ENDDO
+             ENDDO
+          ENDIF
+          
+          IF ( nyn == ny )  THEN
+             DO  i = nxl, nxr
+                DO  k = nzb_2d(ny,i)+1, nzt  
+                   volume_flow_initial_l(2) = volume_flow_initial_l(2) + &
+                                              v_init(k) * dzw(k)
+                   volume_flow_area_l(2)    = volume_flow_area_l(2) + dzw(k)
+                ENDDO
+             ENDDO
+          ENDIF
+
+#if defined( __parallel )
+          CALL MPI_ALLREDUCE( volume_flow_initial_l(1), volume_flow_initial(1),&
+                              2, MPI_REAL, MPI_SUM, comm2d, ierr )
+          CALL MPI_ALLREDUCE( volume_flow_area_l(1), volume_flow_area(1),      &
+                              2, MPI_REAL, MPI_SUM, comm2d, ierr )
+
+#else
+          volume_flow_initial = volume_flow_initial_l
+          volume_flow_area    = volume_flow_area_l
+#endif  
+
+       ELSEIF ( TRIM( initializing_actions ) == 'cyclic_fill' )  THEN
 
           volume_flow_initial_l = 0.0
