LCOV - code coverage report
Current view: | top level - hemco/HEMCO/src/Core - hco_tidx_mod.F90 (source / functions) |  |  | Hit | Total | Coverage
Test: | coverage.info |  | Lines: | 0 | 255 | 0.0 %
Date: | 2024-12-17 22:39:59 |  | Functions: | 0 | 8 | 0.0 %

              Line data    Source code
           1             : !------------------------------------------------------------------------------
           2             : !                   Harmonized Emissions Component (HEMCO)                    !
           3             : !------------------------------------------------------------------------------
           4             : !BOP
           5             : !
           6             : ! !MODULE: hco_tidx_mod.F90
           7             : !
           8             : ! !DESCRIPTION: Module HCO\_tIdx\_Mod contains routines and variables
           9             : ! to organize and index data array time slices.
          10             : !\\
          11             : !\\
          12             : ! The HEMCO data containers can hold multiple 2D or 3D data arrays
          13             : ! (aligned in a vector), providing a 4th dimension (time). During
          14             : ! emission calculation, only the vector element ('time slice')
          15             : ! representative for the given time will be used. Currently, the
          16             : ! following time slice intervals are supported:
          17             : !
          18             : ! \begin{itemize}
          19             : ! \item Constant: Only one time slice (default)
          20             : ! \item Hourly: Between 2-24 time slices. These slices will be split
          21             : !         into even day bins, and are cycled through accordingly.
          22             : !         the local time is used to obtain the current valid index at
          23             : !         each longitude.
          24             : ! \item Hourly\_gridded: As hourly, but uses the same time slice index
          25             : !         across all longitudes (based upon UTC time).
          26             : ! \item Weekdaily: Seven time slices, representing the days of the
          27             : !         week: Sun, Mon, ..., Sat. Uses local time.
          28             : ! \item Monthly: 12 time slices, representing the months of the year:
          29             : !         Jan, ..., Dec. Uses local time.
          30             : ! \end{itemize}
          31             : !
          32             : ! The time slice cycling frequency is automatically determined during
          33             : ! creation of a data container - based upon the time stamp settings in
          34             : ! the HEMCO configuration file and the time information read from the
          35             : ! data (netCDF) file.
          36             : !\\
          37             : !\\
          38             : ! Spatial uniform data (i.e. nx = ny = 1) is always assigned the local
          39             : ! time cycle intervals (hourly, weekdaily, or monthly), e.g. the local
          40             : ! time is used at every grid box when picking the time slice at a given
          41             : ! time. For gridded data, it's assumed that local-time effects are already
          42             : ! taken into account and UTC time is used at all locations to select the
          43             : ! currently valid time slice. The exception is weekdaily data, which is
          44             : ! always assumed to be in local time.
          45             : !\\
          46             : !\\
          47             : ! Structure AlltIDx organizes the indexing of the vector arrays. It
          48             : ! contains the current valid time slice index for each of the above
          49             : ! defined time slice intervals. Each data container points to one of the
          50             : ! elements of AlltIDx, according to the temporal dimension of its array.
          51             : ! The values of AlltIDx become update on every HEMCO time step.
          52             : !\\
          53             : !\\
          54             : !
          55             : ! !INTERFACE:
          56             : !
          57             : MODULE HCO_tIdx_Mod
          58             : !
          59             : ! !USES:
          60             : !
          61             :   USE HCO_Error_Mod
          62             :   USE HCO_Types_Mod,  ONLY : TimeIdx
          63             :   USE HCO_Types_Mod,  ONLY : TimeIdxCollection
          64             :
          65             :   IMPLICIT NONE
          66             :   PRIVATE
          67             : !
          68             : ! !PUBLIC MEMBER FUNCTIONS:
          69             : !
          70             :   PUBLIC :: tIDx_Assign
          71             :   PUBLIC :: tIDx_Init
          72             :   PUBLIC :: tIDx_GetIndx
          73             :   PUBLIC :: tIDx_Cleanup
          74             :   PUBLIC :: tIDx_IsInRange
          75             :   PUBLIC :: HCO_GetPrefTimeAttr
          76             :   PUBLIC :: HCO_ExtractTime
          77             : !
          78             : ! !REMARKS:
          79             : !  The current local time implementation assumes a regular grid,
          80             : !  i.e. local time does not change with latitude!
          81             : !
          82             : ! !REVISION HISTORY:
          83             : !  29 Dec 2012 - C. Keller   - Initialization
          84             : !  See https://github.com/geoschem/hemco for complete history
          85             : !EOP
          86             : !------------------------------------------------------------------------------
          87             : !BOC
          88             : !
          89             : ! !PRIVATE TYPES:
          90             : !
          91             : CONTAINS
          92             : !EOC
          93             : !------------------------------------------------------------------------------
          94             : !                   Harmonized Emissions Component (HEMCO)                    !
          95             : !------------------------------------------------------------------------------
          96             : !BOP
          97             : !
          98             : ! !ROUTINE: tIDx_Init
          99             : !
         100             : ! !DESCRIPTION: Subroutine tIDx\_Init initializes the time slice index
         101             : ! collection.
         102             : !\\
         103             : !\\
         104             : ! !INTERFACE:
         105             : !
         106           0 :   SUBROUTINE tIDx_Init( HcoState, RC )
         107             : !
         108             : ! !USES:
         109             : !
         110             :     USE HCO_State_Mod, ONLY : HCO_State
         111             : !
         112             : ! !INPUT/OUTPUT PARAMETERS:
         113             : !
         114             :     TYPE(HCO_State), POINTER        :: HcoState  ! Hemco state
         115             :     INTEGER,         INTENT(INOUT)  :: RC        ! Return code
         116             : !
         117             : ! !REVISION HISTORY:
         118             : !  29 Dec 2012 - C. Keller - Initialization
         119             : !  See https://github.com/geoschem/hemco for complete history
         120             : !EOP
         121             : !------------------------------------------------------------------------------
         122             : !BOC
         123             : !
         124             : ! !LOCAL VARIABLES:
         125             : !
         126             :     CHARACTER(LEN=255)  :: LOC
         127             :
         128             :     !======================================================================
         129             :     ! tIDx_Init begins here!
         130             :     !======================================================================
         131           0 :     LOC = 'tIDx_Init (HCO_TIDX_MOD.F90)'
         132             :
         133             :     ! Enter
         134           0 :     CALL HCO_ENTER ( HcoState%Config%Err, LOC, RC )
         135           0 :     IF ( RC /= HCO_SUCCESS ) THEN
         136           0 :         CALL HCO_ERROR( 'ERROR 0', RC, THISLOC=LOC )
         137           0 :         RETURN
         138             :     ENDIF
         139             :
         140             :     ! Allocate collection of time indeces
         141           0 :     ALLOCATE ( HcoState%AlltIDx )
         142             :
         143             :     ! Initialize the vectors holding the currently valid time slice
         144             :     ! indices for the various cycle intervals. Only create longitude-
         145             :     ! dependent time slice vector if cycle interval changes with
         146             :     ! longitude, i.e. if it is time-zone dependent.
         147             :
         148             :     ! ----------------------------------------------------------------
         149             :     ! "CONSTANT" => only one time slice, no cycling.
         150             :     ! ----------------------------------------------------------------
         151           0 :     ALLOCATE ( HcoState%AlltIDx%CONSTANT )
         152           0 :     HcoState%AlltIDx%CONSTANT%TypeID       = 0
         153           0 :     HcoState%AlltIDx%CONSTANT%TempRes      = "Constant"
         154             :
         155             :     ! ----------------------------------------------------------------
         156             :     ! "HOURLY" => changes every hour, longitude-dependent
         157             :     ! ----------------------------------------------------------------
         158           0 :     ALLOCATE ( HcoState%AlltIDx%HOURLY )
         159           0 :     HcoState%AlltIDx%HOURLY%TypeID       = 24
         160           0 :     HcoState%AlltIDx%HOURLY%TempRes      = "Hourly"
         161             :
         162             :     ! ----------------------------------------------------------------
         163             :     ! "HOURLY_GRID" => changes every hour, longitude-independent
         164             :     ! ----------------------------------------------------------------
         165           0 :     ALLOCATE ( HcoState%AlltIDx%HOURLY_GRID )
         166           0 :     HcoState%AlltIDx%HOURLY_GRID%TypeID       = 241
         167           0 :     HcoState%AlltIDx%HOURLY_GRID%TempRes      = "Hourly_Grid"
         168             :
         169             :     ! ----------------------------------------------------------------
         170             :     ! "WEEKDAY" => changes every weekday, longitude-dependent
         171             :     ! ----------------------------------------------------------------
         172           0 :     ALLOCATE ( HcoState%AlltIDx%WEEKDAY )
         173           0 :     HcoState%AlltIDx%WEEKDAY%TypeID       = 7
         174           0 :     HcoState%AlltIDx%WEEKDAY%TempRes      = "Weekday"
         175             :
         176             :     ! ----------------------------------------------------------------
         177             :     ! "MONTHLY" => changes every month, longitude-dependent
         178             :     ! ----------------------------------------------------------------
         179           0 :     ALLOCATE ( HcoState%AlltIDx%MONTHLY )
         180           0 :     HcoState%AlltIDx%MONTHLY%TypeID       = 12
         181           0 :     HcoState%AlltIDx%MONTHLY%TempRes      = "Monthly"
         182             :
         183             :     ! Return w/ success
         184           0 :     CALL HCO_LEAVE ( HcoState%Config%Err, RC )
         185             :
         186             :   END SUBROUTINE tIDx_Init
         187             : !EOC
         188             : !------------------------------------------------------------------------------
         189             : !                   Harmonized Emissions Component (HEMCO)                    !
         190             : !------------------------------------------------------------------------------
         191             : !BOP
         192             : !
         193             : ! !ROUTINE: tIDx_Set
         194             : !
         195             : ! !DESCRIPTION: Subroutine tIDx\_Set linkes the passed TimeIDx type to the
         196             : ! corresponding element in the TimeIdx collection, according to the given
         197             : ! TypeID. TypeID can be one of the following:
         198             : !
         199             : ! \begin{itemize}
         200             : ! \item 1:   Constant
         201             : ! \item 24:  Hourly
         202             : ! \item 241: Hourly\_Grid
         203             : ! \item 7:   Weekday
         204             : ! \item 71:  Weekday\_Grid
         205             : ! \item 12:  Monthly
         206             : ! \end{itemize}
         207             : !
         208             : ! !INTERFACE:
         209             : !
         210           0 :   SUBROUTINE tIDx_Set( HcoState, ctIDx, TypeID )
         211             : !
         212             : ! !USES:
         213             : !
         214             :     USE HCO_State_Mod, ONLY : HCO_State
         215             : !
         216             : ! !INPUT PARAMETERS:
         217             : !
         218             :     TYPE(HCO_State), POINTER     :: HcoState ! HEMCO state
         219             :     TYPE(TimeIdx),   POINTER     :: ctIDx   ! container TimeIDx
         220             :     INTEGER,         INTENT(IN)  :: TypeID  ! type ID
         221             : !
         222             : ! !REVISION HISTORY:
         223             : !  29 Dec 2012 - C. Keller - Initialization
         224             : !  See https://github.com/geoschem/hemco for complete history
         225             : !EOP
         226             : !------------------------------------------------------------------------------
         227             : !BOC
         228             :
         229             :     !======================================================================
         230             :     ! tIDx_Set begins here!
         231             :     !======================================================================
         232             :
         233             :     ! Set pointer according to TempRes
         234           0 :     SELECT CASE ( TypeID )
         235             :
         236             :        CASE ( 1 )
         237           0 :           ctIDx => HcoState%AlltIDx%CONSTANT
         238             :
         239             :        CASE ( 24 )
         240           0 :           ctIDx => HcoState%AlltIDx%HOURLY
         241             :
         242             :        CASE ( 241 )
         243           0 :           ctIDx => HcoState%AlltIDx%HOURLY_GRID
         244             :
         245             :        CASE ( 7 )
         246           0 :           ctIDx => HcoState%AlltIDx%WEEKDAY
         247             :
         248             :        CASE ( 12 )
         249           0 :           ctIDx => HcoState%AlltIDx%MONTHLY
         250             :
         251             :        CASE DEFAULT
         252           0 :           ctIDx => HcoState%AlltIDx%CONSTANT
         253             :
         254             :     END SELECT
         255             :
         256           0 :   END SUBROUTINE tIDx_Set
         257             : !EOC
         258             : !------------------------------------------------------------------------------
         259             : !                   Harmonized Emissions Component (HEMCO)                    !
         260             : !------------------------------------------------------------------------------
         261             : !BOP
         262             : !
         263             : ! !ROUTINE: tIDx_Cleanup
         264             : !
         265             : ! !DESCRIPTION: Subroutine tIDx\_Cleanup deallocates the time slice
         266             : ! index collection.
         267             : !\\
         268             : !\\
         269             : ! !INTERFACE:
         270             : !
         271           0 :   SUBROUTINE tIDx_Cleanup( AlltIDx )
         272             : !
         273             : ! !Input/output arguments:
         274             : !
         275             :      TYPE(TimeIdxCollection), POINTER :: AlltIDx
         276             : !
         277             : ! !REVISION HISTORY:
         278             : !  29 Dec 2012 - C. Keller - Initialization
         279             : !  See https://github.com/geoschem/hemco for complete history
         280             : !EOP
         281             : !------------------------------------------------------------------------------
         282             : !BOC
         283             :
         284             :     !======================================================================
         285             :     ! tIDx_Cleanup begins here!
         286             :     !======================================================================
         287             :
         288           0 :     IF ( ASSOCIATED( AlltIDx ) ) THEN
         289             :
         290           0 :        IF ( ASSOCIATED(AlltIDx%CONSTANT) ) THEN
         291           0 :           DEALLOCATE(AlltIDx%CONSTANT)
         292             :        ENDIF
         293             :
         294           0 :        IF ( ASSOCIATED(AlltIDx%HOURLY) ) THEN
         295           0 :           DEALLOCATE(AlltIDx%HOURLY)
         296             :        ENDIF
         297             :
         298           0 :        IF ( ASSOCIATED(AlltIDx%HOURLY_GRID) ) THEN
         299           0 :           DEALLOCATE(AlltIDx%HOURLY_GRID)
         300             :        ENDIF
         301             :
         302           0 :        IF ( ASSOCIATED(AlltIDx%WEEKDAY) ) THEN
         303           0 :           DEALLOCATE(AlltIDx%WEEKDAY)
         304             :        ENDIF
         305             :
         306           0 :        IF ( ASSOCIATED(AlltIDx%MONTHLY) ) THEN
         307           0 :           DEALLOCATE(AlltIDx%MONTHLY)
         308             :        ENDIF
         309             :
         310             :        ! Also deallocate AlltIDx pointer
         311           0 :        DEALLOCATE( AlltIDx )
         312             :     ENDIF
         313           0 :     AlltIDx => NULL()
         314             :
         315           0 :   END SUBROUTINE tIDx_Cleanup
         316             : !EOC
         317             : !------------------------------------------------------------------------------
         318             : !                   Harmonized Emissions Component (HEMCO)                    !
         319             : !------------------------------------------------------------------------------
         320             : !BOP
         321             : !
         322             : ! !ROUTINE: tIDx_GetIndx
         323             : !
         324             : ! !DESCRIPTION: Subroutine tIDx\_GetIndx calculates the current valid
         325             : ! index values for the given file data time slice type and longitude
         326             : ! location
         327             : !\\
         328             : ! !INTERFACE:
         329             : !
         330           0 :   FUNCTION tIDx_GetIndx ( HcoState, Dta, I, J ) RESULT ( Indx )
         331             : !
         332             : ! !USES:
         333             : !
         334             :     USE HCO_State_Mod,    ONLY : HCO_State
         335             :     USE HCO_Types_Mod,    ONLY : FileData
         336             :     USE HCO_CLOCK_MOD,    ONLY : HcoClock_Get, HcoClock_GetLocal
         337             : !
         338             : ! !INPUT PARAMETERS:
         339             : !
         340             :     TYPE(HCO_State), POINTER    :: HcoState  ! Hemco state
         341             :     TYPE(FileData),  POINTER    :: Dta       ! File data object
         342             :     INTEGER,         INTENT(IN) :: I         ! Longitude index of interest
         343             :     INTEGER,         INTENT(IN) :: J         ! Latitude  index of interest
         344             : !
         345             : ! !INPUT/OUTPUT PARAMETERS:
         346             : !
         347             :     INTEGER                     :: Indx      ! Index
         348             : !
         349             : ! !REVISION HISTORY:
         350             : !  02 Dec 2014 - C. Keller - Initial version
         351             : !  See https://github.com/geoschem/hemco for complete history
         352             : !EOP
         353             : !------------------------------------------------------------------------------
         354             : !BOC
         355             : !
         356             : ! !LOCAL VARIABLES:
         357             : !
         358             :     INTEGER             :: HH, WD, MM, RC
         359             :     REAL(hp)            :: LonHH
         360             :     REAL(dp)            :: frac
         361             :     CHARACTER(LEN=255)  :: LOC
         362             :
         363             :     !======================================================================
         364             :     ! tIDx_GetIndx begins here!
         365             :     !======================================================================
         366           0 :     LOC = 'tIDx_GetIndx (HCO_TIDX_MOD.F90)'
         367             :
         368             :     ! Default value (=> This will cause the code to crash!)
         369           0 :     Indx = -1
         370             :
         371             :     ! ----------------------------------------------------------------
         372             :     ! Calculate time slice index for the given time slice type
         373             :     ! ----------------------------------------------------------------
         374           0 :     SELECT CASE ( Dta%tIDx%TypeID )
         375             :
         376             :        ! Constant: there is only one time slice
         377             :        CASE ( 1 )
         378           0 :           Indx = 1
         379             :
         380             :        ! Hourly data (local time)
         381             :        ! Indx returns the time slice representative for the LOCAL time
         382             :        ! at longitude Lon.
         383             :        CASE ( 24 )
         384           0 :           CALL HcoClock_GetLocal( HcoState, I, J, cH=LonHH, RC=RC )
         385           0 :           IF ( RC /= HCO_SUCCESS ) THEN
         386           0 :               CALL HCO_ERROR( 'ERROR 1', RC, THISLOC=LOC )
         387           0 :               RETURN
         388             :           ENDIF
         389           0 :           Indx = FLOOR(LonHH) + 1
         390             :
         391             :        ! Hourly data (already gridded)
         392             :        ! Gridded hourly data is assumed to be already adjusted for
         393             :        ! local time effects, hence just point to the time slice
         394             :        ! of current UTC time. Add one since hour starts at 0.
         395             :        CASE ( 241 )
         396           0 :           CALL HcoClock_Get( HcoState%Clock, cH=HH, RC=RC )
         397           0 :           IF ( RC /= HCO_SUCCESS ) THEN
         398           0 :               CALL HCO_ERROR( 'ERROR 2', RC, THISLOC=LOC )
         399           0 :               RETURN
         400             :           ENDIF
         401           0 :           Indx = HH + 1
         402             :
         403             :        ! Weekday data (local time)
         404             :        ! Indx returns the time slice representative for the LOCAL
         405             :        ! weekday at longitude Lon.
         406             :        CASE ( 7 )
         407             :
         408           0 :           CALL HcoClock_GetLocal( HcoState, I, J, cWeekday=WD, RC=RC )
         409           0 :           IF ( RC /= HCO_SUCCESS ) THEN
         410           0 :               CALL HCO_ERROR( 'ERROR 3', RC, THISLOC=LOC )
         411           0 :               RETURN
         412             :           ENDIF
         413           0 :           Indx = WD + 1
         414             :
         415             :        ! Monthly data (local time)
         416             :        ! Monthly data is always in local time.
         417             :        ! For gridded monthly data, only the current valid time slice
         418             :        ! is kept in memory (and updated whenever a new month is entered).
         419             :        CASE ( 12 )
         420           0 :           CALL HcoClock_GetLocal( HcoState, I, J, cMM = MM, RC=RC )
         421           0 :           IF ( RC /= HCO_SUCCESS ) THEN
         422           0 :               CALL HCO_ERROR( 'ERROR 4', RC, THISLOC=LOC )
         423           0 :               RETURN
         424             :           ENDIF
         425           0 :           Indx = MM
         426             :
         427             :        ! Default: assume it's constant
         428             :        CASE DEFAULT
         429           0 :           Indx = 1
         430             :
         431             :     END SELECT
         432             :
         433             :     ! For hourly data with less than 24 time slices, i.e. time
         434             :     ! intervals of more than 1 hour, map 24 hour index onto the
         435             :     ! reduced time slice.
         436             :     ! For example, for 3-hourly data (8 vector elements), this will
         437             :     ! return index 1 for hours 0-2am, index 2 for 3-5am, etc.
         438             :     ! Dta%DeltaT denotes the time difference between between two time
         439             :     ! slices (in hours).
         440           0 :     IF ( Dta%DeltaT > 1 .AND. Dta%DeltaT < 24 ) THEN
         441           0 :        frac = DBLE(Indx) / DBLE(Dta%DeltaT)
         442           0 :        Indx = CEILING( frac )
         443             :     ENDIF
         444             :
         445             :     ! Sanity check: index must not exceed time dimension
         446           0 :     IF ( Indx > Dta%nt ) THEN
         447           0 :        WRITE(*,*) 'Indx exceeds # of time slices! ', Indx, Dta%nt, TRIM(Dta%ncFile)
         448           0 :        Indx = -1
         449             :     ENDIF
         450             :
         451           0 :   END FUNCTION tIDx_GetIndx
         452             : !EOC
         453             : !------------------------------------------------------------------------------
         454             : !                   Harmonized Emissions Component (HEMCO)                    !
         455             : !------------------------------------------------------------------------------
         456             : !BOP
         457             : !
         458             : ! !IROUTINE: tIDx_Assign
         459             : !
         460             : ! !DESCRIPTION: Subroutine tIDx\_Assign assigns the time index
         461             : ! pointer of the file data object of the passed list container
         462             : ! to the corresponding time index element of the time index
         463             : ! collection. The time slice cycle interval is determined from
         464             : ! the number of time slices (length of the data array vector) and
         465             : ! the time difference (deltaT) between them.
         466             : !\\
         467             : !\\
         468             : ! Note: Scale factors read directly from the HEMCO configuration file
         469             : ! become their delta T assigned upon reading from file (see
         470             : ! subroutine Register\_Scal in hco\_config\_mod.F90).
         471             : !\\
         472             : !\\
         473             : ! !INTERFACE:
         474             : !
         475           0 :   SUBROUTINE tIDx_Assign( HcoState, Dct, RC )
         476             : !
         477             : ! !USES:
         478             : !
         479             :     USE HCO_State_Mod,    ONLY : HCO_State
         480             :     USE HCO_Types_Mod,    ONLY : DataCont
         481             : !
         482             : ! !INPUT PARAMETERS:
         483             : !
         484             :     TYPE(HCO_State), POINTER       :: HcoState  ! Hemco state
         485             :     TYPE(DataCont),  POINTER       :: Dct       ! Data container
         486             : !
         487             : ! !INPUT/OUTPUT PARAMETERS:
         488             : !
         489             :     INTEGER,         INTENT(INOUT) :: RC        ! Success or failure?
         490             : !
         491             : ! !REVISION HISTORY:
         492             : !  13 Jan 2014 - C. Keller - Initial version
         493             : !  See https://github.com/geoschem/hemco for complete history
         494             : !EOP
         495             : !------------------------------------------------------------------------------
         496             : !BOC
         497             : !
         498             : ! !LOCAL VARIABLES:
         499             : !
         500             :     INTEGER            :: nx, ny, nt, ntexp, dt
         501             :     INTEGER            :: cTypeID
         502             :     CHARACTER(LEN=255) :: MSG, LOC
         503             :
         504             :     !-----------------------------------
         505             :     ! tIDx_Assign begins here!
         506             :     !-----------------------------------
         507           0 :     LOC = 'tIDx_Assign (HCO_TIDX_MOD.F90)'
         508             :
         509             :     ! Enter
         510           0 :     CALL HCO_ENTER( HcoState%Config%Err, LOC, RC )
         511           0 :     IF ( RC /= HCO_SUCCESS ) THEN
         512           0 :         CALL HCO_ERROR( 'ERROR 5', RC, THISLOC=LOC )
         513           0 :         RETURN
         514             :     ENDIF
         515             :
         516             :     ! Check if already done
         517           0 :     IF ( ASSOCIATED( Dct%Dta%tIDx ) ) THEN
         518           0 :        CALL HCO_LEAVE( HcoState%Config%Err, RC )
         519           0 :        RETURN
         520             :     ENDIF
         521             :
         522             :     ! Get array dimensions
         523           0 :     nt = Dct%Dta%nt
         524             :
         525             :     ! Do the following only for defined data arrays
         526           0 :     IF ( nt > 0 ) THEN
         527             :
         528             :        ! -------------------------------------------------------------
         529             :        ! Extract data array dimensions and delta t [h] between time
         530             :        ! slices
         531             :        ! -------------------------------------------------------------
         532           0 :        dt = Dct%Dta%DeltaT
         533           0 :        IF ( Dct%Dta%SpaceDim <= 2 ) THEN
         534           0 :           nx = SIZE(Dct%Dta%V2(1)%Val,1)
         535           0 :           ny = SIZE(Dct%Dta%V2(1)%Val,2)
         536             :        ELSE
         537           0 :           nx = SIZE(Dct%Dta%V3(1)%Val,1)
         538           0 :           ny = SIZE(Dct%Dta%V3(1)%Val,2)
         539             :        ENDIF
         540             :
         541             :        ! -------------------------------------------------------------
         542             :        ! Auto detection of temporal resolution.
         543             :        ! -------------------------------------------------------------
         544             :
         545             :        ! No time variation
         546           0 :        IF ( nt == 1 ) THEN
         547           0 :           cTypeID = 1
         548             :
         549             :        ! -------------------------------------------------------------
         550             :        ! Daily varying data.
         551             :        ! For now, these arrays must contain seven time slices, i.e.
         552             :        ! one for every weekday (starting w/ sunday!).
         553             :        ! -------------------------------------------------------------
         554           0 :        ELSEIF ( nt == 7 ) THEN
         555             :
         556             :           ! Sanity check if dt = 24 hours
         557           0 :           IF ( dt /= 24 ) THEN
         558             :              MSG = '7 time slices but delta t is not 24 hours!' // &
         559           0 :                   TRIM(Dct%cName)
         560           0 :              CALL HCO_ERROR( MSG, RC )
         561           0 :              RETURN
         562             :           ENDIF
         563             :
         564             :           ! Check if data is in local time or not, set TempRes attribute
         565             :           ! accordingly. Data will only be in local time if data is
         566             :           ! spatially uniform or country-specific data. The IsLocTime
         567             :           ! flag is set in hco_config_mod.F90 (for data read from other
         568             :           ! sources than netCDF) or in hcoio_dataread_mod.F90 (for
         569             :           ! weekdaily data read from netCDF).
         570           0 :           IF ( .NOT. Dct%Dta%IsLocTime ) THEN
         571             :              MSG = 'Weekday data must be in local time!' // &
         572           0 :                   TRIM(Dct%cName)
         573           0 :              CALL HCO_ERROR( MSG, RC )
         574           0 :              RETURN
         575             :
         576             :           ELSE
         577           0 :              cTypeID = 7
         578             : !             cTypeID = 71
         579             :           ENDIF
         580             :
         581             :        ! -------------------------------------------------------------
         582             :        ! Monthly varying data
         583             :        ! This must be a scalar. Gridded monthly data should be read
         584             :        ! slice by slice!
         585             :        ! -------------------------------------------------------------
         586           0 :        ELSEIF ( nt == 12 .AND. dt /= 2 ) THEN
         587           0 :           IF ( nx == 1 .AND. ny == 1 ) THEN
         588           0 :              cTypeID = 12
         589             :           ELSE
         590             :              MSG = 'Monthly data must not be gridded:' // &
         591           0 :                   TRIM(Dct%cName)
         592           0 :              CALL HCO_ERROR( MSG, RC )
         593           0 :              RETURN
         594             :           ENDIF
         595             :
         596             :        ! -------------------------------------------------------------
         597             :        ! Hourly varying data.
         598             :        ! Hourly time slices can represent more than just one hour,
         599             :        ! e.g. an array can hold only 8 time slices, each representing
         600             :        ! 3-hourly intervals of the day. The only constraint is that
         601             :        ! the number of time slices have to be a factor of 24!
         602             :        ! -------------------------------------------------------------
         603           0 :        ELSEIF ( dt < 24 .AND. dt > 0 ) THEN
         604             :
         605             :           ! Check if we can evenly split up data within a day
         606           0 :           IF ( MOD(24,dt) /= 0 ) THEN
         607             :              MSG = 'Cannot properly split up hourly data!' // &
         608           0 :                   TRIM(Dct%cName)
         609           0 :              CALL HCO_ERROR( MSG, RC )
         610           0 :              RETURN
         611             :           ENDIF
         612             :
         613             :           ! Also check if nt is indeed of expected size
         614           0 :           ntexp = 24/dt
         615           0 :           IF ( ntexp /= nt ) THEN
         616             :              MSG = 'Wrong delta t and/or number of time slices!' // &
         617           0 :                   TRIM(Dct%cName)
         618           0 :              CALL HCO_ERROR( MSG, RC )
         619           0 :              RETURN
         620             :           ENDIF
         621             :
         622             :           ! Check if data is in local time or not, set TempRes attribute
         623             :           ! accordingly. Data will only be in local time if data is
         624             :           ! read from other sources than netCDF. The corresponding
         625             :           ! IsLocTime flag is set in hco_config_mod.F90.
         626           0 :           IF ( Dct%Dta%IsLocTime ) THEN
         627           0 :              cTypeID = 24
         628             :           ELSE
         629           0 :              cTypeID = 241
         630             :           ENDIF
         631             :
         632             :        ! -------------------------------------------------------------
         633             :        ! Return w/ error otherwise
         634             :        ! -------------------------------------------------------------
         635             :        ELSE
         636             :           MSG = 'Invalid time slice for field ' // &
         637           0 :                TRIM(Dct%cName)
         638           0 :           CALL HCO_ERROR( MSG, RC )
         639           0 :           RETURN
         640             :        ENDIF
         641             :
         642             :        ! -------------------------------------------------------------
         643             :        ! Establish the appropriate pointer for the
         644             :        ! 4th dimension (temporal resolution) of the field array
         645             :        ! -------------------------------------------------------------
         646           0 :        CALL tIDx_Set( HcoState, Dct%Dta%tIDx, cTypeID )
         647             :
         648             :     ENDIF
         649             :
         650             :     ! Leave w/ success
         651           0 :     CALL HCO_LEAVE( HcoState%Config%Err, RC )
         652             :
         653             :   END SUBROUTINE tIDx_Assign
         654             : !EOC
         655             : !------------------------------------------------------------------------------
         656             : !                   Harmonized Emissions Component (HEMCO)                    !
         657             : !------------------------------------------------------------------------------
         658             : !BOP
         659             : !
         660             : ! !ROUTINE: tIDx_IsInRange
         661             : !
         662             : ! !DESCRIPTION: Subroutine tIDx\_IsInRange returns true if the passed datetime
         663             : ! is within the range of the date ranges of the data container.
         664             : !\\
         665             : ! !INTERFACE:
         666             : !
         667           0 :   FUNCTION tIDx_IsInRange ( Lct, Yr, Mt, Dy, Hr ) RESULT ( InRange )
         668             : !
         669             : ! !USES:
         670             : !
         671             :     USE HCO_TYPES_MOD,    ONLY : ListCont
         672             : !
         673             : ! !INPUT PARAMETERS:
         674             : !
         675             :     TYPE(ListCont),  POINTER    :: Lct       ! File data object
         676             :     INTEGER,         INTENT(IN) :: Yr
         677             :     INTEGER,         INTENT(IN) :: Mt
         678             :     INTEGER,         INTENT(IN) :: Dy
         679             :     INTEGER,         INTENT(IN) :: Hr
         680             : !
         681             : ! !INPUT/OUTPUT PARAMETERS:
         682             : !
         683             :     LOGICAL                     :: InRange
         684             : !
         685             : ! !REVISION HISTORY:
         686             : !  04 Mar 2015 - C. Keller - Initial version
         687             : !  See https://github.com/geoschem/hemco for complete history
         688             : !EOP
         689             : !------------------------------------------------------------------------------
         690             : !BOC
         691             : !
         692             : ! !LOCAL VARIABLES:
         693             : !
         694             :     ! Init
         695           0 :     InRange = .TRUE.
         696             :
         697           0 :     IF ( Lct%Dct%Dta%ncYrs(1) /= Lct%Dct%Dta%ncYrs(2) ) THEN
         698           0 :        IF ( Yr < Lct%Dct%Dta%ncYrs(1) .OR. &
         699             :             Yr > Lct%Dct%Dta%ncYrs(2)       ) THEN
         700           0 :           InRange = .FALSE.
         701             :        ENDIF
         702             :     ENDIF
         703             :
         704           0 :     IF ( Lct%Dct%Dta%ncMts(1) /= Lct%Dct%Dta%ncMts(2) ) THEN
         705           0 :        IF ( Mt < Lct%Dct%Dta%ncMts(1) .OR. &
         706             :             Mt > Lct%Dct%Dta%ncMts(2)       ) THEN
         707           0 :           InRange = .FALSE.
         708             :        ENDIF
         709             :     ENDIF
         710             :
         711           0 :     IF ( Lct%Dct%Dta%ncDys(1) /= Lct%Dct%Dta%ncDys(2) ) THEN
         712           0 :        IF ( Dy < Lct%Dct%Dta%ncDys(1) .OR. &
         713             :             Dy > Lct%Dct%Dta%ncDys(2)       ) THEN
         714           0 :           InRange = .FALSE.
         715             :        ENDIF
         716             :     ENDIF
         717             :
         718           0 :     IF ( Lct%Dct%Dta%ncHrs(1) /= Lct%Dct%Dta%ncHrs(2) ) THEN
         719           0 :        IF ( Hr < Lct%Dct%Dta%ncHrs(1) .OR. &
         720             :             Hr > Lct%Dct%Dta%ncHrs(2)       ) THEN
         721           0 :           InRange = .FALSE.
         722             :        ENDIF
         723             :     ENDIF
         724             :
         725           0 :   END FUNCTION tIDx_IsInRange
         726             : !EOC
         727             : !------------------------------------------------------------------------------
         728             : !                   Harmonized Emissions Component (HEMCO)                    !
         729             : !------------------------------------------------------------------------------
         730             : !BOP
         731             : !
         732             : ! !IROUTINE: HCO_GetPrefTimeAttr
         733             : !
         734             : ! !DESCRIPTION: Subroutine HCO\_GetPrefTimeAttr returns the preferred time
         735             : ! reading attributes for a given field, based upon the specs set in the HEMCO
         736             : ! configuration file and the current simulation date. This routine is used
         737             : ! to select the proper time slice to be read at the given time.
         738             : !\\
         739             : !\\
         740             : ! The time reading attributes are set to the value that is closest (or equal)
         741             : ! to the current datetime but within the range provided in the configuration
         742             : ! file. If the year, month, or day is not specified, the current simulation
         743             : ! date values are taken. For unspecified hours, a value of -1 is returned
         744             : ! (this allows to read all hourly slices at once).
         745             : !\\
         746             : !\\
         747             : ! !INTERFACE:
         748             : !
         749           0 :   SUBROUTINE HCO_GetPrefTimeAttr( HcoState, Lct,            &
         750             :                                   readYr,   readMt, readDy, &
         751             :                                   readHr,   readMn, RC       )
         752             : !
         753             : ! !USES:
         754             : !
         755             :     USE HCO_STATE_MOD,     ONLY : HCO_State
         756             :     USE HCO_TYPES_MOD,     ONLY : ListCont
         757             :     USE HCO_TYPES_MOD,     ONLY : HCO_CFLAG_RANGE, HCO_CFLAG_EXACT
         758             :     USE HCO_CLOCK_MOD,     ONLY : HcoClock_Get
         759             :     USE HCO_TIMESHIFT_MOD, ONLY : TimeShift_Apply
         760             : !
         761             : ! !INPUT PARAMETERS:
         762             : !
         763             :     TYPE(HCO_State), POINTER       :: HcoState  ! List container
         764             :     TYPE(ListCont),  POINTER       :: Lct       ! List container
         765             : !
         766             : ! !OUTPUT PARAMETERS:
         767             : !
         768             :     INTEGER,         INTENT(  OUT) :: readYr    ! preferred year
         769             :     INTEGER,         INTENT(  OUT) :: readMt    ! preferred month
         770             :     INTEGER,         INTENT(  OUT) :: readDy    ! preferred day
         771             :     INTEGER,         INTENT(  OUT) :: readHr    ! preferred hour
         772             :     INTEGER,         INTENT(  OUT) :: readMn    ! preferred minute
         773             : !
         774             : ! !INPUT/OUTPUT PARAMETERS:
         775             : !
         776             :     INTEGER,         INTENT(INOUT) :: RC        ! Success or failure?
         777             : !
         778             : ! !REVISION HISTORY:
         779             : !  13 Jan 2014 - C. Keller - Initial version
         780             : !  See https://github.com/geoschem/hemco for complete history
         781             : !EOP
         782             : !------------------------------------------------------------------------------
         783             : !BOC
         784             : !
         785             : ! !LOCAL VARIABLES:
         786             : !
         787             :     INTEGER             :: cYr, cMt, cDy, cWd, cHr, cMn, sYr
         788             :     LOGICAL             :: InRange
         789             :     CHARACTER(LEN=255)  :: LOC
         790             :
         791             :     !-----------------------------------
         792             :     ! HCO_GetPrefTimeAttr begins here!
         793             :     !-----------------------------------
         794           0 :     LOC = 'HCO_GetPrefTimeAttr (HCO_TIDX_MOD.F90)'
         795             :
         796             :     ! Init
         797           0 :     RC = HCO_SUCCESS
         798             :
         799             :     ! Get current time
         800             :     CALL HcoClock_Get( HcoState%Clock,                              &
         801             :                        cYYYY    = cYr, cMM = cMt, cDD = cDy,        &
         802             :                        cWEEKDAY = cWd, cH  = cHr, cM  = cMn,        &
         803           0 :                        sYYYY    = sYr, RC = RC )
         804           0 :     IF ( RC /= HCO_SUCCESS ) THEN
         805           0 :         CALL HCO_ERROR( 'ERROR 6', RC, THISLOC=LOC )
         806           0 :         RETURN
         807             :     ENDIF
         808             :
         809             :     ! Always use simulation year when specified
         810           0 :     IF ( Lct%Dct%Dta%UseSimYear ) cYr = sYr
         811             :
         812             :     ! preferred minute is always current one
         813           0 :     readMn = cMn
         814             :
         815             :     ! If data is in weekdays, set day to weekday: 1=Sun, ..., 7=Sat
         816           0 :     IF ( Lct%Dct%Dta%ncDys(1) == 1 .AND. &
         817             :          Lct%Dct%Dta%ncDys(2) == 7        ) THEN
         818           0 :        cDy = cWd + 1
         819             :     ENDIF
         820             :
         821             :     ! -------------------------------------------------------------
         822             :     ! If CycleFlag is set to range, the preferred datetime is
         823             :     ! the current date if we are within the provided range, and
         824             :     ! invalid otherwise.
         825             :     ! -------------------------------------------------------------
         826           0 :     IF ( Lct%Dct%Dta%CycleFlag == HCO_CFLAG_RANGE ) THEN
         827             :
         828             :        ! Are we in range?
         829           0 :        InRange = tIDx_IsInRange ( Lct, cYr, cMt, cDy, cHr )
         830             :
         831           0 :        IF ( InRange ) THEN
         832           0 :           readYr = cYr
         833           0 :           readMt = cMt
         834           0 :           readDy = cDy
         835           0 :           IF ( Lct%Dct%Dta%ncHrs(1) == -1 ) THEN
         836           0 :              readHr = -1
         837             :           ELSE
         838           0 :              readHr = cHr
         839             :           ENDIF
         840             :        ELSE
         841           0 :           readYr = -1
         842           0 :           readMt = -1
         843           0 :           readDy = -1
         844           0 :           readHr = -1
         845             :        ENDIF
         846             :
         847             :        ! Eventually shift reference time by amount specified
         848             :        ! in HEMCO configuration file
         849             :        CALL TimeShift_Apply ( HcoState, Lct, &
         850           0 :                               readYr, readMt, readDy, readHr, readMn, RC )
         851             :
         852             :        ! Don't need below
         853           0 :        RETURN
         854             :     ENDIF
         855             :
         856             :     ! -------------------------------------------------------------
         857             :     ! If CycleFlag is set to exact, the preferred datetime is
         858             :     ! always the current date.
         859             :     ! -------------------------------------------------------------
         860           0 :     IF ( Lct%Dct%Dta%CycleFlag == HCO_CFLAG_EXACT ) THEN
         861           0 :        readYr = cYr
         862           0 :        readMt = cMt
         863           0 :        readDy = cDy
         864           0 :        IF ( Lct%Dct%Dta%ncHrs(1) == -1 ) THEN
         865           0 :           readHr = -1
         866             :        ELSE
         867           0 :           readHr = cHr
         868             :        ENDIF
         869             :
         870             :        ! Eventually shift reference time by amount specified
         871             :        ! in HEMCO configuration file
         872             :        CALL TimeShift_Apply ( HcoState, Lct, &
         873           0 :                               readYr, readMt, readDy, readHr, readMn, RC )
         874             :
         875             :        ! Don't need below
         876           0 :        RETURN
         877             :     ENDIF
         878             :
         879             :     ! -------------------------------------------------------------
         880             :     ! If CycleFlag is anything else, select the time attributes
         881             :     ! as specified in the configuration file and closest to
         882             :     ! current simulation date.
         883             :     ! -------------------------------------------------------------
         884             :
         885             :     ! Year
         886           0 :     IF ( Lct%Dct%Dta%ncYrs(1) == Lct%Dct%Dta%ncYrs(2) ) THEN
         887           0 :        readYr = Lct%Dct%Dta%ncYrs(1)
         888             :     ELSE
         889             :        readYr = MIN( MAX(cYr,Lct%Dct%Dta%ncYrs(1)), &
         890           0 :                          Lct%Dct%Dta%ncYrs(2)          )
         891             :     ENDIF
         892             :
         893             :     ! Month
         894           0 :     IF ( Lct%Dct%Dta%ncMts(1) == Lct%Dct%Dta%ncMts(2) ) THEN
         895           0 :        readMt = Lct%Dct%Dta%ncMts(1)
         896             :     ELSE
         897             :        readMt = MIN( MAX(cMt,Lct%Dct%Dta%ncMts(1)), &
         898           0 :                          Lct%Dct%Dta%ncMts(2)          )
         899             :     ENDIF
         900             :
         901             :     ! Day
         902           0 :     IF ( Lct%Dct%Dta%ncDys(1) == Lct%Dct%Dta%ncDys(2) ) THEN
         903           0 :        readDy = Lct%Dct%Dta%ncDys(1)
         904             :     ELSE
         905             :        readDy = MIN( MAX(cDy,Lct%Dct%Dta%ncDys(1)), &
         906           0 :                          Lct%Dct%Dta%ncDys(2)          )
         907             :     ENDIF
         908             :
         909             :     ! Hour
         910           0 :     IF ( Lct%Dct%Dta%ncHrs(1) == Lct%Dct%Dta%ncHrs(2) ) THEN
         911           0 :        readHr = Lct%Dct%Dta%ncHrs(1)
         912             :     ELSE
         913             :        readHr = MIN( MAX(cHr,Lct%Dct%Dta%ncHrs(1)), &
         914           0 :                          Lct%Dct%Dta%ncHrs(2)          )
         915             :     ENDIF
         916             :
         917             :     ! For weekday data, set day to 1. The seven day slices to be
         918             :     ! read will be detected based upon the current year/month.
         919           0 :     IF ( Lct%Dct%Dta%ncDys(1) == -10 ) readDy = 1
         920             :
         921             :     ! Don't allow invalid entries for years, months or days, i.e.
         922             :     ! force readYr, readMt and readDy to be positive!
         923             :     ! readHr can be negative, in which case all hourly fields will
         924             :     ! become read!
         925           0 :     IF ( readYr < 0 ) readYr = cYr
         926           0 :     IF ( readMt < 0 ) readMt = cMt
         927           0 :     IF ( readDy < 0 ) readDy = cDy
         928             :
         929             :     ! Eventually shift reference time by amount specified
         930             :     ! in HEMCO configuration file
         931             :     CALL TimeShift_Apply ( HcoState, Lct, &
         932           0 :                            readYr, readMt, readDy, readHr, readMn, RC )
         933           0 :     IF ( RC /= HCO_SUCCESS ) THEN
         934           0 :         CALL HCO_ERROR( 'ERROR 7', RC, THISLOC=LOC )
         935           0 :         RETURN
         936             :     ENDIF
         937             :
         938             :     ! Return w/ success
         939           0 :     RC = HCO_SUCCESS
         940             :
         941             :   END SUBROUTINE HCO_GetPrefTimeAttr
         942             : !EOC
         943             : !------------------------------------------------------------------------------
         944             : !                   Harmonized Emissions Component (HEMCO)                    !
         945             : !------------------------------------------------------------------------------
         946             : !BOP
         947             : !
         948             : ! !IROUTINE: HCO_ExtractTime
         949             : !
         950             : ! !DESCRIPTION: Subroutine HCO\_ExtractTime extracts the time stamp (ranges)
         951             : ! from the passed character string. The string is expected to be in
         952             : ! format Yr/Mt/Dy/Hr. Valid values for Yr, Mt, Dy and Hr are:
         953             : !
         954             : ! \begin{enumerate}
         955             : ! \item Range of values, separated by - sign: e.g. 2000-2010.
         956             : ! \item Single value: 2000
         957             : ! \item Wildcard character (default = *). In this case, the data interval
         958             : !  is determined automatically by HEMCO based on the number of time slices
         959             : !  found in the data set.
         960             : ! \item Time tokens: $YYYY, $MM, $DD, $HH. When reading the data, these values
         961             : !  will be substituted by the current simulation date.
         962             : ! \item String 'WD'. Denotes that the data contains weekday data. It is
         963             : !  expected that the first slice represents Sunday. Weekday data can be used
         964             : !  in combination with annual or monthly data. In that case, there need to be
         965             : !  seven entries for every year and/or month, respectively.
         966             : ! \end{enumerate}
         967             : !
         968             : ! The extracted time stamp is written into the arrays ncYrs, ncMts,
         969             : ! ncDys and ncHrs of the passed data structure Dta.
         970             : !\\
         971             : !\\
         972             : ! !INTERFACE:
         973             : !
         974           0 :   SUBROUTINE HCO_ExtractTime ( HcoConfig, CharStr, Dta, RC )
         975             : !
         976             : ! !USES:
         977             : !
         978             :     USE HCO_CHARPAK_MOD,    ONLY : STRSPLIT
         979             :     USE HCO_TYPES_MOD,      ONLY : FileData
         980             :     USE HCO_TYPES_MOD,      ONLY : ConfigObj
         981             :     USE HCO_TYPES_MOD,      ONLY : HCO_UFLAG_ALWAYS
         982             :     USE HCO_EXTLIST_MOD,    ONLY : HCO_GetOpt
         983             :     USE HCO_TIMESHIFT_MOD,  ONLY : TimeShift_Set
         984             : !
         985             : ! !INPUT PARAMETERS:
         986             : !
         987             :     TYPE(ConfigObj),  POINTER       :: HcoConfig  ! config obj
         988             :     CHARACTER(LEN=*), INTENT(IN   ) :: CharStr
         989             :     TYPE(FileData),   POINTER       :: Dta
         990             : !
         991             : ! !OUTPUT PARAMETERS:
         992             : !
         993             :     INTEGER,          INTENT(INOUT) :: RC
         994             : !
         995             : ! !REVISION HISTORY:
         996             : !  18 Sep 2013 - C. Keller - Initial version (update)
         997             : !  See https://github.com/geoschem/hemco for complete history
         998             : !EOP
         999             : !------------------------------------------------------------------------------
        1000             : !BOC
        1001             : !
        1002             : ! !LOCAL VARIABLES:
        1003             : !
        1004             :     INTEGER               :: I, I0, I1, N, M
        1005             :     INTEGER               :: TimeVec(8)
        1006             :     CHARACTER(LEN=255)    :: SUBSTR(255), DATERNG(255), MSG
        1007             :     CHARACTER(LEN=255)    :: LOC = 'HCO_ExtractTime (hco_tidx_mod.F90)'
        1008             :
        1009             :     !=================================================================
        1010             :     ! HCO_ExtractTime begins here!
        1011             :     !=================================================================
        1012             :
        1013             :     ! Check for case where time flag is set to just one wildcard
        1014             :     ! character. In this case, we want to update the file on every
        1015             :     ! HEMCO time step, i.e. it will be added to readlist 'Always'
        1016             :     ! (in hco_readlist_mod.F90).
        1017           0 :     IF ( TRIM(CharStr) == HCO_GetOpt(HcoConfig%ExtList,'Wildcard') ) THEN
        1018           0 :        Dta%UpdtFlag = HCO_UFLAG_ALWAYS
        1019           0 :        Dta%ncYrs    = -999
        1020           0 :        Dta%ncMts    = -999
        1021           0 :        Dta%ncDys    = -999
        1022           0 :        Dta%ncHrs    = -999
        1023             :
        1024           0 :        RC = HCO_SUCCESS
        1025           0 :        RETURN
        1026             :     ENDIF
        1027             :
        1028             :     ! Init
        1029           0 :     TimeVec(:) = -1
        1030             :
        1031             :     ! Extract strings to be translated into integers
        1032           0 :     CALL STRSPLIT( CharStr, HCO_GetOpt(HcoConfig%ExtList,'Separator'), SUBSTR, N )
        1033           0 :     IF ( N < 4 ) THEN
        1034           0 :        MSG = 'Time stamp must have at least 4 elements: ' // TRIM(CharStr)
        1035           0 :        CALL HCO_ERROR( MSG, RC, THISLOC=LOC )
        1036           0 :        RETURN
        1037             :     ENDIF
        1038             :
        1039             :     ! Extract year, month, day, and hour range from the four
        1040             :     ! substrings
        1041             :
        1042             :     ! Do for each substring:
        1043           0 :     DO I = 1,4
        1044             :
        1045             :        ! Indices in TimeVec:
        1046           0 :        I0 = (I-1) * 2 + 1
        1047           0 :        I1 = I0 + 1
        1048             :
        1049             :        ! For wildcard character, set lower and upper limit both to -1.
        1050             :        ! In this case, the whole time slice will be read into file!
        1051           0 :        IF ( TRIM(SUBSTR(I)) == TRIM(HCO_GetOpt(HcoConfig%ExtList,'Wildcard') ) ) THEN
        1052           0 :           TimeVec(I0:I1) = -1
        1053             :
        1054             :        ! Characters YYYY, MM, DD, and/or HH can be used to ensure that
        1055             :        ! the current simulation time is being used.
        1056             :        ELSEIF ( INDEX( TRIM(SUBSTR(I)), 'YYYY' ) > 0 .OR. &
        1057             :                 INDEX( TRIM(SUBSTR(I)), 'MM'   ) > 0 .OR. &
        1058           0 :                 INDEX( TRIM(SUBSTR(I)), 'DD'   ) > 0 .OR. &
        1059             :                 INDEX( TRIM(SUBSTR(I)), 'HH'   ) > 0       ) THEN
        1060           0 :           TimeVec(I0:I1) = -999
        1061             :
        1062             :        ! For weekdaily data in UTC coordinates, set day flags to 1-7.
        1063           0 :        ELSEIF ( I==3 .AND. INDEX( TRIM(SUBSTR(I)), 'UTCWD' ) > 0 ) THEN
        1064           0 :           TimeVec(I0) = 1
        1065           0 :           TimeVec(I1) = 7
        1066           0 :           Dta%IsLocTime = .FALSE.
        1067             :
        1068             :        ! For the daily index, value 'WD' is also supported. This
        1069             :        ! indicates weekdays (Sun, Mon, ..., Sat). Use a special
        1070             :        ! flag here to expliclity state that these are weekday data.
        1071           0 :        ELSEIF ( I==3 .AND. INDEX( TRIM(SUBSTR(I)), 'WD' ) > 0 ) THEN
        1072           0 :           TimeVec(I0:I1) = -10
        1073             :
        1074             :        ! For the hourly index, value 'LH' is also supported. This
        1075             :        ! indicates local hours. Use a special flag here to expliclity
        1076             :        ! state that these data are local hours.
        1077           0 :        ELSEIF ( I==4 .AND. INDEX( TRIM(SUBSTR(I)), 'LH' ) > 0 ) THEN
        1078           0 :           TimeVec(I0:I1) = -10
        1079           0 :           Dta%IsLocTime = .TRUE.
        1080             :
        1081             :        ! Otherwise, check for date range and set lower and upper bound
        1082             :        ! accordingly.
        1083             :        ELSE
        1084             :           CALL STRSPLIT( SUBSTR(I), '-', DATERNG, M )
        1085             :
        1086             :           ! If range is given:
        1087           0 :           IF ( M == 2 ) THEN
        1088           0 :              READ( DATERNG(1), * ) TimeVec(I0)
        1089           0 :              READ( DATERNG(2), * ) TimeVec(I1)
        1090             :
        1091             :           ! Use same value if only one value is given:
        1092           0 :           ELSEIF ( M == 1 ) THEN
        1093           0 :              READ( DATERNG(1), * ) TimeVec(I0)
        1094           0 :              TimeVec(I1) = TimeVec(I0)
        1095             :           ELSE
        1096           0 :              MSG = 'Cannot extract time stamp: ' // TRIM(CharStr)
        1097           0 :              CALL HCO_ERROR( MSG, RC, THISLOC=LOC )
        1098           0 :              RETURN
        1099             :           ENDIF
        1100             :        ENDIF
        1101             :
        1102             :     ENDDO !I
        1103             :
        1104             :     ! Pass to list container
        1105           0 :     Dta%ncYrs = TimeVec(1:2)
        1106           0 :     Dta%ncMts = TimeVec(3:4)
        1107           0 :     Dta%ncDys = TimeVec(5:6)
        1108           0 :     Dta%ncHrs = TimeVec(7:8)
        1109             :
        1110             :     ! Check for local times.
        1111             :     ! Hourly and daily data that is in local time shall be completely
        1112             :     ! read into memory. This will ensure that for every time zone, the
        1113             :     ! correct values can be selected.
        1114             : !    !IF ( Dta%IsLocTime ) THEN
        1115             : !       !Dta%ncDys = -1
        1116             : !       !Dta%ncHrs = -1
        1117             : !    ENDIF
        1118             :
        1119             :     ! Weekdaily data is always in local time. All seven time slices will
        1120             :     ! be read into memory.
        1121           0 :     IF ( Dta%ncDys(1) == -10 ) Dta%IsLocTime  = .TRUE.
        1122             :
        1123             :     ! If time shift is specified, archive it in attribute 'tShift'.
        1124           0 :     IF ( N > 4 ) THEN
        1125           0 :        CALL TimeShift_Set( HcoConfig, Dta, SUBSTR(5), RC )
        1126           0 :        IF ( RC /= HCO_SUCCESS ) THEN
        1127           0 :            CALL HCO_ERROR( 'ERROR 8', RC, THISLOC=LOC )
        1128           0 :            RETURN
        1129             :        ENDIF
        1130             :     ENDIF
        1131             :
        1132             :     ! Leave w/ success
        1133           0 :     RC = HCO_SUCCESS
        1134             :
        1135             :   END SUBROUTINE HCO_ExtractTime
        1136             : !EOC
        1137             : END MODULE HCO_TIDX_MOD

Generated by: LCOV version 1.14