Index: /trunk/ippTools/scripts/camtest.sh
===================================================================
--- /trunk/ippTools/scripts/camtest.sh	(revision 12187)
+++ /trunk/ippTools/scripts/camtest.sh	(revision 12188)
@@ -8,4 +8,4 @@
 camtool -pendingimfile || exit 1
 
-camtool -addprocessedexp -cam_id 1 -uri file://camp -recip myrecipe -bg 1 -bg_stdev 2 -bg_mean_stdev 3 -sigma_ra 1 -sigma_dec 2 -nastro 42 -path_base file:///foo -zp_mean 1 -zp_stdev 2 || exit 1
-camtool -addprocessedexp -cam_id 2 -uri file://camp -recip myrecipe -bg 1 -bg_stdev 2 -bg_mean_stdev 3 -sigma_ra 1 -sigma_dec 2 -nastro 42 -path_base file:///foo -zp_mean 1 -zp_stdev 2 || exit 1
+camtool -addprocessedexp -cam_id 1 -uri file:///cam -bg 1 -bg_stdev 2 -bg_mean_stdev 3 -sigma_ra 1 -sigma_dec 2 -nastro 42 -path_base file:///foo -zp_mean 1 -zp_stdev 2 || exit 1
+camtool -addprocessedexp -cam_id 2 -uri file:///cam -bg 1 -bg_stdev 2 -bg_mean_stdev 3 -sigma_ra 1 -sigma_dec 2 -nastro 42 -path_base file:///foo -zp_mean 1 -zp_stdev 2 || exit 1
Index: /trunk/ippTools/share/Makefile.am
===================================================================
--- /trunk/ippTools/share/Makefile.am	(revision 12187)
+++ /trunk/ippTools/share/Makefile.am	(revision 12188)
@@ -1,14 +1,15 @@
 dist_pkgdata_DATA = \
+	camtool_queue_chip_id.sql \
 	chiptool_completely_processed_exp.sql \
+	chiptool_find_rawexp.sql \
 	chiptool_find_unprocessed_imfile.pl \
 	chiptool_pendingimfile.sql \
 	chiptool_processedimfile.sql \
+	chiptool_queuerawexp.sql \
+	chiptool_queuerawimfile.sql \
+	regtool_find_unprocessed_exp.sql \
+	regtool_find_unprocessed_imfile.sql \
+	regtool_pendingexp.sql \
 	regtool_pendingimfile.sql \
-	regtool_find_unprocessed_exp.sql \
 	regtool_processedexp.sql \
-	regtool_find_unprocessed_imfile.sql \
-	regtool_processedimfile.sql \
-	regtool_pendingexp.sql \
-	chiptool_queuerawexp.sql \
-	chiptool_queuerawimfile.sql
-	chiptool_find_rawexp.sql 
+	regtool_processedimfile.sql
Index: /trunk/ippTools/share/camtool_queue_chip_id.sql
===================================================================
--- /trunk/ippTools/share/camtool_queue_chip_id.sql	(revision 12188)
+++ /trunk/ippTools/share/camtool_queue_chip_id.sql	(revision 12188)
@@ -0,0 +1,13 @@
+-- camtool only operates on exposures so we can safely queue more then one at a
+-- time without worrying about losing the track of the generated cam_id
+INSERT INTO camPendingExp
+    SElECT
+        0,              -- cam_id
+        chip_id,        -- chip_id
+        '%s',           -- label
+        '%s',           -- recipe
+        '%s',           -- expgroup
+        '%s'            -- dvodb 
+    FROM chipProcessedExp
+    WHERE
+        chipProcessedExp.chip_id = %lld
Index: /trunk/ippTools/src/Makefile.am
===================================================================
--- /trunk/ippTools/src/Makefile.am	(revision 12187)
+++ /trunk/ippTools/src/Makefile.am	(revision 12188)
@@ -51,5 +51,6 @@
 	pxio.c \
 	pxtag.c \
-	chipqueuerawexp.c
+	chipqueuerawexp.c \
+	camqueue.c
 
 # for pxtools.h
