Runtime file reading error

  • Thread starter chaim
  • Start date
  • #1
5
0

Main Question or Discussion Point

I frequently get the same runtime error when using g77. Here is the error message:

fmt: end of file
apparent state: unit 16 named vi1.src
last format: (F10.6)
lately reading sequential formatted external IO

abnormal program termination

I have added to my code the REWIND statement after my OPEN statement as you can see in the code below but this has not helped me. I know that the error means that the pointer is at the end of the input file, but I think that the REWIND should solve this problem. Where am I going wrong??

Code:

PROGRAM CloudCoverV1
INTEGER NH,TR,ACC
DIMENSION VI(8788), VF(8788)
c=================================================================
OPEN(UNIT=16, FILE='vi1.src', ACCESS='SEQUENTIAL',STATUS='OLD',
$FORM='FORMATTED')
REWIND (UNIT=16)
c=================================================================



READ(UNIT=16, FMT=55) NH
55 FORMAT (I5)
DO 60, NH = 1,NH
READ(UNIT=16, FMT=56) VI
56 FORMAT (F10.6)
60 CONTINUE
c====================================================================
OPEN(UNIT=18, FILE='test1.out', STATUS='NEW', FORM='FORMATTED')
c=====================================================================

DO 110, TR = 1, 20
WRITE(UNIT=17, FMT=111) VI(NH)
111 FORMAT (F10.6)
110 CONTINUE


c====================================================================
OPEN(UNIT=17, FILE='CCV1.out', STATUS='NEW', FORM='FORMATTED')
c=====================================================================

DO 12, ACC = 1,NH

IF (VI(NH) .LT. 100) VF(NH) = VI(NH)
IF (VI(NH) .LT. 100) GOTO 12

IF (VI(NH) .EQ. 100) THEN
CALL INTERPOLATE(NH)

ENDIF
12 CONTINUE

c=================================================================
DO 120, NH = 1, 100
WRITE(UNIT=17, FMT=100) VF(NH)
100 FORMAT (F10.6)
120 CONTINUE
c===================================================================
CLOSE(UNIT=16)
CLOSE(UNIT=17)
CLOSE(UNIT=18)

END PROGRAM CloudCoverV1




SUBROUTINE INTERPOLATE(NH)
INTEGER NH
INTEGER NUME,VAL
DIMENSION VI(8788)
DO 80,NH = NH,NH+24
NUME = 0
IF (VI(NH) .EQ. 100) NUME = NUME + 1
IF (VI(NH) .NE. 100) EXIT
80 CONTINUE
IF ((VI(NH-NUME)- VI(NH+1)) .GT. 0.0) THEN
DO 77, VAL = NH-NUME,NH
VI(VAL) = VI(NH-NUME)-((VI(NH-NUME)- VI(NH+1))/(NUME+1))
77 CONTINUE

ELSEIF ((VI(NH-NUME)- VI(NH+1)) .LT. 0.0) THEN
DO 99, VAL = NH-NUME,NH
VI(VAL)=VI(NH-NUME)+((VI(NH+1)- VI(NH-NUME))/(NUME+1))
99 CONTINUE
ENDIF
RETURN
END SUBROUTINE INTERPOLATE
 

Answers and Replies

  • #2
33,496
5,188
Caveat: The last fortran programming I did was about 15 years ago.
Your REWIND statement comes right after you open the input file. When you open the file, the file pointer is pointing to the first data in the file, so rewinding doesn't move the file point, so won't affect anything.

In any case, rewinding the file is just a kludge to paper over the real problem, which I believe is related to the line below.

This line is very bad:
Code:
DO 60, NH = 1,NH
You don't want your loop control variable to be the same as the starting or ending value.
 
  • #3
5
0
Yes, Mark44, I appreciate your comment, but the loop has nothing to do with the runtime abend. I still need to know the reason for the abend. Especially what is the meaning of the first line:

fmt: end of file
 
  • #4
33,496
5,188
I believe that the loop has everything to do with your error. Is abend German for error?

I don't have a fortran compiler any more, so I can't test the behavior of that loop, but you need to fix it. The first number in your input file, vi1.src, indicates the number of items that follow it.

