Index: trunk/ippTools/src/warptool.c
===================================================================
--- trunk/ippTools/src/warptool.c	(revision 11702)
+++ trunk/ippTools/src/warptool.c	(revision 11723)
@@ -32,13 +32,13 @@
 
 static bool definerunMode(pxConfig *config);
-static bool addinputimfileMode(pxConfig *config);
-static bool towarpedimfileMode(pxConfig *config);
-static bool addwarpedimfileMode(pxConfig *config);
-static bool warpedimfileMode(pxConfig *config);
+static bool addinputexpMode(pxConfig *config);
+static bool toscfileMode(pxConfig *config);
+static bool addscfileMode(pxConfig *config);
+static bool scfileMode(pxConfig *config);
 static bool tostackedimfileMode(pxConfig *config);
-static bool addstackedimfileMode(pxConfig *config);
+//static bool addstackedimfileMode(pxConfig *config);
 static bool stackedimfileMode(pxConfig *config);
 static bool todiffimfileMode(pxConfig *config);
-static bool adddiffimfileMode(pxConfig *config);
+//static bool adddiffimfileMode(pxConfig *config);
 static bool diffimfileMode(pxConfig *config);
 
@@ -58,13 +58,13 @@
     switch (config->mode) {
         MODECASE(P4TOOL_MODE_DEFINERUN,         definerunMode);
-        MODECASE(P4TOOL_MODE_ADDINPUTIMFILE,    addinputimfileMode);
-        MODECASE(P4TOOL_MODE_TOWARPEDIMFILE,    towarpedimfileMode);
-        MODECASE(P4TOOL_MODE_ADDWARPEDIMFILE,   addwarpedimfileMode);
-        MODECASE(P4TOOL_MODE_WARPEDIMFILE,      warpedimfileMode);
+        MODECASE(P4TOOL_MODE_ADDINPUTEXP,       addinputexpMode);
+        MODECASE(P4TOOL_MODE_TOSCFILE,          toscfileMode);
+        MODECASE(P4TOOL_MODE_ADDSCFILE,         addscfileMode);
+        MODECASE(P4TOOL_MODE_SCFILE,            scfileMode);
         MODECASE(P4TOOL_MODE_TOSTACKEDIMFILE,   tostackedimfileMode);
-        MODECASE(P4TOOL_MODE_ADDSTACKEDIMFILE,  addstackedimfileMode);
+//        MODECASE(P4TOOL_MODE_ADDSTACKEDIMFILE,  addstackedimfileMode);
         MODECASE(P4TOOL_MODE_STACKEDIMFILE,     stackedimfileMode);
         MODECASE(P4TOOL_MODE_TODIFFIMFILE,      todiffimfileMode);
-        MODECASE(P4TOOL_MODE_ADDDIFFIMFILE,     adddiffimfileMode);
+//        MODECASE(P4TOOL_MODE_ADDDIFFIMFILE,     adddiffimfileMode);
         MODECASE(P4TOOL_MODE_DIFFIMFILE,        diffimfileMode);
         default:
@@ -94,11 +94,11 @@
     // required options
     bool status = false;
-    psString survey_mode = psMetadataLookupStr(&status, config->args, "-survey_mode");
+    psString mode = psMetadataLookupStr(&status, config->args, "-mode");
     if (!status) {
         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -survey_mode");
         return false;
     }
-    if (!survey_mode) {
-        psError(PS_ERR_UNKNOWN, true, "-survery_mode is required");
+    if (!mode) {
+        psError(PS_ERR_UNKNOWN, true, "-mode is required");
         return false;
     }
@@ -111,69 +111,4 @@
     if (!workdir) {
         psError(PS_ERR_UNKNOWN, true, "-workdir is required");
-        return false;
-    }
-
-    psString filter = psMetadataLookupStr(&status, config->args, "-filter");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -filter");
-        return false;
-    }
-    if (!filter) {
-        psError(PS_ERR_UNKNOWN, true, "-survery_mode is required");
-        return false;
-    }
-
-    psString skycell_id = psMetadataLookupStr(&status, config->args, "-skycell_id");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -skycell_id");
-        return false;
-    }
-    if (!skycell_id) {
-        psError(PS_ERR_UNKNOWN, true, "-survery_mode is required");
-        return false;
-    }
-
-    psString tess_id = psMetadataLookupStr(&status, config->args, "-tess_id");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -tess_id");
-        return false;
-    }
-    if (!tess_id) {
-        psError(PS_ERR_UNKNOWN, true, "-survery_mode is required");
-        return false;
-    }
-
-    psS32 imfiles = psMetadataLookupS32(&status, config->args, "-imfiles");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -imfiles");
-        return false;
-    }
-    if (imfiles < 1) {
-        psError(PS_ERR_UNKNOWN, true, "-imfiles is required");
-        return false;
-    }
-
-    // optional options
-    psF64 ra = psMetadataLookupS32(&status, config->args, "-ra");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -ra");
-        return false;
-    }
-
-    psF64 decl = psMetadataLookupS32(&status, config->args, "-decl");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -decl");
-        return false;
-    }
-
-    psString input_ss = psMetadataLookupStr(&status, config->args, "-input_ss");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -input_ss");
-        return false;
-    }
-
-    psString output_ss = psMetadataLookupStr(&status, config->args, "-output_ss");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -output_ss");
         return false;
     }
