pro fos_overflow,file,multi=multi ;+ ; fos_overflow ; ; Corrects overflows for counts that exceed 65536 ; ; CALLING SEQUENCE: ; fos_overflow,file ; ; INPUT: ; file - file name (e.g. 'y3hx0606t.d0h') ; ; KEYWORD INPUTS: ; /multi - use first group of multi-group non-destructive readout ; file to estimate counts in subsequent groups ; OUTPUT: ; a new version of the file is written to the current default ; directory ; ; HISTORY: ; version 1, D. Lindler Jul 15, 1997 ;- ;----------------------------------------------------------------------- if n_elements(multi) eq 0 then multi=0 ; ; Open input/output files ; fdecomp,file,disk,dir,name,ext sxopen,1,disk+dir+name+'.'+ext,h sxaddhist,'Overflows fixed w/ FOS_OVERFLOW '+!STIME,H sxopen,2,name+'.'+ext,h,'','W' ; ; determine number of data points, ysteps, and groups ; gcount = sxpar(h,'gcount') naxis = sxpar(h,'naxis') ns = sxpar(h,'naxis1') if naxis gt 1 then ny = sxpar(H,'naxis2') else ny = 1 ; ; loop on groups ; for group = 0,gcount-1 do begin data=sxread(1,group,par) ; ; loop on ysteps ; for k=0,ny-1 do begin d = data(*,k) if (group gt 0) and (multi gt 0) then begin ; ; fix overflows by using first readout to extimate counts ; predict = dsave(*,k)*(group+1) for i=0,ns-1 do begin while (predict(i)-d(i)) gt 32767 do $ d(i) = d(i) + 65536 end end else begin ; ; Fix overflows by examiming changes in neighbors ; ; ; forward search ; for i=1,ns-1 do begin if (d(i-1)-d(i)) gt 45000 then d(i) = d(i)+65536 end ; ; reverse search (needed if d(0) was overflowed) ; for i=ns-2,0,-1 do begin if (d(i+1)-d(i)) gt 45000 then d(i) = d(i)+65536 end end data(*,k) = d end if group eq 0 then dsave = data ; ; write the group ; sxwrite,2,data,par end close,1,2 return end