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

Home » Public Forums » archive » Re: Strange arrary indexing quirk?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Strange arrary indexing quirk? [message #77179 is a reply to message #77178] Thu, 11 August 2011 20:58 Go to previous messageGo to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Beaker writes:

> I stumbled across this strange behaviour:
>
> foo = indgen(2,2)
> print,foo[0,10]
> < gives an error, since the second index is out of range>
>
> however,
>
> indx = indgen(5)
> print,foo[0,indx]
> 0
> 2
> 2
> 2
> 2
>
> Does anyone have any insight into why this happens? I'd expect the
> second line to also throw an error. A lot of the inner workings of IDL
> seem pretty arcane and hard to guess at before you try things...
>
> I was being lazy/naughty and using a catch statement to detect when an
> index went out of range, which I knew would happen very occaisonally
> and was trying to avoid the performance hit of checking for it every
> time. This round off instead of an error behaviour made sure that plan
> didn't work!

This is a famous IDL quirk. If you would prefer to have
an error thrown in this situation, use the compile option
STRICTARRSUBS:

Compile_Opt STRICTARRSUBS

Looking up that compiler option will also point you to information
about array subscripts. (At least it will in the IDL 7 on-line help.)

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Strange arrary indexing quirk?
Next Topic: iPlot Axes Colour

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

Current Time: Wed Oct 08 17:43:26 PDT 2025

Total time taken to generate the page: 0.00605 seconds