!> @file src/inifor_types.f90
!------------------------------------------------------------------------------!
! This file is part of the PALM model system.
!
! PALM is free software: you can redistribute it and/or modify it under the
! terms of the GNU General Public License as published by the Free Software
! Foundation, either version 3 of the License, or (at your option) any later
! version.
!
! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
! A PARTICULAR PURPOSE. See the GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License along with
! PALM. If not, see .
!
! Copyright 2017-2020 Leibniz Universitaet Hannover
! Copyright 2017-2020 Deutscher Wetterdienst Offenbach
!------------------------------------------------------------------------------!
!
! Current revisions:
! -----------------
!
!
! Former revisions:
! -----------------
! $Id: inifor_types.f90 4675 2020-09-11 10:00:26Z suehring $
! Added INIFOR configuration flag for soil profile initialization
!
!
! 4659 2020-08-31 11:21:17Z eckhard
! Added flag in support of new command-line option '--precipitation'
! Improved code formatting
!
!
! 4568 2020-06-19 11:56:30Z eckhard
! Handle COSMO soil data with and without additional surface temperature
!
!
! 4553 2020-06-03 16:34:15Z eckhard
! Minor code readability improvements
!
!
! 4538 2020-05-18 13:45:35Z eckhard
! Added boolean indicator for --static-driver option invocation
!
!
! 4523 2020-05-07 15:58:16Z eckhard
! respect integer working precision (iwp) specified in inifor_defs.f90
!
!
! 4481 2020-03-31 18:55:54Z maronga
! Added boolean indicator for --elevation option invocation, sorted varibles
!
!
! 3866 2019-04-05 14:25:01Z eckhard
! Use PALM's working precision
!
!
! 3779 2019-03-05 11:13:35Z eckhard
! Improved variable naming
!
! 3680 2019-01-18 14:54:12Z knoop
! Prefixed all INIFOR modules with inifor_
!
!
! 3557 2018-11-22 16:01:22Z eckhard
! Updated documentation
!
!
! 3447 2018-10-29 15:52:54Z eckhard
! Renamed source files for compatibilty with PALM build system
!
!
! 3395 2018-10-22 17:32:49Z eckhard
! Added *_is_set LOGICALs to inifor_config type to indicate option invocation
! from the command-line
! Added 1D index vertical weights lists to support addressing averaging regions
! by list of columns instead of index bounds
!
!
! 3183 2018-07-27 14:25:55Z suehring
! Introduced new PALM grid stretching:
! - Converted vertical grid_definition coordinte variables to pointers
! Improved command line interface:
! - Moved INIFOR configuration into a new derived data type
! Removed unnecessary variables
!
!
! 3182 2018-07-27 13:36:03Z suehring
! Initial revision
!
!
!
! Authors:
! --------
!> @author Eckhard Kadasch (Deutscher Wetterdienst, Offenbach)
!
! Description:
! ------------
!> The types module provides derived data types used in INIFOR.
!------------------------------------------------------------------------------!
MODULE inifor_types
USE inifor_defs, &
ONLY: DATE, PATH, SNAME, LNAME, iwp, wp
#if defined ( __netcdf )
USE netcdf, &
ONLY: NF90_MAX_VAR_DIMS, NF90_MAX_NAME
#endif
IMPLICIT NONE
!------------------------------------------------------------------------------!
! Description:
! ------------
!> Contaner for the INIFOR command-line configuration
!------------------------------------------------------------------------------!
TYPE inifor_config
CHARACTER(LEN=DATE) :: start_date !< String of the FORMAT YYYYMMDDHH indicating the start of the intended PALM-4U simulation
CHARACTER(LEN=PATH) :: input_path !< Path to the input data file directory
CHARACTER(LEN=PATH) :: hhl_file !< Path to the file containing the COSMO-DE HHL variable (height of half layers, i.e. vertical cell faces)
CHARACTER(LEN=PATH) :: namelist_file !< Path to the PALM-4U namelist file
CHARACTER(LEN=PATH) :: output_file !< Path to the INIFOR output file (i.e. PALM-4U dynamic driver')
CHARACTER(LEN=PATH) :: soiltyp_file !< Path to the file containing the COSMO-DE SOILTYP variable (map of COSMO-DE soil types)
CHARACTER(LEN=PATH) :: static_driver_file !< Path to the file containing the COSMO-DE SOILTYP variable (map of COSMO-DE soil types)
CHARACTER(LEN=SNAME) :: flow_prefix !< Prefix of flow input files, e.g. 'laf' for COSMO-DE analyses
CHARACTER(LEN=SNAME) :: input_prefix !< Prefix of all input files, e.g. 'laf' for COSMO-DE analyses
CHARACTER(LEN=SNAME) :: radiation_prefix !< Prefix of radiation input files, e.g 'laf' for COSMO-DE analyses
CHARACTER(LEN=SNAME) :: soil_prefix !< Prefix of soil input files, e.g. 'laf' for COSMO-DE analyses
CHARACTER(LEN=SNAME) :: precipitation_prefix !< Prefix of input files for precipitation forcing, e.g 'laf' for COSMO-DE analyses
CHARACTER(LEN=SNAME) :: averaging_mode !< destinguishes between level-based and heigh-based averaging
CHARACTER(LEN=SNAME) :: bc_mode !< destinguishes realistic and idealistic forcing
CHARACTER(LEN=SNAME) :: ic_mode !< destinguishes volume and profile initialization
CHARACTER(LEN=SNAME) :: isc_mode !< destinguishes volume and profile soil initialization
CHARACTER(LEN=SNAME) :: rotation_method !< selects method for velocity rotation
REAL(wp) :: p0 !< manually specified surface pressure [Pa]
REAL(wp) :: ug !< manually spefied geostrophic wind component in x direction [m/s]
REAL(wp) :: vg !< manually spefied geostrophic wind component in y direction [m/s]
REAL(wp) :: z0 !< elevation of the PALM-4U domain above sea level [m]
REAL(wp) :: averaging_angle !< latitudal and longitudal width of averaging regions [deg]
LOGICAL :: debug !< indicates whether --debug option was given
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 :: precipitation_prefix_is_set !< indicates whether the precipitation prefix was set manually
LOGICAL :: process_precipitation !< indicates whether precipitation should be processed
LOGICAL :: static_driver_is_set !< indicates whether a static driver was given
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
!------------------------------------------------------------------------------!
! Description:
! ------------
!> Container for grid data, in partucular coordinates, interpolation neighbours
!> and weights
!------------------------------------------------------------------------------!
TYPE grid_definition
CHARACTER(LEN=SNAME) :: name(3) !< names of the grid dimensions, e.g. (/'x', 'y', 'z'/) or (/'latitude', 'longitude', 'height'/)
CHARACTER(LEN=SNAME) :: kind !< names of the grid dimensions, e.g. (/'x', 'y', 'z'/) or (/'latitude', 'longitude', 'height'/)
INTEGER(iwp) :: k_min !< Index of lowest PALM grid level that is not cut by local COSMO orography; vertically separates interpolation and extrapolation region.
INTEGER(iwp) :: nx !< number of gridpoints in the first dimension
INTEGER(iwp) :: ny !< number of gridpoints in the second dimension
INTEGER(iwp) :: nz !< number of gridpoints in the third dimension, used for PALM points
INTEGER(iwp) :: nlev !< number of COSMO grid levels
INTEGER(iwp) :: n_columns !< number of averaging columns of the source grid
INTEGER(iwp), ALLOCATABLE :: ii(:,:,:) !< Given a point (i,j,k) in the PALM-4U grid, ii(i,j,l) gives the x index of the l'th horizontl neighbour on the COSMO-DE grid.
INTEGER(iwp), ALLOCATABLE :: jj(:,:,:) !< Given a point (i,j,k) in the PALM-4U grid, jj(i,j,l) gives the y index of the l'th horizontl neighbour on the COSMO-DE grid.
INTEGER(iwp), ALLOCATABLE :: kk(:,:,:,:) !< Given a point (i,j,k) in the PALM-4U grid, kk(i,j,k,l) gives the z index of the l'th vertical neighbour in the intermediate grid.
INTEGER(iwp), ALLOCATABLE :: iii(:) !< profile averaging neighbour indices
INTEGER(iwp), ALLOCATABLE :: jjj(:) !< profile averaging neighbour indices
INTEGER(iwp), ALLOCATABLE :: kkk(:,:,:) !< indices of vertical interpolation neightbours, kkk(