Index: trunk/archive/p2tools/src/p2search.c
===================================================================
--- trunk/archive/p2tools/src/p2search.c	(revision 5868)
+++ trunk/archive/p2tools/src/p2search.c	(revision 5869)
@@ -1,78 +1,36 @@
 # include "p2search.h"
-
-typedef enum {
-    P2_MODE_NONE,		      	// grab from raw, output for ppImage
-    P2_MODE_QUICK,		      	// grab from raw, output for ppImage
-    P2_MODE_DEFINE,			// grab from raw, create pending
-    P2_MODE_PENDING,			// grab from pending, output for ppImage
-    P2_MODE_UPDATE,			// set the current state
-} p2Mode;
-
-typedef struct {
-    p2Mode mode;
-    psTime start;
-    psTime stop;
-    psSphere r1;
-    psSphere r2;
-    char *camera;
-    char *filter;
-} p2Config;
-
-// this structure should be defined using the mddb api tools
-typedef struct {
-    char expID[32];			// free-form exposure ID string
-    char class;				// class of file: fpa (0), chip (1), cell (2), readout (3)?
-    int Nclass;				// number of files of this class
-    char camera[32];			// free-form camera ID string
-    char filter[32];			// free-form filter ID string
-    psTime time_start;			// exposure start time
-    psTime time_stop;			// exposure stop time
-    psTime exptime;			// exposure duration (seconds)
-    char exptype;			// type of exposure: object (0), bias (1), dark (2), flat (3), etc
-    float sky;				// measure sky brightness
-    float seeing;			// measured image quality 
-    float dettemp;			// temperature of detector
-} p2RawExposure;
-
-// this structure should be defined using the mddb api tools
-typedef struct {
-    char expID[32];			// free-form exposure ID string
-    char class;				// class of file: fpa (0), chip (1), cell (2), readout (3)?
-    char classID[32];			// identifier for class (chip00, cell00, etc)
-    char url[128];			// locator for file (neb / file)
-    char state;				// current load state
-} p2RawImage;
-
-typedef struct {
-    p2RawExposure *exposure;
-    psArray *images;
-} p2RawSet;
 
 int main (int argc, char **argv) {
 
-    p2SearchConfig (&config, argc, argv);
+    psArray *rawFrames;
+    psArray *doneFrames;
+    psArray *pendingFrames;
 
-    if ((config->mode == P2_MODE_QUICK) || (config->mode == P2_MODE_DEFINE)) {
-	rawSet = p2SearchRawImages (config);
+    p2searchConfig (&config, argc, argv);
+
+    if (config->mode == P2_MODE_QUICK) {
+	rawFrames = p2searchRawFrames (config);
+	pendingFrames = p2rawToPending (config, rawFrames);
+	p2writePendingFrames (config, pendingFrames);
+    }	
+
+    if (config->mode == P2_MODE_DEFINE) {
+	rawFrames = p2searchRawFrames (config);
+	p2insertPendingFrames (config, rawFrames);
     }
 
-    if (config->mode == P2_MODE_DEFINE) {
-	p2InsertRawSet (config, rawSet);
-    }
-
-    if ((config->mode == P2_MODE_PENDING) || (config->mode == P2_MODE_UPDATE)) {
-	pendingSet = p2SearchPendingImages (config);
-    }
-
-    if (config->mode == P2_MODE_QUICK) {
-	pendingSet = p2RawToPending (config, rawSet);
-    }
-
-    if ((config->mode == P2_MODE_QUICK) || (config->mode == P2_MODE_PENDING)) {
-	p2WritePending (config, pendingSet);
+    if (config->mode == P2_MODE_PENDING) {
+	pendingFrames = p2searchPendingFrames (config, FALSE);
+	p2writePendingImages (config, pendingFrames);
     }
 
     if (config->mode == P2_MODE_UPDATE) {
-	p2UpdatePending (config, pendingSet);
+	p2updatePendingFrames (config, pendingFrames);
+    }
+
+    if (config->mode == P2_MODE_DONE) {
+	pendingFrames = p2searchPendingFrames (config, TRUE);
+	doneFrames = p2pendingToDone (config);
+	p2insertDoneFrames (config, doneFrames);
     }
 
