Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove hard-coded tmp_file name #7

Open
jacobwilliams opened this issue Aug 18, 2015 · 3 comments
Open

Remove hard-coded tmp_file name #7

jacobwilliams opened this issue Aug 18, 2015 · 3 comments

Comments

@jacobwilliams
Copy link
Owner

Need to remove this fixed tmp_file name from the code. It should generate an unused file name as needed.

@jacobwilliams
Copy link
Owner Author

Tried to use the STATUS='SCRATCH' feature of the OPEN statement. However, it doesn't appear to be possible to get the name of the file with gfortran. For example:

 program Test

    implicit none

    integer :: istat,iunit
    character(len=256) :: fname

    open(newunit=iunit,status='SCRATCH',iostat=istat)
    inquire(unit=iunit,name=fname,iostat=istat)

    write(*,*) 'name = '//trim(fname)

 end program Test

When compiled with gfortran, fname is just garbage. Might be a bug? It works on ifort. Will look into it some more.

@hennink
Copy link
Contributor

hennink commented Mar 5, 2018

"Modern fortran explained" (Metcalf et al., 2011) lists descriptions of the dummy variables of the inquire statement. I didn't read everything, but this is probably the entry you're looking for:

named=nmd and name= nam, where nmd is a logical variable that is assigned the value
true if the file has a name, and false otherwise. If the file has a name, the character
variable nam will be assigned the name. This value is not necessarily the same as that
given in the file specifier, if used, but may be qualified in some way. However, in
all cases it is a name which is valid for use in a subsequent open statement, and so
the inquire can be used to determine the actual name of a file before connecting it.
Whether the file name is case sensitive is system dependent

It migh tbe worth adding the iomsg dummy variable to both the open and the inquire procedures, and print iomsg if istat /= 0.

@hennink
Copy link
Contributor

hennink commented Mar 14, 2018

And this is the explanation of the status argument:

status= st, where st is a character expression that provides the value old, new, replace,
scratch, or unknown. The file= specifier must be present if new or replace is
specified or if old is specified and the unit is not connected; the file= specifier must
not be present if scratch is specified.

(...)
If the value scratch is specified, the file is created and becomes
connected, but it cannot be kept after completion of the program or execution of a
close statement.

I suppose this all makes sense: a scratch file does not have to be accessible though a filename by the OS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants