Index: /trunk/psModules/src/camera/pmFPAfileDefine.c
===================================================================
--- /trunk/psModules/src/camera/pmFPAfileDefine.c	(revision 11875)
+++ /trunk/psModules/src/camera/pmFPAfileDefine.c	(revision 11876)
@@ -784,4 +784,5 @@
     // added if specified for the particular detrend type by the DETREND.CONSTRAINTS
     // note that the filter-dependent choices are set for ppImage in ppImageParseCamera
+    // XXX make all of the detrend constraints explicit in DETREND.CONSTRAINTS?
 
     // Get the time from FPA.TIME
@@ -793,5 +794,5 @@
 
     // add additional constraints based on the type defined in the PPIMAGE recipe
-    // use PPIMAGE or DETREND or ???
+    // XXX use PPIMAGE or DETREND for the recipe name?
     psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, "PPIMAGE");
     if (!status)
@@ -819,6 +820,9 @@
         char *concept = item->data.V;
 
+	// these items refer to the corresponding values for the input image 
+	// (ie, -filter input:filter or -exptime input:exptime)
         if (!strcasecmp (option, "filter")) {
             options->filter = psMetadataLookupPtr (&status, input->concepts, concept);
+	    psMemIncrRefCounter (options->filter);
             if (!status)
                 psAbort("failed to find filter (concept %s)", concept);
@@ -827,4 +831,5 @@
         if (!strcasecmp (option, "exptime")) {
             options->exptime = psMetadataLookupF32 (&status, input->concepts, concept);
+	    options->exptimeSet = true;
             if (!status)
                 psAbort("exptime not found (concept %s)", concept);
@@ -832,28 +837,31 @@
         if (!strcasecmp (option, "airmass")) {
             options->airmass = psMetadataLookupF32 (&status, input->concepts, concept);
+	    options->airmassSet = true;
             if (!status)
                 psAbort("airmass not found (concept %s)", concept);
         }
-        # if (0)
-            if (!strcasecmp (option, "dettemp")) {
-                options->dettemp = psMetadataLookupF32 (&status, input->concepts, concept);
-                if (!status)
-                    psAbort("dettemp not found (concept %s)", concept);
-            }
-        if (!strcasecmp (option, "version")) {
-            // version is applied as a literal string
-            options->version = psMetadataLookupF32 (&status, input->concepts, concept);
-            if (!status)
-                psAbort("version not found (concept %s)", concept);
-        }
+	if (!strcasecmp (option, "dettemp")) {
+	    options->dettemp = psMetadataLookupF32 (&status, input->concepts, concept);
+	    options->dettempSet = true;
+	    if (!status)
+		psAbort("dettemp not found (concept %s)", concept);
+	}
         if (!strcasecmp (option, "twilight")) {
-            // XXX determine the twilight time based on concept defining the time-of-day
-            // XXX need to include twilight time somehow (uses lookup based on a time value)
             options->twilight = psMetadataLookupF32 (&status, input->concepts, concept);
+	    options->twilightSet = true;
             if (!status)
                 psAbort("twilight not found (concept %s)", concept);
         }
-        # endif
-
+
+	// the version is applied literally
+        if (!strcasecmp (option, "version")) {
+            options->version = psMemIncrRefCounter (concept);
+        }
+	// we can override the detrend database dettype if desired
+	// ie, use DOMEFLAT for type FLAT
+	// the dettype string is applied literally
+        if (!strcasecmp (option, "dettype")) {
+            options->dettype = psMemIncrRefCounter (concept);
+        }
     }
     psFree(iter);
Index: /trunk/psModules/src/detrend/pmDetrendDB.c
===================================================================
--- /trunk/psModules/src/detrend/pmDetrendDB.c	(revision 11875)
+++ /trunk/psModules/src/detrend/pmDetrendDB.c	(revision 11876)
@@ -24,4 +24,7 @@
 
     psFree (options->camera);
+    psFree (options->filter);
+    psFree (options->dettype);
+    psFree (options->version);
 
     return;
@@ -41,7 +44,16 @@
 
     // these other options depend on the type of detrend data
-    options->filter = NULL;  //
-    options->exptime = -1.0; // the undefined value (safe since exptime >= 0)
-    options->airmass = -1.0; // the undefined value (safe since airmass >= 1)
+    options->filter   = NULL;
+    options->version  = NULL;
+    options->dettype  = NULL;
+    options->exptime  = 0.0; 
+    options->airmass  = 0.0; 
+    options->dettemp  = 0.0; 
+    options->twilight = 0.0; 
+
+    options->exptimeSet  = false; // not selected
+    options->airmassSet  = false; // not selected
+    options->dettempSet  = false; // not selected
+    options->twilightSet = false; // not selected
 
     return options;
@@ -105,5 +117,11 @@
     psString line = NULL;
     char *time = psTimeToISO (&options->time);
-    char *type = pmDetrendTypeToString (options->type);
+
+    char *type = NULL;
+    if (options->dettype) {
+	type = psMemIncrRefCounter (options->dettype);
+    } else {
+	type = pmDetrendTypeToString (options->type);
+    }
     unsigned int nFail;
 
@@ -114,9 +132,18 @@
         psStringAppend(&line, " -filter %s", options->filter);
     }
-    if (options->exptime > -1.0) {
+    if (options->version) {
+        psStringAppend(&line, " -version %s", options->version);
+    }
+    if (options->exptimeSet) {
         psStringAppend(&line, " -exp_time %f", options->exptime);
     }
-    if (options->airmass > -1.0) {
+    if (options->airmassSet) {
         psStringAppend(&line, " -airmass %f", options->airmass);
+    }
+    if (options->dettempSet) {
+        psStringAppend(&line, " -airmass %f", options->dettemp);
+    }
+    if (options->twilightSet) {
+        psStringAppend(&line, " -airmass %f", options->twilight);
     }
 
Index: /trunk/psModules/src/detrend/pmDetrendDB.h
===================================================================
--- /trunk/psModules/src/detrend/pmDetrendDB.h	(revision 11875)
+++ /trunk/psModules/src/detrend/pmDetrendDB.h	(revision 11876)
@@ -9,6 +9,6 @@
  * @author EAM, IfA
  *
- * @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-01-31 00:35:24 $
+ * @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-02-18 21:03:20 $
  * Copyright 2004-2005 Institute for Astronomy, University of Hawaii
  */
@@ -37,10 +37,19 @@
 typedef struct
 {
-    char *camera;   // name of camera
-    psTime time;   // time of input data
-    pmDetrendType type;   // type of detrend data
-    char *filter;   // name of filter
-    float exptime;   // exposure time (for dark, maybe flat & fringe)
-    float airmass;   // for fringe
+    char *camera;			// name of camera
+    char *version;			// optional version string
+    char *filter;			// name of filter
+    char *dettype;			// actual detrend type name
+    float exptime;			// exposure time (for dark, maybe flat & fringe)
+    float airmass;			// for fringe
+    float dettemp;			// for fringe
+    float twilight;			// hours (or seconds?) since/before nearest twilight
+    psTime time;			// time of input data
+    pmDetrendType type;			// type of detrend data
+
+    bool  exptimeSet;
+    bool  airmassSet;
+    bool  dettempSet;
+    bool  twilightSet;
 }
 pmDetrendSelectOptions;
