IDL Help for HSRED

This page was created by the IDL library routine make_html_help. For more information on this routine, refer to the IDL Online Help Navigator or type:

     ? make_html_help

at the IDL command line prompt.

Last modified: Sun Mar 6 15:48:02 2005.


List of Routines


Routine Descriptions

ARCFIT_GUESS

[Next Routine] [List of Routines]
 NAME:
   arcfit_guess

 PURPOSE:
   Determine initial wavelength solution by comparing spectrum to arc spectrum

 CALLING SEQUENCE:
   wset = arcfit_guess( spec, loglam, intensity, color=color, $
    [ func=func, bestcorr=bestcorr, acoeff=, dcoeff=, nsteps= ] )

 INPUTS:
   spec       - 1-D spectrum
   loglam     - Log-lambda of arc lines
   intensity  - Intensity of arc lines

 REQUIRED KEYWORDS:
   color      - 'red' or 'blue'

 OPTIONAL KEYWORDS:
   func       - Name of fitting function; default to 'legendre'
   acoeff     - central values of coefficents to explore
   dcoeff     - range (-.5*dcoeff to .5*dcoeff) of values to explore
   nsteps     - array of steps to use

 OUTPUTS:
   wset       - traceset (pix -> lambda)

 OPTIONAL OUTPUTS:
   bestcorr   - Correlation coefficient with simulated arc spectrum

 COMMENTS:

 EXAMPLES:

 BUGS:

 INTERNAL SUPPORT PROCEDURES:
   tset_struc()
   arcfit_iter()

 PROCEDURES CALLED:
   traceset2xy()
   xy2traceset

 REVISION HISTORY:
   18-Nov-1999  Written by D. Schlegel, Princeton.
                Excised code from FITARCIMAGE.
   01-Dec-2000  added acoeff, dcoeff, nsteps keywords

(See /home/hsred/idl/hsred/idl/spec2d/iarcfit_guess.pro)


DIREXIST

[Previous Routine] [Next Routine] [List of Routines]
 NAME: DIREXIST

 PURPOSE: Determine which elements in list are directories.

 CATEGORY: File I/O

 CALLING SEQUENCE: result = direxist(list)
 
 INPUTS:
    list : a list of files (i.e. the result from list = FINDFILE())

 OPTIONAL INPUTS: none

 OUTPUTS: An array of the appropriate size. 1 indicates list(i) is a
          directory. 0 indicates that list(i) is a file.

 PROCEDURE:
   Get a file list
      IDL> list = findfile()
      IDL> dirs = direxist(list)
   Print which elements in list are directories
      IDL> print,where(dirs eq 1)
           1           6          14          22

 MODIFICATION HISTORY:
   27 Dec 96 Initial coding. PMW
     Use direxist.pro from David Fanning as a starting point.
   28 Dec 96 Fixed bug. Now checking last entry in list. PMW
   30 Dec 96 Fixed bug with last entry check. PMW

(See /home/hsred/idl/hsred/idl/spec2d/direxist.pro)


