Re: Turning off math error checking for a code block [message #28890 is a reply to message #28888] |
Thu, 17 January 2002 11:30   |
Vapuser
Messages: 63 Registered: November 1998
|
Member |
|
|
k-bowman@null.com (Kenneth Bowman) writes:
> I have an array x that is likely to have missing values in it, indicated by NaN's. I would like to search the array for values less than x_min. Because of the NaN's, WHERE generates a floating point error, e.g.,
>
> IDL> print, x
> 0.00000 NaN 2.00000 3.00000
> IDL> print, where(x lt 2.0)
> 0
> % Program caused arithmetic error: Floating illegal operand
>
Hmmmm..... I don't get this result.
IDL Version 5.3 (IRIX mipseb). (c) 1999, Research Systems, Inc.
Installation number: 12619.
Licensed for use by: Jet Propulsion Lab
IDL> y=[0,!values.f_nan,2,0.]
IDL> print,where( y LT 2,nx),nx
0 3
2
% Program caused arithmetic error: Floating illegal operand
IDL> !except=0
IDL> print,where( y LT 2,nx),nx
0 3
2
IDL> exit
The help says that for !except=1 (the default) it only reports the
exception upon arriving at back at an interactive prompt. On my SGI, it
still does the `where' and returns the correct answer, it just
complains.
>
> As best I understand the interaction between !EXCEPT and CHECK_MATH,
> in order to suppress this error message, while still checking errors
> elsewhere in the code, I must do the following:
>
> error = CHECK_MATH(/PRINT) ;If any errors have occurred, print
> save_except = !EXCEPT ;Save current exception flag
> !EXCEPT = 0 ;Set exception flag to 0
> i = WHERE(x LT x_min, ni) ;Find all x < x_min
> error = CHECK_MATH() ;Clear accumulated error status
> !EXCEPT = save_except ;Restore exception flag
>
> Am I making this harder than it needs to be?
>
You could use FINITE. But why bother? Your method saves you one
iteration over the array.
whd
--
William Daffer: 818-354-0161: William.Daffer@jpl.nasa.gov
|
|
|