Index: /trunk/ippTools/src/Makefile.am
===================================================================
--- /trunk/ippTools/src/Makefile.am	(revision 12176)
+++ /trunk/ippTools/src/Makefile.am	(revision 12177)
@@ -50,5 +50,6 @@
 	pxdata.c \
 	pxio.c \
-	pxtag.c
+	pxtag.c \
+	chipqueuerawexp.c
 
 # for pxtools.h
Index: /trunk/ippTools/src/chipqueue.c
===================================================================
--- /trunk/ippTools/src/chipqueue.c	(revision 12177)
+++ /trunk/ippTools/src/chipqueue.c	(revision 12177)
@@ -0,0 +1,91 @@
+/*
+ * chipqueuerawexp.c
+ *
+ * Copyright (C) 2007  Joshua Hoblitt
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * program; see the file COPYING. If not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "pxtools.h"
+#include "pxdata.h"
+#include "chiptool.h"
+
+bool chipQueueRawExp(pxConfig *config,
+                     psString exp_tag,
+                     psString label,
+                     psString recipe,
+                     psString expgroup,
+                     psString dvodb)
+{
+    PS_ASSERT_PTR_NON_NULL(config, false);
+
+    // load the SQL to enqueue our exp_tags from disk once
+    static psString queuerawexp_query = NULL;
+    if (!queuerawexp_query) {
+        queuerawexp_query = pxDataGet("chiptool_queuerawexp.sql");
+        psMemSetPersistent(queuerawexp_query, true);
+        if (!queuerawexp_query) {
+            psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
+            return false;
+        }
+    }
+
+    static psString queuerawimfile_query = NULL;
+    if (!queuerawimfile_query) {
+        queuerawimfile_query = pxDataGet("chiptool_queuerawimfile.sql");
+        psMemSetPersistent(queuerawimfile_query, true);
+        if (!queuerawexp_query) {
+            psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
+            return false;
+        }
+    }
+
+    // queue the exp
+    if (!p_psDBRunQuery(config->dbh, queuerawexp_query,
+                label    ? label    : "NULL",
+                recipe   ? recipe   : "NULL",
+                expgroup ? expgroup : "NULL",
+                dvodb    ? dvodb    : "NULL",
+                exp_tag
+    )) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        return false;
+    }
+
+    // just to be safe, we should have changed at least one row
+    if (psDBAffectedRows(config->dbh) < 1) {
+        psError(PS_ERR_UNKNOWN, false,
+                "no rows affected - should have changed at least one row");
+        return false;
+    }
+
+    // queue the imfiles for the exp we just queued
+    if (!p_psDBRunQuery(config->dbh, queuerawimfile_query)) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        return false;
+    }
+
+    // just to be safe, we should have changed at least one row
+    if (psDBAffectedRows(config->dbh) < 1) {
+        psError(PS_ERR_UNKNOWN, false,
+                "no rows affected - should have changed at least one row");
+        return false;
+    }
+
+    return true;
+}
Index: /trunk/ippTools/src/chiptool.c
===================================================================
--- /trunk/ippTools/src/chiptool.c	(revision 12176)
+++ /trunk/ippTools/src/chiptool.c	(revision 12177)
@@ -251,47 +251,10 @@
 
         // queue the exp
-        if (!p_psDBRunQuery(config->dbh, queuerawexp_query,
-                    label    ? label    : "NULL",
-                    recipe   ? recipe   : "NULL",
-                    expgroup ? expgroup : "NULL",
-                    dvodb    ? dvodb    : "NULL",
-                    exp_tag
-        )) {
-            psError(PS_ERR_UNKNOWN, false, "database error");
-            psFree(queuerawimfile_query);
-            psFree(queuerawexp_query);
-            psFree(output);
-            return false;
-        }
-
-        // just to be safe, we should have changed at least one row
-        if (psDBAffectedRows(config->dbh) < 1) {
+        if (!chipQueueRawExp(config, exp_tag, label, recipe, expgroup, dvodb)) {
             if (!psDBRollback(config->dbh)) {
                 psError(PS_ERR_UNKNOWN, false, "database error");
             }
             psError(PS_ERR_UNKNOWN, false,
-                    "no rows affected - should have changed at least one row");
-            psFree(queuerawimfile_query);
-            psFree(queuerawexp_query);
-            psFree(output);
-            return false;
-        }
-
-        // queue the imfiles for the exp we just queued
-        if (!p_psDBRunQuery(config->dbh, queuerawimfile_query)) {
-            psError(PS_ERR_UNKNOWN, false, "database error");
-            psFree(queuerawimfile_query);
-            psFree(queuerawexp_query);
-            psFree(output);
-            return false;
-        }
-
-        // just to be safe, we should have changed at least one row
-        if (psDBAffectedRows(config->dbh) < 1) {
-            if (!psDBRollback(config->dbh)) {
-                psError(PS_ERR_UNKNOWN, false, "database error");
-            }
-            psError(PS_ERR_UNKNOWN, false,
-                    "no rows affected - should have changed at least one row");
+                    "failed to trying to queue exp_tag: %s", exp_tag);
             psFree(queuerawimfile_query);
             psFree(queuerawexp_query);
Index: /trunk/ippTools/src/chiptool.h
===================================================================
--- /trunk/ippTools/src/chiptool.h	(revision 12176)
+++ /trunk/ippTools/src/chiptool.h	(revision 12177)
@@ -37,3 +37,5 @@
 pxConfig *chiptoolConfig(pxConfig *config, int argc, char **argv);
 
+bool chipQueueRawExp(pxConfig *config, psString exp_tag, psString label, psString recipe, psString expgroup, psString dvodb);
+
 #endif // CHIPTOOL_H
Index: /trunk/ippTools/src/regtool.c
===================================================================
--- /trunk/ippTools/src/regtool.c	(revision 12176)
+++ /trunk/ippTools/src/regtool.c	(revision 12177)
@@ -27,4 +27,5 @@
 #include "pxdata.h"
 #include "regtool.h"
+#include "chiptool.h"
 
 static bool pendingimfileMode(pxConfig *config);
@@ -40,6 +41,6 @@
 
 // static guidePendingExpRow *newToP1PendingExp(newExpRow *newExp);
-static chipPendingExpRow *newTochipPendingExp(pxConfig *config, newExpRow *newExp);
-static chipPendingImfileRow *rawImfileTochipPendingImfile(pxConfig *config, psS64 chip_id, rawImfileRow *rawImfile);
+//static chipPendingExpRow *newTochipPendingExp(pxConfig *config, newExpRow *newExp);
+//static chipPendingImfileRow *rawImfileTochipPendingImfile(pxConfig *config, psS64 chip_id, rawImfileRow *rawImfile);
 
 static rawExpRow *newToRawExp(pxConfig *config, newExpRow *exp);
@@ -636,99 +637,22 @@
         }
 
+        psFree(newExp);
+
         // if this is a detrend image don't put it in the chip queue (and we're
         // done)
         if (detrend) {
-            psFree(newExp);
             continue;
         }
 
         // insert an entry into the chipPendingExp table
-        chipPendingExpRow *chipPendingExp = newTochipPendingExp(config, newExp);
-        if (!chipPendingExp) {
-            psError(PS_ERR_UNKNOWN, false, "failed to convert newExp to chipPendingExp");
-            psFree(newExp);
-            psFree(output);
-            return false;
-        }
-
-        // insert the chipPendingExp object into the database
-        if (!chipPendingExpInsertObject(config->dbh, chipPendingExp)) {
+        if (!chipQueueRawExp(config, exp_tag, NULL, NULL, NULL, NULL)) {
             // rollback
             if (!psDBRollback(config->dbh)) {
                 psError(PS_ERR_UNKNOWN, false, "database error");
             }
-            psError(PS_ERR_UNKNOWN, false, "database error");
-            psFree(chipPendingExp);
-            psFree(newExp);
+            psError(PS_ERR_UNKNOWN, false, "failed to queue chipPendingExp");
             psFree(output);
             return false;
         }
-
-        // get the chip_id for the imfiles
-        psS64 chip_id = psDBLastInsertID(config->dbh);
-        psFree(chipPendingExp);
-
-        // find all of the rawImfiles associated with the chipPendingExp object
-        psArray *rawImfiles = NULL;
-        {
-            // build a query to search by exp_tag
-            psMetadata *where = psMetadataAlloc();
-            if (!psMetadataAddStr(where, PS_LIST_TAIL, "exp_tag", 0, "==", newExp->exp_tag)) {
-                // rollback
-                if (!psDBRollback(config->dbh)) {
-                    psError(PS_ERR_UNKNOWN, false, "database error");
-                }
-                psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
-                psFree(where);
-                psFree(newExp);
-                psFree(output);
-                return false;
-            }
-            rawImfiles = rawImfileSelectRowObjects(config->dbh, where, 0);
-            psFree(where);
-        }
-        // sanity check that least results were found
-        if (!rawImfiles) {
-            // rollback
-            if (!psDBRollback(config->dbh)) {
-                psError(PS_ERR_UNKNOWN, false, "database error");
-            }
-            psError(PS_ERR_UNKNOWN, false, "database error");
-            psFree(newExp);
-            psFree(output);
-            return false;
-        }
-        // sanity check the number of rawImfiles found
-        if (psArrayLength(rawImfiles) != newExp->imfiles) {
-            // rollback
-            if (!psDBRollback(config->dbh)) {
-                psError(PS_ERR_UNKNOWN, false, "database error");
-            }
-            psError(PS_ERR_UNKNOWN, false, "found %ld rawImfiles but expected %d",
-                    psArrayLength(rawImfiles), newExp->imfiles);
-            psFree(newExp);
-            psFree(output);
-            return false;
-        }
-        // convert the rawImfiles into chipPendingImfiles and insert them into
-        // the database
-        for (long i = 0; i < psArrayLength(rawImfiles); i++) {
-            rawImfileRow *rawImfile = rawImfiles->data[i];
-            chipPendingImfileRow *pendingImfile = rawImfileTochipPendingImfile(config, chip_id, rawImfile);
-            if (!chipPendingImfileInsertObject(config->dbh, pendingImfile)){
-                // rollback
-                if (!psDBRollback(config->dbh)) {
-                    psError(PS_ERR_UNKNOWN, false, "database error");
-                }
-                psError(PS_ERR_UNKNOWN, false, "database error");
-                psFree(pendingImfile);
-                psFree(rawImfiles);
-                psFree(newExp);
-                psFree(output);
-            }
-            psFree(pendingImfile);
-        }
-        psFree(rawImfiles);
-        psFree(newExp);
     }
 
@@ -879,4 +803,5 @@
 
 
+#if 0
 static chipPendingExpRow *newTochipPendingExp(pxConfig *config, newExpRow *exp)
 {
@@ -914,4 +839,5 @@
     );
 }
+#endif
 
 
