Index: palm/trunk/UTIL/inifor/README
===================================================================
--- palm/trunk/UTIL/inifor/README	(revision 3776)
+++ palm/trunk/UTIL/inifor/README	(revision 3779)
@@ -1,3 +1,3 @@
-# INIFOR - Mesoscale Interface for Initializing and Forcing PALM-4U (v1.4.6)
+# INIFOR - Mesoscale Interface for Initializing and Forcing PALM-4U (v1.4.7)
 
 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 3776)
+++ palm/trunk/UTIL/inifor/src/inifor.f90	(revision 3779)
@@ -15,6 +15,6 @@
 ! PALM. If not, see <http://www.gnu.org/licenses/>.
 !
-! Copyright 2017-2018 Leibniz Universitaet Hannover
-! Copyright 2017-2018 Deutscher Wetterdienst Offenbach
+! Copyright 2017-2019 Leibniz Universitaet Hannover
+! Copyright 2017-2019 Deutscher Wetterdienst Offenbach
 !------------------------------------------------------------------------------!
 !
@@ -26,4 +26,8 @@
 ! -----------------
 ! $Id$
+! Average geostrophic wind components on coarse COSMO levels instead of fine PALM levels
+! Remove --debug netCDF output of internal pressure profiles
+! 
+! 3680 2019-01-18 14:54:12Z knoop
 ! Prefixed all INIFOR modules with inifor_
 ! 
@@ -74,5 +78,5 @@
 !> and forcing data for the urban climate model PALM-4U. The required 
 !> meteorological fields are interpolated from output data of the mesoscale
-!> model COSMO-DE. This is the main program file.
+!> model COSMO. This is the main program file.
 !------------------------------------------------------------------------------!
  PROGRAM inifor
@@ -91,7 +95,8 @@
     USE inifor_io
     USE inifor_transform,                                                      &
-        ONLY:  average_profile, interpolate_2d, interpolate_3d,                &
-               geostrophic_winds, extrapolate_density, extrapolate_pressure,   &
-               get_surface_pressure
+        ONLY:  average_pressure_perturbation, average_profile, interpolate_1d, &
+               interpolate_1d_arr, interpolate_2d, interpolate_3d,             &
+               interp_average_profile, geostrophic_winds, extrapolate_density, &
+               extrapolate_pressure, get_surface_pressure
     USE inifor_types
     
@@ -104,6 +109,8 @@
     REAL(dp), ALLOCATABLE, DIMENSION(:,:,:)     ::  output_arr !< array buffer for interpolated quantities
     REAL(dp), ALLOCATABLE, DIMENSION(:), TARGET ::  rho_centre !< density profile of the centre averaging domain
-    REAL(dp), ALLOCATABLE, DIMENSION(:), TARGET ::  ug_arr     !< geostrophic wind in x direction
-    REAL(dp), ALLOCATABLE, DIMENSION(:), TARGET ::  vg_arr     !< geostrophic wind in y direction
+    REAL(dp), ALLOCATABLE, DIMENSION(:), TARGET ::  ug_cosmo   !< profile of the geostrophic wind in x direction on COSMO levels
+    REAL(dp), ALLOCATABLE, DIMENSION(:), TARGET ::  vg_cosmo   !< profile of the geostrophic wind in y direction on COSMO levels
+    REAL(dp), ALLOCATABLE, DIMENSION(:), TARGET ::  ug_palm    !< profile of the geostrophic wind in x direction interpolated onto PALM levels
+    REAL(dp), ALLOCATABLE, DIMENSION(:), TARGET ::  vg_palm    !< profile of the geostrophic wind in y direction interpolated onto PALM levels
     REAL(dp), ALLOCATABLE, DIMENSION(:), TARGET ::  rho_north  !< density profile of the northern averaging domain
     REAL(dp), ALLOCATABLE, DIMENSION(:), TARGET ::  rho_south  !< density profile of the southern averaging domain
@@ -116,5 +123,5 @@
 
     REAL(dp), POINTER, DIMENSION(:) ::  internal_arr !< pointer to the currently processed internal array (density, pressure)
-    REAL(dp), POINTER, DIMENSION(:) ::  ug_vg_arr    !< pointer to the currently processed geostrophic wind component
+    REAL(dp), POINTER, DIMENSION(:) ::  ug_vg_palm   !< pointer to the currently processed geostrophic wind component
 
     TYPE(nc_var), POINTER        ::  output_var      !< pointer to the currently processed output variable
@@ -255,5 +262,5 @@
  CALL run_control('time', 'alloc')
                       
