Index: lm/trunk/UTIL/inifor/README
===================================================================
--- /palm/trunk/UTIL/inifor/README	(revision 3996)
+++ 	(revision )
@@ -1,197 +1,0 @@
-# INIFOR - Mesoscale Interface for Initializing and Forcing PALM-4U
-
-INIFOR provides the meteorological fields required to initialize and drive the
-urban-climate model PALM-4U. The required meteorological fields are
-interpolated from output data of the meso-scale model COSMO.
-
-
-## COMPILATION
-
-1. Customize ./Makefile and ./tests/Makefile (netCDF library location, compiler
-   and parameters, use Makefile.ifort as a template if you want to use the Intel
-   Fortran compiler)
-2. Run `make`
-
-
-## MINIMAL USAGE EXAMPLE
-
-1. Customize `./namelist` (number of grid points and spacings, end_time)
-2. Run `current_version/trunk/SCRIPTS/inifor --path <scenario path> --date <YYYYMMDD>`
-
-
-## USAGE
-
-After compilation, the `inifor` binary resides in the `$PALM_BIN` path, i.e. in
-`<PALM path>/current_version/trunk/SCRIPTS/`.
-
-In order to run, INIFOR requires three kinds of inputs:
-
-1. hourly COSMO model output,
-2. a steering namelist file, and
-3. command-line options.
-
-In addition, a static driver file may be supplied (see `--static-driver` option
-below) in order to pass the coordinates of the PALM origin to INIFOR. If no
-static driver is passed to INIFOR, origin coordinates are read from the namelist
-file.
-
-A typical `inifor` call looks like this:
-
-    inifor --path /data/evaluation/20170729 --date 2017073006 \
-           --init-mode profile -n namelist -o dynamic_driver.nc \
-           --elevation 110 --input-prefix lff0
-
-### INPUT DATA: COSMO MODEL OUTPUT
-
-INIFOR processes COSMO model output which it requires to be stored in a set of
-netCDF files located in a user-specified path (see `--path` option). These are:
-
-- hhl.nc: This file provides the COSMO numerical grid. (*hhl* abbreviates
-  *height of half layers*, i.e. the heights of the vertical cell boundaries.)
-- soil.nc: This file provides the COSMO soil map and is used to destinguish land
-  from water cells.
-- `<prefix>YYYYMMDDHH-<suffix>.nc`: Each of these files contains COSMO model
-  of one time step at the given time in UTC (Y..year, M..month, D..day, H..hour).
-    - The `<prefix>` distinguishes different DWD products, for instance COSMO
-      analyses (`laf`) or forecasts (`lff`).
-    - The `<suffix>` distinguishes four kinds of COSMO model output data, namely
-        - `flow` (atmospheric fields)
-        - `rad` (radiation)
-        - `soil` (soil moisture and temperature)
-        - `soilmoisture` (precipitation and evaporation)
-    - For example, laf2016010100-flow.nc contains the atmospheric fields of the
-      COSMO analysis of Januray 1st, 2016 for 0:00 UTC.
-
-
-### NAMELIST PARAMETERS
-
-INIFOR mirrors a subset of the PALM-4U's Fortran namelists `inipar` and `d3par`
-and supports the following parameters:
-
-
-#### inipar
-
-    nx, ny, nz - number of PALM-4U grid points in x, y, and z direction
-    dx, dy, dz(10) - PALM-4U grid spacings in x, y, and z direction [m]
-    dz_stretch_level - height above which the grid will be stretched [m]
-    dz_stretch_factor - factor by which the grid will be stretched
-    dz_max - maximum vertical grid spacing [m]
-    dz_stretch_level_start(9) - array of height levels above which the grid is
-        to be stretched vertically [m]
-    dz_stretch_level_end(9) - array of height levels until which the grid is to
-        be stretched vertically [m]
-    longitude, latitude - geographical coordinates of the PALM-4U origin [deg]
-
-
-#### d3par
-
-    end_time - PALM-4U simulation time. INIFOR will produce hourly forcing data
-        from the start date (see -d command-line option) to end_time seconds
-        thereafter. [s]
-
-
-#### EXAMPLE NAMELIST FILE
-
-    &inipar nx = 4679, ny = 3939, nz = 360
-            dx = 10., dy = 10., dz = 10.
-            dz_stretch_level = 2500.0, dz_stretch_factor = 1.08, dz_max = 100.0
-            longitude = 13.082744, latitude = 52.325079
-    /
-    
-    &d3par  end_time = 86400.0
-    /
-
-
-### COMMAND-LINE PARAMETERS
-
-#### INIFOR configuration
-
-    --averaging-mode <mode>:
-        Selects how averaged quantities (large-scale forcing terms) are computed.
-        INIFOR supports averaging along input model levels ('level') and along
-        constant heights ('height'). Default: level
-
-    -a, --averaging-angle <angle>:
-        Width of the averaging box in longitudal and latitudal direction in the
-        source coordinate system (COSMO rotated-pole) [deg]. Default: 2.0
-
-    -d, --date, -date <date>:
-        Start date of the simulation in the form YYYYMMDD or YYYYMMDDHH. If no
-        hours (HH) are given, INIFOR assumes that the simulation starts at O UTC
-        on that day. Default: 20130721
-
-    -i, --init-mode, -mode <mode>:
-        Set the PALM-4U initialization mode. INIFOR can provide initial conditions
-        as either profiles or three-dimensional fields. The corresponding modes
-        are 'profile' and 'volume'. Default: volume
-
-    -r, --surface-pressure, -p0 <pressure>:
-        Manually set the pressure at z=0 in the PALM-4U domain [Pa]. If not
-        given, the surface pressure is computed from the COSMO pressure field.
-
-    -u, --geostrophic-u, -ug <velocity>:
-        Manually specify the geostrophic wind in x direction [m/s]. If not
-        given, the geostrophic wind is computed from the COSMO pressure field.
-
-    -v, --geostrophic-v, -vg <velocity>:
-        Manually specify the geostrophic wind in y direction [m/s]. If not
-        given, the geostrophic wind is computed from the COSMO pressure field.
-
-    -z, --elevation, -z0 <height>: Specifies the elevation of the PALM-4U domain
-        above sea level [m]. Default: 35
-
-#### I/O
-
-    -l, --hhl-file, -hhl <netCDF file>:
-        Location of the netCDF file containing the vertical COSMO grid levels,
-        specifically the heights of half levels (hhl, i.e. vertical cell faces).
-        Default: <scenario path>/hhl.nc
-
-    -n, --namelist <namelist file>:
-        Location of the PALM-4U namelist file. INIFOR expects the file to contain
-        two namelists, inipar and d3par, from which it will read grid parameters
-        and the simulation time. Default: ./namelist
-
-    -o, --output <output file>:
-        Name of the INIFOR output file, i.e. the PALM-4U dynamic driver.
-        Default: ./dynamic_driver.nc
-
-    -p, --path, -path <scenario path>:
-        Scenario path, i.e. the path of the meteorological input data. Default: ./
-
-    -s, --soil-file, -soil <netCDF file>:
-        Location of the netCDF file containing the COSMO soil type map.
-        Default: <scenario path>/soil.nc
-
-    -t, --static-driver, -static <netCDF file>:
-        Location of the netCDF file containing the static driver for the case
-        to be simulated with PALM-4U. Optional parameter. Default: None
-
-
-
-#### FILE PREFIXES
-
-    --input-prefix <prefix>:
-        Set the file prefixes for all input files. Individual prefixes can be
-        overwritten with the options below. Default: laf
-
-    --flow-prefix <prefix>:
-        Set the file prefix of flow input files. Default: laf
-
-    --radiation-prefix <prefix>:
-        Set the file prefix of radiation input files. Default: laf
-
-    --soil-prefix <prefix>:
-        Set the file prefix of soil input files. Default: laf
-
-    --soilmoisture-prefix <prefix>:
-        Set the file prefix of soil moisture input files. Default: laf
-
-#### Non-parameter options
-
-    --debug:
-        Enable additional terminal messages and netCDF output for debugging.
-
-    --version:
-        Output version number and exit.
-
Index: /palm/trunk/UTIL/inifor/src/inifor.f90
===================================================================
--- /palm/trunk/UTIL/inifor/src/inifor.f90	(revision 3996)
+++ /palm/trunk/UTIL/inifor/src/inifor.f90	(revision 3997)
@@ -26,4 +26,8 @@
 ! -----------------
 ! $Id$
