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

Hook for OPEN(FILE=...,DEFAULTFILE=...)

oh_moose
Beginner
547 Views
The Intel Fortran compiler for Linux assumes that an OPEN DEFAULTFILE argument contains only a directory name. That is a rather limited implementation. Is there any hook in the RTL which would allow me to parse the OPEN FILE and DEFAULTFILE arguments so that I can make up the actual file specification before OPEN proceeds with the actual open operation? I do not want to touch the OPEN statement itself in my Fortran code.

Some background information:
In my code I use various VMS features. In particular I specify only the file name with the OPEN FILE argument and specify the location and file type with the OPEN DEFAULTFILE argument. Example: FILE='WHAT',DEFAULTFILE='WHERE:.TXT'
For WHERE I have a logical name defined which points to the actual device and directory (and maybe node name, too). If nothing else is defined, OPEN accesses the file WHERE:WHAT.TXT. Now, if someone defines a logical name WHAT and points that to another file, then that file is being accessed.

In some routines I only specify the file type with DEFAULTFILE to provide a default file type.

Right now I am using symbolic links on Linux to access the actual files. But that is a terrible hack. The symbolic link for the example above would have to be named WHERE:.TXT/WHAT (oh_deer).

I have already written a self-made Linux FUSE based file system which makes files and directories in a particular directory tree all case-insensitive. I could use this code to implement the basic idea of logical names, but that would limit the portability of my application significantly because I may not be able to install the file system on every target machine.

0 Kudos
2 Replies
Steven_L_Intel1
Employee
547 Views
As you have no doubt discovered on your own, Linux is not VMS. Linux has none of the elegant, integrated file system mechanisms that you came to depend on that "just worked". Linux makes you reinvent your own filespec parsing code each time, and there is no standard library or process for doing so. The VMS concept of logical names and their integration into file specifications does not exist in Linux. Windows is somewhat better in this regard, but not even close to what VMS had 30 years ago.

Given that, DEFAULTFILE in ifort is simply a string that is prefixed to what you say in FILE=. If you want a "hook", this is done with a USEROPEN routine - it will at least require you to change the OPEN to specify the USEROPEN keyword and name the routine. Sort of like USEROPEN on VMS, you are passed various items that were specified in the OPEN and you get to do the actual fopen call yourself and return the handle.

I note that the USEROPEN documentation is very much Windows-centric, but it is not documented as Windows-only. I have not yet tried a test case to see what one gets passed on Linux.
0 Kudos
Steven_L_Intel1
Employee
547 Views
I did some experiments and found that the arguments to the USEROPEN routine on Linux are not the same as on Windows. On Linux it is equivalent to the following Fortran routine:

integer(4) function uopn (filename, open_flags, create_mode, unit)
character(*) filename
integer open_flags, create_mode, unit

! Routine calls C library routine "open" with filename, open_flags, create_mode)
uopn = ! file descriptor returned by open()
end function uopn

The filename has already had paths applied to it. The filename length is passed by value at the end of the argument list. All other arguments are passed by reference.
0 Kudos
Reply