>  Docs Center  >  Libraries  >  ASTROLIB  >  VALID_NUM






    Check if a string is a valid number representation.


    The input string is parsed for characters that may possibly
    form a valid number. It is more robust than simply checking
    for an IDL conversion error because that allows strings such
    as '22.3qwert' to be returned as the valid number 22.3
    This function had a major rewrite in August 2008 to use STREGEX
    and allow vector input. It should be backwards compatible.

Calling Sequence

    IDL> status = valid_num(string [,value] [,/integer])


    string - the string to be tested, scalar or array


    status - byte scalar or array, same size as the input string
              set to 1 where the string is a valid number, 0 for invalid

Optional Output

    value - The value the string decodes to, same size as input string.
          This will be returned as a double precision number unless
          /INTEGER is present, in which case a long integer is returned.

Optional Input Keyword

    /INTEGER - if present code checks specifically for an integer.


    (1) IDL> print,valid_num(3.2,/integer)
        --> 0 ;Since 3.2 is not an integer
    (2) IDL> str =['-0.03','2.3g', '3.2e12']
        IDL> test = valid_num(str,val)
              test = [1,0,1] & val = [-0.030000000 ,NaN ,3.2000000e+12]

Revision History

          Version 1, C D Pike, RAL, 24-May-93
          Version 2, William Thompson, GSFC, 14 October 1994
                      Added optional output parameter VALUE to allow
                      VALID_NUM to replace STRNUMBER in FITS routines.
          Version 3 Wayne Landsman rewrite to use STREGEX, vectorize
          Version 4 W.L. (fix from C. Markwardt) Better Stregex expression,
                    was missing numbers like '134.' before Jan 1 2010

© 2022 Harris Geospatial Solutions, Inc. |  Legal
My Account    |    Store    |    Contact Us