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

Recognizing a scratch file

NH_Veldhuijzen
Beginner
1,909 Views
Dear all,

I need a way of finding out (in IVF11) whether an open file is a scratch file. Using INQUIRE, I can get the file name, which is something like "FORTxyz.TMP". This is a great help, but I like to know whether there is a still safer way of spotting a scratch file. (Some of my clients might be daft enough to call there own files "FORTxyz.TMP"!)

0 Kudos
7 Replies
jimdempseyatthecove
Honored Contributor III
1,909 Views
Quoting - NH Veldhuijzen
Dear all,

I need a way of finding out (in IVF11) whether an open file is a scratch file. Using INQUIRE, I can get the file name, which is something like "FORTxyz.TMP". This is a great help, but I like to know whether there is a still safer way of spotting a scratch file. (Some of my clients might be daft enough to call there own files "FORTxyz.TMP"!)


I haven't tried this but I notice in the documentation under "INQUIRE statement" (just benieth "INQUIRE") they have an example of

INQUIRE(DIRECTORY=...

And then if you examine the accepted specifiers you will note that "DIRECTORY" is not listed.
Perhapse this is true for "DISPOS" and/or "DISP"

Try
CHARACTER (255) :: C_DISPOS
...
INQUIRE(iUnit, DISPOS=C_DISPOS)

And see what happens. If the statement is accaptible then I would expect C_DISPOS to contain 'DELETE' (or 'PRINT/DELTET' or "SUBMIT/DELETE') for temp files.

Jim Dempsey

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,909 Views

And if it is not an acceptible statement it would seem appropriate to add as a feature request.

Note, you can establish a site policy that all files written to TMP and/or TEMP are scratch files.

As to if files written to "." are scratch this may be a seperate policy (dependent on who's "." is ".").

Jim Dempsey
0 Kudos
TimP
Honored Contributor III
1,909 Views
While a file is held open by an application, and not shared, other applications would be locked out. There are various standard ways of selecting a name for a scratch file so as to avoid accidental conflicts with other copies of an application. Perhaps it's not a common idiom specific to Windows Fortran. Obviously, judging by the daily growth of my Windows temp directory, there's no uniform maintenance method.
0 Kudos
NH_Veldhuijzen
Beginner
1,909 Views
Dear all,

Thank you for your quick and nice replies. I think I stick (for the moment) to the rule that files named "FORxyz.TMP" are scratch files. I will mention this in my manual.

0 Kudos
Kevin_D_Intel
Employee
1,909 Views

Files opened using STATUS='SCRATCH' are "unnamed" files in which case INQUIRE on the NAMED specifier returns false.

Given the following:

[plain]program u68883

logical isnamed
character*60 fname

open (3,STATUS='SCRATCH')

inquire (3, named=isnamed)
if (.NOT. isnamed) write (*,"('Unit 3 is unnamed')")

inquire (3, name=fname)
write (*,"('Unit 3 file name is: ',a60)") fname

end[/plain]

The inquire on NAMED provides information on whether the file is unnamed.

$ ifort u68883.f90
Intel Visual Fortran Compiler Professional for applications running on IA-32, Version 11.1 Build 20090903 Package ID: w_cprof_p_11.1.046
Copyright (C) 1985-2009 Intel Corporation. All rights reserved.

Microsoft Incremental Linker Version 9.00.21022.08
Copyright (C) Microsoft Corporation. All rights reserved.

-out:u68883.exe
-subsystem:console
u68883.obj

$ ./u68883.exe
Unit 3 is unnamed
Unit 3 file name is: C:UserskddavisAppDataLocalTemp2FOR7BD6.tmp
0 Kudos
jimdempseyatthecove
Honored Contributor III
1,909 Views

Thanks Kevin,

Sounds like a candidate for the documentation.

Jim
0 Kudos
Kevin_D_Intel
Employee
1,909 Views

It is unless you feel something more is needed.

The IVF Userand RefGuide (11.1 vintage) already states under the OPEN: STATUS Specifier (via index: Intel Visual Fortran Compiler User and Reference Guides > Language Reference > File Operation I/O Statements > OPEN Statement Overview > STATUS Specifier) that 'SCRATCH':

"Indicates a new file that is unnamed (called a scratch file). When the file is closed or the program terminates, the scratch file is deleted."

And under INQUIRE: NAMED Specifier (via index: Intel Visual Fortran Compiler User and Reference Guides > Language Reference > File Operation I/O Statements > INQUIRE Statement Overview > NAMED Specifier) that:

"The NAMED specifier asks whether a file is named."

Maybe this was just missed, but then I also have assumed STATUS='SCRATCH' is being used since it really hasn't been explicitly stated, but that is where one sees the reported form of file name used.
0 Kudos
Reply