-                      CALL average_profile(                                    &
+                      CALL interp_average_profile(                             &
                          input_buffer(output_var % input_id) % array(:,:,:),   &
                          output_arr(0,0,:),                                    &
@@ -282,37 +289,37 @@
 
                       CASE('internal_density_centre')
-                         ALLOCATE( rho_centre( 1:output_var % grid % nz ) )
+                         ALLOCATE( rho_centre( 1:cosmo_grid % nz) )
                          internal_arr => rho_centre
 
                       CASE('internal_density_north')
-                         ALLOCATE( rho_north( 1:output_var % grid % nz ) )
+                         ALLOCATE( rho_north( 1:cosmo_grid % nz) )
                          internal_arr => rho_north
 
                       CASE('internal_density_south')
-                         ALLOCATE( rho_south( 1:output_var % grid % nz ) )
+                         ALLOCATE( rho_south( 1:cosmo_grid % nz) )
                          internal_arr => rho_south
 
                       CASE('internal_density_east')
-                         ALLOCATE( rho_east( 1:output_var % grid % nz) )
+                         ALLOCATE( rho_east( 1:cosmo_grid % nz) )
                          internal_arr => rho_east
 
                       CASE('internal_density_west')
-                         ALLOCATE( rho_west( 1:output_var % grid % nz ) )
+                         ALLOCATE( rho_west( 1:cosmo_grid % nz) )
                          internal_arr => rho_west
 
                       CASE('internal_pressure_north')
-                         ALLOCATE( p_north( 1:output_var % grid % nz ) )
+                         ALLOCATE( p_north( 1:cosmo_grid % nz) )
                          internal_arr => p_north
 
                       CASE('internal_pressure_south')
-                         ALLOCATE( p_south( 1:output_var % grid % nz ) )
+                         ALLOCATE( p_south( 1:cosmo_grid % nz) )
                          internal_arr => p_south
 
                       CASE('internal_pressure_east')
-                         ALLOCATE( p_east( 1:output_var % grid % nz) )
+                         ALLOCATE( p_east( 1:cosmo_grid % nz) )
                          internal_arr => p_east
 
                       CASE('internal_pressure_west')
-                         ALLOCATE( p_west( 1:output_var % grid % nz ) )
+                         ALLOCATE( p_west( 1:cosmo_grid % nz) )
                          internal_arr => p_west
 
@@ -324,44 +331,37 @@
 
 
-                      CALL average_profile(                                 &
-                         input_buffer(output_var % input_id) % array(:,:,:),&
-                         internal_arr(:),                                   &
-                         output_var % averaging_grid)
-
-                      SELECT CASE (TRIM(output_var % name))
-
-                      CASE('internal_density_centre',                          &
-                           'internal_density_north',                           &
-                           'internal_density_south',                           &
-                           'internal_density_east',                            &
-                           'internal_density_west')
-                         CALL extrapolate_density(internal_arr,                &
-                                                  output_var % averaging_grid)
-
-                      CASE('internal_pressure_north')
-                         CALL extrapolate_pressure(internal_arr, rho_north,    &
-                                                   output_var % averaging_grid)
-
-                      CASE('internal_pressure_south')
-                         CALL extrapolate_pressure(internal_arr, rho_south,    &
-                                                   output_var % averaging_grid)
-
-                      CASE('internal_pressure_east')
-                         CALL extrapolate_pressure(internal_arr, rho_east,     &
-                                                   output_var % averaging_grid)
-
-                      CASE('internal_pressure_west')
-                         CALL extrapolate_pressure(internal_arr, rho_west,     &
-                                                   output_var % averaging_grid)
+                      SELECT CASE( TRIM( output_var % name ) )
+
+                      CASE( 'internal_pressure_north',                         &
+                            'internal_pressure_south',                         &
+                            'internal_pressure_east',                          &
+                            'internal_pressure_west' )
+
+                         CALL average_pressure_perturbation(                   &
+                            input_buffer(output_var % input_id) % array(:,:,:),&
+                            internal_arr(:),                                   &
+                            cosmo_grid, output_var % averaging_grid            &
+                         )
 
                       CASE DEFAULT
-                         CALL inifor_abort('main loop', message)
+
+                         CALL average_profile(                                 &
+                            input_buffer(output_var % input_id) % array(:,:,:),&
+                            internal_arr(:),                                   &
+                            cosmo_grid, output_var % averaging_grid            &
+                         )
 
                       END SELECT
 
-                      IF (.TRUE.)  THEN
-                         ALLOCATE( output_arr(1,1,1:output_var % grid % nz) )
-                         output_arr(1,1,:) = internal_arr(:)
-                      END IF
+
+!
+!--                   Output of geostrophic pressure profiles (with --debug
+!--                   option) is currently deactivated, since they are now
+!--                   defined on averaged COSMO levels instead of PALM levels
+!--                   (requires definiton of COSMO levels in netCDF output.)
+                      !IF (.TRUE.)  THEN
+                      !   ALLOCATE( output_arr(1,1,1:output_var % grid % nz) )
+                      !   output_arr(1,1,:) = internal_arr(:)
+                      !END IF
  CALL run_control('time', 'comp')
 
@@ -369,15 +369,16 @@
 !--                This case gets called twice, the first time for ug, the
 !--                second time for vg. We compute ug and vg at the first call
-!--                and keep vg (and ug for that matter) around for the second
-!--                call.
+!--                and keep both of them around for the second call.
                    CASE ( 'geostrophic winds' )
 
                       IF (.NOT. ug_vg_have_been_computed )  THEN
-                         ALLOCATE( ug_arr(output_var % grid % nz) )
-                         ALLOCATE( vg_arr(output_var % grid % nz) )
-
-                         IF ( cfg % ug_is_set )  THEN
-                            ug_arr = cfg % ug
-                            vg_arr = cfg % vg
+                         ALLOCATE( ug_palm(output_var % grid % nz) )
+                         ALLOCATE( vg_palm(output_var % grid % nz) )
+                         ALLOCATE( ug_cosmo(cosmo_grid % nz) )
+                         ALLOCATE( vg_cosmo(cosmo_grid % nz) )
+
+                         IF ( cfg % ug_defined_by_user )  THEN
+                            ug_palm = cfg % ug
+                            vg_palm = cfg % vg
                          ELSE
                             CALL geostrophic_winds( p_north, p_south, p_east,  &
@@ -387,5 +388,11 @@
                                                     phi_n, lambda_n,           &
                                                     phi_centre, lam_centre,    &
-                                                    ug_arr, vg_arr )
+                                                    ug_cosmo, vg_cosmo )
+
+                            CALL interpolate_1d( ug_cosmo, ug_palm,             &
+                                                 output_var % grid )
+
+                            CALL interpolate_1d( vg_cosmo, vg_palm,             &
+                                                 output_var % grid )
                          END IF
 
@@ -395,14 +402,14 @@
 
 !
-!--                   Prepare output of geostrophic winds
+!--                   Select output array of current geostrophic wind component
                       SELECT CASE(TRIM(output_var % name))
                       CASE ('ls_forcing_ug')
-                         ug_vg_arr => ug_arr
+                         ug_vg_palm => ug_palm
                       CASE ('ls_forcing_vg')
-                         ug_vg_arr => vg_arr
+                         ug_vg_palm => vg_palm
                       END SELECT
 
                       ALLOCATE( output_arr(1,1,output_var % grid % nz) )
-                      output_arr(1,1,:) = ug_vg_arr(:)
+                      output_arr(1,1,:) = ug_vg_palm(:)
 
                    CASE ( 'average scalar' )
@@ -447,5 +454,12 @@
 !- Section 2.3: Write current time step of current variable
 !------------------------------------------------------------------------------
-                   IF (.NOT. output_var % is_internal .OR. debugging_output)  THEN
+!
+!--                Output of geostrophic pressure profiles (with --debug
+!--                option) is currently deactivated, since they are now
+!--                defined on averaged COSMO levels instead of PALM levels
+!--                (requires definiton of COSMO levels in netCDF output.)
+                   !IF (.NOT. output_var % is_internal .OR. debugging_output)  THEN
+
+                   IF (.NOT. output_var % is_internal)  THEN
                       message = "Writing variable '" // TRIM(output_var%name) // "'."
                       CALL report('main loop', message)
@@ -467,7 +481,9 @@
              IF ( group % kind == 'thermodynamics' )  THEN
                 DEALLOCATE( rho_centre )
-                DEALLOCATE( ug_arr )
-                DEALLOCATE( vg_arr )
-                IF ( .NOT. cfg % ug_is_set )  THEN
+                DEALLOCATE( ug_palm )
+                DEALLOCATE( vg_palm )
+                DEALLOCATE( ug_cosmo )
+                DEALLOCATE( vg_cosmo )
+                IF ( .NOT. cfg % ug_defined_by_user )  THEN
                    DEALLOCATE( rho_north )
                    DEALLOCATE( rho_south )
Index: palm/trunk/UTIL/inifor/src/inifor_control.f90
===================================================================
--- palm/trunk/UTIL/inifor/src/inifor_control.f90	(revision 3776)
+++ palm/trunk/UTIL/inifor/src/inifor_control.f90	(revision 3779)
@@ -15,6 +15,6 @@
 ! PALM. If not, see <http://www.gnu.org/licenses/>.
 !
-! Copyright 2017-2018 Leibniz Universitaet Hannover
-! Copyright 2017-2018 Deutscher Wetterdienst Offenbach
+! Copyright 2017-2019 Leibniz Universitaet Hannover
+! Copyright 2017-2019 Deutscher Wetterdienst Offenbach
 !------------------------------------------------------------------------------!
 !
Index: palm/trunk/UTIL/inifor/src/inifor_defs.f90
===================================================================
--- palm/trunk/UTIL/inifor/src/inifor_defs.f90	(revision 3776)
+++ palm/trunk/UTIL/inifor/src/inifor_defs.f90	(revision 3779)
@@ -15,6 +15,6 @@
 ! PALM. If not, see <http://www.gnu.org/licenses/>.
 !
-! Copyright 2017-2018 Leibniz Universitaet Hannover
-! Copyright 2017-2018 Deutscher Wetterdienst Offenbach
+! Copyright 2017-2019 Leibniz Universitaet Hannover
+! Copyright 2017-2019 Deutscher Wetterdienst Offenbach
 !------------------------------------------------------------------------------!
 !
@@ -26,4 +26,8 @@
 ! -----------------
 ! $Id$
+! Updated version number to 1.4.7, updated copyright note
+! 
+! 
+! 3764 2019-02-26 13:42:09Z eckhard
 ! Bumped version number
 ! 
@@ -136,7 +140,7 @@
  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.6'            !< INIFOR version number
- CHARACTER(LEN=*), PARAMETER ::  COPYRIGHT = 'Copyright 2017-2018 Leibniz Universitaet Hannover' // &
-     ACHAR( 10 ) // ' Copyright 2017-2018 Deutscher Wetterdienst Offenbach' !< Copyright notice
+ CHARACTER(LEN=*), PARAMETER ::  VERSION = '1.4.7'            !< INIFOR version number
+ CHARACTER(LEN=*), PARAMETER ::  COPYRIGHT = 'Copyright 2017-2019 Leibniz Universitaet Hannover' // &
+     ACHAR( 10 ) // ' Copyright 2017-2019 Deutscher Wetterdienst Offenbach' !< Copyright notice
 
  END MODULE inifor_defs
Index: palm/trunk/UTIL/inifor/src/inifor_grid.f90
===================================================================
--- palm/trunk/UTIL/inifor/src/inifor_grid.f90	(revision 3776)
+++ palm/trunk/UTIL/inifor/src/inifor_grid.f90	(revision 3779)
@@ -15,6 +15,6 @@
 ! PALM. If not, see <http://www.gnu.org/licenses/>.
 !
-! Copyright 2017-2018 Leibniz Universitaet Hannover
-! Copyright 2017-2018 Deutscher Wetterdienst Offenbach
+! Copyright 2017-2019 Leibniz Universitaet Hannover
+! Copyright 2017-2019 Deutscher Wetterdienst Offenbach
 !------------------------------------------------------------------------------!
 !
@@ -26,4 +26,9 @@
 ! -----------------
 ! $Id$
+! Assigned names to averaging grids
+! Improved variable naming and minor clean-up
+! 
+! 
+! 3765 2019-02-26 13:45:46Z eckhard
 ! Removed dependency on radiation input files
 ! 
@@ -411,4 +416,5 @@
 !--    Overwrite defaults with user configuration
        CALL parse_command_line_arguments( cfg )
+       CALL report('main_loop', 'Running INIFOR version ' // VERSION)
 
        flow_prefix = TRIM(cfg % input_prefix)
@@ -444,8 +450,8 @@
        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))
        CALL report('setup_parameters', "     averaging mode: " // TRIM(cfg % averaging_mode))
+       CALL report('setup_parameters', "    averaging angle: " // real_to_str(cfg % averaging_angle))
        CALL report('setup_parameters', "          data path: " // TRIM(cfg % input_path))
        CALL report('setup_parameters', "           hhl file: " // TRIM(cfg % hhl_file))
@@ -1051,5 +1057,5 @@
                lonmin = lonmin_palm, lonmax = lonmax_palm,                     &
                latmin = latmin_palm, latmax = latmax_palm,                     &
-               kind='scalar')
+               kind='scalar', name='averaged initial scalar')
 
        CALL init_averaging_grid(averaged_initial_w_profile, cosmo_grid,        &
@@ -1057,5 +1063,5 @@
                lonmin = lonmin_palm, lonmax = lonmax_palm,                     &
                latmin = latmin_palm, latmax = latmax_palm,                     &
-               kind='w')
+               kind='w', name='averaged initial w')
 
        CALL init_averaging_grid(averaged_scalar_profile, cosmo_grid,           &
@@ -1063,5 +1069,5 @@
                lonmin = lam_west, lonmax = lam_east,                           &
                latmin = phi_south, latmax = phi_north,                         &
-               kind='scalar')
+               kind='scalar', name='centre geostrophic scalar')
 
        CALL init_averaging_grid(averaged_w_profile, cosmo_grid,                &
@@ -1069,5 +1075,5 @@
                lonmin = lam_west, lonmax = lam_east,                           &
                latmin = phi_south, latmax = phi_north,                         &
-               kind='w')
+               kind='w', name='centre geostrophic w')
 
        CALL init_averaging_grid(south_averaged_scalar_profile, cosmo_grid,     &
@@ -1076,5 +1082,5 @@
                latmin = phi_centre - averaging_angle,                          &
                latmax = phi_centre,                                            &
-               kind='scalar')
+               kind='scalar', name='south geostrophic scalar')
 
        CALL init_averaging_grid(north_averaged_scalar_profile, cosmo_grid,     &
@@ -1083,5 +1089,5 @@
                latmin = phi_centre,                                            &
                latmax = phi_centre + averaging_angle,                          &
-               kind='scalar')
+               kind='scalar', name='north geostrophic scalar')
 
        CALL init_averaging_grid(west_averaged_scalar_profile, cosmo_grid,      &
@@ -1090,5 +1096,5 @@
                lonmax = lam_centre,                                            &
                latmin = phi_south, latmax = phi_north,                         &
-               kind='scalar')
+               kind='scalar', name='west geostrophic scalar')
 
        CALL init_averaging_grid(east_averaged_scalar_profile, cosmo_grid,      &
@@ -1097,5 +1103,5 @@
                lonmax = lam_centre + averaging_angle,                          &
                latmin = phi_south, latmax = phi_north,                         &
-               kind='scalar')
+               kind='scalar', name='east geostrophic scalar')
 
 !                                                                              
