f



Index should be out of range, right?

2008 is ending in confusion for me.  Here is an example of why:

IDL> x=intarr(10,10)
IDL> y=indgen(15)
IDL> x[y,y]=1
IDL> print, x
       1       0       0       0       0       0       0       0
0       0
       0       1       0       0       0       0       0       0
0       0
       0       0       1       0       0       0       0       0
0       0
       0       0       0       1       0       0       0       0
0       0
       0       0       0       0       1       0       0       0
0       0
       0       0       0       0       0       1       0       0
0       0
       0       0       0       0       0       0       1       0
0       0
       0       0       0       0       0       0       0       1
0       0
       0       0       0       0       0       0       0       0
1       0
       0       0       0       0       0       0       0       0
0       1


This is confusing because some values of y are greater than the
dimensions of the array that they are being used to access and in
fact

IDL> x[y[10],y[10]]=1
% Attempt to subscript X with <INT      (      10)> is out of range.
% Execution halted at: $MAIN$

this fails.  Why do I not get an "out of range error" in the first
case?

Thanks for your help.
0
12/31/2008 7:42:18 PM
comp.lang.idl-pvwave 12260 articles. 4 followers. Post Follow

2 Replies
402 Views

Similar Articles

[PageSpeed] 23

On Dec 31, 2:42=A0pm, "T.H." <timhoagl...@gmail.com> wrote:

> This is confusing because some values of y are greater than the
> dimensions of the array that they are being used to access and in
> fact
>
> IDL> x[y[10],y[10]]=3D1
> % Attempt to subscript X with <INT =A0 =A0 =A0( =A0 =A0 =A010)> is out of=
 range.
> % Execution halted at: $MAIN$
>
> this fails. =A0Why do I not get an "out of range error" in the first
> case?

The difference is that in the second example you are subscripting with
a scalar.    You may want to check out  the "strictarrsubs" option to
the command compile_opt which I quote below:

"When IDL subscripts one array using another array as the source of
array indices, the default behavior is to clip any out-of-range
indices into range and then quietly use the resulting data without
error. This behavior is described in Array Subscripting. Specifying
STRICTARRSUBS will instead cause IDL to treat such out-of-range array
subscripts within the body of the routine containing the COMPILE_OPT
statement as an error. "
0
wlandsman (223)
12/31/2008 7:52:18 PM
On Dec 31, 2:52=A0pm, wlandsman <wlands...@gmail.com> wrote:
> On Dec 31, 2:42=A0pm, "T.H." <timhoagl...@gmail.com> wrote:
>
> > This is confusing because some values of y are greater than the
> > dimensions of the array that they are being used to access and in
> > fact
>
> > IDL> x[y[10],y[10]]=3D1
> > % Attempt to subscript X with <INT =A0 =A0 =A0( =A0 =A0 =A010)> is out =
of range.
> > % Execution halted at: $MAIN$
>
> > this fails. =A0Why do I not get an "out of range error" in the first
> > case?
>
> The difference is that in the second example you are subscripting with
> a scalar. =A0 =A0You may want to check out =A0the "strictarrsubs" option =
to
> the command compile_opt which I quote below:
>
> "When IDL subscripts one array using another array as the source of
> array indices, the default behavior is to clip any out-of-range
> indices into range and then quietly use the resulting data without
> error. This behavior is described in Array Subscripting. Specifying
> STRICTARRSUBS will instead cause IDL to treat such out-of-range array
> subscripts within the body of the routine containing the COMPILE_OPT
> statement as an error. "

This is close to what I suspected.  I appreciate your help.
0
12/31/2008 7:56:33 PM
Reply: