comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: fstat, file_info and file_test
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: fstat, file_info and file_test [message #35073] Thu, 15 May 2003 02:26 Go to next message
Nigel Wade is currently offline  Nigel Wade
Messages: 286
Registered: March 1998
Senior Member
Ben Tupper wrote:

> Hello,
>
> This appears to be the week for file questions.
>
> I see that in the now distant past, my question has been asked here
> before, but the answers were pre-IDL 5.4 when FILE_xxxxx routines
> appeared.
>
> I would like to have a test that reports if the file is open - by simply
> providing the filename. FSTAT almost does it, but I have to associate
> the file with a LUN first. FILE_INFO and FILE_TEST each take the
> filename as an argument (instead of the lun that FSTAT requires), but
> neither test for 'openess'.
>
> What I would like to have is a function similar to:
>
> result = FILE_ISOPEN(filename)
>
> that returns a 1 (for open) or a 0 (for closed). Or, perhaps better in
> the long run, I'd like to see an /ISOPEN keyword added to FILE_TEST.
>
>
> Any suggestions?
>
> Thanks,
> Ben

How do you deal with the issue of the file being renamed or deleted after
you've opened it? What do you do if the file you opened is renamed and new
file created with the same name - should the test indicate it's open or
not?

In general, not even the OS can tell you reliably what you want for these
reasons.

--
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : nmw@ion.le.ac.uk
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555
Re: fstat, file_info and file_test [message #35075 is a reply to message #35073] Thu, 15 May 2003 02:19 Go to previous messageGo to next message
Karsten Rodenacker is currently offline  Karsten Rodenacker
Messages: 98
Registered: July 1997
Member
Hmm, what about using help,/file,output=st and string search for the
appropriate file?
Regards
Karsten

Ben Tupper schrieb:
> Hello,
>
> This appears to be the week for file questions.
>
> I see that in the now distant past, my question has been asked here
> before, but the answers were pre-IDL 5.4 when FILE_xxxxx routines appeared.
>
> I would like to have a test that reports if the file is open - by simply
> providing the filename. FSTAT almost does it, but I have to associate
> the file with a LUN first. FILE_INFO and FILE_TEST each take the
> filename as an argument (instead of the lun that FSTAT requires), but
> neither test for 'openess'.
>
> What I would like to have is a function similar to:
>
> result = FILE_ISOPEN(filename)
>
> that returns a 1 (for open) or a 0 (for closed). Or, perhaps better in
> the long run, I'd like to see an /ISOPEN keyword added to FILE_TEST.
>
>
> Any suggestions?
>
> Thanks,
> Ben
>


--
Karsten Rodenacker
------------------------------------------------------------ -------------:-)
GSF - Forschungszentrum Institute of Biomathematics and Biometry
D-85758 Oberschleissheim Postfach 11 29
Karsten@Rodenacker.de | http://www.gsf.de/ibb/
Tel: +49 89 31873401 | FAX: ...3369
Re: fstat, file_info and file_test [message #35083 is a reply to message #35075] Wed, 14 May 2003 11:28 Go to previous messageGo to next message
btt is currently offline  btt
Messages: 345
Registered: December 2000
Senior Member
Richard Younger wrote:
> Ben Tupper wrote:
> [...]
>
>> What I would like to have is a function similar to:
>>
>> result = FILE_ISOPEN(filename)
>>
>> that returns a 1 (for open) or a 0 (for closed). Or, perhaps better in
>> the long run, I'd like to see an /ISOPEN keyword added to FILE_TEST.
>
>
> Hi Ben.
>
> I don't think IDL associates file names with open files except through LUNs,
> so I can only think of the brute force method:
>
> FUNCTION IsFilenameOpen, filename
>
> COMPILE_OPT idl2
>
> test_struc = Fstat(0)
> struc_array = Replicate(test_struc, 129)
>
> FOR i=1, 128 DO BEGIN
> struc_array[i] = Fstat(i)
> ENDFOR
>
> index = Where(struc_array.name EQ File_Expand_Path(filename), count)
>
> IF count EQ 0 THEN RETURN, 0 ELSE RETURN, 1
>
> END
>
> Wouldn't want to put it in an inner loop, though.
>
> Good luck,
> Rich
>
>

Hi,

OK, how about running through the possible LUNs (100-128) until a match
is found. I like the cross-platforminess of your solution.

FUNCTION File_IsOpen, filename

COMPILE_OPT idl2

For i = 100, 128 Do $
If ( (Fstat(i)).NAME EQ File_Expand_Path(filename) ) Then Return, 1

Return, 0
END

Thanks,
Ben
Re: fstat, file_info and file_test [message #35084 is a reply to message #35083] Wed, 14 May 2003 10:48 Go to previous messageGo to next message
btt is currently offline  btt
Messages: 345
Registered: December 2000
Senior Member
Bruce Bowler wrote:
>> I see that in the now distant past, my question has been asked here
>> before, but the answers were pre-IDL 5.4 when FILE_xxxxx routines appeared.
>>
>> I would like to have a test that reports if the file is open - by simply
>> providing the filename. FSTAT almost does it, but I have to associate
>> the file with a LUN first. FILE_INFO and FILE_TEST each take the
>> filename as an argument (instead of the lun that FSTAT requires), but
>> neither test for 'openess'.
>>
>> What I would like to have is a function similar to:
>>
>> result = FILE_ISOPEN(filename)
>>
>> that returns a 1 (for open) or a 0 (for closed). Or, perhaps better in
>> the long run, I'd like to see an /ISOPEN keyword added to FILE_TEST.
>
>
> Ask the OS. On *nix and OS/X (but not windows, hence not xplatform)
> there's a utility called lsof (list open files) which can tell you not
> only if a file is open, but who's got it open, in case it's opened by
> someone other than yourself...
>

Thanks Richard and Bruce,

I see that MacOSX (ie BSD *nix) has FSTAT and LSOF (but not FUSER); each
of which would do the trick.

Cheers,
Ben
Re: fstat, file_info and file_test [message #35086 is a reply to message #35084] Wed, 14 May 2003 09:56 Go to previous messageGo to next message
Bruce Bowler is currently offline  Bruce Bowler
Messages: 128
Registered: September 1998
Senior Member
> I see that in the now distant past, my question has been asked here
> before, but the answers were pre-IDL 5.4 when FILE_xxxxx routines appeared.
>
> I would like to have a test that reports if the file is open - by simply
> providing the filename. FSTAT almost does it, but I have to associate
> the file with a LUN first. FILE_INFO and FILE_TEST each take the
> filename as an argument (instead of the lun that FSTAT requires), but
> neither test for 'openess'.
>
> What I would like to have is a function similar to:
>
> result = FILE_ISOPEN(filename)
>
> that returns a 1 (for open) or a 0 (for closed). Or, perhaps better in
> the long run, I'd like to see an /ISOPEN keyword added to FILE_TEST.

Ask the OS. On *nix and OS/X (but not windows, hence not xplatform)
there's a utility called lsof (list open files) which can tell you not
only if a file is open, but who's got it open, in case it's opened by
someone other than yourself...

--
+-------------------+--------------------------------------- ------------+
Bruce Bowler | Normally that's the way we do it, except when we
1.207.633.9600 | don't. - Jo Ellen Eros
bbowler@bigelow.org |
+-------------------+--------------------------------------- ------------+
Re: fstat, file_info and file_test [message #35087 is a reply to message #35086] Wed, 14 May 2003 09:13 Go to previous messageGo to next message
Richard Younger is currently offline  Richard Younger
Messages: 43
Registered: November 2000
Member
Ben Tupper wrote:
[...]
> What I would like to have is a function similar to:
>
> result = FILE_ISOPEN(filename)
>
> that returns a 1 (for open) or a 0 (for closed). Or, perhaps better in
> the long run, I'd like to see an /ISOPEN keyword added to FILE_TEST.

Hi Ben.

I don't think IDL associates file names with open files except through LUNs,
so I can only think of the brute force method:

FUNCTION IsFilenameOpen, filename

COMPILE_OPT idl2

test_struc = Fstat(0)
struc_array = Replicate(test_struc, 129)

FOR i=1, 128 DO BEGIN
struc_array[i] = Fstat(i)
ENDFOR

index = Where(struc_array.name EQ File_Expand_Path(filename), count)

IF count EQ 0 THEN RETURN, 0 ELSE RETURN, 1

END

Wouldn't want to put it in an inner loop, though.

Good luck,
Rich


--
Richard Younger
younger@spaMIT.edu (with obvious modification)
Re: fstat, file_info and file_test [message #35184 is a reply to message #35083] Fri, 16 May 2003 11:16 Go to previous message
Richard Younger is currently offline  Richard Younger
Messages: 43
Registered: November 2000
Member
Ben Tupper wrote:
>
[...]
>
> Hi,
>
> OK, how about running through the possible LUNs (100-128) until a match
> is found. I like the cross-platforminess of your solution.
>
> FUNCTION File_IsOpen, filename
>
> COMPILE_OPT idl2
>
> For i = 100, 128 Do $
> If ( (Fstat(i)).NAME EQ File_Expand_Path(filename) ) Then Return, 1
>
> Return, 0
> END

Hi Ben

Been sick the last couple days, so I'm a tad late responding.

That certainly would shortcut things a bit. I'm brainwashed into the Cult of
the Array, but I suppose since the loop will actually run faster almost all
the time, I'll have to give some ground. :-) But isn't being able to do
WHERE(struc_array.name EQ filename) just plain cool?

By cutting out LUNs 0-99, you are trusting your users not to (foolishly)
manage their own LUNs. Only you can tell if that is a wise decision.

Best,
Rich

--
Richard Younger
younger@spaMIT.edu (with obvious modification)
Phone: (781)981-4464
Re: fstat, file_info and file_test [message #35217 is a reply to message #35073] Thu, 15 May 2003 07:56 Go to previous message
btt is currently offline  btt
Messages: 345
Registered: December 2000
Senior Member
Nigel Wade wrote:
> Ben Tupper wrote:
>
>
>> Hello,
>>
>> This appears to be the week for file questions.
>>
>> I see that in the now distant past, my question has been asked here
>> before, but the answers were pre-IDL 5.4 when FILE_xxxxx routines
>> appeared.
>>
>> I would like to have a test that reports if the file is open - by simply
>> providing the filename. FSTAT almost does it, but I have to associate
>> the file with a LUN first. FILE_INFO and FILE_TEST each take the
>> filename as an argument (instead of the lun that FSTAT requires), but
>> neither test for 'openess'.
>>
>> What I would like to have is a function similar to:
>>
>> result = FILE_ISOPEN(filename)
>>
>> that returns a 1 (for open) or a 0 (for closed). Or, perhaps better in
>> the long run, I'd like to see an /ISOPEN keyword added to FILE_TEST.
>>
>>
>> Any suggestions?
>>
>> Thanks,
>> Ben
>
>
> How do you deal with the issue of the file being renamed or deleted after
> you've opened it? What do you do if the file you opened is renamed and new
> file created with the same name - should the test indicate it's open or
> not?
>
> In general, not even the OS can tell you reliably what you want for these
> reasons.
>

Good questions! Another question to add to your list, what happens if
more than one valid pointers exist to the single file? Witness below,
that u1 and u2 are each valid LUNs to the same file. Gaak! I can see
why the underlying OS can't be counted upon for 'truth' - too many cooks!


IDL> get_LUN, u1
IDL> get_LUN, u2
IDL> openW, u1, file
IDL> for i = 0, 2 do print, s[i]
Unit Attributes Name
100 Read, Write, New, Reserved /Users/ben/data.dat
101 Closed, Reserved
IDL> openU, u2, file
IDL> help, /file, output = s
IDL> for i = 0, n_elements(s)-1 do print, s[i]
Unit Attributes Name
100 Read, Write, New, Reserved /Users/ben/data.dat
101 Read, Write, Reserved /Users/ben/data.dat


Thanks,
Ben
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: replace array's elemets
Next Topic: new object from a save/restore doesn't execute init function

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 14:01:13 PDT 2025

Total time taken to generate the page: 0.00439 seconds