Re: Clever Where() test [message #4366] |
Fri, 26 May 1995 00:00  |
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 #4376 is a reply to message #4370] |
Thu, 25 May 1995 00:00   |
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 #4436 is a reply to message #4386] |
Tue, 30 May 1995 00:00  |
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  |
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
|
|
|