STR2INT(), STR2REAL(), and STR2DBLE()

Fortran version:

    SUBROUTINE SCANINT( STRING, VALUE, NCHARS, NDIGITS )
    INTEGER FUNCTION STR2INT(  ASTRING )
    REAL    FUNCTION STR2REAL( ASTRING )
    REAL*8  FUNCTION STR2DBLE( ASTRING )
        CHARACTER*(*), INTENT(IN   ) :: ASTRING  !  string to find effective length for

NO C versions

use "strtol()" or "strtod()"

Summary:

Returns the INTEGER, REAL, or DOUBLE PRECISION value decoded from ASTRING, or IMISS3 or BADVAL3 from PARMS3.EXT (as appropriate) for "missing" or badly-formatted inputs. Skips leading whitespace (defined as ASCII characters less than or equal to the BLANK/SPACE character; terminates input at the first nondigit or the first non-exponent-designator, for STR2REAL.

SCANINT() returns the INTEGER VALUE (equivalent to VALUE=STR2INT(ASTRING), and also returns the total number NCHARS of characters consumed (including whitespace) and the number NDIGITS of digit and/or leading sign characters.

Preconditions:

ASCII collation order for strings; correctly formatted numeric string for input.

Fortran Usage:

For Fortran-90 declarations and interface checking:
    USE M3UTILIO
    

(See sample programs LATLON, PRESZ, or SFCMET for additional usage examples.)

    ...
    USE M3UTILIO
    ...
    CHARACTER*256  ASTRING, BSTRING
    INTEGER        L
    REAL           R
    ...
    L = STR2INT( ASTRING )
    IF ( L .EQ. IMISS3 ) THEN
        WRITE (*,*) 'ASTRING: ", ASTRING, '" blank or not an integer'
    ELSE
        WRITE (*,*) 
  &  'INTEGER value stored in ASTRING is ', L
    END IF
    ...
    R = STR2REAL( BSTRING )
    IF ( R .LT. AMISS3 ) THEN
        WRITE (*,*) 'BSTRING: ", BSTRING, '" blank or not a real'
    ELSE
        WRITE (*,*) 
  &  'REAL value stored in BSTRING is ', R
    END IF
    ...

C Usage:

don't; use standard library functions "strtol()" or "strtod" instead.


Previous: SORTI

Next: SYSTEMF

Up: Utility Routines

To: Models-3/EDSS I/O API: The Help Pages