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

INQUIRE on a FOLDER instead of a file

jbalster
Novice
3,111 Views
I am converting from CVF 6.1 to IVF 9,0 and found the following gives the opposite result

logical LEXIST

INQUIRE ( FILE='.', EXIST=LEXIST )

The inquire is being done on a FOLDER intead of a file and so it's always failing in IVF 9.0 (returns .FALSE. instead of .TRUE. if the folder exists).

Now the IVF 9.0 help is written a little different from the CVF help because it states that it not only exists, but also can be opened, and true, a folder cannot be opened.

Is there a work around for this. In the actual code, the filespec is in a variable, and may be either a file or folder and is used as a partial filespec while composing the full file spec. It is necessary to be able to check for existance only at the point in the code that has the INQUIRE, not whether or not it can be opened.

Thanks, Jim

8 Replies
Steven_L_Intel1
Employee
3,111 Views
Intel Fortran 9.0 has a new feature that allows you to INQUIRE about a directory.

INQUIRE (DIRSPEC='', EXIST=LEXIST)
0 Kudos
jbalster
Novice
3,111 Views

Thanks again, Steve

However, I need to now point out that the new option is DIRECTORY= instead of DIRSPEC=

I was able to fix the problem routine by adding another 22 INQUIRE statements inside IFDEF's so they only get included if using your compilier. My code is generic and the INQUIRE statements are using a character string for the path name which may be either a file or a directory, so I still have to do the INQUIRE for FILE= and then if that comes back .FALSE. then I have to repeat the same INQUIRE, but now with DIRECTORY=. There are a total of 22 INQUIRE statements within the routine that keep futzing with the path name and then trying to check for existance. They do things like translate environment variables embedded within the path spec and trying both upper and lower case versions of the name and trying different file extensions (I also support unix systems with this code). Well, now I have 44 INQUIRE statements in the routine, but it's working again!!! I was a little dissappointed to have found it necessary to make such a change, but I also understand the reasons for wanting to test if a file can be opened rather than existing, however, that should have been done with adding a new output attribute such as OPENABLE=variable instead of changing the behaviour of EXIST=variable which by name implies that you are only checking for existance

0 Kudos
Steven_L_Intel1
Employee
3,111 Views
There's been discussion of this issue in comp.lang.fortran and elsewhere. On some platforms, you can "open" a directory spec and that's what INQUIRE looks at for EXIST. On other platforms, such an operation is not meaningful and other means are necessary to check for directory existence. The standard says that a file for which INQUIRE says exists should be able to be opened in an OPEN statement.

My apologizes on DIRSPEC - that keyword exists but is an output value.
0 Kudos
ronald_g_guenther
3,111 Views
Greetings Steve,
Imagine my delight while attempting to regression test some of our applications with IVF 9.1 when that which had been working with IVF 8.1.30 no longer did. ;-)
Is this a standards interpretation issue? From deep in the belly of the beast emerges the following snippet:

INQUIRE ( FILE=cCDdriveLtr//':.',EXIST=lCDonline )
IF ( lCDonline ) THEN
cVolumeLabel = A1230_VolumeLabel( cCDdriveLtr//":" )
lCDmountIncomplete = .FALSE.
EXIT
END IF

Should there be an agenda other than to change it?
Thanks
Ron Guenther
0 Kudos
Steven_L_Intel1
Employee
3,111 Views
I assume you mean 9.0.

The code you have is undefined by the standard. The standard says "The value of file-name-expr in the FILE= specifier specifies the name of the file being inquired about." A directory/folder is not a file. If it worked for you before, it was by luck and not design. You should change the code.
0 Kudos
ronald_g_guenther
3,111 Views

Greetings Steve,
Absolutely correct assumption! From W_FC_C_9[1].0.019.exe. The last working but undefined code was in w_fc_pc_8[1].1.030.exe.

Thanks for your timely response. BTW, are you aware of a "Fortran standard solution" for determining when removeable media are mounted now?

Ron
0 Kudos
Steven_L_Intel1
Employee
3,111 Views
No, there's no Fortran standard solution to this. My general advice is to put platform-dependent code in a module so that is isolated and easily identified.
0 Kudos
ronald_g_guenther
3,111 Views
Good idea Steve,
Thank you. (I would put a happy face in if it wasn't nonfunctional.) Ah, like module A1200_MountCD.F90! And:
Code:
        !DEC$ IF DEFINED (__INTEL_COMPILER)
        INQUIRE ( DIRECTORY=cCDdriveLtr//':.', EXIST=lDTED_CDonline )
        !DEC$ ELSE
        INQUIRE ( FILE=cCDdriveLtr//':.', EXIST=lDTED_CDonline )
        !DEC$ ENDIF
0 Kudos
Reply