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

Home » Public Forums » archive » Re: IDL-way to use WHERE result as subscripting indices without having to do IF count
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: IDL-way to use WHERE result as subscripting indices without having to do IF count [message #76180] Fri, 20 May 2011 08:22 Go to previous message
Heinz Stege is currently offline  Heinz Stege
Messages: 189
Registered: January 2003
Senior Member
On Fri, 20 May 2011 14:06:58 +0100, Robin Wilson wrote:

> Hi all,
>
> I'm sure this has been discussed before, but I can't find the
> discussion. I have a lot of code that looks like the following:
>
> Array[WHERE(Input LT 5)] = 2
> Array[WHERE(Input GT 7 AND OtherArray LT 9) = 6
> etc...
>
> I know I shouldn't be using WHERE like that without checking the count
> of items returned, as it will crash if there are no values in Input less
> than 5. My question is: is there an IDL-way to do this, without putting
> in loads of IF count NE 0 statements above each of the assignemnts?
> That'll make the code a lot longer, a lot messier etc.
>
> Any ideas?
>
> Cheers,
>
> Robin


Hi Robin,

for IDL versions previous 8.0 you can use a wrapper function for
WHERE:

function anywhere,array,subscripts,count=count
compile_opt idl2
subscripts=where(array,count)
return,count ge 1
end

With this function you still need the IF statement, however you don't
need more than one line:

if anywhere(Input LT 5,ii) then Array[ii] = 2
if anywhere(Input GT 7 AND OtherArray LT 9,ii) then Array[ii] = 6

Cheers, Heinz
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: H5F_OPEN/H5F_CLOSE apparent memory leak
Next Topic: A Sign You're Getting Old

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

Current Time: Thu Oct 09 19:56:46 PDT 2025

Total time taken to generate the page: 0.55953 seconds