@@ -1304,5 +1310,5 @@
         grid % z0 = z0
 
-        SELECT CASE( TRIM (kind) )
+        SELECT CASE( TRIM(kind) )
 
         CASE('boundary')
@@ -1529,5 +1535,5 @@
 !------------------------------------------------------------------------------!
     SUBROUTINE init_averaging_grid(avg_grid, cosmo_grid, x, y, z, z0,          &
-       lonmin, lonmax, latmin, latmax, kind)
+       lonmin, lonmax, latmin, latmax, kind, name)
 
        TYPE(grid_definition), INTENT(INOUT) ::  avg_grid
@@ -1541,6 +1547,7 @@
 
        CHARACTER(LEN=*), INTENT(IN)         ::  kind
-
-       LOGICAL                              :: level_based_averaging
+       CHARACTER(LEN=*), INTENT(IN)         ::  name
+
+       LOGICAL                              ::  level_based_averaging
 
        ALLOCATE( avg_grid % x(1) )
@@ -1559,4 +1566,5 @@
 
        avg_grid % kind = TRIM(kind)
+       avg_grid % name(1) = TRIM(name)
 
 !
@@ -1586,4 +1594,5 @@
 !
 !--    For level-besed averaging, compute average heights
+       !level_based_averaging = ( TRIM(mode) == 'level' )
        level_based_averaging = ( TRIM(cfg % averaging_mode) == 'level' )
        IF (level_based_averaging)  THEN
