Index: trunk/ippMonitor/Makefile
===================================================================
--- trunk/ippMonitor/Makefile	(revision 9010)
+++ trunk/ippMonitor/Makefile	(revision 9011)
@@ -25,5 +25,6 @@
 
 DEFSRC = \
-$(DESTBIN)/masterDetrendImages.php \
+$(DESTBIN)/masterDetrendFrames.php \
+$(DESTBIN)/masterDetrendImfiles.php \
 $(DESTBIN)/detInputExp.php \
 $(DESTBIN)/detMasterFrame.php \
Index: trunk/ippMonitor/def/README
===================================================================
--- trunk/ippMonitor/def/README	(revision 9011)
+++ trunk/ippMonitor/def/README	(revision 9011)
@@ -0,0 +1,96 @@
+
+Each of the *.d files in this directory (except example.d) are used to
+define a page in the ipp web tools which show the contents of a
+database table (or tables).  There are also pages which do not refer
+to a specific database table: these are defined in ../raw and are not
+pre-processed with the 'generate' function.  The contents of the
+description file are confronted with a template file and used to
+generate PHP code.  
+
+The layout of each page is essentially the same: the page is divided
+into a main data area and a left-hand side navigation table.  The
+contents of the navigation table are defined by the menu definition
+file specified for the page.  The data area includes the following
+elements:
+
+- TITLE
+- HEAD (html or php code)
+- TABLE
+- TAIL (html or php code)
+
+The *.d file defines each of these regions with a set of rules.  Each
+rule is specified on a single line, and begins with one of the defined
+keywords.  Several keywords are required to be unique (eg, TABLE and
+TITLE) while others may be repeated (eg, WHERE, FIELD).  For most of
+the keywords, there is no fixed format for the value, but in the case
+of the FIELD keyword, care must be taken to follow the mandatory
+syntax. 
+
+The TITLE is define by a single, fixed keyword (TITLE).
+
+The HEAD and TAIL regions are defined by the HEAD and TAIL lines, and
+are optional.  Each HEAD or TAIL line is followed by a word defining
+the code type (may be HTML or PHP).  The rest of the line defines code
+which is interpreted as either HTML or PHP.  These replace the lines
+"// ** HEAD CODE **" and "// ** TAIL CODE **" in the template file.
+
+By default, the menu definition file for the page is defined by the
+specified MENU key.  If, however, the page is passed a "menu=XXXX"
+directive (either via GET or POST), then the specified file is used
+instead as a menu definition file.  This mechanism is used to allow
+the same table definition page to be linked from different locations
+in the pages and have the same appearence as the referencing page.
+
+The rest of the file defines the displayed contents of the table.  The
+page generates an HTML table based on a query of one (or possibly more
+than one, see below) database tables.  The table used for the query is
+specified by the TABLE key.  An SQL command is generated based on the
+requested fields, defined by the FIELD keys.  If desired, WHERE
+statements may be added to the SQL command with the WHERE key.  Each
+line marked by WHERE is appended (with AND) to the SQL WHERE clause.  
+
+The FIELDS lines define both the queried fields and the rules for
+presenting the fields in the HTML table.  Each FIELD row results in a
+column in the output HTML table, unless otherwise noted (see below).
+Each FIELD row also corresponds to a queried field from the database
+table, again unless otherwise noted.  Each FIELD command is followed
+by a set of comma-separated values.  The first entry defines the name
+of the database table field.  The second entry defines the minimum
+width of the column.  The third entry defines the column header.  The
+rest of the entries are optional.  The fourth entry specifies what is
+placed in the cell, and may consist of:
+
+- the string "value", in which case the corresponding data entry from
+the database for the column and row are used to fill the cell.  This
+is the default behavior.
+
+- the string "value=XXX", in which case the cell is filled with the
+value of XXX instead of the corresponding database cell value.  If XXX
+consists of one of the specified database fields, that column's data
+for this row is substituted instead.  
+
+- the string "image=XXX", in which case the cell is filled with the
+image represented by the URI XXX.  
+
+- the string "none", in which case the cell is column in the output
+HTML table.  Such elements are needed to lookup a value from the
+database (ie, to be passed to links, see below) but not to display the
+value in the table.
+
+The fifth entry defines an optional link for the cell.  If this field
+is set, a link is created for the cell using the given word as the
+target of the link.  The link will also have the mandatory GET data
+attached (including the menu and the pass data needed to validate the
+user).  
+
+The sixth entry is used to specify additional information passed to
+the linked page via GET data elements.  These are typically of the
+form "word=value", and may include multiple comma separated
+entries. If the value elements consist of $field where field is one of
+the valid database field names, this value for the current row is
+passed with the link.
+
+If the first entry of the FIELD row has the value "*", then the row
+is NOT used to define a database field; it is only used to define an
+output column in the HTML table.
+
Index: trunk/ippMonitor/def/autocode.php
===================================================================
--- trunk/ippMonitor/def/autocode.php	(revision 9010)
+++ trunk/ippMonitor/def/autocode.php	(revision 9011)
@@ -20,6 +20,4 @@
 // ** TABLE RESTRICTIONS **
 
