Index: trunk/ippMonitor/Makefile.in
===================================================================
--- trunk/ippMonitor/Makefile.in	(revision 28969)
+++ trunk/ippMonitor/Makefile.in	(revision 29031)
@@ -61,5 +61,6 @@
 $(DESTWWW)/cleanTmpDirectory.php \
 $(DESTWWW)/warpProcessedExp_Images.php \
-$(DESTWWW)/warpProcessedExp.php
+$(DESTWWW)/warpProcessedExp.php \
+$(DESTWWW)/diskUsage.php
 
 DEFSRC = \
Index: trunk/ippMonitor/raw/diskUsage.php
===================================================================
--- trunk/ippMonitor/raw/diskUsage.php	(revision 29031)
+++ trunk/ippMonitor/raw/diskUsage.php	(revision 29031)
@@ -0,0 +1,206 @@
+<?php 
+
+$restricted = 0;
+$TbyteAll = 0;
+
+include 'ipp.php';
+
+function table_section ($db, $WHERE, $TABLE) {
+
+  global $TbytesAll;
+
+  if ("$TABLE" == "rawExp") {
+    # $sql = "SELECT count(exp_id) as n, state, data_state FROM rawExp join rawImfile using (exp_id) $WHERE";
+    $sql = "SELECT count(exp_id) as n, data_state FROM rawImfile where data_state != 'lossy' and data_state != 'missing' group by data_state";
+    # 3GB per exposures (2 copies, compressed)
+    $unitSize = 50;
+  }
+
+  if ("$TABLE" == "chipRun") {
+    # $sql = "SELECT count(chip_id) as n, state, data_state FROM chipRun join chipProcessedImfile using (chip_id) $WHERE";
+    $sql = "SELECT count(chip_id) as n, data_state FROM chipProcessedImfile where data_state != 'cleaned' and data_state != 'purged' and data_state != 'scrubbed' group by data_state";
+    $unitSize = 60;
+  }
+
+  if ("$TABLE" == "warpRun") {
+    # $sql = "SELECT count(warp_id) as n, state, data_state FROM warpRun join warpSkyfile using (warp_id) $WHERE";
+    $sql = "SELECT count(warp_id) as n, data_state FROM warpSkyfile where data_state != 'cleaned' and data_state != 'purged' and data_state != 'scrubbed' group by data_state";
+    $unitSize = 80;
+  }
+
+  if ("$TABLE" == "diffRun") {
+    # $sql = "SELECT count(diff_id) as n, state, data_state FROM diffRun join diffSkyfile using (diff_id) $WHERE";
+    $sql = "SELECT count(diff_id) as n, data_state FROM diffSkyfile where data_state != 'cleaned' and data_state != 'purged' and data_state != 'scrubbed' group by data_state";
+    $unitSize = 80;
+  }
+
+  $FILTER = "distRun.clean = 1 and distRun.state != 'cleaned'";
+  if ("$TABLE" == "distRawClean") {
+    $sql = "SELECT count(dist_id) as n, distRun.state from distRun join distComponent using (dist_id) where distRun.stage = 'raw' and $FILTER group by distRun.state";
+    echo "<b>$sql</b>\n";
+    $unitSize = 0.5;
+  }
+  
+  if ("$TABLE" == "distChipClean") {
+    $sql = "SELECT count(dist_id) as n, distRun.state from distRun join distComponent using (dist_id) where distRun.stage = 'chip' and $FILTER group by distRun.state";
+    $unitSize = 0.5;
+  }
+
+  if ("$TABLE" == "distWarpClean") {
+    $sql = "SELECT count(dist_id) as n, distRun.state from distRun join distComponent using (dist_id) where distRun.stage = 'warp' and $FILTER  group by distRun.state";
+    $unitSize = 0.5;
+  }
+  
+  if ("$TABLE" == "distDiffClean") {
+    $sql = "SELECT count(dist_id) as n, distRun.state from distRun join distComponent using (dist_id) where distRun.stage = 'diff' and $FILTER  group by distRun.state";
+    $unitSize = 0.5;
+  }
+  
+  $FILTER = "distRun.clean = 0 and distRun.state != 'cleaned'";
+  if ("$TABLE" == "distRawFull") {
+    $sql = "SELECT count(dist_id) as n, distRun.state from distRun join distComponent using (dist_id) where distRun.stage = 'raw' and $FILTER  group by distRun.state";
+    $unitSize = 50;
+  }
+  
+  if ("$TABLE" == "distChipFull") {
+    $sql = "SELECT count(dist_id) as n, distRun.state from distRun join distComponent using (dist_id) where distRun.stage = 'chip' and $FILTER  group by distRun.state";
+    $unitSize = 60;
+  }
+  
+  if ("$TABLE" == "distWarpFull") {
+    $sql = "SELECT count(dist_id) as n, distRun.state from distRun join distComponent using (dist_id) where distRun.stage = 'warp' and $FILTER  group by distRun.state";
+    $unitSize = 80;
+  }
+  
+  if ("$TABLE" == "distDiffFull") {
+    $sql = "SELECT count(dist_id) as n, distRun.state from distRun join distComponent using (dist_id) where distRun.stage = 'diff' and $FILTER  group by distRun.state";
+    $unitSize = 80;
+  }
+
+  $qry = $db->query($sql);
+  if (dberror($qry)) {
+    echo "<tr><td><b>error reading $TABLE table</b></td></tr>\n";
+    echo "<tr><td><br><small><b> table query : $sql </b></small></td></tr>\n";
+  }
+  
+  $class = "list";
+  $nlines = 0;
+  
+  $TbytesSum = 0;
+
+  // list the results
+  while ($qry->fetchInto($row)) {
+    echo "<tr><td class=\"$class\"><b>$TABLE</b></td>\n";
+    // ** TABLE DATA **
+
+    $Tbytes = $row[0]*$unitSize/1000000.0;
+    $TbytesSum += $Tbytes;
+    $TbytesAll += $Tbytes;
+
+    write_table_cell ($class, '%s', "", $row[0]);
+    write_table_cell ($class, '%s', "", $row[1]);
+    write_table_cell ($class, '%s', "", $Tbytes);
+    write_table_cell ($class, '%s', "", $TbytesSum);
+    write_table_cell ($class, '%s', "", $TbytesAll);
+    echo "</tr>\n";
+    $nlines ++;
+  }
+  echo "<tr><td class\"$class\">------</td></tr>\n";
+
+  if ($nlines == 0) {
+    echo "<tr><td class\"$class\"><b>$TABLE</b></td><td>no match</td></tr>\n";
+  }
+}
+
+$ID = checkID ();
+
+// require an explicit project
+if (! $ID['proj']) { projectform ($ID); }
+
+$db = dbconnect($ID['proj']);
+
+if ($ID['menu']) {
+  $myMenu = $ID['menu'];
+} else {
+  $myMenu = "ipp.imfiles.dat";
+}
+
+menu($myMenu, 'Disk Usage', 'ipp.css', $ID['link'], $ID['proj']);
+
+echo "<p> Night Summary </p>\n";
+
+// set up the form
+echo "<form action=\"diskUsage.php\" method=\"POST\">\n";
+
+$restricted = 0;
+
+// define restrictions to the queries
+// ** TABLE RESTRICTIONS **
+$WHERE = check_restrict ('state', $WHERE, 'string', 1.0);
+
+// ensure no valid results
+if ($restricted == 0) {
+   $WHERE = "$WHERE WHERE (0 > 1)";
+}
+
+$WHERE = check_ordering ('state,label', $WHERE);
+
+// set up the table
+echo "<table class=list>\n";
+
+// echo "<tr><td></td>\n"; // first field is a label set below for the query rows only
+// ** TABLE HEADER **
+echo "<tr><td></td>\n";
+write_header_cell ("list", "N items");
+write_header_cell ("list", "state");
+write_header_cell ("list", "Tbytes");
+write_header_cell ("list", "Sum(TB)");
+write_header_cell ("list", "All(TB)");
+echo "</tr>\n";
+
+// query restriction form
+// echo "<tr>\n";
+// echo "<td class=list> <input type=\"text\" name=\"expID\"></td>\n";
+// ** TABLE QUERY ** (restictions)
+echo "<tr><td>Dataset</td>\n";
+write_query_row ('N items', 15, 'string');
+write_query_row ('state', 10, 'string');
+write_query_row ('Mbytes', 7, 'string');
+write_query_row ('Sum(MB)', 7, 'string');
+echo "</tr>\n";
+
+// query the database (limit is 10, but should be 1
+table_section($db, $WHERE, "rawExp");
+table_section($db, $WHERE, "chipRun");
+table_section($db, $WHERE, "warpRun");
+table_section($db, $WHERE, "diffRun");
+
+table_section($db, $WHERE, "distRawClean");
+table_section($db, $WHERE, "distChipClean");
+table_section($db, $WHERE, "distWarpClean");
+table_section($db, $WHERE, "distDiffClean");
+
+table_section($db, $WHERE, "distRawFull");
+table_section($db, $WHERE, "distChipFull");
+table_section($db, $WHERE, "distWarpFull");
+table_section($db, $WHERE, "distDiffFull");
+
+// 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 **
+
+echo "<small> WHERE: $WHERE<br><br></small>\n";
+echo "<small> SQL: $sql<br><br></small>\n";
+
+menu_end();
+
+?>
Index: trunk/ippMonitor/raw/ipp.imfiles.dat
===================================================================
--- trunk/ippMonitor/raw/ipp.imfiles.dat	(revision 28969)
+++ trunk/ippMonitor/raw/ipp.imfiles.dat	(revision 29031)
@@ -38,2 +38,3 @@
 menulink  | menuselect 	 | link    | Tables columns               | columns_in_db.php
 menulink  | menuselect 	 | link    | Clean /tmp directory         | cleanTmpDirectory.php
+menutop   | menutop      | link    | disk usage                   | diskUsage.php
