IDL Help for HIRedux

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: Thu Oct 27 17:25:44 2005.


List of Routines


Routine Descriptions

HIRES_1DSPEC

[Next Routine] [List of Routines]
 NAME:
 hires_1dspec
    Version 1.1

 PURPOSE:
   Combines orders of a echfspec structure into a 1d spectrum.  
   Outputs flux and error arrays into separate files (_F.fits, _E.fits)

 CALLING SEQUENCE:
  
   hires_1dspec, hires, setup, obj_id, chip

 INPUTS:
   hires      - MIKE structure
   obj_id   -  Object ID  (e.g. 0L, 1L, etc)
   [exp_id] -  Exposure frames (e.g. [0L, 1L])

 RETURNS:

 OUTPUTS:
   1d flux      -   (fits file; FSpec/name_ech_F.fits)
   1d error     -   (fits file; FSpec/name_ech_E.fits)

 OPTIONAL KEYWORDS:
    /SILENT   - No text output
    OBJ_NM=   - Name of object in slit (a = science)
    /STD      - Run on a standard star
    OUTNM=    - Alternative output name for FSpec file
    ENDTRM=   - Trim order edges by this when calculating ratios
    MINPIX1=  - Minimum 'good' pixels to calculate fitting profile
    ORDNM=    - 0th or 1st order fitting (1 = 1st, 2 = 0th (default))
    SNRMIN=   - Minimum S/N per pixel for consideration in fitting
    MINPIX2=  - Minimum 'good' pixels to calculate simple 0th order fit

 OPTIONAL OUTPUTS:

 COMMENTS: ;
 EXAMPLES:
   hires_1dspec, hires, setup, obj_id, chip

 PROCEDURES/FUNCTIONS CALLED:

 REVISION HISTORY:
   14-Jun-2004 Written by GEP

(See pro/Spec/hires_1dspec.pro)


HIRES_ALLARC

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_allarc
     Version 1.1

 PURPOSE:
   Runs through all of the Arc processing steps in one go.
   Can be used to process a set of arcs for a given object or all
   of the arcs from a given night.

   This file also contains hires_allarc_sngl which can be used to
   fully process a single arc image.  In fact, if the keyword /ALL is
   used, then hires_allarc simply loops through all of the arcs calling
   hires_allarc_sngl for each one.

 CALLING SEQUENCE:
   
   hires_allarc, hires, setup, [chip], /CHK, /CLOBBER, /INDX

 INPUTS:
   hires     -  MIKE structure
   setup  -  Integer defining setup OR an array of index values to
            process
   [chip]   -  Blue (1), Red (2), or both [1,2L]    (Default: [1,2L])

 RETURNS:

 OUTPUTS:
  A series of files related to Arc calibration

 OPTIONAL KEYWORDS:
  /CLOBBER  - Overwite any previous files
  /CHK      - Present GUIs to show results of fitting, etc.
  /PINTER   - Perform fit for pre-identified lines
  /INDX     - Treat setup as an array of index values to process

 OPTIONAL OUTPUTS:
  FITS=     - File to write hires structure to (default: 'strct.fits')

 ADDITIONAL KEYWORDS TO MIKE_ALLARC_SNGL:
   /NOIMG    - Do not create arc image
   /NOWAV    - Do not fit the arc lines (ie. only do tracing)

 COMMENTS:

 EXAMPLES:
   hires_allarc, hires, 1L, 1L, /CHK, /CLOBBER
   hires_allarc, hires, [104L, 107L], /INDX
   rslt = hires_allarc_sngl('Raw/mb0539.fits', 1, 1, /PINTER)


 PROCEDURES/FUNCTIONS CALLED:
  hires_fitarc
  hires_fit2darc
  hires_tracearc
  hires_fittrcarc
  hires_mkaimg

 REVISION HISTORY:
   15-Aug-2003 Written by JXP

  Usage:

(See pro/Arcs/hires_allarc.pro)


HIRES_ALLFLAT

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_allflat   
     Version 1.1

 PURPOSE:
    Identifies flats, processes them.  Creates one flat file
      per slit width.  Takes TFLAT as the default

 CALLING SEQUENCE:
   
  hires_allaflat, hires, setup

 INPUTS:
   hires   -  HIRES structure
   setup   -  Setups  (can be an array of values)
   [chip]  -  Chip to process

 RETURNS:

 OUTPUTS:
  One normalized flat per slit width

 OPTIONAL KEYWORDS:

 OPTIONAL OUTPUTS:

 COMMENTS:

 EXAMPLES:
   hires_allflat, hires, [1L,2L,3L,4L]

 PROCEDURES/FUNCTIONS CALLED:

 REVISION HISTORY:
   Feb-2005 Written by JXP

(See pro/Flat/hires_allflat.pro)


HIRES_ALLOBJ

[Previous Routine] [Next Routine] [List of Routines]
 NAME: hires_allobj   
     Version 1.1

 PURPOSE:
    Run all of the processing steps on a single object.  This
    includes processing, CR rejection, tracing, sky subtraction and
    extraction.  Future version will allow multiple (or all objects)
    and also fluxing.


 CALLING SEQUENCE:
   
    hires_allobj, hires, setup, obj_id, chip, [exp], /PROCALL

 INPUTS:
   hires    -  MIKE structure
   setup   -  Setup ID
   obj_id  -  Object ID  (e.g. 1L)  (or STD index if /STD set)
   chip    -  Blue (1) or Green (2) and/or Red (3) side
   [exp]   -  Exposure frames (e.g. [0L, 1L])

 RETURNS:

 OUTPUTS:

 OPTIONAL KEYWORDS:
  /ALLPROC - Perform all steps
  /SKYCHK  - Check Final sky image
  /RESCHK  - Check Final extracted image
  /DOPROC  - Do image processing
  /DOFNT   - Do object tracing
  /DOSKY   - Do sky sub
  /DOBOX   - Do extraction
  /NOCR    - Turn off CR rejection routine (hires_objcr)
  /CLOBBER - Overwrite previous images (mainly the processed image)

 OPTIONAL OUTPUTS:

 COMMENTS:

 EXAMPLES:
   hires_allobj, hires, 1L, 1L

 PROCEDURES/FUNCTIONS CALLED:

 REVISION HISTORY:
   26-Apr-2004 Written by JXP 

(See pro/Object/hires_allobj.pro)


HIRES_AR

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_ar   
     Version 1.1

 PURPOSE:
   Reads in the first fits file in the directory with name
   'hires_*.fits' and passes back the hires structure.

 CALLING SEQUENCE:
   
  hires = hires_ar(file)

 INPUTS:
    [file] - Filename (default: first file in list ./hires_*fits*)

 RETURNS:
    hires -  MIKE structure

 OUTPUTS:

 OPTIONAL KEYWORDS:

 OPTIONAL OUTPUTS:

 COMMENTS:

 EXAMPLES:
   hires = hires_ar()


 PROCEDURES/FUNCTIONS CALLED:
   hires_rslvall

 REVISION HISTORY:
   13-Nov-2001 Written by JXP
   03-Feb-2003 Polished (JXP)

(See pro/General/hires_ar.pro)


