Index: trunk/ippTools/src/regtool.c
===================================================================
--- trunk/ippTools/src/regtool.c	(revision 18402)
+++ trunk/ippTools/src/regtool.c	(revision 18561)
@@ -297,8 +297,4 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
-    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
-    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
-    PXOPT_LOOKUP_BOOL(faulted, config->args, "-faulted", false);
-
     psMetadata *where = psMetadataAlloc();
     PXOPT_COPY_S64(config->args, where,  "-exp_id", "exp_id", "==");
@@ -306,4 +302,8 @@
     PXOPT_COPY_STR(config->args, where,  "-class_id", "class_id", "==");
 
+    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
+    PXOPT_LOOKUP_BOOL(faulted, config->args, "-faulted", false);
+    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
+
     psString query = pxDataGet("regtool_processedimfile.sql");
     if (!query) {
@@ -313,5 +313,5 @@
     }
 
-    if (where) {
+    if (psListLength(where->list)) {
         psString whereClause = psDBGenerateWhereConditionSQL(where, "rawImfile");
         psStringAppend(&query, " AND %s", whereClause);
@@ -381,15 +381,23 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
+    psMetadata *where = psMetadataAlloc();
+    PXOPT_COPY_S64(config->args, where,  "-exp_id",       "exp_id", "==");
+    PXOPT_COPY_STR(config->args, where,  "-tmp_class_id", "tmp_class_id", "==");
+    PXOPT_COPY_STR(config->args, where,  "-class_id",     "class_id", "==");
+    PXOPT_COPY_S16(config->args, where,  "-code",         "fault", "==");
+
     psString query = pxDataGet("regtool_revertprocessedimfile.sql");
     if (!query) {
         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
-        return false;
-    }
-
-    if (config->where) {
-        psString whereClause = psDBGenerateWhereConditionSQL(config->where, "rawImfile");
+	psFree(where);
+        return false;
+    }
+
+    if (psListLength(where->list)) {
+        psString whereClause = psDBGenerateWhereConditionSQL(where, "rawImfile");
         psStringAppend(&query, " AND %s", whereClause);
         psFree(whereClause);
     }
+    psFree(where);
 
     if (!p_psDBRunQuery(config->dbh, query)) {
@@ -413,10 +421,16 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
+    psMetadata *where = psMetadataAlloc();
+    PXOPT_COPY_S64(config->args, where,  "-exp_id",       "exp_id", "==");
+    PXOPT_COPY_STR(config->args, where,  "-class_id",     "class_id", "==");
+
     PXOPT_LOOKUP_S16(code, config->args, "-code", true, false);
 
-    if (!pxSetFaultCode(config->dbh, "rawImfile", config->where, code)) {
+    if (!pxSetFaultCode(config->dbh, "rawImfile", where, code)) {
         psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag");
-        return false;
-    }
+	psFree (where);
+        return false;
+    }
+    psFree (where);
 
     return true;
@@ -511,9 +525,10 @@
 
     // optional
+    PXOPT_LOOKUP_TIME(dateobs, config->args, "-dateobs", false, false);
+    PXOPT_LOOKUP_STR(exp_type, config->args, "-exp_type", false, false);
+    PXOPT_LOOKUP_STR(workdir, config->args, "-workdir", false, false);
     PXOPT_LOOKUP_STR(dvodb, config->args, "-dvodb", false, false);
     PXOPT_LOOKUP_STR(tess_id, config->args, "-tess_id", false, false);
     PXOPT_LOOKUP_STR(end_stage, config->args, "-end_stage", false, false);
-    PXOPT_LOOKUP_STR(exp_type, config->args, "-exp_type", false, false);
-    PXOPT_LOOKUP_STR(workdir, config->args, "-workdir", false, false);
     PXOPT_LOOKUP_STR(reduction, config->args, "-reduction", false, false);
     PXOPT_LOOKUP_STR(filter, config->args, "-filter", false, false);
@@ -561,5 +576,4 @@
     PXOPT_LOOKUP_STR(label,  config->args, "-label", false, false);
     PXOPT_LOOKUP_STR(hostname, config->args, "-hostname", false, false);
-    PXOPT_LOOKUP_TIME(dateobs, config->args, "-dateobs", false, false);
 
     // default
@@ -789,8 +803,4 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
-    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
-    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
-    PXOPT_LOOKUP_BOOL(faulted, config->args, "-faulted", false);
-
     psString query = pxDataGet("regtool_processedexp.sql");
     if (!query) {
@@ -812,6 +822,6 @@
     PXOPT_COPY_STR(config->args, where,  "-reduction", "reduction", "==");
     PXOPT_COPY_STR(config->args, where,  "-filter", "filter", "==");
-    PXOPT_COPY_F64(config->args, where,  "-airmass_min", "airmass", ">=");
-    PXOPT_COPY_F64(config->args, where,  "-airmass_max", "airmass", "<");
+    PXOPT_COPY_F32(config->args, where,  "-airmass_min", "airmass", ">=");
+    PXOPT_COPY_F32(config->args, where,  "-airmass_max", "airmass", "<");
     PXOPT_COPY_F64(config->args, where,  "-ra_min", "ra", ">=");
     PXOPT_COPY_F64(config->args, where,  "-ra_max", "ra", "<");
@@ -832,6 +842,6 @@
     PXOPT_COPY_F64(config->args, where,  "-az_min", "az", ">=");
     PXOPT_COPY_F64(config->args, where,  "-az_max", "az", "<");
-    PXOPT_COPY_F32(config->args, where,  "-ccd_temp_min", "ccd_temp", ">=");
-    PXOPT_COPY_F32(config->args, where,  "-ccd_temp_max", "ccd_temp", "<");
+    PXOPT_COPY_F64(config->args, where,  "-ccd_temp_min", "ccd_temp", ">=");
+    PXOPT_COPY_F64(config->args, where,  "-ccd_temp_max", "ccd_temp", "<");
     PXOPT_COPY_F64(config->args, where,  "-posang_min", "posang", ">=");
     PXOPT_COPY_F64(config->args, where,  "-posang_max", "posang", "<");
@@ -839,4 +849,8 @@
     PXOPT_COPY_F32(config->args, where,  "-solang_min", "solang", ">=");
     PXOPT_COPY_F32(config->args, where,  "-solang_max", "solang", "<");
+
+    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
+    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
+    PXOPT_LOOKUP_BOOL(faulted, config->args, "-faulted", false);
 
     if (psListLength(where->list)) {
@@ -906,15 +920,22 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
+    psMetadata *where = psMetadataAlloc();
+    PXOPT_COPY_S64(config->args, where,  "-exp_id",       "exp_id", "==");
+    PXOPT_COPY_S16(config->args, where,  "-code",         "fault", "==");
+
     psString query = pxDataGet("regtool_revertprocessedexp.sql");
     if (!query) {
         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
-        return false;
-    }
-
-    if (config->where) {
-        psString whereClause = psDBGenerateWhereConditionSQL(config->where, "rawExp");
+	psFree(where);
+        return false;
+    }
+
+    if (psListLength(where->list)) {
+        psString whereClause = psDBGenerateWhereConditionSQL(where, "rawExp");
         psStringAppend(&query, " AND %s", whereClause);
+	psFree(where);
         psFree(whereClause);
     }
+    psFree(where);
 
     if (!p_psDBRunQuery(config->dbh, query)) {
@@ -938,10 +959,15 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
+    psMetadata *where = psMetadataAlloc();
+    PXOPT_COPY_S64(config->args, where,  "-exp_id",       "exp_id", "==");
+
     PXOPT_LOOKUP_S16(code, config->args, "-code", true, false);
 
-    if (!pxSetFaultCode(config->dbh, "rawExp", config->where, code)) {
+    if (!pxSetFaultCode(config->dbh, "rawExp", where, code)) {
         psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag");
-        return false;
-    }
+	psFree(where);
+        return false;
+    }
+    psFree(where);
 
     return true;
