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

Home » Public Forums » archive » Re: negative indices, am I missing something here?
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: negative indices, am I missing something here? [message #81956] Tue, 06 November 2012 04:20
d.rowenhorst@gmail.co is currently offline  d.rowenhorst@gmail.co
Messages: 10
Registered: August 2008
Junior Member
Many thanks. I'll categorize this as a bugture (a bug inducing feature).

On Friday, November 2, 2012 6:36:08 PM UTC-4, David Fanning wrote:
> Michael Galloy writes:
>
>
>
>> Might be a good idea to use
>
>>
>
>> compile_opt strictarrsubs
>
>>
>
>> to catch these cases.
>
>
>
> Maybe somebody can write a script to paw through 25 years
>
> of archived programs. :-)
>
>
>
> Cheers,
>
>
>
> David
>
>
>
>
>
> --
>
> David Fanning, Ph.D.
>
> Fanning Software Consulting, Inc.
>
> Coyote's Guide to IDL Programming: http://www.dfanning.com/
>
> Sepore ma de ni thue. ("Perhaps thos speakest truth.")
Re: negative indices, am I missing something here? [message #81986 is a reply to message #81956] Fri, 02 November 2012 15:36 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Michael Galloy writes:

> Might be a good idea to use
>
> compile_opt strictarrsubs
>
> to catch these cases.

Maybe somebody can write a script to paw through 25 years
of archived programs. :-)

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thue. ("Perhaps thos speakest truth.")
Re: negative indices, am I missing something here? [message #81987 is a reply to message #81986] Fri, 02 November 2012 15:26 Go to previous message
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
On 11/2/12 3:53 PM, David Fanning wrote:
> fawltylanguage@gmail.com writes:
>
>> Array subscripts are always clipped. From IDL help:
>>
>> "If an element of the subscript array is less than or equal to zero, the first element of the subscripted array is selected. ...
>>
>> Note: Because of the confusion between the clipping of array subscripts and the use of negative indices (see the next section), it is best to avoid using code that relies on this clipping behavior."
>
> You can think of it as karmic justice for sins of the past. ;-)
>
> Cheers,
>
> David
>
>

Might be a good idea to use

compile_opt strictarrsubs

to catch these cases.

Mike
--
Michael Galloy
www.michaelgalloy.com
Modern IDL: A Guide to IDL Programming (http://modernidl.idldev.com)
Research Mathematician
Tech-X Corporation
Re: negative indices, am I missing something here? [message #81989 is a reply to message #81987] Fri, 02 November 2012 14:53 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
fawltylanguage@gmail.com writes:

> Array subscripts are always clipped. From IDL help:
>
> "If an element of the subscript array is less than or equal to zero, the first element of the subscripted array is selected. ...
>
> Note: Because of the confusion between the clipping of array subscripts and the use of negative indices (see the next section), it is best to avoid using code that relies on this clipping behavior."

You can think of it as karmic justice for sins of the past. ;-)

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thue. ("Perhaps thos speakest truth.")
Re: negative indices, am I missing something here? [message #81990 is a reply to message #81989] Fri, 02 November 2012 14:39 Go to previous message
Lajos Foldy is currently offline  Lajos Foldy
Messages: 176
Registered: December 2011
Senior Member
On Friday, November 2, 2012 8:51:56 PM UTC+1, d.rowe...@gmail.com wrote:
> IDL 8 brought negative indices for arrays. Great, love them. However, I am getting strange results.
>
>
>
> IDL> a = indgen(3,5)
>
> IDL> print, a[*,-1]
>
> 12 13 14
>
>
>
> Good, that is what I thought I should get.
>
>
>
> IDL> print, a[*, [3,1,4]]
>
> 9 10 11
>
> 3 4 5
>
> 12 13 14
>
>
>
> Also, this looks right to me.
>
>
>
> So why doesn't this work?
>
> IDL> print, a[*, [3,1,-1]]
>
> 9 10 11
>
> 3 4 5
>
> 0 1 2
>
>
>
> Is this the expected behavior? Or a bug?
>
>
>
> Mac 10.8.2 IDL 8.2.1

Array subscripts are always clipped. From IDL help:

"If an element of the subscript array is less than or equal to zero, the first element of the subscripted array is selected. ...

Note: Because of the confusion between the clipping of array subscripts and the use of negative indices (see the next section), it is best to avoid using code that relies on this clipping behavior."

regards,
Lajos
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: change values of structure variable
Next Topic: use of temporary in IDL

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

Current Time: Wed Oct 08 15:56:16 PDT 2025

Total time taken to generate the page: 0.00667 seconds