Index: palm/trunk/UTIL/inifor/README
===================================================================
--- palm/trunk/UTIL/inifor/README	(revision 3612)
+++ palm/trunk/UTIL/inifor/README	(revision 3613)
@@ -1,3 +1,3 @@
-# INIFOR - Mesoscale Interface for Initializing and Forcing PALM-4U (v1.4.1)
+# INIFOR - Mesoscale Interface for Initializing and Forcing PALM-4U (v1.4.3)
 
 INIFOR provides the meteorological fields required to initialize and drive the
Index: palm/trunk/UTIL/inifor/src/inifor.f90
===================================================================
--- palm/trunk/UTIL/inifor/src/inifor.f90	(revision 3612)
+++ palm/trunk/UTIL/inifor/src/inifor.f90	(revision 3613)
@@ -26,4 +26,7 @@
 ! -----------------
 ! $Id$
+! Moved version output to setup_parameters()
+! 
+! 3557 2018-11-22 16:01:22Z eckhard
 ! Updated documentation
 ! 
@@ -121,5 +124,4 @@
 !------------------------------------------------------------------------------
  CALL run_control('init', 'void')
-    CALL report('main_loop', 'Running INIFOR version ' // VERSION)
 
 !
Index: palm/trunk/UTIL/inifor/src/inifor_defs.f90
===================================================================
--- palm/trunk/UTIL/inifor/src/inifor_defs.f90	(revision 3612)
+++ palm/trunk/UTIL/inifor/src/inifor_defs.f90	(revision 3613)
@@ -26,4 +26,8 @@
 ! -----------------
 ! $Id$
+! Bumped version number
+! 
+! 
+! 3557 2018-11-22 16:01:22Z eckhard
 ! Updated documentation
 ! 
@@ -119,5 +123,5 @@
  INTEGER, PARAMETER          ::  FORCING_STEP = 1             !< Number of hours between forcing time steps [h]
  REAL(dp), PARAMETER         ::  NUDGING_TAU = 21600.0_dp     !< Nudging relaxation time scale [s]
- CHARACTER(LEN=*), PARAMETER ::  VERSION = '1.4.2'            !< INIFOR version number
+ CHARACTER(LEN=*), PARAMETER ::  VERSION = '1.4.3'            !< INIFOR version number
  CHARACTER(LEN=*), PARAMETER ::  COPYRIGHT = 'Copyright 2017-2018 Leibniz Universitaet Hannover' // &
      ACHAR( 10 ) // ' Copyright 2017-2018 Deutscher Wetterdienst Offenbach' !< Copyright notice
Index: palm/trunk/UTIL/inifor/src/inifor_grid.f90
===================================================================
--- palm/trunk/UTIL/inifor/src/inifor_grid.f90	(revision 3612)
+++ palm/trunk/UTIL/inifor/src/inifor_grid.f90	(revision 3613)
@@ -26,4 +26,12 @@
 ! -----------------
 ! $Id$
+! Average initial profiles only over PALM domain region, not the
+!     geostrophic-wind averaging region
+! Fix unintended modification of COSMO heights
+! Fix commenting out of setup_volumentric setting
+! Moved version output to setup_parameters()
+! 
+! 
+! 3557 2018-11-22 16:01:22Z eckhard
 ! Updated documentation
 !
@@ -150,8 +158,12 @@
     REAL(dp) ::  z_top             = 0.0_dp       !< height of the scalar top boundary [m]
     REAL(dp) ::  zw_top            = 0.0_dp       !< height of the vertical velocity top boundary [m]
-    REAL(dp) ::  lonmin            = 0.0_dp       !< Minimunm longitude of COSMO-DE's rotated-pole grid
-    REAL(dp) ::  lonmax            = 0.0_dp       !< Maximum longitude of COSMO-DE's rotated-pole grid
-    REAL(dp) ::  latmin            = 0.0_dp       !< Minimunm latitude of COSMO-DE's rotated-pole grid
-    REAL(dp) ::  latmax            = 0.0_dp       !< Maximum latitude of COSMO-DE's rotated-pole grid
+    REAL(dp) ::  lonmin_cosmo      = 0.0_dp       !< Minimunm longitude of COSMO-DE's rotated-pole grid [COSMO rotated-pole rad]
+    REAL(dp) ::  lonmax_cosmo      = 0.0_dp       !< Maximum longitude of COSMO-DE's rotated-pole grid [COSMO rotated-pole rad]
+    REAL(dp) ::  latmin_cosmo      = 0.0_dp       !< Minimunm latitude of COSMO-DE's rotated-pole grid [COSMO rotated-pole rad]
+    REAL(dp) ::  latmax_cosmo      = 0.0_dp       !< Maximum latitude of COSMO-DE's rotated-pole grid [COSMO rotated-pole rad]
+    REAL(dp) ::  lonmin_palm       = 0.0_dp       !< Minimunm longitude of PALM grid [COSMO rotated-pole rad]
+    REAL(dp) ::  lonmax_palm       = 0.0_dp       !< Maximum longitude of PALM grid [COSMO rotated-pole rad]
+    REAL(dp) ::  latmin_palm       = 0.0_dp       !< Minimunm latitude of PALM grid [COSMO rotated-pole rad]
+    REAL(dp) ::  latmax_palm       = 0.0_dp       !< Maximum latitude of PALM grid [COSMO rotated-pole rad]
     REAL(dp) ::  latitude          = 0.0_dp       !< geographical latitude of the PALM-4U origin, from inipar namelist [deg]
     REAL(dp) ::  longitude         = 0.0_dp       !< geographical longitude of the PALM-4U origin, from inipar namelist [deg]
@@ -255,10 +267,12 @@
     TYPE(grid_definition), TARGET ::  w_south_intermediate            !< intermediate grid for southern w boundary condition
     TYPE(grid_definition), TARGET ::  w_top_intermediate              !< intermediate grid for top w boundary condition
-    TYPE(grid_definition), TARGET ::  north_averaged_scalar_profile   !< grid of the northern scalar averaging region
-    TYPE(grid_definition), TARGET ::  south_averaged_scalar_profile   !< grid of the southern scalar averaging region
-    TYPE(grid_definition), TARGET ::  west_averaged_scalar_profile    !< grid of the western scalar averaging region
-    TYPE(grid_definition), TARGET ::  east_averaged_scalar_profile    !< grid of the eastern scalar averaging region
-    TYPE(grid_definition), TARGET ::  averaged_scalar_profile         !< grid of the central scalar averaging region
-    TYPE(grid_definition), TARGET ::  averaged_w_profile              !< grid of the central w-velocity averaging region
+    TYPE(grid_definition), TARGET ::  north_averaged_scalar_profile   !< grid of the northern geostrophic scalar averaging region
+    TYPE(grid_definition), TARGET ::  south_averaged_scalar_profile   !< grid of the southern geostrophic scalar averaging region
+    TYPE(grid_definition), TARGET ::  west_averaged_scalar_profile    !< grid of the western geostrophic scalar averaging region
+    TYPE(grid_definition), TARGET ::  east_averaged_scalar_profile    !< grid of the eastern geostrophic scalar averaging region
+    TYPE(grid_definition), TARGET ::  averaged_scalar_profile         !< grid of the central geostrophic scalar averaging region
+    TYPE(grid_definition), TARGET ::  averaged_w_profile              !< grid of the central geostrophic w-velocity averaging region
+    TYPE(grid_definition), TARGET ::  averaged_initial_scalar_profile !< averaging grid for initial scalar profiles
+    TYPE(grid_definition), TARGET ::  averaged_initial_w_profile      !< averaging grid for the initial w profile
 
     TYPE(io_group), ALLOCATABLE, TARGET ::  io_group_list(:)  !< List of I/O groups, which group together output variables that share the same input variable
@@ -406,4 +420,5 @@
        CALL validate_config( cfg ) 
 
+       CALL report('main_loop', 'Running INIFOR version ' // VERSION)
        CALL report('setup_parameters', "initialization mode: " // TRIM(cfg % ic_mode))
        CALL report('setup_parameters', "       forcing mode: " // TRIM(cfg % bc_mode))
@@ -501,8 +516,8 @@
        ndepths = SIZE(depths)
 
-       lonmin = MINVAL(rlon) * TO_RADIANS
-       lonmax = MAXVAL(rlon) * TO_RADIANS
-       latmin = MINVAL(rlat) * TO_RADIANS
-       latmax = MAXVAL(rlat) * TO_RADIANS
+       lonmin_cosmo = MINVAL(rlon) * TO_RADIANS
+       lonmax_cosmo = MAXVAL(rlon) * TO_RADIANS
+       latmin_cosmo = MINVAL(rlat) * TO_RADIANS
+       latmax_cosmo = MAXVAL(rlat) * TO_RADIANS
  CALL run_control('time', 'comp')
 
@@ -691,5 +706,5 @@
                xmin=0.0_dp, xmax=lx,                                           &
                ymin=0.0_dp, ymax=ly,                                           &
-               x0=x0, y0=y0, z0=z0,                      &
+               x0=x0, y0=y0, z0=z0,                                            &
                nx=nx, ny=ny, nz=nz, z=z, zw=zw, ic_mode=cfg % ic_mode)
 
@@ -697,7 +712,7 @@
 !--    Subtracting 1 because arrays will be allocated with nlon + 1 elements.
        CALL init_grid_definition('cosmo-de', grid=cosmo_grid,                  &
-               xmin=lonmin, xmax=lonmax,                                       &
-               ymin=latmin, ymax=latmax,                                       &
-               x0=x0, y0=y0, z0=0.0_dp,             &
+               xmin=lonmin_cosmo, xmax=lonmax_cosmo,                           &
+               ymin=latmin_cosmo, ymax=latmax_cosmo,                           &
+               x0=x0, y0=y0, z0=0.0_dp,                                        &
                nx=nlon-1, ny=nlat-1, nz=nlev-1)
 
@@ -710,5 +725,5 @@
                xmin=0.0_dp, xmax=lx,                                           &
                ymin=0.0_dp, ymax=ly,                                           &
-               x0=x0, y0=y0, z0=z0,                      &
+               x0=x0, y0=y0, z0=z0,                                            &
                nx=nx, ny=ny, nz=nlev-2)
 
@@ -1002,4 +1017,21 @@
 ! Section 3: Define profile grids
 !------------------------------------------------------------------------------
+
+       lonmin_palm = MINVAL(palm_intermediate % clon)
+       lonmax_palm = MAXVAL(palm_intermediate % clon)
+       latmin_palm = MINVAL(palm_intermediate % clat)
+       latmax_palm = MAXVAL(palm_intermediate % clat)
+
+       CALL init_averaging_grid(averaged_initial_scalar_profile, cosmo_grid,   &
+               x = 0.5_dp * lx, y = 0.5_dp * ly, z = z, z0 = z0,               &
+               lonmin = lonmin_palm, lonmax = lonmax_palm,                     &
+               latmin = latmin_palm, latmax = latmax_palm,                     &
+               kind='scalar')
+
+       CALL init_averaging_grid(averaged_initial_w_profile, cosmo_grid,        &
+               x = 0.5_dp * lx, y = 0.5_dp * ly, z = zw, z0 = z0,              &
+               lonmin = lonmin_palm, lonmax = lonmax_palm,                     &
+               latmin = latmin_palm, latmax = latmax_palm,                     &
+               kind='w')
 
        CALL init_averaging_grid(averaged_scalar_profile, cosmo_grid,           &
@@ -1176,5 +1208,5 @@
 !--    domain volume. Instead we need vertical weights for the intermediate
 !--    profile grids, which get computed in setup_averaging().
-!--    setup_volumetric = .TRUE.
+       setup_volumetric = .TRUE.
        IF (PRESENT(ic_mode))  THEN
           IF (TRIM(ic_mode) == 'profile')  setup_volumetric = .FALSE.
@@ -1447,5 +1479,5 @@
 ! Description:
 ! ------------
-!> Initializes averagin_grid-type variables.
+!> Initializes averaging grids
 !> 
 !> Input parameters:
@@ -1470,5 +1502,5 @@
 !> Output parameters:
 !> ------------------
-!> avg_grid : averaging_grid variable to be initialized.
+!> avg_grid : averagin grid to be initialized
 !------------------------------------------------------------------------------!
     SUBROUTINE init_averaging_grid(avg_grid, cosmo_grid, x, y, z, z0,          &
@@ -1479,5 +1511,8 @@
        REAL(dp), INTENT(IN)                 ::  x, y, z0
        REAL(dp), INTENT(IN), TARGET         ::  z(:)
-       REAL(dp), INTENT(IN)                 ::  lonmin, lonmax, latmin, latmax
+       REAL(dp), INTENT(IN)                 ::  lonmin !< lower longitude bound of the averaging grid region [COSMO rotated-pole rad]
+       REAL(dp), INTENT(IN)                 ::  lonmax !< upper longitude bound of the averaging grid region [COSMO rotated-pole rad]
+       REAL(dp), INTENT(IN)                 ::  latmin !< lower latitude bound of the averaging grid region [COSMO rotated-pole rad]
+       REAL(dp), INTENT(IN)                 ::  latmax !< lower latitude bound of the averaging grid region [COSMO rotated-pole rad]
 
        CHARACTER(LEN=*), INTENT(IN)         ::  kind
@@ -1529,26 +1564,17 @@
 !
 !--    For level-besed averaging, compute average heights
-       level_based_averaging = .TRUE.
+       level_based_averaging = ( TRIM(cfg % averaging_mode) == 'level' )
        IF (level_based_averaging)  THEN
           ALLOCATE(avg_grid % h(1,1,SIZE(avg_grid % cosmo_h, 3)) )
  
-          CALL average_2d(avg_grid % cosmo_h, avg_grid % h(1,1,:),                            &
+          CALL average_2d(avg_grid % cosmo_h, avg_grid % h(1,1,:),             &
                           avg_grid % iii, avg_grid % jjj)
        END IF
 
 !
-!--    Copy averaged grid to all COSMO columns, leads to computing the same
-!--    vertical interpolation weights for all columns and to COSMO grid level
-!--    based averaging onto the averaged COSMO heights.
-       IF ( TRIM(cfg % averaging_mode) == 'level' )  THEN
-          FORALL(                                                              &
-             i=1:SIZE(avg_grid % cosmo_h, 1),                                  &
-             j=1:SIZE(avg_grid % cosmo_h, 2)                                   &
-          )   avg_grid % cosmo_h(i,j,:) = avg_grid % h(1,1,:)
-       END IF
-
-!
 !--    Compute vertical weights and neighbours
-       CALL find_vertical_neighbours_and_weights_average(avg_grid)
+       CALL find_vertical_neighbours_and_weights_average(                      &
+          avg_grid, level_based_averaging                                      &
+       )
 
     END SUBROUTINE init_averaging_grid
@@ -2433,5 +2459,5 @@
        )
        IF (TRIM(ic_mode) == 'profile')  THEN
-          output_var_table(3) % averaging_grid => averaged_scalar_profile
+          output_var_table(3) % averaging_grid => averaged_initial_scalar_profile
        END IF
 
@@ -2509,5 +2535,5 @@
        )
        IF (TRIM(ic_mode) == 'profile')  THEN
-          output_var_table(9) % averaging_grid => averaged_scalar_profile
+          output_var_table(9) % averaging_grid => averaged_initial_scalar_profile
        END IF
 
@@ -2585,5 +2611,5 @@
        )
        IF (TRIM(ic_mode) == 'profile')  THEN
-          output_var_table(15) % averaging_grid => averaged_scalar_profile
+          output_var_table(15) % averaging_grid => averaged_initial_scalar_profile
        END IF 
 
@@ -2661,5 +2687,5 @@
        )
        IF (TRIM(ic_mode) == 'profile')  THEN
-          output_var_table(21) % averaging_grid => averaged_scalar_profile
+          output_var_table(21) % averaging_grid => averaged_initial_scalar_profile
        END IF
 
@@ -2737,5 +2763,5 @@
        )
        IF (TRIM(ic_mode) == 'profile')  THEN
