Baffled by out of range subscript error [message #93501] |
Mon, 08 August 2016 09:23  |
Med Bennett
Messages: 109 Registered: April 1997
|
Senior Member |
|
|
I'm mystified by this error. Below is a code fragment from a routine that interpolates a value into a three-dimensional array based on nearby data, weighted by sample length and inverse distance squared. My 3D array is 177 by 127 by 28, but I get an error stating out of range subscript at [i,j,k] = [170,21,23], which are clearly not out of range, and this routine worked perfectly last week, before I added the length weighting part. Does anyone have any suggestions or spot the problem?
hc_bm_id2 = fltarr(177,127,28)
for i=0,176 do begin
xb = xax[i]
for j=0,126 do begin
yb = yax[j]
for k=0,27 do begin
zb = zax[k]
d = sqrt((xb - x_hc3d)^2 + (yb - y_hc3d)^2 + 10.*(zb - z_hc3d)^2)
w = where(d le 100.,c)
s = sort(d[w])
if c gt 8 then s = s[0:7]
w = w[s]
d = d[w]
length = hc_length[w]
weights = (1./d^2 * length)/total((1./d^2 * length))
===> if c gt 0 then hc_bm_id2[i,j,k] = hc_fraction[w] * weights
endfor
endfor
endfor
==========================================================
% Out of range subscript encountered: HC_BM_ID2.
% Execution halted at: $MAIN$ 21 E:\Fulton\hc_model.pro
IDL> print,i,j,k
170 21 23
IDL> help,hc_bm_id2
HC_BM_ID2 FLOAT = Array[177, 127, 28]
IDL> help,hc_bm_id2[i,j,k]
<Expression> FLOAT = 0.000000
|
|
|
Re: Baffled by out of range subscript error [message #93503 is a reply to message #93501] |
Mon, 08 August 2016 10:18   |
wlandsman
Messages: 743 Registered: June 2000
|
Senior Member |
|
|
On Monday, August 8, 2016 at 12:23:09 PM UTC-4, Med Bennett wrote:
> My 3D array is 177 by 127 by 28, but I get an error stating out of range subscript at [i,j,k] = [170,21,23], which are clearly not out of range,
It could be out of range if the right hand side is a vector. Can you give the help output for
hc_fraction[w] * weights
?
> weights = (1./d^2 * length)/total((1./d^2 * length))
> ===> if c gt 0 then hc_bm_id2[i,j,k] = hc_fraction[w] * weights
>
> endfor
> endfor
> endfor
> ==========================================================
>
> % Out of range subscript encountered: HC_BM_ID2.
> % Execution halted at: $MAIN$ 21 E:\Fulton\hc_model.pro
> IDL> print,i,j,k
> 170 21 23
> IDL> help,hc_bm_id2
> HC_BM_ID2 FLOAT = Array[177, 127, 28]
> IDL> help,hc_bm_id2[i,j,k]
> <Expression> FLOAT = 0.000000
|
|
|
|