Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29285 Discussions

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

qolin
Novice
903 Views

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 13.1.3.198 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
/PDB:"D:\q_two\main\pipesim\engines\components\psimstub\Debug\psimstub.pdb"
/SUBSYSTEM:CONSOLE /STACK:4194304,65536
/IMPLIB:"D:\q_two\main\pipesim\engines\components\psimstub\Debug\psimstub.lib"
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'

end

!----------------------------------------------------------------------------

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(jerr.ne.0) 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
endif

!-----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(ierr.ne.0) then
print *,' error from OPEN: ',trim(msg)
endif

end

0 Kudos
5 Replies
qolin
Novice
903 Views

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

0 Kudos
Steven_L_Intel1
Employee
903 Views

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

0 Kudos
Steven_L_Intel1
Employee
903 Views

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.

0 Kudos
qolin
Novice
903 Views

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

Qolin

0 Kudos
Steven_L_Intel1
Employee
903 Views

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

0 Kudos
Reply