Recursive I/O error from INQUIRE + OPEN(NEWUNIT=

Recursive I/O error from INQUIRE + OPEN(NEWUNIT=

See below. Running it causes an error 40 somewhere after the 3rd call to macopen1. Am I doing anything wrong?

I am using IA-32, Version Build 20130607.

Compiler command line flags are

/nologo /debug:full /Od /assume:buffered_io /fpp /I"..\..\..\.."
/I"..\..\..\program_files\schlumberger\pipesim\Debug\libs" /warn:errors
/debug-parameters:all /warn:declarations /warn:interfaces /real_size:64
/Qauto /align:dcommons /align:sequence /Qtrapuv /fpe:0 /fpconstant
/module:"Debug/" /object:"Debug/" /Fd"Debug\vc110.pdb" /traceback
/check:pointer /check:bounds /check:uninit /libs:dll /threads /c

Linker command line is

/OUT:"Debug\psimstub.exe" /INCREMENTAL /NOLOGO /LIBPATH:"..\..\..\program_files\schlumberger\pipesim\Debug\libs"
/MANIFEST /MANIFESTFILE:"D:\q_two\main\pipesim\engines\components\psimstub\Debug\psimstub.exe.intermediate.manifest"
/MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG
pnet.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib
advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib

Sorry but I can't get the SELECT MEDIA button to work so here is the source:


program main
implicit none

integer u1,u2,u3, ierr

!-----open a file
call macopen1(u1,'fred',ierr)
write(u1,*) 'hello u1'
print *, 'u1 is ',u1

!-----open the same file again: different LUN variable
call macopen1(u2,'fred',ierr)

write(u1,*) 'hello agen u1'
write(u2,*) 'hello u2'
print *, 'u2 is ',u2

!-----open another file
call macopen1(u3,'sid',ierr)

!-----one of the following will produce error 40, "recursive I/O operation"
write(u1,*) 'hello agen u1'
write(u2,*) 'hello agen u2'
print *, 'u3 is ',u3
write(u3,*) 'hello u3'



subroutine macopen1(unit,afnam,ierr)

implicit none

integer , intent(inout) :: unit ! unit number
character*(*), intent(in ) :: afnam ! file name
integer , intent(out ) :: ierr ! IOSTAT= result

character*12 eaccess
character*12 eform
character*12 estatus
character*12 mmode
character*12 mshare
character*1024 fnam ! local file name
character*256 msg
integer uu, jerr
logical isopen, does_exist

fnam = trim(afnam)
ierr = 0
msg = ' '
estatus = 'UNKNOWN'
mshare = 'DENYWR'
mmode = 'READWRITE'
eform = 'FORMATTED'
eaccess = 'SEQUENTIAL'

!-----if the file is allready open on a different unit, return that unit
msg = ' '
isopen = .false.
inquire ( file=fnam, opened=isopen, number=uu, iostat=jerr, err=886, iomsg=msg )
886 continue
if( print *,' error from INQUIRE: ',trim(msg)
if(isopen) then
inquire ( file=fnam, number=uu, iostat=jerr, err=887 )
887 continue
unit = uu
ierr = 0
goto 900

!-----open the file
msg = ' '
open(newunit=unit, file=fnam, err=888, share=mshare, action=mmode, status=estatus, &
form=eform, access=eaccess, iostat=ierr, iomsg=msg)

888 continue
900 continue

if( then
print *,' error from OPEN: ',trim(msg)


6 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

NOW I think I see how to add attachments ... couldn't see this lot until i had submitted the original.


Downloadapplication/octet-stream psimstub.f902.31 KB

I can reproduce this - thanks. I will let the developers know. Issue ID is DPD200249310.

Steve - Intel Developer Support

We found and fixed the bug that caused this error - it happens when you do an INQUIRE by FILE and no matching file is found. I expect the fix to be included in Update 2, planned for March.

Steve - Intel Developer Support

Thanks Steve.

I think there are other scenarios that will lead to this problem. The attachment I sent you shows the results of reduction of my production code in one configuration. If I get time I'll try to adjust it for some others that I found along the way.

Can you think of any other way I can test for a given filename being allready open? Apart from storing all the file names used on previous OPENs, and searching them on every subsequent open?

Kind regards


If you avoid using NEWUNIT, you'll avoid this error. Otherwise you have to wait for the fix.

Steve - Intel Developer Support

Leave a Comment

Please sign in to add a comment. Not a member? Join today