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

Home » Public Forums » archive » Re: Array indexing "Feature"
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: Array indexing "Feature" [message #28428] Mon, 17 December 2001 09:40
Pavel A. Romashkin is currently offline  Pavel A. Romashkin
Messages: 531
Registered: November 2000
Senior Member
Jeff Jones wrote:
>
> It's funny -- my office mate noticed the same thing just yesterday.

I think this is what David loves IDL for - learning something new every
day. Who cares if its been there forever, its new for us :)

Cheers,
Pavel
Re: Array indexing "Feature" [message #28447 is a reply to message #28428] Thu, 13 December 2001 08:35 Go to previous message
k-bowman is currently offline  k-bowman
Messages: 12
Registered: December 2001
Junior Member
As has been pointed out, this ... ah ... feature has the side effect that
sometimes IDL checks array subscript bounds and sometimes it does not,
depending on the nature of the index.

It would be nice if it were possible to use a compile switch to turn
subscript checking on for array subscripts, at the obvious cost of some
performance.

Ken
Re: Array indexing "Feature" [message #28448 is a reply to message #28447] Thu, 13 December 2001 07:23 Go to previous message
Liam E. Gumley is currently offline  Liam E. Gumley
Messages: 378
Registered: January 2000
Senior Member
Andrew Cool wrote:
> One of my colleagues has noted something apparently screwy in the
> indexing of
> arrays.
>
> e.g. a = indgen(10)
> print, a(9) -> you get 9
> print, a(10) -> you get an error, as expected for a zero-based
> index
>
> but if you access the array with the index as a vector, it seems to
> truncate the index to the maximum allowable:
>
> print, a([10]) -> you get 9
> print, a([666]) -> you get 9
>
> Similarly:
>
> print, a(-1) -> you get an error
> print, a([-1]) -> you get 0
>
> This feature holds good for IDL 5.2 and 5.4 on OpenVMS and for 5.5 on
> Windows.
>
> Where, Oh where in the manuals does it describe this?

For what it's worth, this behavior is documented in "Practical IDL
Programming" on page 30 (section 2.4 "Array Indexing").

Cheers,
Liam
Practical IDL Programming
http://www.gumley.com/
Re: Array indexing "Feature" [message #28451 is a reply to message #28448] Thu, 13 December 2001 06:17 Go to previous message
Paul van Delst is currently offline  Paul van Delst
Messages: 364
Registered: March 1997
Senior Member
Andrew Cool wrote:
>
> Anyways, Y'all have a good Christmas. I'll be thinking of you Paul, freezing your
> buns off in Yankee Land while prawns & cold beer are Order of the Day back in OZ.

Come February, matey, I'll be nursing a cold one on the balcony of the Cottesloe Hotel watching
the sun set over the ocean.

Ahhh......

paulv

--
Paul van Delst Religious and cultural
CIMSS @ NOAA/NCEP purity is a fundamentalist
Ph: (301)763-8000 x7274 fantasy
Fax:(301)763-8545 V.S.Naipaul
Re: Array indexing "Feature" [message #28461 is a reply to message #28451] Wed, 12 December 2001 16:48 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Kristine Hensel (kristine@esands.com) writes:

> Unless you're in Hobart, where it snowed a couple days ago.

Still, a snowy day in Hobart kicking around the
Battery Hill area is better than a whole lot of
warm days somewhere else. :-)

Cheers,

David

--
David W. Fanning, Ph.D.
Fanning Software Consulting
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: Array indexing "Feature" [message #28462 is a reply to message #28461] Wed, 12 December 2001 16:31 Go to previous message
Kristine Hensel is currently offline  Kristine Hensel
Messages: 26
Registered: June 1999
Junior Member
Andrew Cool wrote:
> Anyways, Y'all have a good Christmas. I'll be thinking of you Paul,
> freezing your
> buns off in Yankee Land while prawns & cold beer are Order of the Day
> back in OZ.

Unless you're in Hobart, where it snowed a couple days ago.

Kristine, perilously close to Tasmania

--
Kristine Hensel e-mail: kristine@esands.com
Environmental Systems & Services phone: +61-(0)3-9835-7901
20 Council St., Level 3 fax: +61-(0)3-9835-7900
Hawthorn East, VIC, Australia 3124
Re: Array indexing "Feature" [message #28463 is a reply to message #28462] Wed, 12 December 2001 16:10 Go to previous message
Andrew Cool is currently offline  Andrew Cool
Messages: 219
Registered: January 1996
Senior Member
Paul van Delst wrote:
>
> Craig Markwardt wrote:
>>
>> Andrew Cool <andrew.cool@dsto.defence.gov.au> writes:
>>
>>> Hi All,
>>>
>>> One of my colleagues has noted something apparently screwy in the
>>> indexing of
>>> arrays.
>>>
>>> e.g. a = indgen(10)
>>> print, a(9) -> you get 9
>>> print, a(10) -> you get an error, as expected for a zero-based
>>> index
>>>
>>> but if you access the array with the index as a vector, it seems to
>>> truncate the index to the maximum allowable:
>>
>> See "Using Arrays as Subscripts" in the manual. I believe this
>> behavior has been true since the dawn of SYSTIME().
>
> Huh. How 'bout that?
>
> IDL> a = indgen(10)
> IDL> x=[-100,3, 4, 5]
> IDL> print, a(x)
> 0 3 4 5
>
> but only for array subscripts,
>
> IDL> print, a[-100]
> % Attempt to subscript A with <INT ( -100)> is out of range.
> % Execution halted at: $MAIN$
>
> Seems logical....<insert chirping cricket sounds here>.....in an IDL sorta way.
>
> paulv
>

Thanks David, Craig & Paul...

I did actually search every which way through the online v5.4 "Help"
before posting the query.

Thanks to Jeff, I've gone back to my *paper* v4.0 User's Guide and
found on 5-5 that :-

"If an element of a subscript array is less than or equal to zero, the
first element
of the subscripted variable is selected. If an element of the
subscript is greater
than or equal to the last subscript in the subscripted variable
(N,above), the last
element is selected."

Sounds fair - if only they'd keep that text in the bloody Help!

But what sort of person attempts to subscript an array without checking
the bounds
in the first place? Sounds like sloppy practice to me.

Anyways, Y'all have a good Christmas. I'll be thinking of you Paul,
freezing your
buns off in Yankee Land while prawns & cold beer are Order of the Day
back in OZ.

Cheers,

Andrew


------------------------------------------------------------ ---------
Andrew D. Cool .->-.
Electromagnetics & Propagation Group `-<-'
Surveillance Systems Division Transmitted on
Defence Science & Technology Organisation 100% recycled
PO Box 1500, Salisbury electrons
South Australia 5108

Phone : 061 8 8259 5740 Fax : 061 8 8259 6673
Email : andrew.cool@dsto.defence.gov.au
------------------------------------------------------------ ---------
Re: Array indexing "Feature" [message #28464 is a reply to message #28463] Wed, 12 December 2001 15:03 Go to previous message
Jeff Jones is currently offline  Jeff Jones
Messages: 2
Registered: February 2001
Junior Member
Andrew Cool wrote:

> Hi All,
>
> One of my colleagues has noted something apparently screwy in the
> indexing of
> arrays.
>
> e.g. a = indgen(10)
> print, a(9) -> you get 9
> print, a(10) -> you get an error, as expected for a zero-based
> index
>
> but if you access the array with the index as a vector, it seems to
> truncate the index to the maximum allowable:
>
> print, a([10]) -> you get 9
> print, a([666]) -> you get 9
>
> Similarly:
>
> print, a(-1) -> you get an error
> print, a([-1]) -> you get 0
>
> This feature holds good for IDL 5.2 and 5.4 on OpenVMS and for 5.5 on
> Windows.
>
> Where, Oh where in the manuals does it describe this?
>
> Andrew

It's funny -- my office mate noticed the same thing just yesterday.

It _is_ documented, in the section on "Array Subscripts" in "Building IDL
Applications". (The exact page depends on the version of the doc. My v5.0 book has
it on page 62.)
Re: Array indexing "Feature" [message #28466 is a reply to message #28464] Wed, 12 December 2001 14:44 Go to previous message
Paul van Delst is currently offline  Paul van Delst
Messages: 364
Registered: March 1997
Senior Member
Craig Markwardt wrote:
>
> Andrew Cool <andrew.cool@dsto.defence.gov.au> writes:
>
>> Hi All,
>>
>> One of my colleagues has noted something apparently screwy in the
>> indexing of
>> arrays.
>>
>> e.g. a = indgen(10)
>> print, a(9) -> you get 9
>> print, a(10) -> you get an error, as expected for a zero-based
>> index
>>
>> but if you access the array with the index as a vector, it seems to
>> truncate the index to the maximum allowable:
>
> See "Using Arrays as Subscripts" in the manual. I believe this
> behavior has been true since the dawn of SYSTIME().

Huh. How 'bout that?

IDL> a = indgen(10)
IDL> x=[-100,3, 4, 5]
IDL> print, a(x)
0 3 4 5

but only for array subscripts,

IDL> print, a[-100]
% Attempt to subscript A with <INT ( -100)> is out of range.
% Execution halted at: $MAIN$


Seems logical....<insert chirping cricket sounds here>.....in an IDL sorta way.

paulv

--
Paul van Delst Religious and cultural
CIMSS @ NOAA/NCEP purity is a fundamentalist
Ph: (301)763-8000 x7274 fantasy
Fax:(301)763-8545 V.S.Naipaul
Re: Array indexing "Feature" [message #28468 is a reply to message #28466] Wed, 12 December 2001 14:28 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
Andrew Cool <andrew.cool@dsto.defence.gov.au> writes:

> Hi All,
>
> One of my colleagues has noted something apparently screwy in the
> indexing of
> arrays.
>
> e.g. a = indgen(10)
> print, a(9) -> you get 9
> print, a(10) -> you get an error, as expected for a zero-based
> index
>
> but if you access the array with the index as a vector, it seems to
> truncate the index to the maximum allowable:

See "Using Arrays as Subscripts" in the manual. I believe this
behavior has been true since the dawn of SYSTIME().

Craig

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
Re: Array indexing "Feature" [message #28469 is a reply to message #28468] Wed, 12 December 2001 14:12 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Andrew Cool (andrew.cool@dsto.defence.gov.au) writes:

> One of my colleagues has noted something apparently screwy in the
> indexing of
> arrays.
>
> e.g. a = indgen(10)
> print, a(9) -> you get 9
> print, a(10) -> you get an error, as expected for a zero-based
> index
>
> but if you access the array with the index as a vector, it seems to
> truncate the index to the maximum allowable:
>
> print, a([10]) -> you get 9
> print, a([666]) -> you get 9
>
> Similarly:
>
> print, a(-1) -> you get an error
> print, a([-1]) -> you get 0
>
> This feature holds good for IDL 5.2 and 5.4 on OpenVMS and for 5.5 on
> Windows.
>
> Where, Oh where in the manuals does it describe this?

This has been a feature of IDL since about IDL 0.5, or thereabouts.

I first encountered it in about 1988 in some chapters
Ray Sterner of JHUAPL was putting together for a book about
IDL. He found it incredibly useful for array bound error
checking. But I don't think I have ever read about it in any
documentation. My guess is that after the IDL 1.0
documentation was finished, and RSI had hired a real
technical writer, that he could never figure out
a way to explain the situation that didn't sound
really lame. So he just left it out. :-)

Cheers,

David
--
David W. Fanning, Ph.D.
Fanning Software Consulting
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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: IDL Expert Programmer's Association Vote
Next Topic: Re: Newbie IDl question

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

Current Time: Wed Oct 08 14:32:50 PDT 2025

Total time taken to generate the page: 0.00679 seconds