-echo "WHERE: $WHERE<br><br>\n";
-
 // query the database
 if ($WHERE) {
@@ -28,6 +26,4 @@
   $sql = "SELECT $FIELDS FROM $TABLE LIMIT 20";
 }
-
-echo "SQL: $sql<br><br>\n";
 
 $qry = $db->query($sql);
@@ -78,4 +74,7 @@
 // ** TAIL CODE **
 
+echo "<small> WHERE: $WHERE<br><br></small>\n";
+echo "<small> SQL: $sql<br><br></small>\n";
+
 menu_end();
 
Index: trunk/ippMonitor/def/detInputExp.d
===================================================================
--- trunk/ippMonitor/def/detInputExp.d	(revision 9010)
+++ trunk/ippMonitor/def/detInputExp.d	(revision 9011)
@@ -9,8 +9,8 @@
 
 #     field      width 	name        show  link to                 extras
+FIELD exp_id,    20,   	exposure,   value,      rawImfile.php,          exp_id=$exp_id,det_id=$det_id,iteration=$iteration
+FIELD *,         5,    	choose,     value=proc, detProcessedImfile.php, exp_id=$exp_id,det_id=$det_id,iteration=$iteration
 FIELD det_id,    7,    	det_id
 FIELD iteration, 5,    	iteration
-FIELD exp_id,    20,   	exposure,   value,      rawImfile.php,          exp_id=$exp_id,det_id=$det_id,iteration=$iteration
-FIELD *,         5,    	choose,     value=proc, detProcessedImfile.php, exp_id=$exp_id,det_id=$det_id,iteration=$iteration
 FIELD include,   7,   	include
 
Index: trunk/ippMonitor/def/detProcessedImfile.d
===================================================================
--- trunk/ippMonitor/def/detProcessedImfile.d	(revision 9010)
+++ trunk/ippMonitor/def/detProcessedImfile.d	(revision 9011)
@@ -8,10 +8,10 @@
 
 #     field     name      show   link to     extras
-FIELD det_id,   20,   det_id
-FIELD exp_id, 	20,   exp_id
-FIELD class_id, 20,   class_id
+FIELD det_id,    7,   Detrend Run ID
+FIELD exp_id, 	15,   Exposure
+FIELD class_id, 10,   Chip ID
+FIELD bg, 	10,   bg
+FIELD bg_stdev, 10,   bg_stdev
 FIELD uri, 	20,   uri
 FIELD recipe, 	20,   recipe
-FIELD bg, 	20,   bg
-FIELD bg_stdev, 20,   bg_stdev
-FIELD bg_mean_stdev, 20,   bg_mean_stdev
+# FIELD bg_mean_stdev, 20,   bg_mean_stdev
Index: trunk/ippMonitor/def/detResidExp.d
===================================================================
--- trunk/ippMonitor/def/detResidExp.d	(revision 9010)
+++ trunk/ippMonitor/def/detResidExp.d	(revision 9011)
@@ -5,7 +5,7 @@
 
 #     field      name       show            link to             extras
