pyplot-fortran icon indicating copy to clipboard operation
pyplot-fortran copied to clipboard

Remove hard-coded tmp_file name

Open jacobwilliams opened this issue 8 years ago • 3 comments

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

jacobwilliams avatar Aug 18 '15 16:08 jacobwilliams

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.

jacobwilliams avatar Aug 18 '15 16:08 jacobwilliams

"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 avatar Mar 05 '18 15:03 hennink

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.

hennink avatar Mar 14 '18 17:03 hennink