Re: how to clear error message [message #73266] |
Thu, 04 November 2010 03:51  |
wlandsman
Messages: 743 Registered: June 2000
|
Senior Member |
|
|
On Nov 3, 10:29 pm, Truong Le <truong...@gmail.com> wrote:
> On Nov 3, 10:24 pm, Truong Le <truong...@gmail.com> wrote:
>
>
>
>
>
>> On Nov 3, 9:44 pm, David Fanning <n...@dfanning.com> wrote:
>
>>> Truong Le writes:
>>>> David, I am not trying to suppress the error but instead I am
>>>> trying to catch that error so that I can exit my loop and read the
>>>> next FITS file.
>
>>> Yes, and several people have suggested a CATCH error
>>> handler, which to almost everyone responding here
>>> would seem to be *exactly* what you want to use.
>>> So, what is the problem?
>
>>> Is the problem that the "message" is an informational
>>> message and not really an error?
>
>>> We really need more details I guess, if we are going
>>> to help in any sensible way. It doesn't help us to know
>>> something "didn't work." That's almost always an excuse
>>> for pilot error. :-)
>
>>> Cheers,
>
>>> David
>
>>> --
>>> David Fanning, Ph.D.
>>> Fanning Software Consulting, Inc.
>>> Coyote's Guide to IDL Programming:http://www.dfanning.com/
>>> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
>
>> okay, let's say I have 100 FITS files that I want to loop through to
>> check certain
>> keywords from each FITS file. To obtain the header keywords I use the
>> headfits.pro
>> from the Astronomy IDL's library. When one of the FITS file is badly
>> formatted headfit
>> spat out a run-on warning message "% MRD_HREAD: Warning-Invalid
>> characters in header" and
>> then eventually die. I want to be able to catch this error and move on
>> reading the next
>> FITS file. The problem that I am having is that I use the "Catch"
>> error handler to catch
>> this error as people have suggested but it doesn't work. I have read
>> some of your other
>> thread that talk about trapping error by using
>
>> files = ['file1.fits', 'file2.fits', 'file3.fits', ....]
>> for i=0,100 do begin
>> header = headfit(files[i])
>
>> Help, /Last_Message, Output=theErrorMessage
>> errorLength = N_ELEMENTS(theErrorMessage)
>
>> if (errorLength GT 0) then begin
>> goto, jumptoendOFloop
>> endif
>> ....
>> ....
>> ....
>> jumptoendOfloop
>> endfor
>
>> This will trap the error of the bad FITS file, however, I need to know
>> how I can clear
>> the "errors" that are in memory so that in my next loop with a good
>> FITS file I will pass
>> through the above example.
>
>> and thank you for all the help guys!
>
> incomplete thought :-) ...
>
> I have read some of your other thread that talk about trapping error
> by using
>
>> Help, /Last_Message, Output=theErrorMessage
>> errorLength = N_ELEMENTS(theErrorMessage)
>
> I need to know how to clear the "errors" that are in memory once you
> have trap the
> error using the above method?
You can use message,/reset to clear the errors, so your code will look
like this
Help, /Last_Message, Output=theErrorMessage
errorLength = N_ELEMENTS(theErrorMessage)
if (errorLength GT 0) then begin
message,/reset
goto, jumptoendOFloop
endif
|
|
|
Re: how to clear error message [message #73269 is a reply to message #73266] |
Wed, 03 November 2010 19:29   |
Truong Le
Messages: 42 Registered: September 2010
|
Member |
|
|
On Nov 3, 10:24 pm, Truong Le <truong...@gmail.com> wrote:
> On Nov 3, 9:44 pm, David Fanning <n...@dfanning.com> wrote:
>
>
>
>> Truong Le writes:
>>> David, I am not trying to suppress the error but instead I am
>>> trying to catch that error so that I can exit my loop and read the
>>> next FITS file.
>
>> Yes, and several people have suggested a CATCH error
>> handler, which to almost everyone responding here
>> would seem to be *exactly* what you want to use.
>> So, what is the problem?
>
>> Is the problem that the "message" is an informational
>> message and not really an error?
>
>> We really need more details I guess, if we are going
>> to help in any sensible way. It doesn't help us to know
>> something "didn't work." That's almost always an excuse
>> for pilot error. :-)
>
>> Cheers,
>
>> David
>
>> --
>> David Fanning, Ph.D.
>> Fanning Software Consulting, Inc.
>> Coyote's Guide to IDL Programming:http://www.dfanning.com/
>> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
>
> okay, let's say I have 100 FITS files that I want to loop through to
> check certain
> keywords from each FITS file. To obtain the header keywords I use the
> headfits.pro
> from the Astronomy IDL's library. When one of the FITS file is badly
> formatted headfit
> spat out a run-on warning message "% MRD_HREAD: Warning-Invalid
> characters in header" and
> then eventually die. I want to be able to catch this error and move on
> reading the next
> FITS file. The problem that I am having is that I use the "Catch"
> error handler to catch
> this error as people have suggested but it doesn't work. I have read
> some of your other
> thread that talk about trapping error by using
>
> files = ['file1.fits', 'file2.fits', 'file3.fits', ....]
> for i=0,100 do begin
> header = headfit(files[i])
>
> Help, /Last_Message, Output=theErrorMessage
> errorLength = N_ELEMENTS(theErrorMessage)
>
> if (errorLength GT 0) then begin
> goto, jumptoendOFloop
> endif
> ....
> ....
> ....
> jumptoendOfloop
> endfor
>
> This will trap the error of the bad FITS file, however, I need to know
> how I can clear
> the "errors" that are in memory so that in my next loop with a good
> FITS file I will pass
> through the above example.
>
> and thank you for all the help guys!
incomplete thought :-) ...
I have read some of your other thread that talk about trapping error
by using
> Help, /Last_Message, Output=theErrorMessage
> errorLength = N_ELEMENTS(theErrorMessage)
I need to know how to clear the "errors" that are in memory once you
have trap the
error using the above method?
|
|
|
Re: how to clear error message [message #73270 is a reply to message #73269] |
Wed, 03 November 2010 19:25   |
wlandsman
Messages: 743 Registered: June 2000
|
Senior Member |
|
|
On Nov 3, 8:58 pm, Truong Le <truong...@gmail.com> wrote:
> On Nov 3, 7:59 pm, wlandsman <wlands...@gmail.com> wrote:
>
>
>
>
>
>> On Nov 3, 7:43 pm, ThanhThoan Nguyen <marct...@gmail.com> wrote:
>
>>>> > When I try to read a bad FITS file I obtain the following error
>
>>>> > % MRD_HREAD: Warning-Invalid characters in header
>
>>> I am trying to loop over several FITS files, and I want to be able to
>>> catch
>>> this error and move on to the next FITS file. With the silent keyword
>>> I don't
>>> think this will resolve my problem.
>
>> Note that MRD_HREAD is not printing an error message, but an
>> "informational" message.
>> Below is the relevant code within MRD_HREAD
>
>> ; Check that there aren't improper null characters in strings that are
>> causing
>> ; them to be truncated. Issue a warning but continue if problems are
>> found.
>
>> w = where(strlen(block) ne 80, Nbad)
>> if (Nbad GT 0) then begin
>> if ~keyword_set(SILENT) then message, /INF, $
>> 'Warning-Invalid characters in header'
>> block[w] = string(replicate(32b, 80))
>> endif
>
>> You might be able to catch the error if you change the /INFORMATIONAL
>> to /CONTINUE.
>
>> --Wayne
>
> I am sorry but are you suggesting that I modify the MRD_HREAD
> procedure?
Yes, I am suggesting that you modify the MRD_HREAD procedure.
I assume this is a one-time case where for some reason you have been
given some corrupted FITS files mixed with good ones. So I would
make the above change to MRD_HREAD and when you are done processing
these files, revert back to the original MRD_HREAD. (Better yet, I
would first flag the corrupted files -- and find out how they are
corrupted -- by using the fitsverify tool ( http://fits.gsfc.nasa.gov/fits_verify.html
).
If for some reason you expect this problem to keep occurring, then I
suggest you contact the author of MRD_HREAD ;-) and ask for a new
keyword -- maybe /STRICTERROR to tell MRD_HREAD to abort with an error
signal at any sign of a corrupted file, rather than trying to keep
reading the file, as it currently does. --Wayne
|
|
|
Re: how to clear error message [message #73271 is a reply to message #73270] |
Wed, 03 November 2010 19:24   |
Truong Le
Messages: 42 Registered: September 2010
|
Member |
|
|
On Nov 3, 9:44 pm, David Fanning <n...@dfanning.com> wrote:
> Truong Le writes:
>> David, I am not trying to suppress the error but instead I am
>> trying to catch that error so that I can exit my loop and read the
>> next FITS file.
>
> Yes, and several people have suggested a CATCH error
> handler, which to almost everyone responding here
> would seem to be *exactly* what you want to use.
> So, what is the problem?
>
> Is the problem that the "message" is an informational
> message and not really an error?
>
> We really need more details I guess, if we are going
> to help in any sensible way. It doesn't help us to know
> something "didn't work." That's almost always an excuse
> for pilot error. :-)
>
> Cheers,
>
> David
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
okay, let's say I have 100 FITS files that I want to loop through to
check certain
keywords from each FITS file. To obtain the header keywords I use the
headfits.pro
from the Astronomy IDL's library. When one of the FITS file is badly
formatted headfit
spat out a run-on warning message "% MRD_HREAD: Warning-Invalid
characters in header" and
then eventually die. I want to be able to catch this error and move on
reading the next
FITS file. The problem that I am having is that I use the "Catch"
error handler to catch
this error as people have suggested but it doesn't work. I have read
some of your other
thread that talk about trapping error by using
files = ['file1.fits', 'file2.fits', 'file3.fits', ....]
for i=0,100 do begin
header = headfit(files[i])
Help, /Last_Message, Output=theErrorMessage
errorLength = N_ELEMENTS(theErrorMessage)
if (errorLength GT 0) then begin
goto, jumptoendOFloop
endif
....
....
....
jumptoendOfloop
endfor
This will trap the error of the bad FITS file, however, I need to know
how I can clear
the "errors" that are in memory so that in my next loop with a good
FITS file I will pass
through the above example.
and thank you for all the help guys!
|
|
|
|
Re: how to clear error message [message #73273 is a reply to message #73272] |
Wed, 03 November 2010 18:39   |
Truong Le
Messages: 42 Registered: September 2010
|
Member |
|
|
On Nov 3, 9:22 pm, David Fanning <n...@dfanning.com> wrote:
> Truong Le writes:
>> I am sorry but are you suggesting that I modify the MRD_HREAD
>> procedure?
>
> It's generally not my style to state the obvious,
> but normally when a program issues an error message,
> you don't seek to turn the error message off, you
> try to fix the error that caused it.
>
> Is there something about this program that you would
> like to share with us that makes it out of the
> ordinary?
>
> I haven't used every single one of the NASA Astronomy
> Library routines, but I've used enough to know if
> an error is being issued, there is probably a pretty
> good reason for it.
>
> Cheers,
>
> David
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
David, I am not trying to suppress the error but instead I am
trying to catch that error so that I can exit my loop and read the
next FITS file.
|
|
|
|
|
Re: how to clear error message [message #73276 is a reply to message #73275] |
Wed, 03 November 2010 18:01   |
Truong Le
Messages: 42 Registered: September 2010
|
Member |
|
|
On Nov 3, 7:12 pm, chris <rog...@googlemail.com> wrote:
> On 3 Nov., 22:45, David Fanning <n...@dfanning.com> wrote:
>
>
>
>> Truong Le writes:
>>> I did that but it didn't work.
>
>> Coyote wanted me to point out that a silent error handler
>> is often required in this case. That way, no one is the
>> wiser, and there is no need to fix the underlying
>> cause of the error, either. ;-)
>
>> Cheers,
>
>> David
>
>> --
>> David Fanning, Ph.D.
>> Fanning Software Consulting, Inc.
>> Coyote's Guide to IDL Programming:http://www.dfanning.com/
>> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
>
> Or you just add this in the first line and you will never get an error
> again :-)
>
> goto1:while ~n_elements(_) do goto,goto1
>
> Cheers
>
> CR
could you please explain exactly what this line does?
|
|
|
Re: how to clear error message [message #73277 is a reply to message #73276] |
Wed, 03 November 2010 17:58   |
Truong Le
Messages: 42 Registered: September 2010
|
Member |
|
|
On Nov 3, 7:59 pm, wlandsman <wlands...@gmail.com> wrote:
> On Nov 3, 7:43 pm, ThanhThoan Nguyen <marct...@gmail.com> wrote:
>
>>>> When I try to read a bad FITS file I obtain the following error
>
>>>> % MRD_HREAD: Warning-Invalid characters in header
>
>> I am trying to loop over several FITS files, and I want to be able to
>> catch
>> this error and move on to the next FITS file. With the silent keyword
>> I don't
>> think this will resolve my problem.
>
> Note that MRD_HREAD is not printing an error message, but an
> "informational" message.
> Below is the relevant code within MRD_HREAD
>
> ; Check that there aren't improper null characters in strings that are
> causing
> ; them to be truncated. Issue a warning but continue if problems are
> found.
>
> w = where(strlen(block) ne 80, Nbad)
> if (Nbad GT 0) then begin
> if ~keyword_set(SILENT) then message, /INF, $
> 'Warning-Invalid characters in header'
> block[w] = string(replicate(32b, 80))
> endif
>
> You might be able to catch the error if you change the /INFORMATIONAL
> to /CONTINUE.
>
> --Wayne
I am sorry but are you suggesting that I modify the MRD_HREAD
procedure?
|
|
|
|
|
Re: how to clear error message [message #73284 is a reply to message #73283] |
Wed, 03 November 2010 16:12   |
rogass
Messages: 200 Registered: April 2008
|
Senior Member |
|
|
On 3 Nov., 22:45, David Fanning <n...@dfanning.com> wrote:
> Truong Le writes:
>> I did that but it didn't work.
>
> Coyote wanted me to point out that a silent error handler
> is often required in this case. That way, no one is the
> wiser, and there is no need to fix the underlying
> cause of the error, either. ;-)
>
> Cheers,
>
> David
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Or you just add this in the first line and you will never get an error
again :-)
goto1:while ~n_elements(_) do goto,goto1
Cheers
CR
|
|
|
|
|
Re: how to clear error message [message #73287 is a reply to message #73286] |
Wed, 03 November 2010 14:28   |
Truong Le
Messages: 42 Registered: September 2010
|
Member |
|
|
On Nov 3, 5:26 pm, Paul van Delst <paul.vande...@noaa.gov> wrote:
> What about trying a catch error handler? Something like this:
>
> pro blah
> CATCH, error_status
> IF ( error_status NE 0 ) THEN BEGIN
> CATCH, /CANCEL
> MESSAGE, !ERROR_STATE.MSG, /CONTINUE
> RETURN
> ENDIF
>
> ....do other stuff....
>
> end
>
> If an error occurs in the "....do other stuff...." section, the error message will get printed out control will return
> to the caller.
>
> You can throw your own errors in the "....do other stuff...." section by doing something like
>
> IF ( ...an error condition is detected... ) THEN $
> MESSAGE, 'this is my own error message', /NONAME, /NOPRINT
>
> when you detect an error in your own code.
>
> cheers,
>
> paulv
>
> Truong Le wrote:
>> All,
>
>> I need to know how to clear all error message that idl generated.
>
>> I am using this two lines to stop to trap my error.
>
>> Help, /Last_Message, Output=theErrorMessage
>> errorLength = N_ELEMENTS(theErrorMessage)
>
>> However, I need to clear all the error message so that when I am
>> looping to these two lines again the
>> errorLength should be zero when no error message occur.
>
>> Thanks
>
>
I did that but it didn't work.
Thanks,
|
|
|
|
Re: how to clear error message [message #73289 is a reply to message #73288] |
Wed, 03 November 2010 14:26   |
Paul Van Delst[1]
Messages: 1157 Registered: April 2002
|
Senior Member |
|
|
What about trying a catch error handler? Something like this:
pro blah
CATCH, error_status
IF ( error_status NE 0 ) THEN BEGIN
CATCH, /CANCEL
MESSAGE, !ERROR_STATE.MSG, /CONTINUE
RETURN
ENDIF
....do other stuff....
end
If an error occurs in the "....do other stuff...." section, the error message will get printed out control will return
to the caller.
You can throw your own errors in the "....do other stuff...." section by doing something like
IF ( ...an error condition is detected... ) THEN $
MESSAGE, 'this is my own error message', /NONAME, /NOPRINT
when you detect an error in your own code.
cheers,
paulv
Truong Le wrote:
> All,
>
> I need to know how to clear all error message that idl generated.
>
> I am using this two lines to stop to trap my error.
>
> Help, /Last_Message, Output=theErrorMessage
> errorLength = N_ELEMENTS(theErrorMessage)
>
> However, I need to clear all the error message so that when I am
> looping to these two lines again the
> errorLength should be zero when no error message occur.
>
> Thanks
|
|
|
|
Re: how to clear error message [message #73397 is a reply to message #73281] |
Thu, 04 November 2010 11:47  |
Truong Le
Messages: 42 Registered: September 2010
|
Member |
|
|
On Nov 3, 7:59 pm, wlandsman <wlands...@gmail.com> wrote:
> On Nov 3, 7:43 pm, ThanhThoan Nguyen <marct...@gmail.com> wrote:
>
>>>> When I try to read a bad FITS file I obtain the following error
>
>>>> % MRD_HREAD: Warning-Invalid characters in header
>
>> I am trying to loop over several FITS files, and I want to be able to
>> catch
>> this error and move on to the next FITS file. With the silent keyword
>> I don't
>> think this will resolve my problem.
>
> Note that MRD_HREAD is not printing an error message, but an
> "informational" message.
> Below is the relevant code within MRD_HREAD
>
> ; Check that there aren't improper null characters in strings that are
> causing
> ; them to be truncated. Issue a warning but continue if problems are
> found.
>
> w = where(strlen(block) ne 80, Nbad)
> if (Nbad GT 0) then begin
> if ~keyword_set(SILENT) then message, /INF, $
> 'Warning-Invalid characters in header'
> block[w] = string(replicate(32b, 80))
> endif
>
> You might be able to catch the error if you change the /INFORMATIONAL
> to /CONTINUE.
>
> --Wayne
thank you everyone for helping me with this problem. I have to modify
the MRD_HREAD
by breaking inner if statement into a block and set status=-1 and
return to get out
of this loop; and it works!
Thank you All!
|
|
|
Re: how to clear error message [message #73408 is a reply to message #73287] |
Thu, 04 November 2010 06:53  |
Paul Van Delst[1]
Messages: 1157 Registered: April 2002
|
Senior Member |
|
|
Truong Le wrote:
> On Nov 3, 5:26 pm, Paul van Delst <paul.vande...@noaa.gov> wrote:
>> What about trying a catch error handler? Something like this:
>>
>> pro blah
>> CATCH, error_status
>> IF ( error_status NE 0 ) THEN BEGIN
>> CATCH, /CANCEL
>> MESSAGE, !ERROR_STATE.MSG, /CONTINUE
>> RETURN
>> ENDIF
>>
>> ....do other stuff....
>>
>> end
>>
>> If an error occurs in the "....do other stuff...." section, the error message will get printed out control will return
>> to the caller.
>>
>> You can throw your own errors in the "....do other stuff...." section by doing something like
>>
>> IF ( ...an error condition is detected... ) THEN $
>> MESSAGE, 'this is my own error message', /NONAME, /NOPRINT
>>
>> when you detect an error in your own code.
>>
>> cheers,
>>
>> paulv
>>
>> Truong Le wrote:
>>> All,
>>> I need to know how to clear all error message that idl generated.
>>> I am using this two lines to stop to trap my error.
>>> Help, /Last_Message, Output=theErrorMessage
>>> errorLength = N_ELEMENTS(theErrorMessage)
>>> However, I need to clear all the error message so that when I am
>>> looping to these two lines again the
>>> errorLength should be zero when no error message occur.
>>> Thanks
>>
>
> I did that but it didn't work.
I tried that and it did work.
cheers,
paulv
|
|
|