-FIELD det_id,    20,   det_id,    value
-FIELD iteration, 20,   iteration, value
-FIELD accept,    20,   accept,    value
+FIELD det_id,     7,   Det ID,    value
+FIELD iteration,  5,   iter,      value
+FIELD accept,     4,   keep,      value
 FIELD exp_id, 	 20,   exp_id,    value,          rawImfile.php,      exp_id=$exp_id
 FIELD b2_uri, 	 20,   b2_uri,    image=$b2_uri,  detResidImfile.php, det_id=$det_id,iteration=$iteration,exp_id=$exp_id,image=$b1_uri
Index: trunk/ippMonitor/def/detRunSummary.d
===================================================================
--- trunk/ippMonitor/def/detRunSummary.d	(revision 9010)
+++ trunk/ippMonitor/def/detRunSummary.d	(revision 9011)
@@ -7,5 +7,5 @@
 FIELD det_id,    7,    det_id    
 FIELD iteration, 5,    iter
-FIELD accept,    20,   accept
+FIELD accept,    4,    keep
 FIELD *,         20,   choose,    value=input, detInputExp.php,  det_id=$det_id,iteration=$iteration
 FIELD *,         20,   choose,    value=resid, detResidExp.php,  det_id=$det_id,iteration=$iteration
Index: trunk/ippMonitor/def/masterDetrendFrames.d
===================================================================
--- trunk/ippMonitor/def/masterDetrendFrames.d	(revision 9011)
+++ trunk/ippMonitor/def/masterDetrendFrames.d	(revision 9011)
@@ -0,0 +1,30 @@
+# this file is based on the detRunSummary.d file: it uses the same tables restricted to the 
+# master detrend runs which have been accepted
+
+TABLE detRunSummary, detRun
+TITLE Master Detrend Frames
+FILE  masterDetrendFrames.php
+MENU  ipp.detrend.dat
+
+# the following WHERE clauses are added to all queries joined by AND
+WHERE detRunSummary.accept = 1
+WHERE detRun.position = detRunSummary.det_id
+WHERE detRun.iteration = detRunSummary.iteration
+
+#     field                    width name          show         link to            extras
+FIELD detRunSummary.det_id,    7,    det_id,       value,       detRunSummary.php, det_id=$detRunSummary.det_id
+FIELD detRunSummary.iteration, 5,    iter
+FIELD detRun.det_type,         5,    type
+FIELD *,                       20,   choose,       value=files, masterDetrendImfiles.php,  det_id=$detRunSummary.det_id,iteration=$detRunSummary.iteration
+FIELD *,                       20,   choose,       value=input, detInputExp.php,  det_id=$detRunSummary.det_id,iteration=$detRunSummary.iteration
+FIELD *,                       20,   choose,       value=resid, detResidExp.php,  det_id=$detRunSummary.det_id,iteration=$detRunSummary.iteration
+FIELD detRunSummary.bg,        20,   bg
+FIELD detRunSummary.bg_stdev,  20,   bg_stdev
+# FIELD bg_mean_stdev, 20,   bg_mean_stdev
+
+# this file illustrates a simple inner join to generate the output table
+# assuming no other dynamic restrictions are added, this generates the following query:
+# SELECT detRunSummary.det_id,detRunSummary.iteration,detRunSummary.iteration,detRun.det_type,detRunSummary.bg,detRunSummary.bg_stdev \
+# FROM detRunSummary, detRun \
+# WHERE detRunSummary.accept = 1 AND detRun.position = detRunSummary.det_id AND detRun.iteration = detRunSummary.iteration \
+# LIMIT 20
Index: trunk/ippMonitor/def/masterDetrendImages.d
===================================================================
--- trunk/ippMonitor/def/masterDetrendImages.d	(revision 9010)
+++ 	(revision )
@@ -1,29 +1,0 @@
-# this file is based on the detRunSummary.d file: it uses the same tables restricted to the 
-# master detrend runs which have been accepted
-
-TABLE detRunSummary, detRun
-TITLE Master Detrend Images
-FILE  masterDetrendImages.php
-MENU  ipp.detrend.dat
-
-# the following WHERE clauses are added to all queries joined by AND
-WHERE detRunSummary.accept = 1
-WHERE detRun.position = detRunSummary.det_id
-WHERE detRun.iteration = detRunSummary.iteration
-
-#     field                    width name          show         link to            extras
-FIELD detRunSummary.det_id,    7,    det_id,       value,       detRunSummary.php, det_id=$detRunSummary.det_id
-FIELD detRun.det_type,         5,    type
-FIELD detRunSummary.iteration, 5,    iter
-FIELD *,                       20,   choose,       value=input, detInputExp.php,  det_id=$detRunSummary.det_id,iteration=$detRunSummary.iteration
-FIELD *,                       20,   choose,       value=resid, detResidExp.php,  det_id=$detRunSummary.det_id,iteration=$detRunSummary.iteration
-FIELD detRunSummary.bg,        20,   bg
-FIELD detRunSummary.bg_stdev,  20,   bg_stdev
-# FIELD bg_mean_stdev, 20,   bg_mean_stdev
-
-# this file illustrates a simple inner join to generate the output table
-# assuming no other dynamic restrictions are added, this generates the following query:
-# SELECT detRunSummary.det_id,detRunSummary.iteration,detRunSummary.iteration,detRun.det_type,detRunSummary.bg,detRunSummary.bg_stdev \
-# FROM detRunSummary, detRun \
-# WHERE detRunSummary.accept = 1 AND detRun.position = detRunSummary.det_id AND detRun.iteration = detRunSummary.iteration \
-# LIMIT 20
Index: trunk/ippMonitor/def/masterDetrendImfiles.d.src
===================================================================
--- trunk/ippMonitor/def/masterDetrendImfiles.d.src	(revision 9011)
+++ trunk/ippMonitor/def/masterDetrendImfiles.d.src	(revision 9011)
@@ -0,0 +1,19 @@
+# this file is based on the detRunSummary.d file: it uses the same tables restricted to the 
+# master detrend runs which have been accepted
+
+TABLE detStackedImfile
+TITLE Master Detrend Imfiles
+FILE  masterDetrendImfiles.php
+MENU  ipp.detrend.dat
+
+#     field      width name          show         link to            extras
+FIELD det_id,    7,    det_id
+FIELD iteration, 5,    iter
+FIELD uri,       5,    uri
+
+# this file illustrates a simple inner join to generate the output table
+# assuming no other dynamic restrictions are added, this generates the following query:
+# SELECT detRunSummary.det_id,detRunSummary.iteration,detRunSummary.iteration,detRun.det_type,detRunSummary.bg,detRunSummary.bg_stdev \
+# FROM detRunSummary, detRun \
+# WHERE detRunSummary.accept = 1 AND detRun.position = detRunSummary.det_id AND detRun.iteration = detRunSummary.iteration \
+# LIMIT 20
Index: trunk/ippMonitor/def/rawImfile.d
===================================================================
--- trunk/ippMonitor/def/rawImfile.d	(revision 9010)
+++ trunk/ippMonitor/def/rawImfile.d	(revision 9011)
@@ -4,10 +4,9 @@
 MENU  ipp.imfiles.dat
 
