subr com3to2,x3d,x2d
 ;used to compress a 3-D power spectra into a 2-D version by
 ;symmetrizing the spatial dimensions which are assumed to be the last 2
 ;i.e., the omega t is the inner dimension
 ;3/6/90 note - this routine assumes that (0,0,0) corresponds to zero
 ;frequencies for all 3 k's, DO NOT use with the output from powerphase3d !
 ;input array is x3d and result is x2d
 if num_dim(x3d) ne 3 then { t,'COM3TO2 -- input is not 3-D'  RETALL }
 nx=dimen(x3d,2)  ny=dimen(x3d,1)
 nt=dimen(x3d,0)
 maskprep,msk,ny,nx
 msk=long(msk+0.5) ;add 0.5 so subsequent truncation is actually a rounding
 np=max(msk)+1
 x2d=fltarr(nt,np)
 wt=fltarr(np)	;for the weights
 zero,x2d,wt
 nxm1=nx-1
 for j=0,ny-1 do for i=0,nxm1 do begin
 k=msk(j,i)
 x2d(0,k)=x2d(*,k)+x3d(*,j,i)
 wt(k)=wt(k)+1
 end
 ;now normalize by dividing by the weights
 for k=0,np-1 do begin
 x2d(0,k)=x2d(*,k)/wt(k)
 end
 endsubr
 ;=========================================================================
