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

Home » Public Forums » archive » Re: error reading file question
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: error reading file question [message #51200 is a reply to message #51197] Tue, 07 November 2006 11:08 Go to previous messageGo to previous message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
David Groff wrote:
> Is there a way in IDL to check for problems when reading a data file?
> For example in Fortran you would do something like
> Error_Status = Read (filename)
> IF ( Error_Status /= Success ) THEN
> --------------------------(etc.)
>
> If something is wrong with the data file the problem would be discovered
> via error_status.
>
> Thanks

Hello again Dave! :o)

This is how I do it (you can check the netCDF TauProfile read function for more details):

pro test
; Setup error handler
catch, ierr
if(ierr ne 0)then begin
catch, /cancel
message, !error_state.msg + '; Closing file...', /continue
if(n_elements(fileid) ne 0) then free_lun, fileid
return
endif
; Read non-existant file
openr, fileid, 'newfile.dat', /get_lun
x=0.0
readu, fileid, x
free_lun, fileid
print, x
catch,/cancel ; <--- don't forget this
end

IDL> .run test
% Compiled module: TEST.
IDL> test
% TEST: OPENR: Error opening file. Unit: 100, File: newfile.dat; Closing file...

You can also use ON_IOERROR, but that's basically a fancy way of saying GOTO. I reckon the
CATCH method is cleaner.

BTW, this should work for any error. If you want to flag your own errors you can just do
something like:

if( ...some error condition...) then $
message, 'Some error condition occurred', /noname, /noprint

and control will be sent to the CATCH handler.


cheers,

paulv

--
Paul van Delst Ride lots.
CIMSS @ NOAA/NCEP/EMC Eddy Merckx
Ph: (301)763-8000 x7748
Fax:(301)763-8545
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Printing problem as RGB in Linux
Next Topic: 3D plotting

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

Current Time: Sun Oct 12 07:02:47 PDT 2025

Total time taken to generate the page: 1.12459 seconds