NAME: 
  getspec
 PURPOSE:
  Extract a point source spectrum from OSIRIS XD data.
 DESCRIPTION:
 CATEGORY:
  Spectroscopy
 CALLING SEQUENCE:
  getspec,calib,root,i1,i2,spec,all,
     RAW=raw,NONEG=noneg,AUTO=auto,MASK=mask
 INPUTS:
  calib- Anonymous structure containing all pertinent calibration
           information.  This structure is usually loaded beforehand using
           the routine, "ldcalir"
  root - string containing the root of the file name (with leading path
         if desired).  DO NOT include the . between the root and suffix.
  i1   - Frame id (integer) of first image.
  i2   - Frame id (integer) of second image.
 OPTIONAL INPUT PARAMETERS:
 KEYWORD INPUT PARAMETERS:
  AUTO - Flag, if true, enables automatic aperture location for extracting
         the spectra.   The image is collapsed into a single column.  Any
         pixel more than 3 sigma from the background is flagged for
         extraction.  Default is to require clicking on the image displayed
         in window 0.  Three rows centered on the clicked location are
         extracted for the spetrum.  /AUTO is the preferred option.
  APLOC- Override to specify the positive object location.  Overrides AUTO.
  APSIZE-Override to force the size of the extraction aperture.  The
           will extend from the location (auto or APLOC) + and - by APSIZE.
           Thus the total aperture is 2*APSIZE+1 rows.
  NONEG - Flag, if true, inhibits using the "negative" spectrum in the
          background image (i2).  Default is to extact the negative
          spectrum, negate it, and add to the positive spectrum.
  RAW  - Flag, if true will inhibit the column-wise background subtraction.
           The default is to fit the background in each column (along the
           slit) and subtract the fitted background.  Use a linear function
           for the background.
  MASK - Indicies in strip image.  These pixels will be replaced by the
           average of their nearest neighbors in the x direction.
  SAVE - Flag, if true, final spectrum will be saved to a file.  The output
           file name is root+'s'+suffix.  Thus 950911.003 would be saved to
           the file 950911s.003
  PATH - optional string that points to the directory containing the data.
           This information is not used if the root already begins with '/'.
           If root is not an absolute pathname, then PATH is prepended to
           root for READ operations.  This path is not used for saving.
           This allows reading from one directory (possible a read only area)
           and then saving to the current directory.
  CLEAN - Flag, if set, calls clnspec to allow removing bad points before
           saving spectrum.

 OUTPUTS:
  spec - 1-D spectrum extracted from spectral image.
  all  - i1-i2 after XD spectra extracted to strip image. (see getpair)
 KEYWORD OUTPUT PARAMETERS:
 COMMON BLOCKS:
 SIDE EFFECTS:
 RESTRICTIONS:
  Specifically written for OSIRIS cross-dispersed spectral data.  MASK
  does not work particularly well.
 PROCEDURE:
 MODIFICATION HISTORY:
  95/03/24, Written by Marc W. Buie, Lowell Observatory
  95/06/21, MWB, modified aperture algorithm.
  95/09/14, MWB, added calib structure pass through, added SAVE flag, added
                 PATH keyword, added CLEAN flag.
  95/09/18, MWB, improved auto-aperture locating algorithm
  95/09/21, MWB, added APLOC and APSIZE keywords