[UP]


Manual Reference Pages  - string_to_values (3)

NAME

string_to_values(3f) - [M_strings:NUMERIC] read a string representing numbers into a numeric array (LICENSE:PD)

CONTENTS

Synopsis
Description
Options
Results
Example
Author
License

SYNOPSIS

subroutine string_to_values(line,iread,values,inums,delims,ierr)

       character(len=*) :: line
       integer          :: iread
       real             :: values(*)
       integer          :: inums
       character(len=*) :: delims
       integer          :: ierr

DESCRIPTION

This routine can take a string representing a series of numbers and convert it to a numeric array and return how many numbers were found.

OPTIONS

LINE Input string containing numbers
IREAD maximum number of values to try to read from input string

RESULTS

VALUES real array to be filled with numbers
INUMS number of values successfully read (before error occurs if one does)
DELIMS delimiter character(s), usually a space. must not be a null string. If more than one character, a space must not be the last character or it will be ignored.
IERR error flag (0=no error, else column number string starts at that error occurred on).

EXAMPLE

Sample Program:

     program demo_string_to_values
      use M_strings, only : string_to_values
      implicit none
      character(len=80)  :: s=’ 10 20e3;3.45 -400.3e-2;1234; 5678 ’
      integer,parameter  :: isz=10
      real               :: array(isz)
      integer            :: inums, ierr, ii

call string_to_values(s,10,array,inums,’ ;’,ierr) call reportit()

call string_to_values(’10;2.3;3.1416’,isz,array,inums,’ ;’,ierr) call reportit()

contains subroutine reportit() write(*,*)’string_to_values:’ write(*,*)’input string.............’,trim(s) write(*,*)’number of values found...’,inums write(*,*)’values...................’,(array(ii),ii=1,inums) end subroutine reportit end program demo_string_to_values

Expected output

    string_to_values:
    input string............. 10 20e3;3.45 -400.3e-2;1234; 5678
    number of values found...           6
    values...................   10.0000000  20000.0000  3.45000005
    -4.00299978  1234.00000  5678.00000
    string_to_values:
    input string............. 10 20e3;3.45 -400.3e-2;1234; 5678
    number of values found...           3
    values...................   10.0000000  2.29999995  3.14159989

AUTHOR

John S. Urban

LICENSE

Public Domain


string_to_values (3) March 11, 2021
Generated by manServer 1.08 from 39424f5c-146a-47ea-bad5-a5b8ea8ed66b using man macros.