[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: openr and /get_lun



Craig Markwardt 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?
 

Hi Craig,
you have to trap the error.
it is the open that can fail, so you have to check the err variable:

pro test2
  get_lun, unit
  openr, unit, filename, error=err
  if (err le 0) then begin
        ;error management
        ...............................
  endif
  free_lun, unit
end
 
 

You can also use the more flexible error trapping CATCH procedure.
It is general and not only for file management:

pro testOpen
        errorStatus=0
        catch,errorStatus
        if errorStatus ne 0 then begin
                ;error management
                print,!ERR_STRING
                return
        endif
        openr,lun,'pippone',/get_lun
        free_lun,lun
end
 
-- 
Nando Iavarone
Advanced Computer System - SPACE DIVISION
via Lazzaro Belli, 23
00040  Frascati - RM
Tel: +39-6-944091 (switchboard)
          9440968 (direct)
E-mail: 
    f.iavarone@acsys.it
    FrdndVrn@altavista.net