int_parse Subroutine

private subroutine int_parse(this, values, err_msg)

Type Bound

nml_int_key_t

Arguments

Type IntentOptional Attributes Name
class(nml_int_key_t), intent(inout) :: this
character(len=*), intent(in) :: values(:)
character(len=:), intent(out), allocatable :: err_msg

Calls

proc~~int_parse~~CallsGraph proc~int_parse nml_int_key_t%int_parse proc~fmt_int fmt_int proc~int_parse->proc~fmt_int

Variables

Type Visibility Attributes Name Initial
character(len=128), private :: imsg
integer, private :: ios
integer, private :: v

Source Code

   subroutine int_parse(this, values, err_msg)
      class(nml_int_key_t), intent(inout) :: this
      character(len=*), intent(in) :: values(:)
      character(len=:), allocatable, intent(out) :: err_msg
      integer :: v, ios
      character(len=128) :: imsg

      if (size(values) /= 1) then
         err_msg = "key '"//this%name//"' expects 1 value, got "//fmt_int(size(values))
         return
      end if
      read (values(1), *, iostat=ios, iomsg=imsg) v
      if (ios /= 0) then
         err_msg = "key '"//this%name//"': cannot parse integer from '"//trim(values(1))//"'"
         return
      end if
      if (this%has_min .and. v < this%vmin) then
         err_msg = "key '"//this%name//"' = "//fmt_int(v)//" below min "//fmt_int(this%vmin)
         return
      end if
      if (this%has_max .and. v > this%vmax) then
         err_msg = "key '"//this%name//"' = "//fmt_int(v)//" above max "//fmt_int(this%vmax)
         return
      end if
      this%tgt = v
   end subroutine int_parse