Index: trunk/ippTools/src/pxframes.c
===================================================================
--- trunk/ippTools/src/pxframes.c	(revision 6224)
+++ trunk/ippTools/src/pxframes.c	(revision 6257)
@@ -2,4 +2,38 @@
 
 #include "pxtools.h"
+
+#define PX_FRAME_ALLOC(frametype, exptype) \
+ \
+static void frametype##Free(frametype *ptr);\
+ \
+frametype *frametype##Alloc( \
+    exptype##Row *exposure, \
+    psArray *images \
+) \
+{ \
+    frametype *frame; \
+ \
+    PS_ASSERT_PTR_NON_NULL(exposure, NULL); \
+    PS_ASSERT_PTR_NON_NULL(images, NULL); \
+ \
+    frame = psAlloc(sizeof(frametype)); \
+    psMemSetDeallocator(frame, (psFreeFunc)frametype##Free); \
+ \
+    frame->exposure = exposure; \
+    frame->images   = images; \
+ \
+    return frame; \
+} \
+ \
+static void frametype##Free(frametype *ptr) \
+{ \
+    psFree(ptr->exposure); \
+    psFree(ptr->images); \
+}
+
+PX_FRAME_ALLOC(newFrame, newExp);
+PX_FRAME_ALLOC(rawScienceFrame, rawScienceExp);
+PX_FRAME_ALLOC(p2PendingFrame, p2PendingExp);
+PX_FRAME_ALLOC(p2DoneFrame, p2DoneExp);
 
 #define PX_FRAME_PRINT(frametype, imfiletype) \
@@ -35,2 +69,43 @@
 PX_FRAME_PRINT(rawScienceFrame, rawImfile);
 PX_FRAME_PRINT(p2PendingFrame, p2PendingImfile);
+
+
+#define PX_FRAME_SEARCH(frametype, exptype, imfiletype) \
+psArray *frametype##Search(pxConfig *config) \
+{ \
+    PS_ASSERT_PTR_NON_NULL(config, NULL); \
+ \
+    psArray *exposures = exptype##SelectRowObjects(config->database, \
+        config->where, MAX_ROWS); \
+    if (!exposures) { \
+        psError(PS_ERR_UNKNOWN, false, "no exptype rows found"); \
+ \
+        return NULL; \
+    } \
+ \
+    psArray *allFrames = psArrayAlloc(exposures->n); \
+    allFrames->n = 0; \
+ \
+    psMetadata *where = psMetadataAlloc (); \
+    for (int i = 0; i < exposures->n; i++) { \
+        exptype##Row *exposure = exposures->data[i]; \
+\
+        psMetadataAddStr(where, PS_LIST_TAIL, "exp_id", PS_META_REPLACE, "==", \
+            exposure->exp_id); \
+ \
+        psArray *images = imfiletype##SelectRowObjects(config->database, where, \
+            MAX_ROWS); \
+        if (!images) { \
+            psError(PS_ERR_UNKNOWN, false, "database access failed"); \
+ \
+            return NULL; \
+        } \
+ \
+        frametype *frame = frametype##Alloc(exposure, images); \
+        psArrayAdd(allFrames, 100, frame); \
+    } \
+ \
+    return allFrames; \
+} 
+
+PX_FRAME_SEARCH(newFrame, newExp, newImfile);
