[UP]


Manual Reference Pages  - getvals (3)

NAME

getvals(3f) - [M_strings:NUMERIC] read arbitrary number of REAL values from a character variable up to size of VALUES() array (LICENSE:PD)

CONTENTS

Synopsis
Description
Options
Returns
Examples
Author
License

SYNOPSIS

subroutine getvals(line,values,icount,ierr)

    character(len=*),intent(in)  :: line
    class(*),intent(out)         :: values(:)
    integer,intent(out)          :: icount
    integer,intent(out),optional :: ierr

DESCRIPTION

GETVALS(3f) reads a relatively arbitrary number of numeric values from a character variable into a REAL array using list-directed input.

NOTE: In this version null values are skipped instead of meaning to leave that value unchanged

1,,,,,,,2 / reads VALUES=[1.0,2.0]

Per list-directed rules when reading values, allowed delimiters are comma, semi-colon and space.

the slash separator can be used to add inline comments.

       10.1, 20.43e-1 ; 11 / THIS IS TREATED AS A COMMENT

Repeat syntax can be used up to the size of the output array. These are equivalent input lines:

       4*10.0
       10.0, 10.0, 10.0, 10.0

OPTIONS

LINE A character variable containing the characters representing a list of numbers

RETURNS

VALUES()
  array holding numbers read from string. May be of type INTEGER, REAL, DOUBLEPRECISION, or CHARACTER. If CHARACTER the strings are returned as simple words instead of numeric values.
ICOUNT number of defined numbers in VALUES(). If ICOUNT reaches the size of the VALUES() array parsing stops.
IERR zero if no error occurred in reading numbers. Optional. If not present and an error occurs the program is terminated.

EXAMPLES

Sample program:

      program demo_getvals
      use M_strings, only: getvals
      implicit none
      integer,parameter  :: longest_line=256
      character(len=longest_line) :: line
      real               :: values(longest_line/2+1)
      integer            :: ios,icount,ierr
      INFINITE: do
         read(*,’(a)’,iostat=ios) line
         if(ios.ne.0)exit INFINITE
         call getvals(line,values,icount,ierr)
         write(*,’(4(g0,1x))’)’VALUES=’,values(:icount)
      enddo INFINITE
      end program demo_getvals

Sample input lines

       10,20 30.4
       1 2 3
       1

3 4*2.5 8 32.3333 / comment 1 30e3;300, 30.0, 3 even 1 like this! 10 11,,,,22,,,,33

Expected output:

    VALUES=   10.0000000       20.0000000       30.3999996
    VALUES=   1.00000000       2.00000000       3.00000000
    VALUES=   1.00000000
    VALUES=
    VALUES=   3.00000000       2.50000000       2.50000000
    2.50000000       2.50000000       8.00000000
    VALUES=   32.3333015
    VALUES=   30000.0000       300.000000       30.0000000
    3.00000000
    *getvals* WARNING:[even] is not a number
    *getvals* WARNING:[like] is not a number
    *getvals* WARNING:[this!] is not a number
    VALUES=   1.00000000       10.0000000
    VALUES=   11.0000000       22.0000000       33.0000000

AUTHOR

John S. Urban

LICENSE

Public Domain


getvals (3) March 11, 2021
Generated by manServer 1.08 from d9181ca1-25d6-4e5c-a4fa-270554c32bca using man macros.