Index: palm/trunk/SOURCE/init_grid.f90
===================================================================
--- palm/trunk/SOURCE/init_grid.f90	(revision 559)
+++ palm/trunk/SOURCE/init_grid.f90	(revision 667)
@@ -4,5 +4,10 @@
 ! Current revisions:
 ! -----------------
-! 
+! Definition of new array bounds nxlg, nxrg, nysg, nyng on each PE. 
+! Furthermore the allocation of arrays and steering of loops is done with these
+! parameters. Call of exchange_horiz are modified.
+! In case of dirichlet bounday condition at the bottom zu(0)=0.0
+! dzu_mg has to be set explicitly for a equally spaced grid near bottom.
+! ddzu_pres added to use a equally spaced grid near bottom.
 !
 ! Former revisions:
@@ -76,9 +81,15 @@
 
     REAL, DIMENSION(:,:,:), ALLOCATABLE ::  distance
-
+    
+!
+!   Computation of the array bounds.
+    nxlg = nxl - nbgp
+    nxrg = nxr + nbgp
+    nysg = nys - nbgp
+    nyng = nyn + nbgp
 !
 !-- Allocate grid arrays
     ALLOCATE( ddzu(1:nzt+1), ddzw(1:nzt+1), dd2zu(1:nzt), dzu(1:nzt+1), &
-              dzw(1:nzt+1), l_grid(1:nzt), zu(0:nzt+1), zw(0:nzt+1) )
+              dzw(1:nzt+1), l_grid(1:nzt), zu(nzb:nzt+1), zw(nzb:nzt+1) )
 
 !
@@ -97,9 +108,13 @@
 !
 !--    Grid for atmosphere with surface at z=0 (k=0, w-grid).
-!--    Since the w-level lies on the surface, the first u-level (staggered!)
-!--    lies below the surface (used for "mirror" boundary condition).
 !--    The first u-level above the surface corresponds to the top of the 
 !--    Prandtl-layer.
-       zu(0) = - dz * 0.5
+
+       IF ( ibc_uv_b == 0 .OR. ibc_uv_b == 2 ) THEN
+          zu(0) = 0.0
+      !    zu(0) = - dz * 0.5
+       ELSE
+          zu(0) = - dz * 0.5
+       ENDIF
        zu(1) =   dz * 0.5
 
@@ -173,4 +188,16 @@
        dd2zu(k) = 1.0 / ( dzu(k) + dzu(k+1) )
     ENDDO
+    
+!    
+!-- In case of FFT method or SOR swap inverse grid lenght ddzu to ddzu_fft and 
+!-- modify the lowest entry. This is necessary for atmosphere runs, because
+!-- zu(0) and so ddzu(1) changed. Accompanied with this modified arrays 
+!-- pressure solver uses wrong values and this causes kinks in the profiles
+!-- of turbulent quantities.  
+    IF ( psolver /= 'multigrid' ) THEN
+       ALLOCATE( ddzu_pres(1:nzt+1) )
+       ddzu_pres = ddzu
+       IF( .NOT. ocean ) ddzu_pres(1) = ddzu_pres(2)
+    ENDIF   
 
 !
@@ -187,4 +214,9 @@
 
        dzu_mg(:,maximum_grid_level) = dzu
+!       
+!--    To ensure a equally spaced grid. For ocean runs this is not necessary, 
+!--    because zu(0) does not changed so far. Also this would cause errors 
+!--    if a vertical stretching for ocean runs is used.
+       IF ( .NOT. ocean ) dzu_mg(1,maximum_grid_level) = dzu(2)
        dzw_mg(:,maximum_grid_level) = dzw
        nzt_l = nzt
@@ -239,34 +271,38 @@
 !-- the flag arrays needed for the multigrid method
     gls = 2**( maximum_grid_level )
