Index: trunk/ippTools/src/dettool.c
===================================================================
--- trunk/ippTools/src/dettool.c	(revision 9046)
+++ trunk/ippTools/src/dettool.c	(revision 9057)
@@ -127,6 +127,6 @@
 
      psString query = psStringCopy("SELECT rawDetrendExp.* FROM rawDetrendExp"
-        " LEFT JOIN detInputExp ON rawDetrendExp.exp_id = detInputExp.exp_id"
-        " WHERE detInputExp.exp_id IS NULL");
+        " LEFT JOIN detInputExp ON rawDetrendExp.exp_tag = detInputExp.exp_tag"
+        " WHERE detInputExp.exp_tag IS NULL");
 
     if (config->where) {
@@ -190,14 +190,14 @@
     }
 
-    // we have to support multipe exp_ids
-    psMetadataItem *item = psMetadataLookup(config->args, "-exp_id");
+    // we have to support multipe exp_tags
+    psMetadataItem *item = psMetadataLookup(config->args, "-exp_tag");
     if (!item) {
         // this shouldn't actually happen when using psArgs
-        psError(PS_ERR_UNKNOWN, true, "-exp_id is required");
+        psError(PS_ERR_UNKNOWN, true, "-exp_tag is required");
         return false;
     }
     psMetadata *where = psMetadataAlloc();
 
-    // make sure that -exp_id was parsed correctly
+    // make sure that -exp_tag was parsed correctly
     // XXX this can be removed someday
     if (item->type == PS_DATA_METADATA_MULTI) {
@@ -205,17 +205,17 @@
         psMetadataItem *mItem = NULL;
         while ((mItem = psListGetAndIncrement(iter))) {
-            psString exp_id = mItem->data.V;
-            // if exp_id is NULL then it means that -exp_id has not been
+            psString exp_tag = mItem->data.V;
+            // if exp_tag is NULL then it means that -exp_tag has not been
             // specified
-            if (!exp_id) {
+            if (!exp_tag) {
                 psError(PS_ERR_UNKNOWN, true,
-                        "at least one -exp_id is required");
+                        "at least one -exp_tag is required");
                 psFree(where);
                 return false;
             }
 
-            if (!psMetadataAddStr(where, PS_LIST_TAIL, "exp_id",
-                 PS_META_DUPLICATE_OK, "==", exp_id)) {
-                psError(PS_ERR_UNKNOWN, false, "failed to add item exp_id");
+            if (!psMetadataAddStr(where, PS_LIST_TAIL, "exp_tag",
+                 PS_META_DUPLICATE_OK, "==", exp_tag)) {
+                psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
                 psFree(iter);
                 psFree(where);
@@ -226,5 +226,5 @@
     } else {
         psAbort(config->argv[0],
-                "-exp_id was not parsed correctly (this should not happen");
+                "-exp_tag was not parsed correctly (this should not happen");
     }
 
@@ -234,5 +234,5 @@
     }
 
-    // check that the specified exp_ids actually exist
+    // check that the specified exp_tags actually exist
     psArray *detrendExps = rawDetrendExpSelectRowObjects(config->dbh, where, 0);
     psFree(where);
@@ -242,8 +242,8 @@
     }
 
-    // we should have one rawDetrendExp row per exp_id specified
+    // we should have one rawDetrendExp row per exp_tag specified
     if (psListLength(item->data.list) != psArrayLength(detrendExps)) {
         psAbort(config->argv[0],
-    "an -exp_id matched more then one rawDetrendExp (this should not happen");
+    "an -exp_tag matched more then one rawDetrendExp (this should not happen");
 
     }
@@ -717,5 +717,5 @@
         det_id,
         iteration,
-        rawExp->exp_id,
+        rawExp->exp_tag,
         true            // use
     );
@@ -729,5 +729,5 @@
     // select rawDetrendExp.*
     // by:
-    // exp_id
+    // exp_tag
 
     psString query = psStringCopy(
@@ -735,5 +735,5 @@
         " FROM detInputExp"
         " JOIN rawDetrendExp"
-        " USING(exp_id)"
+        " USING(exp_tag)"
         );
 
@@ -789,22 +789,22 @@
     //
     // det_id is in detInputExp
-    // exp_id is in detInputExp
+    // exp_tag is in detInputExp
     // det_id is not in detProccessedImfile
