NAME:
   chknccal
 PURPOSE:  
   Review and grade calibration images for nasacam.
 DESCRIPTION:
   Widget searches the nasacam.calib and nasacam.image tables to build
   lists of calibration entries and associated raw and [sub]super calibration
   images. It allows an interactive search based on date range, filters,
   calibration type, and calibration status to fill a scrollable list of
   calibration entries. By default, the entries searched  are flats for all 
   dates and filters  with pending status. When an entry is selected, another
   list with individual images is populated, and a thumbnail view of the
   calibration product (eg, sub super flat) is presented. Individual images
   may be selected and displayed, and the status of the calibration entry
   may be modified in the data base. Image display occurs in a separate
   reused ITOOL window. The image display may be set to either raw or 
   processed mode. In processed mode, each image is divided 
   by its proper [sub]superflat after subtraction of overscan and
   appropriate superbias image (which is chosen as the superbias with good
   status nearest in time).
 CATEGORY:
    CCD data processing
 CALLING SEQUENCE:
   chknccal
 INPUTS:

 OPTIONAL INPUT PARAMETERS:

 KEYWORD INPUT PARAMETERS:
  CALROOT  - string giving the path to locate the calibration images referenced
             in the data base entries, and created by addnccal. 
             The current default is
             '/kolvir/data1/buie/rawfits/nasacamcal' (on kolvir).
  CALTABLENAME- Name of table in MYSQL database for calibration entries.
             The default is 'calib'. 
  CROP     - region of original image to save, [x1,x2,y1,y2]
             default is 2006 NASACAM default of [21, 2064, 3, 2046].
  DATABASE - Name of MYSQL database for calibration entries.
             The default is 'nasacam'.
  IMGROOT  - string giving the path to locate the image files referenced
             in the data base entries. The default is 
             '/kolvir/data1/buie/rawfits' (on kolvir).
  IMGTABLENAME- Name of table in MYSQL database for image entries.
             The default is 'image'. 
  INSTTABLENAME- Name of table in MYSQL database for instrument entries.
             The default is 'instrument'. 
  KEYFILE-   Default keyfile for PARSEKEY. The default is to provide
             a default key list suitable for nasacam data.
  OVERSCAN - column overscan region to use for frame bias level,
             default is 2006 NASACAM default of [2069, 2103].
  
 OUTPUTS:
 No outputs for this procedure.

 KEYWORD OUTPUT PARAMETERS:
 COMMON BLOCKS:
 SIDE EFFECTS:
    Data base entries are updated.
 RESTRICTIONS:
   Assumes images are located in subdirectories named YYYYMMDD for each night.
   They may be either of the form YYYYMMDD.nnn or YYYYMMDD.nnn.fits
   They may be either of the form YYYYMMDD.nnn or YYYYMMDD.nnn.fits
   Places calibration products in paths named YYYY/MM/DD for each night.
   It currently processes data ONLY for the NASACAM CCD on the 31", and there
   is no support for dark images.
   Image frame numbers must be in the range 1-999 inclusive.
 
 PROCEDURE:
 MODIFICATION HISTORY:
   2006/08/07, Written by Peter L. Collins, Lowell Observatory
   2006/08/10, PLC, fixes to support proper update of edit status
                    buttons with calibration selection, add 'unknown'
                    to editable status states, and proper update of
                    thumbnail and image itool windows on requery & refresh
   2006/08/12, PLC, fixed a bug in the main SQL query that prevented biases
                    from displaying when a filter was selected, also a bug in
                    chknccal_list that occasionally caused the subsuper
                    thumbnail to be displayed in a separate window.
   2006/08/19, PLC, cleanups, made sure dblun closed on exit and
                    set /NO_RELEASE on the Raw/Processed and Set Status
                    radio buttons to eliminate redundant operations.