      program rwinfn
************************************************************************
*     (Read/write Infinity and NaN)
*     Program to test whether Infinity and NaN can be output to a text
*     file, and then input correctly.
*     (30-Nov-2001)
************************************************************************
      character*50 line
      real arg, s, x, nan, inf
      logical isnan, ispinf, isninf

      isnan(arg)  = (arg .ne. arg)
      isninf(arg) = (arg .eq. -inf)
      ispinf(arg) = (arg .eq. inf)

      open (unit = 1, file = 'rwinfnan.tmp', status = 'unknown',
     x     access = 'sequential', form = 'formatted')

      s = 0.0
      x = s
      inf = 1.0/s
      nan = x/s

      write (1,*) nan
      write (1,*) inf

      rewind (1)
      read (1,'(a)') line
      write (6,*) 'NaN was written as: ', line
      read (1,'(a)') line
      write (6,*) 'Inf was written as: ', line

      rewind (1)
      read (1,*) x
      if (isnan(x)) then
           write (6,*) 'NaN was correctly input'
      else
           write (6,*) 'NaN was INCORRECTLY input as ', x
      endif

      read (1,*) x
      if (x .eq. x) then
           write (6,*) 'Inf was correctly input'
      else
           write (6,*) 'Inf was INCORRECTLY input as ', x
      endif

      end
