Index: /trunk/ippTools/src/regtool.c
===================================================================
--- /trunk/ippTools/src/regtool.c	(revision 6299)
+++ /trunk/ippTools/src/regtool.c	(revision 6300)
@@ -6,4 +6,6 @@
 static bool updateMode(pxConfig *config);
 static psArray *newFrameSearchPending(pxConfig *config);
+static p1PendingExpRow *newToP1PendingExp(newExpRow *newExp);
+static p2PendingExpRow *newToP2PendingExp(newExpRow *newExp);
 
 int main(int argc, char **argv)
@@ -55,4 +57,8 @@
 
     psArray *new = newFrameSearchPending(config);
+    if (!new) {
+        psError(PS_ERR_UNKNOWN, false, "no newFrames found");
+        return true;
+    }
 
     // insert 'new' rawScience & detrendframes
@@ -73,5 +79,54 @@
                 }
             }
+            
+            // lookup camera name in p0CameraConfig
+            psMetadata *where = psMetadataAlloc();
+            //bool status = false;
+            psMetadataAddStr(where, PS_LIST_TAIL, "camera", 0, NULL,
+                newFrame->exposure->camera);
+            psArray *configs = p0CameraConfigSelectRowObjects(config->database, where, MAX_ROWS);
+            psFree(where);
+            // if there is no match then we default to sending into into p2
+            if (!configs) {
+                // convert newFrame->exposure to p2PendingExp 
+                p2PendingExpRow *p2PendingExp = newToP2PendingExp(
+                    newFrame->exposure
+                );
+                p2PendingExpInsertObject(config->database, p2PendingExp);
+                psFree(p2PendingExp);
+                continue;
+            }
+
+            // only use the first match
+            int pX = ((p0CameraConfigRow *)configs->data[0])->phase;
+            switch (pX) {
+                case 1:
+                    // convert newFrame->exposure to p1PendingExp 
+                {
+                    p1PendingExpRow *p1PendingExp = newToP1PendingExp(
+                        newFrame->exposure
+                    );
+                    p1PendingExpInsertObject(config->database, p1PendingExp);
+                    psFree(p1PendingExp);
+                }
+                    break;
+                case 2:
+                    // convert newFrame->exposure to p2PendingExp 
+                {
+                    p2PendingExpRow *p2PendingExp = newToP2PendingExp(
+                        newFrame->exposure
+                    );
+                    p2PendingExpInsertObject(config->database, p2PendingExp);
+                    psFree(p2PendingExp);
+                }
+                    break;
+                default:
+                    // XXX add argv[0] to pxConfig
+                    psAbort("foo", "invalid phase (this should not happen)");
+            }
+
+            psFree(configs);
         }
+        psFree(new);
     }
 
@@ -141,2 +196,32 @@
     return new;
 }
+
+
+static p1PendingExpRow *newToP1PendingExp(newExpRow *newExp)
+{
+    return p1PendingExpRowAlloc(
+        newExp->exp_id,
+        newExp->camera,
+        newExp->exp_type,
+        newExp->filter,
+        newExp->class,
+        newExp->nclass,
+        newExp->stats,
+        0 // XXX calc version number
+    );
+}
+
+static p2PendingExpRow *newToP2PendingExp(newExpRow *newExp)
+{
+    return p2PendingExpRowAlloc(
+        newExp->exp_id,
+        newExp->camera,
+        newExp->exp_type,
+        newExp->filter,
+        newExp->class,
+        newExp->nclass,
+        newExp->stats,
+        0, // XXX calc version number
+        0 // XXX calc version number
+    );
+}
