Table of contents
CSPICE_PRSINT parses a string as an integer, encapsulating error
handling.
Given:
string a string representing a numeric value.
help, string
STRING = Scalar
Commas and spaces may be used in this string for ease of
reading and writing the number. They are treated as
insignificant but non-error-producing characters.
For exponential representation any of the characters
'E','D','e','d' may be used.
The following are legitimate numeric expressions
+12.2 e-1
-3. 1415 9276
1e6
E8
The program also recognizes the following mnemonics
'PI', 'pi', 'Pi', 'pI'
'+PI', '+pi', '+Pi', '+pI'
'-PI', '-pi', '-Pi', '-pI'
and returns the value ( + OR - ) 3 as appropriate.
the call:
cspice_prsint, string, intval
returns:
intval the integer obtained by parsing `string'.
help, intval
LONG = Scalar
If an error is encountered, `intval' is not changed from
whatever the input value was. If the input string has a
fractional part, the fractional part will be truncated. Thus
3.18 is interpreted as 3. -4.98 is interpreted as -4.
None.
Any numerical results shown for this example may differ between
platforms as the results depend on the SPICE kernels used as input
and the machine specific arithmetic implementation.
1) Parse into a LONG variable a set of strings representing
numeric values.
Example code begins here.
PRO prsint_ex1
;;
;; Local parameters.
;;
SETSIZ = 10L
;;
;; Initialize the array of strings.
;;
strval = [ '100,000,000', ' -2 690 192', $
' +12.2 e-1', '-3. 141 592', $
' 1.2e8', ' E6', $
' Pi', ' -PI', $
'-2147483648', ' 2147483647' ]
;;
;; Parse each string into a LONG variable.
;;
print, format='(A)', ' STRVAL INTVAL'
print, format='(A)', '----------- ------------'
for i=0L, SETSIZ-1L do begin
cspice_prsint, strval[i], intval
print, format='(A11,2X,I12)', strval[i], intval
endfor
END
When this program was executed on a Mac/Intel/IDL8.x/64-bit
platform, the output was:
STRVAL INTVAL
----------- ------------
100,000,000 100000000
-2 690 192 -2690192
+12.2 e-1 1
-3. 141 592 -3
1.2e8 120000000
E6 1000000
Pi 3
-PI -3
-2147483648 -2147483648
2147483647 2147483647
The purpose of this routine is to enable safe parsing of numeric
values into a LONG variable without the necessity of in-line
error checking.
1) If the input string cannot be parsed or if the string
represents a number that is outside the range of representable
integers, as defined by cspice_intmin and cspice_intmax, the error
SPICE(NOTANLONG) is signaled by a routine in the call tree
of this routine. The value of `intval' is not changed from
whatever the input value was.
2) If the input argument `string' is undefined, an error is
signaled by the IDL error handling system.
3) If the input argument `string' is not of the expected type, or
it does not have the expected dimensions and size, an error is
signaled by the Icy interface.
4) If the output argument `intval' is not a named variable, an
error is signaled by the Icy interface.
None.
None.
ICY.REQ
None.
J. Diaz del Rio (ODC Space)
E.D. Wright (JPL)
-Icy Version 1.0.2, 10-AUG-2021 (JDR)
Edited the header to comply with NAIF standard. Added complete
code example.
Updated the header to properly describe its input and output.
Added -Parameters, -Exceptions, -Files, -Restrictions,
-Literature_References and -Author_and_Institution sections, and
completed -Particulars section.
Removed reference to the routine's corresponding CSPICE header from
-Abstract section.
Added arguments' type and size information in the -I/O section.
-Icy Version 1.0.1, 09-DEC-2005 (EDW)
Added -Examples section.
-Icy Version 1.0.0, 16-JUN-2003 (EDW)
parse integer with encapsulated error handling
|