Index: /trunk/psModules/src/camera/pmFPAfileDefine.c
===================================================================
--- /trunk/psModules/src/camera/pmFPAfileDefine.c	(revision 11225)
+++ /trunk/psModules/src/camera/pmFPAfileDefine.c	(revision 11226)
@@ -406,5 +406,6 @@
 
     file->format = format;
-    *found = true;
+    if (found)
+        *found = true;
     return file;
 }
@@ -427,5 +428,4 @@
     pmFPAfile *file = NULL;
     psMetadata *phu = NULL;
-    psMetadata *format = NULL;
 
     if (found && *found)
@@ -452,4 +452,7 @@
     }
     // XXX temporary hack : force PSF input onto filename
+    // XXX EAM : I need to define a PSF container which specifies the chip/cell element
+    // XXX we could use the flat metadata style IF we restrict it to SIMPLE cameras
+    // XXX (ie, one readout per cell, one cell per chip, one chip per fpa)
     if (file->type == PM_FPA_FILE_PSF) {
         file->filerule = psStringCopy (infiles->data[0]);
@@ -461,5 +464,5 @@
     file->format = psMemIncrRefCounter(input->format);
 
-    // defin the rule to identify these files in the file->names data
+    // define the rule to identify these files in the file->names data
     psFree (file->filerule);
     psFree (file->filextra);
@@ -489,6 +492,6 @@
             return NULL;
         }
-        if (!pmConfigValidateCameraFormat (format, phu)) {
-            psError(PS_ERR_IO, false, "specified MASK %s does not match format of supplied INPUT\n", realName);
+        if (!pmConfigValidateCameraFormat (input->format, phu)) {
+            psError(PS_ERR_IO, false, "specified data file %s does not match format of supplied INPUT\n", realName);
             psFree (realName);
             psFitsClose (fits);
@@ -499,12 +502,8 @@
 
         // set the view to the corresponding entry for this phu
-        // XXX this will override the fpa->header, which I don't want to do.
-        // XXX do I need to carry around the mask and weight headers???
-        psAbort ("psModules", "pmFPAfileBindMaskFromArgs is not completed");
-        pmFPAview *view = pmFPAAddSourceFromHeader (input->fpa, phu, format);
+        pmFPAview *view = pmFPAIdentifySourceFromHeader (input->fpa, phu, input->format);
         if (!view) {
             psError(PS_ERR_IO, false, "Unable to determine source for %s", file->name);
             psFree(phu);
-            psFree (format);
             return NULL;
         }
@@ -520,5 +519,6 @@
         psFree (phu);
     }
-    *found = true;
+    if (found)
+        *found = true;
     return file;
 }
@@ -604,4 +604,7 @@
     if (!filemenu) {
         psError (PS_ERR_IO, true, "missing FILE in FORMAT");
+        psFree(phu);
+        psFree(fpa);
+        psFree(format);
         return NULL;
     }
@@ -609,4 +612,7 @@
     if (!levelName) {
         psError (PS_ERR_IO, true, "missing PHU in FILE in FORMAT");
+        psFree(phu);
+        psFree(fpa);
+        psFree(format);
         return NULL;
     }
@@ -614,4 +620,7 @@
     if (file->fileLevel == PM_FPA_LEVEL_NONE) {
         psError (PS_ERR_IO, true, "unknown level");
+        psFree(phu);
+        psFree(fpa);
+        psFree(format);
         return NULL;
     }
@@ -622,6 +631,6 @@
         psError(PS_ERR_IO, false, "Unable to determine source for %s", file->name);
         psFree(phu);
-        psFree (fpa);
-        psFree (format);
+        psFree(fpa);
+        psFree(format);
         return NULL;
     }
@@ -638,6 +647,6 @@
     psFree (fpa);
 
-    file->format = format;
-    *found = true;
+    if (found)
+        *found = true;
     return file;
 }
@@ -669,11 +678,9 @@
     // the returned file is just a view to the entry on config->files
     pmFPAfile *file = pmFPAfileDefineInput (config, fpa, filename);
