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

Home » Public Forums » archive » NaN doesn't work!
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
NaN doesn't work! [message #93350] Mon, 20 June 2016 15:11 Go to next message
Libo Wang is currently offline  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 Go to previous message
Dick Jackson is currently offline  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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Moment and XROI
Next Topic: WHERE command returning -1 even if matching is there

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

Current Time: Wed Oct 08 11:24:31 PDT 2025

Total time taken to generate the page: 0.18220 seconds