HIRES_ARCTEMPL

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_arctempl
     Version 1.1

 PURPOSE:

 CALLING SEQUENCE:
   
  hires_arctempl, hires, setup, obj_id, [chip], /INTER, LINLIST=, /CHK, /CLOBBER,
  SIGREJ=, /DEBUG, IORDR=, /PINTER 

 INPUTS:
   hires     -  MIKE structure
   setup    -  Integer defining setup
   obj_id   -  Object identifier
   [chip]   -  Blue (1), Red (2), or both [1,2L]    (Default: [1,2L])

 RETURNS:

 OUTPUTS:
  IDL fit file (one per order)  (e.g. Arcs/ArcECH_##fit.idl)

 OPTIONAL KEYWORDS:

 OPTIONAL OUTPUTS:

 COMMENTS:

 EXAMPLES:
   hires_arctempl, hires, 1, 1


 PROCEDURES/FUNCTIONS CALLED:

 REVISION HISTORY:
   20-Feb-2005 Created by JXP (based on mike_fitarc)

(See pro/Arcs/hires_arctempl.pro)


HIRES_CHKCALIB

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_chkcalib
     Version 1.1

 PURPOSE:
    Checks to see what calibrations files are taken or missing

 CALLING SEQUENCE:
  hires_chkcalib

 INPUTS:

 RETURNS:

 OUTPUTS:

 OPTIONAL KEYWORDS:

 OPTIONAL OUTPUTS:

 COMMENTS:

 EXAMPLES:
   hires_chkcalib

 PROCEDURES/FUNCTIONS CALLED:

 REVISION HISTORY:
   27-Oct-2005 Written by JXP

(See pro/General/hires_chkcalib.pro)


HIRES_CHKFLUX

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_chkflux
     Version 1.1

 PURPOSE:
    Fluxes the spectrum using a standard star calibration.  Default
    is to use the one in CALIBS which is probably good enough for
    relative fluxing.  Definitely not good enough for absolute.

 CALLING SEQUENCE:
   
  hires_flux, hires, setup, obj_id, chip, FLUXFIL=, /CLOBBER, /STD

 INPUTS:
   setup   -  Setup ID
   obj_id  -  Object ID  (e.g. 1L)  (or STD index if /STD set)
   chip    -  Blue (1) Green (2) or Red (3)

 RETURNS:

 OUTPUTS:

 OPTIONAL KEYWORDS:
   FLUXFIL -  File name of standard star for fluxing (default:
               $MIKE_DIR/pro/Std/Archive/sens_blue#.fits)
   /STD    - Extraction should be set for a standard star
   /BOXCAR - Flux data from a Boxcar extraction

 OPTIONAL OUTPUTS:

 COMMENTS:

 EXAMPLES:
   hires_chkflux, hires, setup, obj_id, chip, /CLOBBER


 PROCEDURES/FUNCTIONS CALLED:

 REVISION HISTORY:
   02-Sep-2005 JXP

(See pro/Flux/hires_chkflux.pro)


HIRES_COMBSPEC

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_combspec
    Version 1.1

 PURPOSE:
   Combines multiple exposures of the same obj
    Must be run even on an object with a single exposure

 CALLING SEQUENCE:
   
   hires_combspec, hires, setup, obj_id, chip, exp_id

 INPUTS:
   hires      - MIKE structure
   obj_id   -  Object ID  (e.g. 0L, 1L, etc)
   [exp_id] -  Exposure frames (e.g. [0L, 1L])

 RETURNS:

 OUTPUTS:
   echfspec      -  ESI fspec structure (fits file; FSpec/name_ech.fits)

 OPTIONAL KEYWORDS:
    /SILENT   - No text output
    LIST=     - Use an input list to combine (required for multiple
                night obs).  Output is in 'FSpec/tmp_ech.fits', unless OUTFIL flag set to something.
    OBJ_NM=   - Name of object in slit (a = science)
    /STD      - Run on a standard star
    OUTNM=    - Alternative output name for FSpec file
    /NOFLUX   - Fill echfspec structure with fx, rather than flux array 
    ENDTRM=   - Trim order edges by this when calculating ratios
    MINPIX1=  - Minimum 'good' pixels to calculate fitting profile
    ORDNM=    - Fitting profile order (default: 1)
    SNRMIN=   - Minimum S/N per pixel for consideration in fitting

 OPTIONAL OUTPUTS:

 COMMENTS: ;
 EXAMPLES:
   hires_combspec, hires, setup, obj_id, side

 PROCEDURES/FUNCTIONS CALLED:

 REVISION HISTORY:
   04-Jan-2004 Written by JXP
   10-Jun-2004 Revisited by GEP
   Sep-2005 Revisited by JXP

(See pro/Spec/hires_combspec.pro)


HIRES_CONTI2D

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_conti2d
     Version 1.1

 PURPOSE:
   Reads in the first fits file in the directory with name
   'hires_*.fits' and passes back the hires structure.

 CALLING SEQUENCE:
   
  hires = hires_ar(file)

 INPUTS:
    [file] - Filename (default: first file in list ./hires_*fits*)

 RETURNS:
    hires -  MIKE structure

 OUTPUTS:

 OPTIONAL KEYWORDS:

 OPTIONAL OUTPUTS:

 COMMENTS:

 EXAMPLES:
   hires = hires_ar()


 PROCEDURES/FUNCTIONS CALLED:
   hires_rslvall

 REVISION HISTORY:
   13-Nov-2001 Written by JXP
   03-Feb-2003 Polished (JXP)

(See pro/Spec/hires_conti2d.pro)


HIRES_DELOV

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_delov   
     Version 1.0

 PURPOSE:
    Deletes OV images

 CALLING SEQUENCE:
   
  hires_delov, hires, indx

 INPUTS:
   hires   -  ESI structure
   indx  -  Index numbers of frames to delete

 RETURNS:

 OUTPUTS:

 OPTIONAL KEYWORDS:

 OPTIONAL OUTPUTS:

 COMMENTS:

 EXAMPLES:
   hires_delov, hires, indx


 PROCEDURES/FUNCTIONS CALLED:

 REVISION HISTORY:
   18-Jul-2002 Written by JXP

(See pro/General/hires_delov.pro)


HIRES_EDGEFLAT

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_edgeflat
     Version 1.1

 PURPOSE:
  This is mainly a frontend to x_edgeflat.  See that routine for
  extensive (and the most recent) details


 CALLING SEQUENCE:
   
  hires_edgeflat, hires, setup, [side], /CHK, 

 INPUTS:
   hires     -  MIKE structure
   setup    -  Setup identifier 
   [side]   -  Blue (1), Red (2), or both [1,2L]    (Default: [1,2L])

 RETURNS:

 OUTPUTS:
  A structure containing the information for the order by order
  fits.  This structure is then fed to hires_fittflat to create a 2D
  solution.  Typical name:  'Flats/TStr_B_01.fits'

 OPTIONAL KEYWORDS:
  /CHK -- Check the order edges interactively (similar to INTER)
  /INTER -- Determine the order edges interactively
  SMSHROW -- Row where order edges are determined (default: 1/2 way
             up the image)
  THRESH  -- Threshold for an order edge on the red side
              (default: 100.)
  /CLOBBER -- Overwrite the output structure
  P_NSIG  --  Number of sigma significance that an order edge should
             have for the red side (default: 50.)
  NSIG  --  Number of sigma significance that an order edge should
             have fo the blue side (default: 2.0)
  MINFLAT -- Mininum counts in flat on blue side to use orders (100)


 OPTIONAL OUTPUTS:

 COMMENTS:

 EXAMPLES:
   hires_edgeflat, hires, 1.0

 PROCEDURES/FUNCTIONS CALLED:
   hires_edgeflat_clean
   hires_getfil
   x_edgeflat

 REVISION HISTORY:
   Feb-2005 Written by JXP

(See pro/Flat/hires_edgeflat.pro)


HIRES_EDITSTRCT

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_editstrct   
   Version 1.1

 PURPOSE:
    Launches a gui to edit the MIKE structure

 CALLING SEQUENCE:
   
   hires_editstrct, hires

 INPUTS:
  hires  --  ESI structure

 RETURNS:

 OUTPUTS:

 OPTIONAL KEYWORDS:

 OPTIONAL OUTPUTS:

 COMMENTS:

 EXAMPLES:
   hires_editstrct, hires


 PROCEDURES/FUNCTIONS CALLED:

 REVISION HISTORY:
   04-Jan-2002 Written by JXP
   29-Jan-2003 Polished by JXP

(See pro/General/hires_editstrct.pro)


HIRES_EXTRACT

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_extract
     Version 1.1

 PURPOSE:
   Extract 1D spectra from the 2D images.  For each order, a boxcar
   and an optimal extraction is performed.  For the latter, an object
   profile is derived and both the object flux and sky are fit throughout
   the order (i.e. not row by row).  The main driver is
   mike_box_sngl.  For the optimal extraction, the data is extracted
   to a specific set of vacuum wavelengths, chosen to be the same for
   every spectrum to facilitate coadding without rebinning.  Here are
   the steps in detail:

    1.  Perform a boxcar extraction using extract_box
    2.  Estimate the SNR per order from the boxcar extraction
      -- LOOP ON ORDERS IN DECREASING SNR --
    3.  Fit the boxcar extraction with a bspline
    4.  Calculate the object profile
          a. bspline_iterfit the flux vs position on slit
          b. Force the profile to be positive everywhere and have a
          sensible FWHM
    5.  Fit the order using the profile and sky (bspline_extract)

 CALLING SEQUENCE:
   
  hires_extract, hires, setup, obj_id, chip, [exp], /RESCHK, /CHK

 INPUTS:
   hires    -  MIKE structure
   setup   -  Setup ID
   obj_id  -  Object ID  (e.g. 1L)  (or STD index if /STD set)
   chip    -  Blue (1), Green (2) OR Red (3) chip
   [exp]   -  Exposure frames (e.g. [0L, 1L])

 RETURNS:

 OUTPUTS:
   Fills up the 1D spectral tags in the Object structure.

 OPTIONAL KEYWORDS:
   /OCHK   - Plot the extracted flux (optimal) for each order
   /RESCHK - Check the residuals of the 2D, fully extracted image
   /STD    - Extraction should be set for a standard star
   /DEBUG  - Stop within extraction routine to check stuff
   /SKIPSKYSUB - Perform extraction on the processed but NOT sky
                 subtracted image.
   HIGHSNR - Value of SNR^2 of the data for a given order which when
             exceeded mike_box uses an additional parameter for the
             profile shape.  (Default:  500 corresponding to SNR=22)
             Lowering this parameter may improve extraction.
   ORDRS   - Input array of physical order numbers to extract
   /SCTCHK - Show the scattered light image

 Optional OUTPUTS:

 COMMENTS:
  The program extracts the orders in order of decreasing SNR.  If the
  SNR is lower than lowsnr (default: 2.49) then the optimal
  extraction is performed using the profile parameters from the
  previous order(s).

 EXAMPLES:
   hires_extract, hires, 1L, [0L]

 PROCEDURES/FUNCTIONS CALLED:
  x_echextobj
  extract_boxcar
  smooth_mask
  bspline_extract

 REVISION HISTORY:
   26-Aug-2003 Written by SMB

(See pro/Object/hires_extract.pro)


HIRES_FINDGAIN

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_findgain
     Version 1.1

 PURPOSE:
    Calculate the inverse gain using the routine hires_gain and the Milky Flats.
   The value of the gain is then saved into hires.gain

 CALLING SEQUENCE:
   
  hires_findgain, hires, setup, [side]

 INPUTS:
   setup   -  Setup ID
   [side]  -  Blue (1) and/or Red (2) side  [default: [1,2] ]

 RETURNS:

 OUTPUTS:

 OPTIONAL KEYWORDS:

 OPTIONAL OUTPUTS:

 COMMENTS:

 EXAMPLES:

 PROCEDURES/FUNCTIONS CALLED:

 REVISION HISTORY:
   26-Jun-2004 Written by SMB

(See pro/Flat/hires_findgain.pro)


HIRES_FIT2DARC

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_fit2darc   
     Version 1.1

 PURPOSE:
  To fit the arc lines identified in hires_fitarc as a fucntion of
  their y-centroid and order number.  The main routine is in
  hires_fit2darc_work.  The fit is a simple least-squares with one
  round of rejection.

 CALLING SEQUENCE:
   
  hires_fit2darc, hires

 INPUTS:
   hires    -  HIRES structure
   setup    -  Integer defining setup
   obj_id   -  Object identifier
   [chip]   -  Blue (1), Red (2), or both [1,2L]    (Default: [1,2L])

 RETURNS:

 OUTPUTS:
 A fits file containing the 2D solution.  Named something like
 'Arcs/Fits/Arc_mb0539_fit2D.fits' 

 OPTIONAL KEYWORDS:
   NOCOEFF   - Number of coefficients to use in the x-direction
               (default: 6 for blue, 7 for red)
   NYCOEFF   - Number of coefficients to use in the y-direction
               (default: 4)
   /CLOBBER  - Overwrite any previous solution
   /DEBUG    - debug
   /CHKRES   - Plot the residuals

 OPTIONAL OUTPUTS:

 COMMENTS:

 EXAMPLES:
   hires_fit2darc, hires, 1.0

 PROCEDURES/FUNCTIONS CALLED:
  hires_fit2darc_work

 REVISION HISTORY:
   28-Feb-2003 Written by SB
   18-Apr-2003 Revised by JXP

(See pro/Arcs/hires_fit2darc.pro)


HIRES_FITARC

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_fitarc   
     Version 1.1

 PURPOSE:
  To identify and centroid arc lines in each order.  There is
  actually no fitting done at this stage other than to reject bad
  lines.   The main program calls x_fitarc as its driver.
  The algorithm x_fitarc does the following:

    1) Input the arc image from hires_mkarc 
    2) Input an archived arc solution appropriate to the chip
    3) Extract 1D (boxcar) spectra down each order :: extract_arc
    4) Cross correlate (FFT) against the archived 1D arc spectrum,
    this gives the order number and the pixel offset
    5) Automatically identify a set of lines (x_templarc)
    6) Perform a low order fit to these lines
    7) Reidentify all lines with this fit and refit 
    8) Write arc solutions (one per order) to a fits file 
    9) If the orders extend beyond the archived solution, attempt to
    extrapolate to the remaining orders.  The idea is to use the
    known wavelengths from the good orders to extrapolate a guess at
    the solution.  Then use this guess to peak up on the arc lines in
    these additional orders.

 CALLING SEQUENCE:
   
  hires_fitarc, hires, setup, obj_id, [chip], /INTER, LINLIST=, /CHK, /CLOBBER,
  SIGREJ=, /DEBUG, IORDR=, /PINTER 

 INPUTS:
   hires     -  HIRES structure
   setup    -  Integer defining setup
   obj_id   -  Object identifier
   [chip]   -  Blue (1), Red (2), or both [1,2L]    (Default: [1,2L])

 RETURNS:

 OUTPUTS:
  IDL fit file (one per order)  (e.g. Arcs/ArcECH_##fit.idl)

 OPTIONAL KEYWORDS:
   /PINTER   - Perform fit for pre-identified lines
   /INTER    - Identify lines interactively and then fit
   LINLIST   -  Arc line list (default: $XIDL_DIR/Spec/Arcs/Lists/hires_thar.lst
   /CHK      - Manually check steps along the way
   /DEBUG    - Debugging
   SIGREJ=   - Rejection sigma for outliers in arc line fitting
              (default: 2.)
   IORDR     - Initial order for analysis
   /CLOBBER  - Overwrite previous fits
   SHFTPRM=  - Fit structure for shifting the orders of the arc

 OPTIONAL OUTPUTS:

 COMMENTS:

 EXAMPLES:
   hires_fitarc, hires, 1, 1
   hires_fitarc, hires, 1, /clobb, arcfil='Arcs/Arc_B0171.fits'


 PROCEDURES/FUNCTIONS CALLED:
   x_fitarc

 REVISION HISTORY:
   20-Feb-2005 Created by JXP (based on mike_fitarc)

(See pro/Arcs/hires_fitarc.pro)


HIRES_FITSCATT

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_fitscatt
     Version 1.2

 PURPOSE:
    Fit scattered light image to the light in the order gaps

 CALLING SEQUENCE:
   
  hires_fitscatt, img, ivar, ordr_str, chip

 INPUTS:

 RETURNS:

 OUTPUTS:
   A fit to the scattered light 

 OPTIONAL KEYWORDS:

 OPTIONAL OUTPUTS:

 COMMENTS:

 EXAMPLES:

 PROCEDURES/FUNCTIONS CALLED:
  x_fitgap
  x_ordermask

 REVISION HISTORY:
   02-Sep-2005 Written by JXP

(See pro/Skysub/hires_fitscatt.pro)


HIRES_FITTFLAT

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_fittflat   
     Version 1.1

 PURPOSE:
  To create a 2D solution which describes the order curvature.  This
  solution is derived from the individual traces created by
  hires_trcflat and saved within the Trace structure.  The 2D fitting
  algorithm is a simple least-squares algorithm.  The code then
  attempts to extrapolate the solution for orders which are partially
  on the CCD.  The code then makes a guess for the physical order
  number which is not particularly accurate right now.  Finally, the
  order structure (a key input for the HIRES pipeline) is written to
  disk.
  ---  The code primarily calls x_fittflat for everything

 CALLING SEQUENCE:
   
  hires_fittflat, hires, setup, [chip], /DEBUG, INNY=, INNT=, LHEDGE=,
                  /CLOBBER

 INPUTS:
   hires     -  HIRES structure
   setup    -  Setup identifier 
   [chip]   -  Blue (1), Red (2), or both [1,2L]    (Default: [1,2L])

 RETURNS:

 OUTPUTS:
  One normalized flat per slit width

 OPTIONAL KEYWORDS:
   INNY   -- Number of coefficients for fitting in vertical
             direction.  (Default: 7)
   INNT   -- Number of coefficients for fitting in horizontal
             direction.  (Default: 6)
   /DEBUG -- Turn debugging on
   LHEDG  -- Used primarily for debugging

 OPTIONAL OUTPUTS:

 COMMENTS:

 EXAMPLES:
   hires_fittflat, hires, 1, 1

 PROCEDURES/FUNCTIONS CALLED:

 REVISION HISTORY:
   28-Feb-2003 Written by SB
   18-Apr-2003 Revised by JXP

(See pro/Flat/hires_fittflat.pro)


HIRES_FITTRCARC

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_fittrcarc
     Version 1.1

 PURPOSE:
   To fit the slope of the arc lines as a function of order number
   and y position on the CCD.  This information is then used to
   construct a 2D wavelength image.  The fitting routine is the usual
   least-squares algorithm with two rounds of rejection.

 CALLING SEQUENCE:

 INPUTS:
   hires     -  MIKE structure
   setup    -  Integer defining setup
   obj_id   -  Object identifier
   [chip]   -  Blue (1), Red (2), or both [1,2L]    (Default: [1,2L])

 RETURNS:

 OUTPUTS:
  Fits file with the coefficients of the 2D fit.  Filename like
  'Arcs/TRC/Arc_mb0539_F.fits' 

 OPTIONAL KEYWORDS:
  /CHK  -- Plots residuals
  /CLOBBER -- Overwrite previous solution
  /ORDRCLOB -- Overwrite arc_m in the order structure

 OPTIONAL OUTPUTS:

 COMMENTS:

 EXAMPLES:

 PROCEDURES/FUNCTIONS CALLED:
  hires_fittrcarc_work -- Main driver
  hires_getfil

 REVISION HISTORY:
   24-Feb-2005 Written by JXP

(See pro/Arcs/hires_fittrcarc.pro)


HIRES_FLUX

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_flux
     Version 1.1

 PURPOSE:
    Fluxes the spectrum using a standard star calibration.  Default
    is to use the one in CALIBS which is probably good enough for
    relative fluxing.  Definitely not good enough for absolute.

 CALLING SEQUENCE:
   
  hires_flux, hires, setup, obj_id, chip, FLUXFIL=, /CLOBBER, /STD

 INPUTS:
   setup   -  Setup ID
   obj_id  -  Object ID  (e.g. 1L)  (or STD index if /STD set)
   chip    -  Blue (1) Green (2) or Red (3)

 RETURNS:

 OUTPUTS:

 OPTIONAL KEYWORDS:
   FLUXFIL -  File name of standard star for fluxing (default:
               $MIKE_DIR/pro/Std/Archive/sens_blue#.fits)
   /STD    - Extraction should be set for a standard star
   /BOXCAR - Flux data from a Boxcar extraction

 OPTIONAL OUTPUTS:

 COMMENTS:

 EXAMPLES:
   hires_flux, hires, obj_id, /CLOBBER


 PROCEDURES/FUNCTIONS CALLED:

 REVISION HISTORY:
   02-Sep-2005 JXP

(See pro/Flux/hires_flux.pro)


HIRES_FNTOBJ

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_fntobj   
     Version 1.1

 PURPOSE:
    Identify the object within the slit (single object) and trace it
    along each order.  The code rectifies each order, collapses it
    and looks for the object.  IF it finds it in >7 orders then it
    peaks up on the object.  Otherwise, it guesses the object is at
    the center of the order.  It then uses xy2tracset (trace_crude)
    to trace the object along each order individually.  Finally, it
    performs a PCA analysis on the trace_crude coefficients to create
    a smoothed (pseudo-2D) solution for the trace.  The code outputs
    an object structure which includes the trace and other info.


 CALLING SEQUENCE:
   
    hires_fntobj, hires, setup, obj_id, chip, [exp], /STD, /CHK [v1.0]'

 INPUTS:
   hires    -  MIKE structure
   setup   -  Setup ID
   obj_id  -  Object ID  (e.g. 1L)  (or STD index if /STD set)
   chip    -  Blue (1) or Red (2) chip
   [exp]   -  Exposure frames (e.g. [0L, 1L])

 RETURNS:

 OUTPUTS:
  Object structure (MIKEOBJSTRCT) including the trace and other information
  regarding the object.  This structure is then filled up with the 1D
  spectrum, etc.

 OPTIONAL KEYWORDS:
  /STD     - Find object for standard star
  /CHK     - Show diagnostics of the code performance
  /NOCLOB  - Do not clobber existing files (default: clobber)
  /DEBUG   - Debug
  OBJAPER  - Set aperture to mask for sky subtraction (default: 20
             unbinned pixels for obj, 26 for STD)

 OPTIONAL OUTPUTS:

 COMMENTS:

 EXAMPLES:
   hires_fntobj, hires, 1L, 1L, /CHK, 

 PROCEDURES/FUNCTIONS CALLED:
  hires_rectify
  find_npeaks
  hires_fweight
  hires_fntobj_off
  trace_crude
  hires_basis

 REVISION HISTORY:
   23-Sep-2003 Written by JXP (combined aspects of fndobj with trcobj)
   10-Nov-2003 Changed fntobj_off, SMB

(See pro/Object/hires_fntobj.pro)


HIRES_GETARCFIL

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_getarcfil
     Version 1.1

 PURPOSE:
   Runs through all of the Arc processing steps in one go.
   Can be used to process a set of arcs for a given object or all
   of the arcs from a given night.

   This file also contains hires_allarc_sngl which can be used to
   fully process a single arc image.  In fact, if the keyword /ALL is
   used, then hires_allarc simply loops through all of the arcs calling
   hires_allarc_sngl for each one.

 CALLING SEQUENCE:
   
   hires_allarc, hires, setup, [chip], /CHK, /CLOBBER, /INDX

 INPUTS:
   hires     -  MIKE structure
   setup  -  Integer defining setup OR an array of index values to
            process
   [chip]   -  Blue (1), Red (2), or both [1,2L]    (Default: [1,2L])

 RETURNS:

 OUTPUTS:
  A series of files related to Arc calibration

 OPTIONAL KEYWORDS:
  /CLOBBER  - Overwite any previous files
  /CHK      - Present GUIs to show results of fitting, etc.
  /PINTER   - Perform fit for pre-identified lines
  /INDX     - Treat setup as an array of index values to process

 OPTIONAL OUTPUTS:
  FITS=     - File to write hires structure to (default: 'strct.fits')

 ADDITIONAL KEYWORDS TO MIKE_ALLARC_SNGL:
   /NOIMG    - Do not create arc image
   /NOWAV    - Do not fit the arc lines (ie. only do tracing)

 COMMENTS:

 EXAMPLES:
   hires_allarc, hires, 1L, 1L, /CHK, /CLOBBER
   hires_allarc, hires, [104L, 107L], /INDX
   rslt = hires_allarc_sngl('Raw/mb0539.fits', 1, 1, /PINTER)


 PROCEDURES/FUNCTIONS CALLED:
  hires_fitarc
  hires_fit2darc
  hires_tracearc
  hires_fittrcarc
  hires_mkaimg

 REVISION HISTORY:
   15-Aug-2003 Written by JXP

  Usage:

(See pro/Arcs/hires_getarcfil.pro)


HIRES_GETFIL

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_getfil   
     Version 1.1

 PURPOSE:
   Pass back a structure and/or filename for a specified file type in
   the MIKE code.

 CALLING SEQUENCE:
   
  rslt = hires_getfil('type', [setup], CHIP=, /NAME, SUBFIL=, CHKFIL=,
  SZ=, INDX=, FIL_NM=, HEAD=)

 INPUTS:
   [setup]   -  Setup identifier 

 RETURNS:
  Structure, image, name, etc.

 OUTPUTS:

 OPTIONAL KEYWORDS:
   /name   -- Only return resolved name (string)
   CHKFIL  -- Value equal to the number of files matching name
   SZ      -- Image size
   SUBFIL  -- Image name generally used to parse the root name of the
              image  (e.g.  'Arcs/arc_mb0539.fits').  Required in
              many cases.
   CHIP    -- Specify camera: Blue (1) or Red (2)
   INDX    -- Image extension in the fits file (generally 0, 1, or 2)

 OPTIONAL OUTPUTS:
   FIL_NM  -- Filename of the file 
   HEAD    -- Image header

 COMMENTS:

 EXAMPLES:
   ordr_str = hires_getfil('ordr_str', 1, CHIP=1)

 PROCEDURES/FUNCTIONS CALLED:

 REVISION HISTORY:
   24-Jan-2005 Written by JXP

(See pro/General/hires_getfil.pro)


HIRES_GETPIXFLAT

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_getpixflat   
     Version 1.1

 PURPOSE:
   Pass back a structure and/or filename for a specified file type in
   the MIKE code.

 CALLING SEQUENCE:
   
  rslt = hires_getfil('type', [setup], CHIP=, /NAME, SUBFIL=, CHKFIL=,
  SZ=, INDX=, FIL_NM=, HEAD=)

 INPUTS:
   [setup]   -  Setup identifier 

 RETURNS:
  Structure, image, name, etc.

 OUTPUTS:

 OPTIONAL KEYWORDS:
   /name   -- Only return resolved name (string)
   CHKFIL  -- Value equal to the number of files matching name
   SZ      -- Image size
   SUBFIL  -- Image name generally used to parse the root name of the
              image  (e.g.  'Arcs/arc_mb0539.fits').  Required in
              many cases.
   CHIP    -- Specify camera: Blue (1) or Red (2)
   INDX    -- Image extension in the fits file (generally 0, 1, or 2)

 OPTIONAL OUTPUTS:
   FIL_NM  -- Filename of the file 
   HEAD    -- Image header

 COMMENTS:

 EXAMPLES:
   flg = hires_getpixflat(chip, cbin, rbin, crossd, flat)

 PROCEDURES/FUNCTIONS CALLED:

 REVISION HISTORY:
   24-Jan-2005 Written by JXP

(See pro/General/hires_getpixflat.pro)


HIRES_HEADID

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_headid   
     Version 1.1

 PURPOSE:
    Guess the type of MIKE image based on exposure time, counts,
    and other characteristics of the image.

 CALLING SEQUENCE:
   
  guess = hires_headid(data, xbinguess, ybinguess, $
               filename=img[q], hdr=head, /silent)

 INPUTS:
    data      - 2D image (generally set to 0 and read from filename)

 RETURNS:
  Image type::  'UNK', 'BAD', 'ZRO', 'ARC', 'TFLT', 'TFLT', 'STD',
  'OBJ', 'MFLT', 'TWI'

 OUTPUTS:

 OPTIONAL KEYWORDS:
   FILENAME   - Name of the image to be considered
   XBIN       - x binning
   YBIN       - y binning
   SILENT     - Suppress print statements
   SATURATED  - Saturation level (default = 50000.)
   

 OPTIONAL OUTPUTS:
   HDR     -  Image header if filename specified
   GUESS_EXPTIME -- Guess of exposure time based on CR hits

 COMMENTS:
   Need to do some consistency checks between red and blue side,
         i.e. they should be the same type

 EXAMPLES:
   guess = hires_headid(data, xbin, ybin, filename='file')


 PROCEDURES/FUNCTIONS CALLED:

 REVISION HISTORY:
   ??-??-2003 Written by SB

(See pro/General/hires_headid.pro)


HIRES_MKAIMG

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_mkaimg
     Version 1.1

 PURPOSE:
   Given the 2D solution for the slope of the lines as a function of
   position this code creates a wavelength image (i.e. assigns a
   unique wavelength to each pixel in each order).  The xoffset is 
   input in order to properly determine the edges of each order.  A
   simple spline interpolation is used to determine the values.


 CALLING SEQUENCE:
   
  hires_mkaimg, hires, setup, [chip], /CHK, /CLOBBER

 INPUTS:
   hires     -  MIKE structure
   setup    -  Integer defining setup
   obj_id   -  Object identifier
   [chip]   -  Blue (1), Red (2), or both [1,2L]    (Default: [1,2L])

 RETURNS:

 OUTPUTS:
  2D wavelength image with name like 'Arcs/Arc_mb0439I.fits'

 OPTIONAL KEYWORDS:
   /CLOBBER  - Overwrite previous image
   /CHK      - Display the final image

 OPTIONAL OUTPUTS:

 COMMENTS:

 EXAMPLES:
   hires_mkaimg, hires, setup, obj_id


 PROCEDURES/FUNCTIONS CALLED:
  hires_getfil

 REVISION HISTORY:
   15-May-2003 Written by SB

(See pro/Arcs/hires_mkaimg.pro)


HIRES_MKASCII

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_mkascii   
     Version 1.0

 PURPOSE:
    Deletes OV images

 CALLING SEQUENCE:
   
  hires_delov, hires, indx

 INPUTS:
   hires   -  ESI structure
   indx  -  Index numbers of frames to delete

 RETURNS:

 OUTPUTS:

 OPTIONAL KEYWORDS:

 OPTIONAL OUTPUTS:

 COMMENTS:

 EXAMPLES:
   hires_writefits, hires, indx


 PROCEDURES/FUNCTIONS CALLED:

 REVISION HISTORY:
   08-Sep-2005 Written by JXP

(See pro/Spec/hires_mkascii.pro)


HIRES_MKTEMPL

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_mktempl
     Version 1.1

 PURPOSE:

 CALLING SEQUENCE:
   
  hires_arctempl, hires, setup, obj_id, [chip], /INTER, LINLIST=, /CHK, /CLOBBER,
  SIGREJ=, /DEBUG, IORDR=, /PINTER 

 INPUTS:
   hires     -  MIKE structure
   setup    -  Integer defining setup
   obj_id   -  Object identifier
   [chip]   -  Blue (1), Red (2), or both [1,2L]    (Default: [1,2L])

 RETURNS:

 OUTPUTS:
  IDL fit file (one per order)  (e.g. Arcs/ArcECH_##fit.idl)

 OPTIONAL KEYWORDS:

 OPTIONAL OUTPUTS:

 COMMENTS:

 EXAMPLES:
   hires_mktempl, hires, 1, 1


 PROCEDURES/FUNCTIONS CALLED:

 REVISION HISTORY:
   22-Aug-2005 Created by JXP 

(See pro/Arcs/hires_mktempl.pro)


HIRES_MKTFLAT

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_mktflat   
     Version 1.1

 PURPOSE:
    Combines all flats for a given setup into one final image.
    The images are first bias subtracted using hires_subbias.
    The images are median combined after scaling by the median after
    iteratively rejecting bad pixels.  The image and its inverse
    variance array are written to one fits file. Because of the
    thermal gradients, it is highly recommended that one use 
    only a coeval set of trace flats.  

 CALLING SEQUENCE:
   
  hires_mktflat, hires, setup, [chip], /SVOV, /REDOOV, /CLOBBER

 INPUTS:
   hires     -  HIRES structure
   setup    -  Setup identifier 
   [chip]   -  Blue (1), Green (2), Red (3), or multiple (Default:
              [1,2,3L])

 RETURNS:

 OUTPUTS:
  One normalized flat per setup and side
  (e.g. 'Flats/Flat/_B_01_T.fits.gz')

 OPTIONAL KEYWORDS:
   /REDOOV  - Overwrite OV files if they exist for the flats
   /SVOV    - Save the OV files created during this step
   /CLOBBER - Overwrite the final fits file
   /USEBIAS - Use the bias frame in bias subtraction

 OPTIONAL OUTPUTS:

 COMMENTS:

 EXAMPLES:
   hires_mktflat, hires, 1.0

 PROCEDURES/FUNCTIONS CALLED:
  hires_subbias
  xcombine
  hires_delov

 REVISION HISTORY:
   17-Apr-2003 Written by JXP

(See pro/Flat/hires_mktflat.pro)


HIRES_NRMFLAT

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_nrmflat
     Version 1.1

 PURPOSE:
  To normalize the flat (remove the blaze) to create an image useful
  for pixel-to-pixel corrections.  Ideally, I recommend you use one
  of the archived flat frames as the flats created here have the
  following problems:
  1.  They fail at the slit edges
  2.  They contain scattered light which cannot be removed
  3.  Large chip defects cause more trouble

 CALLING SEQUENCE:
   
  hires_nrmflat, hires, setup, [side], /CHK, 

 INPUTS:
   hires     -  MIKE structure
   setup    -  Setup identifier 
   [side]   -  Blue (1), Red (2), or both [1,2L]    (Default: [1,2L])

 RETURNS:

 OUTPUTS:
  A normalized flat image

 OPTIONAL KEYWORDS:

 OPTIONAL OUTPUTS:

 COMMENTS:

 EXAMPLES:
   hires_nrmflat, hires, 1

 PROCEDURES/FUNCTIONS CALLED:

 REVISION HISTORY:

(See pro/Flat/hires_nrmflat.pro)


HIRES_OBJCR

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_objcr   
   Version 1.1

 PURPOSE:
    Flags CRs given 2 or more object images.  

 CALLING SEQUENCE:
   
  hires_objcr, hires, setup, obj_id, chip, [iexp]

 INPUTS:
   hires    -  MIKE structure
   setup   -  Setup ID
   obj_id  -  Object ID  (e.g. 1L)  (or STD index if /STD set)
   side    -  Blue (1) and/or Red (2) side  (Default:  [1L,2L])
   [iexp]  -  Exposure frames (e.g. [0L, 1L])

 RETURNS:

 OUTPUTS:
   flat - fits file in the dir Flats named 'Flat_##.fits'
                 where ## is the mask_id value
   VAR  - Variance in the flat (in electrons)

 OPTIONAL KEYWORDS:
   SVOV - save ov files
   /NOFITS - No FITS output
   RTIO -  Ratio CR must exceed to be flagged (default: 9)

 OPTIONAL OUTPUTS:

 COMMENTS:
   Algorithm for 3 or more images is not well tested.
   It would be nice to add a GROW option.

 EXAMPLES:
   hires_objcr, hires, setup, obj_id, chip, 

 PROCEDURES/FUNCTIONS CALLED:

 REVISION HISTORY:
   19-Aug-2003 Written by JXP

(See pro/Object/hires_objcr.pro)


HIRES_ORDERMASK

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_ordermask
     Version 0.1

 PURPOSE:
    Returns a integer image which identifies each pixel with a given order
      or inter-order gap.

 CALLING SEQUENCE:
   
  maskimage = hires_ordermask(ncol, nrow, ordr_str, trim=trim)

    (note: it's a little silly to pass ncol and nrow, but had no better
           idea at the time.  I should have just passed hires structure,
           but it doesn't really need it to run.)


 INPUTS:
   ncol     - number of columns in image
   nrow     - number of rows
   ordr_str - Structure array describing order format

 RETURNS:

 OUTPUTS:
  An [NCOL,NROW] image with each pixel exclusively assigned to an order or gap

 OPTIONAL KEYWORDS:
   trim     - The buffer included in each order (default 0. pixels).
              Increasing trim increases the width of each order!

 OPTIONAL OUTPUTS:

 COMMENTS:
   Crude routine to make a map of order placement
     Orders fall at positive Maps  [1...nord]
     Gaps  are marked with [-1 ... -NGAP]
     Pixel leftward of 1st order or rightward of last order in 
           ordr_str are set to 0

 EXAMPLES:
  maskimage = hires_ordermask(ncol, nrow, ordr_str, trim=trim)

 PROCEDURES/FUNCTIONS CALLED:
  gap_index  (internal routine to find those gaps!)

 REVISION HISTORY:
   15-Jul-2003 Checked in by SB
     
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  gap_index jumps through hoops to find the list of image indices which
       lie between lhedg <= column <= rhedg 

(See pro/General/hires_ordermask.pro)


HIRES_PARSEHDU

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_parsehdu
     Version 1.1

 PURPOSE:
    Guess the type of MIKE image based on exposure time, counts,
    and other characteristics of the image.

 CALLING SEQUENCE:
   
  guess = hires_headid(data, xbinguess, ybinguess, $
               filename=img[q], hdr=head, /silent)

 INPUTS:
    data      - 2D image (generally set to 0 and read from filename)

 RETURNS:
  Image type::  'UNK', 'BAD', 'ZRO', 'ARC', 'IFLT', 'TFLT', 'STD',
  'OBJ', 'MFLT', IFLT', 'TWI'

 OUTPUTS:

 OPTIONAL KEYWORDS:
   FILENAME   - Name of the image to be considered
   XBIN       - x binning
   YBIN       - y binning
   SILENT     - Suppress print statements
   SATURATED  - Saturation level (default = 50000.)
   

 OPTIONAL OUTPUTS:
   HDR     -  Image header if filename specified
   GUESS_EXPTIME -- Guess of exposure time based on CR hits

 COMMENTS:
   Need to do some consistency checks between red and blue side,
         i.e. they should be the same type

 EXAMPLES:
   guess = hires_headid(data, xbin, ybin, filename='file')


 PROCEDURES/FUNCTIONS CALLED:

 REVISION HISTORY:
   24-Jan-2005 Written by JXP

(See pro/General/hires_parsehdu.pro)


HIRES_PIXFLAT

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_pixflat
     Version 1.1

 PURPOSE:
    This set of routines takes a series of flats observed through the
    diffuser and creates a normalized Flat used to correct
    pixel-to-pixel response variations.  A principal challenge with
    MIKE in its current state (April 2004) is that it is difficult to
    get sufficient counts on the blue chip.  

    hires_pixflat :: The main routine simply does some basic
    accounting, organizes bias subtraction and performs I/O.

    hires_mkflat_work :: Accepts the name(s) of a series of OV
    subtracted milky flats.  It then:
      1.  Opens the file and creates an inverse variance array
      2.  Takes out the low order variation in the image (lo_interp)
      3.  Performs a series of medians along the columns rejecting bad
          pixels (replace by local mean). 
      4.  If multiple images were input, they are stacked with
          rejection and the final image is returned

 CALLING SEQUENCE:
   
  hires_pixflat, hires, setup, [side]

 INPUTS:
   hires     -  MIKE structure
   setup    -  Setup identifier 
   [side]   -  Blue (1), Red (2), or both [1,2L]    (Default: [1,2L])

 RETURNS:

 OUTPUTS:
  One normalized flat per setup per side with names like
  'Flats/Flat_B_01_M.fits.gz' 

 OPTIONAL KEYWORDS:
   /CLOBBER - Overwrite Output MilkyFlat
   /OVCLOB  - Overwrite OV files if they exist for the flats
   /SVOV    - Save the OV files created during this step
   /USEBIAS - Use bias frame in OV subtraction

 OPTIONAL OUTPUTS:

 COMMENTS:

 EXAMPLES:
   hires_pixflat, hires, 1

 PROCEDURES/FUNCTIONS CALLED:
   hires_getfil
   hires_subbias
   hires_pixflat_work

 REVISION HISTORY:
   16-May-2003 Adapted by JXP from existing programs by SB
   24-Feb-2004 Switched to a series of median/linear interpolations (SB)

(See pro/Flat/hires_pixflat.pro)


HIRES_PROC

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_proc   
     Version 1.0

 PURPOSE:
    Process a raw data frame.  Bias subtract and flatten.  Output is
    written in Final/ and is a mutli-extension fits file.
    Extension-0 is the processed image, Extension-1 is the inverse
    variance.

 CALLING SEQUENCE:
   
  There are several ways to call hires_proc
 
  hires_proc, hires, indx    [processes the image with index=indx]
  hires_proc, hires, SETUP=1, OBJ=4  [processes images with setup=1 and
     obj_id=4]
  rslt = hires_proc_sngl('Rawfil')    [process a single image]

 INPUTS:
   hires     -  HIRES structure
   [indx]   -  Index (or indices) of the image(s) in the HIRES
              structure to process

 RETURNS:

 OUTPUTS:
  Fully processed image

 OPTIONAL KEYWORDS:
  /CLOBBER - Clobber existing image
  SETUP    - Setup number
  EXP      - Exposure numbers
  OBJ      - Obj_id value
  /ARC     - Identifies the image as an Arc explicitly.  This is
             important for bias subtraction on the red chip.
  /NOFLAT  - Do not flatten
  FLATFIL  - Name of flat file to use.
  /SVOV    - Save the OV subtracted image
  /REDOOV  - Overwrite any existing OV images
  IOUTFIL  - Name for output file (array for mult
  /STD     - Processes standard stars corresponding to an input SETUP

 OPTIONAL OUTPUTS:

 COMMENTS:
   The inverse variance is given this set of values in an attempt to
   deal with the Poisson limit

   ivar = 1.0/(abs(img * gain - sqrt(2.0)*readno) + readno^2 ) 

 EXAMPLES:
   hires_proc, hires, [20L,21L], /CLOBBER


 PROCEDURES/FUNCTIONS CALLED:
  hires_proc_work
  hires_subbias_sngl
  hires_getfil
  hires_delov

 REVISION HISTORY:
   30-Apr-2002 Written by JXP
   19-Aug-2003 Added work routine
   20-Feb-2005 Taken from mike_proc

(See pro/General/hires_proc.pro)


HIRES_PROCARC

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_procarc   
     Version 1.1

 PURPOSE:
    Process (bias subtract, flatten) the arc files.  In addition, the
    code first calls hires_arcxyoff which uses a 2D FFT to determine
    the offset between the Template Arc and the current arc due to
    thermal expansion in the instrument.
   
    This file also includes the routine hires_procarc_sngl which
    allows the processing of a single Arc image given the filename of
    the Raw image.

 CALLING SEQUENCE:
   
  hires_procarc, hires, setup, obj_id, [chip], ATEMPL=, /CLOBBER,
  FLATFIL=

 INPUTS:
   hires     -  MIKE structure
   setup    -  Integer defining setup
   obj_id   -  Object identifier
   [chip]   -  Blue (1), Red (2), or both [1,2L]    (Default: [1,2L])

 RETURNS:

 OUTPUTS:
  One processed, combined Arc Image (e.g. Arcs/Arc_mb0539.fits)

 OPTIONAL KEYWORDS:
   /CLOBBER - Overwrite exisiting arc image
   ATEMPL -- Index of the Template Arc image (default: 0L)
   FLATFIL -- Filename of the milky flat (pixel to pixel correction)

 OPTIONAL OUTPUTS:

 COMMENTS:

 EXAMPLES:
   hires_procarc, hires, 1, 1, 1, /CLOBBER


 PROCEDURES/FUNCTIONS CALLED:
  hires_getfil
  hires_arcxyoff
  hires_proc

 REVISION HISTORY:
   13-Aug-2003 Written by JXP

(See pro/Arcs/hires_procarc.pro)


HIRES_QCKRDX

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_qckrdx   
     Version 1.1

 PURPOSE:
    Examines the Kast IDL structure, checks for appropriate
  Flats and Arcs and then outputs a summary ASCII file.

 CALLING SEQUENCE:
  hires_qckrdx, hires, OUTFIL=

 INPUTS:
   hires --  Kast IDL structure

 RETURNS:

 OUTPUTS:

 OPTIONAL KEYWORDS:
  OUTFIL=  -- Name of ASCII file (default: hires_summ.txt')

 OPTIONAL OUTPUTS:

 COMMENTS:

 EXAMPLES:
   hires_qckrdx, 'hires0023.fits',
   ['hires0030.fits','hires0031.fits'], 'hires0082.fits', CHIP=1

 PROCEDURES/FUNCTIONS CALLED:

 REVISION HISTORY:
   01-May-2005 Written by JXP

(See pro/General/hires_qckrdx.pro)


HIRES_RDXLOG

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_rdxlog   
     Version 1.1

 PURPOSE:
    Creates and outputs a structure for a series of MIKE images.
    This structure organizes the data for the night and is used 
    to run most of the programs in the MIKE package.  It will
    attempt to identify the type of object using the algorithm
    (hires_autoid).  It also parses the header for information related
    to exposure time, RA,DEC, etc. Finally, the code calculates the
    gain for pairs of Milky flat exposures with the routine
    hires_gain.  At present these gain values are not used.
    Use hires_setgain to set the values [highly recommended].

    See hiresstrct__define.pro for all of the tags of the hires structure.


 CALLING SEQUENCE:
   
  hires_strct, struct, LIST=, /NOMKDIR, /NOFILE, OUTFIL=, /EDIT, FILE_LIST=

 INPUTS:
    By default the program examines all of the files with the form
    *b####.fits in the Raw/ directory.

 RETURNS:

 OUTPUTS:
   struct     -  IDL structure based on the MIKE images

 OPTIONAL KEYWORDS:
   LIST       - Image list:  e.g.  'gd_files.lst'
   NOMKDIR    - Suppress the creation of sub directories (not
                recommended)
   EDIT     - Edit the final structure with the GUI
   OUTFIL     - Name of fits output file (default = hiresstrct.fits)
   FILE_LIST  - String Array of all input filenames
   

 OPTIONAL OUTPUTS:

 COMMENTS:
   Need to do some consistency checks between red and blue side,
         i.e. they should be the same type

 EXAMPLES:
   hires_strct, nght1_strct


 PROCEDURES/FUNCTIONS CALLED:

 REVISION HISTORY:
   24-Jan-2005 Written by JXP

(See pro/General/hires_rdxlog.pro)


HIRES_REDUX

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_redux
    Version 1.0

 PURPOSE:
   Calls various routines to analyse the data

 CALLING SEQUENCE:
   
   hires_redux, wfccd, maskid, expsr, XSIZE=, YSIZE=

 INPUTS:

 RETURNS:

 OUTPUTS:

 OPTIONAL KEYWORDS:

 OPTIONAL OUTPUTS:

 COMMENTS:

 EXAMPLES:
   hires_redux, hires


 PROCEDURES/FUNCTIONS CALLED:

 REVISION HISTORY:
   02-May-2005 Written by JXP

(See pro/General/hires_redux.pro)


HIRES_RSLVALL

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_rslvall  
     Version 1.1

 PURPOSE:
   Resolves a number of key codes for MIKE redux

 CALLING SEQUENCE:
   
  hires_rslvall

 INPUTS:

 RETURNS:

 OUTPUTS:

 OPTIONAL KEYWORDS:

 OPTIONAL OUTPUTS:

 COMMENTS:

 EXAMPLES:
   hires_rslvall


 PROCEDURES/FUNCTIONS CALLED:

 REVISION HISTORY:
   19-Aug-2003 Written by JXP

(See pro/General/hires_rslvall.pro)


HIRES_SETARCFIL

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_setarcfil
     Version 1.1

 PURPOSE:
  Set the arc file name

 CALLING SEQUENCE:
   hires_setarcfil, hires, setup

 INPUTS:
   hires -  Raw arc file used to set the arc_m values
   setup   -  Integer defining setup

 RETURNS:

 OUTPUTS:

 OPTIONAL KEYWORDS:

 OPTIONAL OUTPUTS:

 ADDITIONAL KEYWORDS TO MIKE_ALLARC_SNGL:

 COMMENTS:

 EXAMPLES:
   hires_setarcfil, hires, 1

 PROCEDURES/FUNCTIONS CALLED:
  hires_getfil

 REVISION HISTORY:
   28-Sep-2005 Written by JXP

  Usage:

(See pro/Arcs/hires_setarcfil.pro)


HIRES_SETARCM

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_setarcm
     Version 1.1

 PURPOSE:
  Run through the necessary steps to set the arc_m values in the
  order structure.  This seperate routine was created to avoid the
  high level of confusion occuring in hires_allarc.

 CALLING SEQUENCE:
   
   hires_setarcm, arc_fil, setup, chip

 INPUTS:
   arc_fil -  Raw arc file used to set the arc_m values
   setup   -  Integer defining setup
   chip    -  Blue (1) or Red (2)

 RETURNS:

 OUTPUTS:
  A series of files related to Arc calibration

 OPTIONAL KEYWORDS:
  /PINTER   - Perform fit for pre-identified lines

 OPTIONAL OUTPUTS:
  ARC_FIL=  - Name of processed arc
  XYOFF=    - Offset fit info

 ADDITIONAL KEYWORDS TO MIKE_ALLARC_SNGL:

 COMMENTS:

 EXAMPLES:
   hires_setarcm, 'Raw/hires_mb0032', 1, 1

 PROCEDURES/FUNCTIONS CALLED:
  hires_procarc
  hires_alignarc
  hires_fitarc
  hires_fit2darc
  hires_tracearc
  hires_fittrcarc

 REVISION HISTORY:
   18-Aug-2004 Written by JXP

  Usage:

(See pro/Arcs/hires_setarcm.pro)


HIRES_SETGAINRN

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_setgainrn
     Version 1.1

 PURPOSE:
    Guess the type of MIKE image based on exposure time, counts,
    and other characteristics of the image.

 CALLING SEQUENCE:
   
  guess = hires_headid(data, xbinguess, ybinguess, $
               filename=img[q], hdr=head, /silent)

 INPUTS:
    data      - 2D image (generally set to 0 and read from filename)

 RETURNS:
  Image type::  'UNK', 'BAD', 'ZRO', 'ARC', 'IFLT', 'TFLT', 'STD',
  'OBJ', 'MFLT', IFLT', 'TWI'

 OUTPUTS:

 OPTIONAL KEYWORDS:
   FILENAME   - Name of the image to be considered
   XBIN       - x binning
   YBIN       - y binning
   SILENT     - Suppress print statements
   SATURATED  - Saturation level (default = 50000.)
   

 OPTIONAL OUTPUTS:
   HDR     -  Image header if filename specified
   GUESS_EXPTIME -- Guess of exposure time based on CR hits

 COMMENTS:
   Need to do some consistency checks between red and blue side,
         i.e. they should be the same type

 EXAMPLES:
   hires_setgainrn, hires, idx, ccdgain


 PROCEDURES/FUNCTIONS CALLED:

 REVISION HISTORY:
   24-Jan-2005 Written by JXP  (These values are only good for after
   10/27/2004)
   22-Aug-2005 Updated gain for pre-Oct 2004 based on my own
   measurements

(See pro/General/hires_setgainrn.pro)


HIRES_SETUP

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_setup   
     Version 1.1

 PURPOSE:
    Examines the Kast IDL structure, checks for appropriate
  Flats and Arcs and then outputs a summary ASCII file.

 CALLING SEQUENCE:
  hires_setup, hires, OUTFIL=

 INPUTS:
   hires --  Kast IDL structure

 RETURNS:

 OUTPUTS:

 OPTIONAL KEYWORDS:
  OUTFIL=  -- Name of ASCII file (default: hires_summ.txt')
  /KEEPSET -- Dont modify the setup numbers (useful to reset the
              arcs)

 OPTIONAL OUTPUTS:

 COMMENTS:

 EXAMPLES:
   hires_setup, hires

 PROCEDURES/FUNCTIONS CALLED:

 REVISION HISTORY:
   01-Mar-2003 Written by JXP

(See pro/General/hires_setup.pro)


HIRES_SKYSUB

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_skysub   
     Version 1.2

 PURPOSE:
    Sky Subtract image and add sky subtracted frame to the final
    image (e.g. Final/f_hires0020.fits).  The program also outputs
    information related to the sky fit in the Sky directory.  The
    user has control over which order to subtract (ORDR=), the
    wavelength image to use (AIMG=).  The program preforms the
    following steps:

    1.  Offset the Order structure by the appropriate shift
    2.  Subtract scattered light (hires_fitgap)
     -- LOOP ON ORDERS --
    3.  After masking the object, the code finds the sky pixels and
    normalizes them by the slit profile.
    4.  It bspline fit to the sky
    5.  It assesses the fit and adds in breakpoints in a somewhat
    smart way.
    6.  It performs a second bspline fit
    7.  The coefficients of the fit are saved and the image is
    subtracted 
    8.  The code compares the extracted sky spectrum against the UVES
    sky spectrum to guess at a shift.  This is saved to the Object
    structure. 
     -- END OF LOOP
    9.  The final sky subtracted image is written to the fits file
    (extension #2)

 CALLING SEQUENCE:
   
  hires_skysub, hires, setup, obj_id, side, [exp], /CHK, /STD, ORDR=,
  AIMG=, /USEOLD, /FCHK

 INPUTS:
   hires    -  MIKE structure
   setup   -  Setup ID
   obj_id  -  Object ID  (e.g. 1L)  (or STD index if /STD set)
   side    -  Blue (1) or Red (2) side
   [exp]   -  Exposure frames (e.g. [0L, 1L])

 RETURNS:

 OUTPUTS:
   A sky subtracted image added as extension #2 to the fits file.
   A file in the directory Sky/ describing the fit


 OPTIONAL KEYWORDS:
  /STD     - Sky subtract standard star
  /CHK     - Show steps along the way
  AIMG=    - Use alternate Wavelength map for sky subtraction
             (string filename)
  ORDR=    - Sky subtract a single order only (e.g.  [5L,5L])
  /CLOBBER - Overwrite any previos sky image
  /USEOLD  - Overwrite only the new orders into the old sky sub image
  /FCHK    - Show the final sky subtracted image

 OPTIONAL OUTPUTS:
  SCATTERED_LIGHT= -- Scattered light image.  It may be useful to
                      save and use this if you are subtracting individual
                      orders

 COMMENTS:

 EXAMPLES:
   hires_skysub, hires, 1L, 1L, 1L, /FCHK

 PROCEDURES/FUNCTIONS CALLED:
  hires_fitgap
  hires_ordermask
  bspline_iterfit
  hires_getfil
  hires_skyshift
  hires_skysub_write

 REVISION HISTORY:
   16-May-2003 Written by JXP
   ??-2003     Modified extensively by SMB
   26-Jun-2004 Update arc shifting

(See pro/Skysub/hires_skysub.pro)


HIRES_SLITFLAT

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_slitflat
     Version 1.1

 PURPOSE:
    Stores slit profile and gradient along each order from twilight flats.
    This routine is critical for performing ideal sky subtraction,
    especially given the short slit length.  The following steps are
    performed in hires_slitflat_work:
    
    1.  Fit and subtract the scattered light in the twilight flat
    2.  Extract a boxcar profile down the center of the flat
    3.  Loop on orders
    4.  Calculate the slit angle at each pixel in the order
    5.  Calculate the Jacobian   (DEPRECATED)
    6.  Fit a bspline to the profile
    7.  Run diagnsotics on the fit
    8.  Save the good ones to profile0 and profile1 tags

 CALLING SEQUENCE:
   
  hires_slitflat, hires, setup, chip, [/chk, /clobber]

 INPUTS:
   hires     -  MIKE structure
   setup    -  Setup identifier 
   [chip]   -  Blue (1), Red (2), or both [1,2L]    (Default: [1,2L])

 RETURNS:

 OUTPUTS:
   Fills in the profile0 and profile1 tags in the Order structure

 OPTIONAL KEYWORDS:
  /CHK  - Show the profiles and fits order by order
  /CLOBBER - Clobber an previous work
  TFLAT_FIL - Name for TFLAT file
  RESIDUAL_FIL  - Output name for Jacobian matrix
  PROFILE_FIL - Output name for profile fits
  DETILT    - Remove a linear tilt from the Cross-section fit

  NXBKT  -  Number of x breakpoints for scattered light fit 
  NYBKT  -  Number of x breakpoints for scattered light fit 

 OPTIONAL OUTPUTS:

 COMMENTS:

 EXAMPLES:
   hires_slitflat, hires, 1

 PROCEDURES/FUNCTIONS CALLED:
  hires_ordermask
  hires_fitgap
  hires_qw
  hires_slitflat_work

 REVISION HISTORY:
   ??-??-2003 Written by SB

(See pro/Flat/hires_slitflat.pro)


HIRES_SLITLEN

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_slitlen
     Version 1.1

 PURPOSE:
    Guess the type of MIKE image based on exposure time, counts,
    and other characteristics of the image.

 CALLING SEQUENCE:
   
  guess = hires_headid(data, xbinguess, ybinguess, $
               filename=img[q], hdr=head, /silent)

 INPUTS:
    data      - 2D image (generally set to 0 and read from filename)

 RETURNS:
  Image type::  'UNK', 'BAD', 'ZRO', 'ARC', 'IFLT', 'TFLT', 'STD',
  'OBJ', 'MFLT', IFLT', 'TWI'

 OUTPUTS:

 OPTIONAL KEYWORDS:
   FILENAME   - Name of the image to be considered
   XBIN       - x binning
   YBIN       - y binning
   SILENT     - Suppress print statements
   SATURATED  - Saturation level (default = 50000.)
   

 OPTIONAL OUTPUTS:
   HDR     -  Image header if filename specified
   GUESS_EXPTIME -- Guess of exposure time based on CR hits

 COMMENTS:
   Need to do some consistency checks between red and blue side,
         i.e. they should be the same type

 EXAMPLES:
   hires_slitlen, hires, idx, ccdgain


 PROCEDURES/FUNCTIONS CALLED:

 REVISION HISTORY:
   23-Aug-2005 Written by JXP  

(See pro/General/hires_slitlen.pro)


HIRES_SPECPLT

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_specplt   
   Version 1.0

 PURPOSE:
    Plots any array interactively

 CALLING SEQUENCE:
   
   hires_specplt, ydat, [head], XSIZE=, YSIZE=, TITLE=, WAVE=, LLIST=,
           QAL=, ERR=, /GAL

 INPUTS:
   ydat       - Values 
   [head]     - Header

 RETURNS:

 OUTPUTS:

 OPTIONAL KEYWORDS:
   xsize      - Draw window xsize (pixels)
   ysize      - Draw window ysize (pixels)
   wave       - wavelength array
   ERR        - Error array (fits or image)

 OPTIONAL OUTPUTS:

 COMMENTS:

 EXAMPLES:
   hires_specplt, 'spec.fits'


 PROCEDURES/FUNCTIONS CALLED:

 REVISION HISTORY:
   23-Aug-2002 Written by JXP

(See pro/Spec/hires_specplt.pro)


HIRES_STRCT

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_strct   
     Version 1.1

 PURPOSE:
    Creates and outputs a structure for a series of MIKE images.
    This structure organizes the data for the night and is used 
    to run most of the programs in the MIKE package.  It will
    attempt to identify the type of object using the algorithm
    (hires_autoid).  It also parses the header for information related
    to exposure time, RA,DEC, etc. Finally, the code calculates the
    gain for pairs of Milky flat exposures with the routine
    hires_gain.  At present these gain values are not used.
    Use hires_setgain to set the values [highly recommended].

    See hiresstrct__define.pro for all of the tags of the hires structure.


 CALLING SEQUENCE:
   
  hires_strct, struct, LIST=, /NOMKDIR, /NOFILE, OUTFIL=, /EDIT, FILE_LIST=

 INPUTS:
    By default the program examines all of the files with the form
    *b####.fits in the Raw/ directory.

 RETURNS:

 OUTPUTS:
   struct     -  IDL structure based on the MIKE images

 OPTIONAL KEYWORDS:
   LIST       - Image list:  e.g.  'gd_files.lst'
   NOMKDIR    - Suppress the creation of sub directories (not
                recommended)
   EDIT     - Edit the final structure with the GUI
   OUTFIL     - Name of fits output file (default = hiresstrct.fits)
   FILE_LIST  - String Array of all input filenames
   

 OPTIONAL OUTPUTS:

 COMMENTS:
   Need to do some consistency checks between red and blue side,
         i.e. they should be the same type

 EXAMPLES:
   hires_strct, nght1_strct


 PROCEDURES/FUNCTIONS CALLED:

 REVISION HISTORY:
   24-Jan-2005 Written by JXP

(See pro/General/hires_strct.pro)


HIRES_SUBBIAS

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_subbias   
     Version 1.2

 PURPOSE:
    Remove bias from all exposures listed in the "hires" structure.
    The main driver is hires_suboscan which strips the image of the
    overscan region (see that program for a full
    description).  The hires_subbias routine will also remove an
    archived bias image if requested.

 CALLING SEQUENCE:
   
  hires_subbias, hires, indx, /usebias, /nobiasrow, /clobber, /ARC,
  /debug, BADROW=

 INPUTS:
   hires  -  MIKE structure

 RETURNS:

 OUTPUTS:

 OPTIONAL KEYWORDS:
  /NOBIASROW= if set, bias row is not used (normally, you should not use it)
  /USEBIAS = use the bias image in addition to subtracting a fit to the
             overscan columns (at right).  The code first generates a
             smoothed version of the bias image.
             If you do this, you want to be sure the same options
             were used in hires_mkbias (i.e. /nobiasrow )
             Presently, this step is not recommended.
  /CLOBBER = Overwrite existing OV files 
  /DEBUG -- Turn debug mode on
  BADROW -- Rows identified as anomolous in the overscan region.
            Generally the result of an electronics 'hiccup'.

 
 OUTPUTS TO SNGL:
   /NOFITS -- Do not write a fits file
   OVIMG=    -- Bias subtracted image

 OPTIONAL OUTPUTS:

 COMMENTS:


 EXAMPLES:
   hires_subbias, hires, indx, /usebias, /nobiasrow


 PROCEDURES/FUNCTIONS CALLED:

   hires_subbias_sngl -- Subroutine under hires_subbias.  Uses most of
                        the keywords described above.  Example:  
                        rslt = hires_subbias_sngl('Raw/mb0020.fits',
                        chip)
   hires_suboscan

 REVISION HISTORY:
   01-Feb-2005 Written by JXP  (taken from mike_subbias)
                                

(See pro/Bias/hires_subbias.pro)


HIRES_TEST

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_test
     Version 1.1

 PURPOSE:
   Reads in the first fits file in the directory with name
   'hires_*.fits' and passes back the hires structure.

 CALLING SEQUENCE:
   
  hires = hires_ar(file)

 INPUTS:
    [file] - Filename (default: first file in list ./hires_*fits*)

 RETURNS:
    hires -  MIKE structure

 OUTPUTS:

 OPTIONAL KEYWORDS:

 OPTIONAL OUTPUTS:

 COMMENTS:

 EXAMPLES:
   hires = hires_ar()


 PROCEDURES/FUNCTIONS CALLED:
   hires_rslvall

 REVISION HISTORY:
   13-Nov-2001 Written by JXP
   03-Feb-2003 Polished (JXP)

(See pro/General/hires_test.pro)


HIRES_TRACEARC

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_tracearc   
     Version 1.1

 PURPOSE:
    To trace the arc lines in each order (individually) and fit a
    straight line to each one.  The following steps are taken:
    1.  Scattered light is removed from the image
    2.  All significant arc lines are identified (5 sigma)
    3.  trace_crude is used to trace the lines 
    4.  trace_crude is reapplied to only those lines which are
    entirely in the order
    5.  xy2traceset is used to fit a straight line to each arc line
    6.  Only the good lines are saved for 2D fitting in a structure
    which is written to disk

 CALLING SEQUENCE:
   
  hires_tracearc, hires, setup, obj_id, [chip], /CLOBBER, INIO=

 INPUTS:
   hires     -  MIKE structure
   setup    -  Integer defining setup
   obj_id   -  Object identifier
   [chip]   -  Blue (1), Red (2), or both [1,2L]    (Default: [1,2L])

 RETURNS:
  all_xset -- A structure describing the fits to the arc lines

 OUTPUTS:

 OPTIONAL KEYWORDS:
   INIO      - Initial order (for debugging)
   /CLOBBER  - Overwrite previous fits

 OPTIONAL OUTPUTS:

 COMMENTS:

 EXAMPLES:
  hires_tracearc, hires, setup, obj_id


 PROCEDURES/FUNCTIONS CALLED:
  trace_crude
  xy2traceset
  x_echtracearc

 REVISION HISTORY:
   28-Apr-2003 Written by SB


(See pro/Arcs/hires_tracearc.pro)


HIRES_TRCFLAT

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_trcflat
     Version 1.1

 PURPOSE:
  This is mainly a frontend to x_trcflat.  See that routine for
  extensive (and the most recent) details


 CALLING SEQUENCE:
   
  hires_trcflat, hires, setup, [side], /CHK, 

 INPUTS:
   hires     -  MIKE structure
   setup    -  Setup identifier 
   [side]   -  Blue (1), Red (2), or both [1,2L]    (Default: [1,2L])

 RETURNS:

 OUTPUTS:
  A structure containing the information for the order by order
  fits.  This structure is then fed to hires_fittflat to create a 2D
  solution.  Typical name:  'Flats/TStr_B_01.fits'

 OPTIONAL KEYWORDS:
  /CHK -- Check the order edges interactively (similar to INTER)
  /INTER -- Determine the order edges interactively
  SMSHROW -- Row where order edges are determined (default: 1/2 way
             up the image)
  THRESH  -- Threshold for an order edge on the red side
              (default: 100.)
  /CLOBBER -- Overwrite the output structure
  P_NSIG  --  Number of sigma significance that an order edge should
             have for the red side (default: 50.)
  NSIG  --  Number of sigma significance that an order edge should
             have fo the blue side (default: 2.0)
  MINFLAT -- Mininum counts in flat on blue side to use orders (100)


 OPTIONAL OUTPUTS:

 COMMENTS:

 EXAMPLES:
   hires_trcflat, hires, 1.0

 PROCEDURES/FUNCTIONS CALLED:
   hires_trcflat_clean
   hires_getfil
   x_trcflat

 REVISION HISTORY:
   Feb-2005 Written by JXP

(See pro/Flat/hires_trcflat.pro)


HIRES_TWEAKARC

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_tweakarc   
     Version 1.1

 PURPOSE:

 CALLING SEQUENCE:
   
  hires_fitarc, hires, setup, obj_id, [chip], /INTER, LINLIST=, /CHK, /CLOBBER,
  SIGREJ=, /DEBUG, IORDR=, /PINTER 

 INPUTS:
   hires     -  HIRES structure
   setup    -  Integer defining setup
   obj_id   -  Object identifier
   [chip]   -  Blue (1), Red (2), or both [1,2L]    (Default: [1,2L])

 RETURNS:

 OUTPUTS:
  IDL fit file (one per order)  (e.g. Arcs/ArcECH_##fit.idl)

 OPTIONAL KEYWORDS:
   /PINTER   - Perform fit for pre-identified lines
   /INTER    - Identify lines interactively and then fit
   LINLIST   -  Arc line list (default: $XIDL_DIR/Spec/Arcs/Lists/hires_thar.lst
   /CHK      - Manually check steps along the way
   /DEBUG    - Debugging
   SIGREJ=   - Rejection sigma for outliers in arc line fitting
              (default: 2.)
   IORDR     - Initial order for analysis
   /CLOBBER  - Overwrite previous fits
   SHFTPRM=  - Fit structure for shifting the orders of the arc

 OPTIONAL OUTPUTS:

 COMMENTS:

 EXAMPLES:
   hires_fitarc, hires, 1, 1


 PROCEDURES/FUNCTIONS CALLED:
   x_fitarc

 REVISION HISTORY:
   Summer-2005 Created by JXP 

(See pro/Arcs/hires_tweakarc.pro)


HIRES_WRITEFITS

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_writefits   
     Version 1.0

 PURPOSE:
    Deletes OV images

 CALLING SEQUENCE:
   
  hires_delov, hires, indx

 INPUTS:
   hires   -  ESI structure
   indx  -  Index numbers of frames to delete

 RETURNS:

 OUTPUTS:

 OPTIONAL KEYWORDS:

 OPTIONAL OUTPUTS:

 COMMENTS:

 EXAMPLES:
   hires_writefits, hires, indx


 PROCEDURES/FUNCTIONS CALLED:

 REVISION HISTORY:
   08-Sep-2005 Written by JXP

(See pro/General/hires_writefits.pro)


HIRES_WRSTRCT

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 hires_wrstrct   
    Version 1.1

 PURPOSE:
    Write the hires structure to a FITS file and write an ASCII summary

 CALLING SEQUENCE:
   
  hires_wrstrct, hires, /ANONLY, OUTFIL=, FITS=

 INPUTS:
   hires   - An ESI structure

 RETURNS:

 OUTPUTS:

 OPTIONAL KEYWORDS:
   ANONLY - Only print files with flg_anly NE 0   

 OPTIONAL OUTPUTS:
   OUTFIL= - Output file (default: 'hires.list')
   FITS=   - Name of fits output file (default: 'strct.fits')

 COMMENTS:

 EXAMPLES:
   hires_wrstrct, hires, FITS='hires_13oct02.fits'


 PROCEDURES/FUNCTIONS CALLED:

 REVISION HISTORY:
   24-Jan-2005 Written by JXP

(See pro/General/hires_wrstrct.pro)


MIKE_AUTOID

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 mike_autoid   
     Version 1.1

 PURPOSE:
    Guess the type of MIKE image based on exposure time, counts,
    and other characteristics of the image.

 CALLING SEQUENCE:
   
  guess = mike_autoid(data, xbinguess, ybinguess, $
               filename=img[q], hdr=head, /silent)

 INPUTS:
    data      - 2D image (generally set to 0 and read from filename)

 RETURNS:
  Image type::  'UNK', 'BAD', 'ZRO', 'ARC', 'IFLT', 'TFLT', 'STD',
  'OBJ', 'MFLT', IFLT', 'TWI'

 OUTPUTS:

 OPTIONAL KEYWORDS:
   FILENAME   - Name of the image to be considered
   XBIN       - x binning
   YBIN       - y binning
   SILENT     - Suppress print statements
   SATURATED  - Saturation level (default = 50000.)
   

 OPTIONAL OUTPUTS:
   HDR     -  Image header if filename specified
   GUESS_EXPTIME -- Guess of exposure time based on CR hits

 COMMENTS:
   Need to do some consistency checks between red and blue side,
         i.e. they should be the same type

 EXAMPLES:
   guess = mike_autoid(data, xbin, ybin, filename='file')


 PROCEDURES/FUNCTIONS CALLED:

 REVISION HISTORY:
   ??-??-2003 Written by SB

(See pro/General/hires_autoid.pro)


MIKE_CROSSARC

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
 mike_crossarc
     Version 1.1

 PURPOSE:
    Finds shift between saved template and current arc spectra. 

 CALLING SEQUENCE:
  mike_crossarc, guessarc, cur_aspec, guess_spec, guess_fit, ordrs, $
         ordr_shift, row_shift, chk=chk, sigrej=sigrej, /DEBUG

 INPUTS:
   guessarc  -  Filename of IDL save file with known wavelength solution
   cur_aspec -  Current extracted Arc spectra to be fit

   obj_id   -  Object identifier
   [side]   -  Blue (1), Red (2), or both [1,2L]    (Default: [1,2L])

 RETURNS:

 OUTPUTS:
   guess_spec -  saved arc spectrum rebinned to match cur_aspec
   guess_fit  -  polynomial wavelength fits in rebinned space
   ordrs      -  Orders matching saved spectrum
   ordr_shift -  Order offset between template and current
   row_shift  -  Pixel offset between template and current

 OPTIONAL KEYWORDS:
   /CHK      - Manually check steps along the way
   /DEBUG    - Debugging
   SIGREJ=   - Rejection sigma for outliers in arc line fitting
              (default: 2.)

 OPTIONAL OUTPUTS:

 COMMENTS:

 EXAMPLES:

 PROCEDURES/FUNCTIONS CALLED:
   restore
   fft()

 REVISION HISTORY:
   2004 Written by SB

(See pro/Arcs/hires_crossarc.pro)


X_WRECHFSPEC

[Previous Routine] [List of Routines]
 NAME:
 x_wrechfspec
    Version 1.0

 PURPOSE:
    Reads and writes the echfspec structure

 CALLING SEQUENCE:
   
   x_wrechfspec, echfspec, outfil, /READ

 INPUTS:
   wfstrct     - WFCCD structure

 RETURNS:

 OUTPUTS:
   wfarc      -  WFCCD arc structure (fits file)

 OPTIONAL KEYWORDS:

 OPTIONAL OUTPUTS:

 COMMENTS:

 EXAMPLES:
   x_wrechfspec, echfspec, 'Extract/2015+657_ech.fits'


 PROCEDURES/FUNCTIONS CALLED:

 REVISION HISTORY:
   08-Sep-2005 Written by JXP

(See pro/Spec/hires_wrfspec.pro)