+! Alert user to warnings if any
+! 
+! 
+! 3866 2019-04-05 14:25:01Z eckhard
 ! Use PALM's working precision
 ! Show error message if compiled without netCDF support
@@ -185,6 +189,6 @@
 !
 !-- Initialize the netCDF output file and define dimensions
-    CALL setup_netcdf_dimensions(output_file, palm_grid, cfg%start_date,    &
-                                 origin_lon, origin_lat)
+    CALL setup_netcdf_dimensions( output_file, palm_grid, cfg%start_date,      &
+                                  origin_lon, origin_lat )
     CALL log_runtime( 'time', 'write' )
 
@@ -587,6 +591,13 @@
     CALL log_runtime( 'report', 'void' )
 
-    message = "Finished writing dynamic driver '" // TRIM( output_file%name ) // &
-              "' successfully."
+    message = "Finished writing dynamic driver '" // TRIM( output_file%name )
+   
+    IF ( n_wrngs > 0 )  THEN
+       message = TRIM( message ) // "' with " // TRIM( str( n_wrngs ) ) //     &
+       " warning(s). Please see logfile '" // LOG_FILE_NAME // "'."
+    ELSE
+       message = TRIM( message ) // "' successfully."
+    END IF
+
     CALL report( 'main loop', message )
     CALL close_log
