I am trying to open an ASCII file with unknown number of lines (but fixed number of entries in each line - please see example file below). It goes to the end of the file, but fails after that.
Option 1: Using iostat statement: I get the same error when using either "Use, intrinsic :: iso_fortran_env, Only : iostat_end" or simply treating io as an integer.
Option 2: Using "end= .." option. This is what I have used earlier (F77).
Both approaches should work in principle, but neither does. Any help in fixing this will be greatly appreciated.
Thanks, Pinaki.
Program:
!=======================================!
program read
!=======================================!
! Use, intrinsic :: iso_fortran_env, Only : iostat_end
implicit none
integer :: i,io,n
n=0
open(10,file='a.dat',status='old',action='read')
!=================================!
! option 1
!=================================!
do
read(10,*,iostat=io)
write(*,*)io
! if (io.eq.iostat_end) exit
if (io.ne.0) exit
n=n+1
write(*,*)'n=',n
enddo
!=================================!
!=================================!
! option 2
!=================================!
do 10 i=1,1000000
read(10,*,end=10)
n=n+1
write(*,*)n
10 continue
!================================!
close(10)
write(*,*)'n=',n
end program read
!======================!
Compiled using "gfortran --std=f2003 -o read.out read.f90"
Error message:
==============================================
dyld: lazy symbol binding failed: Symbol not found: ___emutls_get_address
Referenced from: /usr/local/opt/gcc/lib/gcc/11/libgfortran.5.dylib
Expected in: /usr/lib/libSystem.B.dylib
dyld: Symbol not found: ___emutls_get_address
Referenced from: /usr/local/opt/gcc/lib/gcc/11/libgfortran.5.dylib
Expected in: /usr/lib/libSystem.B.dylib
Program received signal SIGABRT: Process abort signal.
Backtrace for this error: #0 0x105364f8e #1 0x10536419d #2 0x7fff6eed05fc zsh: abort ./read.out
=====================================================
File I am trying to read:
=====================================================
1 -1.1559859375 2.0399371094 0.1686166667 0.8242152778
2 -1.1618015625 2.1375250000 0.1765231481 0.8105046296
3 -1.1696710937 2.2325417969 0.1860513889 0.7936782407
1 -1.1730312500 2.3271382813 0.1975254630 0.7718773148
2 -1.1767945313 2.3942726563 0.2113162500 0.7446933333
3 -1.1694437500 2.4738000000 0.2281966667 0.7099266667
1 -1.1566140625 2.5312164063 0.2494466667 0.6636841667
2 -1.1293765625 2.5746707031 0.2747766667 0.6066154167
3 -1.0836390625 2.5938144531 0.3026616667 0.5403733333
1 -1.0380632812 2.5721433594 0.3302462121 0.4727159091
=======================================================================