Index: /trunk/ippTools/src/camqueue.c
===================================================================
--- /trunk/ippTools/src/camqueue.c	(revision 12188)
+++ /trunk/ippTools/src/camqueue.c	(revision 12188)
@@ -0,0 +1,70 @@
+/*
+ * camqueue.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 "camtool.h"
+
+bool camQueueChipID(pxConfig *config,
+                    psS64 chip_id,
+                    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 query = NULL;
+    if (!query) {
+        query = pxDataGet("camtool_queue_chip_id.sql");
+        psMemSetPersistent(query, true);
+        if (!query) {
+            psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
+            return false;
+        }
+    }
+
+    // queue the exp
+    // XXX chip_id is being cast here work around psS64 have a different type
+    // different on 32/64
+    if (!p_psDBRunQuery(config->dbh, query,
+                label    ? label    : "NULL",
+                recipe   ? recipe   : "NULL",
+                expgroup ? expgroup : "NULL",
+                dvodb    ? dvodb    : "NULL",
+                (long long)chip_id
+    )) {
+        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/camtool.c
===================================================================
--- /trunk/ippTools/src/camtool.c	(revision 12187)
+++ /trunk/ippTools/src/camtool.c	(revision 12188)
@@ -293,14 +293,4 @@
     }
 
-    psString recipe = psMetadataLookupStr(&status, config->args, "-recip");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -recip");
-        return false;
-    }
-    if (!recipe) {
-        psError(PS_ERR_UNKNOWN, true, "-recip is required");
-        return false;
-    }
-
     psF64 bg = psMetadataLookupF64(&status, config->args, "-bg");
     if (!status) {
@@ -428,6 +418,8 @@
         pendingRow->chip_id,
         pendingRow->label,
+        pendingRow->recipe,
+        pendingRow->expgroup,
+        pendingRow->dvodb,
         uri,
-        recipe,
         bg,
         bg_stdev,
@@ -439,7 +431,5 @@
         zp_mean,
         zp_stdev,
-        code,
-        pendingRow->expgroup,
-        pendingRow->dvodb
+        code
     );
 
Index: /trunk/ippTools/src/camtool.h
===================================================================
--- /trunk/ippTools/src/camtool.h	(revision 12187)
+++ /trunk/ippTools/src/camtool.h	(revision 12188)
@@ -37,3 +37,10 @@
 pxConfig *camtoolConfig(pxConfig *config, int argc, char **argv);
 
+bool camQueueChipID(pxConfig *config,
+                    psS64 chip_id,
+                    psString label,
+                    psString recipe,
+                    psString expgroup,
+                    psString dvodb);
+
 #endif // CAMTOOL_H
Index: /trunk/ippTools/src/camtoolConfig.c
===================================================================
--- /trunk/ippTools/src/camtoolConfig.c	(revision 12187)
+++ /trunk/ippTools/src/camtoolConfig.c	(revision 12188)
@@ -78,6 +78,4 @@
     psMetadataAddStr(addprocessedexpArgs, PS_LIST_TAIL, "-uri", 0,
             "define URI (required)", NULL);
-    psMetadataAddStr(addprocessedexpArgs, PS_LIST_TAIL, "-recip",  0,
-            "define recipe (required)", NULL);
     psMetadataAddF64(addprocessedexpArgs, PS_LIST_TAIL, "-bg", 0,
             "define exposue background (required)", NAN);
Index: /trunk/ippTools/src/chiptool.c
===================================================================
--- /trunk/ippTools/src/chiptool.c	(revision 12187)
+++ /trunk/ippTools/src/chiptool.c	(revision 12188)
@@ -29,4 +29,5 @@
 #include "pxdata.h"
 #include "chiptool.h"
+#include "camtool.h"
 
 static bool queuerawexpMode(pxConfig *config);
@@ -41,5 +42,4 @@
 static chipProcessedImfileRow *chipPendingToProcessedImfile(pxConfig *config, chipPendingImfileRow *imfile);
 static chipProcessedExpRow *chipPendingToProcessedExp(pxConfig *config, chipPendingExpRow *pendingExp);
-static camPendingExpRow *chipPendingTocamPendingExp(pxConfig *config, chipPendingExpRow *pendingExp);
 static bool chipProcessedCompleteExp(pxConfig *config);
 
@@ -748,53 +748,62 @@
     for (long i = 0; i < psArrayLength(output); i++) {
         psMetadata *row = output->data[i];
+
         // convert metadata into a chipPendingExp object
-        chipPendingExpRow *object = chipPendingExpObjectFromMetadata(row);
-        // do both *Exp type conversion first so we don't insert one and then
-        // have to rollback the change as the 2nd failed
+        chipPendingExpRow *pendingExp = chipPendingExpObjectFromMetadata(row);
+        if (!pendingExp) {
+            psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into chipPendingExp");
+            psFree(output);
+            return false;
+        }
+
         // convert chipPendingExp object into a chipProcesseExp object
-        chipProcessedExpRow *processedExp = chipPendingToProcessedExp(config, object);
+        chipProcessedExpRow *processedExp = chipPendingToProcessedExp(config, pendingExp);
         if (!processedExp) {
             psError(PS_ERR_UNKNOWN, false, "failed to convert chipPendingExp to chipProcessedExp");
-            psFree(object);
-            psFree(output);
-            return false;
-        }
-        // convert chipPendingExp object into a camPendingExp object
-        camPendingExpRow *pendingExp = chipPendingTocamPendingExp(config, object);
-        if (!processedExp) {
-            psError(PS_ERR_UNKNOWN, false, "failed to convert chipPendingExp to camPendingExp");
+            psFree(pendingExp);
+            psFree(output);
+            return false;
+        }
+
+        // delete the chipPendingExp object from the database
+        if (!chipPendingExpDeleteObject(config->dbh, pendingExp)) {
+            // there must be atleast 1 Imfile to get this far
+            psError(PS_ERR_UNKNOWN, false, "database error");
             psFree(processedExp);
-            psFree(object);
-            psFree(output);
-            return false;
-        }
+            psFree(pendingExp);
+            psFree(output);
+            return false;
+        }
+        psFree(pendingExp);
+
         // insert chipProccessedExp object into the database
         if (!chipProcessedExpInsertObject(config->dbh, processedExp)) {
             psError(PS_ERR_UNKNOWN, false, "database error");
             psFree(processedExp);
-            psFree(pendingExp);
-            psFree(object);
-            psFree(output);
-            return false;
-        }
+            psFree(output);
+            return false;
+        }
+
+        // camQueueChipID() can only be run after the chipProcessedExp entry
+        // has been inserted.
+        // queue the chip_id in the camPendingExp table 
+        if (!camQueueChipID(config,
+                    processedExp->chip_id,
+                    processedExp->label,
+                    processedExp->recipe,
+                    processedExp->expgroup,
+                    processedExp->dvodb
+        )) {
+            // rollback
+            if (!psDBRollback(config->dbh)) {
+                psError(PS_ERR_UNKNOWN, false, "database error");
+            }
+            psError(PS_ERR_UNKNOWN, false, "failed to queue camPendingExp");
+            psFree(processedExp);
+            psFree(output);
+            return false;
+        }
+
         psFree(processedExp);
-        // insert camPendingExp object into the database
-        if (!camPendingExpInsertObject(config->dbh, pendingExp)) {
-            psError(PS_ERR_UNKNOWN, false, "database error");
-            psFree(pendingExp);
-            psFree(object);
-            psFree(output);
-            return false;
-        }
-        psFree(pendingExp);
-        // delete the chipPendingExp object from the database
-        if (!chipPendingExpDeleteObject(config->dbh, object)) {
-            // there must be atleast 1 Imfile to get this far
-            psError(PS_ERR_UNKNOWN, false, "database error");
-            psFree(object);
-            psFree(output);
-            return false;
-        }
-        psFree(object);
     }
 
@@ -875,20 +884,7 @@
         pendingExp->guide_id,
         pendingExp->label,
+        pendingExp->recipe,
         pendingExp->expgroup,
         pendingExp->dvodb
     );
 }
-
-
-static camPendingExpRow *chipPendingTocamPendingExp(pxConfig *config, chipPendingExpRow *pendingExp)
-{
-    PS_ASSERT_PTR_NON_NULL(pendingExp, NULL);
-
-    return camPendingExpRowAlloc(
-        0,                      // cam version, assigned by db
-        pendingExp->chip_id,
-        pendingExp->label,
-        pendingExp->expgroup,
-        pendingExp->dvodb
-    );
-}