-    // exp_id is not in detProccessedImfile
+    // exp_tag is not in detProccessedImfile
     // class_is is not in detProccessedImfile
     psString query = psStringCopy(
             "SELECT detInputExp.det_id, detRun.det_type, rawImfile.*"
             " FROM rawImfile"
-            " LEFT JOIN detInputExp USING(exp_id) "
+            " LEFT JOIN detInputExp USING(exp_tag) "
             " LEFT JOIN detRun ON detInputExp.det_id = detRun.position"
             " LEFT JOIN detProcessedImfile"
                 " ON detInputExp.det_id = detProcessedImfile.det_id"
-                " AND rawImfile.exp_id = detProcessedImfile.exp_id"
+                " AND rawImfile.exp_tag = detProcessedImfile.exp_tag"
                 " AND rawImfile.class_id = detProcessedImfile.class_id"
             " WHERE"
             " detInputExp.det_id IS NOT NULL"
-            " AND detInputExp.exp_id IS NOT NULL"
+            " AND detInputExp.exp_tag IS NOT NULL"
             " AND detProcessedImfile.det_id IS NULL"
-            " AND detProcessedImfile.exp_id IS NULL"
+            " AND detProcessedImfile.exp_tag IS NULL"
             " AND detProcessedImfile.class_id IS NULL"
         );
@@ -861,5 +861,5 @@
     }
 
-    // select exp_ids from detInputExp matching det_idp
+    // select exp_tags from detInputExp matching det_idp
     // where query should be pre-generated
     psArray *detInputExp =
@@ -870,14 +870,14 @@
     }
 
-    // generate where query with just the exp_ids
-    psMetadata *where_exp_ids = psMetadataAlloc();
+    // generate where query with just the exp_tags
+    psMetadata *where_exp_tags = psMetadataAlloc();
     for (long i = 0; i < psArrayLength(detInputExp); i++) {
         detInputExpRow *row = detInputExp->data[i];
-        if (!psMetadataAddStr(where_exp_ids, PS_LIST_TAIL, "exp_id",
-                PS_META_DUPLICATE_OK, "==", row->exp_id)
+        if (!psMetadataAddStr(where_exp_tags, PS_LIST_TAIL, "exp_tag",
+                PS_META_DUPLICATE_OK, "==", row->exp_tag)
         ) {
-            psError(PS_ERR_UNKNOWN, false, "failed to add item exp_id");
+            psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
             psFree(detInputExp);
-            psFree(where_exp_ids);
+            psFree(where_exp_tags);
             return NULL;
         }
@@ -885,8 +885,8 @@
     psFree(detInputExp);
 
-    // select rawImfiles with matching exp_ids
+    // select rawImfiles with matching exp_tags
     psArray *rawImfiles =
-        rawImfileSelectRowObjects(config->dbh, where_exp_ids, 0);
-    psFree(where_exp_ids);
+        rawImfileSelectRowObjects(config->dbh, where_exp_tags, 0);
+    psFree(where_exp_tags);
     if (!rawImfiles) {
         psError(PS_ERR_UNKNOWN, false, "no rawImfile rows found");
@@ -901,5 +901,5 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
-    // det_id, exp_id, class_id, uri, recipe, -bg, -bg_stdev, & -bg_mean_stdev
+    // det_id, exp_tag, class_id, uri, recipe, -bg, -bg_stdev, & -bg_mean_stdev
     // are required
     bool status = false;
@@ -913,11 +913,11 @@
         return false;
     }
-    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");
+    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;
     }
@@ -988,8 +988,8 @@
     }
 
-    // find the matching rawImfile by exp_id/class_id
+    // find the matching rawImfile by exp_tag/class_id
     psMetadata *where = psMetadataAlloc();
