0

I have a problem with my for-loops in IDL.

for sl=0,2 do begin  ; number of hours
 for t=90,90 do begin   ; timesteps each hour
  for rad_num = 0, 3 do begin   ; number of radars
   for ibin = 0, 333 do begin   ; distance to radar
     for iray = 0, 359 do begin   ; angle

       if finite(input(ibin,iray,rad_num)) eq 1 then begin
        bin = bin_index(ibin,iray,rad_num)
        ray = ray_index(ibin,iray,rad_num)  ; necessary because of different grids 

        array(sl,t,ray,bin)=array(sl,t,ray,bin)+ input(ibin,iray,rad_num)
        array_N(sl,t,ray,bin) = array_N(sl,t,ray,bin) + 1. 
       endif
      endfor
     endfor
    endfor
   endfor
  endfor

array = array / array_N

When I stopped the program after the first sl-loop-step, I get the following:

 print, array[0,90,315,49]
     44.0.673

But when I don't stop the program, I get this:

 print, array[0,90,315,49]
    -NaN

It seems, that my program overwrites the data of the previous loop-step. When I make a scatter-plot, I also have the points of the last loop-step only...

Do you see my mistake? Thanks a lot! kiki

user1704042
  • 399
  • 1
  • 5
  • 18

1 Answers1

0

You don't assign to dwd in the code you show (and the code won't compile as-is because of the enddo's -- I assume you had to rewrite the code instead of copy-and-past for some reason?).

mgalloy
  • 2,356
  • 1
  • 12
  • 10
  • So there are multiple values of `ibin`/`iray`/`ray_num`, that have the same values in `bin` and `ray`? – mgalloy Mar 27 '14 at 17:07
  • Displaying the data gives me that the plot program gets the same as the main program... –  Apr 01 '14 at 11:12
  • I'm not sure you understand: multiple values of `ibin`/`iray`/`ray_num` having then same values of `bin` and `ray` is why you are overwriting. – mgalloy Apr 10 '14 at 21:21