Index: /palm/trunk/UTIL/inifor/src/inifor_control.f90
===================================================================
--- /palm/trunk/UTIL/inifor/src/inifor_control.f90	(revision 3996)
+++ /palm/trunk/UTIL/inifor/src/inifor_control.f90	(revision 3997)
@@ -26,4 +26,8 @@
 ! -----------------
 ! $Id$
+! Added warnings counter
+! 
+! 
+! 3866 2019-04-05 14:25:01Z eckhard
 ! Use PALM's working precision
 ! Renamed run_control -> log_runtime
@@ -85,4 +89,5 @@
     CHARACTER (LEN=5000) ::  tip     = '' !< optional log message buffer for tips on how to rectify encountered errors
     INTEGER, SAVE        ::  u            !< Fortran file unit for the log file
+    INTEGER, SAVE        ::  n_wrngs = 0  !< Fortran file unit for the log file
 
  CONTAINS
@@ -143,4 +148,5 @@
     CHARACTER(LEN=*), INTENT(IN) ::  message !< log message
 
+    n_wrngs = n_wrngs + 1
     CALL report(routine, "WARNING: " // TRIM(message))
 
Index: /palm/trunk/UTIL/inifor/src/inifor_defs.f90
===================================================================
--- /palm/trunk/UTIL/inifor/src/inifor_defs.f90	(revision 3996)
+++ /palm/trunk/UTIL/inifor/src/inifor_defs.f90	(revision 3997)
@@ -26,4 +26,10 @@
 ! -----------------
 ! $Id$
+! Defined netCDF attribute names for PALM origin coordinates
+! Make netCDF variable names constants
+! Bumped version number
+! 
+! 
+! 3867 2019-04-05 16:15:55Z eckhard
 ! Added parameter for INIFOR's log file name
 ! Use PALM's working precision
@@ -145,13 +151,19 @@
  REAL(wp), PARAMETER ::  CP_PALM = 1005.0_wp  !< heat capacity of dry air at constant pressure, used in computation of PALM-4U's potential temperature [J/kg/K]
 
+!
+!-- PALM static driver attribute names (PIDS 1.9)
+CHARACTER(SNAME), PARAMETER ::  PIDS_ORIGIN_LON = 'origin_lon'
+CHARACTER(SNAME), PARAMETER ::  PIDS_ORIGIN_LAT = 'origin_lat'
+CHARACTER(SNAME), PARAMETER ::  PIDS_ORIGIN_Z   = 'origin_z'
+
 ! 
 !-- COSMO netCDF names
-CHARACTER(SNAME) ::  NC_DEPTH_NAME = 'depth_2'
-CHARACTER(SNAME) ::  NC_HHL_NAME = 'HHL'
-CHARACTER(SNAME) ::  NC_RLAT_NAME = 'rlat'
-CHARACTER(SNAME) ::  NC_RLON_NAME = 'rlon'
-CHARACTER(SNAME) ::  NC_ROTATED_POLE_NAME = 'rotated_pole'
-CHARACTER(SNAME) ::  NC_POLE_LATITUDE_NAME = 'grid_north_pole_latitude'
-CHARACTER(SNAME) ::  NC_POLE_LONGITUDE_NAME = 'grid_north_pole_longitude'
+CHARACTER(SNAME), PARAMETER ::  NC_DEPTH_NAME = 'depth_2'
+CHARACTER(SNAME), PARAMETER ::  NC_HHL_NAME = 'HHL'
+CHARACTER(SNAME), PARAMETER ::  NC_RLAT_NAME = 'rlat'
+CHARACTER(SNAME), PARAMETER ::  NC_RLON_NAME = 'rlon'
+CHARACTER(SNAME), PARAMETER ::  NC_ROTATED_POLE_NAME = 'rotated_pole'
+CHARACTER(SNAME), PARAMETER ::  NC_POLE_LATITUDE_NAME = 'grid_north_pole_latitude'
+CHARACTER(SNAME), PARAMETER ::  NC_POLE_LONGITUDE_NAME = 'grid_north_pole_longitude'
 
 !
@@ -164,5 +176,5 @@
     ACHAR( 10 ) // ' Copyright 2017-2019 Deutscher Wetterdienst Offenbach' !< Copyright notice
  CHARACTER(LEN=*), PARAMETER ::  LOG_FILE_NAME = 'inifor.log' !< Name of INIFOR's log file
- CHARACTER(LEN=*), PARAMETER ::  VERSION = '1.4.9rc'          !< INIFOR version number
+ CHARACTER(LEN=*), PARAMETER ::  VERSION = '1.4.9'            !< INIFOR version number
  
  END MODULE inifor_defs
Index: /palm/trunk/UTIL/inifor/src/inifor_grid.f90
===================================================================
--- /palm/trunk/UTIL/inifor/src/inifor_grid.f90	(revision 3996)
+++ /palm/trunk/UTIL/inifor/src/inifor_grid.f90	(revision 3997)
@@ -26,4 +26,9 @@
 ! -----------------
 ! $Id$
+! Read origin_z from static driver if given on the command line
+! Warn if origin_z is specified twice (by static driver and --elevation)
+! 
+! 
+! 3866 2019-04-05 14:25:01Z eckhard
 ! Use PALM's working precision
 ! Catch errors while reading namelists
@@ -140,5 +145,8 @@
                SNAME, LNAME, PATH, FORCING_STEP, WATER_ID, FILL_ITERATIONS,    &
                BETA, P_SL, T_SL, BETA, RD, RV, G, P_REF, RD_PALM, CP_PALM,     &
-               RHO_L, OMEGA, HECTO, wp, iwp
+               RHO_L, OMEGA, HECTO, wp, iwp,                                   &
+               PIDS_ORIGIN_LON,                                                &
+               PIDS_ORIGIN_LAT,                                                &
+               PIDS_ORIGIN_Z
     USE inifor_io,                                                             &
         ONLY:  get_cosmo_grid, get_netcdf_attribute, get_netcdf_dim_vector,    &
@@ -440,6 +448,4 @@
 
     output_file%name = cfg%output_file
-    z0 = cfg%z0
-    p0 = cfg%p0
 
     init_variables_required = .TRUE.
@@ -536,6 +542,8 @@
     IF (TRIM(cfg%static_driver_file) .NE. '')  THEN
 
-       origin_lon = get_netcdf_attribute(cfg%static_driver_file, 'origin_lon')
-       origin_lat = get_netcdf_attribute(cfg%static_driver_file, 'origin_lat')
+       origin_lon = get_netcdf_attribute(cfg%static_driver_file, TRIM( PIDS_ORIGIN_LON ) )
+       origin_lat = get_netcdf_attribute(cfg%static_driver_file, TRIM( PIDS_ORIGIN_LAT ) )
+       z0         = get_netcdf_attribute(cfg%static_driver_file, TRIM( PIDS_ORIGIN_Z ) )
+
 
        message = TRIM(message) // " static driver file '"                   &
@@ -556,4 +564,17 @@
 
     CALL report('setup_parameters', message)
+
+    IF ( cfg%z0_is_set .AND. TRIM( cfg%static_driver_file ) .NE. '' )  THEN
+
+       message = 'You specified both --static-driver/-t and --elevation/-z0. ' // &
+                 'Using the command line value (' // TRIM( real_to_str_f( cfg%z0 ) ) // &
+                 ') instead of static driver value (' // TRIM( real_to_str_f( z0 ) ) // ').'
+       CALL warn('setup_parameters', message)
+
+       z0 = cfg%z0
+
+    END IF
+
+    p0 = cfg%p0
 
     CALL log_runtime('time', 'read')
Index: /palm/trunk/UTIL/inifor/src/inifor_io.f90
===================================================================
--- /palm/trunk/UTIL/inifor/src/inifor_io.f90	(revision 3996)
+++ /palm/trunk/UTIL/inifor/src/inifor_io.f90	(revision 3997)
@@ -26,4 +26,9 @@
 ! -----------------
 ! $Id$
+! Added boolean indicator for --elevation option invocation
+! Stop INIFOR if no command-line options given
+! 
+! 
+! 3866 2019-04-05 14:25:01Z eckhard
 ! Use PALM's working precision
 ! Improved coding style
@@ -143,6 +148,6 @@
 !------------------------------------------------------------------------------!
     INTERFACE get_netcdf_variable
-        MODULE PROCEDURE get_netcdf_variable_int
-        MODULE PROCEDURE get_netcdf_variable_real
+       MODULE PROCEDURE get_netcdf_variable_int
+       MODULE PROCEDURE get_netcdf_variable_real
     END INTERFACE get_netcdf_variable
 
@@ -411,12 +416,13 @@
     INTEGER                            ::  arg_count, i
 
-    cfg%p0_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.
+    cfg%p0_is_set = .FALSE.
     cfg%radiation_prefix_is_set = .FALSE.
     cfg%soil_prefix_is_set = .FALSE.
     cfg%soilmoisture_prefix_is_set = .FALSE.
+    cfg%ug_defined_by_user = .FALSE.
+    cfg%vg_defined_by_user = .FALSE.
+    cfg%z0_is_set = .FALSE.
 
     arg_count = COMMAND_ARGUMENT_COUNT()
@@ -448,4 +454,5 @@
 
              CASE( '-z0', '-z', '--elevation' )
+                cfg%z0_is_set = .TRUE.
                 CALL get_option_argument( i, arg )
                 READ(arg, *) cfg%z0
@@ -552,6 +559,7 @@
     ELSE
          
-       message = "No arguments present, using default input and output files"
-       CALL report('parse_command_line_arguments', message)
+       CALL print_version
+       CALL report( 'parse_command_line_arguments', 'No arguments present, exiting.' )
+       STOP
 
     ENDIF
@@ -559,5 +567,5 @@
  END SUBROUTINE parse_command_line_arguments
 
-   
+
 
  SUBROUTINE get_datetime_file_list( start_date_string, start_hour, end_hour, &
Index: /palm/trunk/UTIL/inifor/src/inifor_types.f90
===================================================================
--- /palm/trunk/UTIL/inifor/src/inifor_types.f90	(revision 3996)
+++ /palm/trunk/UTIL/inifor/src/inifor_types.f90	(revision 3997)
@@ -26,4 +26,8 @@
 ! -----------------
 ! $Id$
+! Added boolean indicator for --elevation option invocation, sorted varibles
+! 
+! 
+! 3866 2019-04-05 14:25:01Z eckhard
 ! Use PALM's working precision
 !
@@ -117,12 +121,13 @@
     
     LOGICAL              ::  debug                       !< indicates whether --debug option was given
-    LOGICAL              ::  p0_is_set                   !< indicates whether p0 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              ::  p0_is_set                   !< indicates whether p0 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              ::  z0_is_set                   !< indicates whether z0 was set manually
  END TYPE inifor_config
 