@@ -195,15 +130,9 @@
 
     p4RunRow *p4Run = p4RunRowAlloc(
-            0,
-            survey_mode,
-            "run",
+            0,          // ID
+            mode,
+            "reg",      // state
             workdir,
-            filter,
-            skycell_id,
-            tess_id,
-            ra,
-            decl,
-            input_ss,
-            output_ss
+            registered
     );
     psFree(registered);
@@ -240,5 +169,5 @@
 }
 
-static bool addinputimfileMode(pxConfig *config)
+static bool addinputexpMode(pxConfig *config)
 {
     PS_ASSERT_PTR_NON_NULL(config, NULL);
@@ -265,14 +194,4 @@
     }
 
-    psString class_id = psMetadataLookupStr(&status, config->args, "-class_id");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -class_id");
-        return false;
-    }
-    if (!class_id) {
-        psError(PS_ERR_UNKNOWN, true, "-class_id is required");
-        return false;
-    }
-
     // defaults to 0
     psS32 p3_version = psMetadataLookupS32(&status, config->args, "-p3_version");
@@ -282,10 +201,17 @@
     }
 
+    // defaults to false
+    bool magiced = psMetadataLookupBool(&status, config->args, "-p3_version");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -p3_version");
+        return false;
+    }
+
     // XXX need to validate the p4_id here
-    if (!p4InputImfileInsert(config->dbh, 
+    if (!p4InputExpInsert(config->dbh, 
             (psS32)atoi(p4_id),
             exp_tag,
             p3_version,
-            class_id
+            magiced
         )) {
         psError(PS_ERR_UNKNOWN, false, "database error");
@@ -296,5 +222,5 @@
 }
 
-static bool towarpedimfileMode(pxConfig *config)
+static bool toscfileMode(pxConfig *config)
 {
     PS_ASSERT_PTR_NON_NULL(config, NULL);
@@ -326,5 +252,5 @@
 
     if (config->where) {
-        psString whereClause = psDBGenerateWhereConditionSQL(config->where, "p4InputImfile");
+        psString whereClause = psDBGenerateWhereConditionSQL(config->where, "p4InputExp");
         psStringAppend(&query, " AND %s", whereClause);
         psFree(whereClause);
@@ -360,5 +286,5 @@
 
     // negative simple so the default is true
-    if (!ippdbPrintMetadatas(stdout, output, "p4InputImfile", !simple)) {
+    if (!ippdbPrintMetadatas(stdout, output, "p4InputExp", !simple)) {
         psError(PS_ERR_UNKNOWN, false, "failed to print array");
         psFree(output);
@@ -371,5 +297,5 @@
 }
 
-static bool addwarpedimfileMode(pxConfig *config)
+static bool addscfileMode(pxConfig *config)
 {
     PS_ASSERT_PTR_NON_NULL(config, NULL);
@@ -386,4 +312,24 @@
     }
 
+    psString skycell_id = psMetadataLookupStr(&status, config->args, "-skycell_id");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -skycell_id");
+        return false;
+    }
+    if (!skycell_id) {
+        psError(PS_ERR_UNKNOWN, true, "-skycell_id is required");
+        return false;
+    }
+
+    psString tess_id = psMetadataLookupStr(&status, config->args, "-tess_id");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -tess_id");
+        return false;
+    }
+    if (!tess_id) {
+        psError(PS_ERR_UNKNOWN, true, "-tess_id is required");
+        return false;
+    }
+
     psString exp_tag = psMetadataLookupStr(&status, config->args, "-exp_tag");
     if (!status) {
@@ -396,14 +342,4 @@
     }
 
-    psString class_id = psMetadataLookupStr(&status, config->args, "-class_id");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -class_id");
-        return false;
-    }
-    if (!class_id) {
-        psError(PS_ERR_UNKNOWN, true, "-class_id is required");
-        return false;
-    }
-
     psString uri = psMetadataLookupStr(&status, config->args, "-uri");
     if (!status) {
@@ -424,25 +360,27 @@
 
     // optional
-    psString b1_uri = psMetadataLookupStr(&status, config->args, "-b1_uri");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -b1_uri");
-        return false;
-    }
-
-    psString b2_uri = psMetadataLookupStr(&status, config->args, "-b2_uri");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -b2_uri");
-        return false;
-    }
+    psF64 bg = psMetadataLookupF64(&status, config->args, "-bg");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -bg");
+        return false;
+    }
+
+    psF64 bg_mean_stdev = psMetadataLookupF64(&status, config->args, "-bg_mean_stdev");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -bg_mean_stdev");
+        return false;
+    }
+
 
     // XXX need to validate that this coresponds to an p4InputImfile