-RESTRICT exp_id
-RESTRICT class_id
-
-#        field        name           show   link to         extras
-FIELD    exp_id,      20,   Exposure ID
-FIELD    class_id,    20,   Class ID
+#        field        name   show         link to         extras
+FIELD    exp_id,      15,    Exposure
+FIELD    class_id,    8,     Chip ID
+FIELD    bg,	      20,    backgnd
+FIELD    bg_stdev,    20,    backgnd stdev
 # FIELD    class,       20,   Class
 # FIELD    uri,	      20,   uri
@@ -18,6 +17,4 @@
 # FIELD    decl,      20,   decl
 # FIELD    exp_time,  20,   exp_time
-FIELD    bg,	      20,   bg
-FIELD    bg_stdev,  20,   bg_stdev
 # FIELD    bg_mean_stdev, 20,   bg_mean_stdev
 # FIELD    alt,       20,   alt
Index: trunk/ippMonitor/raw/ipp.detrend.dat
===================================================================
--- trunk/ippMonitor/raw/ipp.detrend.dat	(revision 9010)
+++ trunk/ippMonitor/raw/ipp.detrend.dat	(revision 9011)
@@ -23,5 +23,5 @@
 
 menutop   | menutop      | plain   | &nbsp;                       | 
-menulink  | menuselect 	 | link    | Master Detrend Images        | masterDetrendImages.php
+menulink  | menuselect 	 | link    | Master Detrend Frames        | masterDetrendFrames.php
 menulink  | menuselect 	 | link    | Detrend Runs                 | detRunSummary.php             
 menulink  | menuselect 	 | link    | Input Detrend Exp            | detInputExp.php                    
