Index: trunk/ippTools/src/regtool.c
===================================================================
--- trunk/ippTools/src/regtool.c	(revision 14018)
+++ trunk/ippTools/src/regtool.c	(revision 14023)
@@ -111,7 +111,7 @@
 
     // select newImfiles that:
-    // exp_tag is in newExp
-    // don't have their exp_tag in rawExp 
-    // XXX having the same exp_tag in newExp and raw*Exp is probably an error
+    // exp_id is in newExp
+    // don't have their exp_id in rawExp 
+    // XXX having the same exp_id in newExp and raw*Exp is probably an error
     // that should be checked for
 
@@ -181,5 +181,5 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
-    psString query = pxDataGet("regtool_find_unprocessed_imfile.sql");
+    psString query = pxDataGet("regtool_pendingimfile.sql");
     if (!query) {
         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
@@ -188,16 +188,16 @@
 
     {
-        // build a query to search by exp_tag, class, class_id
+        // build a query to search by exp_id, class, class_id
         psMetadata *where = psMetadataAlloc();
         bool status = false;
-        psString exp_tag = psMetadataLookupStr(&status, config->args, "-exp_tag");
+        psString exp_id = psMetadataLookupStr(&status, config->args, "-exp_id");
         if (!status) {
-            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_tag");
+            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_id");
             psFree(query);
             return false;
         }
-        if (exp_tag) {
-            if (!psMetadataAddStr(where, PS_LIST_TAIL, "exp_tag", 0, "==", exp_tag)) {
-                psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
+        if (exp_id) {
+            if (!psMetadataAddStr(where, PS_LIST_TAIL, "exp_id", 0, "==", exp_id)) {
+                psError(PS_ERR_UNKNOWN, false, "failed to add item exp_id");
                 psFree(where);
                 psFree(query);
@@ -206,13 +206,13 @@
         }
 
-        psString class_id = psMetadataLookupStr(&status, config->args, "-class_id");
+        psString tmp_class_id = psMetadataLookupStr(&status, config->args, "-tmp_class_id");
         if (!status) {
-            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -class_id");
+            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -tmp_class_id");
             psFree(query);
             return false;
         }
-        if (class_id) {
-            if (!psMetadataAddStr(where, PS_LIST_TAIL, "class_id", 0, "==", class_id)) {
-                psError(PS_ERR_UNKNOWN, false, "failed to add item class_id");
+        if (tmp_class_id) {
+            if (!psMetadataAddStr(where, PS_LIST_TAIL, "tmp_class_id", 0, "==", tmp_class_id)) {
+                psError(PS_ERR_UNKNOWN, false, "failed to add item tmp_class_id");
                 psFree(where);
                 psFree(query);
@@ -511,17 +511,17 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
-    // make sure that the exp_tag(s) are ready to be updated based on:
-    // exp_tag is not in rawExp
-    // exp_tag is not in newImfile
+    // make sure that the exp_id(s) are ready to be updated based on:
+    // exp_id is not in rawExp
+    // exp_id is not in newImfile
     // that the correct count of imfiles is in rawImfile
    
     bool status = false;
-    psString exp_tag = psMetadataLookupStr(&status, config->args, "-exp_tag");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_tag");
-        return false;
-    }
-    if (!exp_tag) {
-        psError(PS_ERR_UNKNOWN, true, "-exp_tag is required");
+    psString exp_id = psMetadataLookupStr(&status, config->args, "-exp_id");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_id");
+        return false;
+    }
+    if (!exp_id) {
+        psError(PS_ERR_UNKNOWN, true, "-exp_id is required");
         return false;
     }
@@ -539,5 +539,5 @@
     }
 
-    if (!p_psDBRunQuery(config->dbh, query, exp_tag)) {
+    if (!p_psDBRunQuery(config->dbh, query, exp_id)) {
         psError(PS_ERR_UNKNOWN, false, "database error");
         psFree(query);
@@ -608,10 +608,10 @@
         if (detrend) {
             // set the state for the newExp to stop 
-            if (!pxnewExpSetState(config, exp_tag, "stop")) {
+            if (!pxnewExpSetState(config, exp_id, "stop")) {
                 // rollback
                 if (!psDBRollback(config->dbh)) {
                     psError(PS_ERR_UNKNOWN, false, "database error");
                 }
-                psError(PS_ERR_UNKNOWN, false, "failed to change newExp.state for exp_tag: %s", exp_tag);
+                psError(PS_ERR_UNKNOWN, false, "failed to change newExp.state for exp_id: %s", exp_id);
                 psFree(output);
                 return false;
@@ -622,10 +622,10 @@
 
         // set the state for the newExp to stop
-        if (!pxnewExpSetState(config, exp_tag, "stop")) {
+        if (!pxnewExpSetState(config, exp_id, "stop")) {
             // rollback
             if (!psDBRollback(config->dbh)) {
                 psError(PS_ERR_UNKNOWN, false, "database error");
             }
-            psError(PS_ERR_UNKNOWN, false, "failed to change newExp.state for exp_tag: %s", exp_tag);
+            psError(PS_ERR_UNKNOWN, false, "failed to change newExp.state for exp_id: %s", exp_id);
             psFree(output);
             return false;
@@ -634,5 +634,5 @@
         // insert an entry into the chipPendingExp table
         // this can only be run as the newExp's state has been set to stop
-        if (!pxchipQueueByExpTag(config, exp_tag, NULL, NULL, NULL, NULL, NULL)) {
+        if (!pxchipQueueByExpTag(config, exp_id, NULL, NULL, NULL, NULL, NULL)) {
             // rollback
             if (!psDBRollback(config->dbh)) {
@@ -776,5 +776,5 @@
 {
     return guidePendingExpRowAlloc(
-        newExp->exp_tag,
+        newExp->exp_id,
         newExp->camera,
         newExp->telescope,
@@ -810,5 +810,5 @@
     chipPendingExpRow *chipExp = chipPendingExpRowAlloc(
             0,              // chip ID, assigned by db
-            exp->exp_tag,
+            exp->exp_id,
             0xdeadbeef,     // guide version
             label,
@@ -839,4 +839,55 @@
 
     bool status = false;
+    // required
+    psString exp_name = psMetadataLookupStr(&status, config->args, "-exp_name");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_name");
+        return false;
+    }
+    if (!exp_name) {
+        psError(PS_ERR_UNKNOWN, true, "-exp_name is required");
+        return false;
+    }
+
+    psString camera = psMetadataLookupStr(&status, config->args, "-inst");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -inst");
+        return false;
+    }
+    if (!camera) {
+        psError(PS_ERR_UNKNOWN, true, "-inst is required");
+        return false;
+    }
+
+    psString telescope = psMetadataLookupStr(&status, config->args, "-telescope");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -telescope");
+        return false;
+    }
+    if (!telescope) {
+        psError(PS_ERR_UNKNOWN, true, "-telescope 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) {
+        psError(PS_ERR_UNKNOWN, true, "-imfiles is required");
+        return false;
+    }
+
+    psString exp_tag = psMetadataLookupStr(&status, config->args, "-exp_tag");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_tag");
+        return false;
+    }
+    if (!exp_tag) {
+        psError(PS_ERR_UNKNOWN, true, "-exp_tag is required");
+        return false;
+    }
+
     // optional
     psString exp_type = psMetadataLookupStr(&status, config->args, "-exp_type");
@@ -989,11 +1040,12 @@
 
     rawExpRow *raw = rawExpRowAlloc(
-        exp->exp_tag,
         exp->exp_id,
-        exp->camera,
-        exp->telescope,
+        exp_name,
+        camera,
+        telescope,
         dateobs,
+        exp_tag,
         exp_type,
-        exp->imfiles,
+        imfiles,
         filelevel,
         exp->workdir,
@@ -1011,9 +1063,9 @@
         ccd_temp,
         posang,
-	user_1,
-	user_2,
-	user_3,
-	user_4,
-	user_5,
+        user_1,
+        user_2,
+        user_3,
+        user_4,
+        user_5,
         object,
         0.0,
@@ -1035,4 +1087,55 @@
 
     bool status = false;
+    // required
+    psString exp_name = psMetadataLookupStr(&status, config->args, "-exp_name");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_name");
+        return false;
+    }
+    if (!exp_name) {
+        psError(PS_ERR_UNKNOWN, true, "-exp_name is required");
+        return false;
+    }
+
+    psString camera = psMetadataLookupStr(&status, config->args, "-inst");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -inst");
+        return false;
+    }
+    if (!camera) {
+        psError(PS_ERR_UNKNOWN, true, "-inst is required");
+        return false;
+    }
+
+    psString telescope = psMetadataLookupStr(&status, config->args, "-telescope");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -telescope");
+        return false;
+    }
+    if (!telescope) {
+        psError(PS_ERR_UNKNOWN, true, "-telescope is required");
+        return false;
+    }
+
+    psString tmp_class_id = psMetadataLookupStr(&status, config->args, "-tmp_class_id");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -tmp_class_id");
+        return false;
+    }
+    if (!tmp_class_id) {
+        psError(PS_ERR_UNKNOWN, true, "-tmp_class_id is required");
+        return false;
+    }
+
+    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;
+    }
+
     // optional
     psString exp_type = psMetadataLookupStr(&status, config->args, "-exp_type");
@@ -1180,6 +1283,11 @@
 
     rawImfileRow *raw = rawImfileRowAlloc(
-        imfile->exp_tag,
-        imfile->class_id,
+        imfile->exp_id,
+        exp_name,
+        camera,
+        telescope,
+        dateobs,
+        tmp_class_id,
+        class_id,
         imfile->uri,
         exp_type,
@@ -1198,11 +1306,10 @@
         ccd_temp,
         posang,
-	user_1,
-	user_2,
-	user_3,
-	user_4,
-	user_5,
+        user_1,
+        user_2,
+        user_3,
+        user_4,
+        user_5,
         object,
-        dateobs,
         code
     );
