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.

open same file twice?

lklawrie
Beginner
1,901 Views
Recently one of our developers wrote some code where a file that is already opened is opened (and read) again during this routine.

Neither g95 nor gfortran think that is acceptable. IVF lets it go by.

(open is read access, theoretically, I suppose it's okay. just doesn't seem like a good idea).

I think the standard leaves it up to the compiler.

Do IVF developers think this might be a bug in their compiler?

Linda
0 Kudos
4 Replies
mecej4
Honored Contributor III
1,901 Views
From the Intel Fortran Reference, Open Statement Overview:

The OPEN statement connects an external file to a unit, creates a new file and connects it to a unit, creates a preconnected file, or changes certain properties of a connection.

Note that OPEN may be used to change the properties of an existing connection, or to implicitly close the file to which the unit was previously connected and open a connection to the currently specified file.
0 Kudos
Steven_L_Intel1
Employee
1,901 Views
If you open the same file on the same unit, that is the F77 feature "OPEN on a connected unit" (which I detest) - it lets you change certain attributes of the file. If you open a different file on a unit where a file is open, the old one is silently closed and the new one open.

If you're talking about opening the same file on different units, yes, we deliberately allow that if the OS does. Most OSes permit some sort of shared file access. You can control it with OPEN keywords. It is true that the standard disallows this, but that is a restriction on the program, not the compiler, and the compiler is not required to be able to diagnose that.
0 Kudos
lklawrie
Beginner
1,901 Views
If you're talking about opening the same file on different units, yes, we deliberately allow that if the OS does. Most OSes permit some sort of shared file access. You can control it with OPEN keywords. It is true that the standard disallows this, but that is a restriction on the program, not the compiler, and the compiler is not required to be able to diagnose that.

Yes, talking about this one. So, it's "beyond" the standard and IVF is currently allowing that.

Thanks, Steve.

Linda

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,901 Views
>>If you're talking about opening the same file on different units, yes, we deliberately allow that if the OS does.

This is a good feature, especially in light of multi-threaded applications whereby different threads in the application want to perform independent and non-conflicting buffered stream access to the same file (but at different locations within the file). Without this feature, excessive seeking on file access may occur.

Jim Dempsey
0 Kudos
Reply