-          output_var_table(27) % averaging_grid => averaged_w_profile
+          output_var_table(27) % averaging_grid => averaged_initial_w_profile
        END IF
 
Index: palm/trunk/UTIL/inifor/src/inifor_transform.f90
===================================================================
--- palm/trunk/UTIL/inifor/src/inifor_transform.f90	(revision 3612)
+++ palm/trunk/UTIL/inifor/src/inifor_transform.f90	(revision 3613)
@@ -26,4 +26,9 @@
 ! -----------------
 ! $Id$
+! Use averaged heights profile for level-based averaging instead of modified
+!    COSMO heights array
+! 
+! 
+! 3557 2018-11-22 16:01:22Z eckhard
 ! Updated documentation
 ! 
@@ -898,12 +903,17 @@
 !> iii(:) and jjj(:).
 !------------------------------------------------------------------------------!
-    SUBROUTINE find_vertical_neighbours_and_weights_average( avg_grid )
-       TYPE(grid_definition), INTENT(INOUT) ::  avg_grid
-
-       INTEGER  ::  i, j, k_palm, k_intermediate, l, nlev
-       LOGICAL  ::  point_is_below_grid, point_is_above_grid,                  &
-                    point_is_in_current_cell
-       REAL(dp) ::  current_height, column_base, column_top, h_top, h_bottom,  &
-                    weight
+    SUBROUTINE find_vertical_neighbours_and_weights_average(                   &
+       avg_grid, level_based_averaging                                         &
+    )
+
+       TYPE(grid_definition), INTENT(INOUT), TARGET ::  avg_grid
+       LOGICAL                                      ::  level_based_averaging
+
+       INTEGER           ::  i, j, k_palm, k_intermediate, l, nlev
+       LOGICAL           ::  point_is_below_grid, point_is_above_grid,         &
+                             point_is_in_current_cell
+       REAL(dp)          ::  current_height, column_base, column_top, h_top,   &
+                             h_bottom, weight
+       REAL(dp), POINTER ::  cosmo_h(:,:,:)
 
 
@@ -911,4 +921,10 @@
 
        nlev = SIZE(avg_grid % cosmo_h, 3)
