Reading records from a file in FORTRAN66 using stdin adding extra unwanted junk
I'm trying to read a file in the format specified below using FORTRAN 66.
1000 MS 1 - Join Grps Group Project 5 5 Four Programs Programming 15 9 Quiz 1 Quizzes 10 7 FORTRAN Programming 25 18 Quiz 2 Quizzes 10 9 HW 1 - Looplang Homework 20 15
I execute and read the file like so:
program < grades.txt
The first line is the total number of points that can be earned in a class The rest of the lines are assignments in a class Each line is formatted as such: Assignment name(20 chars) category (20 chars) possible points(14 chars) earned points(14 chars)
For some reason, when the code runs and reads the file, starting at the first assignment record, I get error 5006, and cannot find an explanation of the error code. The output of the program while debugging looks like this:
$ file < grades.txt MS 1 - Join Grps Group Project 5 6417876 NOT EOF EOF 5006 NAME CATEGORY POSSIBLE EARNED
My goal is to be able to read each line and put each column into it's appropriate array, then reference those arrays later on to print a report for each category, with each assignment, points possible, earned, and total percentage for the category, then loop, etc. I do not understand where the "6417876" in the output is coming from, it is definitely not part of the file that's being piped into stdin while the program reads. The code for the program is as follows:
CHARACTER*20 ASSIGNMENTT(100) CHARACTER*20 CATEGORY(100) INTEGER POSSIBLE(100) INTEGER EARNED(100) INTEGER TOTALPTS INTEGER REASON INTEGER I, N READ(5,50)TOTALPTS 50 FORMAT(I4) c Read the arrays in I=1 100 READ(5,110,IOSTAT=REASON)ASSIGNMENTT(I),CATEGORY(I),POSSIBLE(I),EARNED(I) 110 FORMAT(2A20x,2I14x) WRITE(*,110)ASSIGNMENTT(I),CATEGORY(I),POSSIBLE(I),EARNED(I) I=I+1 IF (REASON < 0) GOTO 120 WRITE(*,*)"NOT EOF" IF (I<100 .AND. REASON == 0) GOTO 100 WRITE(*,*)"EOF", REASON c Get the number of items (For some reason stdin adds an extra item that's not in the file, so I subtract 2 instead of 1 120 N=I-2 c Display the Names and Ages WRITE(*,200) 200 FORMAT("NAME",T20,"CATEGORY",T40,"POSSIBLE",T54,"EARNED",T68) DO 300 I=1,N 210 FORMAT(A20,A20,I14,I14) 300 WRITE(*,210)ASSIGNMENTT(I),CATEGORY(I),POSSIBLE(I),EARNED(I) END
What could be causing the read issues I'm facing?
The line to read the file contents was too long, so I shortened the names of the variables to save some space and the problem was solved.