pro clean70,INcube,OUTcube
;
;Cleans up 70um data cube of stacked BCDs images 
;by removing column dependent stim latent residuals.
;Subtracts the median value for a column from every 
;pixel in the column.
;;INcube = stacked cube of bcd or fbcd images
;;OUTcube = column filtered output cube
;;
;Users need to stack input files into a cube before running.
;After clean70 correction, users need to split OUTcube into
;corrected images and attach pointing information (headers) 
;from the original images before mosaicing the data.
;;
;Notes:
; JPL and the SSC claim no responsibility for this script.
; From the project point of view, this is unoffical 
; software, provided as an example to users.  
; Your mileage may vary.
;
;Feel free to report any bugs to frayer@ipac.caltech.edu
;Frayer, version 2004 June 22
;;
;
sizeIN=size(INcube)
xIN=sizeIN(1)
yIN=sizeIN(2)
zIN=sizeIN(3)
OUTcube=INcube
for zz=0,zIN-1 do begin
  for xx=0,11 do begin
    tmp=median(INcube[xx,*,zz],/even)
    OUTcube[xx,*,zz]=INcube[xx,*,zz]-tmp
  endfor
;;Skip bad readout for columns 12-15
  for xx=12,15 do begin
    tmp=median(INcube[xx,8:31,zz],/even)
    OUTcube[xx,*,zz]=INcube[xx,*,zz]-tmp
  endfor
;;Ignore bad half of the array columns 16-31
end
;;IDL ignores NaNs in the median
return
end