@@ -1592,4 +1601,5 @@
           CALL average_2d(avg_grid % cosmo_h, avg_grid % h(1,1,:),             &
                           avg_grid % iii, avg_grid % jjj)
+
        END IF
 
@@ -1645,5 +1655,5 @@
        jmax = CEILING( (avg_grid % lat(2) - cosmo_lat(0)) / dlat )
        
-       message = "Averaging '" // TRIM(avg_grid % kind) // "' over "//         &
+       message = "Grid " // TRIM(avg_grid % name(1)) // " averages over " // &
                  TRIM(str(imin)) // " <= i <= " // TRIM(str(imax)) //          &
                  " and " //                                                    &
@@ -3167,5 +3177,5 @@
        )
        output_var_table(57) % averaging_grid => north_averaged_scalar_profile
-       output_var_table(57) % to_be_processed = .NOT. cfg % ug_is_set
+       output_var_table(57) % to_be_processed = .NOT. cfg % ug_defined_by_user
 
 
@@ -3182,5 +3192,5 @@
        )
        output_var_table(58) % averaging_grid => south_averaged_scalar_profile
-       output_var_table(58) % to_be_processed = .NOT. cfg % ug_is_set
+       output_var_table(58) % to_be_processed = .NOT. cfg % ug_defined_by_user
 
 
@@ -3197,5 +3207,5 @@
        )
        output_var_table(59) % averaging_grid => east_averaged_scalar_profile