The loop control variable should be, say, I, so that the loop executes NH times. That way the loop will stop reading input values at the right place, and you won't have the error of trying to read past the end of data in your file.

Instead of this
Code:
DO 60, NH = 1,NH
change to this
Code:
DO 60, I = 1,NH
 
  • #5
5
0
Mark44, I made the changes that you suggested and I still get the same error. I would like to add that I get this error with different programs. The odd thing is that "sometimes" the program works and then stops working. I think that the external data file is in some way being corrupted, but I cannot figure out what is happening.
 
  • #6
33,496
5,188
I didn't notice this before, but I'm pretty sure the line marked with <--- is causing you problems as well.

Code:
DIMENSION VI(8788), VF(8788)
.
.
.

READ(UNIT=16, FMT=55) NH
55 FORMAT (I5)
DO 60, NH = 1,NH 
READ(UNIT=16, FMT=56) VI <---
56 FORMAT (F10.6)
60 CONTINUE
You should be reading from the input file to one element of your array; i.e., to VI(I), assuming you are using I for the loop control variable for that loop.

There are a number of other errors in your code.
1.
Code:
DO 110, TR = 1, 20
WRITE(UNIT=17, FMT=111) VI(NH)
111 FORMAT (F10.6)
110 CONTINUE
This loop writes the same value, VI(NH), to your output file 20 times. I doubt this is what you intended. Notice that TR starts off at 1 and is incremented by 1 each time until it gets to 21, the first value that is too large. The apparent intent of this loop is to write the first 20 values of the VI array to the output file.

2. The block below has a similar problem.
Code:
DO 12, ACC = 1,NH

IF (VI(NH) .LT. 100) VF(NH) = VI(NH)
IF (VI(NH) .LT. 100) GOTO 12 

IF (VI(NH) .EQ. 100) THEN
CALL INTERPOLATE(NH)

ENDIF
12 CONTINUE
Everywhere you have VI(NH) or VF(NH), you should be using your loop control variable, ACC. IOW, where it says VI(NH), it should be VI(ACC). Same for the VF array.

3. Same with this block.
Code:
DO 120, NH = 1, 100 
WRITE(UNIT=17, FMT=100) VF(NH) 
100 FORMAT (F10.6) 
120 CONTINUE
4. In your subroutine you are declaring an array named VI. This array is different from the one you have declared above it, even though both have the same name and the same number of elements. You should be passing this array to your subroutine as a parameter.

5. In the subroutine again you have this loop.
Code:
DO 80,NH = NH,NH+24
NUME = 0
IF (VI(NH) .EQ. 100) NUME = NUME + 1
IF (VI(NH) .NE. 100) EXIT
80 CONTINUE
The line DO 80 NH = NH, NH + 24 is bad for at least a couple of reasons:
a) NH is a parameter passed into your subroutine. It should not also be used as a loop control variable.
b) Setting a variable to its own value is always silly.
 
  • #7
5
0
Mark44, Yes after thourough checking of the program you are correct. I was trying to read more records than existed in the input file. Also all your remarks concerning my syntax problems will be corrected. Just one question that you may be able to help me with. How can I make my arrays VI(8788) and VF(8788) accessable to both the main program and the subroutine. That is I would like both the main and the subroutine to be able to update both of the arrays?
 
  • #8
33,496
5,188
Something like this:
Code:
PROGRAM CloudCoverV1
INTEGER NH = 8788
c - other declarations

REAL VI(NH), VF(NH)
.
.
.
CALL INTERPOLATE(VI, NH)
...
END PROGRAM CloudCoverV1


SUBROUTINE INTERPOLATE(Array, NH)
INTEGER NH
REAL Array(NH)
c Declarations of subroutine local variables
.
.
.
 
RETURN 
END SUBROUTINE INTERPOLATE
 

Related Threads on Runtime file reading error

Replies
5
Views
895
Replies
2
Views
19K
Replies
2
Views
7K
Replies
19
Views
3K
Replies
4
Views
6K
  • Last Post
Replies
17
Views
739
  • Last Post
Replies
1
Views
4K
Replies
4
Views
8K
  • Last Post
Replies
12
Views
5K
Top