real_parse Subroutine

private subroutine real_parse(this, values, err_msg)

Type Bound

nml_real_key_t

Arguments

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

Calls

proc~~real_parse~~CallsGraph proc~real_parse nml_real_key_t%real_parse proc~fmt_int fmt_int proc~real_parse->proc~fmt_int proc~fmt_real fmt_real proc~real_parse->proc~fmt_real

Variables

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

Source Code

   subroutine real_parse(this, values, err_msg)
      class(nml_real_key_t), intent(inout) :: this
      character(len=*), intent(in) :: values(:)
      character(len=:), allocatable, intent(out) :: err_msg
      real(rk) :: v
      integer :: 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 real from '"//trim(values(1))//"'"
         return
      end if
      if (this%has_min .and. v < this%vmin) then
         err_msg = "key '"//this%name//"' = "//fmt_real(v)//" below min "//fmt_real(this%vmin)
         return
      end if
      if (this%has_max .and. v > this%vmax) then
         err_msg = "key '"//this%name//"' = "//fmt_real(v)//" above max "//fmt_real(this%vmax)
         return
      end if
      this%tgt = v
   end subroutine real_parse