parse_date_string Subroutine

public pure subroutine parse_date_string(str, y, m, d, ok)

Parse a “YYYY-MM-DD” calendar date. ok = .false. on any malformed field (caller decides fail-loud policy).

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str
integer, intent(out) :: y
integer, intent(out) :: m
integer, intent(out) :: d
logical, intent(out) :: ok

Called by

proc~~parse_date_string~~CalledByGraph proc~parse_date_string parse_date_string proc~configure_ocean_bc configure_ocean_bc proc~configure_ocean_bc->proc~parse_date_string proc~configure_ocean_tides configure_ocean_tides proc~configure_ocean_tides->proc~parse_date_string proc~engine_setup engine_setup proc~engine_setup->proc~configure_ocean_bc proc~engine_setup->proc~configure_ocean_tides proc~complete_ocean_create complete_ocean_create proc~complete_ocean_create->proc~engine_setup proc~driver_run_ocean driver_run_ocean proc~driver_run_ocean->proc~engine_setup proc~driver_validate driver_validate proc~driver_validate->proc~engine_setup proc~driver_run driver_run proc~driver_run->proc~driver_run_ocean proc~rdb_ocean_create_finalize rdb_ocean_create_finalize proc~rdb_ocean_create_finalize->proc~complete_ocean_create proc~rdb_ocean_create_from_string rdb_ocean_create_from_string proc~rdb_ocean_create_from_string->proc~complete_ocean_create

Variables

Type Visibility Attributes Name Initial
character(len=128), private :: emsg
integer, private :: ios
integer, private :: p1
integer, private :: p2
character(len=:), private, allocatable :: t

Source Code

   pure subroutine parse_date_string(str, y, m, d, ok)
      !! Parse a "YYYY-MM-DD" calendar date.  `ok = .false.` on any
      !! malformed field (caller decides fail-loud policy).
      character(len=*), intent(in) :: str
      integer, intent(out) :: y, m, d
      logical, intent(out) :: ok
      character(len=:), allocatable :: t
      character(len=128) :: emsg
      integer :: p1, p2, ios
      y = 0
      m = 0
      d = 0
      ok = .false.
      t = trim(adjustl(str))
      p1 = index(t, "-")
      if (p1 <= 1) return
      p2 = index(t(p1 + 1:), "-")
      if (p2 <= 1) return
      p2 = p1 + p2
      read (t(1:p1 - 1), *, iostat=ios, iomsg=emsg) y
      if (ios /= 0) return
      read (t(p1 + 1:p2 - 1), *, iostat=ios, iomsg=emsg) m
      if (ios /= 0) return
      read (t(p2 + 1:), *, iostat=ios, iomsg=emsg) d
      if (ios /= 0) return
      if (m < 1 .or. m > 12 .or. d < 1 .or. d > 31) return
      ok = .true.
   end subroutine parse_date_string