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

Home » Public Forums » archive » Re: Unexpected array subscript truncation
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: Unexpected array subscript truncation [message #68878] Mon, 30 November 2009 14:01
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
M. Katz wrote:
> Here's an interesting little array trick I discovered by accident. It
> doesn't give an error message where I would expect one! Try this:
>
> * As a warm-up enter this and see that IDL does complain.
>
> a = intarr(3,3)
> a[0,5] = 1
>
> * Now try to set it as follows, with an array of y-index values.
>
> a[0,[0,5]] = 1
> print, a
> 1 0 0
> 0 0 0
> 1 0 0
>
> No complaint! In fact, IDL quietly truncated the 5 down to its highest
> allowed value, which is 2.
>
> It also works like this:
>
> a[*,[0,9]] = 3
>
> is equivalent to
>
> a[*,[0,2]] = 3
>
> The same truncation happens with x indices as well.
>
> I suppose there could be some cases where this would not be the
> desired behavior. Any thoughts? Am I missing something?

Note that IDL will not only bring too large subscript back the last
element, but also will bring negative subscripts back to 0. This is the
case any time you index an array by an array of indices.

You can make IDL complain instead of quietly truncating by setting the
strictarrsubs compile option:

compile_opt strictarrsubs

Mike
--
www.michaelgalloy.com
Research Mathematician
Tech-X Corporation
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: How to store compressed data ?
Next Topic: Re: Code snippets from CRU

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

Current Time: Thu Oct 09 23:01:21 PDT 2025

Total time taken to generate the page: 0.40101 seconds