Index: palm/trunk/UTIL/inifor/src/inifor_io.f90
===================================================================
--- palm/trunk/UTIL/inifor/src/inifor_io.f90	(revision 3618)
+++ palm/trunk/UTIL/inifor/src/inifor_io.f90	(revision 3678)
@@ -26,4 +26,11 @@
 ! -----------------
 ! $Id$
+! Moved get_input_file_list() here from grid module, added check for presence of
+!    input files
+!
+! 
+! 
+! 
+! 3618 2018-12-10 13:25:22Z eckhard
 ! Prefixed all INIFOR modules with inifor_
 ! 
@@ -98,5 +105,5 @@
     USE inifor_types
     USE inifor_util,                                                           &
-        ONLY:  reverse, str, real_to_str
+        ONLY:  add_hours_to, reverse, str, real_to_str
     USE netcdf
 
@@ -529,4 +536,102 @@
 
    
+
+   SUBROUTINE get_datetime_file_list( start_date_string, start_hour, end_hour, &
+                                      step_hour, input_path, prefix, suffix,   &
+                                      file_list )
+
+      CHARACTER (LEN=DATE), INTENT(IN) ::  start_date_string
+      CHARACTER (LEN=*),    INTENT(IN) ::  prefix, suffix, input_path
+      INTEGER,              INTENT(IN) ::  start_hour, end_hour, step_hour
+      CHARACTER(LEN=*), ALLOCATABLE, INTENT(INOUT) ::  file_list(:)
+
+      INTEGER             ::  number_of_intervals, hour, i
+      CHARACTER(LEN=DATE) ::  date_string
+
+      number_of_intervals = CEILING( REAL(end_hour - start_hour) / step_hour )
+      ALLOCATE( file_list(number_of_intervals + 1) )
+
+      DO i = 0, number_of_intervals
+
+         hour = start_hour + i * step_hour
+         date_string = add_hours_to(start_date_string, hour)
+
+         file_list(i+1) = TRIM(input_path) // TRIM(prefix) //                  &
+                          TRIM(date_string) // TRIM(suffix) // '.nc'
+
+         message = "Set up input file name '" // TRIM(file_list(i+1)) // "'"
+         CALL report('input_file_list', message)
+
+      END DO
+
+   END SUBROUTINE get_datetime_file_list
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Establish a list of files based on the given start and end times and file
+!> prefixes and suffixes.
+!------------------------------------------------------------------------------!
+   SUBROUTINE get_input_file_list( start_date_string, start_hour, end_hour,    &
+                                   step_hour, input_path, prefix, suffix,      &
+                                   file_list )
+
+      CHARACTER (LEN=DATE), INTENT(IN) ::  start_date_string
+      CHARACTER (LEN=*),    INTENT(IN) ::  prefix, suffix, input_path
+      INTEGER,              INTENT(IN) ::  start_hour, end_hour, step_hour
+      CHARACTER(LEN=*), ALLOCATABLE, INTENT(INOUT) ::  file_list(:)
+
+      INTEGER             ::  number_of_intervals, hour, i
+      CHARACTER(LEN=DATE) ::  date_string
+      CHARACTER(LEN=PATH) ::  file_name
+
+      CALL get_datetime_file_list( start_date_string, start_hour, end_hour,    &
+                                   step_hour, input_path, prefix, suffix,      &
+                                   file_list )
+
+      tip = "Please check if you specified the correct file prefix " //        &
+            "using the options --input-prefix, --flow-prefix, etc."
+
+      DO i = 1, SIZE(file_list)
+          CALL verify_file(file_list(i), 'input', tip)
+      END DO
+
+   END SUBROUTINE get_input_file_list
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Abort INIFOR if the given file is not present.
+!------------------------------------------------------------------------------!
+   SUBROUTINE verify_file(file_name, file_kind, tip)
+
+      CHARACTER(LEN=*), INTENT(IN)           ::  file_name, file_kind
+      CHARACTER(LEN=*), INTENT(IN), OPTIONAL ::  tip
+
+      IF (.NOT. file_present(file_name))  THEN
+
+         IF (LEN(TRIM(file_name)) == 0)  THEN
+
+            message = "No name was given for the " // TRIM(file_kind) // " file."
+
+         ELSE
+
+            message = "The " // TRIM(file_kind) // " file '" //                &
+                      TRIM(file_name) // "' was not found."
+
+            IF (PRESENT(tip))  THEN
+               message = TRIM(message) // " " // TRIM(tip)
+            END IF
+
+         END IF
+
+         CALL inifor_abort('verify_file', message)
+
+      END IF
+
+   END SUBROUTINE verify_file
+
+
 !------------------------------------------------------------------------------!
 ! Description:
@@ -552,23 +657,15 @@
    SUBROUTINE validate_config(cfg)
       TYPE(inifor_config), INTENT(IN) ::  cfg
-      LOGICAL                         ::  all_files_present
-
-      all_files_present = .TRUE.
-      all_files_present = all_files_present .AND. file_present(cfg % hhl_file, 'HHL')
-      all_files_present = all_files_present .AND. file_present(cfg % namelist_file, 'NAMELIST')
-      all_files_present = all_files_present .AND. file_present(cfg % soiltyp_file, 'SOILTYP')
+
+      CALL verify_file(cfg % hhl_file, 'HHL')
+      CALL verify_file(cfg % namelist_file, 'NAMELIST')
+      CALL verify_file(cfg % soiltyp_file, 'SOILTYP')
 
 !
 !--   Only check optional static driver file name, if it has been given.
       IF (TRIM(cfg % static_driver_file) .NE. '')  THEN
-         all_files_present = all_files_present .AND. file_present(cfg % static_driver_file, 'static driver')
+         CALL verify_file(cfg % static_driver_file, 'static driver')
       END IF
 
-      IF (.NOT. all_files_present)  THEN
-         message = "INIFOR configuration invalid; some input files are missing."
-         CALL inifor_abort( 'validate_config', message )
-      END IF
-      
-      
       SELECT CASE( TRIM(cfg % ic_mode) )
       CASE( 'profile', 'volume')
@@ -619,25 +716,8 @@
 !> Check whether the given file is present on the filesystem.
 !------------------------------------------------------------------------------!
-   LOGICAL FUNCTION file_present(filename, kind)
+   LOGICAL FUNCTION file_present(filename)
       CHARACTER(LEN=PATH), INTENT(IN) ::  filename
-      CHARACTER(LEN=*), INTENT(IN)    ::  kind
-
-      IF (LEN(TRIM(filename))==0)  THEN
-
-         file_present = .FALSE.
-         message = "No name was given for the " // TRIM(kind) // " file."
-         CALL report('file_present', message)
-
-      ELSE
-
-         INQUIRE(FILE=filename, EXIST=file_present)
-
-         IF (.NOT. file_present)  THEN
-            message = "The given " // TRIM(kind) // " file '" //               &
-                      TRIM(filename) // "' does not exist."
-            CALL report('file_present', message)
-         END IF
-
-      END IF
+
+      INQUIRE(FILE=filename, EXIST=file_present)
 
    END FUNCTION file_present
