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

Home » Public Forums » archive » Re: Clever Where() test
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
Re: Clever Where() test [message #4366] Fri, 26 May 1995 00:00 Go to next message
steinhh is currently offline  steinhh
Messages: 260
Registered: June 1994
Senior Member
In article <3q2tld$8du@post.gsfc.nasa.gov>, thompson@orpheus.nascom.nasa.gov (William Thompson) writes:
|> Paul Probert <probert@uwmfe.neep.wisc.edu> writes:
|>
|> >IDL allows you to give a zero subscript to a scalar,
|> >so you can say:
|> > i=WHERE(...)
|> > IF i(0) EQ -1 THEN BEGIN
|> > ...
|> >
|> >One word of caution. If you have a scalar element of a structure,
|> >for some reason you can't do this:
|> > x={i:0,j:1}
|> > IF x.i(0) ... ;bombs
|> >But you can make it work with more parentheses:
|> > IF (x.i)(0) ... ;works
|> >
|> > Paul Probert
|> > University of Wisconsin
|>
|> So does x(0).i
|>
|> Bill Thompson
|>

Just nit-picking: If the tag i in x.i is an array, only
the (x.i)(0) notation works. This works if x and/or i are
arrays (or scalars).


Stein Vidar
Re: Clever Where() test [message #4370 is a reply to message #4366] Thu, 25 May 1995 00:00 Go to previous messageGo to next message
thompson is currently offline  thompson
Messages: 584
Registered: August 1991
Senior Member
Paul Probert <probert@uwmfe.neep.wisc.edu> writes:

> IDL allows you to give a zero subscript to a scalar,
> so you can say:
> i=WHERE(...)
> IF i(0) EQ -1 THEN BEGIN
> ...
>
> One word of caution. If you have a scalar element of a structure,
> for some reason you can't do this:
> x={i:0,j:1}
> IF x.i(0) ... ;bombs
> But you can make it work with more parentheses:
> IF (x.i)(0) ... ;works
>
> Paul Probert
> University of Wisconsin

So does x(0).i

Bill Thompson
Re: Clever Where() test [message #4375 is a reply to message #4370] Thu, 25 May 1995 00:00 Go to previous messageGo to next message
Paul Probert is currently offline  Paul Probert
Messages: 7
Registered: May 1995
Junior Member
IDL allows you to give a zero subscript to a scalar,
so you can say:
i=WHERE(...)
IF i(0) EQ -1 THEN BEGIN
...

One word of caution. If you have a scalar element of a structure,
for some reason you can't do this:
x={i:0,j:1}
IF x.i(0) ... ;bombs
But you can make it work with more parentheses:
IF (x.i)(0) ... ;works

Paul Probert
University of Wisconsin
Re: Clever Where() test [message #4376 is a reply to message #4370] Thu, 25 May 1995 00:00 Go to previous messageGo to next message
thompson is currently offline  thompson
Messages: 584
Registered: August 1991
Senior Member
afl@cdc.noaa.gov (Andy Loughe) writes:

> In article <moleD93CEG.79n@netcom.com>, mole@netcom.com (Aaron Birenboim) writes:
> |> Is there a clever way to test for null return (-1) from WHERE???
> |>
> |> I'm doing stuff like :
> |>
> |> i = WHERE(x GT 0.0)
> |> s = SIZE(i)
> |> IF s(0) EQ 0 THEN BEGIN
> |> IF i GE 0 THEN BEGIN
> |> ; do something with x(i)
> |> ENDIF
> |> ENDIF ELSE BEGIN
> |> ; do something with the multiple elements x(i)
> |> ENDIF
> |>
> |> Is there a more clever way to handle this? Especially since the
> |> "do something...." code is often the same weather i is scalar or vector.
> |>
> |> I wish that "IF i eq -1 THEN..." wouldnt crash for vector i's!!!
> |> --


> How about this?

> i = WHERE( x GT 0.0, count)
> IF ( count gt 0 ) then 'do something with the x's

> The count is very handy indeed. You could also build a
> loop from 0, count-1 if you needed to.

For that matter, one could also do

i = WHERE(x GT 0.0)
IF i(0) NE -1 THEN 'do something with the x's

although I also prefer using the optional count parameter. On the other hand,
if all one cared about was whether and matches were found, and didn't care
where they are, then one could do something like

IF (WHERE(x GT 0.0))(0) NE -1 THEN PRINT, 'At least one is > 0.0'

One can always reference a variable with (0), even if it's a scalar.

Bill Thompson
Re: Clever Where() test [message #4379 is a reply to message #4370] Thu, 25 May 1995 00:00 Go to previous messageGo to next message
bertin is currently offline  bertin
Messages: 4
Registered: October 1994
Junior Member
Andy Loughe (afl@cdc.noaa.gov) wrote:
> In article <moleD93CEG.79n@netcom.com>, mole@netcom.com (Aaron Birenboim) writes:
> |> Is there a clever way to test for null return (-1) from WHERE???
> |>
> |> I'm doing stuff like :
> |>
> |> i = WHERE(x GT 0.0)
> |> s = SIZE(i)
> |> IF s(0) EQ 0 THEN BEGIN
> |> IF i GE 0 THEN BEGIN
> |> ; do something with x(i)
> |> ENDIF
> |> ENDIF ELSE BEGIN
> |> ; do something with the multiple elements x(i)
> |> ENDIF
> |>
> |> Is there a more clever way to handle this? Especially since the
> |> "do something...." code is often the same weather i is scalar or vector.
> |>
> |> I wish that "IF i eq -1 THEN..." wouldnt crash for vector i's!!!
> |> --
>
>
> How about this?
>
> i = WHERE( x GT 0.0, count)
> IF ( count gt 0 ) then 'do something with the x's
>
> The count is very handy indeed. You could also build a
> loop from 0, count-1 if you needed to.
>
> --

or this

IF i(0) EQ -1 THEN ...

Works for vector and scalar i's

Scott J. Bertin
bertin@euler.cpi.com
Re: Clever Where() test [message #4386 is a reply to message #4370] Wed, 24 May 1995 00:00 Go to previous messageGo to next message
afl is currently offline  afl
Messages: 51
Registered: December 1994
Member
In article <moleD93CEG.79n@netcom.com>, mole@netcom.com (Aaron Birenboim) writes:
|> Is there a clever way to test for null return (-1) from WHERE???
|>
|> I'm doing stuff like :
|>
|> i = WHERE(x GT 0.0)
|> s = SIZE(i)
|> IF s(0) EQ 0 THEN BEGIN
|> IF i GE 0 THEN BEGIN
|> ; do something with x(i)
|> ENDIF
|> ENDIF ELSE BEGIN
|> ; do something with the multiple elements x(i)
|> ENDIF
|>
|> Is there a more clever way to handle this? Especially since the
|> "do something...." code is often the same weather i is scalar or vector.
|>
|> I wish that "IF i eq -1 THEN..." wouldnt crash for vector i's!!!
|> --


How about this?

i = WHERE( x GT 0.0, count)
IF ( count gt 0 ) then 'do something with the x's

The count is very handy indeed. You could also build a
loop from 0, count-1 if you needed to.

--

Andrew F. Loughe email: afl@cdc.noaa.gov
University of Colorado, CIRES voice: (303) 492-0707
Campus Box 449 fax: (303) 497-7013
Boulder, CO 80309-0449 USA
Re: Clever Where() test [message #4436 is a reply to message #4386] Tue, 30 May 1995 00:00 Go to previous message
offenbrg is currently offline  offenbrg
Messages: 31
Registered: August 1993
Member
afl@cdc.noaa.gov (Andy Loughe) writes:

> In article <moleD93CEG.79n@netcom.com>, mole@netcom.com (Aaron Birenboim) writes:
> |> Is there a clever way to test for null return (-1) from WHERE???
> |>
> |> I'm doing stuff like :
> |>
> |> i = WHERE(x GT 0.0)
> |> s = SIZE(i)
> |> IF s(0) EQ 0 THEN BEGIN
> |> IF i GE 0 THEN BEGIN
> |> ; do something with x(i)
> |> ENDIF
> |> ENDIF ELSE BEGIN
> |> ; do something with the multiple elements x(i)
> |> ENDIF
> |>
> |> Is there a more clever way to handle this? Especially since the
> |> "do something...." code is often the same weather i is scalar or vector.
> |>
> |> I wish that "IF i eq -1 THEN..." wouldnt crash for vector i's!!!
> |> --

There's another cute way:

i = WHERE(x GT 0.0)
IF (i(0) ge 0) THEN BEGIN
blah blah
endIF

If "I" is a scalar, "I(0)" will still equal "I".

Joel

--
"...And I am unanimous in this." - Mrs. Slocumbe
Joel D. Offenberg | offenbrg@fondue.gsfc.nasa.gov
Hughes STX, NASA/GSFC/LASP | (301)-286-5801
Re: Clever Where() test [message #4441 is a reply to message #4386] Tue, 30 May 1995 00:00 Go to previous message
thompson is currently offline  thompson
Messages: 584
Registered: August 1991
Senior Member
steinhh@amon.uio.no (Stein Vidar Hagfors Haugan) writes:


> In article <3q2tld$8du@post.gsfc.nasa.gov>, thompson@orpheus.nascom.nasa.gov (William Thompson) writes:
> |> Paul Probert <probert@uwmfe.neep.wisc.edu> writes:
> |>
> |> >IDL allows you to give a zero subscript to a scalar,
> |> >so you can say:
> |> > i=WHERE(...)
> |> > IF i(0) EQ -1 THEN BEGIN
> |> > ...
> |> >
> |> >One word of caution. If you have a scalar element of a structure,
> |> >for some reason you can't do this:
> |> > x={i:0,j:1}
> |> > IF x.i(0) ... ;bombs
> |> >But you can make it work with more parentheses:
> |> > IF (x.i)(0) ... ;works
> |> >
> |> > Paul Probert
> |> > University of Wisconsin
> |>
> |> So does x(0).i
> |>
> |> Bill Thompson
> |>

> Just nit-picking: If the tag i in x.i is an array, only
> the (x.i)(0) notation works. This works if x and/or i are
> arrays (or scalars).


> Stein Vidar

Hi, Stein Vidar!

Even more nitty nit-picking: The post did say "a scalar element of a
structure". However, you're correct--Paul's way would work in either case.

Bill Thompson
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: V4.0 Exclusive Button Groups
Next Topic: Different FFT-results on vector and array?!

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

Current Time: Wed Oct 08 13:32:20 PDT 2025

Total time taken to generate the page: 0.00835 seconds