PRO awfulpix,file image=readfits(file,h,exten=0) noise=readfits(file,exten=1) flags=readfits(file,exten=2) dataset={image:ptr_new(image),noise:ptr_new(noise),flags:ptr_new(flags)} cube=*dataset.image h=headfits(file) itime=sxpar(h,'itime') coadd=sxpar(h,'coadd') sat=sxpar(h,'saturate') max=sat*1./(itime) min=-20.0 print,'Using a max of: ',max print,'Using a min of: ',min len=n_elements(reform(cube[*,0,0])) for i=0,len-1 do begin slice=reform(cube[i,*,*]) if (max((slice ne slice) gt 0.0))then slice[where(slice ne slice)]=(-99999) bad=(slice gt max or slice lt min) good=abs(1-bad) ;good=(slice le max and slice ge min) new=median([[[shift(slice,1,0)]],[[shift(slice,-1,0)]],[[shift(slice,1,1)]],[[shift(slice,1,-1)]],[[shift(slice,-1,1)]],[[shift(slice,-1,-1)]]],dim=3) slice=bad*new + good*slice cube[i,*,*]=slice print,len-i,format='($,%"\R","Counter: ",I)' endfor sxaddpar,h,'AWFULPIX',1.0,'Bad rows fixed by awfulfix.pro' file='fixed_'+file writefits,file,cube,h writefits,file,*dataset.noise,/append writefits,file,*dataset.flags,/append end