I have this problem. I have a big code which launches an external operation and i need to wait until this operation is finished.
I have a text file which gives me information about this external procedure. When a certain word is written in that file, then i know that the procedure has been terminated and that i can continue to execute the next operation.
The further complication is that the external procedures writes the code while it runs, therefore, it can happen that i read the text file too early and that the magic word has not already been written in the text file, therefore i need to read the text file multiple times until the magic word has been written.
This is the prototype that i wrote.
5 open(unit=123,file='textfile.text')
10 read(123, '(A)', end = 20) line
ind=index(line,'magic word')
if (ind .ne. 0) then
write(*,*)
print *, line
goto 30
endif
goto 10
20 close (123)
goto 5
30 continue
close (123)
This code acts like this: it scans the file 'textfile.text' looking for the magic word, and, if it doesn't find it, it reads the file till the end, closes it and opens it again to keep looking for the word. When it finds the word, it stops looking for the magic word, it closes the file and goes to the next operation.
This code worked fine for the first 2283 iterations, but then it failed, can someone tell me why it failed?
The error that i received is:
At line 355 of file rfi_na.F
Fortran runtime error: End of file
Line 355 is: read(111,*) name1, name2, misfitval
The error arises because the 111 file is empty. It is a consequence of something bad happened in the previous lines, in the part of the code written above.
Any suggestion would be greatly appreciated,
Angelo Sajeva,
PhD student, Pisa, Geophysics
I have a text file which gives me information about this external procedure. When a certain word is written in that file, then i know that the procedure has been terminated and that i can continue to execute the next operation.
The further complication is that the external procedures writes the code while it runs, therefore, it can happen that i read the text file too early and that the magic word has not already been written in the text file, therefore i need to read the text file multiple times until the magic word has been written.
This is the prototype that i wrote.
5 open(unit=123,file='textfile.text')
10 read(123, '(A)', end = 20) line
ind=index(line,'magic word')
if (ind .ne. 0) then
write(*,*)
print *, line
goto 30
endif
goto 10
20 close (123)
goto 5
30 continue
close (123)
This code acts like this: it scans the file 'textfile.text' looking for the magic word, and, if it doesn't find it, it reads the file till the end, closes it and opens it again to keep looking for the word. When it finds the word, it stops looking for the magic word, it closes the file and goes to the next operation.
This code worked fine for the first 2283 iterations, but then it failed, can someone tell me why it failed?
The error that i received is:
At line 355 of file rfi_na.F
Fortran runtime error: End of file
Line 355 is: read(111,*) name1, name2, misfitval
The error arises because the 111 file is empty. It is a consequence of something bad happened in the previous lines, in the part of the code written above.
Any suggestion would be greatly appreciated,
Angelo Sajeva,
PhD student, Pisa, Geophysics