program TTPV
c This program reads data from a file, then calculates the average
c of the data and displays it in a readable table.
c *******Nathaniel Hayes 4/02/08 ***********
CHARACTER*2, TCH
integer EOF, TIME, COUNT
logical TEST
real TEMP, PRES, VOL, SUMT, SUMP, SUMV, ASUMT, ASUMP, ASUMV
DATA COUNT, TCH, SUMT, SUMP, SUMV/0, 'am', 3*0.0/
c ***Prep by opening the File*****
open (UNIT=15, FILE='free.txt', STATUS= 'OLD')
c ***Set up the Formats to be used throughout the program***
100 FORMAT(1x, I4.4, A3, F10.1, F12.1, F10.1)
110 FORMAT(1X, 'AVERAGES', F10.3, F12.3, F10.3)
c ***Set up the Header of the Table****
Print *, 'Time', ' Temperature', ' Pressure', ' Volume'
Print *, '====', ' ===========', ' ========', ' ======'
c ***Read the file and execute minor adjustments***
read(UNIT=15, FMT=*, IOSTAT=EOF) TIME, TEMP, PRES, VOL
10 if(EOF .GE. 0) THEN
COUNT=COUNT+1
c ***Change to military time and add appropraite time stamp***
TEST = .TRUE.
if(TIME .GE. 1200) TEST = .FALSE.
if(TIME .GE. 1300) TIME=TIME-1200
if(test) then
goto 20
else
TCH='pm'
endif
c ***Start the average calculations and print the numbers***
20 SUMT=SUMT + TEMP
SUMP=SUMP + PRES
SUMV=SUMV + VOL
print 100, TIME, TCH, TEMP, PRES, VOL
read(UNIT=15, FMT=*, IOSTAT=EOF) TIME, TEMP, PRES, VOL
goto 10
end if
c ***Finish the average calculations and End the tables***
ASUMT=SUMT/COUNT
ASUMP=SUMP/COUNT
ASUMV=SUMV/COUNT
print *, '======================================='
print 110, ASUMT, ASUMP, ASUMV
end