PROGRAM Temperature_Volume_Readings_2
!-----------------------------------------------------------------------
! Program to read temperatures and volumes from a file containing
! time, temperature, pressure, and volume readings made by some
! monitoring device.  The temperature and volume measurements are
! displayed in tabular form.  Format specifiers for these files
! are entered during execution.  Variables used are:
!   FileName     : name of data file
!   OpenStatus   : status variable for OPEN statement
!   InputStatus  : status variable for READ statement
!   Form         : input format specifier
!   Temperature  : temperature recorded
!   Volume       : volume recorded
!
! Input (file):    Collection of temperature and volume readings 
! Input (keyboard): Format specifiers
! Output (screen):  Table of readings
!-----------------------------------------------------------------------

  IMPLICIT NONE
  CHARACTER(50) :: Form, FileName*20
  INTEGER :: OpenStatus, InputStatus    
  REAL :: Temperature, Volume

  ! Open the file as unit 15.  If successful, set up the 
  ! input and output formats, and display the table heading

  WRITE (*, '(1X, A)', ADVANCE = "NO") "Enter name of data file: "
  READ *, FileName
  OPEN (UNIT = 15, FILE = FileName, STATUS = "OLD", IOSTAT = OpenStatus)
  IF (OpenStatus > 0) STOP "*** Cannot open the file ***"

  PRINT *, "Enter input format for ", FileName
  READ '(A)', Form

  110 FORMAT(1X, A11, A10)
  120 FORMAT(1X, F8.1, F12.1)
  PRINT *
  PRINT 110, "Temperature", "Volume"
  PRINT 110, "===========", "======"

  ! While there is more data, read temperatures and volumes,
  ! display each in the table, and calculate the necessary sums

  DO
     READ (UNIT = 15, FMT = Form, IOSTAT = InputStatus) Temperature, Volume
     IF (InputStatus > 0) STOP "*** Input error ***"
     IF (InputStatus < 0) EXIT  ! end of file

     PRINT 120, Temperature, Volume
  END DO

  CLOSE (15)
      
END PROGRAM Temperature_Volume_Readings_2
