Re: How to get file UNIT from file NAME? [message #58880] |
Tue, 26 February 2008 11:22 |
Paul Van Delst[1]
Messages: 1157 Registered: April 2002
|
Senior Member |
|
|
Vince Hradil wrote:
> On Feb 26, 12:27 pm, Paul van Delst <Paul.vanDe...@noaa.gov> wrote:
>> Hello,
>>
>> Is it possible to get a file UNIT from a file NAME? For example, in Fortran95 you can do,
>>
>> INQUIRE( FILE=Filename, NUMBER=FileID )
>>
>> i.e. supplying a Filename yields its associated unit number, FileID (which is -1 if no
>> unit is connected to the file)
>>
>> Is there an equivalent IDL command? FSTAT requires one to supply a UNIT argument, which is
>> opposite of what I need, i.e. similar to the f95
>>
>> INQUIRE( UNIT=FileID, NAME=Filename )
>>
>> Basically I want to be able to derive all the necessary info about the file, in particular
>> answering the "Is it open? If so, what unit number?" questions just from the filename.
>>
>> Any info appreciated.
>>
>> cheers,
>>
>> paulv
>
> You could loop through all possible luns (1:128) and check to see if
> they are open:
>
> for i=1, 128 do begin
> a = fstat(i)
> if a.open eq 1 then print, 'File ' + a.name + ' is open as LUN ' +
> string(i,format='(I3.3)')
> endfor
Yeah... I guess that would work. But.... uff da! :o)
cheers.
paulv
|
|
|
Re: How to get file UNIT from file NAME? [message #58881 is a reply to message #58880] |
Tue, 26 February 2008 11:19  |
Paul Van Delst[1]
Messages: 1157 Registered: April 2002
|
Senior Member |
|
|
F�LDY Lajos wrote:
>
> On Tue, 26 Feb 2008, Paul van Delst wrote:
>
>> Hello,
>>
>> Is it possible to get a file UNIT from a file NAME? For example, in
>> Fortran95 you can do,
>>
>> INQUIRE( FILE=Filename, NUMBER=FileID )
>>
>> i.e. supplying a Filename yields its associated unit number, FileID
>> (which is -1 if no unit is connected to the file)
>>
>> Is there an equivalent IDL command? FSTAT requires one to supply a
>> UNIT argument, which is opposite of what I need, i.e. similar to the f95
>>
>> INQUIRE( UNIT=FileID, NAME=Filename )
>>
>> Basically I want to be able to derive all the necessary info about the
>> file, in particular answering the "Is it open? If so, what unit
>> number?" questions just from the filename.
>>
>> Any info appreciated.
>>
>> cheers,
>>
>> paulv
>>
>
> You can use HELP, /FILES, OUTPUT=OUT and parse OUT.
Kewl. Thanks muchly.
So, since the unit/filename correspondence information is available... I wonder how one
would influence ITTVIS to build this capability into FSTAT (or FILE_INFO, FILE_TEST, or
something)?
cheers,
paulv
|
|
|
Re: How to get file UNIT from file NAME? [message #58883 is a reply to message #58881] |
Tue, 26 February 2008 10:57  |
Vince Hradil
Messages: 574 Registered: December 1999
|
Senior Member |
|
|
On Feb 26, 12:27 pm, Paul van Delst <Paul.vanDe...@noaa.gov> wrote:
> Hello,
>
> Is it possible to get a file UNIT from a file NAME? For example, in Fortran95 you can do,
>
> INQUIRE( FILE=Filename, NUMBER=FileID )
>
> i.e. supplying a Filename yields its associated unit number, FileID (which is -1 if no
> unit is connected to the file)
>
> Is there an equivalent IDL command? FSTAT requires one to supply a UNIT argument, which is
> opposite of what I need, i.e. similar to the f95
>
> INQUIRE( UNIT=FileID, NAME=Filename )
>
> Basically I want to be able to derive all the necessary info about the file, in particular
> answering the "Is it open? If so, what unit number?" questions just from the filename.
>
> Any info appreciated.
>
> cheers,
>
> paulv
You could loop through all possible luns (1:128) and check to see if
they are open:
for i=1, 128 do begin
a = fstat(i)
if a.open eq 1 then print, 'File ' + a.name + ' is open as LUN ' +
string(i,format='(I3.3)')
endfor
|
|
|
Re: How to get file UNIT from file NAME? [message #58884 is a reply to message #58883] |
Tue, 26 February 2008 10:52  |
Foldy Lajos
Messages: 268 Registered: October 2001
|
Senior Member |
|
|
On Tue, 26 Feb 2008, Paul van Delst wrote:
> Hello,
>
> Is it possible to get a file UNIT from a file NAME? For example, in Fortran95
> you can do,
>
> INQUIRE( FILE=Filename, NUMBER=FileID )
>
> i.e. supplying a Filename yields its associated unit number, FileID (which is
> -1 if no unit is connected to the file)
>
> Is there an equivalent IDL command? FSTAT requires one to supply a UNIT
> argument, which is opposite of what I need, i.e. similar to the f95
>
> INQUIRE( UNIT=FileID, NAME=Filename )
>
> Basically I want to be able to derive all the necessary info about the file,
> in particular answering the "Is it open? If so, what unit number?" questions
> just from the filename.
>
> Any info appreciated.
>
> cheers,
>
> paulv
>
You can use HELP, /FILES, OUTPUT=OUT and parse OUT.
regards,
lajos
|
|
|