-    if (!psMetadataAddStr(where, PS_LIST_TAIL, "exp_id", 0, "==", exp_id)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item exp_id");
+    if (!psMetadataAddStr(where, PS_LIST_TAIL, "exp_tag", 0, "==", exp_tag)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
         psFree(where);
         return false;
@@ -1011,5 +1011,5 @@
     detProcessedImfileRow *detRow = detProcessedImfileRowAlloc(
         (psS32)atol(det_id),
-        exp_id,
+        exp_tag,
         class_id,
         uri,
@@ -1044,7 +1044,7 @@
     // by:
     // find the current iteration bassed on det_id
-    // find all exp_ids in the current det_id/iteration from detInputExp
-    // find all rawImfiles in the current exp_ids
-    // compare to detProcessedImfiles by det_id/exp_id
+    // find all exp_tags in the current det_id/iteration from detInputExp
+    // find all rawImfiles in the current exp_tags
+    // compare to detProcessedImfiles by det_id/exp_tag
     // found how many imfile there are in each class_id
     // and:
@@ -1065,8 +1065,8 @@
         "    AND detRun.iteration = detInputExp.iteration"
         " JOIN rawDetrendExp"
-        "    ON detInputExp.exp_id = rawDetrendExp.exp_id"
+        "    ON detInputExp.exp_tag = rawDetrendExp.exp_tag"
         " JOIN detProcessedImfile"
         "    ON detInputExp.det_id = detProcessedImfile.det_id"
-        "    AND detInputExp.exp_id = detProcessedImfile.exp_id"
+        "    AND detInputExp.exp_tag = detProcessedImfile.exp_tag"
         " LEFT JOIN detStackedImfile"
         "    ON detInputExp.det_id = detStackedImfile.det_id"
@@ -1074,5 +1074,5 @@
         "    AND detProcessedImfile.class_id = detStackedImfile.class_id"
         " LEFT JOIN rawImfile"
-        "    ON detInputExp.exp_id = rawImfile.exp_id"
+        "    ON detInputExp.exp_tag = rawImfile.exp_tag"
         "    AND detProcessedImfile.class_id = rawImfile.class_id"
         " WHERE"
@@ -1165,5 +1165,5 @@
         // det_id is not in detStackedImfile
         // iteration is not in detStackedImfile
-        // detProcessedImfile.exp_id is not in detStackedImfile
+        // detProcessedImfile.exp_tag is not in detStackedImfile
         // detProcessedImfile.class_id is not in detStackedImfile
         // and detInputExp.include is 1
@@ -1180,5 +1180,5 @@
             "       ON detRun.position = detInputExp.det_id"
             "       AND detRun.iteration = detInputExp.iteration"
-            "       AND detProcessedImfile.exp_id = detInputExp.exp_id"
+            "       AND detProcessedImfile.exp_tag = detInputExp.exp_tag"
             "   LEFT JOIN detStackedImfile"
             "       ON detRun.position = detStackedImfile.det_id"
@@ -1267,5 +1267,5 @@
     // remove detStackedImfiles unless -unmask
     if (!psMetadataLookupBool(&status, config->args, "-unmask")) {
-        // detStackedImfiles doesn't have an exp_id so we have to generate the
+        // detStackedImfiles doesn't have an exp_tag so we have to generate the
         // where query ourselves
         bool status = false;
@@ -1293,5 +1293,5 @@
             if (!psMetadataAddS32(where, PS_LIST_TAIL, "det_id", 0, "==",
                     (psS32)atoi(det_id))) {
-                psError(PS_ERR_UNKNOWN, false, "failed to add item exp_id");
+                psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
                 psFree(where);
                 return false;
@@ -1582,5 +1582,5 @@
     if (!psMetadataAddS32(where, PS_LIST_TAIL, "det_id", 0, "==",
             (psS32)atoi(det_id))) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item exp_id");
+        psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
         psFree(where);
         return false;
@@ -1794,5 +1794,5 @@
     // by:
     // find the current iteration bassed on det_id
-    // find all exp_ids in the current det_id/iteration from detInputExp
+    // find all exp_tags in the current det_id/iteration from detInputExp
     // sort to detInputExp.imfiles to find the largest value per det_id/iter
     // compare imfiles to the number of detStackedImfiles by class_id
@@ -1812,5 +1812,5 @@
         "     AND detRun.iteration = detInputExp.iteration"
         " LEFT JOIN rawDetrendExp"
-        "     ON detInputExp.exp_id = rawDetrendExp.exp_id"
+        "     ON detInputExp.exp_tag = rawDetrendExp.exp_tag"
         " LEFT JOIN detStackedImfile"
         "     ON detInputExp.det_id = detStackedImfile.det_id"
@@ -1819,5 +1819,5 @@
         "   detStackedImfile.normalize = 1"
         " GROUP BY"
-        "     rawDetrendExp.exp_id"
+        "     rawDetrendExp.exp_tag"
         " HAVING MAX(rawDetrendExp.imfiles) = COUNT(detStackedImfile.class_id)"
         );
@@ -2106,8 +2106,8 @@
         psMetadata *where = psMetadataAlloc();
         for (long i = 0; i < psArrayLength(inputExps); i++) {
-            if (!psMetadataAddStr(where, PS_LIST_TAIL, "exp_id",
+            if (!psMetadataAddStr(where, PS_LIST_TAIL, "exp_tag",
                     PS_META_DUPLICATE_OK, "==",
-                    ((detInputExpRow *)inputExps->data[i])->exp_id)) {
-                psError(PS_ERR_UNKNOWN, false, "failed to add item exp_id");
+                    ((detInputExpRow *)inputExps->data[i])->exp_tag)) {
+                psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
                 psFree(inputExps);
                 psFree(where);
@@ -2312,5 +2312,5 @@
         " JOIN detProcessedImfile"
         "   ON detRun.position = detProcessedImfile.det_id"
-        "   AND detInputExp.exp_id = detProcessedImfile.exp_id"
+        "   AND detInputExp.exp_tag = detProcessedImfile.exp_tag"
         " JOIN detNormalizedImfile"
         "   ON detRun.position = detNormalizedImfile.det_id"
@@ -2320,10 +2320,10 @@
         "   ON detRun.position = detResidImfile.det_id"
         "   AND detRun.iteration = detResidImfile.iteration"
-        "   AND detProcessedImfile.exp_id = detResidImfile.exp_id"
+        "   AND detProcessedImfile.exp_tag = detResidImfile.exp_tag"
         "   AND detProcessedImfile.class_id = detResidImfile.class_id"
         " WHERE"
         "   detResidImfile.det_id IS NULL"
         "   AND detResidImfile.iteration IS NULL"
-        "   AND detResidImfile.exp_id IS NULL"
+        "   AND detResidImfile.exp_tag IS NULL"
         "   AND detResidImfile.class_id IS NULL"
         " UNION"
@@ -2339,5 +2339,5 @@
         " JOIN detProcessedImfile"
         "   ON detRun.position = detProcessedImfile.det_id"
-        "   AND detInputExp.exp_id = detProcessedImfile.exp_id"
+        "   AND detInputExp.exp_tag = detProcessedImfile.exp_tag"
         " JOIN detStackedImfile"
         "   ON detRun.position = detStackedImfile.det_id"
@@ -2347,10 +2347,10 @@
         "   ON detRun.position = detResidImfile.det_id"
         "   AND detRun.iteration = detResidImfile.iteration"
-        "   AND detProcessedImfile.exp_id = detResidImfile.exp_id"
+        "   AND detProcessedImfile.exp_tag = detResidImfile.exp_tag"
         "   AND detStackedImfile.class_id = detResidImfile.class_id"
         " WHERE"
         "   detResidImfile.det_id IS NULL"
         "   AND detResidImfile.iteration IS NULL"
-        "   AND detResidImfile.exp_id IS NULL"
+        "   AND detResidImfile.exp_tag IS NULL"
         "   AND detResidImfile.class_id IS NULL"
         "   AND detStackedImfile.normalize = 0"
@@ -2571,5 +2571,5 @@
 
     // make sure that there is a coresponding entry in detNormalizedImfile
-    // and the exp_id specified is valid
+    // and the exp_tag specified is valid
     // select * from detNormalizedImfile
     // by det_id, iteration, class_id
@@ -2588,12 +2588,12 @@
         "   ON detNormalizedImfile.det_id = detResidImfile.det_id"
         "   AND detNormalizedImfile.iteration= detResidImfile.iteration"
-        "   AND detInputExp.exp_id = detResidImfile.exp_id"
+        "   AND detInputExp.exp_tag = detResidImfile.exp_tag"
         "   AND detNormalizedImfile.class_id = detResidImfile.class_id"
         " WHERE"
         "  detResidImfile.det_id IS NULL"
         "  AND detResidImfile.iteration IS NULL"
-        "  AND detResidImfile.exp_id IS NULL"
+        "  AND detResidImfile.exp_tag IS NULL"
         "  AND detResidImfile.class_id IS NULL"
-        "  AND detInputExp.exp_id = '%s'"
+        "  AND detInputExp.exp_tag = '%s'"
         " UNION"
         " SELECT"
@@ -2608,12 +2608,12 @@
         "   ON detStackedImfile.det_id = detResidImfile.det_id"
         "   AND detStackedImfile.iteration= detResidImfile.iteration"
-        "   AND detInputExp.exp_id = detResidImfile.exp_id"
+        "   AND detInputExp.exp_tag = detResidImfile.exp_tag"
         "   AND detStackedImfile.class_id = detResidImfile.class_id"
         " WHERE"
         "   detResidImfile.det_id IS NULL"
         "   AND detResidImfile.iteration IS NULL"
-        "   AND detResidImfile.exp_id IS NULL"
+        "   AND detResidImfile.exp_tag IS NULL"
         "   AND detResidImfile.class_id IS NULL"
-        "   AND detInputExp.exp_id = '%s'"
+        "   AND detInputExp.exp_tag = '%s'"
         "   AND detStackedImfile.normalize = 0"
         " ) as detNormStackedImfile"
@@ -2678,20 +2678,20 @@
     }
 
-    // exp_id is manadatory to cross check that this is a exp_id for this
+    // exp_tag is manadatory to cross check that this is a exp_tag for this
     // detRUn
     bool status = false;
-    psString exp_id = psMetadataLookupStr(&status, config->args, "-exp_id");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_id");
+    psString exp_tag = psMetadataLookupStr(&status, config->args, "-exp_tag");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_tag");
         psFree(query);
         return false;
     }
-    if (!exp_id) {
-        psError(PS_ERR_UNKNOWN, true, "-exp_id is required");
+    if (!exp_tag) {
+        psError(PS_ERR_UNKNOWN, true, "-exp_tag is required");
         psFree(query);
         return false;
     }
 
-    if (!p_psDBRunQuery(config->dbh, query, exp_id, exp_id)) {
+    if (!p_psDBRunQuery(config->dbh, query, exp_tag, exp_tag)) {
         psError(PS_ERR_UNKNOWN, false, "database error");
         psFree(query);
@@ -2757,11 +2757,11 @@
 
     bool status = false;
-    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");
+    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;
     }
@@ -2827,5 +2827,5 @@
             normalizedImfile->det_id,
             normalizedImfile->iteration,
-            exp_id,
+            exp_tag,
             normalizedImfile->class_id,
             uri,
@@ -2845,5 +2845,5 @@
     // select detResidImfile.*
     // by:
-    // where det_id, iteration, exp_id is not in detResidExp;
+    // where det_id, iteration, exp_tag is not in detResidExp;
 
     psString query = psStringCopy(
@@ -2852,9 +2852,9 @@
         " FROM detResidImfile"
         " LEFT JOIN detResidExp"
-        "   USING(det_id, iteration, exp_id)"
+        "   USING(det_id, iteration, exp_tag)"
         " WHERE"
         "   detResidExp.det_id IS NULL"
         "   AND detResidExp.iteration IS NULL"
-        "   AnD detResidExp.exp_id IS NULL"
+        "   AnD detResidExp.exp_tag IS NULL"
         );
 
@@ -2917,12 +2917,12 @@
     // select detRun.iteration
     // select detRun.det_type
-    // select detInputExp.exp_id
+    // select detInputExp.exp_tag
     // select detInputExp.include
     // by:
     // find the current iteration bassed on det_id
-    // find all exp_ids in the current det_id/iteration from detInputExp
+    // find all exp_tags in the current det_id/iteration from detInputExp
     // compare to detInputExp.imfiles to derResidImfile by class_id
     // and:
-    // detResidImfile.{det_id, iteration, exp_id} is not in detResidExp
+    // detResidImfile.{det_id, iteration, exp_tag} is not in detResidExp
 
     psString query = psStringCopy(
@@ -2931,5 +2931,5 @@
         "   iteration,"
         "   det_type,"
-        "   exp_id,"
+        "   exp_tag,"
         "   include"
         " FROM"
@@ -2938,5 +2938,5 @@
         "       detRun.iteration,"
         "       detRun.det_type,"
-        "       detInputExp.exp_id,"
+        "       detInputExp.exp_tag,"
         "       detInputExp.include,"
         "       rawDetrendExp.imfiles"
@@ -2946,19 +2946,19 @@
         "       AND detRun.iteration = detInputExp.iteration"
         "   LEFT JOIN rawDetrendExp"
-        "       ON detInputExp.exp_id = rawDetrendExp.exp_id"
+        "       ON detInputExp.exp_tag = rawDetrendExp.exp_tag"
         "   LEFT JOIN detResidImfile"
         "       ON detRun.position = detResidImfile.det_id"
         "       AND detRun.iteration = detResidImfile.iteration"
-        "       AND detInputExp.exp_id = detResidImfile.exp_id"
+        "       AND detInputExp.exp_tag = detResidImfile.exp_tag"
         "   LEFT JOIN detResidExp"
         "       ON detRun.position = detResidExp.det_id"
         "       AND detRun.iteration = detResidExp.iteration"
-        "       AND detInputExp.exp_id = detResidExp.exp_id"
+        "       AND detInputExp.exp_tag = detResidExp.exp_tag"
         "   WHERE"
         "       detResidExp.det_id IS NULL"
         "       AND detResidExp.iteration IS NULL"
-        "       AND detResidExp.exp_id IS NULL"
+        "       AND detResidExp.exp_tag IS NULL"
         "   GROUP BY"
-        "       detInputExp.exp_id"
+        "       detInputExp.exp_tag"
         "   HAVING"
         "       rawDetrendExp.imfiles = COUNT(detResidImfile.class_id)"
@@ -3026,12 +3026,12 @@
     // select detRun.iteration
     // select detRun.det_type
-    // select detInputExp.exp_id
+    // select detInputExp.exp_tag
     // select detInputExp.include
     // by:
     // find the current iteration bassed on det_id
-    // find all exp_ids in the current det_id/iteration from detInputExp
+    // find all exp_tags in the current det_id/iteration from detInputExp
     // compare to detInputExp.imfiles to derResidImfile by class_id
     // and:
-    // detResidImfile.{det_id, iteration, exp_id} is not in detResidExp
+    // detResidImfile.{det_id, iteration, exp_tag} is not in detResidExp
 
     psString query = psStringCopy(
@@ -3039,5 +3039,5 @@
         "   det_id,"
         "   iteration,"
-        "   exp_id,"
+        "   exp_tag,"
         "   include"
         " FROM"
@@ -3046,5 +3046,5 @@
         "       detRun.iteration,"
         "       detRun.det_type,"
-        "       detInputExp.exp_id,"
+        "       detInputExp.exp_tag,"
         "       detInputExp.include,"
         "       rawDetrendExp.imfiles"
@@ -3054,19 +3054,19 @@
         "       AND detRun.iteration = detInputExp.iteration"
         "   LEFT JOIN rawDetrendExp"
-        "       ON detInputExp.exp_id = rawDetrendExp.exp_id"
+        "       ON detInputExp.exp_tag = rawDetrendExp.exp_tag"
         "   LEFT JOIN detResidImfile"
         "       ON detRun.position = detResidImfile.det_id"
         "       AND detRun.iteration = detResidImfile.iteration"
-        "       AND detInputExp.exp_id = detResidImfile.exp_id"
+        "       AND detInputExp.exp_tag = detResidImfile.exp_tag"
         "   LEFT JOIN detResidExp"
         "       ON detRun.position = detResidExp.det_id"
         "       AND detRun.iteration = detResidExp.iteration"
-        "       AND detInputExp.exp_id = detResidExp.exp_id"
+        "       AND detInputExp.exp_tag = detResidExp.exp_tag"
         "   WHERE"
         "       detResidExp.det_id IS NULL"
         "       AND detResidExp.iteration IS NULL"
-        "       AND detResidExp.exp_id IS NULL"
+        "       AND detResidExp.exp_tag IS NULL"
         "   GROUP BY"
-        "       detInputExp.exp_id"
+        "       detInputExp.exp_tag"
         "   HAVING"
         "       rawDetrendExp.imfiles = COUNT(detResidImfile.class_id)"
@@ -3075,5 +3075,5 @@
 
     {
-        // build a query to search by det_id, iteration, exp_id
+        // build a query to search by det_id, iteration, exp_tag
         psMetadata *where = psMetadataAlloc();
         bool status = false;
@@ -3107,14 +3107,14 @@
             return false;
         }
-        psString exp_id = psMetadataLookupStr(&status, config->args, "-exp_id");
-        if (!status) {
-            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_id");
+        psString exp_tag = psMetadataLookupStr(&status, config->args, "-exp_tag");
+        if (!status) {
+            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_tag");
             psFree(where);
             psFree(query);
             return false;
         }
-        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");
+        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");
                 psFree(where);
                 psFree(query);
@@ -3208,11 +3208,11 @@
         return false;
     }
-    psString exp_id = psMetadataLookupStr(&status, row, "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");
+    psString exp_tag = psMetadataLookupStr(&status, row, "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;
     }
@@ -3283,5 +3283,5 @@
             det_id,
             iteration,
-            exp_id,
+            exp_tag,
             recipe,
             bg,
@@ -3343,7 +3343,7 @@
     // by:
     // find the current iteration bassed on det_id
-    // find all exp_ids in the current det_id/iteration from detInputExp
-    // find all exp_ids in the current det_id/iteration from detResidExp
-    // compare the counts of exp_ids
+    // find all exp_tags in the current det_id/iteration from detInputExp
+    // find all exp_tags in the current det_id/iteration from detResidExp
+    // compare the counts of exp_tags
 
     psString query = psStringCopy(
@@ -3357,5 +3357,5 @@
         "       detRun.iteration,"
         "       detRun.det_type,"
-        "       detInputExp.exp_id"
+        "       detInputExp.exp_tag"
         "   FROM detRun"
         "       LEFT JOIN detInputExp"
@@ -3363,14 +3363,14 @@
         "       AND detRun.iteration = detInputExp.iteration"
         "   LEFT JOIN rawDetrendExp"
-        "       ON detInputExp.exp_id = rawDetrendExp.exp_id"
+        "       ON detInputExp.exp_tag = rawDetrendExp.exp_tag"
         "   LEFT JOIN detResidExp"
         "       ON detRun.position = detResidExp.det_id"
         "       AND detRun.iteration = detResidExp.iteration"
-        "       AND detInputExp.exp_id = detResidExp.exp_id"
+        "       AND detInputExp.exp_tag = detResidExp.exp_tag"
         "   GROUP BY"
         "       detRun.position,"
         "       detRun.iteration"
         "   HAVING"
-        "       COUNT(detResidExp.exp_id) = COUNT(detInputExp.exp_id)"
+        "       COUNT(detResidExp.exp_tag) = COUNT(detInputExp.exp_tag)"
         " ) AS residdetrun"
         );
@@ -3425,5 +3425,5 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
-    // build a query to search by det_id, iteration, exp_id
+    // build a query to search by det_id, iteration, exp_tag
     psMetadata *where = psMetadataAlloc();
     bool status = false;
@@ -3453,13 +3453,13 @@
         return false;
     }
-    psString exp_id = psMetadataLookupStr(&status, config->args, "-exp_id");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_id");
+    psString exp_tag = psMetadataLookupStr(&status, config->args, "-exp_tag");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_tag");
         psFree(where);
         return false;
     }
-    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");
+    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");
             psFree(where);
             return false;
@@ -3468,5 +3468,5 @@
 
     // find the values we're going to set
-    // copy everything but det_id, iteration, & exp_id from the args and
+    // copy everything but det_id, iteration, & exp_tag from the args and
     // remove the '-' prefix
     psMetadata *set = psMetadataAlloc();
@@ -3601,7 +3601,7 @@
     // by:
     // find the current iteration bassed on det_id
-    // find all exp_ids in the current det_id/iteration from detInputExp
-    // find all exp_ids in the current det_id/iteration from detResidExp
-    // compare the counts of exp_ids
+    // find all exp_tags in the current det_id/iteration from detInputExp
+    // find all exp_tags in the current det_id/iteration from detResidExp
+    // compare the counts of exp_tags
 
     psString query = psStringCopy(
@@ -3613,5 +3613,5 @@
         "       detRun.position AS det_id,"
         "       detRun.iteration,"
-        "       detInputExp.exp_id"
+        "       detInputExp.exp_tag"
         "   FROM detRun"
         "       LEFT JOIN detInputExp"
@@ -3619,19 +3619,19 @@
         "       AND detRun.iteration = detInputExp.iteration"
         "   LEFT JOIN rawDetrendExp"
-        "       ON detInputExp.exp_id = rawDetrendExp.exp_id"
+        "       ON detInputExp.exp_tag = rawDetrendExp.exp_tag"
         "   LEFT JOIN detResidExp"
         "       ON detRun.position = detResidExp.det_id"
         "       AND detRun.iteration = detResidExp.iteration"
-        "       AND detInputExp.exp_id = detResidExp.exp_id"
+        "       AND detInputExp.exp_tag = detResidExp.exp_tag"
         "   GROUP BY"
         "       detRun.position,"
         "       detRun.iteration"
         "   HAVING"
-        "       COUNT(detResidExp.exp_id) = COUNT(detInputExp.exp_id)"
+        "       COUNT(detResidExp.exp_tag) = COUNT(detInputExp.exp_tag)"
         " ) AS residdetrun"
         );
 
     {
-        // build a query to search by det_id, iteration, exp_id
+        // build a query to search by det_id, iteration, exp_tag
         psMetadata *where = psMetadataAlloc();
         bool status = false;
@@ -3839,11 +3839,11 @@
     // select detRun.position
     // select detRun.iteration
-    // select detInputExp.exp_id
+    // select detInputExp.exp_tag
     // select detResidExp.accept
     // by:
     // find the current iteration bassed on det_id
-    // find all exp_ids in the current det_id/iteration from detInputExp
-    // find all exp_ids in the current det_id/iteration from detResidExp
-    // compare the counts of exp_ids
+    // find all exp_tags in the current det_id/iteration from detInputExp
+    // find all exp_tags in the current det_id/iteration from detResidExp
+    // compare the counts of exp_tags
 
     psString query = psStringCopy(
@@ -3851,5 +3851,5 @@
         "   detRun.position AS det_id,"
         "   detRun.iteration,"
-        "   detInputExp.exp_id,"
+        "   detInputExp.exp_tag,"
         "   detResidExp.accept"
         " FROM detRun"
@@ -3860,14 +3860,14 @@
         "   ON detRun.position = detResidExp.det_id"
         "   AND detRun.iteration = detResidExp.iteration"
-        "   AND detInputExp.exp_id = detResidExp.exp_id"
+        "   AND detInputExp.exp_tag = detResidExp.exp_tag"
         " WHERE"
-        "   detInputExp.exp_id IS NOT NULL"
+        "   detInputExp.exp_tag IS NOT NULL"
         "   AND detResidExp.accept IS NOT NULL"
         " GROUP BY"
         "   detRun.position,"
         "   detRun.iteration,"
-        "   detInputExp.exp_id"
+        "   detInputExp.exp_tag"
         " HAVING"
-        "   COUNT(detResidExp.exp_id) = COUNT(detInputExp.exp_id)"
+        "   COUNT(detResidExp.exp_tag) = COUNT(detInputExp.exp_tag)"
         );
 
@@ -3910,5 +3910,5 @@
     for (long i = 0; i < psArrayLength(output); i++) {
         psMetadata *row = output->data[i];
-        psString exp_id = psMetadataLookupStr(&status, row, "exp_id");
+        psString exp_tag = psMetadataLookupStr(&status, row, "exp_tag");
         if (!status) {
             // rollback
@@ -3916,5 +3916,5 @@
                 psError(PS_ERR_UNKNOWN, false, "database error");
             }
-            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for exp_id");
+            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for exp_tag");
             psFree(output);
             return false;
@@ -3936,5 +3936,5 @@
                     (psS32)atol(det_id),
                     newIteration,
-                    exp_id,
+                    exp_tag,
                     accept
                 )
@@ -4098,15 +4098,15 @@
     }
 
-    // we have to support multipe exp_ids
-    psMetadataItem *item = psMetadataLookup(config->args, "-exp_id");
+    // we have to support multipe exp_tags
+    psMetadataItem *item = psMetadataLookup(config->args, "-exp_tag");
     if (!item) {
         // this shouldn't actually happen when using psArgs
-        psError(PS_ERR_UNKNOWN, true, "-exp_id is required");
-        return false;
-    }
-
-    psList *exp_id_list = item->data.list;
+        psError(PS_ERR_UNKNOWN, true, "-exp_tag is required");
+        return false;
+    }
+
+    psList *exp_tag_list = item->data.list;
     psMetadata *where = psMetadataAlloc();
-    // make sure that -exp_id was parsed correctly
+    // make sure that -exp_tag was parsed correctly
     // XXX this can be removed someday
     if (item->type == PS_DATA_METADATA_MULTI) {
@@ -4114,17 +4114,17 @@
         psMetadataItem *mItem = NULL;
         while ((mItem = psListGetAndIncrement(iter))) {
-            psString exp_id = mItem->data.V;
-            // if exp_id is NULL then it means that -exp_id has not been
+            psString exp_tag = mItem->data.V;
+            // if exp_tag is NULL then it means that -exp_tag has not been
             // specified
-            if (!exp_id) {
+            if (!exp_tag) {
                 psError(PS_ERR_UNKNOWN, true,
-                        "at least one -exp_id is required");
+                        "at least one -exp_tag is required");
                 psFree(where);
                 return false;
             }
 
-            if (!psMetadataAddStr(where, PS_LIST_TAIL, "exp_id",
-                        PS_META_DUPLICATE_OK, "==", exp_id)) {
-                psError(PS_ERR_UNKNOWN, false, "failed to add item exp_id");
+            if (!psMetadataAddStr(where, PS_LIST_TAIL, "exp_tag",
+                        PS_META_DUPLICATE_OK, "==", exp_tag)) {
+                psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
                 psFree(iter);
                 psFree(where);
@@ -4135,8 +4135,8 @@
     } else {
         psAbort(config->argv[0],
-                "-exp_id was not parsed correctly (this should not happen");
-    }
-
-    // check that the specified exp_ids actually exist in the iteration zero
+                "-exp_tag was not parsed correctly (this should not happen");
+    }
+
+    // check that the specified exp_tags actually exist in the iteration zero
     // detInputExp set
 
@@ -4162,9 +4162,9 @@
     }
 
-    // build a hash for the valid exp_ids
-    psHash *valid_exp_ids = psHashAlloc(psArrayLength(detrendExps));
+    // build a hash for the valid exp_tags
+    psHash *valid_exp_tags = psHashAlloc(psArrayLength(detrendExps));
     for (long i = 0; i < psArrayLength(detrendExps); i++) {
-        psHashAdd(valid_exp_ids,
-            ((detInputExpRow *)detrendExps->data[i])->exp_id,
+        psHashAdd(valid_exp_tags,
+            ((detInputExpRow *)detrendExps->data[i])->exp_tag,
             detrendExps->data[i]
         );
@@ -4176,5 +4176,5 @@
     if (!psDBTransaction(config->dbh)) {
         psError(PS_ERR_UNKNOWN, false, "database error");
-        psFree(valid_exp_ids);
+        psFree(valid_exp_tags);
         return false;
     }
@@ -4187,15 +4187,15 @@
             psError(PS_ERR_UNKNOWN, false, "database error");
         }
-        psFree(valid_exp_ids);
-        return false;
-    }
-
-    // check exp_ids and build up an array of new detInputExp rows at the same
+        psFree(valid_exp_tags);
+        return false;
+    }
+
+    // check exp_tags and build up an array of new detInputExp rows at the same
     // time
-    psListIterator *iter = psListIteratorAlloc(exp_id_list, 0, false);
+    psListIterator *iter = psListIteratorAlloc(exp_tag_list, 0, false);
     psMetadataItem *mItem = NULL;
-    psArray *newInputExps = psArrayAlloc(psListLength(exp_id_list));
+    psArray *newInputExps = psArrayAlloc(psListLength(exp_tag_list));
     while ((mItem = psListGetAndIncrement(iter))) {
-        detInputExpRow *inputExp = psHashLookup(valid_exp_ids,
+        detInputExpRow *inputExp = psHashLookup(valid_exp_tags,
                 (char *)mItem->data.V);
         if (!inputExp) {
@@ -4204,9 +4204,9 @@
                 psError(PS_ERR_UNKNOWN, false, "database error");
             }
-            // invalid exp_id
-            psError(PS_ERR_UNKNOWN, false, "exp_id %s is invalid for det_id %s",
+            // invalid exp_tag
+            psError(PS_ERR_UNKNOWN, false, "exp_tag %s is invalid for det_id %s",
                     (char *)mItem->data.V, det_id);
             psFree(iter);
-            psFree(valid_exp_ids);
+            psFree(valid_exp_tags);
             return false;
         }
@@ -4214,5 +4214,5 @@
             (psS32)atol(det_id),
             newIteration,
-            inputExp->exp_id,
+            inputExp->exp_tag,
             true   // use
         );
@@ -4221,5 +4221,5 @@
     }
     psFree(iter);
-    psFree(valid_exp_ids);
+    psFree(valid_exp_tags);
 
     for (long i = 0; i < psArrayLength(newInputExps); i++) {