-       output_var_table(59) % to_be_processed = .NOT. cfg % ug_is_set
+       output_var_table(59) % to_be_processed = .NOT. cfg % ug_defined_by_user
 
 
@@ -3212,5 +3222,5 @@
        )
        output_var_table(60) % averaging_grid => west_averaged_scalar_profile
-       output_var_table(60) % to_be_processed = .NOT. cfg % ug_is_set
+       output_var_table(60) % to_be_processed = .NOT. cfg % ug_defined_by_user
 
        output_var_table(61) = init_nc_var(                                     &
@@ -3226,5 +3236,5 @@
        )
        output_var_table(61) % averaging_grid => north_averaged_scalar_profile
-       output_var_table(61) % to_be_processed = .NOT. cfg % ug_is_set
+       output_var_table(61) % to_be_processed = .NOT. cfg % ug_defined_by_user
 
 
@@ -3241,5 +3251,5 @@
        )
        output_var_table(62) % averaging_grid => south_averaged_scalar_profile
-       output_var_table(62) % to_be_processed = .NOT. cfg % ug_is_set
+       output_var_table(62) % to_be_processed = .NOT. cfg % ug_defined_by_user
 
 
@@ -3256,5 +3266,5 @@
        )
        output_var_table(63) % averaging_grid => east_averaged_scalar_profile
-       output_var_table(63) % to_be_processed = .NOT. cfg % ug_is_set
+       output_var_table(63) % to_be_processed = .NOT. cfg % ug_defined_by_user
 
 
@@ -3271,5 +3281,5 @@
        )
        output_var_table(64) % averaging_grid => west_averaged_scalar_profile
-       output_var_table(64) % to_be_processed = .NOT. cfg % ug_is_set
+       output_var_table(64) % to_be_processed = .NOT. cfg % ug_defined_by_user
 
 !
@@ -3416,5 +3426,5 @@
           var % task            = "interpolate_2d"
 
-       CASE( 'left scalar', 'right scalar') ! same as right
+       CASE( 'left scalar', 'right scalar')
           var % lod             = -1
           var % ndim            = 3
@@ -3429,5 +3439,5 @@
           var % task            = "interpolate_3d"
 
-       CASE( 'north scalar', 'south scalar') ! same as south
+       CASE( 'north scalar', 'south scalar')
           var % lod             = -1
           var % ndim            = 3
Index: palm/trunk/UTIL/inifor/src/inifor_io.f90
===================================================================
--- palm/trunk/UTIL/inifor/src/inifor_io.f90	(revision 3776)
+++ palm/trunk/UTIL/inifor/src/inifor_io.f90	(revision 3779)
@@ -15,6 +15,6 @@
 ! PALM. If not, see <http://www.gnu.org/licenses/>.
 !
-! Copyright 2017-2018 Leibniz Universitaet Hannover
-! Copyright 2017-2018 Deutscher Wetterdienst Offenbach
+! Copyright 2017-2019 Leibniz Universitaet Hannover
+! Copyright 2017-2019 Deutscher Wetterdienst Offenbach
 !------------------------------------------------------------------------------!
 !
@@ -26,4 +26,9 @@
 ! -----------------
 ! $Id$
