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

Re: N_ELEMENTS and WHERE: Scalar or Array ?



wmc@bas.ac.uk writes:
> ...
> But since this has come up, & its one of my pet peeves: why cannot where
> return a null array to indicate no-elements-match. And then array[null] would
> match to nothing. This would allow one to say
> 
>   array[where(wurble)]='stoat'
> 
> instead of the ugly
> 
>   i=where(wurble,count)
>   if (count gt 0) then array[i]='stoat'
> 

Amen brother!  It is sadly unfortunate that where(0) returns a number
at all.  A null array -- if IDL had them! -- would be the best.

Of course, there is the trade-off between power user and newbie user.
Consider the following:

wh_one = where(x GT 1)
x[wh_ine] = 0              ; NOTE the type

Because of the typo, the second statement would have the mysterious
side effect of having no effect at all! (including no error message) I
would still love to have it, but newbies might go crazy.

Craig

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