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

Home » Public Forums » archive » Re: Strange array subscripting 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
Re: Strange array subscripting error [message #67123] Tue, 07 July 2009 16:37 Go to next message
pgrigis is currently offline  pgrigis
Messages: 436
Registered: September 2007
Senior Member
robintw wrote:
> Hi,
>
> I'm getting the error "% Out of range subscript encountered: VALUES.",
> but I can't work out why. I have three arrays (azimuths, zeniths and
> values) each of which is set to a size of 360 * 90 (which is 32400). I
> then have a loop which populates these arrays with values, but when
> the loop gets to 32398 it stops and gives the error above.
>
> I really can't understand what's going on here. I've made sure that
> the variable I'm using to keep the array_index in is a long, in case
> above 32398 it was going over a limit in a standard integer, but that
> didn't help. The only way I've found to get round it is to manually
> add three to my array declaration (ie. change it to fltarr((360*90) +
> 3)). That is obviously a very ugly hack, and ends up with me having
> some blank unused array values at the end.
>
> Does anybody have any ideas why this is happening and what I can do
> about it? I've attached the code below:
>
> PRO BRUNGER_HOOPER_MODEL, a0, a1, a2, a3, azimuths=azimuths,
> zeniths=zeniths, values=values, s_theta, s_phi
> sun_theta = s_theta*!DTOR
> sun_phi = s_phi*!DTOR
>
> ; Initialise arrays
> array_size = (360*90) + 3 ; BUG ALERT! When set to 360*90 (32400) it
> seems to overrun at 32398, this is an ugly fix
>
> azimuths = intarr(array_size)
> zeniths = intarr(array_size)
> values = fltarr(array_size)
>
> FOR phi=0, 360-1 DO BEGIN
> FOR theta=0, 90-1 DO BEGIN
> ; Convert the current phi and theta to radians
> view_phi = phi*!DTOR
> view_theta = theta*!DTOR
>
> value = CALCULATE_SKY_VALUE(a0, a1, a2, a3, view_theta,
> view_phi, sun_theta, sun_phi)
>
> array_index = long((90*phi) + theta)

This statement looks very dangerous. While it won't
actually overflow in your example, it comes very close
to it. instead of applying long() to the result, phi and theta
should be longs from the start (i.e. for phi=0L,360... ).
If you want to see why, try the difefrence between:
IDL> print,long(256^2)
IDL> print,256L^2

The former is probably going to mess you up, while the latter
is fine.

This is good advice, even if that was not the cause of your problem :)

Ciao,
Paolo


