NaN doesn't work! [message #93350] |
Mon, 20 June 2016 15:11  |
Libo Wang
Messages: 6 Registered: October 2009
|
Junior Member |
|
|
Hi, I have an array with negative numbers (-99.0) representing invalid values. I need to use Total to do some calculation, so I'm converting the invalid values to NaN first:
print,data[60,31,1]
bad=where(data lt 0.0,cbad)
if cbad gt 0 then data[bad]=nan
print,data[60,31,1]
I've got -99.0 from both the print line!! Anybody knows why? I thought I knew how to do some simple IDL coding, now I'm not sure!
Thanks in advance!
Jenny
|
|
|
Re: NaN doesn't work! [message #93351 is a reply to message #93350] |
Mon, 20 June 2016 16:41  |
Dick Jackson
Messages: 347 Registered: August 1998
|
Senior Member |
|
|
On Monday, 20 June 2016 15:11:34 UTC-7, lib...@gmail.com wrote:
> Hi, I have an array with negative numbers (-99.0) representing invalid values. I need to use Total to do some calculation, so I'm converting the invalid values to NaN first:
>
> print,data[60,31,1]
> bad=where(data lt 0.0,cbad)
> if cbad gt 0 then data[bad]=nan
> print,data[60,31,1]
>
> I've got -99.0 from both the print line!! Anybody knows why? I thought I knew how to do some simple IDL coding, now I'm not sure!
>
> Thanks in advance!
> Jenny
I think what you want here is
if cbad gt 0 then data[bad]=!VALUES.F_NAN ; or !VALUES.D_NAN for Double
But I'm puzzled: if you ran it exactly as you said, the elements in data[bad] would have been given the value of a variable named 'nan'. For your final print to have given -99.0, that variable 'nan' must have had -99.0 in it. Is that possible? If so, then IDL's doing just what you asked. :-)
You could, of course set the variable before this code section as follows, then it will work fine:
nan = !VALUES.F_NAN ; or !VALUES.D_NAN for Double
Cheers,
-Dick
Dick Jackson Software Consulting Inc.
Victoria, BC, Canada --- http://www.d-jackson.com
|
|
|