Ignore:
Timestamp:
Jan 17, 2019 2:12:17 PM (3 years ago)
Author:
eckhard
Message:

inifor: bugfix: avoid empty averaging regions, check if all input files are present

File:
1 edited

Legend:

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

    r3618 r3678  
    2626! -----------------
    2727! $Id$
     28! Moved get_input_file_list() here from grid module, added check for presence of
     29!    input files
     30!
     31!
     32!
     33!
     34! 3618 2018-12-10 13:25:22Z eckhard
    2835! Prefixed all INIFOR modules with inifor_
    2936!
     
    98105    USE inifor_types
    99106    USE inifor_util,                                                           &
    100         ONLY:  reverse, str, real_to_str
     107        ONLY:  add_hours_to, reverse, str, real_to_str
    101108    USE netcdf
    102109
     
    529536
    530537   
     538
     539   SUBROUTINE get_datetime_file_list( start_date_string, start_hour, end_hour, &
     540                                      step_hour, input_path, prefix, suffix,   &
     541                                      file_list )
     542
     543      CHARACTER (LEN=DATE), INTENT(IN) ::  start_date_string
     544      CHARACTER (LEN=*),    INTENT(IN) ::  prefix, suffix, input_path
     545      INTEGER,              INTENT(IN) ::  start_hour, end_hour, step_hour
     546      CHARACTER(LEN=*), ALLOCATABLE, INTENT(INOUT) ::  file_list(:)
     547
     548      INTEGER             ::  number_of_intervals, hour, i
     549      CHARACTER(LEN=DATE) ::  date_string
     550
     551      number_of_intervals = CEILING( REAL(end_hour - start_hour) / step_hour )
     552      ALLOCATE( file_list(number_of_intervals + 1) )
     553
     554      DO i = 0, number_of_intervals
     555
     556         hour = start_hour + i * step_hour
     557         date_string = add_hours_to(start_date_string, hour)
     558
     559         file_list(i+1) = TRIM(input_path) // TRIM(prefix) //                  &
     560                          TRIM(date_string) // TRIM(suffix) // '.nc'
     561
     562         message = "Set up input file name '" // TRIM(file_list(i+1)) // "'"
     563         CALL report('input_file_list', message)
     564
     565      END DO
     566
     567   END SUBROUTINE get_datetime_file_list
     568
     569!------------------------------------------------------------------------------!
     570! Description:
     571! ------------
     572!> Establish a list of files based on the given start and end times and file
     573!> prefixes and suffixes.
     574!------------------------------------------------------------------------------!
     575   SUBROUTINE get_input_file_list( start_date_string, start_hour, end_hour,    &
     576                                   step_hour, input_path, prefix, suffix,      &
     577                                   file_list )
     578
     579      CHARACTER (LEN=DATE), INTENT(IN) ::  start_date_string
     580      CHARACTER (LEN=*),    INTENT(IN) ::  prefix, suffix, input_path
     581      INTEGER,              INTENT(IN) ::  start_hour, end_hour, step_hour
     582      CHARACTER(LEN=*), ALLOCATABLE, INTENT(INOUT) ::  file_list(:)
     583
     584      INTEGER             ::  number_of_intervals, hour, i
     585      CHARACTER(LEN=DATE) ::  date_string
     586      CHARACTER(LEN=PATH) ::  file_name
     587
     588      CALL get_datetime_file_list( start_date_string, start_hour, end_hour,    &
     589                                   step_hour, input_path, prefix, suffix,      &
     590                                   file_list )
     591
     592      tip = "Please check if you specified the correct file prefix " //        &
     593            "using the options --input-prefix, --flow-prefix, etc."
     594
     595      DO i = 1, SIZE(file_list)
     596          CALL verify_file(file_list(i), 'input', tip)
     597      END DO
     598
     599   END SUBROUTINE get_input_file_list
     600
     601
     602!------------------------------------------------------------------------------!
     603! Description:
     604! ------------
     605!> Abort INIFOR if the given file is not present.
     606!------------------------------------------------------------------------------!
     607   SUBROUTINE verify_file(file_name, file_kind, tip)
     608
     609      CHARACTER(LEN=*), INTENT(IN)           ::  file_name, file_kind
     610      CHARACTER(LEN=*), INTENT(IN), OPTIONAL ::  tip
     611
     612      IF (.NOT. file_present(file_name))  THEN
     613
     614         IF (LEN(TRIM(file_name)) == 0)  THEN
     615
     616            message = "No name was given for the " // TRIM(file_kind) // " file."
     617
     618         ELSE
     619
     620            message = "The " // TRIM(file_kind) // " file '" //                &
     621                      TRIM(file_name) // "' was not found."
     622
     623            IF (PRESENT(tip))  THEN
     624               message = TRIM(message) // " " // TRIM(tip)
     625            END IF
     626
     627         END IF
     628
     629         CALL inifor_abort('verify_file', message)
     630
     631      END IF
     632
     633   END SUBROUTINE verify_file
     634
     635
    531636!------------------------------------------------------------------------------!
    532637! Description:
     
    552657   SUBROUTINE validate_config(cfg)
    553658      TYPE(inifor_config), INTENT(IN) ::  cfg
    554       LOGICAL                         ::  all_files_present
    555 
    556       all_files_present = .TRUE.
    557       all_files_present = all_files_present .AND. file_present(cfg % hhl_file, 'HHL')
    558       all_files_present = all_files_present .AND. file_present(cfg % namelist_file, 'NAMELIST')
    559       all_files_present = all_files_present .AND. file_present(cfg % soiltyp_file, 'SOILTYP')
     659
     660      CALL verify_file(cfg % hhl_file, 'HHL')
     661      CALL verify_file(cfg % namelist_file, 'NAMELIST')
     662      CALL verify_file(cfg % soiltyp_file, 'SOILTYP')
    560663
    561664!
    562665!--   Only check optional static driver file name, if it has been given.
    563666      IF (TRIM(cfg % static_driver_file) .NE. '')  THEN
    564          all_files_present = all_files_present .AND. file_present(cfg % static_driver_file, 'static driver')
     667         CALL verify_file(cfg % static_driver_file, 'static driver')
    565668      END IF
    566669
    567       IF (.NOT. all_files_present)  THEN
    568          message = "INIFOR configuration invalid; some input files are missing."
    569          CALL inifor_abort( 'validate_config', message )
    570       END IF
    571      
    572      
    573670      SELECT CASE( TRIM(cfg % ic_mode) )
    574671      CASE( 'profile', 'volume')
     
    619716!> Check whether the given file is present on the filesystem.
    620717!------------------------------------------------------------------------------!
    621    LOGICAL FUNCTION file_present(filename, kind)
     718   LOGICAL FUNCTION file_present(filename)
    622719      CHARACTER(LEN=PATH), INTENT(IN) ::  filename
    623       CHARACTER(LEN=*), INTENT(IN)    ::  kind
    624 
    625       IF (LEN(TRIM(filename))==0)  THEN
    626 
    627          file_present = .FALSE.
    628          message = "No name was given for the " // TRIM(kind) // " file."
    629          CALL report('file_present', message)
    630 
    631       ELSE
    632 
    633          INQUIRE(FILE=filename, EXIST=file_present)
    634 
    635          IF (.NOT. file_present)  THEN
    636             message = "The given " // TRIM(kind) // " file '" //               &
    637                       TRIM(filename) // "' does not exist."
    638             CALL report('file_present', message)
    639          END IF
    640 
    641       END IF
     720
     721      INQUIRE(FILE=filename, EXIST=file_present)
    642722
    643723   END FUNCTION file_present
Note: See TracChangeset for help on using the changeset viewer.