>
> ; Put the value into the array
> values[array_index] = value
> azimuths[array_index] = phi
> zeniths[array_index] = theta
>
> ENDFOR
> ENDFOR
>
> ; Normalise the values
> values = values / MAX(values)
> END
Re: Strange array subscripting error [message #67128 is a reply to message #67123] Tue, 07 July 2009 03:46 Go to previous messageGo to next message
robintw is currently offline  robintw
Messages: 37
Registered: March 2009
Member
I've managed to sort it now. Thanks for the help. I think trying to
explain myself to people on this group helped me to formulate my
thoughts and work out what was wrong.

It turned out that I was passing an array in somewhere rather than a
scalar, and that was confusing the rest of my program which was
expecting a single value but got an array!

Thanks again,

Robin
Re: Strange array subscripting error [message #67129 is a reply to message #67128] Tue, 07 July 2009 03:15 Go to previous messageGo to next message
robintw is currently offline  robintw
Messages: 37
Registered: March 2009
Member
Another update:

I realised I forgot to answer some of your questions. The line that
the error is occurring on is the "values[array_index] = value" line.
I've found that it works fine in a couple of situations:

* If I run it (with nothing commented out) by itself as a function

or

* If I run it from the rest of my program with the CALCULATE_SKY_VALUE
function commented out and replaced with "value = 1".

I can't see how these two observations fit together. It can't be a
fundamental problem with the CALCULATE_SKY_VALUE function because
otherwise it would fail even when I ran it by itself as a function,
but then again it only works when called from the rest of my program
when that function is commented out.

The rest of the program is only providing a couple of bits of input to
this function, but I'll investigate those and get back to you.

Robin
Re: Strange array subscripting error [message #67130 is a reply to message #67129] Tue, 07 July 2009 03:05 Go to previous messageGo to next message
robintw is currently offline  robintw
Messages: 37
Registered: March 2009
Member
Thanks for the help Greg. I've done some more investigation and found
that if I run just that function it works fine (even when the
CALCULATE_SKY_VALUE function isn't commented out), but when I run it
from within my program it causes this error...most of the time.

In the last 10 minutes of playing with it, it's worked a few times,
but hasn't the others.

I'll carry on playing with it, but I really don't know what's causing
it.

If anyone's got any other ideas about what's causing this then I'd be
delighted to hear them.

Robin
Re: Strange array subscripting error [message #67131 is a reply to message #67130] Tue, 07 July 2009 02:55 Go to previous messageGo to next message
greg.addr is currently offline  greg.addr
Messages: 160
Registered: May 2007
Senior Member
On Jul 7, 11:27 am, robintw <r.t.wil...@rmplc.co.uk> wrote:
> Hi,
>
> I'm getting the error "% Out of range subscript encountered: VALUES.",
> but I can't work out why. I have three arrays (azimuths, zeniths and
> values) each of which is set to a size of 360 * 90 (which is 32400). I
> then have a loop which populates these arrays with values, but when
> the loop gets to 32398 it stops and gives the error above.
>
> I really can't understand what's going on here. I've made sure that
> the variable I'm using to keep the array_index in is a long, in case
> above 32398 it was going over a limit in a standard integer, but that
> didn't help. The only way I've found to get round it is to manually
> add three to my array declaration (ie. change it to fltarr((360*90) +
> 3)). That is obviously a very ugly hack, and ends up with me having
> some blank unused array values at the end.
>
> Does anybody have any ideas why this is happening and what I can do
> about it? I've attached the code below:
>
> PRO BRUNGER_HOOPER_MODEL, a0, a1, a2, a3, azimuths=azimuths,
> zeniths=zeniths, values=values, s_theta, s_phi
>   sun_theta = s_theta*!DTOR
>   sun_phi = s_phi*!DTOR
>
>   ; Initialise arrays
>   array_size = (360*90) + 3 ; BUG ALERT! When set to 360*90 (32400) it
> seems to overrun at 32398, this is an ugly fix
>
>   azimuths = intarr(array_size)
>   zeniths = intarr(array_size)
>   values = fltarr(array_size)
>
>   FOR phi=0, 360-1 DO BEGIN
>     FOR theta=0, 90-1 DO BEGIN
>       ; Convert the current phi and theta to radians
>       view_phi = phi*!DTOR
>       view_theta = theta*!DTOR
>
>       value = CALCULATE_SKY_VALUE(a0, a1, a2, a3, view_theta,
> view_phi, sun_theta, sun_phi)
>
>       array_index = long((90*phi) + theta)
>
>       ; Put the value into the array
>       values[array_index] = value
>       azimuths[array_index] = phi
>       zeniths[array_index] = theta
>
>     ENDFOR
>   ENDFOR
>
>   ; Normalise the values
>   values = values / MAX(values)
> END

If I comment out your calculate sky function it works fine on my
machine. I can't see anything wrong with your index calculations. You
didn't say in which line the error occurs - could it be in a loop in
your function?

Is there a reason that you avoid 2-D arrays?

regards,
Greg
Re: Strange array subscripting error [message #67132 is a reply to message #67131] Tue, 07 July 2009 02:38 Go to previous messageGo to next message
robintw is currently offline  robintw
Messages: 37
Registered: March 2009
Member
UPDATE:

In fact, it seems to be even stranger than I thought. It's now
crashing at 32389, even when I've made the array size 32403 rather
than 32400. Any ideas? This seems very strange...

Robin
University of Southampton, UK
Re: Strange array subscripting error [message #67220 is a reply to message #67123] Wed, 08 July 2009 01:43 Go to previous message
robintw is currently offline  robintw
Messages: 37
Registered: March 2009
Member
Thanks for the advice, Paolo. I'll change that now.

Cheers,

Robin
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: nike clothing,nike shoes,online store,http://www.nbashoe.com air Jordan Shoes,Nike Air Jordans, Air Force Ones,Retro Air Jordan, Bape Hoodies,Bape shoes-Tencent Traveler|Jordan Shoes,Nike Air Jordans, Air Force Ones,Retro Air Jordan, Bape Hoodie
Next Topic: Color problem with contours

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

Current Time: Wed Oct 08 15:47:32 PDT 2025

Total time taken to generate the page: 0.00694 seconds