+! Temporariliy disabled height-based geostrophic wind averaging
+! Improved variable naming
+! 
+! 
+! 3764 2019-02-26 13:42:09Z eckhard
 ! Removed dependency on radiation input files
 ! 
@@ -397,6 +402,6 @@
 
        cfg % p0_is_set = .FALSE.
-       cfg % ug_is_set = .FALSE.
-       cfg % vg_is_set = .FALSE.
+       cfg % ug_defined_by_user = .FALSE.
+       cfg % vg_defined_by_user = .FALSE.
        cfg % flow_prefix_is_set = .FALSE.
        cfg % input_prefix_is_set = .FALSE.
@@ -442,10 +447,10 @@
 
              CASE( '-ug', '-u', '--geostrophic-u' )
-                cfg % ug_is_set = .TRUE.
+                cfg % ug_defined_by_user = .TRUE.
                 CALL get_option_argument( i, arg )
                 READ(arg, *) cfg % ug
 
              CASE( '-vg', '-v', '--geostrophic-v' )
-                cfg % vg_is_set = .TRUE.
+                cfg % vg_defined_by_user = .TRUE.
                 CALL get_option_argument( i, arg )
                 READ(arg, *) cfg % vg
@@ -712,15 +717,23 @@
 
       SELECT CASE( TRIM(cfg % averaging_mode) )
-      CASE( 'level', 'height')
+      CASE( 'level' )
+      CASE( 'height' )
+         message = "Averaging mode '" // TRIM(cfg % averaging_mode) //&
+                   "' is currently not supported. " //&
+                   "Please use level-based averaging by selecting 'level', " //&
+                   "or by omitting the --averaging-mode option entirely."
+         CALL inifor_abort( 'validate_config', message )
       CASE DEFAULT
          message = "Averaging mode '" // TRIM(cfg % averaging_mode) //&
                    "' is not supported. " //&
-                   "Please select either 'height' or 'level', " //&
-                   "or omit the --averaging-mode option entirely, which corresponds "//&
-                   "to the latter."
+         !          "Please select either 'height' or 'level', " //&
+         !          "or omit the --averaging-mode option entirely, which corresponds "//&
+         !          "to the latter."
+                   "Please use level-based averaging by selecting 'level', " //&
+                   "or by omitting the --averaging-mode option entirely."
          CALL inifor_abort( 'validate_config', message )
       END SELECT
 
-      IF ( cfg % ug_is_set .NEQV. cfg % vg_is_set )  THEN
+      IF ( cfg % ug_defined_by_user .NEQV. cfg % vg_defined_by_user )  THEN
          message = "You specified only one component of the geostrophic " // &
                    "wind. Please specify either both or none."
@@ -965,6 +978,7 @@
           var => output_variable_table(i)
 
-          to_be_written = ( var % to_be_processed  .AND. .NOT. var % is_internal) .OR.                        &
-                          ( var % is_internal  .AND.  debug )
+          !to_be_written = ( var % to_be_processed  .AND. .NOT. var % is_internal) .OR. &
+          !                ( var % is_internal  .AND.  debug )
+          to_be_written = ( var % to_be_processed  .AND. .NOT. var % is_internal)
 
           IF ( to_be_written )  THEN
Index: palm/trunk/UTIL/inifor/src/inifor_transform.f90
===================================================================
--- palm/trunk/UTIL/inifor/src/inifor_transform.f90	(revision 3776)
+++ palm/trunk/UTIL/inifor/src/inifor_transform.f90	(revision 3779)
@@ -15,6 +15,6 @@
 ! PALM. If not, see <http://www.gnu.org/licenses/>.
 !
-! Copyright 2017-2018 Leibniz Universitaet Hannover
-! Copyright 2017-2018 Deutscher Wetterdienst Offenbach
+! Copyright 2017-2019 Leibniz Universitaet Hannover
+! Copyright 2017-2019 Deutscher Wetterdienst Offenbach
 !------------------------------------------------------------------------------!
 !
@@ -26,4 +26,17 @@
 ! -----------------
 ! $Id$
+! Remove basic state pressure before computing geostrophic wind
+!  - Introduced new level-based profile averaging routine that does not rely on
+!    external weights average_profile()
+!  - Renamed original weights-based routine average_profile() ->
+!    interp_average_profile()
+! Average geostrophic wind components on coarse COSMO levels instead of fine PALM levels
+!  - Introduced new profile interpolation routine for interpolating single
+!    profiles from COSMO to PALM levels
+!  - Renamed original array variant interpolate_1d() -> interpolate_1d_arr()
+! 
+! 
+! 
+! 3716 2019-02-05 17:02:38Z eckhard
 ! Include out-of-bounds error message in log 
 ! 
@@ -93,12 +106,43 @@
     USE inifor_control
     USE inifor_defs,                                                           &
-        ONLY: G, TO_DEGREES, TO_RADIANS, PI, dp
+        ONLY: BETA, dp, G, P_SL, PI, RD, T_SL, TO_DEGREES, TO_RADIANS
     USE inifor_types
     USE inifor_util,                                                           &
-        ONLY: real_to_str, str
+        ONLY: get_basic_state, real_to_str, str
 
     IMPLICIT NONE
 
  CONTAINS
