[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: N_ELEMENTS and WHERE: Scalar or Array ?
- Subject: Re: N_ELEMENTS and WHERE: Scalar or Array ?
- From: wmc(at)bas.ac.uk
- Date: 1 Feb 1999 09:51:48 GMT
- Newsgroups: comp.lang.idl-pvwave
- References: <firstname.lastname@example.org>
- User-Agent: tin/pre-1.4-981114 ("The Watchman") (UNIX) (OSF1/V4.0 (alpha))
- Xref: news.doit.wisc.edu comp.lang.idl-pvwave:13503
>Hi All, I keep making the same mistake with N_ELEMENTS so I decided
>to write and ask if anyone has found a solution. I use WHERE to find some
>zeroes in a data set which I want to exclude in further processing. Problem
>is that sometimes they are all zeroes. Using a simple :
>non_zero_xvalues = WHERE (subarray1 GT 0)
>IF(non_zero_array EQ -1) ...
>gets me into trouble because, when it is an array, I get an error. If I use
>N_ELEMENTS(non_zero_array) there is always at least one element, whether it
>is -1 or something else. I don't like ignoring the 'something else' value
>just because it is the only one. Is the answer another IF statement or some
>sort of error control?
The temporay solution to this is to use where(wurble,count)...
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
instead of the ugly
if (count gt 0) then array[i]='stoat'
I use Perl a lot, and the contrast is very striking there: perl handles null
values quite happily and it simplifies a lot of things.
While I'm here: would RSI please put a decent regexp package into IDL?
William M Connolley | email@example.com | http://www.nbs.ac.uk/public/icd/wmc/
Climate Modeller, British Antarctic Survey | Disclaimer: I speak for myself