Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | time_string | |||
class(KeywordEnforcer), | intent(in), | optional | :: | unusable | ||
integer, | intent(out), | optional | :: | rc |
function string_to_integer_time(time_string,unusable,rc) result(time) character(len=*), intent(in) :: time_string class(KeywordEnforcer), optional, intent(in) :: unusable integer, optional, intent(out) :: rc integer :: time integer mpos(2), hpos(2), spos(2) integer strlen integer firstcolon, lastcolon integer lastspace integer hour,min,sec _UNUSED_DUMMY(unusable) strlen = LEN_TRIM (time_string) firstcolon = index(time_string, ':') if (firstcolon .LE. 0) then ! If no colons, check for hour. ! Logic below assumes a null character or something else is after the hour ! if we do not find a null character add one so that it correctly parses time !if (time_string(strlen:strlen) /= char(0)) then !time_string = trim(time_string)//char(0) !strlen=len_trim(time_string) !endif lastspace = index(TRIM(time_string), ' ', BACK=.TRUE.) if ((strlen-lastspace).eq.2 .or. (strlen-lastspace).eq.3) then hpos(1) = lastspace+1 hpos(2) = strlen-1 read (time_string(hpos(1):hpos(2)), * ) hour min = 0 sec = 0 else hour = 0 min = 0 sec = 0 endif else hpos(1) = firstcolon - 2 hpos(2) = firstcolon - 1 lastcolon = index(time_string, ':', BACK=.TRUE.) if ( lastcolon .EQ. firstcolon ) then mpos(1) = firstcolon + 1 mpos(2) = firstcolon + 2 read (time_string(hpos(1):hpos(2)), * ) hour read (time_string(mpos(1):mpos(2)), * ) min sec = 0 else mpos(1) = firstcolon + 1 mpos(2) = lastcolon - 1 spos(1) = lastcolon + 1 spos(2) = lastcolon + 2 read (time_string(hpos(1):hpos(2)), * ) hour read (time_string(mpos(1):mpos(2)), * ) min read (time_string(spos(1):spos(2)), * ) sec endif endif time = hour*10000+min*100+sec _RETURN(_SUCCESS) end function string_to_integer_time