Saved Bookmarks
| 1. |
How Do I Read Until The End Of A File (eof)? |
|
Answer» A common Fortran 95 idiom for reading lines until the end of FILE is INTEGER :: stat character(len=100) :: buf open(15, file='foo.txt') do read(fh, iostat=stat) buf if (stat /= 0) exit ! process buf end do close(15)This example catches all conditions, not just the end of file. To specifically catch the EOF in Fortran 2003 one can USE the iso_fortran_env module and REPLACE the if condition above with if (stat == iostat_end) exitA common Fortran 95 idiom for reading lines until the end of file is This example catches all conditions, not just the end of file. To specifically catch the EOF in Fortran 2003 one can use the iso_fortran_env module and replace the if condition above with |
|