Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
New Contributor II
23 Views

empty iomsg after read error (suggested improvement)

Hello,

usually the Fortran runtime is supposed to provide a meaningful error message in the IOMSG variable after certain IO error conditions encountered (e.g. for input from the user, I report IOMSG back)

I wanted to share the following observation where the error message is empty despite an error occurred (in list-directed, internal read of a real number, upon encountering parentheses; compiled with ifort 19.0.3):

program p
	implicit none
	character(len=:), allocatable :: str
	real :: x
	character(len=99) :: iomsg
	integer :: iostat 

	! Case 1: iostat=24, iomsg=""
	str = "(1"
	x = 0.0; iostat = 0; iomsg = ""
	read(str, *, iostat=iostat, iomsg=iomsg) x
	print *, x, iostat, '"', trim(iomsg), '"'

	! Case 2: iostat=59, iomsg=""
	str = "(1)"
	x = 0.0; iostat = 0; iomsg = ""
	read(str, *, iostat=iostat, iomsg=iomsg) x
	print *, x, iostat, '"', trim(iomsg), '"'
end program

Is this supposed to be like that? Maybe this could be an improvement in future (@Intel)?
Gfortran reports "Bad real number in item 1 of list input" in both cases.

Also, according to https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-list-of-run-time-err..., the value 24 is not even supposed to be assumed by the IOSTAT variable at all(?).

Kind regards,
Ferdinand

 

 

 

 

 

0 Kudos
1 Reply
Highlighted
Black Belt Retired Employee
23 Views

If you got a non-zero IOSTAT, IOMSG should have been filled in. If not, that's a bug.

You're also right that a READ should return -1 for IOSTAT on an EOF and not 24.

0 Kudos