      LOGICAL FUNCTION VALID (R)
      INTEGER R
*
* Set FALSE if R = bad value flag, TRUE if not
*
* Cleaned up version of the VMS specific VALID function supplied by
* Oxford University. Converted to (almost) standard Fortran 77.
*
* Also made it test against two different 'null' values (see BADVAL.INC)
*
* Passed variables...
*   R      - Input value to be tested (real number but passed as integer)
*
* Local variables...
*   IVAL   - Integer equivalent of R
*   RVAL   - Real equivalent of R
*
      INTEGER IVAL
      REAL    RVAL
      EQUIVALENCE (IVAL, RVAL)

      INCLUDE 'badval.inc'

      IVAL  = R
*
* The two tests!  The second test is only done if the first one shows the
* value to be 'valid' real - testing 'invalid' reals would give an error!
*
      VALID = IVAL .NE. INVREA
      IF (VALID) VALID = (RVAL .NE. NULREA)

      RETURN
      END
