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

Home » Public Forums » archive » Baffled by out of range subscript error
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
Baffled by out of range subscript error [message #93501] Mon, 08 August 2016 09:23 Go to next message
Med Bennett is currently offline  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 Go to previous messageGo to next message
wlandsman is currently offline  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
Re: Baffled by out of range subscript error [message #93504 is a reply to message #93503] Mon, 08 August 2016 10:29 Go to previous message
Med Bennett is currently offline  Med Bennett
Messages: 109
Registered: April 1997
Senior Member
I forgot to do total(hc_fraction[w]*weights) - doh!

Thanks so much!
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: open file (double click)
Next Topic: Odd behavior with NaNs

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

Current Time: Wed Oct 08 11:44:38 PDT 2025

Total time taken to generate the page: 0.00634 seconds