[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bad data in structure (NaN HowTo?)

Randall Skelton <rhskelto@atm.ox.ac.uk> writes:
> I have an array of large structures which occasionally is filled (via an
> external C program) and passed into IDL with -12345 signifying the data
> for that element is lost.  I would like to convert the occurances of
> -12345 to NaN's in IDL but I am a little perplexed on how to do this.
> I had hoped that since this is technically an 'array' (albeit an array of
> structures) I would just be able to use the 'where' command; alas, it
> appears that structures are not allowed in the where command:
> B = where(atrl eq -12345, count)
> % Struct expression not allowed in this context: ATRL.

Hi Randall--

You have the 500-pound gorilla approach from Pavel.  However, if your
-12345's appear in a few well defined fields in the structure, then
it's much easier and more efficent to do the following:

  wh = where(atrl.field1 EQ -12345, ct) 
  if ct GT 0 then atrl(wh).field1 = -12345

However, if there are lots of fields then the 500-pound gorilla may be
what you need.  You mentioned that integers and strings are the same
way.  How can this be?  There is no such thing as a NaN string or

If you do it in C, I would propose that you pass in the value of NaN
into your C procedure and then just use it there.  That should be the
most portable.  Then from the IDL side you would call your routine


Craig B. Markwardt, Ph.D.         EMAIL:    craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response