NAME:
  reduc
 PURPOSE:
  Photometry reduction widget for using reductor.
 DESCRIPTION:
 Locates reduction directory and builds and/or edits the
 reduc.inf file. It allows user to run reductor when desired
 and appropriate. Reduc allows one 1 rule line only to be run
 at a time.
 CATEGORY:
  Photometry
 CALLING SEQUENCE:
  reduc
 INPUTS:
 OPTIONAL INPUT PARAMETERS:
 KEYWORD INPUT PARAMETERS:
 BROWSE-     Flag, if set, will not allow editing of reduc.inf or running
                reductor (for any reason), but will display all information,
                with edit windows disabled.
 DATATABLE-  Alternate table for data table access in the photometry
                data base ('phot'). If not specified the 'data' table is used.
                This keyword is also passed to reductor and through to dbphot.
                It is a string- if it is of the form 'd.t' where d and t
                are non-null substrings, d is taken to be a database name
                and t is the table. If t is a null string, it is individually
                defaulted as phot.
 DIR -       Directory for reduc to run. This should be a directory with
                rundate (yymmdd) directories beneath. If not specified, the
                default is '/net/frakir/raid/buie/Reduced'.
 INSTDB   -  Alternate database for instrument queries and updates. A string 
                giving an alternate database to query for the runstat and
                image table.
                This is a single data base to be usd for all instruments.
                If it is set to a string with an embedded dot 'd.t'
                the table name searched is changed to t, and the data
                base is taken as d. If it is of the form
                {a,b,c} where a, b, c ... are either of the form 'd'
                or 'd.t' then it represents a list of databases/tables
                to be searched in order.
                If not specified, the runstat table is accessed in the
                instrument databases roboccd, pccdobs and pccd2obs.
                ie, equivalent to 
                '{pccd2obs.runstat,pccdobs.runstat,roboccd.runstat]'
                The image table is always 'x.image' where x is the 
                database where the rundate was found with the INSTDB
                search.
 INSTDEFTABLE-Alternate table for instdef table access in the photometry
               data base ('phot'). If  unspecified the 'instdef' table is used.
               The 'd.t' format (see DATATABLE keyword) is also supported.
 NOTESXSIZE- Size of notes widget in columns, default 80.
 NOTESYSIZE- Size of notes widget in rows, default 5.
 TRANSFTABLE-Alternate table for transformation table access in the photometry
               data base ('phot'). If not specified the 'transf' table is used.
               The 'd.t' format (see DATATABLE keyword) is also supported.
 
 OUTPUTS:
 KEYWORD OUTPUT PARAMETERS:
 COMMON BLOCKS:
 SIDE EFFECTS:
 Reduc rewrites the reduc.inf file in the reduction directory to which
 it is directed, and also runs reductor, under control of the user.
 It may update the runstat table in one or more of the instrument data bases.
 RESTRICTIONS:
 Code needs some internal reorganization.
 Reduc is not well protected against badly formed reduc.inf lines.
 The search for rundate in the data bases controlled by INSTDB is
 amended in the case of pccdobs only- the select will include
 INST = 'L'  AND'd with the usual RUNDATE = 'xxxxxx'
 If a data base name in INSTDB is nondefault, the instrument pertaining
 is assumed to be PCCD.

 Reduc/reductor don't allow the same rundate for different instruments.
 PROCEDURE:
 MODIFICATION HISTORY:
  Written by Peter L. Collins, 2006/09/07, Lowell Observatory
  2006/09/18, PLC, some fixes, especially to add/delete lines from menu bar.
  2006/10/03,PLC, many fixes and additions.
  2006/10/05,PLC, small changes to run reductor buttons and display of
                  transf data base in the detail (per rule) window.
  2006/10/18,PLC, many changes including runstat (db) edit and selection.
  2006/10/19,PLC, adding reports.
  2006/10/23, PLC, transf and object observation reports, 'database only' mode.
  2006/11/03,PLC,  modified Prev/Next and Enter Rundate to search for best
                   available rundate based on search criteria and context.
  2006/11/04,PLC,  added 'Not' qualifier to Autostep criteria.
  2006/11/06,PLC,  fixes for non existent reduc directory when trying to write
                   reduc.log for runstat edits, and non-existent ddir check
                   and modifier for "no cal directory" message. New img report.
  2006/11/07,PLC,  allow notes update to function normally in browse mode. Add
                   print for edit runstat query (ie, all db updates get print).
  2006/11/09,PLC,  add all observations report and incorporate mysqlquery fix
                   in imglistreport.
  2006/12/07,PLC,  slightly rationalized color filter handling, fixed calls
                   to qinput and qannounc to enforce modality, changes for 
                   new phot.data format.
  2006/12/09,PLC,  add DATATABLE keyword.
  2006/12/12,PLC,  fix bug in run reduc so force pulldown menus preserve
                   state, change menu for hardcopy to dropdown near buttons,
                   rationalize browse/edit modes.
  2006/12/14,PLC,  some bug fixes and added reduc_nightbad to remove data
                   records and mark transf records bad when a night marked 
                   bad (sky non-phot or status bad). Add default color term
                   forcing widget buttons and menu bar edit options. Add
                   sky and stat outputs to transf report.
  2006/12/16,PLC,  big rearrangement of code- alphabetize, remove secondary and
                   subevents.
  2006/12/19, PLC, Added support for /SAVEALLPLOTS option to reductor
                   and for transition to 'reduced' runstatus.
  2006/12/30,PLC,  further rationalized handling of rundate and status 
                   processing, current directory management, and extended the 
                   definition of the database table keywords. Recomissioned
                   the run reductor buttons in upper gui and removed /NORUN.
                   Added maintenance bar with options for verbosity. Allowed
                   "Recompute Log1 File" to always work as long as rundir is
                   not read-only. It is the same as the regular run reductor
                   button except that all rules are disabled and /NOSAVE is
                   not allowed. 
  2007/01/04,PLC,  Changed 'Enter Rundate' menu operation to use autostep 
                   criteria when picking rundates to go to when the rundate
                   entered is not available.
                   Upgraded rundate selection idl screen error output.
                   Modified order of directory evaluation when changing
                   rundate to avoid accessing rundir when runstat is such
                   that the directory will be hidden.
                   Added a qannounc for rundate transitioning to reduced 
                   status prior to running the rules in SAVEALLPLOTS mode.
 2007/01/05,PLC,   Added call to plpedit to edit log1 bd flags via the edit
                   menu bar, and
                   commented out raw->cal processing stuff in reduc_setstatsky,
                   at least for now.
 2007/01/10,PLC,   fixed a logic hole that prevented the runstat Stat and Sky
                   from being displayed if a rule was selected while editing
                   former. The fix was in reduc_newrundisp.
 2007/01/20,PLC,   Several fixes to get queries and updates to  db 'pccdobs' 
                   to use the 1 letter 'inst' code correctly. The major
                   one was to reduc_dbstr2hook to strtrim database name.
 2007/02/15, PLC,  Modify queries to phot.data to reflect addition of Color
                   column.
 2007/02/20, MWB, Added DP rule clump
 2007/02/21, MWB, Further cleanup and exception handling.
 2008/06/19, MWB, repaired a logic problem with 'sl' rule display information.
                    Remember, there may be more in phot.data than what comes
                    from this program!
 2008/09/15, MWB, image list broken for roboccd, fixed mysql query