+
+       IF (level_based_averaging)  THEN
+          cosmo_h => avg_grid % h
+       ELSE
+          cosmo_h => avg_grid % cosmo_h
+       END IF
 
 !
@@ -916,9 +932,14 @@
        DO l = 1, avg_grid % n_columns
 
-          i = avg_grid % iii(l)
-          j = avg_grid % jjj(l)
-
-          column_base = avg_grid % cosmo_h(i,j,1)
-          column_top  = avg_grid % cosmo_h(i,j,nlev)
+          IF (level_based_averaging)  THEN
+             i = 1
+             j = 1
+          ELSE
+             i = avg_grid % iii(l)
+             j = avg_grid % jjj(l)
+          END IF
+
+          column_base = cosmo_h(i,j,1)
+          column_top  = cosmo_h(i,j,nlev)
 
 !
@@ -934,6 +955,6 @@
 !--          current height within it
              current_height = avg_grid % z(k_palm) + avg_grid % z0
-             h_top    = avg_grid % cosmo_h(i,j,k_intermediate+1)
-             h_bottom = avg_grid % cosmo_h(i,j,k_intermediate)
+             h_top    = cosmo_h(i,j,k_intermediate+1)
+             h_bottom = cosmo_h(i,j,k_intermediate)
 
 !
@@ -972,6 +993,6 @@
                    k_intermediate = k_intermediate + 1
 
-                   h_top    = avg_grid % cosmo_h(i,j,k_intermediate+1)
-                   h_bottom = avg_grid % cosmo_h(i,j,k_intermediate)
+                   h_top    = cosmo_h(i,j,k_intermediate+1)
+                   h_bottom = cosmo_h(i,j,k_intermediate)
                    point_is_in_current_cell = (                                &
                       current_height >= h_bottom .AND.                         &