+
     ALLOCATE( corner_nl(nys:nyn,nxl:nxr), corner_nr(nys:nyn,nxl:nxr),       &
               corner_sl(nys:nyn,nxl:nxr), corner_sr(nys:nyn,nxl:nxr),       &
-              nzb_local(-gls:ny+gls,-gls:nx+gls), nzb_tmp(-1:ny+1,-1:nx+1), &
+              nzb_local(-gls:ny+gls,-gls:nx+gls),                                   &
+              nzb_tmp(-nbgp:ny+nbgp,-nbgp:nx+nbgp),                         &
               wall_l(nys:nyn,nxl:nxr), wall_n(nys:nyn,nxl:nxr),             &
               wall_r(nys:nyn,nxl:nxr), wall_s(nys:nyn,nxl:nxr) )
-    ALLOCATE( fwxm(nys-1:nyn+1,nxl-1:nxr+1), fwxp(nys-1:nyn+1,nxl-1:nxr+1), &
-              fwym(nys-1:nyn+1,nxl-1:nxr+1), fwyp(nys-1:nyn+1,nxl-1:nxr+1), &
-              fxm(nys-1:nyn+1,nxl-1:nxr+1), fxp(nys-1:nyn+1,nxl-1:nxr+1),   &
-              fym(nys-1:nyn+1,nxl-1:nxr+1), fyp(nys-1:nyn+1,nxl-1:nxr+1),   &
-              nzb_s_inner(nys-1:nyn+1,nxl-1:nxr+1),                         &
-              nzb_s_outer(nys-1:nyn+1,nxl-1:nxr+1),                         &
-              nzb_u_inner(nys-1:nyn+1,nxl-1:nxr+1),                         &
-              nzb_u_outer(nys-1:nyn+1,nxl-1:nxr+1),                         &
-              nzb_v_inner(nys-1:nyn+1,nxl-1:nxr+1),                         &
-              nzb_v_outer(nys-1:nyn+1,nxl-1:nxr+1),                         &
-              nzb_w_inner(nys-1:nyn+1,nxl-1:nxr+1),                         &
-              nzb_w_outer(nys-1:nyn+1,nxl-1:nxr+1),                         &
-              nzb_diff_s_inner(nys-1:nyn+1,nxl-1:nxr+1),                    &
-              nzb_diff_s_outer(nys-1:nyn+1,nxl-1:nxr+1),                    &
-              nzb_diff_u(nys-1:nyn+1,nxl-1:nxr+1),                          &
-              nzb_diff_v(nys-1:nyn+1,nxl-1:nxr+1),                          &
-              nzb_2d(nys-1:nyn+1,nxl-1:nxr+1),                              &
-              wall_e_x(nys-1:nyn+1,nxl-1:nxr+1),                            &
-              wall_e_y(nys-1:nyn+1,nxl-1:nxr+1),                            &
-              wall_u(nys-1:nyn+1,nxl-1:nxr+1),                              &
-              wall_v(nys-1:nyn+1,nxl-1:nxr+1),                              &
-              wall_w_x(nys-1:nyn+1,nxl-1:nxr+1),                            &
-              wall_w_y(nys-1:nyn+1,nxl-1:nxr+1) )
-
-    ALLOCATE( l_wall(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) )
+    ALLOCATE( fwxm(nysg:nyng,nxlg:nxrg), fwxp(nysg:nyng,nxlg:nxrg),         &
+              fwym(nysg:nyng,nxlg:nxrg), fwyp(nysg:nyng,nxlg:nxrg),         &
+              fxm(nysg:nyng,nxlg:nxrg), fxp(nysg:nyng,nxlg:nxrg),           &
+              fym(nysg:nyng,nxlg:nxrg), fyp(nysg:nyng,nxlg:nxrg),           &
+              nzb_s_inner(nysg:nyng,nxlg:nxrg),                             &
+              nzb_s_outer(nysg:nyng,nxlg:nxrg),                             &
+              nzb_u_inner(nysg:nyng,nxlg:nxrg),                             &
+              nzb_u_outer(nysg:nyng,nxlg:nxrg),                             &
+              nzb_v_inner(nysg:nyng,nxlg:nxrg),                             &
+              nzb_v_outer(nysg:nyng,nxlg:nxrg),                             &
+              nzb_w_inner(nysg:nyng,nxlg:nxrg),                             &
+              nzb_w_outer(nysg:nyng,nxlg:nxrg),                             &
+              nzb_diff_s_inner(nysg:nyng,nxlg:nxrg),                        &
+              nzb_diff_s_outer(nysg:nyng,nxlg:nxrg),                        &
+              nzb_diff_u(nysg:nyng,nxlg:nxrg),                              &
+              nzb_diff_v(nysg:nyng,nxlg:nxrg),                              &
+              nzb_2d(nysg:nyng,nxlg:nxrg),                                  &
+              wall_e_x(nysg:nyng,nxlg:nxrg),                                &
+              wall_e_y(nysg:nyng,nxlg:nxrg),                                &
+              wall_u(nysg:nyng,nxlg:nxrg),                                  &
+              wall_v(nysg:nyng,nxlg:nxrg),                                  &
+              wall_w_x(nysg:nyng,nxlg:nxrg),                                &
+              wall_w_y(nysg:nyng,nxlg:nxrg) )
+
+
+
+    ALLOCATE( l_wall(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
 
     nzb_s_inner = nzb;  nzb_s_outer = nzb
@@ -327,6 +363,6 @@
     vertical_influence(0) = vertical_influence(1)
 
-    DO  i = nxl-1, nxr+1
-       DO  j = nys-1, nyn+1
+    DO  i = nxlg, nxrg
+       DO  j = nysg, nyng
           DO  k = nzb_s_inner(j,i) + 1, &
                   nzb_s_inner(j,i) + vertical_influence(nzb_s_inner(j,i))
@@ -477,4 +513,6 @@
           nzb_local(:,-gls:-1)        = nzb_local(:,nx-gls+1:nx)
           nzb_local(:,nx+1:nx+gls)    = nzb_local(:,0:gls-1)
+
+
       
           GOTO 12
@@ -588,5 +626,5 @@
 !--    nzb_s_outer: 
 !--    extend nzb_local east-/westwards first, then north-/southwards
-       nzb_tmp = nzb_local(-1:ny+1,-1:nx+1)
+       nzb_tmp = nzb_local(-nbgp:ny+nbgp,-nbgp:nx+nbgp)
        DO  j = -1, ny + 1
           DO  i = 0, nx
@@ -620,5 +658,5 @@
 !--    nzb_u_inner: 
 !--    extend nzb_local rightwards only
-       nzb_tmp = nzb_local(-1:ny+1,-1:nx+1)
+       nzb_tmp = nzb_local(-nbgp:ny+nbgp,-nbgp:nx+nbgp)
        DO  j = -1, ny + 1
           DO  i = 0, nx + 1
@@ -626,5 +664,5 @@
           ENDDO
        ENDDO
-       nzb_u_inner = nzb_tmp(nys-1:nyn+1,nxl-1:nxr+1)
+       nzb_u_inner = nzb_tmp(nysg:nyng,nxlg:nxrg)
 
 !
@@ -652,5 +690,5 @@
 !--    nzb_v_inner:
 !--    extend nzb_local northwards only
-       nzb_tmp = nzb_local(-1:ny+1,-1:nx+1)
+       nzb_tmp = nzb_local(-nbgp:ny+nbgp,-nbgp:nx+nbgp)
        DO  i = -1, nx + 1
           DO  j = 0, ny + 1
@@ -658,5 +696,5 @@
           ENDDO
        ENDDO
-       nzb_v_inner = nzb_tmp(nys-1:nyn+1,nxl-1:nxr+1)
+       nzb_v_inner = nzb_tmp(nys-nbgp:nyn+nbgp,nxl-nbgp:nxr+nbgp)
 
 !
@@ -1096,5 +1134,6 @@
 !
 !-- Need to set lateral boundary conditions for l_wall
-    CALL exchange_horiz( l_wall )
+
+    CALL exchange_horiz( l_wall, nbgp )
 
     DEALLOCATE( corner_nl, corner_nr, corner_sl, corner_sr, nzb_local, &
