C Library Functions  - aton (3)

NAME

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

CONTENTS

Synopsis
Description
Options
Returns
Example
Author
License

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 [char46]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


Nemo Release 3.1 aton (3) July 22, 2023
Generated by manServer 1.08 from e2f6ee29-3323-41b6-b03f-74d4d3a14550 using man macros.