Index: palm/trunk/UTIL/inifor/src/inifor.f90
===================================================================
--- palm/trunk/UTIL/inifor/src/inifor.f90	(revision 3534)
+++ palm/trunk/UTIL/inifor/src/inifor.f90	(revision 3537)
@@ -26,4 +26,8 @@
 ! -----------------
 ! $Id$
+! Print version number on program start
+! 
+! 
+! 3456 2018-10-30 14:29:54Z eckhard
 ! NetCDf output of internal arrays only with --debug option 
 ! 
@@ -110,4 +114,5 @@
 !------------------------------------------------------------------------------
  CALL run_control('init', 'void')
+    CALL report('main_loop', 'Running INIFOR version ' // VERSION)
 
     ! Initialize INIFOR's parameters from command-line interface and namelists
Index: palm/trunk/UTIL/inifor/src/inifor_defs.f90
===================================================================
--- palm/trunk/UTIL/inifor/src/inifor_defs.f90	(revision 3534)
+++ palm/trunk/UTIL/inifor/src/inifor_defs.f90	(revision 3537)
@@ -26,4 +26,8 @@
 ! -----------------
 ! $Id$
+! Bumped version number
+! 
+! 
+! 3534 2018-11-19 15:35:16Z raasch
 ! NEW_LINE intrinsic replaced by ACHAR to avoid compile time error
 ! 
@@ -101,5 +105,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.1'            !< INIFOR version number
+ CHARACTER(LEN=*), PARAMETER ::  VERSION = '1.4.2'            !< 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 3534)
+++ palm/trunk/UTIL/inifor/src/inifor_grid.f90	(revision 3537)
@@ -26,4 +26,9 @@
 ! -----------------
 ! $Id$
+! Read COSMO domain extents and soil depths from input files
+! Report averaging mode and debugging mode in log
+! 
+! 
+! 3456 2018-10-30 14:29:54Z eckhard
 ! Remove surface forcing from netCDF output (radiation + precipitation)
 ! NetCDf output of internal arrays only with --debug option 
@@ -83,6 +88,7 @@
                RHO_L, OMEGA, HECTO
     USE io,                                                                    &
-        ONLY:  get_netcdf_variable, get_netcdf_attribute,                      &
-               parse_command_line_arguments, validate_config
+        ONLY:  get_netcdf_attribute, get_netcdf_dim_vector,                    &
+               get_netcdf_variable, parse_command_line_arguments,              &
+               validate_config
     USE netcdf,                                                                &
         ONLY:  NF90_MAX_NAME, NF90_MAX_VAR_DIMS
@@ -154,5 +160,6 @@
     REAL(dp), DIMENSION(:,:,:), ALLOCATABLE, TARGET ::  hfl             !< heights of full layers (cell centres) above sea level in COSMO-DE, computed as arithmetic average of hhl
     REAL(dp), DIMENSION(:), ALLOCATABLE, TARGET     ::  depths          !< COSMO-DE's TERRA-ML soil layer depths
-    REAL(dp), DIMENSION(:), ALLOCATABLE, TARGET     ::  d_depth_rho_inv !< COSMO-DE's TERRA-ML soil layer thicknesses
+    REAL(dp), DIMENSION(:), ALLOCATABLE, TARGET     ::  d_depth         !< COSMO-DE's TERRA-ML soil layer thicknesses
+    REAL(dp), DIMENSION(:), ALLOCATABLE, TARGET     ::  d_depth_rho_inv !< inverted soil water mass
     REAL(dp), DIMENSION(:), ALLOCATABLE, TARGET     ::  rlon            !< longitudes of COSMO-DE's rotated-pole grid
     REAL(dp), DIMENSION(:), ALLOCATABLE, TARGET     ::  rlat            !< latitudes of COSMO-DE's rotated-pole grid
@@ -177,5 +184,5 @@
     INTEGER ::  nlat  !< number of latitudal points in target grid (COSMO-DE)
     INTEGER ::  nlev  !< number of levels in target grid (COSMO-DE)
-    INTEGER ::  layers !< number of COSMO-DE soil layers
+    INTEGER ::  ndepths !< number of COSMO-DE soil layers
     INTEGER ::  start_hour_flow         !< start of flow forcing in number of hours relative to start_date
     INTEGER ::  start_hour_soil         !< start of soil forcing in number of hours relative to start_date, typically equals start_hour_flow
@@ -293,20 +300,8 @@
        start_hour_soilmoisture = - (4 * 7 * 24) - 2
 
-       lonmin =  -5.0_dp * TO_RADIANS
-       lonmax =   5.5_dp * TO_RADIANS
-       latmin =  -5.0_dp * TO_RADIANS
-       latmax =   6.5_dp * TO_RADIANS
-
        ! COSMO-DE default rotated pole
        phi_n     =   40.0_dp * TO_RADIANS
        phi_equat =   50.0_dp * TO_RADIANS
        lambda_n  = -170.0_dp * TO_RADIANS
