I am trying to read and display data from a text file in FORTRAN. Eventually I want to store the data in an array to calculate specific averages but right now I am having trouble getting the data to be read and displayed. With the code below I am getting a program error "STOP ***Input error***". Help would be much appreciated. Below is the code I have been working on and here is a link to the text file containing the data
Code:
PROGRAM testx
IMPLICIT NONE
CHARACTER(20) :: FileName
INTEGER :: Count = 0, OpenStatus, InputStatus
REAL :: Y, M, D, Rain, Tmax, Tmin, srain, stmax, stmin
! Open the file as unit 15.
! Input and output formats and proper display
WRITE (*, '(1X, A)', ADVANCE = "NO") "Enter name of data file:"
READ *, FileName
OPEN (15, FILE = FileName, STATUS = "OLD", IOSTAT=OpenStatus)
IF (OpenStatus > 0) STOP "***Cannot open the file ***"
99 FORMAT (1X, A5, 1X, A5, 1X, A4, 1X, A8, A8, A8)
100 FORMAT (1X, I4, 1X, I2, 1X, I2, 1X, F4.2, 1X, F4.2, F4.2)
PRINT 99, "Year", "Month", "Day", "Rainfall", "MaxTemp", "MinTemp"
PRINT 99, "====", "=====", "===", "========", "=======", "======="
! Read the data line by line
! Display the data in a table
DO
READ (15, FMT=100, IOSTAT=InputStatus) Y, M, D, Rain, Tmax, Tmin
IF (InputStatus > 0) STOP "***Input error ***"
IF (InputStatus < 0) EXIT ! end of file
PRINT 100, Y, M, D, Rain, Tmax, Tmin
END DO
END PROGRAM testx