Read parameters Open and read input spectrum and spectrum OOT file header Open and read QPB calibration file if (withplotfiles) open LUNs for ASCII QDP output if (withimg) open and read input template image file get PN submode from spectrum header Open and read RMF, get channel to energy conversion Create the background spectrum by scaling the spectrum both by the ratio of the exposure and the ratio of the backscale value, as well as the OOT scale factor. Subtract the OOT spectrum Set channel ranges for some energy bands, total, soft, hard Set channel ranges for the interpolation bridge do i=1,4 (nQUADs) if (selected) then Read in FOV spec for QUADi (areafov(i) and expofov(i)) Read in FOV OOT spec for QUADi (areafov(i) and expofov(i)) Fill FOV by-quad spectrum endif enddo do i=1,4 (nQUADs) if (selected) then Read in FWC spec for QUADi (areafwc(i) and expofwc(i)) Normalize specFWC(1:4096,i) and specFWCunc(1:4096,i) endif enddo Remove any chip's data that has less area than limiting area do i=1,4 Object corner data if (selected) then Read in Obj Corner spec for QUADi (areacoro(i) and expocoro(i)) Calculate hardness Calculate rate Normalize the count rate Set the search values for the augmentation spectrum Augment spectra Calculate augmented count rate Scale by count rate and then test the scaling of the background spectrum Write augmented spectra to output file endif enddo do i=1,4 FWC corner data if (selected) then Read in FWC Corner spec for QUADi (areafwcc(i) and expofwcc(i)) Subtract the OOT events from the spectrum and normalize the result endif enddo Smooth the data Exclude data if they are in a bridge region Create the masks to remove strong instrumental lines Remove the Al line from all spectra if (withplotfiles) open and write output QDP file header if (withimg) Create final image (check for bright pixels, reset if necessary) Create output spectrum (mask if necessary) if (withplotfiles) fill QDP plot, close several QDP files Add in the OOT events for CSTAT background spectrum if (withimage) fill opened final image (and OOT image), close images if (withplotfiles) open bridgefit QDP file Bridge the Al and high-energy gaps Set a number of line-free windows Extract the data from those windows Fit a simple polynomial to the log of the data Use the result to interpolate over the Al gap Finish the bridge Write bkg spectrum if (withplotfiles) Write bkg spectrum QDP plot, close QDP file Close bkg spectrum