-
-       ! COMSMO-DE soil layers
-       layers = 8    
-       ALLOCATE( depths(layers), d_depth_rho_inv(layers) )
-       depths = (/0.005_dp, 0.02_dp, 0.06_dp, 0.18_dp, 0.54_dp, 1.62_dp, 4.86_dp, 14.58_dp/)
-       d_depth_rho_inv = 1.0_dp / &
-          ( (/0.01_dp, 0.02_dp, 0.06_dp, 0.18_dp, 0.54_dp, 1.62_dp, 4.86_dp, 14.58_dp/) * RHO_L )
 
        ! Defaultmain centre (_c) of the PALM-4U grid in the geographical system (_g)
@@ -395,4 +390,5 @@
        CALL report('setup_parameters', "initialization mode: " // TRIM(cfg % ic_mode))
        CALL report('setup_parameters', "       forcing mode: " // TRIM(cfg % bc_mode))
+       CALL report('setup_parameters', "     averaging mode: " // TRIM(cfg % averaging_mode))
        CALL report('setup_parameters', "          data path: " // TRIM(cfg % input_path))
        CALL report('setup_parameters', "           hhl file: " // TRIM(cfg % hhl_file))
@@ -400,4 +396,5 @@
        CALL report('setup_parameters', "      namelist file: " // TRIM(cfg % namelist_file))
        CALL report('setup_parameters', "   output data file: " // TRIM(output_file % name))
+       IF (cfg % debug )  CALL report('setup_parameters', "     debugging mode: enabled")
 
  CALL run_control('time', 'init')
@@ -472,4 +469,7 @@
        cosmo_var % name = 'HHL'
        CALL get_netcdf_variable(cfg % hhl_file, cosmo_var, hhl)
+       CALL get_netcdf_dim_vector(cfg % hhl_file, 'rlon', rlon)
+       CALL get_netcdf_dim_vector(cfg % hhl_file, 'rlat', rlat)
+       CALL get_netcdf_dim_vector(soil_files(1), 'depth_2', depths)
  CALL run_control('time', 'read')
 
@@ -478,14 +478,28 @@
        nlat = SIZE(hhl, 2)
        nlev = SIZE(hhl, 3)
-
+       ndepths = SIZE(depths)
+
+       lonmin = MINVAL(rlon) * TO_RADIANS
+       lonmax = MAXVAL(rlon) * TO_RADIANS
+       latmin = MINVAL(rlat) * TO_RADIANS
+       latmax = MAXVAL(rlat) * TO_RADIANS
  CALL run_control('time', 'comp')
 
        ! Appoximate COSMO-DE heights of full layers (cell centres)
        ALLOCATE( hfl(nlon, nlat, nlev-1) )
+       ALLOCATE( d_depth(ndepths), d_depth_rho_inv(ndepths) )
+
  CALL run_control('time', 'alloc')
+       CALL get_soil_layer_thickness( depths, d_depth )
+       d_depth_rho_inv = 1.0_dp / ( d_depth * RHO_L )
+
+       ! Appoximate COSMO-DE heights of full layers (cell centres)
        DO k = 1, nlev-1
           hfl(:,:,k) = 0.5_dp * ( hhl(:,:,k) +                                 &
                                   hhl(:,:,k+1) )
        END DO
+ CALL run_control('time', 'comp')
+
+
 
 !------------------------------------------------------------------------------
@@ -1489,5 +1503,5 @@
        END IF
 
-       ! Copy averaged grid to all COSMO columnts, leads to computing the same
+       ! 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.
@@ -1542,13 +1556,13 @@
 
        imin = CEILING( (avg_grid % lon(1) - cosmo_lon(0)) / dlon )
-       imax = FLOOR(   (avg_grid % lon(2) - cosmo_lon(0)) / dlon )
+       imax = FLOOR  ( (avg_grid % lon(2) - cosmo_lon(0)) / dlon )
 
        jmin = CEILING( (avg_grid % lat(1) - cosmo_lat(0)) / dlat )
-       jmax = FLOOR(   (avg_grid % lat(2) - cosmo_lat(0)) / dlat )
+       jmax = FLOOR  ( (avg_grid % lat(2) - cosmo_lat(0)) / dlat )
        
-       message = "Averaging over "//                                           &
-                 TRIM(str(imin)) // " < i < " // TRIM(str(imax)) //            &
+       message = "Averaging '" // TRIM(avg_grid % kind) // "' over "//         &
+                 TRIM(str(imin)) // " <= i <= " // TRIM(str(imax)) //          &
                  " and " //                                                    &
-                 TRIM(str(jmin)) // " < j < " // TRIM(str(jmax))
+                 TRIM(str(jmin)) // " <= j <= " // TRIM(str(jmax))
        CALL report( 'get_cosmo_averaging_region', message )
 
@@ -1557,5 +1571,5 @@
        avg_grid % n_columns = nx * ny
 
-       ALLOCATE( avg_grid % iii(avg_grid % n_columns),                                 &
+       ALLOCATE( avg_grid % iii(avg_grid % n_columns),                         &
                  avg_grid % jjj(avg_grid % n_columns) )
 
@@ -3933,3 +3947,42 @@
     END SUBROUTINE fill_water_cells
 
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Fills the thickness array of the COSMO soil layers. Since COSMO's (i.e. 
+!> TERRA_ML's [1]) soil layer boundaries follow the rule
+!>
+!>    depth(0) = 0.0, and
+!>    depth(k) = 0.01 * 3**(k-1), k in [1,2,3,...,7]
+!>
+!> and full levels are defined as the midpoints between two layer boundaries, 
+!> all except the first layer thicknesses equal the depth of the midpoint.
+!> 
+!> [1] A Description of the Nonhydrostatic Regional COSMO Model Part II :
+!>     Physical Parameterization*, Sect. 11 TERRA_ML.
+!>     http://www.cosmo-model.org/content/model/documentation/core/cosmoPhysParamtr.pdf)
+!> 
+!> Input parameters:
+!> -----------------
+!>
+!> depths: array of full soil layer depths (cell midpoints)
+!>
+!>
+!> Output parameters:
+!> ------------------
+!>
+!> d_depth: array of soil layer thicknesses
+!>
+!------------------------------------------------------------------------------!
+    SUBROUTINE get_soil_layer_thickness(depths, d_depth)
+       
+       REAL(dp), INTENT(IN)  ::  depths(:)
+       REAL(dp), INTENT(OUT) ::  d_depth(:)
+
+       d_depth(:) = depths(:)
+       d_depth(1) = 2.0_dp * depths(1)
+
+    END SUBROUTINE get_soil_layer_thickness
+
  END MODULE grid
Index: palm/trunk/UTIL/inifor/src/inifor_io.f90
===================================================================
--- palm/trunk/UTIL/inifor/src/inifor_io.f90	(revision 3534)
+++ palm/trunk/UTIL/inifor/src/inifor_io.f90	(revision 3537)
@@ -26,4 +26,8 @@
 ! -----------------
 ! $Id$
+! New routine get_netcdf_dim_vector()
+! 
+! 
+! 3534 2018-11-19 15:35:16Z raasch
 ! bugfix: INTENT attribute changed
 ! 
@@ -173,4 +177,33 @@
 
 
+    SUBROUTINE get_netcdf_dim_vector(filename, varname, array)
+
+       CHARACTER(LEN=*), INTENT(IN)         ::  filename
+       CHARACTER(LEN=*), INTENT(IN)         ::  varname
+       REAL(dp), ALLOCATABLE, INTENT(INOUT) ::  array(:)
+
+       INTEGER ::  ncid, varid, dimlen
+       INTEGER ::  dimids(NF90_MAX_VAR_DIMS)
+
+       IF ( nf90_open( TRIM(filename), NF90_NOWRITE, ncid ) .EQ. NF90_NOERR .AND. &
+            nf90_inq_varid( ncid, varname, varid ) .EQ. NF90_NOERR )  THEN
+
+          CALL check(nf90_inquire_variable( ncid, varid, dimids = dimids ))
+          CALL check(nf90_inquire_dimension( ncid, dimids(1), len = dimlen ))
+
+          ALLOCATE(array(dimlen))
+          CALL check(nf90_get_var( ncid, varid, array ))
+
+       ELSE
+
+          message = "Failed to read '" // TRIM(varname) // &
+             "' from file '" // TRIM(filename) // "'."
+          CALL abort('get_netcdf_dim_vector', message)
+
+       END IF
+
+    END SUBROUTINE get_netcdf_dim_vector
+
+
     SUBROUTINE get_input_dimensions(in_var, ncid)
 
@@ -209,5 +242,5 @@
 
           message = "Failed reading NetCDF variable " //                       &
-             TRIM(in_var % name) // " with " // TRIM(str(in_var%ndim)) //      &
+             TRIM(in_var % name) // " with " // TRIM(str(in_var % ndim)) //    &
              " dimensions because only two- and and three-dimensional" //      &
              " variables are supported."
Index: palm/trunk/UTIL/inifor/src/inifor_transform.f90
===================================================================
--- palm/trunk/UTIL/inifor/src/inifor_transform.f90	(revision 3534)
+++ palm/trunk/UTIL/inifor/src/inifor_transform.f90	(revision 3537)
@@ -271,5 +271,5 @@
                 k_source = avg_grid % kkk(l, k_profile, m)
 
-                profile_array(k_profile) = profile_array(k_profile)    &
+                profile_array(k_profile) = profile_array(k_profile)            &
                    + avg_grid % w(l, k_profile, m)                             &
                    * source_array(i_source, j_source, k_source)
