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

Home » Public Forums » archive » Re: Interesting WHERE function gotcha
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: Interesting WHERE function gotcha [message #33931] Fri, 07 February 2003 08:04 Go to next message
JD Smith is currently offline  JD Smith
Messages: 850
Registered: December 1999
Senior Member
On Thu, 06 Feb 2003 19:35:31 -0700, Craig Markwardt wrote:


> David Fanning <david@dfanning.com> writes:
>>
>> How about this:
>>
>> Help, veggie_letter, letter
>> VEGGIE_LETTER BYTE = Array[4]
>> LETTER BYTE = Array[1]
>>
>> "LETTER, a byte *array*!? You don't suppose..." Try this:
>>
>> index = WHERE( (Byte(array))[0,*] EQ (Byte('a'))[0], count) Print,
>> count
>> 2
>>
>> Hummm. V-e-r-y interesting...
>>
>> Now I know how to fix the problem, but I don't know exactly what the
>> problem is. (Although this is not so different from most computer
>> problems, when you come to think of it.) Is the problem that the BYTE
>> function always makes a byte *array* when extracting string arguments?
>> Or is it that the WHERE function acts in a, uh, non-intuitive way when
>> there are two vectors in a boolean expression?
>
> Hi David!
>
> You are being bitten by the "feature" that I love so much. Namely that
> in IDL, when you do "X OPERATION Y", and X and Y are both arrays, then
> the expression is trimmed to the smaller of the two arrays.
>
> So it's not anything special regarding WHERE, or boolean expressions,
> but rather that VEGGIE_LETTER EQ LETTER evaluates to a 1-element array.

Yes, the tension between single element arrays and scalars is felt
deeply, even within the core IDL development group. It's a
regrettable legacy which must, unfortunately, be preserved for
compatibitlity. There are, however, minor changes and improvements:
e.g., with v5.6, KEYWORD_SET now considers a single element array TRUE
only if its single element is non-zero; i.e. it's treated just like a
scalar for this (and only this) function.

JD
Re: Interesting WHERE function gotcha [message #33934 is a reply to message #33931] Thu, 06 February 2003 19:06 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Craig Markwardt (craigmnet@cow.physics.wisc.edu) writes:

> By the way, why not do this instead?
>
> index = where( strmid(array,0,1) EQ 'a')

Well, basically, because it didn't make nearly as
interesting a story. :-)

Cheers,

David

--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: Interesting WHERE function gotcha [message #33935 is a reply to message #33934] Thu, 06 February 2003 18:35 Go to previous messageGo to next message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
David Fanning <david@dfanning.com> writes:
>
> How about this:
>
> Help, veggie_letter, letter
> VEGGIE_LETTER BYTE = Array[4]
> LETTER BYTE = Array[1]
>
> "LETTER, a byte *array*!? You don't suppose..." Try this:
>
> index = WHERE( (Byte(array))[0,*] EQ (Byte('a'))[0], count)
> Print, count
> 2
>
> Hummm. V-e-r-y interesting...
>
> Now I know how to fix the problem, but I don't know exactly
> what the problem is. (Although this is not so different
> from most computer problems, when you come to think of it.)
> Is the problem that the BYTE function always makes a byte
> *array* when extracting string arguments? Or is it that
> the WHERE function acts in a, uh, non-intuitive way when
> there are two vectors in a boolean expression?

Hi David!

You are being bitten by the "feature" that I love so much. Namely
that in IDL, when you do "X OPERATION Y", and X and Y are both arrays,
then the expression is trimmed to the smaller of the two arrays.

So it's not anything special regarding WHERE, or boolean expressions,
but rather that VEGGIE_LETTER EQ LETTER evaluates to a 1-element
array. One element, because LETTER only has one element:

IDL> help, veggie_letter EQ letter
<Expression> BYTE = Array[1]

There are many times that I wish that IDL has an easier way to get the
ASCII value of a character.

By the way, why not do this instead?

index = where( strmid(array,0,1) EQ 'a')

This avoids the whole issue of converting to a different
representation, and it just looks less gobbledygooky.

Happy guacamole,
Craig

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
Re: Interesting WHERE function gotcha [message #34016 is a reply to message #33931] Mon, 10 February 2003 09:21 Go to previous message
Stein Vidar Hagfors H[2] is currently offline  Stein Vidar Hagfors H[2]
Messages: 28
Registered: October 2002
Junior Member
JD Smith <jdsmith@as.arizona.edu> writes:

> On Thu, 06 Feb 2003 19:35:31 -0700, Craig Markwardt wrote:
[...]
> Yes, the tension between single element arrays and scalars is felt
> deeply, even within the core IDL development group. It's a
> regrettable legacy which must, unfortunately, be preserved for
> compatibitlity. There are, however, minor changes and improvements:
> e.g., with v5.6, KEYWORD_SET now considers a single element array TRUE
> only if its single element is non-zero; i.e. it's treated just like a
> scalar for this (and only this) function.

Uh... improvement? I beg to differ. Not only does it introduce a
single mysterious case where the legacy compatibility fails (when
someone relies on the previous truth that "when it's defined as an
array, it's set!") (I hope I never have to debug a code experiencing
this!), but it introduces even one more level of exception to how
singular arrays are treated.... Okay, so trailing singular dimensions
are disappearing or are ignored, except when it's the last dimension
to survive the slaughter, *except* that this one nifty function that
we wrote specifically to say that anything not a scalar zero means
"set" is right now doing a vote on whether to consider your singular
dimension worthy of noticing... Ugh..!

--
------------------------------------------------------------ --------------
Stein Vidar Hagfors Haugan
ESA SOHO SOC/European Space Agency Science Operations Coordinator for SOHO

NASA Goddard Space Flight Center, Tel.: 1-301-286-9028
Mail Code 682.3, Bld. 26, Room G-1, Cell: 1-240-354-6066
Greenbelt, Maryland 20771, USA. Fax: 1-301-286-0264
------------------------------------------------------------ --------------
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: p_correlate
Next Topic: Re: SQL access without Dataminer (perl off topic)

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

Current Time: Wed Oct 08 15:52:41 PDT 2025

Total time taken to generate the page: 0.00692 seconds