Index: /trunk/ippTools/src/Makefile.am
===================================================================
--- /trunk/ippTools/src/Makefile.am	(revision 6133)
+++ /trunk/ippTools/src/Makefile.am	(revision 6134)
@@ -11,4 +11,5 @@
     p2search.c \
     p2searchConfig.c \
+	p2searchDoneFrames.c \
     p2searchPendingFrames.c \
     p2searchRawFrames.c \
Index: /trunk/ippTools/src/p2searchDoneFrames.c
===================================================================
--- /trunk/ippTools/src/p2searchDoneFrames.c	(revision 6134)
+++ /trunk/ippTools/src/p2searchDoneFrames.c	(revision 6134)
@@ -0,0 +1,53 @@
+#include "p2tools.h"
+
+// select raw frames (exposure+images) which match the given config options
+psArray *p2searchDoneFrames(p2Config *config) {
+    PS_ASSERT_PTR_NON_NULL(config, NULL);
+
+    // build 'where' structure
+    psMetadata *where = psMetadataAlloc ();
+
+    if (config->camera_name != NULL) {
+        psMetadataAddStr(where, PS_LIST_TAIL, "camera", 0, "==",
+            config->camera_name);
+    }
+    if (config->filter != NULL) {
+        psMetadataAddStr(where, PS_LIST_TAIL, "filter", 0, "==",
+            config->filter);
+    }
+
+    psArray *exposures = p2DoneExpSelectRowObjects(config->database, where, 
+        MAX_ROWS);
+    psFree (where);
+    if (!exposures) {
+        psError(PS_ERR_UNKNOWN, false, "no p2DoneExp rows found");
+
+        return NULL;
+    }
+
+    // output array of ppRawFrame
+    psArray *frames = psArrayAlloc(exposures->n);
+    frames->n = 0;
+
+    // 'where' to select each exposure
+    where = psMetadataAlloc ();
+    for (int i = 0; i < exposures->n; i++) {
+        p2DoneExpRow *exposure = exposures->data[i];
+
+        psMetadataAddStr(where, PS_LIST_TAIL, "exp_id", PS_META_REPLACE, "==",
+            exposure->exp_id);
+
+        psArray *images = p2DoneImfileSelectRowObjects(config->database, where,
+            MAX_ROWS);
+        if (!images) {
+            psError(PS_ERR_UNKNOWN, false, "database access failed");
+
+            return NULL;
+        }
+
+        p2DoneFrame *doneFrame = p2DoneFrameAlloc(exposure, images);
+        psArrayAdd(frames, 100, doneFrame);
+    }
+
+    return frames;
+} 
Index: /trunk/ippTools/src/pxtools.h
===================================================================
--- /trunk/ippTools/src/pxtools.h	(revision 6133)
+++ /trunk/ippTools/src/pxtools.h	(revision 6134)
@@ -86,2 +86,3 @@
 bool psTimeIsZero(psTime *time);
 bool p2writePendingFrames (p2Config *config, psArray *frames);
+psArray *p2searchDoneFrames(p2Config *config);
