Changeset 4568 for palm/trunk/UTIL


Ignore:
Timestamp:
Jun 19, 2020 11:56:30 AM (4 years ago)
Author:
eckhard
Message:

Handle COSMO soil data with and without additional surface temperature

Location:
palm/trunk/UTIL/inifor/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • palm/trunk/UTIL/inifor/src/inifor_defs.f90

    r4553 r4568  
    2626! -----------------
    2727! $Id$
     28! Bumped version number
     29!
     30!
     31! 4553 2020-06-03 16:34:15Z eckhard
    2832! Bumped version number
    2933!
     
    178182
    179183!
    180 !-- COSMO netCDF names
     184!-- COSMO netCDF parameters
     185INTEGER, PARAMETER          ::  NC_DEPTH_DIM_IDX = 3
    181186CHARACTER(SNAME), PARAMETER ::  NC_DEPTH_NAME = 'depth_2'
    182187CHARACTER(SNAME), PARAMETER ::  NC_HHL_NAME = 'HHL'
     
    196201    ACHAR( 10 ) // ' Copyright 2017-2020 Deutscher Wetterdienst Offenbach' !< Copyright notice
    197202 CHARACTER(LEN=*), PARAMETER ::  LOG_FILE_NAME = 'inifor.log' !< Name of INIFOR's log file
    198  CHARACTER(LEN=*), PARAMETER ::  VERSION = '1.4.15'           !< INIFOR version number
     203 CHARACTER(LEN=*), PARAMETER ::  VERSION = '1.4.16'           !< INIFOR version number
    199204 
    200205 END MODULE inifor_defs
  • palm/trunk/UTIL/inifor/src/inifor_grid.f90

    r4553 r4568  
    2626! -----------------
    2727! $Id$
     28! Handle COSMO soil data with and without additional surface temperature
     29! Imporved messaging
     30!
     31!
     32! 4553 2020-06-03 16:34:15Z eckhard
    2833! Fixed domain extent check
    2934! Added and fixed code documentation
     
    177182        ONLY:  get_cosmo_grid, get_input_file_list, get_netcdf_attribute,      &
    178183               get_netcdf_dim_vector, get_netcdf_variable, set_palm_origin,    &
    179                parse_command_line_arguments, validate_config
     184               parse_command_line_arguments, validate_config,                  &
     185               has_surface_value
    180186    USE inifor_transform,                                                      &
    181187        ONLY:  average_2d, rotate_to_cosmo, find_horizontal_neighbours,        &
     
    639645    CALL report ('setup_parameters', message)
    640646
    641     message = "North pole of the rotated COSMO-DE system:" // NEW_LINE(' ') // &
     647    message = "COSMO rotated north pole:" // NEW_LINE(' ') // &
    642648       "           lon (lambda) = " // &
    643649       TRIM(real_to_str_f(lambda_n * TO_DEGREES)) // " deg" // NEW_LINE(' ') //&
     
    23842390    ENDIF
    23852391
    2386     nc_source_text = 'COSMO-DE analysis from ' // TRIM(cfg%start_date)
     2392    nc_source_text = 'COSMO analysis from ' // TRIM(cfg%start_date)
    23872393
    23882394    n_invar = 17
     
    23952401!- Section 1: NetCDF input variables
    23962402!------------------------------------------------------------------------------
     2403
     2404!
     2405!-- COSMO's soil temperature T_SO may contain the surface temperature at
     2406!-- depth=0, which is a redundant copy the first soil layer. INIFOR uses this
     2407!-- flag to decide if this level is present and has to be ignored in
     2408!-- inifor_io:get_netcdf_start_and_count().
     2409    input_var_table(:)%has_redundant_first_level = .FALSE.
     2410
    23972411    var => input_var_table(1)
    23982412    var%name = 'T_SO'
    23992413    var%to_be_processed = .TRUE.
    24002414    var%is_upside_down = .FALSE.
     2415    input_var_table(1)%has_redundant_first_level = has_surface_value( var, soil_files(1) )
    24012416
    24022417    var => input_var_table(2)
  • palm/trunk/UTIL/inifor/src/inifor_io.f90

    r4553 r4568  
    2626! -----------------
    2727! $Id$
     28! Handle COSMO soil data with and without additional surface temperature
     29!
     30!
     31! 4553 2020-06-03 16:34:15Z eckhard
    2832! Option --help now points the user to INIFOR's wiki page
    2933! Remove deprecated command-line options -clon and -clat
     
    146150    USE inifor_defs,                                                           &
    147151        ONLY:  DATE, SNAME, PATH, PI, TO_RADIANS, TO_DEGREES, VERSION,         &
    148                NC_DEPTH_NAME, NC_HHL_NAME, NC_RLAT_NAME, NC_RLON_NAME,         &
    149                NC_ROTATED_POLE_NAME, NC_POLE_LATITUDE_NAME,                    &
     152               NC_DEPTH_DIM_IDX, NC_DEPTH_NAME, NC_HHL_NAME, NC_RLAT_NAME,     &
     153               NC_RLON_NAME, NC_ROTATED_POLE_NAME, NC_POLE_LATITUDE_NAME,      &
    150154               NC_POLE_LONGITUDE_NAME, RHO_L, iwp, wp,                         &
    151155               PIDS_ORIGIN_LON, PIDS_ORIGIN_LAT, PIDS_ORIGIN_Z
    152156    USE inifor_types
    153157    USE inifor_util,                                                           &
    154         ONLY:  add_hours_to, reverse, str, real_to_str
     158        ONLY:  add_hours_to, nearly_equal, reverse, str, real_to_str
    155159    USE netcdf
    156160
     
    355359
    356360    start = (/ 1, 1, 1 /)
    357     IF ( TRIM(in_var%name) .EQ. 'T_SO' )  THEN
     361    IF ( TRIM(in_var%name) .EQ. 'T_SO' .AND.                                &
     362         in_var%has_redundant_first_level )  THEN
     363       
    358364!
    359365!--    Skip depth = 0.0 for T_SO and reduce number of depths from 9 to 8
     
    15781584 END SUBROUTINE set_palm_origin
    15791585
     1586
     1587!------------------------------------------------------------------------------!
     1588! Description:
     1589! ------------
     1590! This function is meant to check weather a COSMO soil variable has an
     1591! additional and redunant surface value at depth = 0.0. For instance operational
     1592! DWD COSMO output contains the surface temperature in T_SO as a copy of the
     1593! values in the first soil layer.
     1594!------------------------------------------------------------------------------!
     1595 LOGICAL FUNCTION has_surface_value( soil_var, filename )
     1596
     1597    TYPE(nc_var), INTENT(IN)     ::  soil_var
     1598    CHARACTER(LEN=*), INTENT(IN) ::  filename
     1599   
     1600    CHARACTER(LEN=NF90_MAX_NAME) ::  dimname
     1601    REAL(wp), ALLOCATABLE        ::  depths(:)
     1602
     1603    CALL get_dimension_vector_of_variable(                                     &
     1604       soil_var%name,                                                          &
     1605       dim_idx = NC_DEPTH_DIM_IDX,                                             &
     1606       filename = filename,                                                    &
     1607       dim_vector = depths                                                     &
     1608    )
     1609
     1610    has_surface_value = nearly_equal( depths(1), 0.0_wp, 10 * EPSILON(1.0_wp) )
     1611
     1612 END FUNCTION has_surface_value
     1613
     1614
     1615!------------------------------------------------------------------------------!
     1616! Description:
     1617! ------------
     1618! This routine reads the dim_idx-th dimension vector of the variable varname
     1619! from netCDF file filename. It is used for finding the depth coordinate vector
     1620! of COSMO soil variables without knowing its name.
     1621!------------------------------------------------------------------------------!
     1622 SUBROUTINE get_dimension_vector_of_variable( varname, dim_idx, filename, dim_vector )
     1623    CHARACTER(LEN=*), INTENT(IN)              ::  varname, filename
     1624    INTEGER, INTENT(IN)                       ::  dim_idx
     1625
     1626    REAL(wp), INTENT(OUT), ALLOCATABLE ::  dim_vector(:)
     1627
     1628    INTEGER                            ::  dimids(NF90_MAX_VAR_DIMS)
     1629    INTEGER                            ::  varid
     1630    CHARACTER(LEN=NF90_MAX_NAME)       ::  dimname
     1631
     1632    INTEGER ::  ncid
     1633
     1634    IF ( nf90_open( TRIM( filename ), NF90_NOWRITE, ncid ) .EQ. NF90_NOERR )  THEN
     1635
     1636!
     1637!--    get id of variable varname
     1638       CALL check( nf90_inq_varid( ncid, TRIM( varname ), varid ) )
     1639       
     1640!
     1641!--    get dimension ids of variable with varid
     1642       CALL check( nf90_inquire_variable( ncid, varid, dimids = dimids ) )
     1643
     1644!
     1645!--    get name of dim_idx-th dimension variable
     1646       CALL check( nf90_inquire_dimension( ncid, dimids(dim_idx), name = dimname ) )
     1647       CALL check( nf90_close( ncid ) )
     1648
     1649    ELSE
     1650
     1651       message = "Failed to open file '" // TRIM(filename) // "'."
     1652       CALL inifor_abort('get_netcdf_variable', message)
     1653
     1654    ENDIF
     1655
     1656    ! get dimension vector with dimname
     1657    CALL get_netcdf_dim_vector( filename, dimname, dim_vector )
     1658
     1659 END SUBROUTINE get_dimension_vector_of_variable
     1660
     1661
    15801662 END MODULE inifor_io
    15811663#endif
  • palm/trunk/UTIL/inifor/src/inifor_types.f90

    r4553 r4568  
    2626! -----------------
    2727! $Id$
     28! Handle COSMO soil data with and without additional surface temperature
     29!
     30!
     31! 4553 2020-06-03 16:34:15Z eckhard
    2832! Minor code readability improvements
    2933!
     
    245249    LOGICAL                               ::  is_read = .FALSE.         !< INIFOR flag indicating whether variable has been read
    246250    LOGICAL                               ::  is_upside_down  = .FALSE. !< INIFOR flag indicating whether vertical dimension is reversed (typically the case with COSMO-DE atmospheric fields)
     251    LOGICAL                               ::  has_redundant_first_level !< INIFOR flag inidicating whether a soil variable has a redundant first level (e.g. COSMO's T_SO may contain the surface temperature at depth=0, which is a redundant copy the first model layer)
    247252    TYPE(grid_definition), POINTER        ::  grid                      !< Pointer to the corresponding output grid
    248253    TYPE(grid_definition), POINTER        ::  intermediate_grid         !< Pointer to the corresponding intermediate grid
  • palm/trunk/UTIL/inifor/src/inifor_util.f90

    r4523 r4568  
    2626! -----------------
    2727! $Id$
     28! Added function for checking floating point equality
     29!
     30!
     31! 4523 2020-05-07 15:58:16Z eckhard
    2832! respect integer working precision (iwp) specified in inifor_defs.f90
    2933!
     
    462466 END SUBROUTINE
    463467
     468
     469!------------------------------------------------------------------------------!
     470! Description:
     471! ------------
     472!> Check for exact or near equality of two floating point numbers. Inspired by
     473!> https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
     474!------------------------------------------------------------------------------!
     475 LOGICAL FUNCTION nearly_equal(a, b, max_rel_diff)
     476
     477    REAL(wp), INTENT(IN) ::  a, b, max_rel_diff
     478    REAL(wp)             ::  diff, mag
     479 
     480    diff = ABS( a - b )
     481    mag = MAX( ABS(a), ABS(b) )
     482    nearly_equal = ( diff .LE. mag * max_rel_diff )
     483
     484 END FUNCTION nearly_equal
     485
    464486 END MODULE inifor_util
Note: See TracChangeset for help on using the changeset viewer.