[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: User selectable lower array bound?

In article <3B69CA57.FD3B1D8D@noaa.gov>,
Paul van Delst  <paul.vandelst@noaa.gov> wrote:
>Hey there,
>Is is just me, or would anyone else find useful the ability to
>define arrays in IDL such
>that the lower bound is *not* always zero? Sorta like:
>  x = FINDGEN( 11, LOWER = -5 )
>  y = DBLARR( 100, LOWER = 1 )
>so that accessing elements such as x[ -4 ] or y[ 100 ] are o.k.?

     Yes, that would make a lot of code much more understandable
and less prone to errors during development.
>I know this can be done now with judicious use of proxy indices, e.g.
>  FOR i = -5, 5 DO BEGIN
>    ix = i + 5
>    PRINT, x[ ix ]
>    ....do other stuff with negative i's....
>but sometimes this makes code hard to follow (or explain to
>someone who's never used the
>code before) in direct correspondence with a physical process.
>It seems like such a simple thing to be able to do (with default
>action being start at
>index 0) although I'm sure the amount of work required to
>implement this would be
>horrendous. Still, it shur would be nice.....
     That depends upon how IDL already keeps track of arrays
internally.  In PL/1, for example, one declared an array with the
boundaries for each dimension in the form lowerbound:upperbound,
where specification of the lower bound and the colon were optional.
If only the upper bound were specified, then the lower bound defaulted
to 1.  In its internal representation of arrays, IIRC, PL/1 kept
the lower and upper boundaries of each dimension as part of a control
block preceding the actual array memory.  If a language implementation
doesn't already store both boundaries, or equivalently, the lower
boundary and number of elements, for each dimension, then yes, adding
such support might well be a major headache.

                                  Scott Bennett, Comm. ASMELG, CFIAG
                                  College of Oceanic and Atmospheric
                                  Oregon State University
                                  Corvallis, Oregon 97331
* Internet:       sbennett at oce.orst.edu                           *
* "Lay then the axe to the root, and teach governments humanity.     *
* It is their sanguinary punishments which corrupt mankind."         *
*    -- _The_Rights_of_Man_ by Tom Paine (1791.)                     *