Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28446 Discussions

Fortran Runtime Library (forrtl) error numbers and iostat values

TomBayesQ
Beginner
611 Views

Hi,
I am working on improving error handling in my codes, and have ran into some questions:

1) When reading a file, I want to check “iostat” values to see whether EOF is reached (IVF seems to set "iostat=-1" for EOF condition).

Is there some named/parameterised value that can be used instead of hardcoding "-1"?

I’d like something similar to "FOR$IOS_ENDDURREA" (forrtl=24), but for iostat values instead.

And some follow on questions - would appreciate some general guidance:

2) I noticed that in some cases the "iostat" error numbers match "forrtl" numbers, but sometimes not.  Are there any rules on how/why/when they do or don’t match? Can you suggest a good practice for using these facilities in a robust and portable way?

3) Any comments on exception handling in general in Fortran?  Does anyone have some simple examples?  And what do people use? Forrtl error numbers?  Or IEEE modules?

Thanks in advance!
Tom

0 Kudos
5 Replies
IanH
Honored Contributor II
611 Views

The intrinsic function IS_IOSTAT_END (which has a brother called IS_IOSTAT_EOR) can be used to test the variable.  You can also compare the value of the variable against the named constant IOSTAT_END (who has a sister IOSTAT_EOR) from the ISO_FORTRAN_ENV intrinsic module.  Use of these standard facilities for these two particular conditions is robust and portable.

When I've needed it (which isn't often), for detecting IEEE numeric exceptions I've use the facilities from the IEEE_* intrinsic modules.  You need to be mindful about whether the exception flags propagate into and out of a procedure, but bar that it is simply a case of calling IEEE_GET_FLAG at the end of the calculation sequence of interest.

 

0 Kudos
TomBayesQ
Beginner
611 Views

Thanks Ian - I will investigate the ISO_FORTRAN_ENV intrinsic module.

Just wondering whether anyone has ideas regarding the RTL and IOSTAT mismatch in 2 above?

0 Kudos
Steven_L_Intel1
Employee
611 Views

Which cases did you have in mind?

The standard specifies that IOSTAT values for EOF and EOR are negative and that they be different. EOF for IOSTAT therefore has to be different from the ENDDURREA RTL error code. The ISO_FORTRAN_ENV intrinsic module (and the IS_IOSTAT_xxx intrinsics) were created so that you didn't have to depend on implementation-specific values.

0 Kudos
TomBayesQ
Beginner
611 Views

Hi Steve,

Thanks - as usual your responses make the original question look mis-informed! :-)

regards,

Tom

0 Kudos
Steven_L_Intel1
Employee
611 Views

Not at all - it's a reasonable question. As Ian and I wrote above, the intrinsics and constants were added to the language to help with this problem.

0 Kudos
Reply