NAME:
  xdavg
 PURPOSE:
  Interactive tool for combining and correcting OSIRIS XD spectra.
 DESCRIPTION:

  This program handles the removal of instrumental defects from OSIRIS XD
    spectra.  This is accomplished through the removal of bad points in the
    data from bad pixels on the NICMOS chip, applying slope corrections to the
    spectra to remove the effects of wavelength dependent vignetting, and the
    exclusion of bad spectra from the averaging process.

 CATEGORY:
  Spectroscopy
 CALLING SEQUENCE:
  xdavg
 INPUTS:

 OPTIONAL INPUT PARAMETERS:

 KEYWORD INPUT PARAMETERS:

 OUTPUTS:

  Spectra selected in the tool are displayed in cw_osipl.  The final products
    consist of the individual corrected spectra and their averages.  These
    spectra have had all the badflag editting done, primary slope correction
    applied to make them consistent within a set, all the bad spectra excluded,
    and have had the secondary slope correction applied relative to some
    reference.  A preliminary amount of ratioing is also done in which these
    corrected spectra are ratioed against either one other corrected average or
    an airmass corrected denominator interpolated between two of these
    corrected averages.  Each individual ratio is saved as well as the average
    of the set.  The badflags for each spectrum are also saved.

  File format for each type is:

    Individual corrected spectra - Spec/yymmddc.### where ### is the index
                                   number of the spectrum.  These have both
                                   the primary and secondary slope corrections
                                   applied but the flux in the file is still
                                   in units of [counts].

    Average corrected spectra - Corr/yymmdda.## where ## is the set number of
                                the average.  These are weighted set averages
                                and the "flux" values are all in counts/sec.

    Individual ratio spectra - Ratio/yymmddr.### where ### is the index number
                               of the spectrum.

    Average ratio spectra - Ratio/yymmdda.## where ## is the set number of the
                            average.

    Badflags have the same file format as their corresponding parents and are
      in the same directory except they are "b." files instead.

 KEYWORD OUTPUT PARAMETERS:

 COMMON BLOCKS:

 SIDE EFFECTS:

 RESTRICTIONS:

  At present, you cannot remove all spectra in a set (flag with X) with
    this tool.  You must edit the .tbl file by hand in this case.

 PROCEDURE:

  This program begins by loading the information regarding the nights worth of
    data by loading the table and calibration files from whichever directory
    that has been selected.  Next, the user can select to display whichever
    spectra that help in the process of removing the instrumental defects and
    edit them accordingly.  The primary slope correction is applied
    automatically to the spectra.  Spectra may also be excluded from the
    averages by means of either an x or s flag.

  The bulk of the editting of this type should be accomplished before moving on
    to making ratios with the bottom part of the tool and applying the
    secondary slope correction manually.  You begin by selecting one numerator
    as the reference denominator and then getting the night consistent by
    applying the secondary slope correction to various ratios.  Moving the an
    object into the denominator is also the point at which the various product
    spectra are saved to disk.

  Instance structure locations
     state  - First child of XDAVG
                 Contains all widget ids.

     tbl     - UVALUE of state.cwdid (current working directory)
                 Contains the contents of the observation summary table as
                 generated by XDSPEC.  Also has derived information about
                 groups of observations.

     calib   - UVALUE of state.tblnameid (name of current table file).
                 This is the calibration structure as read in by ldcalir

     oblist  - UVALUE of state.tblnsetid

     spec    - UVALUE of state.butspecid (Structure containing the various
                 levels of processed spectra as well as flags indicating how
                 far each has been processed).