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

Home » Public Forums » archive » Re: openr and /get_lun
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: openr and /get_lun [message #19733] Mon, 17 April 2000 00:00
Nando Iavarone is currently offline  Nando Iavarone
Messages: 48
Registered: December 1998
Member
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Craig Markwardt wrote:
<blockquote TYPE=CITE>I have noticed that the use of /GET_LUN and ERROR
keywords to openr is
<br>not as helpful as I would have hoped.&nbsp; Do other have this experience?
<br>The problem is that when an error occurs, it is hard to know whether
<br>the file unit was "gotten" or not.
<p>For example:
<p>pro test1
<br>&nbsp; openr, unit, filename, /get_lun, error=err
<br>&nbsp; free_lun, unit
<br>end
<p>If there was an error, then it is possible that UNIT was never set,
<br>and is hence undefined.&nbsp; FREE_LUN doesn't take undefined variables.
<p>If there is error checking to do, I don't know exactly what it should
<br>be.&nbsp; So I find myself explicitly doing this instead:
<p>pro test2
<br>&nbsp; get_lun, unit
<br>&nbsp; openr, unit, filename, error=err
<br>&nbsp; free_lun, unit
<br>end
<p>Comments?
<br>&nbsp;</blockquote>
Hi Craig,
<br>you have to trap the error.
<br>it is the open that can fail, so you have to check the err variable:
<p>pro test2
<br>&nbsp; get_lun, unit
<br>&nbsp; openr, unit, filename, error=err
<br>&nbsp; if (err le 0) then begin
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; ;error management
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; ...............................
<br>&nbsp; endif
<br>&nbsp; free_lun, unit
<br>end
<br>&nbsp;
<br>&nbsp;
<pre>You can also use the more flexible error trapping CATCH procedure.</pre>

<pre>It is general and not only for file management:</pre>

<pre></pre>
pro testOpen<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; errorStatus=0<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; catch,errorStatus<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; if errorStatus ne 0 then begin
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
;error management<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
print,!ERR_STRING<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
return<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; endif<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; openr,lun,'pippone',/get_lun<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; free_lun,lun<br>
end
<br>&nbsp;
<pre>--&nbsp;
Nando Iavarone
Advanced Computer System - SPACE DIVISION
via Lazzaro Belli, 23
00040&nbsp; Frascati - RM
Tel: +39-6-944091 (switchboard)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 9440968 (direct)
E-mail:&nbsp;
&nbsp;&nbsp;&nbsp; f.iavarone@acsys.it
&nbsp;&nbsp;&nbsp; FrdndVrn@altavista.net</pre>
&nbsp;</html>
Re: openr and /get_lun [message #19734 is a reply to message #19733] Sun, 16 April 2000 00:00 Go to previous message
majewski is currently offline  majewski
Messages: 15
Registered: March 2000
Junior Member
you could always jump over the access of the file with a GOTO...

pro test_lun_free

filename = 'c:\dne.dat'

openr, unit, filename, /get_lun, error=err
IF (err NE 0) then goto, bad_file
;Insert your read statement here
;Insert your read statement here

print, 'the file exists - lun#', strcompress(string(unit),
/remove_all),' set'
free_lun, unit

;Insert the rest of your program here

bad_file:If err ne 0 then print, 'lun not set'

end

- i think this is what you want
leon

On 14 Apr 2000 16:36:04 -0500, Craig Markwardt
<craigmnet@cow.physics.wisc.edu> wrote:

>
> I have noticed that the use of /GET_LUN and ERROR keywords to openr is
> not as helpful as I would have hoped. Do other have this experience?
> The problem is that when an error occurs, it is hard to know whether
> the file unit was "gotten" or not.
>
> For example:
>
> pro test1
> openr, unit, filename, /get_lun, error=err
> free_lun, unit
> end
>
> If there was an error, then it is possible that UNIT was never set,
> and is hence undefined. FREE_LUN doesn't take undefined variables.
>
> If there is error checking to do, I don't know exactly what it should
> be. So I find myself explicitly doing this instead:
>
> pro test2
> get_lun, unit
> openr, unit, filename, error=err
> free_lun, unit
> end
>
> Comments?
>
> Craig
>
> --
> ------------------------------------------------------------ --------------
> Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
> Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
> ------------------------------------------------------------ --------------

-------------------------
Leon Majewski

Remote Sensing & Satellite Research Group
Curtin University of Technology, Perth, Australia

email: majewski@ses.curtin.edu.au
Re: openr and /get_lun [message #19736 is a reply to message #19734] Sun, 16 April 2000 00:00 Go to previous message
mallors is currently offline  mallors
Messages: 76
Registered: November 1997
Member
In article <onitxkz7p7.fsf@cow.physics.wisc.edu>,
Craig Markwardt <craigmnet@cow.physics.wisc.edu> writes:
>
> I have noticed that the use of /GET_LUN and ERROR keywords to openr is
> not as helpful as I would have hoped. Do other have this experience?
> The problem is that when an error occurs, it is hard to know whether
> the file unit was "gotten" or not.
>
> For example:
>
> pro test1
> openr, unit, filename, /get_lun, error=err
> free_lun, unit
> end
>
> If there was an error, then it is possible that UNIT was never set,
> and is hence undefined. FREE_LUN doesn't take undefined variables.


I guess I never thought about it too much, because if
there is an error with the OPEN, then I should handle
it somehow:

OPENR, fl, 'nofile', /GET_LUN, ERROR = error
IF (error NE 0) THEN BEGIN
MESSAGE, /CONTINUE, 'Could not open file.'
RETURN
ENDIF
.
.
.
FREE_LUN, fl


Otherwise, if you don't want to handle the error, you can just
free the unit number conditionally, as I am sure you know:

IF (error EQ 0) THEN FREE_LUN, fl


I sure wish we had a boolean datatype - the mistake of
using something like "IF (NOT error) THEN" is one that
is really a pain to find, although it certainly makes
your code much more readable.


-bob



--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~
Robert S. Mallozzi 256-544-0887
Mail Code SD 50
http://gammaray.msfc.nasa.gov/ Marshall Space Flight Center
http://cspar.uah.edu/~mallozzir/ Huntsville, AL 35812
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~
Re: openr and /get_lun [message #19740 is a reply to message #19734] Fri, 14 April 2000 00:00 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Craig Markwardt (craigmnet@cow.physics.wisc.edu) writes:

> I have noticed that the use of /GET_LUN and ERROR keywords to openr is
> not as helpful as I would have hoped. Do other have this experience?
> The problem is that when an error occurs, it is hard to know whether
> the file unit was "gotten" or not.
>
> For example:
>
> pro test1
> openr, unit, filename, /get_lun, error=err
> free_lun, unit
> end
>
> If there was an error, then it is possible that UNIT was never set,
> and is hence undefined. FREE_LUN doesn't take undefined variables.
>
> If there is error checking to do, I don't know exactly what it should
> be. So I find myself explicitly doing this instead:
>
> pro test2
> get_lun, unit
> openr, unit, filename, error=err
> free_lun, unit
> end
>
> Comments?

I guess I'd use the ol' IF N_Elements(lun) NE 0 THEN Free_Lun, lun

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: interactive plotting and ps output.
Next Topic: ROUTINE_NAMES and other magic

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

Current Time: Wed Oct 08 18:40:12 PDT 2025

Total time taken to generate the page: 0.00656 seconds