PROGRAM readfile
!
! Author:  Br. David Carlson
!
! Date:  March 3, 2000
!
! This program reads in floats from the text (formatted) file readfile.dat
! and displays them on the screen.  Nothing else is done.  This program was
! written simply to show how to read data from such a file.

IMPLICIT NONE

REAL::item
INTEGER::status

OPEN (UNIT=5, FILE='readfile.dat', STATUS='OLD', ACTION='READ', IOSTAT=status)

IF (status == 0) THEN
   DO
      READ (5, *, IOSTAT=status) item
      IF (status /= 0) THEN  ! exit from the loop, we're probably at end of file
         EXIT
      END IF
      WRITE (*, 100) item
   END DO

   IF (status > 0) THEN
      WRITE (*, *) 'A read error has occurred.'
   ELSE
      WRITE (*, *) 'End of file has been reached.'
   END IF
   CLOSE (UNIT=5)
ELSE
   WRITE (*, *) 'Error opening file readfile.dat, IOSTAT = ', status
END IF

100 FORMAT (' ', F12.5)

END PROGRAM

