aton(3f) - [M_strings:TYPE] function returns argument as a numeric value from a string (LICENSE:PD)
Synopsis
Description
Options
Returns
Examples
Author
License
logical function aton(str,val[,msg])
character(len=*),intent(in) :: str type(TYPE(kind=KIND)),intent(out) :: val character(len=:),allocatable,intent(out) :: msg
This function converts a string to a numeric value.
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.
aton [char46]true. if the conversion was successful, .false. otherwise
Sample Program:
program demo_atonuse 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
John S. Urban
Public Domain
Nemo Release 3.1 | aton (3m_strings) | January 10, 2025 |