Table of contents
CSPICE_PRSDP parses a string as a double precision number, 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
1e12
E10
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.1415 9265 3589 7932 3846 26 ...
as appropriate.
the call:
cspice_prsdp, string, dpval
returns:
dpval the double precision number obtained by parsing `string'.
help, dpval
DOUBLE = Scalar
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 DOUBLE variable a set of strings
representing numeric values.
Example code begins here.
PRO prsdp_ex1
;;
;; Local parameters.
;;
SETSIZ = 8L
;;
;; Initialize the array of strings.
;;
strval = [ '100,000,000', ' -2 690 192', $
' +12.2 e-1', '-3. 141 592', $
' 1.2e12', ' E10', $
' Pi', ' -PI' ]
;;
;; Parse each string into a DOUBLE variable.
;;
print, format='(A)', ' STRVAL DPVAL'
print, format='(A)', '----------- --------------------------'
for i=0L, SETSIZ-1L do begin
cspice_prsdp, strval[i], dpval
print, format='(A11,F28.12)', strval[i], dpval
endfor
END
When this program was executed on a Mac/Intel/IDL8.x/64-bit
platform, the output was:
STRVAL DPVAL
----------- --------------------------
100,000,000 100000000.000000000000
-2 690 192 -2690192.000000000000
+12.2 e-1 1.220000000000
-3. 141 592 -3.141592000000
1.2e12 1200000000000.000000000000
E10 10000000000.000000000000
Pi 3.141592653590
-PI -3.141592653590
The purpose of this routine is to enable safe parsing of double
precision numbers without the necessity of in-line error checking.
1) If the input string cannot be parsed due to use of an
unexpected or misplaced character or due to a string
representing a number too large for double precision, the
error SPICE(NOTADPNUMBER) is signaled by a routine in the call
tree of this routine.
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 `dpval' 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 d.p. number with encapsulated error handling
|