string_to_value(3f) - [M_strings:TYPE] subroutine returns numeric value from string (LICENSE:PD)
Synopsis
Description
Options
Returns
Examples
Author
License
subroutine string_to_value(chars,valu,ierr)
character(len=*),intent(in) :: chars ! input string integer|real|doubleprecision,intent(out) :: valu integer,intent(out) :: ierr
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.
CHARS input string to read numeric value from
VALU numeric value returned. May be INTEGER, REAL, or DOUBLEPRECISION. IERR error flag (0 == no error)
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
John S. Urban
Public Domain
Nemo Release 3.1 | string_to_value (3m_strings) | January 10, 2025 |