Reputation: 181
I have the following code:
if (complex) then
read(unitvector) (CoefC(jl),jl=1,NV)
endif
Where a user indicates if the data is a collection of complex numbers. Now, if the user indicates that it is, but it actually isn't, i get error 67 (input requires too much data). How can i trap that, so i can write that perhaps a user made a mistake. I was thinking it would look something like:
read(unitvector, ioStat=iocplx) (CoefC(jl),jl=1,NV)
but where would i put the "if" to check for the error?
Upvotes: 1
Views: 763
Reputation: 59999
That depends on the overall logic of the program, we cannot tell you the best way for you from such small code snippet. You can try something like (not tested):
if (complex) then
read(unitvector, ioStat=iocplx) (CoefC(jl),jl=1,NV)
if (iocplx/=0) stop "Error reading the complex data."
end if
or
if (complex) then
read(unitvector, ioStat=iocplx) (CoefC(jl),jl=1,NV)
if (iocplx/=0) then
write(*,*) "Error reading the complex data, triung real."
complex = .false.
backspace(unitvector)
read(unitvector, ioStat=ioreal) (CoefR(jl),jl=1,NV)
if (ioreal/=0) then
stop "Error reading real data."
end if
end if
end if
But you really did not specify what you want, stop the program and write a meaningful message? Read data some other way? Everything is possible and we do not have a crystal ball.
Upvotes: 1