- #1
dorado29
- 17
- 0
Homework Statement
Write a program that reads the time, temperature, pressure, and volume measurements from a data file like :
0900015001990700
1000019602210877
1100021202790925
1234034203221015
1300038803221121
1400044803241425
1503051303201520
1604055503181665
1700061303191865
1800067503232080
1900072103282262
2005076803252564
2100083503272869
2200088903303186
The program has to convert the first 4 digits of each line from military time to a result that prints out in standard time with AM and PM indicated. The program has to print out that time and the temp, pressure and volume in this form:
Time Temp Press Volume
======================================
12:00PM 34.2 32.2 101.5
- - - -
- - - -
10:00PM 88.9 33.0 318.6
======================================
Averages 75.4 41.7 193.2
Each 4 numbers from the data line apply to time, temp, pressure and volume respectively
0900015001990700
"0900" is the time, "0150" is temperature, etc
Here's what I've done so far:
PROGRAM TABLE
CHARACTER*2 TIMVAL
INTEGER COUNT, EOF, MLTIME, A, B
REAL TEMP, VOL, PRES, AVTEMP, AVVOL, AVPRES
REAL SUMT, SUMV, SUMP
COUNT=0
SUMT=0.0
SUMP=0.0
SUMV=0.0
A = 0
B = 0
MLTIME=0
OPEN (UNIT = 15, FILE = 'FORMAT1.TXT', STATUS = 'OLD')
PRINT *
90 FORMAT(1X, A6, 6X, A11, 7X, A8, 6X, A6)
PRINT 90, 'TIME', 'TEMPERATURE', 'PRESSURE', 'VOLUME'
PRINT*,'======================================================='
100 FORMAT(1X, I2.2, ':', I2.2, A3, 7X, F4.1, 13X, F4.1, 8X, F5.1)
110 FORMAT(1X, I2.2, I2.2, T5, F4.1, T9, F4.1, T13, F4.1)
READ (UNIT = 15, FMT = 110, IOSTAT = EOF) A, B, TEMP, PRES, VOL
DO WHILE(EOF .GE. 0)
IF(A .GE. 12) THEN
TIMVAL = 'PM'
ELSE
TIMVAL = 'AM'
END IF
IF(A .GE. 13) THEN
A = A - 12
END IF
PRINT 100, A, B, TIMVAL, TEMP, PRES, VOL
COUNT = COUNT + 1
SUMT = SUMT + TEMP
SUMP = SUMP + PRES
SUMV = SUMV + VOL
READ (UNIT = 15, FMT = 110, IOSTAT = EOF) A, B, TEMP, PRES, VOL
END DO
(the averages part of the program should go here but I'm not having problems with
it)
END
I'll post a picture of the output shortly.. For some reason copy paste isn't being very nice.
Anywho, my problem lies with blanks and zeros. The first few lines of the ouput involving data is:
00:00AM 0.0 0.0 0.0
10:00AM 1.9 **** 108.7
11:00AM 2.1 **** 909.2
12:34PM **** **** 210.1
etc...
from the data
0900015001990700
1000019602210877
1100021202790925
1234034203221015
it seems that where the data is read from after "time" is shifted. instead of reading "0877" and printing "87.8" it reads "1087" and prints "108.7"
Do you guys see anything glaringly wrong with the program? My professor doesn't cover any of this and isn't available to help.