NAME
string_to_value(3f) - [M_strings:TYPE] subroutine returns numeric
value from string
(LICENSE:PD)
SYNOPSIS
subroutine string_to_value(chars,valu,ierr)
character(len=*),intent(in) :: chars ! input string
integer|real|doubleprecision,intent(out) :: valu
integer,intent(out) :: ierr
DESCRIPTION
Returns a numeric value from a numeric character string.
Works with any g-format input, including integer, real, and
exponential. If the input string begins with "B", "Z", or "O"
and otherwise represents a positive whole number it is assumed to
be a binary, hexadecimal, or octal value. If the string contains
commas they are removed. If the string is of the form NN:MMM... or
NN#MMM then NN is assumed to be the base of the whole number.
If an error occurs in the READ, IOSTAT is returned in IERR and
value is set to zero. if no error occurs, IERR=0.
OPTIONS
CHARS input string to read numeric value from
RETURNS
VALU numeric value returned. May be INTEGER, REAL, or
DOUBLEPRECISION.
IERR error flag (0 == no error)
EXAMPLE
Sample Program:
program demo_string_to_value
use M_strings, only: string_to_value
implicit none
real :: value
integer :: ierr
character(len=80) :: string
string=' -40.5e-2 '
call string_to_value(string,value,ierr)
write(*,*) 'value of string ['//trim(string)//'] is ',value
end program demo_string_to_value
AUTHOR
LICENSE
Arguments
Type |
Intent | Optional | Attributes |
|
Name |
|
character(len=*),
|
intent(in) |
|
|
:: |
chars |
|
real,
|
intent(out) |
|
|
:: |
valu |
|
integer,
|
intent(out) |
|
|
:: |
ierr |
|