| nparsd |
|
Table of contents
Procedure
NPARSD ( Double Precision parsing of a string )
SUBROUTINE NPARSD ( STRING, X, ERROR, PTR )
Abstract
Parse a character string that represents a number and return
a double precision value.
Required_Reading
None.
Keywords
ALPHANUMERIC
CONVERSION
PARSING
Declarations
IMPLICIT NONE
CHARACTER*(*) STRING
DOUBLE PRECISION X
CHARACTER*(*) ERROR
INTEGER PTR
Brief_I/O
VARIABLE I/O DESCRIPTION
-------- --- ---------------------------------------------------
STRING I Character string representing a numeric value.
X O Double precision value parsed from STRING.
ERROR O Message indicating whether errors have occurred.
PTR O Position in string where an error occurred.
Detailed_Input
STRING is a character string that represents a numeric value.
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 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 2600 D0 as
appropriate.
Detailed_Output
X double precision parsed value of input string. If an
error is encountered, X is not changed.
ERROR is a message indicating that the string could
not be parsed due to use of an unexpected or misplaced
character or due to a string representing a number
too large for double precision. If the number was
successfully parsed, ERROR will be returned as a blank.
In particular, blank strings, or strings that do not
contain either a digit or exponent character will
be regarded as errors.
PTR this indicates which character was being used when
the error occurred. If no error occurs, PTR is
returned as 0.
Parameters
None.
Exceptions
Error free.
1) If the string is non-numeric, PTR indicates the location in
the string where the error occurred, and ERROR contains a
descriptive error message.
Files
None.
Particulars
This routine parses an input character string that represents a
number, checks for overflow, unexpected or misplaced
characters. It returns the double precision number or an error
message.
Examples
Let LINE = 'DELTA_T_A = 32.184'
The following code fragment parses the line and obtains the
double precision value.
CALL NEXTWD ( LINE, FIRST, REST )
CALL NEXTWD ( REST, SECOND, REST )
CALL NEXTWD ( REST, THIRD, REST )
CALL NPARSD ( THIRD, VALUE, ERROR, PTR )
Restrictions
1) Due to rounding errors this routine may not be able to parse
the decimal character string representation of the largest
and smallest double precision numbers.
Literature_References
None.
Author_and_Institution
N.J. Bachman (JPL)
J. Diaz del Rio (ODC Space)
K.R. Gehringer (JPL)
H.A. Neilan (JPL)
W.L. Taber (JPL)
Version
SPICELIB Version 3.6.0, 12-AUG-2021 (JDR)
Added IMPLICIT NONE statement.
Edited the header to comply with NAIF standard. Removed
unnecessary $Revisions section.
SPICELIB Version 3.5.0, 15-AUG-2002 (WLT)
Replaced the call to INSSUB with a call to ZZINSSUB so
that this routine can legitimately call itself Error Free
SPICELIB Version 3.4.0, 03-DEC-2001 (NJB)
Added an extra check to make sure that ICHAR of any character
of the input string is positive.
SPICELIB Version 3.3.0, 29-FEB-1996 (KRG)
The declaration for the SPICELIB function PI is now
preceded by an EXTERNAL statement declaring PI to be an
external function. This removes a conflict with any
compilers that have a PI intrinsic function.
Removed the error message and storage for the unexpected
comma error message. This variable was set but never used,
and according to the spec for this routine a comma is a valid
delimiter, treated like a space, within numbers.
SPICELIB Version 3.2.0, 10-JAN-1995 (WLT)
Changed error strings from parameters to assignments to
compensate for shortcomings of the Absoft FORTRAN compiler
on the NeXT.
SPICELIB Version 3.1.0, 12-JUL-1994 (WLT)
The previous version of the routine assumed that the range
of values of ICHAR was 0 to 128. That turns out not to be
true on some machines. If a character whose ICHAR value is
outside this range is detected, it is now handled properly
as an unexpected character.
SPICELIB Version 3.0.0, 24-FEB-1993 (WLT)
The previous version of the algorithm interpreted P or p as 1.
This was not the intent of the routine and was corrected.
SPICELIB Version 2.0.0, 28-AUG-1992 (WLT) (KRG)
The basic algorithm was completely re-written. As a result
the routine now runs an order of magnitude faster than
it did before. In addition, strings that do not contain
enough information to assign a value to the string are now
regarded as errors. These include blank strings or strings
that contain only a sign characters, blanks and commas.
In addition the error diagnosis and checking for overflow
was greatly enhanced.
Note: strings may now parse with slightly different values
from the previous version of NPARSD. The current
implementation is more accurate in converting strings to
double precision numbers.
SPICELIB Version 1.1.1, 10-MAR-1992 (WLT)
Comment section for permuted index source lines was added
following the header.
SPICELIB Version 1.1.0, 17-APR-1990 (WLT)
Bug fix. The subscript used to reference individual characters
of the input string could sometimes step out of bounds. This
went unnoticed until NAIF began compiling with the CHECK=BOUNDS
option of the DEC Fortran compiler.
SPICELIB Version 1.0.0, 31-JAN-1990 (WLT) (HAN) (NJB)
|
Fri Dec 31 18:36:35 2021