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

IOSTAT behavior in ifort?

doctoromega1234
Beginner
486 Views

Hi guys,

I can't seem to understand why iostat is behaving the way it does when it compiles. Here is the program:
-------------------------------------------------
PROGRAM ERROR

IMPLICIT NONE

INTEGER :: x,k

DO

read (*,*, iostat=k ) x

write (*,*) k, 'this is the iostat value'
if ( k == 0 ) exit
END DO

write (*,*) 'Now out of loop'

END PROGRAM
-------------------------------------

All I want to be able to do is to be able to tell when the user does not enter in an integer and to give him a second chance to enter in a valid number.

This iostat method above seems to do the job for all non integer values except the letters " f ", " t ", " , " , " / ", and all real values. Why is this the case? Can anyone explain what's going on? Or if there is another method to achieve what I set out to do.

Thanks,

-Jason.

0 Kudos
1 Reply
Steven_L_Intel1
Employee
486 Views
List-directed input is designed to be flexible - more so than you want it to be. f and t are accepted as FALSE and TRUE - it is an extension that these are accepted when the variables are not LOGICAL. Comma and slash indicate an omitted value which does not change the variable. Real values are converted to integer, per the standard.

Do not use list-directed input to "validate" user input. You can get closer to what you want by reading with an I5 format or somethng similar - this will be much less accepting of non-integer values. Or read into a string and scan it for valid characters.
0 Kudos
Reply