+
+
+    SUBROUTINE interpolate_1d(in_arr, out_arr, outgrid)
+       TYPE(grid_definition), INTENT(IN) ::  outgrid
+       REAL(dp), INTENT(IN)              ::  in_arr(:)
+       REAL(dp), INTENT(OUT)             ::  out_arr(:)
+
+       INTEGER :: i, j, k, l, nz
+
+       nz = UBOUND(out_arr, 1)
+
+       DO k = nz, LBOUND(out_arr, 1), -1
+
+!
+!--       TODO: Remove IF clause and extrapolate based on a critical vertical
+!--       TODO: index marking the lower bound of COSMO-DE data coverage.
+!--       Check for negative interpolation weights indicating grid points 
+!--       below COSMO-DE domain and extrapolate from the top in such cells.
+          IF (outgrid % w(1,k,1) < -1.0_dp .AND. k < nz)  THEN
+             out_arr(k) = out_arr(k+1)
+          ELSE
+             out_arr(k) = 0.0_dp
+             DO l = 1, 2
+                out_arr(k) = out_arr(k) +                                      &
+                    outgrid % w(1,k,l) * in_arr(outgrid % kkk(1,k,l) )
+             END DO
+          END IF
+       END DO
+
+    END SUBROUTINE interpolate_1d
+
 
 !------------------------------------------------------------------------------!
@@ -125,5 +169,5 @@
 !> outvar : Array of interpolated data
 !------------------------------------------------------------------------------!
-    SUBROUTINE interpolate_1d(in_arr, out_arr, outgrid)
+    SUBROUTINE interpolate_1d_arr(in_arr, out_arr, outgrid)
        TYPE(grid_definition), INTENT(IN) ::  outgrid
        REAL(dp), INTENT(IN)              ::  in_arr(0:,0:,0:)
@@ -156,5 +200,5 @@
        END DO
        END DO
-    END SUBROUTINE interpolate_1d
+    END SUBROUTINE interpolate_1d_arr
 
 
@@ -174,5 +218,5 @@
 !>     of PALM-4U point (i,j,k) on the input grid corresponding to the source
 !>     data invar. (The outgrid carries the relationship with the ingrid in the
-!      form of the interpoaltion weights.)
+!      form of the interpolation weights.)
 !> 
 !> outgrid % w_horiz: Array of weights for horizontal bi-linear interpolation
@@ -298,5 +342,5 @@
 !--    Interpolate from intermediate grid to palm_grid grid, includes
 !--    extrapolation for cells below COSMO domain.
-       CALL interpolate_1d(intermediate_array, palm_array, palm_grid)
+       CALL interpolate_1d_arr(intermediate_array, palm_array, palm_grid)
 
        DEALLOCATE(intermediate_array)
@@ -311,5 +355,5 @@
 !> averaging grid 'avg_grid' and store the result in 'profile_array'.
 !------------------------------------------------------------------------------!
-    SUBROUTINE average_profile(source_array, profile_array, avg_grid)
+    SUBROUTINE interp_average_profile(source_array, profile_array, avg_grid)
        TYPE(grid_definition), INTENT(IN)          ::  avg_grid
        REAL(dp), DIMENSION(:,:,:), INTENT(IN)     ::  source_array
@@ -358,5 +402,109 @@
        profile_array(1:avg_grid % k_min-1) = profile_array(avg_grid % k_min)
 
