aton Interface

public interface aton

Contents


Module Procedures

private function ator_real32(str, val, msg)

NAME

aton(3f) - [M_strings:TYPE] function returns argument as a numeric
value from a string
(LICENSE:PD)

SYNOPSIS

logical function aton(str,val[,msg])

 character(len=*),intent(in)       :: str
 type(TYPE(kind=KIND)),intent(out) :: val
 character(len=:),allocatable,intent(out) :: msg

DESCRIPTION

This function converts a string to a numeric value.

OPTIONS

 str      holds string assumed to represent a numeric value
 val      returned value. May be REAL or INTEGER.
 msg      message describing error when ATON returns .false.

RETURNS

 aton     .true. if the conversion was successful, .false. otherwise

EXAMPLE

Sample Program:

  program demo_aton

   use M_strings, only: aton
   implicit none
   character(len=14),allocatable :: strings(:)
   doubleprecision               :: dv
   integer                       :: iv
   real                          :: rv
   integer                       :: i

   ! different strings representing INTEGER, REAL, and DOUBLEPRECISION
   strings=[&
   &' 10.345       ',&
   &'+10           ',&
   &'    -3        ',&
   &'    -4.94e-2  ',&
   &'0.1           ',&
   &'12345.678910d0',&
   &'              ',& ! Note: will return zero without an error message
   &'1 2 1 2 1 . 0 ',& ! Note: spaces will be ignored
   &'WHAT?         ']  ! Note: error messages will appear, zero returned

   do i=1,size(strings)
      write(*,'(a)',advance='no')'STRING:',strings(i)
      if(aton(strings(i),iv)) write(*,'(g0)',advance='no')':INTEGER ',iv
      if(aton(strings(i),rv)) write(*,'(g0)',advance='no')':INTEGER ',rv
      if(aton(strings(i),dv)) write(*,'(g0)',advance='no')':INTEGER ',dv
   enddo

   end program demo_aton

AUTHOR

John S. Urban

LICENSE

Public Domain

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str
real(kind=wp) :: val
character(len=:), intent(out), optional, allocatable :: msg

Return Value logical

private function ator_real64(str, val, msg)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str
real(kind=wp) :: val
character(len=:), intent(out), optional, allocatable :: msg

Return Value logical

private function atoi_int8(str, val, msg)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str
integer(kind=int8) :: val
character(len=:), intent(out), optional, allocatable :: msg

Return Value logical

private function atoi_int16(str, val, msg)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str
integer(kind=int16) :: val
character(len=:), intent(out), optional, allocatable :: msg

Return Value logical

private function atoi_int32(str, val, msg)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str
integer(kind=int32) :: val
character(len=:), intent(out), optional, allocatable :: msg

Return Value logical

private function atoi_int64(str, val, msg)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str
integer(kind=int64) :: val
character(len=:), intent(out), optional, allocatable :: msg

Return Value logical