+    psFree (fpa);
     if (!file) {
         psError(PS_ERR_IO, false, "file %s not defined\n", filename);
-        psFree(fpa);
-        psFree(file);
-        return NULL;
-    }
-
+        return NULL;
+    }
 
     // image names may not come from file->names
@@ -681,5 +688,4 @@
         psError(PS_ERR_IO, true, "supplied filerule uses illegal value @FILES");
         // XXX remove the file from config->files
-        psFree(fpa);
         psFree(file);
         return NULL;
@@ -691,5 +697,4 @@
         // don't free the file here: it is left on config->files
         // to be used optionally by pmFPAfileDefineFromDetDB (or others)
-        psFree(fpa);
         return NULL;
     }
@@ -700,9 +705,6 @@
     file->filerule = tmpName;
 
-    if (found) {
+    if (found)
         *found = true;
-    }
-    psFree (fpa);                       // Drop reference
-
     return file;
 }
@@ -794,27 +796,7 @@
         }
         char *option  = item->name;     // item->name must correspond to a valid detselect option
-
-        psArray *conceptData = psStringSplitArray ((char *) item->data.V, ":", true);
-        if (conceptData == NULL)
-            psAbort ("psModules", "programming error");
-        if (conceptData->n == 0)
-            psAbort ("psModules", "missing data for %s", item->name);
-        if (conceptData->n  > 2)
-            psAbort ("psModules", "invalid format for %s", item->name);
-
-        char *concept = NULL;
-        char *function = NULL;
-        if (conceptData->n == 1) {
-            concept = conceptData->data[0];
-        }
-        if (conceptData->n == 2) {
-            function = conceptData->data[0];
-            concept = conceptData->data[1];
-        }
-
-        // XXX: 'function' unncesssary now that it's not required for filter?
+        char *concept = item->data.V;
+
         if (!strcasecmp (option, "filter")) {
-            if (function)
-                psAbort ("psModules", "no detrend constraint function for filter");
             options->filter = psMetadataLookupPtr (&status, input->concepts, concept);
             if (!status)
@@ -823,6 +805,4 @@
         }
         if (!strcasecmp (option, "exptime")) {
-            if (function)
-                psAbort ("psModules", "no detrend constraint function for exptime");
             options->exptime = psMetadataLookupF32 (&status, input->concepts, concept);
             if (!status)
@@ -830,7 +810,5 @@
         }
         if (!strcasecmp (option, "airmass")) {
-            if (function)
-                psAbort ("psModules", "no detrend constraint function for airmass");
-            options->airmass = psMetadataLookupF32 (NULL, input->concepts, concept);
+            options->airmass = psMetadataLookupF32 (&status, input->concepts, concept);
             if (!status)
                 psAbort ("psModules", "airmass not found");
@@ -838,5 +816,5 @@
         # if (0)
             if (!strcasecmp (option, "dettemp")) {
-                options->dettemp = psMetadataLookupF32 (NULL, input->concepts, concept);
+                options->dettemp = psMetadataLookupF32 (&status, input->concepts, concept);
                 if (!status)
                     psAbort ("psModules", "dettemp not found");
@@ -844,15 +822,15 @@
         if (!strcasecmp (option, "version")) {
             // version is applied as a literal string
-            if (function)
-                psAbort ("psModules", "no detrend constraint function for airmass");
-            options->version = psStringCopy(concept);
+            options->version = psMetadataLookupF32 (&status, input->concepts, concept);
+            if (!status)
+                psAbort ("psModules", "version not found");
         }
         if (!strcasecmp (option, "twilight")) {
             // XXX determine the twilight time based on concept defining the time-of-day
-            options->twilight = psMetadataLookupF32 (NULL, input->concepts, concept);
+            // XXX need to include twilight time somehow (uses lookup based on a time value)
+            options->twilight = psMetadataLookupF32 (&status, input->concepts, concept);
             if (!status)
-                psAbort ("psModules", "dettemp not found");
-        }
-        // XXX need to include twilight time somehow (uses lookup based on a time value)
+                psAbort ("psModules", "twilight not found");
+        }
         # endif
 
@@ -877,5 +855,6 @@
     psFree (options);
 
-    *found = true;
+    if (found)
+        *found = true;
     return file;
 }
