Reset Pointer at End of For Loop Issue [message #84099] |
Tue, 30 April 2013 13:37  |
Lisa08
Messages: 4 Registered: February 2013
|
Junior Member |
|
|
Hi,
I have run into something in IDL that has me a bit confused. I am trying to run this script to make an interval of day_of_year values (bounded by lowlim and uplim) that IDL will later use to find data that corresponds to the days specified in that interval. The lowlim and uplim is supposed to change during each iteration. If I set the time_step as 30 so that it sets the interval limits as 0 to 30, 30 to 60, etc, it works fine. However, when I try to use the specified limits for each month, low_daylim and up_daylim, it only makes it to day 31 and then spits out an error that says:
% Expression must be a scalar in this context: DIDX.
I can't set the time_step as 30 since I am trying to do a monthly analysis and not all months have 30 days. Consequently, I have to use the month limits that I specify in the beginning of the routine. If this is an issue with the pointer being reset at the end of the for loop I don't understand why it would work in one case and not in the other. Can somebody explain to me where I have gone wrong? I just don't see it.
Here is the routine that spits out the error:
PRO test_loop
;First day of each month
low_daylim=[1,32,61,92,122,153,183,214,245,275,306,336]
;Last day of each month
upper_daylim=[31,60,91,121,152,182,213,244,274,305,335,366]
;First day to begin loop
day_begin=1
;Last day to begin loop
day_end=366
;Number of days in interval
time_step=30
FOR didx=day_begin,day_end DO BEGIN
limits=where(low_daylim EQ didx)
lowlim=didx-1
uplim=upper_daylim[limits]
; lowlim=didx-1
; uplim=didx+(time_step-1)
print, 'lowlim'
print, lowlim
print, 'uplim'
print, uplim
;Set didx as uplim before next iteration
didx=uplim
print, 'didx'
print, didx
ENDFOR
STOP
END
The other one (where the time_step is set as 30) works when you comment out this part:
limits=where(low_daylim EQ didx)
lowlim=didx-1
uplim=upper_daylim[limits]
and uncomment the two lines below this.
If you need any more information from me or I haven't made something very clear please let me know. I tried using a ptr_free before setting the didx to uplim at the end of the for loop but I really didn't expect it to work. Any suggestions would be greatly appreciated as I have been stuck for a while.
|
|
|