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

Home » Public Forums » archive » Indexing problems under V6
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
Indexing problems under V6 [message #53195] Fri, 30 March 2007 02:41 Go to next message
Ian Dean is currently offline  Ian Dean
Messages: 26
Registered: January 2000
Junior Member
Hi,
This is almost a repeat of a psoting by Wayne Landsman, 12-Aug-2003.
Because of contracts, we have been stuck on v5.5 for years!!!
However, we are now in a position to upgrade to 6.3. As part of this, a
great deal of our code is now broken because of the change in indexing.
In 5.5,
a={x:indgen(10)}
b=[1, 4, 10]
c=[4]
val=a.x[c] <<<<<<<<<<this was a scalar of 4
pos=where(b eq val) <<<<<<<<<<<<<< returned [1]

In 6.3.
a={x:indgen(10)}
b=[1, 4, 10]
c=[4]
val=a.x[c] <<<<<<<<<<this is now an array of [4]
pos=where(b eq val) <<<<<<<<<<<<<< now returns -1

The where fails because it is now comparing an array with an array, not an
array with a scalar.
Is there any trick/switch that can be used to revert the action to that used
in 5.5?

The real problem is much deeper than this, as the search may be done several
levels lower than where the selection criteria is setup and furthermore,
some searches genuinely use arrays.

I hope this makes sense and I hope for some favourable replies.

Regards,
Ian
Re: Indexing problems under V6 [message #53263 is a reply to message #53195] Sat, 31 March 2007 13:27 Go to previous messageGo to next message
MarioIncandenza is currently offline  MarioIncandenza
Messages: 231
Registered: February 2005
Senior Member
> Is there any trick/switch that can be used to revert the action to that used
> in 5.5?

Obviously, the easiest solution would be a COMPILE_OPT IDL55 for all
of the affected routines, but if anything like that is implemented, it
is certainly not documented.

> The real problem is much deeper than this, as the search may be done several
> levels lower than where the selection criteria is setup and furthermore,
> some searches genuinely use arrays.

This is indeed a thorny problem. But if you truly are comparing both
arrays to scalars and arrays to arrays, I find the behavior of WHERE
to be unintuitive (I always end up using pen and paper to figure out
what it's going to do), and you might just be driven to a more
powerful tool, such as the SETINTERSECTION-type tools (http://
www.dfanning.com/tips/set_operations.html).

Good luck,

Edward H.
Re: Indexing problems under V6 [message #53332 is a reply to message #53195] Mon, 02 April 2007 14:48 Go to previous message
JD Smith is currently offline  JD Smith
Messages: 850
Registered: December 1999
Senior Member
On Fri, 30 Mar 2007 10:41:54 +0100, Ian Dean wrote:

> Hi,
> This is almost a repeat of a psoting by Wayne Landsman, 12-Aug-2003.
> Because of contracts, we have been stuck on v5.5 for years!!!
> However, we are now in a position to upgrade to 6.3. As part of this, a
> great deal of our code is now broken because of the change in indexing.
> In 5.5,
> a={x:indgen(10)}
> b=[1, 4, 10]
> c=[4]
> val=a.x[c] <<<<<<<<<<this was a scalar of 4
> pos=where(b eq val) <<<<<<<<<<<<<< returned [1]
>
> In 6.3.
> a={x:indgen(10)}
> b=[1, 4, 10]
> c=[4]
> val=a.x[c] <<<<<<<<<<this is now an array of [4]
> pos=where(b eq val) <<<<<<<<<<<<<< now returns -1
>
> The where fails because it is now comparing an array with an array, not an
> array with a scalar.
> Is there any trick/switch that can be used to revert the action to that used
> in 5.5?
>
> The real problem is much deeper than this, as the search may be done several
> levels lower than where the selection criteria is setup and furthermore,
> some searches genuinely use arrays.
>
> I hope this makes sense and I hope for some favourable replies.

Probably not what you want to hear, but... it's important to know
whether you intend the "scalar inflation" of IDL's operators to work,
and, if so, always explicitly use a scalar, e.g. val[0]. This is a
good habit to get into. Often I recommend turning an array into a
scalar as soon as its returned, if you only expect, or ever intend to
use, a single value:

wh=where(array eq val,cnt)
wh=wh[0]

Short of that, you could use WHERE_ARRAY in place of WHERE, at a cost
of some performance (or write your own version to replace WHERE which
simply checks for single element arrays, and converts them to scalars for
you). If it's any solace, I know that at least one of IDL's former
engineers regarded the scalar <-> single element array ambiguity as the
most troubling vestigial issue in IDL.

JD
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Calculating Pi
Next Topic: Problem with TIF image

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

Current Time: Wed Oct 08 19:57:10 PDT 2025

Total time taken to generate the page: 0.00517 seconds