-    if (!p4WarpedImfileInsert(config->dbh, 
+    if (!p4ScfileInsert(config->dbh, 
             (psS32)atoi(p4_id),
+            skycell_id,
+            tess_id,
             exp_tag,
             p3_version,
-            class_id,
             uri,
-            b1_uri,
-            b2_uri
+            bg,
+            bg_mean_stdev
         )) {
         psError(PS_ERR_UNKNOWN, false, "database error");
@@ -453,5 +391,5 @@
 }
 
-static bool warpedimfileMode(pxConfig *config)
+static bool scfileMode(pxConfig *config)
 {
     PS_ASSERT_PTR_NON_NULL(config, NULL);
@@ -459,7 +397,7 @@
     psString query = psStringCopy(
         " SELECT DISTINCT"
-        "   p4WarpedImfile.*"
+        "   p4Scfile.*"
         " FROM p4Run"
-        " JOIN p4WarpedImfile"
+        " JOIN p4Scfile"
         "   USING(p4_id)"
         " WHERE"
@@ -468,5 +406,5 @@
 
     if (config->where) {
-        psString whereClause = psDBGenerateWhereConditionSQL(config->where, "p4WarpedImfile");
+        psString whereClause = psDBGenerateWhereConditionSQL(config->where, "p4Scfile");
         psStringAppend(&query, " AND %s", whereClause);
         psFree(whereClause);
@@ -486,5 +424,5 @@
     }
     if (!psArrayLength(output)) {
-        psError(PS_ERR_UNKNOWN, false, "no p4WarpedImfile rows found");
+        psError(PS_ERR_UNKNOWN, false, "no p4Scfile rows found");
         psFree(output);
         return true;
@@ -502,5 +440,5 @@
 
     // negative simple so the default is true
-    if (!ippdbPrintMetadatas(stdout, output, "p4WarpedImfile", !simple)) {
+    if (!ippdbPrintMetadatas(stdout, output, "p4Scfile", !simple)) {
         psError(PS_ERR_UNKNOWN, false, "failed to print array");
         psFree(output);
@@ -578,4 +516,5 @@
 }
 
+#if 0
 static bool addstackedimfileMode(pxConfig *config)
 {
@@ -640,4 +579,5 @@
     return true;
 }
+#endif
 
 static bool stackedimfileMode(pxConfig *config)
@@ -774,4 +714,5 @@
 }
 
+#if 0
 static bool adddiffimfileMode(pxConfig *config)
 {
@@ -855,4 +796,5 @@
     return true;
 }
+#endif
 
 static bool diffimfileMode(pxConfig *config)