FIND_NMINIMA

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   find_nminima

 PURPOSE:
   Find one or several minima in a vector of chi^2 values.

 CALLING SEQUENCE:
   xpeak = find_nminima( yflux, [ xvec, dofarr=, nfind=, minsep=, $
    width=, ypeak=, xerr=, errcode=, npeak=, plottitle=, /doplot, /debug ]

 INPUTS:
   yflux          - Y values

 OPTIONAL INPUTS:
   xvec           - X values, which must either be sorted in ascending
                    or descending order; default to 0-indexed integers.
   dofarr         - If set, then fit to the minima in the function
                    YFLUX/DOFARR, but avoiding any points where DOFARR
                    is set to zero.
   nfind          - Number of minima to find; default to 1.  It is possible
                    to find fewer than NFIND minima.
   minsep         - Minimum separation between local minima.  If a peak
                    is found closer than MINSEP to an existing peak, then
                    the latter peak is discarded.
   width          - Width to use when selecting the points used in the fit.
                    Only use points where XVEC is within WIDTH of the
                    the lowest-values point (which is used as the initial
                    guess); default to using all points.

 OUTPUTS:
   ypeak          - Fit value for either chi^2 or chi^2/DOF at the minima.
                    If the fit value is less than zero, then change it to zero.

 OPTIONAL OUTPUTS:
   xerr           - Formal errors of XPEAK.
   errcode        - Error codes for each minima; 0 for no errors in the fit.
   npeak          - The number of peaks found, between [0,NFIND].
   plottitle      - Title of plot (if /DOPLOT is set).
   doplot         - If set, then make plots.  Discarded peaks are not plotted.
   debug          - If set, then wait for keystroke after plot.

 COMMENTS:
   This routine calls SVDFIT for fitting quadratics, or MPFIT for
   fitting gaussians.
   
 EXAMPLES:
   
 BUGS:

 PROCEDURES CALLED:
   djs_icolor()
   djs_oplot
   djs_plot
   mpfitpeak
   mpfitpeak_gauss
   textoidl

 INTERNAL SUPPORT ROUTINES:
   zfitmin()
  
 REVISION HISTORY:
   22-Aug-2001  Written by D. Schlegel, Princeton 
   30-Jul-2002  Fixed bug - yrange passed twice to djs_plot

(See /home/hsred/idl/hsred/idl/spec1d/hs_find_nminima.pro)


FITARCIMAGE[1]

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   fitarcimage

 PURPOSE:
   Determine wavelength calibration from arclines

 CALLING SEQUENCE:
   fitarcimage, arc, arcivar, xcen, ycen, wset, [wfirst=, $
    color=color, lampfile=lampfile, fibermask=fibermask, $
    func=func, aset=aset, ncoeff=ncoeff, lambda=lambda, $
    thresh=thresh, row=row, nmed=nmed, /gauss, $
    xdif_tset=xdif_tset, bestcorr=bestcorr ]

 INPUTS:
   arc        - Extracted arc spectra with dimensions [NY,NFIBER]
   arcivar    - Inverse variance of ARC

 OPTIONAL KEYWORDS:
   color      - 'red' or 'blue'; not required if ANS is set
   lampfile   - Name of file describing arc lamp lines;
                default to the file 'lamphgcdne.dat' in $IDLSPEC2D_DIR/etc.
   fibermask  - Fiber status bits, set nonzero for bad status [NFIBER]
   func       - Name of fitting function; default to 'legendre'
   aset       - Trace set for initial wavelength solution in row number ROW.
   ncoeff     - Number of coefficients in fits.  This may be different than
                the number of coefficients in the initial guess ASET.
                Default to 5.
   thresh     - Threshhold counts for significant lines;
                default to 200 if COLOR='blue' or 500 if COLOR='red'
   row        - Row to use in initial guess of wavelength solution;
                default to (NFIBER-30)/2
   nmed       - Number of rows around ROW to median filter for initial
                wavelengths solution; default to 5
   maxdev     - max deviation in log lambda to allow (default 1.0e-5=7 km/s)
   gauss      - Use gaussian profile fitting for final centroid fit

 OUTPUTS:
   aset       - (Modified)
   xcen       - pixel position of lines [nfiber, nlambda]
   ycen       - fiber number [nfiber, nlambda]
   wset       - traceset (pix -> lambda)

 OPTIONAL OUTPUTS:
   lampfile   - Modified from input to include full path name of file
   lambda     - Returns wavelengths of good lamp lines [Angstroms]
   fibermask  - (Modified)
   xdif_tset  - Fit residual of lamp lines to fit positions [pixels]
   bestcorr   - Correlation coefficient with simulated arc spectrum
   wfirst     - traceset from first iteration on arc fits

 COMMENTS:
   Return from routine after computing BESTCORR if XCEN, YCEN and WSET
   are not to be returned.

 EXAMPLES:

 BUGS:
   Not making sure that only the same lines are fit for each fiber.
      (Different lines can be rejected in xy2traceset.)
   THRESH is unused.
   TRACESET2PIX maybe returns the transpose of what is natural?
   Check QA stuff at end.
   FIBERMASK not yet modified if an arc is atrociously bad.


 PROCEDURES CALLED:
   arcfit_guess()
   djs_median
   djsig()
   fibermask_bits()
   trace_crude()
   trace_fweight()
   traceset2pix()
   traceset2xy()
   xy2traceset

 DATA FILES:
   $IDLSPEC2D_DIR/etc/lamphgcdne.dat

 REVISION HISTORY:
   15-Oct-1999  Written by S. Burles, D. Finkbeiner, & D. Schlegel, APO.
   09-Nov-1999  Major modifications by D. Schlegel, Ringberg.
   20-Jan-2000  Gone back to very simple procedure: replacement (S. Burles)

(See /home/hsred/idl/hsred/idl/spec2d/hs_fiberflatgen.pro)


FITARCIMAGE[2]

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   fitarcimage

 PURPOSE:
   Determine wavelength calibration from arclines

 CALLING SEQUENCE:
   fitarcimage, arc, arcivar, xcen, ycen, wset, [wfirst=, $
    color=color, lampfile=lampfile, fibermask=fibermask, $
    func=func, aset=aset, ncoeff=ncoeff, lambda=lambda, $
    thresh=thresh, row=row, nmed=nmed, /gauss, $
    xdif_tset=xdif_tset, bestcorr=bestcorr ]

 INPUTS:
   arc        - Extracted arc spectra with dimensions [NY,NFIBER]
   arcivar    - Inverse variance of ARC

 OPTIONAL KEYWORDS:
   color      - 'red' or 'blue'; not required if ANS is set
   lampfile   - Name of file describing arc lamp lines;
                default to the file 'lamphgcdne.dat' in $IDLSPEC2D_DIR/etc.
   fibermask  - Fiber status bits, set nonzero for bad status [NFIBER]
   func       - Name of fitting function; default to 'legendre'
   aset       - Trace set for initial wavelength solution in row number ROW.
   ncoeff     - Number of coefficients in fits.  This may be different than
                the number of coefficients in the initial guess ASET.
                Default to 5.
   thresh     - Threshhold counts for significant lines;
                default to 200 if COLOR='blue' or 500 if COLOR='red'
   row        - Row to use in initial guess of wavelength solution;
                default to (NFIBER-30)/2
   nmed       - Number of rows around ROW to median filter for initial
                wavelengths solution; default to 5
   maxdev     - max deviation in log lambda to allow (default 1.0e-5=7 km/s)
   gauss      - Use gaussian profile fitting for final centroid fit

   parity     - Even or odd?

   ccdnum     - CCD number

 OUTPUTS:
   aset       - (Modified)
   xcen       - pixel position of lines [nfiber, nlambda]
   ycen       - fiber number [nfiber, nlambda]
   wset       - traceset (pix -> lambda)

 OPTIONAL OUTPUTS:
   lampfile   - Modified from input to include full path name of file
   lambda     - Returns wavelengths of good lamp lines [Angstroms]
   fibermask  - (Modified)
   xdif_tset  - Fit residual of lamp lines to fit positions [pixels]
   bestcorr   - Correlation coefficient with simulated arc spectrum
   wfirst     - traceset from first iteration on arc fits

 COMMENTS:
   Return from routine after computing BESTCORR if XCEN, YCEN and WSET
   are not to be returned.

 EXAMPLES:

 BUGS:
   Not making sure that only the same lines are fit for each fiber.
      (Different lines can be rejected in xy2traceset.)
   THRESH is unused.
   TRACESET2PIX maybe returns the transpose of what is natural?
   Check QA stuff at end.
   FIBERMASK not yet modified if an arc is atrociously bad.


 PROCEDURES CALLED:
   arcfit_guess()
   djs_median
   djsig()
   fibermask_bits()
   trace_crude()
   trace_fweight()
   traceset2pix()
   traceset2xy()
   xy2traceset

 DATA FILES:
   $IDLSPEC2D_DIR/etc/lamphgcdne.dat

 REVISION HISTORY:
   15-Oct-1999  Written by S. Burles, D. Finkbeiner, & D. Schlegel, APO.
   09-Nov-1999  Major modifications by D. Schlegel, Ringberg.
   20-Jan-2000  Gone back to very simple procedure: replacement (S. Burles)

(See /home/hsred/idl/hsred/idl/spec2d/hs_fitarcimage.pro)


HS_ARCFIT_GUESS

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_arcfit_guess

 PURPOSE:
   Determine initial wavelength solution by comparing spectrum to arc spectrum

 CALLING SEQUENCE:
   wset = arcfit_guess( spec, loglam, intensity, color=color, $
    [ func=func, bestcorr=bestcorr, acoeff=, dcoeff=, nsteps= ] )

 INPUTS:
   spec       - 1-D spectrum
   loglam     - Log-lambda of arc lines
   intensity  - Intensity of arc lines
;
 OPTIONAL KEYWORDS:
   func       - Name of fitting function; default to 'legendre'
   acoeff     - central values of coefficents to explore
   dcoeff     - range (-.5*dcoeff to .5*dcoeff) of values to explore
   nsteps     - array of steps to use

 OUTPUTS:
   wset       - traceset (pix -> lambda)

 OPTIONAL OUTPUTS:
   bestcorr   - Correlation coefficient with simulated arc spectrum

 COMMENTS:

 EXAMPLES:

 BUGS:

 INTERNAL SUPPORT PROCEDURES:
   tset_struc()
   arcfit_iter()

 PROCEDURES CALLED:
   traceset2xy()
   xy2traceset

 REVISION HISTORY:
   18-Nov-1999  Written by D. Schlegel, Princeton.
                Excised code from FITARCIMAGE.
   01-Dec-2000  added acoeff, dcoeff, nsteps keywords

(See /home/hsred/idl/hsred/idl/spec2d/hs_arcfit_guess.pro)


HS_ARCGEN

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_arcgen

 PURPOSE:
   Create a super arc image from all of the single arc images

 CALLING SEQUENCE:
  hs_arcgen, arcfiles, outdir=outdir, mjd=mjd

 INPUTS:
   arcfiles   - a linst of arc files that are to be comined

 OPTIONAL KEYWORDS:
   outdir     - Output directory for the final combined arc
   mjd        - Integer part of the MJD for the observations 
                this will create the outname for the file if
                 in the headers of the file

 OUTPUTS:
      creates the /calibration/XXXX/arc-YYYY.fits file where
      XXXX is the rerun number and YYYY is the MJD

 OPTIONAL OUTPUTS:
   

 COMMENTS:


 EXAMPLES:

 BUGS:

    Not sure the scaling for the images is appropriate
    is the entrie chip being used or just the illuminated
    region
;
 REVISION HISTORY:
   April 2004 - Written by R Cool - UofA         
                adapted from code in Schlegals IDLSPEC2d
                 package

(See /home/hsred/idl/hsred/idl/spec2d/hs_arcgen.pro)


HS_BATCH

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_batch

 PURPOSE:
  Given a plugplan and reduction plans this will reduce data

 CALLING SEQUENCE:
  hs_batch, redplan=redplan, rerun=rerun, plugplan=plugplan,link=link, $
              basedir=basedir, checkaverage=checkaverage, docosmic=docosmic, $
              nofluxplan=nofluxplan, superfile=superfile


 INPUTS:
 ;
 OPTIONAL KEYWORDS:
   redplan      - List of directories that need to be reduced (with fluxing)
   nofluxplan   - List of directories that need to be reduced without fluxing
   plugplan     - A translation file between config and field pass
   checkaverage - Same as in hs_extract
   superfile    - same as in hs_extract
   docosmic     - same as in hs_extract
   link         - if set, run hs_makelinks at the end

 OUTPUTS:
;
 OPTIONAL OUTPUTS:
;
 COMMENTS:


 EXAMPLES:

 BUGS:

;   

 REVISION HISTORY:
   April 2004 - Written by R Cool - UofA         
                

(See /home/hsred/idl/hsred/idl/spec2d/hs_batch.pro)


HS_BATCH1D

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_batch1d

 PURPOSE:
  Given a plugplan and reduction plans this will reduce 1d data

 CALLING SEQUENCE:
  hs_batch, redplan=redplan, rerun=rerun, plugplan=plugplan,link=link, $
              basedir=basedir, checkaverage=checkaverage, docosmic=docosmic, $
              nofluxplan=nofluxplan, superfile=superfile


 INPUTS:
 ;
 OPTIONAL KEYWORDS:
   redplan      - List of directories that need to be reduced (with fluxing)
   nofluxplan   - List of directories that need to be reduced without fluxing
   plugplan     - A translation file between config and field pass
   checkaverage - Same as in hs_extract
   superfile    - same as in hs_extract
   docosmic     - same as in hs_extract
   link         - if set, run hs_makelinks at the end

 OUTPUTS:
;
 OPTIONAL OUTPUTS:
;
 COMMENTS:


 EXAMPLES:

 BUGS:

;   

 REVISION HISTORY:
   April 2004 - Written by R Cool - UofA         
                

(See /home/hsred/idl/hsred/idl/spec1d/hs_batch1d.pro)


HS_BATCH_EXTRACT

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_batch_extract

 PURPOSE:
   Reduce all of the files as layd out in the cal-YYYY.list
   file in the list directory

 CALLING SEQUENCE:
  hs_batch_extract, skysubtract=skysubtract, $
     fiberflat=fiberflat,  tweaksky=tweaksky, $
     plugcat=plugcat, combine=combine, writeout=writeout,$
     lamout=lamout, fluxout=fluxout, fluxcorr=fluxcorr, $
     tellcorr=tellcorr, uberextract=uberextract, $
     ivarout=ivarout, rerun=rerun,  outname=outname,  $
     writeall=writeall,  plateid=plateid, $
     qaplot=qaplot, quicklook=quicklook, quickplot=quickplot,$
     stand=stand,  checkaverage=checkaverage, $
     docosmic=docosmic, superfile=superfile, dostand=dostand

 INPUTS:
   lists/cal-YYYY.list - this file is automatically used
                          as a reduction plan

 OPTIONAL KEYWORDS:
   skysubtract - turn on sky subtraction
   fiberflat   - turn on flat fielding
   tweaksky    - use skylines to tweak the intial wavelength 
                 solution
   plugcat     - turn this on if you are using specially formated
                 plugcat files for your reductions. If you are not sure, 
                 then you are probably not using these files
   plugfile    - If plugcat is set, then plugfile must be set to the plugcat 
                 file for the reduction
   combine     - Set this to combine the multiple observations. The spectra
                 are extracted and then combined
   writeout    - Set to write the final coadded spectrum- this will be
                 a spHect file
   fluxcorr    - Set this to flux the data with F star standards
                 NOTE: Fluxing must have at least two observations
   tellcorr    - Set this to telluric correct the data.  You need 
                 standard stars in order for this to work
   uberextract - Set this to turn on tweaksky, fiberflat, skysubtract
                 tellcorr, and fluxcorr. Obivously, you don't want this 
                 if you don't have standards
   rerun       - This should be set to the rerun number you would like to 
                 for the reduction. If not set rerun=0000
   outname     - Root outname you would like to use for the data.  If
                 this is not set, then outname='test'
   writeall    - Set this if you want the individual files written to disk
                 these will be spObs files
   qaplot      - Setting this results in the quality assurance plots to be
                 be created
   superfile   - If this is set, the file $HSRED_DIR/etc/superstand.fits
                 instead of typing the stars
   docosmic    - If docosmic is set then the cosmic ray rejection is turned 
                 on.
   checkaverage- This will check the current flux soln against an archival 
                 solution and will truncate the data if the counts of the 
                 standard stars are fewer than 100 

 OUTPUTS:
      Creates a variety of files (depending on settings) in the 
      /reduction/YYYY/ direcory where YYYY is the rerun

 OPTIONAL OUTPUTS:
   lamout       - the final wavelength map
   fluxout      - the final flux
   ivarout      - the final inverse variance map

 COMMENTS:


 EXAMPLES:

 BUGS:
    The flat field is generated after tracing.  A proper flat field would
    alsop have a 2d component.  There are issues with this.  
   

 REVISION HISTORY:
   April 2004 - Written by R Cool - UofA         
                

(See /home/hsred/idl/hsred/idl/spec2d/hs_batch_extract.pro)


HS_BIASGEN

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_biasgen

 PURPOSE:
   Create a super bias image from all of the single bias images

 CALLING SEQUENCE:
  hs_biasgen, biasfiles, outdir=outdir, mjd=mjd

 INPUTS:
   biasfiles   - a linst of bias files that are to be comined

 OPTIONAL KEYWORDS:
   outdir     - Output directory for the final combined arc
   mjd        - Integer part of the MJD for the observations
                this will create the outname for the file if
                 in the headers of the file

 OUTPUTS:
      creates the /calibration/XXXX/bias-YYYY.fits file where
      XXXX is the rerun number and YYYY is the MJD

 OPTIONAL OUTPUTS:


 COMMENTS:


 EXAMPLES:

 BUGS:

    Not sure the scaling for the images is appropriate
    is the entrie chip being used or just the illuminated
    region
;
 REVISION HISTORY:
   April 2004 - Written by R Cool - UofA
                adapted from code in Schlegals IDLSPEC2d
                 package

(See /home/hsred/idl/hsred/idl/spec2d/hs_biasgen.pro)


HS_CALIBPROC

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_calibproc

 PURPOSE:
   Do the intial processing of calibration frames

 CALLING SEQUENCE:
  hs_calibproc, listpath=listpath, calpath=calpath,$
                  mjd=mjd, rerun=rerun, wavetweak=wavetweak, path=path, $
                  doall=doall, dobias=dobias, dodome=dodome, dosky=dosky,$
                  doarc=doarc, dowave=dowave, doflatten=doflatten


 INPUTS:
   

 OPTIONAL KEYWORDS:
   listpath      - Directory containing lists (default to 'lists/')
   calpath       - Where calibration will be written (default to 'lists/')
   mjd           - integer modified julian date for the observations. If 
                   not set, it will be found in the header
   dobias        - DO the bias combination
   dodome        - combine the domeflats
   dosky         - combine the skyflats
   doarc         - combine the arcfiles
   dowave        - find the wavelength solution
   doall         - sets all of the above processes

 OUTPUTS:
     dobias - same as hs_biasgen
     doarc  - same as hs_arcgen
     dodome - same as hs_dflatgen
     dosky  - same as hs_sflatgen
     dowave - same as hs_maketraceset, hs_findwave

 OPTIONAL OUTPUTS:


 COMMENTS:


 EXAMPLES:

 BUGS:

;
 REVISION HISTORY:
   April 2004 - Written by R Cool - UofA
                adapted from code in Schlegals IDLSPEC2d
                 package

(See /home/hsred/idl/hsred/idl/spec2d/hs_calibproc.pro)


HS_CATTOPLUG

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_cattoplug

 PURPOSE:
   Make the plumap structure from the plugcat files

 CALLING SEQUENCE:
  hs_cattoplug, root, plugmap, ccdnum=ccdnum

 INPUTS:
   root = the root name for the files containing the plugcat 


 OPTIONAL KEYWORDS:
   ccdnum    - set for which ccd number to use

 OUTPUTS:
   plugmap    - output plugmap structure

 OPTIONAL OUTPUTS:


 COMMENTS:
    You also need the _map files from the hectospec output as well

 EXAMPLES:

 BUGS:


 REVISION HISTORY:
   April 2004 - Written by R Cool - UofA
                adapted from code in Schlegals IDLSPEC2d
                 package

(See /home/hsred/idl/hsred/idl/spec2d/hs_cattoplug.pro)


HS_COMBINE1FIBER

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_combine1fiber

 PURPOSE:
   Combine several spectra of the same object, or resample a single spectrum.

 CALLING SEQUENCE:
   combine1fiber, inlam, objflux, [ objivar, finalmask=, indisp=, skyflux=,$
    newlam=, newflux=, newivar=, andmask=, ormask=, newdisp=, newsky=, $
    nord=, binsz=, bkptbin=, maxsep=, _EXTRA=KeywordsForReject, /verbose ]

 INPUTS:
   inlam       - Wavelengths in Angstroms [NPIX,NSPEC]
   objflux        - Flux [NPIX,NSPEC]

 REQUIRED KEYWORDS:
   newlam      - Wavelengths for output evaluation, also in log10-Angstroms
                    [NNEWPIX]

 OPTIONAL INPUTS:
   objivar        - Inverse variance [NPIX,NSPEC]
   finalmask      - Pixel mask [NPIX,NSPEC]
   indisp         - Dispersion values [NPIX,NSPEC]
   skyflux        - Sky flux vectors [NPIX,NSPEC]
   binsz          - Bin separation for INLOGLAM; if not set, then default
                    to INLOGLAM[1]-INLOGLAM[0].
   nord           - Order of spline fit; default to 3.
   bkptbin        - Break point binning; default to 1.2 * BINSZ.
   maxsep         - Maximum separation between input wavelengths.  The spline
                    fit is split into pieces, with the breaks wherever this
                    spacing is exceeded.  Default to 2.0 * BINSZ.
   _EXTRA         - Keywords for DJS_REJECT().
   verbose        - If set, then output messages about bad break points and
                    masked data points.

 OUTPUTS:

 OPTIONAL OUTPUTS:
   finalmask      - Modified from its input by setting the COMBINEREJ bit
                    for deviant pixels in individual spectra that have
                    been rejected.
   objivar        - Modified from itts input by setting to zero wherever
                    the COMBINEREJ bit has been set in FINALMASK.
   newflux        - Resampled flux [NNEWPIX].
   newivar        - Resampled inverse variance [NNEWPIX].
   andmask        - Resampled mask. For each mask bit, set that bit only if
                    every input spectrum at this wavelength has that bit set
                    (e.g., this is a logical AND) [NNEWPIX].
   ormask         - Resampled mask. For each mask bit, set that bit if any
                    of the input spectra at this wavelength has that bit set
                    (e.g., this is a logical OR) [NNEWPIX].
   newdisp        - Resampled dispersion values [NNEWPIX].
   newsky         - Resampled sky flux [NNEWPIX].

 COMMENTS:
   One can pass this routine a single spectrum to be fit by a spline and
   re-sampled, in which case all the inputs (such as FLUX) are 1-dimensional
   arrays.  Or, one can pass it several spectra, in which case these inputs
   are 2-dimensional arrays.

   There's also some code in here to grow masked regions by another pixel
   on either end if the region is more than 3 pixels wide.

 EXAMPLES:

 BUGS:

 PROCEDURES CALLED:
   bspline_iterfit()
   bspline_valu()
   djs_laxisgen()
   djs_maskinterp()
   djs_median()
   pixelmask_bits()
   splog

 REVISION HISTORY:
   02-Jan-2000  Written by D. Schlegel; modified from COMBINE2DOUT
   April 2004  - Adapted from combine1fiber from IDLSPEC2D

(See /home/hsred/idl/hsred/idl/spec2d/hs_combine1fiber.pro)


HS_COSMIC

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_cosmic

 PURPOSE:
   Calls the cosmic ray rejection routines

 CALLING SEQUENCE:
  hs_cosmic, flux, newflux, sigclip=sigclip, objlim=objlim
       sigfrac=sigfrac, blocksize=blocksize, rerun=rerun
       nodelete=nodelete

 INPUTS:
   flux       - input image

 OPTIONAL KEYWORDS:
   sigclip - sigclip setting for LAcosmic (default to 5.0)
   objlim  - objlim setting for LAcosmic (default to 2.0)
   sigfrac - sigfrac setting for LAcosmic (default to 0.5)
   blocksize - subimage size to use in LAcosmic (default to 1024)
   rerun - rerun for the reduction (default to 0)

 OUTPUTS:
      newflux  - CR rejected image

 OPTIONAL OUTPUTS:


 COMMENTS:
    This is quite slow.  

 EXAMPLES:

 BUGS:

;
 REVISION HISTORY:
   April 2004 - Written by R Cool - UofA
                adapted from code in Schlegals IDLSPEC2d
                 package

(See /home/hsred/idl/hsred/idl/spec2d/hs_cosmic.pro)


HS_DARKGEN

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_darkgen

 PURPOSE:
   Create a super dark image from all of the single dark images

 CALLING SEQUENCE:
  hs_darkgen, darkfiles, outdir=outdir, mjd=mjd

 INPUTS:
   darkfiles   - a linst of dark files that are to be comined

 OPTIONAL KEYWORDS:
   outdir     - Output directory for the final combined dark

 OUTPUTS:
      creates the /calibration/XXXX/dark.fits file where
      XXXX is the rerun number

 OPTIONAL OUTPUTS:


 COMMENTS:


 EXAMPLES:

 BUGS:

    Not sure the scaling for the images is appropriate
    is the entrie chip being used or just the illuminated
    region
;
 REVISION HISTORY:
   April 2004 - Written by R Cool - UofA
                adapted from code in Schlegals IDLSPEC2d
                 package

(See /home/hsred/idl/hsred/idl/spec2d/hs_darkgen.pro)


HS_DFLATGEN

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_dflatgen

 PURPOSE:
   Create a super dflat image from all of the single dflat images

 CALLING SEQUENCE:
  hs_flatgen, dflatfiles, outdir=outdir, mjd=mjd

 INPUTS:
   dflatfiles   - a linst of dflat files that are to be comined

 OPTIONAL KEYWORDS:
   outdir     - Output directory for the final combined arc

 OUTPUTS:
      creates the /calibration/XXXX/dflat.fits file where
      XXXX is the rerun number

 OPTIONAL OUTPUTS:


 COMMENTS:


 EXAMPLES:

 BUGS:

    Not sure the scaling for the images is appropriate
    is the entrie chip being used or just the illuminated
    region
;
 REVISION HISTORY:
   April 2004 - Written by R Cool - UofA
                adapted from code in Schlegals IDLSPEC2d
                 package

(See /home/hsred/idl/hsred/idl/spec2d/hs_dflatgen.pro)


HS_EXTRACT

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_extract

 PURPOSE:
  Main reduction workhorse

 CALLING SEQUENCE:
  hs_extract, filelist,  skysubtract=skysubtract, $
     fiberflat=fiberflat,  tweaksky=tweaksky, $
     plugcat=plugcat, combine=combine, $
     lamout=lamout, fluxout=fluxout, fluxcorr=fluxcorr, $
     tellcorr=tellcorr, uberextract=uberextract, $
     ivarout=ivarout, rerun=rerun,  outname=outname,  $
     plateid=plateid, $
     qaplot=qaplot, quicklook=quicklook, quickplot=quickplot,$
     stand=stand,  checkaverage=checkaverage, $
     docosmic=docosmic, superfile=superfile, dostand=dostand

 INPUTS:
  filelist - list of files to be reduced

 OPTIONAL KEYWORDS:
   skysubtract - turn on sky subtraction
   fiberflat   - turn on flat fielding
   tweaksky    - use skylines to tweak the intial wavelength 
                 solution
   plugcat     - turn this on if you are using specially formated
                 plugcat files for your reductions. If you are not sure, 
                 then you are probably not using these files
   plugfile    - If plugcat is set, then plugfile must be set to the plugcat 
                 file for the reduction
   combine     - Set this to combine the multiple observations. The spectra
                 are extracted and then combined
   fluxcorr    - Set this to flux the data with F star standards
                 NOTE: Fluxing must have at least two observations
   tellcorr    - Set this to telluric correct the data.  You need 
                 standard stars in order for this to work
   uberextract - Set this to turn on tweaksky, fiberflat, skysubtract
                 tellcorr, and fluxcorr. Obivously, you don't want this 
                 if you don't have standards
   rerun       - This should be set to the rerun number you would like to 
                 for the reduction. If not set rerun=0000
   outname     - Root outname you would like to use for the data.  If
                 this is not set, then outname='test'
   qaplot      - Setting this results in the quality assurance plots to be
                 be created
   superfile   - If this is set, the file $HSRED_DIR/etc/superstand.fits
                 instead of typing the stars
   docosmic    - If docosmic is set then the cosmic ray rejection is turned 
                 on.
   checkaverage- This will check the current flux soln against an archival 
                 solution and will truncate the data if the counts of the 
                 standard stars are fewer than 100 
   dostand    - This will provide the standard flags that you need
                 (skyssubtract, fiberflat, tweaksky, combine,
                 writeout, writeall)
 
 OUTPUTS:
      Creates a variety of files (depending on settings) in the 
      /reduction/YYYY/ direcory where YYYY is the rerun

 OPTIONAL OUTPUTS:
   lamout       - the final wavelength map
   fluxout      - the final flux
   ivarout      - the final inverse variance map

 COMMENTS:


 EXAMPLES:

 BUGS:
    The flat field is generated after tracing.  A proper flat field would
    alsop have a 2d component.  There are issues with this.  
   

 REVISION HISTORY:
   April 2004 - Written by R Cool - UofA         
                

(See /home/hsred/idl/hsred/idl/spec2d/hs_extract.pro)


HS_EXTRACT_IMAGE

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_extract_image

 PURPOSE:
   Extract the fiber profile flux for an entire image

 CALLING SEQUENCE:
   extract_image(fimage, invvar, xcen, sigma, flux, [finv, yrow=,
              ymodel=, fscat=, proftype=, ansimage=,
              wfixed=, mask=mask, pixelmask=,  reject=, wsigma=, 
              nPoly=, maxIter=, highrej=, lowrej=,
              fitans=, whopping=, /relative, 
              nband= ])

 INPUTS:
   fimage     - Image [NCOL,NROW]
   invvar     - Inverse variance [NCOL,NROW]
   xcen       - Initial guesses for X centers [NROW,NFIBER]
   sigma      - Input sigma of gaussian profile; default to 1.0 pixels.
                This can be a scalar, an [NFIBER] vector, or
                an [NROW,NFIBER] array.

 OPTIONAL KEYWORDS:
   yrow       - List of row numbers (0-indexed) to extract; default to all.
   proftype   - currently, one can only use 1: Gaussian (scalar)
              - or                          2: Exp Cubic
              - or                          3: Double Gaussian
              - or              4: Exp Cubic with doublewide Gaussian
   wfixed     - array of 1's and zero's which set which parameters are fixed.
                e.g. [1] just gaussian's with fixed width sigma
                     [1, 1] fit gaussian + sigma correction
                     [1, 0, 1] fit gaussian + center correction
                     [1, 1, 1] fit gaussian + sigma and center corrections.   
   mask       - byte mask: 1 is good and 0 is bad [NCOL,NROW] 
   pixelmask  - bits set due to extraction rejection [NROW,NFIBER]
   reject     - Array setting rejection threshholds; defaults are set
                in EXTRACT_ROW().
   nPoly      - order of chebyshev scattered light background; default to 4
   nband      - band-width of full covariance fiber profile matrix;
                default to 1.
   maxIter    - maximum number of profile fitting iterations; default to 20
   highrej    - positive sigma deviation to be rejected (default 10.0)
   lowrej     - negative sigma deviation to be rejected (default 10.0)
   fitans     - ratio of profiles to do in single profile fitting
   relative   - Scale rejection thresholds by reduced chi-squared (default 0)
   whopping   - traces which have WHOPPINGingly high counts, and need extra
                background terms
   wsigma     - sigma width of whopping profile (exponential, default 25)
   oldreject  - ???

 OUTPUTS:
   flux       - Total extracted flux in each profile [nRowExtract,NFIBER]

 OPTIONAL OUTPUTS:
   ansimage   - Coefficients of fit for each row [nCoeff,nRow]
   mask       - Modified by setting the values of bad pixels to 0
   finv       - Estimated inverse variance each profile [nRowExtract,NFIBER]
   ymodel     - Model best fit of row [NCOL,NROW]
   fscat      - Scattered light contribution in each fiber [NROW,NFIBER]
   pimage     - ???
   chisq      - Chi^2 of each row [NROW]

 COMMENTS:

 EXAMPLES:

 PROCEDURES CALLED:
   calcflux
   extract_row()
   pixelmask_bits()
   splog

 REVISION HISTORY:
   08-Aug-1999  Written by Scott Burles, Chicago 
   22-Aug-2000  Added banded-matrix possibility 
   April 2004   Modified slightly for compatability with HS data 
                R Cool U of A - converted to hs_extract_image

(See /home/hsred/idl/hsred/idl/spec2d/hs_extract_image.pro)


HS_EXTRACT_ROW

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_extract_row

 PURPOSE:
   Fit the fiber profiles and background in a single row with least squares

 CALLING SEQUENCE:
   ans = extract_row( fimage, invvar, xcen, sigma, [ymodel=, fscat=, 
              proftype=, wfixed=, inputans=, iback=, bfixarr=, xvar=,
              mask=, relative=, diagonal=, fullcovar=, wfixarr=, npoly=,
              maxiter=, lowrej=, highrej=, niter=, squashprofile=,
              whopping=, wsigma=, pixelmask=, reject=, reducedChi=,
              nBand=  ])

 INPUTS:
   fimage     - Vector [nCol]
   invvar     - Inverse variance [nCol]
   xcen       - Initial guesses for X centers [nFiber]
   sigma      - Sigma of gaussian profile; (scalar or [nFiber])

 OPTIONAL KEYWORDS:
   proftype   - Select profile type:
                  1: Gaussian
                  2: (exponential)^3
                  3: (exponential)^2.5
                Default to 1.
   inputans   - Input fit, excluding background and whopping terms
                [ncoeff*nFiber]
                The array is sorted as follows:
                  [ncoeff] values for fiber #0
                   ...
                  [ncoeff] values for fiber #(nFiber-1)
   relative   - Set to use reduced chi-square to scale rejection threshold
   squashprofile - ???
   npoly      - Order of chebyshev scattered light background; default to 5
   nband      - Band-width of covariance matrix of fiber profiles: default 1
   maxiter    - Maximum number of profile fitting iterations; default to 10
   lowrej     - Negative sigma deviation to be rejected; default to 5
   highrej    - Positive sigma deviation to be rejected; default to 5
   whopping   - X locations to center additional "whopping" terms to describe
                the exponentail tails of flux near bright fibers; default
                to -1, which means not to use any such terms.
   wsigma     - Sigma width for exponential whopping profiles; default to 25
   reject     - Three-element array setting partial and full rejection
                thresholds for profiles; default [0.2, 0.6, 0.6].
                When there is less than REJECT[2] of the area is left,
                  then drop fitting of all higher-order terms.
                When there is less than REJECT[1] of the area is left,
                  then the pixel is rejected (inverse variance is set to 0).
                When there is less than REJECT[0] of the area is left,
                  then assume that there's no fiber there, and don't fit
                  for that fiber at all.

 MODIFIED INPUTS (OPTIONAL):
   wfixed     - Array to describe which parameters to fix in the profile;
                0=fixed, 1=float; default to [1].
                The number of parameters to fit per fiber is determined
                this way; e.g. nCoeff = n_elements(wfixed), so the default
                is to fit only 1 parameter per fiber.  For the (default)
                Gaussian profile, this is the height of the Gaussian.
                Note that WFIXED is used to build the array WFIXARR.
   iback      - 1D array of input background coeff 
                (needed if fixed parameters are non-zero)
   bfixarr    - 1D integer array to specify which terms of the background
                coefficients to fix; 0=fixed, 1=float.
   wfixarr    - 1D integer array to specify which parameters in the full fit
                to fix; 0=fixed, 1=float.
                The array is sorted as follows:
                  [ncoeff] values for fiber #0
                   ...
                  [ncoeff] values for fiber #(nFiber-1)
                  [npoly] values for the background polynomial terms
                  [whoppingct] values for the whopping terms
   xvar       - X values of fimage and invvar; default is findgen(NX).
   mask       - Image mask: 1=good, 0=bad [NX]
   pixelmask  - Bits set for each fiber due to extraction rejection [nFiber]

 OUTPUTS:
   ans        - Output fit [ncoeff*nFiber+npoly+whoppingct]
                The array is sorted as follows:
                  [nFiber] values for coefficient #0
                   ...
                  [nFiber] values for coefficient #(nCoeff-1)
                  [npoly] values for the background polynomial terms
                  [whoppingct] values for the whopping terms
                Note this array is **not** sorted as INPUTANS or WFIXARR!

 OPTIONAL OUTPUTS:
   ymodel     - Evaluation of best fit [nCol]
   fscat      - Scattered light contribution in each fiber [nFiber]
   diagonal   - 1D diagonal of covariance matrix.  Currently, this is
                the diagonal from the Cholesky decompostion, which is
                1/error[j].  [ncoeff*nFiber+npoly+whoppingct]
   fullcovar  - 2D covariance matrix.  This is a symmetric matrix, and we
                only fill the lower triangle.  Computing this increases CPU
                time by a factor of 2 or 3.
   niter      - Number of rejection iterations performed
   reducedChi - Reduced chi ???

 COMMENTS:

 BUGS:
    Still need to do:
       limits on chebyshev polynomial are assumed to be 0.0 <--> nx
       these may need to be optional if only partial rows are being fit

       Error codes need to be returned, currently no such codes are returned

 EXAMPLES:

 PROCEDURES CALLED:
   Dynamic link to extract_row.c

 REVISION HISTORY:
    8-Aug-1999  Written by Scott Burles, Chicago 
    April 2004  Modified for compliance with Hectospec data 
                R. Cool UofA 

(See /home/hsred/idl/hsred/idl/spec2d/hs_extract_row.pro)


HS_FINDWAVE

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_findwave

 PURPOSE:
   Wrapper for the wavelength solution 

 CALLING SEQUENCE:
  hs_findwave, arcname=arcname, rerun=rerun, root=root, arcguess=arcguess

 INPUTS:
   

 OPTIONAL KEYWORDS:
   arcname    - The arc file to find the wavelenth solution from
   rerun      - Rerun number for the reduction - in order to find
                output directory
   root       - Modified Julian date for the arc
   arcguess   - input solution guess - I wouldn't use this

 OUTPUTS:
     Creates a wset for the data

 OPTIONAL OUTPUTS:


 COMMENTS:


 EXAMPLES:

 BUGS:

  
 REVISION HISTORY:
   April 2004 - Written by R Cool - UofA
                adapted from code in Schlegals IDLSPEC2d
                 package

(See /home/hsred/idl/hsred/idl/spec2d/hs_findwave.pro)


HS_FLATTEN

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_flatten

 PURPOSE:
   Create pixel-to-pixel flat-field from a stack of Hectospec spectral flats.

 CALLING SEQUENCE:
   spflatten2, flatname, allflats, [ pixflat, sigrej=, maxiter=, $
    oldflat=, outfile=, indir=, outdir=, tmpdir=, $
    pixspace=, nord=, lower=, upper=, mincounts=, /nodelete ]

 INPUTS:
   flatname   - Name of flat image for tracing arc
  
   allflats   - Name(s) of raw SDSS flat-field image(s).
                Note that many flats from many nights can be combined.

 OPTIONAL INPUTS:
   sigrej     - Sigma rejection level; default to 1, 1, 1.1, 1.3, 1.6 or 1.9
                for 1,2,3,4,5 or 6 flats.  For more then 6 flats, default
                to 2.0.
   maxiter    - Number of rejection iterations; default to 2.
   oldflat    - Name of old flat-field from which to select pixels to mask;
                if not set, then read the masks in this source distribution.
   outfile    - Write the image PIXFLAT to this file.
   indir      - Input directory for FLATNAME; default to current directory
   outdir     - Output directory for OUTFILE; default to current directory
   tmpdir     - Directory for temporary files; default to current directory
   pixspace   - Approximate spacing in pixels for break points in the
                spline fits to individual fibers; default to 50 pixels.
                Note that this spacing need be small enough to fit out
                the flux variations of multiple fibers crossing a single
                column, but it need not fit out the actual flat-field
                variations.
   mincounts  - The summed model image must have a minimum of this many counts
                at each pixel, or the output flat is set to zero for that
                pixel; default to 100 counts.
   nodelete   - If set, then do not delete temporary files.

 PARAMETERS FOR SLATEC_SPLINEFIT:
   nord       - Default to 4
   lower      - Default to 2
   upper      - Default to 2

 OUTPUTS:

 OPTIONAL OUTPUTS:
   pixflat    - Image containing all the information about pixel-to-pixel
                variations.  Illumination variations are removed.

 COMMENTS:
   This program writes 2*nflat temporary files to disk to save internal memory.
   But it still creates an two arrays (FLATARR (float) and OUTMASK (byte))
   that is as large as all of the input flats.
   Thus, if you are using ten 16 MB flat images,
   that array will be 10*(16+4)=200 MB (in addition to a few other images).

   The header contains the number of files used in each camera (NEXP),
   and an identifier for each of those files (EXPID*).  Those identifiers
   contain the camera name, MJD, flat exposure number, and arc exposure
   number, all dash-separated.

 EXAMPLES:

 BUGS:
  Since the traces move around this might night work too well.  This is 
  not a trivial problem as the wavelength solution, and thus the fringe 
  patterns are not continuous fiber-to-fiber. 

  Also, this is very traumatic on the CPU. It is very possible, if the wrong
  settings are used for the memory settings, will crash the computer.

 PROCEDURES CALLED:
   bspline_iterfit()
   bspline_valu()
   calcscatimage()
   djs_avsigclip()
   djs_filepath()
   extract_image
   fileandpath()
   genflatmask()
   readfits()
   repstr()
   rmfile
   sdssproc
   sxaddpar
   sxpar()
   superflat()
   trace320crude()
   traceset2xy
   writefits
   xy2traceset

 REVISION HISTORY:
   13-Oct-1999  Written by D. Schlegel, APO
   April 2004 - Modified hs_spflatten2 to work with HS  data.  
                R Cool U of A

(See /home/hsred/idl/hsred/idl/spec2d/hs_flatten.pro)


HS_FLUXCORR

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_fluxcorr

 PURPOSE:
   Find the fluxing vector for data with F stars

 CALLING SEQUENCE:
   flux_out = hs_fluxcorr, lam1, flux1, ivar1, plugmap1, mask1,
           outname=outname,$
            plateid=plateid, rerun=rerun, psplot=psplot,$
            checkaverage=checkaverage, stand=stand, $
            header=header, cut=cut, superfile=superfile

 INPUTS:
   lam1 = [Nim, Npix, Nfib] wavelength
   flux1 = flux [Nim, Npix, Nfib]
   ivar1 = ivar [Nim, Npix, Nfib]
   plugmap1 = plugmap structure for the data (Nfiber)


 OPTIONAL KEYWORDS:
   rerun   - rerun reductions for the data
   checkaverage - if set, then truncate the spectrum where the 
                  standard stars have fewer than 100 counts.
   superfile    - if set use provided spectral types for the stars
   header       - object hearder

 OUTPUTS:
     fluxout - Fluxing vectors for the data

 OPTIONAL OUTPUTS:


 COMMENTS:


 EXAMPLES:

 REVISION HISTORY:
   April 2004 - Written by R Cool - UofA
                adapted from code in Schlegals IDLSPEC2d
                 package

(See /home/hsred/idl/hsred/idl/spec2d/hs_fluxcorr.pro)


HS_IARCFIT

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
	hs_IARCFIT

 PURPOSE:
	Generate a two dimensional map between pixel position and
	wavelength from an arc calibration lamp.

 CALLING SEQUENCE:
       hs_iarcfit, arc, arcinvvar, wset, xcen, ycen, 
          [datapath=, lamp=, wmapname=], $'
          [row=, nmed_arc=, xcoeff=, dxcoeff=, func_arc=, norder_arc=,
          mintol=], $'
          arclambda=arclambda, xdiff=xdiff, gauss=gauss, $'
          write=write, doplot=doplot'

 INPUTS:
	arc - flux for the arc image
       arcivar - inverse variance for the arc image

 OPTIONAL INPUTS:
       acoeff     - inital guess for the acoeffs
       dcoeff     - window for which the solution will look
	datapath   - path to the data and the WRITE directory
	lamp       - type of comparison lamp (e.g., 'HeAr')
       wmapname   - name of the output wavelength map
       row        - row to use for initial wavelength solution
                    (default to the middle row) 
	nmed_arc   - number of rows to median filter around ROW for
                    initial wavelength solution (default 5)
	xcoeff     - two-element array giving the [starting wavelength
                    (Angstrom), dispersion (Angstrom/pixel)] initial
                    guesses (default [3600.0,2.75])
	dxcoeff    - deviations from XCOEFF (default [50.0,0.1])
	func_arc   - name of fitting function (default 'legendre')
	norder_arc - order of the fit of column number versus
                    wavelength (default 4) 
;	mintol     - minimum tolerance for acceptable arc lines
                    (default 0.2 Angstrom) 
	
 KEYWORD PARAMETERS:
	gauss    - use gaussian profile fitting for final centroid fit
                  (default to flux-weighted centering)
	write    - write the wavelength map and the QA plots to disk
       doplot   - generate QA plots on the screen (will be generated
                  anyway if WRITE=1)

 OUTPUTS:
	wset    - 2D wavelength map (pixel -> lambda)
	xcen    - column pixel positions of arc lines [nrows,nlines] 
	ycen    - row positions of arc lines [nrows,nlines]

 OPTIONAL OUTPUTS:
	arclambda - wavelengths of good lamp lines (Angstrom)
	xdiff     - residuals of fitted lamp lines to fitted positions
                   (pixels)

 COMMENTS:
       A 2nd order Legendre function is fitted to the row-dependent
       arc line position, while an NORDER_ARC Legendre polynomial is
       fitted in the wavelength dimension.

	Also see FITARCIMAGE in Dave Schlegel's IDLSPEC2D package.

 EXAMPLE:

 PROCEDURES USED:
	RD2DSPEC(), READCOL, IARCFIT_GUESS(), DJS_MEDIAN(),
	TRACE_CRUDE(), FIND_NPEAKS(),  TRACESET2XY(), TRACESET2PIX(),
	XY2TRACESET, TRACE_FWEIGHT(), TRACE_GWEIGHT(), ICLEANUP,
	DFPSPLOT, DFPSCLOSE, CWD(), GET_ELEMENT, CLEANPLOT,
	LINEID_PLOT, DJS_ITERSTAT, ERRPLOT, LEGEND, CMSAVE

 DATA FILES:
	${ISPEC_DIR}/etc/lamphear.dat

 OLD MODIFICATION HISTORY:
	J. Moustakas, 2001 August, U of A
       jm02nov15uofa - added a quality assurance plot
       jm03jan12uofa - added support for a HeNeAr lamp

 MODIFICATION HISTORY:
       J. Moustakas, 2003 April 9, U of A, checked out ISPEC v1.0.0
       jm03dec7uofa - added DEBUG keyword
       April 2004 - Modified for use with Hectospec dat
                    R cool U of A
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(See /home/hsred/idl/hsred/idl/spec2d/hs_iarcfit.pro)


HS_LACOSMIC

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_lacosmic

 PURPOSE:
   Remove cosmic rays from imaging data.  Images must be debiased for
     gain estimation to work properly.

 CALLING SEQUENCE:
   la_cosmic, imlist, [outlist=, masklist=, sigclip=, gain=, readn=, $
               skyval=,objlim=, niter=,sigfrac=,verbose=,statsec=, $
               zeroindexed=,masksuffix=, outsuff=,isbig=,blocksize=]

 INPUTS:
   imlist:     List (strarr) of images to be cleaned or string with
                regexp of files      

 OPTIONAL INPUTS:
   outlist:    List (string array) of output cleaned images
   masklist:   List of mask files associated with the cleaned images
   sigclip     Level of cr clipping
   gain        Gain of the CCD (< 0 to estimate) (default=-1.0)
   readn       Readnoise of CCD (default=0.0)
   skyval      Avg. of sky level already subtracted off the images (array)
   objlim      Detection threshold for objects (not crs)
   niter       How many passes to take
   sigfrac     Sigfrac: see PASP paper
   verbose     Verbose printing of steps? 
   statsec     image region for statistics
                string which can be of the form "[23:45,100:300]" or
                                                 [*,100:400], etc.
   zeroindexed Is the image region zeroindexed?
   masksuffix  Suffix to automatically determine mask output name
   outsuff     Suffix to automatically determine output image name
   blocksize   Size of working blocks.  Keep in integer multiples of 512
   isbig       Tell the routine to chop up the images in to more
                manageable sections of size blocksize x blocksize

 OUTPUTS:

 OPTIONAL OUTPUTS:

 PROCEDURES CALLED:
   DJS_ITERSTAT
   DJS_MEDIAN   
   reckon_statsec
   lacos_replace
   astro-library 

 COMMENTS:
  This routine is based on Pieter Van Dokkum's "LACOSMIC" Cosmic
  ray rejection routine for IRAF.

  If you find that after ~4 iterations that the routine is still
  finding up cosmic rays chances are that you are digging into the
  noise and or objects.  Try setting the sigclip number a bit higher

 DEFAULTS:
   outlist:    This will be set to the input list with the suffix
                outsuffix + '.fits' 
   masklist:   This will be set to the input list with the suffix
                masksuffix + '.fits' 
   sigclip     4.5
   gain        -1.0 (e-/DN) (forces routine to estimate for gain)
   readn       0.0
   skyval      0.0 
   objlim      4.0
   niter       4
   sigfrac     0.5
   verbose     1 (yes)
   statsec     "[*,*]" (use the entire image to estimate the gain)
   zeroindexed 0 (no)
   masksuffix  "-mask"
   outsuff     "-out"
   isbig       0
   blocksize   1024

 NOTES:
    (1) This routine will only work on .fits images 
    (2) Haven't checked how useful it is on spectroscopic images.
    (3) Speed is clearly an issue.  It takes about 21 seconds per iteration
        on a fairly zippy (650 PIII Linux 2.4 kernel) laptop on a
        1k x 1k image.
        Using the isbig=1 the speed should scale as the number of
        pixels. So the scaling for speed is,
 
                t = 21 s * (n/1024)^2 * (cpu/650 MHz)^(-1)

        So that a 2k x 2k image will take ~80s per interation.


 EXAMPLES:
   1. Remove the cosmic rays from a debiased flat-fielded HST STIS/Clear image
   hst1.fits and created a replaced image called hst1-cleaned.fits
   with a mask file called mask.fits. Set the read noise to be 4.46 e-
   and the gain to be = 1.0 (e-/DN)

      IDL> la_cosmic, ['hst1.fits'], masklist=['mask.fits'], $
                      outsuffix="-cleaned", readn=4.46, gain=1.0

   2. Remove the cosmic rays from all images starting with the name
   hst and create masks "hst*-mask.fits" and output images
   "hst*-out.fits". Set sigclip = 4. Let la_cosmic determine the gain
   from a region of [50:100,*] (indexed exactly as in IRAF, ie. unity
   indexed).

      IDL> la_cosmic, 'hst*.fits', outsuffix="-out",
                masksuffix="-mask",statsec="[50:100,*]",zeroindexed=0, 
                gain = -1, sigclip = 4.0

 BUGS:

  1. If the image has not been debiased, then the gain estimation
     will go horribly wrong.  Could add a "biassec" parameter to
     allow the bias to be estimated.
  2. Speed scaling of the routine works well until the point that
     the images are too large to store entirely in memory.  Could write
     a little section which chops up the image in to manageable
     chunks and pastes those chuncks together...

 REVISION HISTORY:
   20-May-2001  Written by Joshua Bloom, Caltech
   (jsb@astro.caltech.edu)
   jm02uofa - some modifications for use in ISPEC

(See /home/hsred/idl/hsred/idl/spec2d/hs_lacosmic.pro)


HS_LOCATESKYLINES

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_locateskylines

 PURPOSE:
   Compute shifts for arc lines used in wavelength calibration.

 CALLING SEQUENCE:
   hs_locateskylines, skylinefile, fimage, ivar, wset, xarc, $
    arcshift=arcshift,
    [ xsky=, ysky=, skywaves=, skyshift= ]

 INPUTS:
   skylinefile - Name of skyline file (with air wavelengths in Angstroms)
   fimage      - Flattened image containing skylines [NPIX,NFIBER]
   ivar        - Inverse variance of FIMAGE
   wset        - Wavelength solution traceset (pix -> lambda)
   xarc        - Arc line positions from arc frame [pix]

 OUTPUTS:
   arcshift    - Shifts to apply to arc lines in pix [NROW,NTRACE]

 OPTIONAL OUTPUTS:
   xsky        - Pixel position of sky lines [NFIBER,NLINE]
   skywaves    - Wavelengths of sky lines used for computing shifts (Ang)
   skyshift    - Shifts to apply to sky lines in pix [NROW,NTRACE]

 COMMENTS:
   The wavelength as a function of fiber number is only allowed to
   vary quadratically.  The scale 

 EXAMPLES:

 BUGS:

 PROCEDURES CALLED:
   djs_iterstat
   fitmeanx()
   trace_fweight()
   trace_gweight()
   traceset2pix()
   traceset2xy
   xy2traceset

 REVISION HISTORY:
   15-Oct-1999  Written by S. Burles, D. Finkbeiner, & D. Schlegel, APO
   18-Nov-1999  Moved skyline QA to fit_skyset (SMB)
   April 2004   Modified for HS compliance
                R Cool U of A

(See /home/hsred/idl/hsred/idl/spec2d/hs_locateskylines.pro)


HS_MAKECALIBS

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_makecalibs

 PURPOSE:
   Complete more calibration steps

 CALLING SEQUENCE:
  hs_biasgen, biasfiles, outdir=outdir, mjd=mjd

 INPUTS:
   biasfiles   - a linst of bias files that are to be comined

 OPTIONAL KEYWORDS:
   outdir     - Output directory for the final combined arc
   mjd        - Integer part of the MJD for the observations
                this will create the outname for the file if
                 in the headers of the file

 OUTPUTS:
      creates the /calibration/XXXX/bias-YYYY.fits file where
      XXXX is the rerun number and YYYY is the MJD

 OPTIONAL OUTPUTS:


 COMMENTS:


 EXAMPLES:

 BUGS:

    Not sure the scaling for the images is appropriate
    is the entrie chip being used or just the illuminated
    region
;
 REVISION HISTORY:
   April 2004 - Written by R Cool - UofA
                adapted from code in Schlegals IDLSPEC2d
                 package

(See /home/hsred/idl/hsred/idl/spec2d/hs_makecalibs.pro)


HS_MAKEFIBERFLAT

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_makefiberflat

 PURPOSE:
   Create a flat field vector for a secondary correction 
   preferably from the sky flats

 CALLING SEQUENCE:
  hs_makefiberflat, usesky=usesky, flatname=flatname, fflat=fflat,
                    rerun=rerun, root=root

 INPUTS:
   

 OPTIONAL KEYWORDS:
   usesky - use the sky flat rather than the dome flats for the 
            correction
   flatfile - file to make the flat vectors from
   rerun - reduction rerun
   root  - integer modified julian date for the observation

 OUTPUTS:
    fiberflat.fits in the calibration/XXXX directory

 OPTIONAL OUTPUTS:
    fflat  - flat fielding vector for the data

 COMMENTS:


 EXAMPLES:

 BUGS:


 REVISION HISTORY:
   April 2004 - Written by R Cool - UofA
                adapted from code in Schlegals IDLSPEC2d
                 package

(See /home/hsred/idl/hsred/idl/spec2d/hs_makefiberflat.pro)


HS_MAKELINKS

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_makelinks

 PURPOSE:
   Link the plugplan to the reduced data

 
 REVISION HISTORY:
   April 2004 - Written by R Cool - UofA
                adapted from code in Schlegals IDLSPEC2d
                 package

(See /home/hsred/idl/hsred/idl/spec2d/hs_makelinks.pro)


HS_MAKESUPERFLAT

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_makesuperflat

 PURPOSE:
   Create a flat field vector for a primary correction 
   preferably from the dome flats

 CALLING SEQUENCE:
  hs_makesuperflat, usesky=usesky, flatname=flatname, fflat=fflat,
                    rerun=rerun, root=root

 INPUTS:
   

 OPTIONAL KEYWORDS:
   usesky - use the sky flat rather than the dome flats for the 
            correction
   flatfile - file to make the flat vectors from
   rerun - reduction rerun
   root  - integer modified julian date for the observation

 OUTPUTS:
    traceflat.fits in the calibration/XXXX directory

 OPTIONAL OUTPUTS:
    fflat  - flat fielding vector for the data

 COMMENTS:


 EXAMPLES:

 BUGS:


 REVISION HISTORY:
   April 2004 - Written by R Cool - UofA
                adapted from code in Schlegals IDLSPEC2d
                 package

(See /home/hsred/idl/hsred/idl/spec2d/hs_makesuperflat.pro)


HS_MAKETRACESET

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_maketraceset

 PURPOSE:
   Create a trace set for hectospec data set

 CALLING SEQUENCE:
  hs_maketraceset, flatfile=flatfile, write=write, xcen=xcen, 
                   tset=tset, xsol=xsol, rerun=rerun, mjd=mjd

 INPUTS:
   

 OPTIONAL KEYWORDS:
   flatfile - file to make the flat vectors from
   write    - Turn on if you want to write the data set out

 OUTPUTS:
    

 OPTIONAL OUTPUTS:

 COMMENTS:


 EXAMPLES:

 BUGS:


 REVISION HISTORY:
   April 2004 - Written by R Cool - UofA
                adapted from code in Schlegals IDLSPEC2d
                 package

(See /home/hsred/idl/hsred/idl/spec2d/hs_maketraceset.pro)


HS_MAPTOPLUG

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_maptoplug

 PURPOSE:
  Create a plugmap structure for the Hectospec generated map files

 CALLING SEQUENCE:
  hs_maptoplug, mapfile, plugmap, ccdnum=ccdnum

 INPUTS:
   mapfile - file to use to create plugmap
   

 OPTIONAL KEYWORDS:
   ccdnum  - ccdnumber to make plugmap for

 OUTPUTS:
    plugmap - output stucture

 OPTIONAL OUTPUTS:


 COMMENTS:


 EXAMPLES:

 BUGS:


 REVISION HISTORY:
   April 2004 - Written by R Cool - UofA
                adapted from code in Schlegals IDLSPEC2d
                 package

(See /home/hsred/idl/hsred/idl/spec2d/hs_maptoplug.pro)


HS_OVERSCAN

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_overscan

 PURPOSE:
   Overscan correct a hectospec frame

 CALLING SEQUENCE:
  hs_overscan, image, head, overscan=overscan, 
              checkoverscan=checkoverscan, $
              norder_overscan=norder_overscan

 INPUTS:
   image - input image
   head  - header for the input file
   

 OPTIONAL KEYWORDS:
   overscan - overscan region for the data
   

 OUTPUTS:
   

 OPTIONAL OUTPUTS:


 COMMENTS:


 EXAMPLES:

 BUGS:

   
 REVISION HISTORY:
   April 2004 - Written by R Cool - UofA
                adapted from code in ISPEC
   

(See /home/hsred/idl/hsred/idl/spec2d/hs_overscan.pro)


HS_PAGE

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_page

 PURPOSE:
   Examine reduced hs data

 CALLING SEQUENCE:
  hs_page, lam, flux, nstart=, plugmap=, ivar=, nsmooth=, xrange=, 

 INPUTS:
  lam,   - wavelength
  flux   -  flux

 OPTIONAL KEYWORDS:
   nstart - starting aperture
   nsmooth - number of pixels to smooth over
   xrange - plotting xrange

 OUTPUTS:

 OPTIONAL OUTPUTS:


 COMMENTS:


 EXAMPLES:

 BUGS:

;
 REVISION HISTORY:
   April 2004 - Written by R Cool - UofA

(See /home/hsred/idl/hsred/idl/spec2d/hs_page.pro)


HS_PAGE_FILE

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_page_file

 PURPOSE:
   Examine reduced hs data

 CALLING SEQUENCE:
  hs_page_file, filename, nstart=, plugmap=, ivar=, nsmooth=, xrange=, 

 INPUTS:
  filename 6   - filename for for the Hectospec data

 OPTIONAL KEYWORDS:
   nstart - starting aperture
   nsmooth - number of pixels to smooth over
   xrange - plotting xrange

 OUTPUTS:

 OPTIONAL OUTPUTS:


 COMMENTS:


 EXAMPLES:

 BUGS:

;
 REVISION HISTORY:
   April 2004 - Written by R Cool - UofA

(See /home/hsred/idl/hsred/idl/spec2d/hs_page_file.pro)


HS_PROC

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_proc

 PURPOSE:
  Read the Hectospec data

 CALLING SEQUENCE:
  hs_proc, infile, ccdnum, image, invvar, header=haeder, indir, $
           pixelmask=, rerun=, root=, docosmic=, 

 INPUTS:
     infile  - file containing image
     ccdnum  - ccdnum of the side of the image you would like
     
 OPTIONAL KEYWORDS:
   rerun = reduction rerun
   root  = reduction MJD
   docosmic - do CR rejection

 OUTPUTS:

   image - output image
   invvar - output inverse variance

 OPTIONAL OUTPUTS:

   header - image header
   pixelmask - badpixel mask

 COMMENTS:
   This code will read the bad pixel mask and bias correct the data
   automatically (as well as trim and overscan)

 EXAMPLES:

 BUGS:

;
 REVISION HISTORY:
   April 2004 - Written by R Cool - UofA

(See /home/hsred/idl/hsred/idl/spec2d/hs_proc.pro)


HS_READCAT

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_readcat

 PURPOSE:
   Read the catalog file in order to match them to the observation

 CALLING SEQUENCE:
  hs_readcat, catname, mapfile, columnnames, colformat

 INPUTS:
    catname - name of input catalog to be matched
    mapfile - name of HS map file to be matched
    columnnames - [ncol] - string array containing the names of column
                           entries.  Note that should match the standard
                           plugcat standards for anything you want to get
                           included in the plugmap.  These are listed in the
                           documentation.
    colformat - [ncol] - Format string for each columns
                         A - string
                         D - Double
                         F - Float
                         I - integer
                         L - Long

 OPTIONAL KEYWORDS:
     comment  - comment string (default to '#')
     skyfile  - file containing catalog of sky locations
     skycolumnnames - same as column names for skies
     skycolformat - same as column names for skies

 OUTPUTS:


 OPTIONAL OUTPUTS:
   plugcat/mapfile_XXXX files which will server as the plugmaps

 COMMENTS:

 EXAMPLES:

 BUGS:

;
 REVISION HISTORY:
   March 2005 - Written by R Cool - UofA

(See /home/hsred/idl/hsred/idl/spec2d/hs_readcat.pro)


HS_READTRACESET

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_readtraceset

 PURPOSE:
  Read in the traceset

 CALLING SEQUENCE:
  hs_readtraceset, ccdnum, xsol, rerun, 

 INPUTS:
  ccdnum - CCD number

 OPTIONAL KEYWORDS:
   rerun - reduction rerun
   
 OUTPUTS:

 OPTIONAL OUTPUTS:
   xsol - traceset xsol

 COMMENTS:


 EXAMPLES:

 BUGS:

;
 REVISION HISTORY:
   April 2004 - Written by R Cool - UofA

(See /home/hsred/idl/hsred/idl/spec2d/hs_readtraceset.pro)


HS_READWSET

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_readwset

 PURPOSE:
   Read in a wset file

 CALLING SEQUENCE:
  hs_readwset,ccdnum, wset=, rerun=, 

 INPUTS:
  ccdnum - side of chip to read

 OPTIONAL KEYWORDS:
  wset = wavelngth solution
  rerun  = reduction rerun

 OUTPUTS:

 OPTIONAL OUTPUTS:


 COMMENTS:


 EXAMPLES:

 BUGS:

;
 REVISION HISTORY:
   April 2004 - Written by R Cool - UofA

(See /home/hsred/idl/hsred/idl/spec2d/hs_readwset.pro)


HS_REDMONSTER

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_redmonster

 PURPOSE:
   Search for the Red Monster (contiguous region of bad sky residuals),
   and set a pixelmask bit.

 CALLING SEQUENCE:
   hs_redmonster, relloglam, relchi2, 
                 [ objloglam, filtsz=, thresh=, pixelmask= ]

 INPUTS:
   relloglam  - Log10(Angstroms) for RELCHI2 vector
   relchi2    - Relative chi^2 vector from sky fiber residuals

 OPTIONAL INPUTS:
   objlogam   - Log10(Angstroms) image for object frame [NPIX,NFIBER];
                required input for modifying PIXELMASK
   filtsz     - Filter size for looking for Red Monster; default to 25 pix
   thresh     - Treshold in relative chi^2 for identifying REDMONSTER;
                in the pixel mask; default to 4.0.
   pixelmask  - If this and OBJLOGLAM are specified, then add the REDMONSTER
                bit to this mask [NPIX,NFIBER]

 OUTPUTS:
   pixelmask  - (Modified.)

 COMMENTS:

 EXAMPLES:

 BUGS:

 PROCEDURES CALLED:
   pixelmask_bits()
   splog

 REVISION HISTORY:
   14-Mar-2001  Written by D. Schlegel, Princeton

(See /home/hsred/idl/hsred/idl/spec2d/hs_redmonster.pro)


HS_REDUCE1D

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_reduce1d

 PURPOSE:
   1-D reduction of spectra from 1 plate

 CALLING SEQUENCE:
   hs_reduce1d, platefile, wavemin=wavemin, wavemax=wavemax, rerun=rerun, 
                pseudoflux=pseudoflux

 INPUTS:

 OPTIONAL INPUTS:
   platefile  - Plate file(s) from spectro-2D; default to all files
                matching 'spPlate*.fits'
   wavemin    - Minimum wave to use in the redshift
   wavemax    - maximum wave to use in the redshift algorithm
   rerun      - reduction rerun
   pseudoflux - apply an averaged vector if the data is not fluxed

 OUTPUTS:

 OPTIONAL OUTPUTS:

 COMMENTS:
   Names of output files are derived from PLATEFILE.
   For example, if PLATEFILE='spHect-0306-51690.fits', then
     ZALLFILE = 'spZall-0306-51690.fits'
     ZBESTFILE = 'spZbest-0306-51690.fits'

 EXAMPLES:

 BUGS:

 DATA FILES:
   $IDLSPEC2D_DIR/templates/TEMPLATEFILES

 PROCEDURES CALLED:
   cpbackup
   dfpsclose
   dfpsplot
   elodie_best()
   filter_thru()
   mrdfits()
   mwrfits
   qaplot_fcalibvec
   splog
   skymask()
   speclinefit
   struct_addtags()
   sxaddpar
   sxdelpar
   sxpar()
   synthspec()
   vdispfit
   zfind()
   zrefind()

 REVISION HISTORY:
   28-Jun-2000  Written by D. Schlegel, Princeton

(See /home/hsred/idl/hsred/idl/spec1d/hs_reduce1d.pro)


HS_REDUCE2D

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_reduce2d

 PURPOSE:
   Run the 2d reduction pipeline

 CALLING SEQUENCE:
  hs_reduce2d, plugplan=, write=, checkaverage=, docosmic=, superfil=, 

 INPUTS:
  Uses the cal.list file to do the reductions

 OPTIONAL KEYWORDS:
  plugplan - translation file for the reductions
  checkaverage - same as in hs_extract
  docosmic - same as in hs_extract
  superfile - same as in hs_extract

 OUTPUTS:

 OPTIONAL OUTPUTS:


 COMMENTS:


 EXAMPLES:

 BUGS:

;
 REVISION HISTORY:
   April 2004 - Written by R Cool - UofA

(See /home/hsred/idl/hsred/idl/spec2d/hs_reduce2d.pro)


HS_REDUCE2D_NOFLUX

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_reduce2d_noflux

 PURPOSE:
   Run the 2d reduction pipeline without fluxing

 CALLING SEQUENCE:
  hs_reduce2d_noflux, plugplan=, write=, checkaverage=, docosmic=, superfil=,

 INPUTS:
  Uses the cal.list file to do the reductions

 OPTIONAL KEYWORDS:
  plugplan - translation file for the reductions
  checkaverage - same as in hs_extract
  docosmic - same as in hs_extract
  superfile - same as in hs_extract

 OUTPUTS:

 OPTIONAL OUTPUTS:


 COMMENTS:


 EXAMPLES:

 BUGS:

;
 REVISION HISTORY:
   April 2004 - Written by R Cool - UofA

(See /home/hsred/idl/hsred/idl/spec2d/hs_reduce2d_noflux.pro)


HS_SCALE

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_scale

 PURPOSE:
   Find the scales for the fibers based on sky lines

 CALLING SEQUENCE:
  hs_scale, lam, flux, scale=, 

 INPUTS:
    lam - Input wavelenth [npix, nfib]
    flux - input flux [npix, nfib]

 OPTIONAL KEYWORDS:
  

 OUTPUTS:


 OPTIONAL OUTPUTS:
   scale = scale for each of the fibers

 COMMENTS:

 EXAMPLES:

 BUGS:

;
 REVISION HISTORY:
   April 2004 - Written by R Cool - UofA

(See /home/hsred/idl/hsred/idl/spec2d/hs_scale.pro)


HS_SCALETOSKY

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_scaletosky

 PURPOSE:
   Find the scales for the fibers based on sky lines - alternate method

 CALLING SEQUENCE:
  hs_scale, lam, flux, scale=, 

 INPUTS:
    lam - Input wavelenth [npix, nfib]
    flux - input flux [npix, nfib]

 OPTIONAL KEYWORDS:
  

 OUTPUTS:


 OPTIONAL OUTPUTS:
   scale = scale for each of the fibers

 COMMENTS:

 EXAMPLES:

 BUGS:

;
 REVISION HISTORY:
   April 2004 - Written by R Cool - UofA

(See /home/hsred/idl/hsred/idl/spec2d/hs_scaletosky.pro)


HS_SFLATGEN

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_sflatgen

 PURPOSE:
   Create a super sflat image from all of the single sflat images

 CALLING SEQUENCE:
  hs_sflatgen, sflatfiles, outdir=outdir, mjd=mjd

 INPUTS:
   sflatfiles   - a linst of sflat files that are to be comined

 OPTIONAL KEYWORDS:
   outdir     - Output directory for the final combined arc
   mjd        - Integer part of the MJD for the observations
                this will create the outname for the file if
                 in the headers of the file

 OUTPUTS:
      creates the /calibration/XXXX/dflat-YYYY.fits file where
      XXXX is the rerun number and YYYY is the MJD

 OPTIONAL OUTPUTS:


 COMMENTS:


 EXAMPLES:

 BUGS:

    Not sure the scaling for the images is appropriate
    is the entrie chip being used or just the illuminated
    region
;
 REVISION HISTORY:
   April 2004 - Written by R Cool - UofA
                adapted from code in Schlegals IDLSPEC2d
                 package

(See /home/hsred/idl/hsred/idl/spec2d/hs_sflatgen.pro)


HS_SKYSUBTRACT

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_skysubtract

 PURPOSE:
   Sky-subtract an image and modify the variance

 CALLING SEQUENCE:
   hs_skystruct = skysubtract(objflux, objivar, plugsort, wset, 
    objsub, objsubivar, $
    [ iskies= , fibermask=, nord=, upper=, lower=, maxiter=, pixelmask=, $
    dispset=, /novariance, relchi2struct=, npoly=, tai=, newmask=, sset= ])

 INPUTS:
   objflux    - Image flux [NPIX,NFIBER]
   objivar    - Inverse variance for OBJFLUX [NPIX,NFIBER]
   plugsort   - Plugmap structure trimmed to one element per fiber [NFIBER]
   wset       - Structure with traceset of wavelength solution

 OPTIONAL KEYWORDS:
   fibermask  - Fiber status bits, set nonzero for bad status [NFIBER]
   pixelmask  - Mask of 0 for good pixels [NPIX,NFIBER]
   thresh     - Treshold in relative chi^2 for identifying BADSKYCHI in;
                the pixel mask.  Default to 4.0, and pass this value to
                the REDMONSTER function.
   dispset    - Dispersion trace-set; if present, then solve for the
                super-sky vector using a variable PSF described by this
                structure.
   novariance - Set keyword to prevent variance correction for sky residuals
   relchi2struct- Structure containing information of chi^2 fitting
   npoly      - Polynomial order of 2d fit.
   tai        - TAI of plate exposure, if supplied a linear airmass correction
                  is applied
   nbkpt      - Number of bkpts to use for full sky spectrum fit.
                This gives us the freedom to use less points for the blue side
 PARAMETERS FOR SLATEC_SPLINEFIT (for supersky fit):
   nord       -
   upper      -
   lower      -
   maxiter    -

 OUTPUTS:
   skystruct  - structure containing sorted sky wavelengths,flux,fluxivar
                      +  bkpts and coeffs from fitting
   objsub     - Image (OBJFLUX) after sky-subtraction
   objsubivar - Inverse variance (OBJIVAR) after sky-subtraction

 OPTIONAL OUTPUTS:
   iskies     - Indices of good sky fibers
   newmask    - Modified version of PIXELMASK,
   sset       - B-spline structure for supersky.

 COMMENTS:
   Construct a "supersky" spectrum by spline-fitting the (good) sky fibers,
   resampling this at every wavelength in the extracted image, then
   subtracting.  We then measure the variance of the sky-subtracted sky
   fibers in terms of chi^2.  Wherever chi^2 > 1, we increase the variance
   of all fibers such that chi^2=1 in the sky fibers.

 EXAMPLES:

 BUGS:

 PROCEDURES CALLED:
   bspline_iterfit()
   bspline_valu()
   gauss_kernel()
   pixelmask_bits()
   redmonster
   splog
   tai2airmass()
   traceset2xy

 REVISION HISTORY:
   16-Sep-1999  Written by S. Burles, APO
   30-Dec-1999  Modified by D. Schlegel, Princeton
    4-Oct-2000  Changed to bspline_iterfit 
   26-Jul-2001  Implemented Higher-order fits, if dispset is set it fits
                  against fiber number (I know this doesn't make sense)
                Also upped the tolerance on rejection by 5 times!
                Too many pixels were masked for high order fit!

(See /home/hsred/idl/hsred/idl/spec2d/hs_skysubtract.pro)


HS_SNR

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_snr

 PURPOSE:
   Create the signal to noise plot for a file

 CALLING SEQUENCE:
  hs_snr, lam, flux, plugmap, sn2=sn2, noplot=noplot, snr=snr

 INPUTS:
    lam = lam [npix,nfib]
    flux = flux [npix, nfib]
    plugmap = plugmap [nfib]

 OPTIONAL KEYWORDS:
   

 OUTPUTS:
   
 OPTIONAL OUTPUTS:
   sn2 = critical signal to noise for the observation
   snr = output signal to noise for each of the fiber

 COMMENTS:


 EXAMPLES:

 BUGS:

;
 REVISION HISTORY:
   April 2004 - Written by R Cool - UofA
                adapted from code in Schlegals IDLSPEC2d
                 package

(See /home/hsred/idl/hsred/idl/spec2d/hs_snr.pro)


HS_SNR_FILE

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_snr_file

 PURPOSE:
   Create the signal to noise plot for a file

 CALLING SEQUENCE:
  hs_snr_file, file, sn2=, noplot=, snr=, 

 INPUTS:
    file  - file to do the snr calculation on

 OPTIONAL KEYWORDS:
   noplot - don't do the plots

 OUTPUTS:
   
 OPTIONAL OUTPUTS:
   sn2 = critical signal to noise for the observation
   snr = output signal to noise for each of the fiber

 COMMENTS:


 EXAMPLES:

 BUGS:

;
 REVISION HISTORY:
   April 2004 - Written by R Cool - UofA
                adapted from code in Schlegals IDLSPEC2d
                 package

(See /home/hsred/idl/hsred/idl/spec2d/hs_snr_file.pro)


HS_SNR_HIST

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_snr_hist

 PURPOSE:
   Create the signal to noise histogram for the data

 CALLING SEQUENCE:
  hs_snr_file, lam, flux, plugmap

 INPUTS:
    lam - wavelength [npix, nfib]
    flux - flux [npix,nfib]
    plugmap - plugmap [ nfib]

 OPTIONAL KEYWORDS:


 OUTPUTS:
   
 OPTIONAL OUTPUTS:

 COMMENTS:


 EXAMPLES:

 BUGS:

;
 REVISION HISTORY:
   April 2004 - Written by R Cool - UofA
                adapted from code in Schlegals IDLSPEC2d
                 package

(See /home/hsred/idl/hsred/idl/spec2d/hs_snr_hist.pro)


HS_SNR_SKY

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_snr_sky

 PURPOSE:
   Create the signal to noise plot for a file

 CALLING SEQUENCE:
  hs_snr_sky, lam, flux, plugmap

 INPUTS:
    lam = lam [npix,nfib]
    flux = flux [npix, nfib]
    plugmap = plugmap [nfib]

 OPTIONAL KEYWORDS:
   

 OUTPUTS:
   
 OPTIONAL OUTPUTS:
  

 COMMENTS:


 EXAMPLES:

 BUGS:

;
 REVISION HISTORY:
   April 2004 - Written by R Cool - UofA
                adapted from code in Schlegals IDLSPEC2d
                 package

(See /home/hsred/idl/hsred/idl/spec2d/hs_snr_sky.pro)


HS_TELLURIC_CORR

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_telluric_corr

 PURPOSE:
   Use SPECTROPHOTO and REDDEN_STD's to fit telluric features.

 CALLING SEQUENCE:
   hs_telluric_factor = telluric_corr(flux, fluxivar, wset, plugsort, $
    fibermask=, tellbands=, ncoeff=, pixspace=, /dospline, $
    nord=, upper=, lower=, plottitle=

 INPUTS:
   flux         - Sky-subtracted extracted spectra [NX,NTRACE]
   fluxivar     - Inverse variance for FLUX [NX,NTRACE]
   wset         - Wavelength coefficients as a trace set
   plugsort     - Plugmap entries

 OPTIONAL KEYWORDS:
   fibermask  - Fiber status bits, set nonzero for bad status [NFIBER]
   tellbands  - Structure array defining the telluric bands and the
                wavelengths used to fit the continuum.  If not set,
                then default values are used.  See the code for the
                definition of this structure.
   ncoeff     - Number of coefficients used in constructing continuum;
                default to 4.
   pixspace   - Approximate spacing in pixels for break points in the
                spline fits to individual fibers; default to 10 pixels.
   dospline   - If this keyword is set, then fit the continuum
                to splines (using PIXSPACE) rather than to a Legendre
                polynomial (using NCOEFF).
   plottitle  - Title for QA plot; if not set, then do not plot.

 PARAMETERS FOR SLATEC_SPLINEFIT:
   nord
   upper
   lower

 OUTPUTS:
   telluric_factor - Telluric correction for each pixel in flux array;
                     set to 1 where there is no correction.

 OPTIONAL OUTPUTS:

 COMMENTS:
   Objects that are SPECTROPHOTO_STD or REDDEN_STD (as listed in the plugmap
   structure) are selected for constructing the telluric-correction factor.

 EXAMPLES:

 BUGS:
   Other fainter telluric bands at [7178,7212], [8130,8206].

 PROCEDURES CALLED:
   djs_oplot
   djs_plot
   djs_reject()
   fibermask_bits()
   func_fit()
   bspline_valu()
   bspline_iterfit()
   splog
   traceset2xy

 REVISION HISTORY:
   19-Oct-1999  Written by S. Burles, Chicago
   15-Aug-2000  Major modifications by D. Schlegel to fit all telluric
                bands with one spline, and to do this fit on the spectra
                before flux-correction.

(See /home/hsred/idl/hsred/idl/spec2d/hs_telluric_corr.pro)


HS_TRIM

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_trim

 PURPOSE:
   trim an image

 CALLING SEQUENCE:
  hs_trime, image, header=, trim=, immask=, 

 INPUTS:
   image = image to be trimmed

 OPTIONAL KEYWORDS:
   header = image header
   trim   - trim section
   immask - image mask

 OUTPUTS:
   
 OPTIONAL OUTPUTS:
  


 COMMENTS:


 EXAMPLES:

 BUGS:

;
 REVISION HISTORY:
   April 2004 - Written by R Cool - UofA
                adapted from code in Schlegals IDLSPEC2d
                 package

(See /home/hsred/idl/hsred/idl/spec2d/hs_trim.pro)


HS_TWEAKSKY

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_tweaksky

 PURPOSE:
   Tweak the wavelength solution based on sky lines

 CALLING SEQUENCE:
  hs_tweaksky, flux, fluxivar, wset, ccdnum=, ariset=, xsky=, rerun=, 
               filename=, skywaves=, arcshift=, 
 INPUTS:
   flux = flux [npix, nfib]
   fluxivar = inverse varriance [npix, nfib]
   wset  = input wavelenth solution

 OPTIONAL KEYWORDS:
  xsky  - location of skylines
  ccdnum - side of ccd working with
  filename  - output file name for tweaks
  skywaves - wavelength of skylines

OUTPUTS:
   
 OPTIONAL OUTPUTS:
  airset = output solution set
  skyshift - shifts needed to be applied to the skylines

 COMMENTS:


 EXAMPLES:

 BUGS:

;
 REVISION HISTORY:
   April 2004 - Written by R Cool - UofA
                adapted from code in Schlegals IDLSPEC2d
                 package

(See /home/hsred/idl/hsred/idl/spec2d/hs_tweaksky.pro)


HS_WAVECAL

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   hs_wavecal

 PURPOSE:
   Determine wavelength calibration from arclines

 CALLING SEQUENCE:
   hs_wavecal, arc, arcivar, xcen, ycen, wset, [wfirst=, $
    color=color, lampfile=lampfile, fibermask=fibermask, $
    func=func, aset=aset, ncoeff=ncoeff, lambda=lambda, $
    thresh=thresh, row=row, nmed=nmed, /gauss, $
    xdif_tset=xdif_tset, bestcorr=bestcorr , ccdnum=, arcguess=arcguess

 INPUTS:
   arc        - Extracted arc spectra with dimensions [NY,NFIBER]
   arcivar    - Inverse variance of ARC

 OPTIONAL KEYWORDS:
   color      - 'red' or 'blue'; not required if ANS is set
   lampfile   - Name of file describing arc lamp lines;
                default to the file 'lamphgcdne.dat' in $IDLSPEC2D_DIR/etc.
   fibermask  - Fiber status bits, set nonzero for bad status [NFIBER]
   func       - Name of fitting function; default to 'legendre'
   aset       - Trace set for initial wavelength solution in row number ROW.
   ncoeff     - Number of coefficients in fits.  This may be different than
                the number of coefficients in the initial guess ASET.
                Default to 5.
   thresh     - Threshhold counts for significant lines;
                default to 200 if COLOR='blue' or 500 if COLOR='red'
   row        - Row to use in initial guess of wavelength solution;
                default to (NFIBER-30)/2
   nmed       - Number of rows around ROW to median filter for initial
                wavelengths solution; default to 5
   maxdev     - max deviation in log lambda to allow (default 1.0e-5=7 km/s)
   gauss      - Use gaussian profile fitting for final centroid fit

   parity     - Even or odd?

   ccdnum     - CCD number

 OUTPUTS:
   aset       - (Modified)
   xcen       - pixel position of lines [nfiber, nlambda]
   ycen       - fiber number [nfiber, nlambda]
   wset       - traceset (pix -> lambda)

 OPTIONAL OUTPUTS:
   lampfile   - Modified from input to include full path name of file
   lambda     - Returns wavelengths of good lamp lines [Angstroms]
   fibermask  - (Modified)
   xdif_tset  - Fit residual of lamp lines to fit positions [pixels]
   bestcorr   - Correlation coefficient with simulated arc spectrum
   wfirst     - traceset from first iteration on arc fits

 COMMENTS:
   Return from routine after computing BESTCORR if XCEN, YCEN and WSET
   are not to be returned.

 EXAMPLES:

 BUGS:


 PROCEDURES CALLED:
   arcfit_guess()
   djs_median
   djsig()
   fibermask_bits()
   trace_crude()
   trace_fweight()
   traceset2pix()
   traceset2xy()
   xy2traceset

 DATA FILES:
   $IDLSPEC2D_DIR/etc/lamphgcdne.dat

 REVISION HISTORY:
   15-Oct-1999  Written by S. Burles, D. Finkbeiner, & D. Schlegel, APO.
   09-Nov-1999  Major modifications by D. Schlegel, Ringberg.
   20-Jan-2000  Gone back to very simple procedure: replacement (S. Burles)
   April 2004 - Modified for HS data - 
                R Cool U of A

(See /home/hsred/idl/hsred/idl/spec2d/hs_wavecal.pro)


IARCFIT

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
	IARCFIT

 PURPOSE:
	Generate a two dimensional map between pixel position and
	wavelength from an arc calibration lamp.

 CALLING SEQUENCE:
       iarcfit, arcfile, wset, xcen, ycen, [datapath=, lamp=, wmapname=], $'
          [row=, nmed_arc=, xcoeff=, dxcoeff=, func_arc=,
          norder_arc=, mintol=], $
          arclambda=arclambda, xdiff=xdiff, gauss=gauss, $
          write=write, doplot=doplot'

 INPUTS:
	arcfile  - arc lamp FITS file from which to derive the
                  wavelength map

 OPTIONAL INPUTS:
	datapath   - path to the data and the WRITE directory
	lamp       - type of comparison lamp (e.g., 'HeAr')
       wmapname   - name of the output wavelength map
       row        - row to use for initial wavelength solution
                    (default to the middle row) 
	nmed_arc   - number of rows to median filter around ROW for
                    initial wavelength solution (default 5)
	xcoeff     - two-element array giving the [starting wavelength
                    (Angstrom), dispersion (Angstrom/pixel)] initial
                    guesses (default [3600.0,2.75])
	dxcoeff    - deviations from XCOEFF (default [50.0,0.1])
	func_arc   - name of fitting function (default 'legendre')
	norder_arc - order of the fit of column number versus
                    wavelength (default 4) 
	mintol     - minimum tolerance for acceptable arc lines
                    (default 0.2 Angstrom) 
	
 KEYWORD PARAMETERS:
	gauss    - use gaussian profile fitting for final centroid fit
                  (default to flux-weighted centering)
	write    - write the wavelength map and the QA plots to disk
       doplot   - generate QA plots on the screen (will be generated
                  anyway if WRITE=1)

 OUTPUTS:
	wset    - 2D wavelength map (pixel -> lambda)
	xcen    - column pixel positions of arc lines [nrows,nlines] 
	ycen    - row positions of arc lines [nrows,nlines]

 OPTIONAL OUTPUTS:
	arclambda - wavelengths of good lamp lines (Angstrom)
	xdiff     - residuals of fitted lamp lines to fitted positions
                   (pixels)

 COMMENTS:
       A 2nd order Legendre function is fitted to the row-dependent
       arc line position, while an NORDER_ARC Legendre polynomial is
       fitted in the wavelength dimension.

	Also see FITARCIMAGE in Dave Schlegel's IDLSPEC2D package.

 EXAMPLE:

 PROCEDURES USED:
	RD2DSPEC(), READCOL, IARCFIT_GUESS(), DJS_MEDIAN(),
	TRACE_CRUDE(), FIND_NPEAKS(),  TRACESET2XY(), TRACESET2PIX(),
	XY2TRACESET, TRACE_FWEIGHT(), TRACE_GWEIGHT(), ICLEANUP,
	DFPSPLOT, DFPSCLOSE, CWD(), GET_ELEMENT, CLEANPLOT,
	LINEID_PLOT, DJS_ITERSTAT, ERRPLOT, LEGEND, CMSAVE

 DATA FILES:
	${ISPEC_DIR}/etc/lamphear.dat

 OLD MODIFICATION HISTORY:
	J. Moustakas, 2001 August, U of A
       jm02nov15uofa - added a quality assurance plot
       jm03jan12uofa - added support for a HeNeAr lamp

 MODIFICATION HISTORY:
       J. Moustakas, 2003 April 9, U of A, checked out ISPEC v1.0.0
       jm03dec7uofa - added DEBUG keyword

(See /home/hsred/idl/hsred/idl/spec2d/hs_arcfit.pro)


ICLEANUP

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       ICLEANUP

 PURPOSE:
       Free RD2DSPEC() structure pointer and array memory. 

 CALLING SEQUENCE:
       icleanup, cube, main=main

 INPUTS:
       cube - data cube from RD2DSPEC()

 KEYWORD PARAMETERS:
       main - call RETALL

 OUTPUTS:
       None.

 PROCEDURES USED:

 EXAMPLE:

 OLD MODIFICATION HISTORY:
       J. Moustakas, 2001 August 23, U of A, written

 MODIFICATION HISTORY:
       J. Moustakas, 2003 April 9, U of A, checked out ISPEC v1.0.0
       jm03dec8uofa - added SKY structure entry

(See /home/hsred/idl/hsred/idl/spec2d/icleanup.pro)


LACOS_REPLACE, ARR, REPVAL, LOW, HIGH

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   lacos_replace, arr, repval, low, high 

 PURPOSE:
  replace pixels whose value are between low and high with value = repval
  modelled after IRAF (!) IMREPLACE

 CALLING SEQUENCE:
     lacos_replace, arr, repval, low, high

 INPUTS:
   arr:       number array of any size or dimension.
   repval     valid replacment value
   low,high   bracket values to replace (can be 'INDEF') to replace all

 OUTPUTS:
   returns the array = arr but with the replaced pixels

 PROCEDURES CALLED:

 COMMENTS:

 NOTES:
 BUGS:

 REVISION HISTORY:
   20-May-2001  Written by Joshua Bloom, Caltech (jsb@astro.caltech.edu)

(See /home/hsred/idl/hsred/idl/spec2d/hs_lacosmic.pro)


QAPLOT_ARCLINE

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   qaplot_arcline

 PURPOSE:
   Generate QA plot for arcline fits

 CALLING SEQUENCE:
   qaplot_arcline, xdif, lambda, [color=, fibermask=, title=]

 INPUTS:
   xdif       - Deviations in arc line fits in pixels, array [NFIBER, NLAMP]
   lambda     - Wavelength for each lamp in Angstroms, vector [NLAMP]

 OPTIONAL KEYWORDS:
   color      - Specify 'blue' or 'red' to fix plotting limits
   fibermask  - Fiber status bits, set nonzero for bad status [NFIBER]
   title      - TITLE of plot

 OUTPUTS:

 OPTIONAL OUTPUTS:

 COMMENTS:
   Skip over bad fibers in plots.

 EXAMPLES:

 BUGS:

 PROCEDURES CALLED:
   djs_iterstat
   djs_oplot
   djs_plot
   errplot
   fibermask_bits()
   traceset2xy
   splog

 REVISION HISTORY:
   15-Oct-1999  Written by D. Finkbeiner, APO
   23-Nov-1999  Modified by D. Schlegel, Princeton

(See /home/hsred/idl/hsred/idl/spec2d/hs_qaplot_arcline.pro)


QAPLOT_FCALIBVEC

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   qaplot_fcalibvec

 PURPOSE:
   Generate QA plot: apparent flux-calibration errors

 CALLING SEQUENCE:
   qaplot_fcalibvec, loglam, objflux, objivar, synflux, plugmap, zans, $
    [plottitle= ]

 INPUTS:
   loglam     - Wavelengths in log-10(Angstroms) [NPIX]
   objflux    - Object flux [NPIX,NOBJ]
   objivar    - Object inverse variance [NPIX,NOBJ]
   synflux    - Best-fit model flux [NPIX,NOBJ]
   plugmap    - Plug-map structure [NOBJ]
   zans       - Structure with redshift-fit information [NOBJ]

 OPTIONAL KEYWORDS:
   plottitle  - TITLE of plot

 OUTPUTS:
   Output plots only

 OPTIONAL OUTPUTS:

 COMMENTS:
   Plot the ratio of the observed spectra divided by the best-fit
   model spectra as a function of observed wavelength.  Deviations
   from unity are an empirical measure of the flux-calibration errors.

 EXAMPLES:

 BUGS:

 PROCEDURES CALLED:
   djs_maskinterp()
   djs_oplot
   djs_xyouts

 REVISION HISTORY:
   26-Feb-2002 Written by D. Schlegel, Princeton

(See /home/hsred/idl/hsred/idl/spec1d/hs_qaplot_fcalibvec.pro)


QAPLOT_FFLAT

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   qaplot_fflat

 PURPOSE:
   Generate QA plot for fiber-flats

 CALLING SEQUENCE:
   qaplot_fflat, fflat, wset, [ fibermask=, dx=, title= ]

 INPUTS:
   fflat      - Array of flat-field flat-field vectors for each fiber
                that remove relative flat-field variations as a function
                of wavelength between fibers [Nrow, Ntrace]
   wset       - Wavelength solution

 OPTIONAL KEYWORDS:
   fibermask  - Fiber status bits, set nonzero for bad status [NFIBER]
   dx         - Bin log-lambda by this number; default to 1.e-3 (about 10 pix)
   title      - TITLE of plot

 OUTPUTS:

 OPTIONAL OUTPUTS:

 COMMENTS:
   Do not plot bad fibers or masked pixels in good fibers.

 EXAMPLES:

 BUGS:

 PROCEDURES CALLED:
   djs_oplot
   djs_plot
   fibermask_bits()
   traceset2xy

 REVISION HISTORY:
   23-Nov-1999  Written by D. Schlegel, Princeton

(See /home/hsred/idl/hsred/idl/spec2d/hs_qaplot_fflat.pro)


QAPLOT_SKYLINE

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   qaplot_skyline

 PURPOSE:
   Generate QA plots for flux in particular skylines

 CALLING SEQUENCE:
   qaplot_skyline, lwave, obj, objivar, objsub, objsubivar, plugsort, wset, $
    tai=, [fibermask=, dwave=, title= ]

 INPUTS:
   lwave      -
   obj        - Image
   objivar    - Inverse variance for OBJ
   objsub     - Image after sky-subtraction
   objsubivar - Inverse variance for image after sky-subtraction
   plugsort   - Plugmap structure trimmed to one element per fiber
   wset       - Wavelength solution
   tai        - TAI time for computing airmass or elevation for each fiber

 OPTIONAL KEYWORDS:
   fibermask  - Fiber status bits, set nonzero for bad status [NFIBER]
   dwave      - Half-width about LWAVE for fitting sky line;
                default to 5.0 Ang
   titel      - File name to use for TITLE of plot

 OUTPUTS:

 OPTIONAL OUTPUTS:

 COMMENTS:

 EXAMPLES:

 BUGS:

 PROCEDURES CALLED:
   djs_iterstat
   djs_median
   djs_oplot
   splog
   tai2airmass()
   traceset2xy

 INTERNAL SUPPORT ROUTINES:

 REVISION HISTORY:
   01-Jan-2000  Written by D. Schlegel, Princeton

(See /home/hsred/idl/hsred/idl/spec2d/hs_qaplot_skyline.pro)


QAPLOT_SKYSHIFT

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   qaplot_skyshift

 PURPOSE:
   Generate QA plot: scatter in sky line positions

 CALLING SEQUENCE:
   qaplot_skyshift, wset, xsky, skywaves, skyshift, [title= ]

 INPUTS:
   wset       - Wavelength solution from arc line spectra
   xsky       - Pixel position of sky lines [NFIBER,NLINE]
   skywaves   - Wavelengths of sky lines used for computing shifts (Ang)
   skyshift   - Shifts to apply to sky lines in pix [NROW,NTRACE]

 OPTIONAL KEYWORDS:
   title      - TITLE of plot

 OUTPUTS:
   Output plots only

 OPTIONAL OUTPUTS:

 COMMENTS:

 EXAMPLES:

 BUGS:

 PROCEDURES CALLED:
   djs_laxisgen()
   djs_oplot
   djs_plot
   traceset2pix

 REVISION HISTORY:
   11-Apr-2000 Written by D. Schlegel, Princeton

(See /home/hsred/idl/hsred/idl/spec2d/hs_qaplot_skyshift.pro)


QAPLOT_SKYSUB

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   qaplot_skysub

 PURPOSE:
   Generate QA plots for sky-subtraction

 CALLING SEQUENCE:
   qaplot_skysub, obj, objivar, objsub, objsubivar, wset, $
    iskies, [title= ]

 INPUTS:
   obj        - Image
   objivar    - Inverse variance for OBJ
   objsub     - Image after sky-subtraction
   objsubivar - Inverse variance for image after sky-subtraction
   wset       - Wavelength solution
   iskies     - List of good sky fibers

 OPTIONAL KEYWORDS:
   title      - TITLE of plot

 OUTPUTS:

 OPTIONAL OUTPUTS:

 COMMENTS:

 EXAMPLES:

 BUGS:

 PROCEDURES CALLED:
   djs_median
   djs_oplot
   djs_oploterr
   djs_plot
   splog
   traceset2xy

 INTERNAL SUPPORT ROUTINES:
   skyplot

 REVISION HISTORY:
   30-Dec-1999  Written by D. Schlegel, Princeton

(See /home/hsred/idl/hsred/idl/spec2d/hs_qaplot_skysub.pro)


RC_HIST

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   rc_hist

 PURPOSE:
   Creates a histogram for the data give

 CALLING SEQUENCE:
  histstruct= rc_hist( value, min, max, binsize)

 INPUTS:
  value  -  vector to be used to create the histogram
  min    -  minimum value of the array to be used in the histogram
  max    -  maximum value of the array to be used in the histrogram
  binsize - width of the bin to use in the historgam


 OUTPUTS:
  histstuct = stucture with the histogram information included
 
 OPTIONAL OUTPUTS:
 ;

 COMMENTS:


 EXAMPLES:

 BUGS:

 PROCEDURES CALLED:
   readfits()
   sxpar()
   sxaddpar
   writefits
   create_struct

 REVISION HISTORY:
   May 2004 - Written ; Cool UofA

(See /home/hsred/idl/hsred/idl/spec1d/rc_hist.pro)


RC_READFILE

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   rc_readfile

 PURPOSE:
   Will read ascii file into arrays

 CALLING SEQUENCE:
   outarray = rc_readfile(file, nskip, columns=columns)

 INPUTS:
   file   - ascii file to be read
   nskip  - how many lines to skip in the begining

 REQUIRED KEYWORDS:;

 OPTIONAL INPUTS:
  columns -  columns of data (assumes all float).  This doesn't work for 
             strings


 OUTPUTS:
  outarray  - array of file

 OPTIONAL OUTPUTS:


 COMMENTS:


 EXAMPLES:

 BUGS:

 PROCEDURES CALLED:
   readfits()
   sxpar()
   sxaddpar
   writefits

 REVISION HISTORY:
   May 2004 - Written ; Cool UofA

(See /home/hsred/idl/hsred/idl/utils/rc_readfile.pro)


RECKON_STATSEC

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
    reckon_statsec

 PURPOSE:
   parse the statsec string in la_cosmic and return the indices
   which bracket the section to be exaimed.


 CALLING SEQUENCE:
     reckon_statsec,  statstring,arrsize

 INPUTS:
   statstring:  The string such as "[23:34,*]"
   arrsize   :  Array with the x and y sizes of the image

 OUTPUTS:
   returns the indices of the statsec in the form [x1,x2,y1,y2]


 PROCEDURES CALLED:

 COMMENTS:
   A good deal of error checking is done to ensure that
   a statsection will be valid.

 NOTES:
 BUGS:

 REVISION HISTORY:
   20-May-2001  Written by Joshua Bloom, Caltech (jsb@astro.caltech.edu)

(See /home/hsred/idl/hsred/idl/spec2d/hs_lacosmic.pro)


TRACE150CEN

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   trace150cen

 PURPOSE:
   Find the 150 fiber positions for the central row of an image.

 CALLING SEQUENCE:
   xfiber = trace150cen( fimage, [mthresh=, ystart=, nmed=, xgood= ] )

 INPUTS:
   fimage     - Image

 OPTIONAL INPUTS:
   mthresh    - Threshold for peak-finding in convolved row; default to 0.5
                times the dispersion (found with djs_iterstat).
   ystart     - Y position in image to search for initial X centers; default
                to the central row
   nmed       - Number of rows to median filter around YSTART; default to 21

 OUTPUTS:
   xfiber     - Vector of 150 X centers

 OPTIONAL OUTPUTS:
   xgood      - Set to 1 for fibers that were actually found, 0 otherwise

 COMMENTS:

 EXAMPLES:

 PROCEDURES CALLED:
   djs_iterstat

 REVISION HISTORY:
   13-Sep-1999  Written by David Schlegel, Princeton.
   April 2004   Modified to HS data
                R Cool U of A

(See /home/hsred/idl/hsred/idl/spec2d/trace150cen.pro)


TRACE150CRUDE

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
   trace150crude

 PURPOSE:
   Calling script to return 320 full traces using TRACE_CRUDE.

 CALLING SEQUENCE:
   xset = trace150crude( fimage, invvar, [mthresh=, ystart=, nmed=, $
    xmask=, yset=, maxerr=, maxshifte=, maxshift0=, xerr=, maxdev=, ngrow=, $
    fibermask=  ] )

 INPUTS:
   fimage     - Image

 OPTIONAL INPUTS FOR TRACE320CEN:
   mthresh    - Threshold for peak-finding in convolved row; default to 0.5
                times the dispersion (found with djs_iterstat).
   ystart     - Y position in image to search for initial X centers; default
                to the central row
   nmed       - Number of rows to median filter around YSTART; default to 21

 OPTIONAL INPUTS FOR TRACE_CRUDE:
   invvar     - Inverse variance (weight) image
   radius     - Radius for centroiding; default to 3.0
   maxerr     - Maximum error in centroid allowed for valid recentering;
                default to 0.2
   maxshifte  - Maximum shift in centroid allowed for valid recentering;
                default to 0.1
   maxshift0  - Maximum shift in centroid allowed for initial row;
                default to 0.5

 OPTIONAL INPUTS:
   maxdev     - Maximum deviation of X in pixels; default to rejecting any
                XPOS positions that deviate by more than 1.0 pixels from
                a polynomial remapping of the centroids from other rows.
   ngrow      - For each trace, replace all centroids within NGROW rows
                of a bad centroid with the predicted centroid locations.
                Default to 5.
   fibermask  - Fiber status bits, set nonzero for bad status [NFIBER]

 OUTPUTS:
   xset       - X centers for all traces

 OPTIONAL OUTPUTS:
   yset       - Y centers for all traces
   xerr       - Errors for XSET
   xmask      - Mask set to 1 for good fiber centers, 0 for bad;
                same dimensions as XSET.
   fibermask  - (Modified.)

 COMMENTS:
   Without djs_maskinterp, hot columns skew traces 

 EXAMPLES:

 PROCEDURES CALLED:
   djs_maskinterp()
   fibermask_bits()
   trace_crude()
   trace_fweight()
   trace320cen()

 REVISION HISTORY:
   13-Sep-1999  Written by David Schlegel, Princeton.
    8-Jul-2001  Added djs_maskinterp call
    April 2004  Modified for HS data
                R cool

(See /home/hsred/idl/hsred/idl/spec2d/trace150crude.pro)


ZCOMPUTE

[Previous Routine] [List of Routines]
 NAME:
   zcompute

 PURPOSE:
   Compute relative redshift of object(s) vs. eigen-templates.

 CALLING SEQUENCE:
   zans = zcompute(objflux, objivar, starflux, [starmask, nfind=, $
    poffset=, pspace=, pmin=, pmax=, mindof=, width=, minsep=, $
    plottitle=, /doplot, /debug, /verbose ]

 INPUTS:
   objflux    - Object fluxes [NPIXOBJ,NOBJ]
   objivar    - Object inverse variances [NPIXOBJ,NOBJ]
   starflux   - Eigen-template fluxes [NPIXSTAR,NTEMPLATE]

 OPTIONAL INPUTS:
   starmask   - Eigen-template mask; 0=bad, 1=good [NPIXSTAR]
   nfind      - Number of solutions to find per object; default to 1.
   poffset    - Offset between all objects and templates, in pixels.
                A value of 10 indicates that STARFLUX begins ten pixels
                after OBJFLUX, i.e. OBJFLUX[i+10] = STARFLUX[i] for the
                case when the relative redshift should be zero.  If the
                wavelength coverage of the templates is larger, then the
                value of ZOFFSET will always be negative.
                [Scalar or vector of size NOBJ]
   pspace     - The spacing in redshifts to consider; default to 1 [pixels];
                [Scalar or vector of size NOBJ]
   pmin       - The smallest redshift to consider [pixels].
                [Scalar or vector of size NOBJ]
   pmax       - The largest redshift to consider [pixels].
                [Scalar or vector of size NOBJ]
   mindof     - Minimum number of degrees of freedom for a valid fit;
                default to 10.
   width      - Parameter for FIND_NMINIMA(); default to 3 * PSPACE.
   minsep     - Parameter for FIND_NMINIMA(); default to the same as WIDTH.
   plottitle  - Title of plot (if /DOPLOT is set).
   doplot     - If set, then make plots.
   debug      - If set, then wait for keystroke after plot.
   verbose    - If set, then log using SPLOG instead of PRINT.

 OUTPUTS:
   zans       - Output structure [NOBJECT,NFIND] with the following elements:
                z : The relative redshift.
                z_err : Error in the redshift, based upon the local quadratic
                        fit to the chi^2 minimum. 
                chi2 : Fit value for the best (minimum) chi^2
                dof : Number of degrees of freedom, equal to the number of
                      pixels in common between the object and templates
                      minus the number of templates.
                theta : Mixing angles [NTEMPLATE].  These are computed at the
                        nearest integral redshift, e.g. at ROUND(ZOFFSET).

 COMMENTS:
   Fits are done to chi^2/DOF, not to chi^2.

 EXAMPLES:

 BUGS:

 DATA FILES:
   $IDLSPEC2D_DIR/etc/TEMPLATEFILES

 PROCEDURES CALLED:
   computechi2()
   find_nminima()
   splog

 INTERNAL SUPPORT ROUTINES:
   create_zans()

 REVISION HISTORY:
   10-Jul-2000  Written by D. Schlegel, Princeton

(See /home/hsred/idl/hsred/idl/spec1d/hs_zcompute.pro)