Index: trunk/ppImage/src/ppImageParseDetrend.c
===================================================================
--- trunk/ppImage/src/ppImageParseDetrend.c	(revision 6747)
+++ trunk/ppImage/src/ppImageParseDetrend.c	(revision 6817)
@@ -1,23 +1,62 @@
-#include <stdio.h>
-#include "pslib.h"
-#include "psmodules.h"
-#include "ppFile.h"
-#include "ppImageData.h"
-#include "ppImageOptions.h"
 #include "ppImage.h"
 
-// open all needed detrend files
-// read in primary headers
-// validate camera for each detrend image
+// identify all needed detrend and other I/O files
+// create the pmFPAfiles for the active I/O files 
 
-// XXX : keep the primary headers in data?
-// XXX : add fringe frame
+bool ppImageParseDetrend(ppImageOptions *options, pmConfig *config)
+{
 
-bool ppImageParseDetrend(ppImageData *data, ppImageOptions *options, pmConfig *config)
-{
-    ppFileOpen(data->mask, "mask", options->doMask);
-    ppFileOpen(data->bias, "bias", options->doBias);
-    ppFileOpen(data->dark, "dark", options->doDark);
-    ppFileOpen(data->flat, "flat", options->doFlat);
+    bool status;
+
+    // some of the output files are associated with the input fpa
+    pmFPAfile *input = psMetadataLookupPtr (&status, config->files, "PPIMAGE.INPUT");
+
+    // the following are defined from the argument list, if given, 
+    // otherwise they revert to the config information
+
+    if (options->doBias) {
+	bool status = false;
+	pmFPAfileFromArgs (&status, config, "PPIMAGE.BIAS", "BIAS");
+	pmFPAfileFromConf (&status, config, "PPIMAGE.BIAS", input->fpa);
+	if (!status) psAbort ("ppImageParseDetrend", "can't find a bias image source");
+    }
+
+    if (options->doDark) {
+	bool status = false;
+	pmFPAfileFromArgs (&status, config, "PPIMAGE.DARK", "DARK");
+	pmFPAfileFromConf (&status, config, "PPIMAGE.DARK", input->fpa);
+	if (!status) psAbort ("ppImageParseDetrend", "can't find a dark image source");
+    }
+
+    if (options->doMask) {
+	bool status = false;
+	pmFPAfileFromArgs (&status, config, "PPIMAGE.MASK", "MASK");
+	pmFPAfileFromConf (&status, config, "PPIMAGE.MASK", input->fpa);
+	if (!status) psAbort ("ppImageParseDetrend", "can't find a mask image source");
+    }
+
+    if (options->doFlat) {
+	bool status = false;
+	pmFPAfileFromArgs (&status, config, "PPIMAGE.FLAT", "FLAT");
+	pmFPAfileFromConf (&status, config, "PPIMAGE.FLAT", input->fpa);
+	if (!status) psAbort ("ppImageParseDetrend", "can't find a flat image source");
+    }
+
+    // the following files are output targets
+    // XXX which of these are required?
+    pmFPAfileDefine (config->files, config->camera, input->fpa, "PPIMAGE.OUTPUT");
+
+    // XXX do these need to construct a new fpa?
+    // pmFPAfileDefine (config->files, config->camera, input->input, "PPIMAGE.BIN1");
+    // pmFPAfileDefine (config->files, config->camera, input->input, "PPIMAGE.BIN2");
+    // pmFPAfileDefine (config->files, config->camera, input->input, "PPIMAGE.JPG1");
+    // pmFPAfileDefine (config->files, config->camera, input->input, "PPIMAGE.JPG2");
+
+    // ppImage is supplied with an output name, which may be used by multiple
+    // output files to construct the output names.  supply this value to the
+    // files which are write types.
+    char *output = psMetadataLookupPtr(&status, config->arguments, "OUTPUT");
+    pmFPAfileAddFileNames (config->files, "OUTPUT", output, PM_FPA_MODE_WRITE);
+
     return true;
 }
