[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: More For Loops

majewski@cygnus.uwa.edu.au_stralia writes:
> Hi
> I'm looking to get rid of the for loops below.
> They make two arrays;
>    one containing evey second column and evey second row
>    the other containing evey second column and evey alternate row
> ;------------------------------------------------------------------------------------------------------------
> 	x_data = 3072
> 	y_data = 512
> 	DATA_size = [x_data/2,y_data]
> 	Data_sets_ev = bytarr(DATA_size[0],DATA_size[1])
> 	Data_sets_od = bytarr(DATA_size[0],DATA_size[1])
> 	for i = 0, (DATA_size[0]/2)-1 do begin
> 		for j = 0, DATA_size[1]-1 do begin		
> 			Data_sets_ev[i,j] = my_data[(2*i),(2*j)]
> 			Data_sets_od[i,j] = my_data[(2*i),(2*j+1)]
> 		endfor
> 	endfor
> ;------------------------------------------------------------------------------------------------------------
> This is to extract a couple of NOAA14  AVHRR Sea Surface Temperature
> measurements. The different spectral bands overlap in the data file,
> hence they need to be separated by the above.

Liam has shown the array subscripting method -- which is fine -- but I
will show another.

Keep in mind that a (2M) x N array can be thought of as a 2 x M x N
array -- or an M x N array of pairs.  IDL can reform the first kind of
array into the second, and then it's a simple matter of extracting
what you want.  The "_ev" is the first of each pair, the "_od" is the

my_data = reform(my_data, 2, x_data/2, y_data, /overwrite)

data_sets_ev = my_data[0,*,*]
data_sets_od = my_data[1,*,*]

I use the /overwrite keyword for memory savings, but this of course
modifies the dimensions of the original data.


Craig Markwardt, Ph.D.              
EMAIL: craigm@lheamail.gsfc.nasa.gov