+    END SUBROUTINE interp_average_profile
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Average data horizontally from the source_array over the region given by the
+!> averaging grid 'avg_grid' and store the result in 'profile_array'.
+!------------------------------------------------------------------------------!
+    SUBROUTINE average_profile( source_array, profile_array,                   &
+                                source_grid, avg_grid )
+
+       TYPE(grid_definition), INTENT(IN)          ::  source_grid, avg_grid
+       REAL(dp), DIMENSION(:,:,:), INTENT(IN)     ::  source_array 
+       REAL(dp), DIMENSION(:), INTENT(OUT)        ::  profile_array
+
+       INTEGER ::  i_source, j_source, k_profile, k_source, l, m, nz, nlev
+
+       REAL                            ::  ni_columns
+
+       nlev = SIZE( source_array, 3 )
+       nz   = SIZE( profile_array, 1 )
+
+       IF ( nlev /= nz )  THEN
+          message = "Lengths of input and output profiles do not match: " //   &
+                    "cosmo_pressure(" // TRIM( str( nlev ) ) //                &
+                    "), profile_array(" // TRIM( str( nz ) )  // ")."
+          CALL inifor_abort('average_pressure_perturbation', message)
+       ENDIF
+      
+       profile_array(:) = 0.0_dp
+
+       DO l = 1, avg_grid % n_columns
+
+          i_source = avg_grid % iii(l)
+          j_source = avg_grid % jjj(l)
+
+          profile_array(:) = profile_array(:)                                  &
+                           + source_array(i_source, j_source, :)
+
+       END DO
+
+       ni_columns = 1.0_dp / avg_grid % n_columns
+       profile_array(:) = profile_array(:) * ni_columns
+
     END SUBROUTINE average_profile
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> This is a sister routine to average_profile() and differes from it in that
+!> it removes the COSMO basic state pressure from the input array before
+!> averaging.
+!------------------------------------------------------------------------------!
+    SUBROUTINE average_pressure_perturbation( cosmo_pressure, profile_array,   &
+                                              cosmo_grid, avg_grid )
+
+       TYPE(grid_definition), INTENT(IN)          ::  cosmo_grid, avg_grid
+       REAL(dp), DIMENSION(:,:,:), INTENT(IN)     ::  cosmo_pressure
+       REAL(dp), DIMENSION(:), INTENT(OUT)        ::  profile_array
+
+       INTEGER ::  i_source, j_source, k_profile, k_source, l, m, nz, nlev
+
+       REAL(dp)                            ::  ni_columns
+       REAL(dp), DIMENSION(:), ALLOCATABLE ::  basic_state_pressure
+
+       nlev = SIZE( cosmo_pressure, 3 )
+       nz   = SIZE( profile_array, 1 )
+
+       IF ( nlev /= nz )  THEN
+          message = "Lengths of input and output profiles do not match: " //   &
+                    "cosmo_pressure(" // TRIM( str( nlev ) ) //                &
+                    "), profile_array(" // TRIM( str( nz ) )  // ")."
+          CALL inifor_abort('average_pressure_perturbation', message)
+       ENDIF
+
+       ALLOCATE( basic_state_pressure(nz) )
+       profile_array(:) = 0.0_dp
+
+       DO l = 1, avg_grid % n_columns
+          i_source = avg_grid % iii(l)
+          j_source = avg_grid % jjj(l)
+
+!
+!--       Compute pressure perturbation by removing COSMO basic state pressure
+          CALL get_basic_state( cosmo_grid % hfl(i_source,j_source,:), BETA,   &
+                                P_SL, T_SL, RD, G, basic_state_pressure )
+
+          profile_array(:) = profile_array(:)                                  &
+                           + cosmo_pressure(i_source, j_source, :)             &
+                           - basic_state_pressure(:)
+
+!
+!--    Loop over horizontal neighbours l
+       END DO
+
+       DEALLOCATE( basic_state_pressure )
+
+       ni_columns = 1.0_dp / avg_grid % n_columns
+       profile_array(:) = profile_array(:) * ni_columns
+
+    END SUBROUTINE average_pressure_perturbation
+
+
 
 
Index: palm/trunk/UTIL/inifor/src/inifor_types.f90
===================================================================
--- palm/trunk/UTIL/inifor/src/inifor_types.f90	(revision 3776)
+++ palm/trunk/UTIL/inifor/src/inifor_types.f90	(revision 3779)
@@ -15,6 +15,6 @@
 ! PALM. If not, see <http://www.gnu.org/licenses/>.
 !
-! Copyright 2017-2018 Leibniz Universitaet Hannover
-! Copyright 2017-2018 Deutscher Wetterdienst Offenbach
+! Copyright 2017-2019 Leibniz Universitaet Hannover
+! Copyright 2017-2019 Deutscher Wetterdienst Offenbach
 !------------------------------------------------------------------------------!
 !
@@ -26,4 +26,7 @@
 ! -----------------
 ! $Id$
+! Improved variable naming
+! 
+! 3680 2019-01-18 14:54:12Z knoop
 ! Prefixed all INIFOR modules with inifor_
 ! 
@@ -109,11 +112,11 @@
     LOGICAL              ::  debug                       !< indicates whether --debug option was given
     LOGICAL              ::  p0_is_set                   !< indicates whether p0 was set manually
-    LOGICAL              ::  ug_is_set                   !< indicates whether ug was set manually
-    LOGICAL              ::  vg_is_set                   !< indicates whether vg was set manually
-    LOGICAL              ::  flow_prefix_is_set          !<  indicates whether the flow prefix was set manually
-    LOGICAL              ::  input_prefix_is_set         !<  indicates whether the input prefix was set manually
-    LOGICAL              ::  radiation_prefix_is_set     !<  indicates whether the radiation prefix was set manually
-    LOGICAL              ::  soil_prefix_is_set          !<  indicates whether the soil prefix was set manually
-    LOGICAL              ::  soilmoisture_prefix_is_set  !<  indicates whether the soilmoisture prefix was set manually
+    LOGICAL              ::  ug_defined_by_user          !< indicates whether ug was set manually
+    LOGICAL              ::  vg_defined_by_user          !< indicates whether vg was set manually
+    LOGICAL              ::  flow_prefix_is_set          !< indicates whether the flow prefix was set manually
+    LOGICAL              ::  input_prefix_is_set         !< indicates whether the input prefix was set manually
+    LOGICAL              ::  radiation_prefix_is_set     !< indicates whether the radiation prefix was set manually
+    LOGICAL              ::  soil_prefix_is_set          !< indicates whether the soil prefix was set manually
+    LOGICAL              ::  soilmoisture_prefix_is_set  !< indicates whether the soilmoisture prefix was set manually
  END TYPE inifor_config
 
Index: palm/trunk/UTIL/inifor/src/inifor_util.f90
===================================================================
--- palm/trunk/UTIL/inifor/src/inifor_util.f90	(revision 3776)
+++ palm/trunk/UTIL/inifor/src/inifor_util.f90	(revision 3779)
@@ -15,6 +15,6 @@
 ! PALM. If not, see <http://www.gnu.org/licenses/>.
 !
-! Copyright 2017-2018 Leibniz Universitaet Hannover
-! Copyright 2017-2018 Deutscher Wetterdienst Offenbach
+! Copyright 2017-2019 Leibniz Universitaet Hannover
+! Copyright 2017-2019 Deutscher Wetterdienst Offenbach
 !------------------------------------------------------------------------------!
 !
