Index: /trunk/psModules/src/camera/pmFPAfileDefine.c
===================================================================
--- /trunk/psModules/src/camera/pmFPAfileDefine.c	(revision 11091)
+++ /trunk/psModules/src/camera/pmFPAfileDefine.c	(revision 11092)
@@ -608,4 +608,5 @@
     PS_ASSERT_STRING_NON_EMPTY(filename, NULL);
 
+    bool status;
     pmFPA *fpa = NULL;
     pmFPAfile *file = NULL;
@@ -654,4 +655,54 @@
     pmDetrendSelectOptions *options = pmDetrendSelectOptionsAlloc(config->cameraName, *time, type);
 
+    // add additional constraints based on the type defined in the PPIMAGE recipe
+    // use PPIMAGE or DETREND or ???
+    psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, "PPIMAGE");
+    if (!status)
+        psAbort ("psModules", "PPIMAGE recipe not found");
+    psMetadata *detConstraints = psMetadataLookupPtr (&status, recipe, "DETREND.CONSTRAINTS");
+    if (!status)
+        psAbort ("psModules", "DETREND.CONSTRAINTS not found");
+    // XXX allow this and just skip?
+
+    char *typeName = pmDetrendTypeToString (type);
+    psMetadata *constraints = psMetadataLookupPtr (&status, detConstraints, typeName);
+    if (!status)
+        psAbort ("psModules", "DETREND.CONSTRAINTS for type %s not found", typeName);
+
+    // loop over the constraints and include in the detselect options
+    psMetadataIterator *iter = psMetadataIteratorAlloc (constraints, PS_LIST_HEAD, NULL);
+    psMetadataItem *item = NULL;
+    while ((item = psMetadataGetAndIncrement (iter)) != NULL) {
+        if (item->type != PS_DATA_STRING) {
+            psAbort ("psModules", "invalid type for DETREND.CONSTRAINT element");
+        }
+        char *option  = item->name;     // item->name must correspond to a valid detselect option
+        char *concept = item->data.V; // item->data.V is a concept to look up
+        if (!strcasecmp (option, "filter")) {
+            options->filter = psMetadataLookupPtr (&status, input->concepts, concept);
+            if (!status)
+                psAbort ("psModules", "filter not found");
+        }
+        if (!strcasecmp (option, "exptime")) {
+            options->exptime = psMetadataLookupF32 (&status, input->concepts, concept);
+            if (!status)
+                psAbort ("psModules", "exptime not found");
+        }
+        if (!strcasecmp (option, "airmass")) {
+            options->airmass = psMetadataLookupF32 (NULL, input->concepts, concept);
+            if (!status)
+                psAbort ("psModules", "airmass not found");
+        }
+        # if (0)
+            if (!strcasecmp (option, "dettemp")) {
+                options->dettemp = psMetadataLookupF32 (NULL, input->concepts, concept);
+                if (!status)
+                    psAbort ("psModules", "dettemp not found");
+            }
+        // XXX need to include twilight time somehow (uses lookup based on a time value)
+        # endif
+
+    }
+
     // search for existing detrend data (detID)
     pmDetrendSelectResults *results = pmDetrendSelect (options);