Index: trunk/ippMonitor/raw/masterDetrendImfiles.php
===================================================================
--- trunk/ippMonitor/raw/masterDetrendImfiles.php	(revision 9011)
+++ trunk/ippMonitor/raw/masterDetrendImfiles.php	(revision 9011)
@@ -0,0 +1,94 @@
+<?php 
+
+include 'ipp.php';
+
+$ID = checkID ();
+
+if ($ID['menu']) {
+  $myMenu = $ID['menu'];
+} else {
+  $myMenu = "ipp.detrend.dat";
+}
+
+menu($myMenu, 'Master Detrend Imfiles', 'ipp.css', $ID['link']);
+
+echo "<p> Master Detrend Imfiles </p>";
+
+$db = dbconnect();
+
+// define restrictiosn to the queries
+// ** TABLE RESTRICTIONS **
+$WHERE = check_restrict ('det_id', $WHERE);
+$WHERE = check_restrict ('iteration', $WHERE);
+$WHERE = check_restrict ('uri', $WHERE);
+
+echo "WHERE: $WHERE<br><br>\n";
+
+// query the database
+if ($WHERE) {
+  $sql = "SELECT det_id,iteration,uri FROM detNormalizedImfile WHERE $WHERE UNION SELECT det_id,iteration,uri FROM detStackedImfile WHERE normalize = 0 AND $WHERE LIMIT 20";
+} else {
+  $sql = "SELECT det_id,iteration,uri FROM detNormalizedImfile UNION SELECT det_id,iteration,uri FROM detStackedImfile WHERE normalize = 0 LIMIT 20";
+}
+
+echo "SQL: $sql<br><br>\n";
+
+$qry = $db->query($sql);
+if (DB::iserror($db)) {
+  echo "<b>error reading detStackedImfile table</b><br>\n";
+  menu_end();
+}
+
+// ** HEAD CODE **
+
+// set up the table and form
+echo "<form action=\"masterDetrendImfiles.php\" method=\"POST\">\n";
+
+echo "<table class=list>\n";
+echo "<tr>\n";
+// ** TABLE HEADER **
+echo "<th class=\"list\"> det_id </th>\n";
+echo "<th class=\"list\"> iter </th>\n";
+echo "<th class=\"list\"> uri </th>\n";
+// echo "<th class=list> FIELD </th>\n";
+echo "</tr>\n";
+
+// list the results
+while ($qry->fetchInto($row)) {
+  // $link = "masterDetrendImfiles.php" . "?expID=" . $row[0] . "&" . $ID['link'];
+
+  echo "<tr>\n";
+  // ** TABLE DATA **
+  echo "<td class=\"list\"> $row[0] </td>\n";
+  echo "<td class=\"list\"> $row[1] </td>\n";
+  echo "<td class=\"list\"> $row[2] </td>\n";
+  // echo "<td class=list><a href=\"$link\"> $row[0] </a></td>\n";
+  // echo "<td class=list> $row[1] </td>\n";
+  echo "</tr>\n";
+}
+
+// query restriction form
+echo "<tr>\n";
+// echo "<td class=list> <input type=\"text\" name=\"expID\"></td>\n";
+// ** TABLE QUERY **
+write_query_row ('det_id', 7);
+write_query_row ('iteration', 5);
+write_query_row ('uri', 5);
+echo "</tr>\n";
+
+// close the table and form
+echo "</table>\n";
+echo "<input type=\"submit\" name=\"constraints\" value=\"refine search\">\n";
+$pass = $ID['pass'];
+$proj = $ID['proj'];
+$menu = $ID['menu'];
+echo "<input type=\"hidden\" name=\"pass\" value=\"$pass\">\n";
+echo "<input type=\"hidden\" name=\"proj\" value=\"$proj\">\n";
+echo "<input type=\"hidden\" name=\"menu\" value=\"$menu\">\n";
+echo "</form>\n";
+
+// ** TAIL CODE **
+
+menu_end();
+
+?>
