pyplot-fortran
pyplot-fortran copied to clipboard
Remove hard-coded tmp_file name
Need to remove this fixed tmp_file
name from the code. It should generate an unused file name as needed.
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.
"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
.
And this is the explanation of the status
argument:
status
= st, where st is a character expression that provides the valueold
,new
,replace
,scratch
, orunknown
. Thefile
= specifier must be present if new or replace is specified or if old is specified and the unit is not connected; thefile
= specifier must not be present if scratch is specified. (...) If the valuescratch
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.