NANINF browses and input array (or a single value) and informs you whether there is a NaN or an infinite value in the given array.
A NaN (Not A Number) is a floating-point data type introduced by the IEEE 754 standard to signal invalid real values resulting from operations like 0/0 or asin(3). The standard also provides floating-point representations for infinity quantities resulting from operations like 1/0.
Use
Called By
Any user-written subroutine
Prerequisite
None
Calling Sequence
CALL NANINF (values, n, answer, pos)
Input Argument
values | A real input array of any size. |
n | An integer that indicates the size of the input array. |
Output Argument
answer | An integer value signaling the outcome of the browsing action. A value 0 indicates all entries in the array are real numbers. A value of 1 indicates there is one NaN in the array. A value of 2 indicates there is an infinite value in the array. |
pos | If 'answer' returns a value 1 or 2, then 'pos' returns the 1-based index into the array with the offending value. |
Extended Definition
Subroutine NANINF is useful to check values passed to Adams Solver from within user-written subroutines. This subroutine should be used only while debugging.
Passing a NaN will cause an integrator failure because NaNs propagate through all data structures. Due to performance issues, Adams Solver does not check whether NaNs or infinite values are passed to it by user-written subroutines.
FORTRAN - Prototype
Subroutine NANINF is defined as follows.
SUBROUTINE NANINF(VALUES, N, ANSWER, POS)
C
C
INTEGER N, ANSWER, POS
DOUBLE PRECISION VALUES(*)
C Style - Prototype
Function c_naninf is defined as follows.
void c_naninf( const double *values, const int *n, int *answer, int *pos )
Caution: | When using the C-Style function, argument 'pos' returns a 1-based index of the offending value if any. |
Example
For example, from within a VFOSUB, you could write:
SUBROUTINE VTOSUB(ID, TIME, PAR, NPAR, DFLAG,
& IFLAG, RESULT)
C
C
INTEGER ID
DOUBLE PRECISION TIME
DOUBLE PRECISION PAR(*)
INTEGER NPAR
LOGICAL DFLAG
INTEGER IFLAG
DOUBLE PRECISION RESULT(3)
INTEGER N, ANSWER, IDX
C Compute values in RESULT
……
C Check values
N = 3
CALL NANINF( RESULT, N, ANSWER, IDX )
IF(ANSWER.EQ.1) THEN
C Print value of IDX and stop. Review the code
WRITE(*,*) 'Value NaN found at IDX = `, IDX
STOP
ENDIF
C
RETURN
END