Index: trunk/psModules/src/camera/pmFPA_JPEG.c
===================================================================
--- trunk/psModules/src/camera/pmFPA_JPEG.c	(revision 10417)
+++ trunk/psModules/src/camera/pmFPA_JPEG.c	(revision 10421)
@@ -5,6 +5,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-12-02 04:24:48 $
+ *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-12-03 18:48:10 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -31,5 +31,5 @@
 
 
-bool pmFPAviewWriteJPEG(const pmFPAview *view, pmFPAfile *file)
+bool pmFPAviewWriteJPEG(const pmFPAview *view, pmFPAfile *file, pmConfig *config)
 {
     PS_ASSERT_PTR_NON_NULL(view, false);
@@ -39,5 +39,5 @@
 
     if (view->chip == -1) {
-        pmFPAWriteJPEG (fpa, view, file);
+        pmFPAWriteJPEG (fpa, view, file, config);
         return true;
     }
@@ -49,5 +49,5 @@
 
     if (view->cell == -1) {
-        pmChipWriteJPEG (chip, view, file);
+        pmChipWriteJPEG (chip, view, file, config);
         return true;
     }
@@ -59,5 +59,5 @@
 
     if (view->readout == -1) {
-        pmCellWriteJPEG (cell, view, file);
+        pmCellWriteJPEG (cell, view, file, config);
         return true;
     }
@@ -68,10 +68,10 @@
     pmReadout *readout = cell->readouts->data[view->readout];
 
-    pmReadoutWriteJPEG (readout, view, file);
+    pmReadoutWriteJPEG (readout, view, file, config);
     return true;
 }
 
 // read in all chip-level JPEG files for this FPA
-bool pmFPAWriteJPEG (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file)
+bool pmFPAWriteJPEG (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, pmConfig *config)
 {
     PS_ASSERT_PTR_NON_NULL(fpa, false);
@@ -82,5 +82,5 @@
 
         pmChip *chip = fpa->chips->data[i];
-        pmChipWriteJPEG (chip, view, file);
+        pmChipWriteJPEG (chip, view, file, config);
     }
     return true;
@@ -88,5 +88,5 @@
 
 // read in all cell-level JPEG files for this chip
-bool pmChipWriteJPEG (pmChip *chip, const pmFPAview *view, pmFPAfile *file)
+bool pmChipWriteJPEG (pmChip *chip, const pmFPAview *view, pmFPAfile *file, pmConfig *config)
 {
     PS_ASSERT_PTR_NON_NULL(chip, false);
@@ -97,5 +97,5 @@
 
         pmCell *cell = chip->cells->data[i];
-        pmCellWriteJPEG (cell, view, file);
+        pmCellWriteJPEG (cell, view, file, config);
     }
     return true;
@@ -103,5 +103,5 @@
 
 // read in all readout-level JPEG files for this cell
-bool pmCellWriteJPEG (pmCell *cell, const pmFPAview *view, pmFPAfile *file)
+bool pmCellWriteJPEG (pmCell *cell, const pmFPAview *view, pmFPAfile *file, pmConfig *config)
 {
     PS_ASSERT_PTR_NON_NULL(cell, false);
@@ -112,5 +112,5 @@
 
         pmReadout *readout = cell->readouts->data[i];
-        pmReadoutWriteJPEG (readout, view, file);
+        pmReadoutWriteJPEG (readout, view, file, config);
     }
     return true;
@@ -118,5 +118,5 @@
 
 // read in all readout-level Objects files for this cell
-bool pmReadoutWriteJPEG (pmReadout *readout, const pmFPAview *view, pmFPAfile *file)
+bool pmReadoutWriteJPEG (pmReadout *readout, const pmFPAview *view, pmFPAfile *file, pmConfig *config)
 {
     PS_ASSERT_PTR_NON_NULL(readout, false);
@@ -178,4 +178,5 @@
 
     psString name = pmFPAfileNameFromRule (file->filerule, file, view);
+    psString newName = pmConfigConvertFilename (name, config);
     psString mapname = pmFPAfileNameFromRule (file->filextra, file, view);
     psImageJpegColormap *map = psImageJpegColormapSet (NULL, mapname);
@@ -185,5 +186,6 @@
     }
 
-    psImageJpeg (map, readout->image, name, min, max);
+    psImageJpeg (map, readout->image, newName, min, max);
+    psFree(newName);
     psFree(name);
     psFree(map);
Index: trunk/psModules/src/camera/pmFPA_JPEG.h
===================================================================
--- trunk/psModules/src/camera/pmFPA_JPEG.h	(revision 10417)
+++ trunk/psModules/src/camera/pmFPA_JPEG.h	(revision 10421)
@@ -7,6 +7,6 @@
 *  @author EAM, IfA
 *
-*  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2006-05-01 01:55:43 $
+*  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2006-12-03 18:48:10 $
 *
 *  Copyright 2004-2005 Institute for Astronomy, University of Hawaii
@@ -19,9 +19,9 @@
 /// @{
 
-bool pmFPAviewWriteJPEG (const pmFPAview *view, pmFPAfile *file);
-bool pmFPAWriteJPEG (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file);
-bool pmChipWriteJPEG (pmChip *chip, const pmFPAview *view, pmFPAfile *file);
-bool pmCellWriteJPEG (pmCell *cell, const pmFPAview *view, pmFPAfile *file);
-bool pmReadoutWriteJPEG (pmReadout *readout, const pmFPAview *view, pmFPAfile *file);
+bool pmFPAviewWriteJPEG (const pmFPAview *view, pmFPAfile *file, pmConfig *config);
+bool pmFPAWriteJPEG (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, pmConfig *config);
+bool pmChipWriteJPEG (pmChip *chip, const pmFPAview *view, pmFPAfile *file, pmConfig *config);
+bool pmCellWriteJPEG (pmCell *cell, const pmFPAview *view, pmFPAfile *file, pmConfig *config);
+bool pmReadoutWriteJPEG (pmReadout *readout, const pmFPAview *view, pmFPAfile *file, pmConfig *config);
 
 # endif
Index: trunk/psModules/src/camera/pmFPA_MANAPLOT.c
===================================================================
--- trunk/psModules/src/camera/pmFPA_MANAPLOT.c	(revision 10417)
+++ trunk/psModules/src/camera/pmFPA_MANAPLOT.c	(revision 10421)
@@ -5,6 +5,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-10-17 00:41:05 $
+ *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-12-03 18:48:10 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -31,5 +31,5 @@
 
 
-bool pmFPAviewWriteMANAPLOT(const pmFPAview *view, pmFPAfile *file)
+bool pmFPAviewWriteMANAPLOT(const pmFPAview *view, pmFPAfile *file, pmConfig *config)
 {
     PS_ASSERT_PTR_NON_NULL(view, false);
@@ -39,5 +39,5 @@
 
     if (view->chip == -1) {
-        pmFPAWriteMANAPLOT (fpa, view, file);
+        pmFPAWriteMANAPLOT (fpa, view, file, config);
         return true;
     }
@@ -49,5 +49,5 @@
 
     if (view->cell == -1) {
-        pmChipWriteMANAPLOT (chip, view, file);
+        pmChipWriteMANAPLOT (chip, view, file, config);
         return true;
     }
@@ -59,5 +59,5 @@
 
     if (view->readout == -1) {
-        pmCellWriteMANAPLOT (cell, view, file);
+        pmCellWriteMANAPLOT (cell, view, file, config);
         return true;
     }
@@ -68,10 +68,10 @@
     pmReadout *readout = cell->readouts->data[view->readout];
 
-    pmReadoutWriteMANAPLOT (readout, view, file);
+    pmReadoutWriteMANAPLOT (readout, view, file, config);
     return true;
 }
 
 // read in all chip-level MANAPLOT files for this FPA
-bool pmFPAWriteMANAPLOT (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file)
+bool pmFPAWriteMANAPLOT (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, pmConfig *config)
 {
     PS_ASSERT_PTR_NON_NULL(fpa, false);
@@ -82,5 +82,5 @@
 
         pmChip *chip = fpa->chips->data[i];
-        pmChipWriteMANAPLOT (chip, view, file);
+        pmChipWriteMANAPLOT (chip, view, file, config);
     }
     return true;
@@ -88,5 +88,5 @@
 
 // read in all cell-level MANAPLOT files for this chip
-bool pmChipWriteMANAPLOT (pmChip *chip, const pmFPAview *view, pmFPAfile *file)
+bool pmChipWriteMANAPLOT (pmChip *chip, const pmFPAview *view, pmFPAfile *file, pmConfig *config)
 {
     PS_ASSERT_PTR_NON_NULL(chip, false);
@@ -97,5 +97,5 @@
 
         pmCell *cell = chip->cells->data[i];
-        pmCellWriteMANAPLOT (cell, view, file);
+        pmCellWriteMANAPLOT (cell, view, file, config);
     }
     return true;
@@ -103,5 +103,5 @@
 
 // read in all readout-level MANAPLOT files for this cell
-bool pmCellWriteMANAPLOT (pmCell *cell, const pmFPAview *view, pmFPAfile *file)
+bool pmCellWriteMANAPLOT (pmCell *cell, const pmFPAview *view, pmFPAfile *file, pmConfig *config)
 {
     PS_ASSERT_PTR_NON_NULL(cell, false);
@@ -112,5 +112,5 @@
 
         pmReadout *readout = cell->readouts->data[i];
-        pmReadoutWriteMANAPLOT (readout, view, file);
+        pmReadoutWriteMANAPLOT (readout, view, file, config);
     }
     return true;
@@ -118,5 +118,5 @@
 
 // read in all readout-level Objects files for this cell
-bool pmReadoutWriteMANAPLOT (pmReadout *readout, const pmFPAview *view, pmFPAfile *file)
+bool pmReadoutWriteMANAPLOT (pmReadout *readout, const pmFPAview *view, pmFPAfile *file, pmConfig *config)
 {
     PS_ASSERT_PTR_NON_NULL(readout, false);
@@ -136,7 +136,16 @@
     // output : filerule
 
-    psString input = pmFPAfileNameFromRule (file->filextra, file, view);
-    psString output = pmFPAfileNameFromRule (file->filerule, file, view);
-    psString script = pmFPAfileNameFromRule (file->extname, file, view);
+    psString tmpName;
+    tmpName = pmFPAfileNameFromRule (file->filextra, file, view);
+    psString input = pmConfigConvertFilename (tmpName, config);
+    psFree (tmpName);
+
+    tmpName = pmFPAfileNameFromRule (file->filerule, file, view);
+    psString output = pmConfigConvertFilename (tmpName, config);
+    psFree (tmpName);
+
+    tmpName = pmFPAfileNameFromRule (file->extname, file, view);
+    psString script = pmConfigConvertFilename (tmpName, config);
+    psFree (tmpName);
 
     psString line = NULL;
Index: trunk/psModules/src/camera/pmFPA_MANAPLOT.h
===================================================================
--- trunk/psModules/src/camera/pmFPA_MANAPLOT.h	(revision 10417)
+++ trunk/psModules/src/camera/pmFPA_MANAPLOT.h	(revision 10421)
@@ -7,6 +7,6 @@
 *  @author EAM, IfA
 *
-*  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2006-10-17 00:41:05 $
+*  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2006-12-03 18:48:10 $
 *
 *  Copyright 2004-2005 Institute for Astronomy, University of Hawaii
@@ -19,9 +19,9 @@
 /// @{
 
-bool pmFPAviewWriteMANAPLOT (const pmFPAview *view, pmFPAfile *file);
-bool pmFPAWriteMANAPLOT (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file);
-bool pmChipWriteMANAPLOT (pmChip *chip, const pmFPAview *view, pmFPAfile *file);
-bool pmCellWriteMANAPLOT (pmCell *cell, const pmFPAview *view, pmFPAfile *file);
-bool pmReadoutWriteMANAPLOT (pmReadout *readout, const pmFPAview *view, pmFPAfile *file);
+bool pmFPAviewWriteMANAPLOT (const pmFPAview *view, pmFPAfile *file, pmConfig *config);
+bool pmFPAWriteMANAPLOT (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, pmConfig *config);
+bool pmChipWriteMANAPLOT (pmChip *chip, const pmFPAview *view, pmFPAfile *file, pmConfig *config);
+bool pmCellWriteMANAPLOT (pmCell *cell, const pmFPAview *view, pmFPAfile *file, pmConfig *config);
+bool pmReadoutWriteMANAPLOT (pmReadout *readout, const pmFPAview *view, pmFPAfile *file, pmConfig *config);
 
 # endif
Index: trunk/psModules/src/camera/pmFPAfileDefine.c
===================================================================
--- trunk/psModules/src/camera/pmFPAfileDefine.c	(revision 10417)
+++ trunk/psModules/src/camera/pmFPAfileDefine.c	(revision 10421)
@@ -277,7 +277,23 @@
     }
 
+    psString realName = pmConfigConvertFilename (infiles->data[0], config);
+    if (!realName) {
+        psError(PS_ERR_IO, false, "Failed to convert file name %s\n", (char *) infiles->data[0]);
+        return NULL;
+    }
+
     // load the header of the first image
-    fits = psFitsOpen (infiles->data[0], "r");
+    fits = psFitsOpen (realName, "r");
+    if (!fits) {
+        psError(PS_ERR_IO, false, "Failed to open file %s\n", realName);
+        psFree (realName);
+        return NULL;
+    }
     phu = psFitsReadHeader (NULL, fits);
+    if (!phu) {
+        psError(PS_ERR_IO, false, "Failed to read file header %s\n", realName);
+        psFree (realName);
+        return NULL;
+    }
     psFitsClose (fits);
 
@@ -286,6 +302,7 @@
     format = pmConfigCameraFormatFromHeader (config, phu);
     if (!format) {
-        psError(PS_ERR_IO, false, "Failed to read CCD format from %s\n", (char *)infiles->data[0]);
+        psError(PS_ERR_IO, false, "Failed to read CCD format from %s\n", realName);
         psFree(phu);
+        psFree (realName);
         return NULL;
     }
@@ -294,7 +311,9 @@
     fpa = pmFPAConstruct (config->camera);
     if (!fpa) {
-        psError(PS_ERR_IO, false, "Failed to construct FPA from %s", (char *)infiles->data[0]);
-        return NULL;
-    }
+        psError(PS_ERR_IO, false, "Failed to construct FPA from %s", realName);
+        psFree (realName);
+        return NULL;
+    }
+    psFree (realName);
 
     // load the given filerule (from config->camera) and bind it to the fpa
@@ -337,7 +356,28 @@
     for (int i = 0; i < infiles->n; i++) {
         if (i > 0) {
-            fits = psFitsOpen (infiles->data[i], "r");
+            psString realName = pmConfigConvertFilename (infiles->data[i], config);
+            if (!realName) {
+                psError(PS_ERR_IO, false, "Failed to convert file name %s", (char *) infiles->data[i]);
+                return NULL;
+            }
+            fits = psFitsOpen (realName, "r");
+            if (!fits) {
+                psError(PS_ERR_IO, false, "Failed to open file %s\n", realName);
+                psFree (realName);
+                return NULL;
+            }
             phu = psFitsReadHeader (NULL, fits);
-            pmConfigValidateCameraFormat (format, phu);
+            if (!phu) {
+                psError(PS_ERR_IO, false, "Failed to read file header %s", realName);
+                psFree (realName);
+                psFitsClose (fits);
+                return NULL;
+            }
+            if (!pmConfigValidateCameraFormat (format, phu)) {
+                psError(PS_ERR_IO, false, "file %s is not from the required camera", realName);
+                psFree (realName);
+                psFitsClose (fits);
+                return NULL;
+            }
             psFitsClose (fits);
         }
@@ -545,7 +585,7 @@
 
     // Prepend the global path to the file rule
-    if (config->workdir) {
-        psStringPrepend(&file->filerule, "%s/", config->workdir);
-    }
+    psString tmpName = pmConfigConvertFilename (file->filerule, config);
+    psFree (file->filerule);
+    file->filerule = tmpName;
 
     if (found) {
Index: trunk/psModules/src/camera/pmFPAfileIO.c
===================================================================
--- trunk/psModules/src/camera/pmFPAfileIO.c	(revision 10417)
+++ trunk/psModules/src/camera/pmFPAfileIO.c	(revision 10421)
@@ -210,15 +210,12 @@
         }
 
-        // XXXX this is very ad-hoc
-        // XXXX prepend the value config[WORKDIR] to the filename...
-        char *workdir = psMetadataLookupStr (NULL, config->site, "WORKDIR");
-        if (workdir) {
-            psStringPrepend (&file->filename, "%s/", workdir);
-        }
-
         psTrace ("pmFPAfile", 6, "got detrend file %s\n", file->filename);
         psFree (extra);
     }
-    // if () "neb://" -> get from neb...
+
+    // apply filename mangling rules (file://, path://, neb://, WORKDIR)
+    psString tmpName = pmConfigConvertFilename (file->filename, config);
+    psFree (file->filename);
+    file->filename = tmpName;
 
     switch (file->type) {
@@ -353,10 +350,10 @@
     case PM_FPA_FILE_CMP:
     case PM_FPA_FILE_CMF:
-        pmFPAviewReadObjects (view, file);
+        pmFPAviewReadObjects (view, file, config);
         psTrace ("pmFPAfile", 5, "reading %s (type: %d)\n", file->filename, file->type);
         break;
 
     case PM_FPA_FILE_PSF:
-        pmFPAviewReadPSFmodel (view, file);
+        pmFPAviewReadPSFmodel (view, file, config);
         psTrace ("pmFPAfile", 5, "reading %s (type: %d)\n", file->filename, file->type);
         break;
@@ -508,5 +505,5 @@
     case PM_FPA_FILE_CMF:
         psTrace ("pmFPAfile", 5, "writing object %s (fpa: %p)\n", file->filename, file->fpa);
-        if (!pmFPAviewWriteObjects (view, file)) {
+        if (!pmFPAviewWriteObjects (view, file, config)) {
             psError(PS_ERR_IO, false, "Failed to write object %s", file->filename);
             return false;
@@ -516,15 +513,15 @@
 
     case PM_FPA_FILE_PSF:
-        pmFPAviewWritePSFmodel (view, file);
+        pmFPAviewWritePSFmodel (view, file, config);
         psTrace ("pmFPAfile", 5, "wrote PSF %s (fpa: %p)\n", file->filename, file->fpa);
         break;
 
     case PM_FPA_FILE_JPEG:
-        pmFPAviewWriteJPEG (view, file);
+        pmFPAviewWriteJPEG (view, file, config);
         psTrace ("pmFPAfile", 5, "wrote JPEG %s (fpa: %p)\n", file->filename, file->fpa);
         break;
 
     case PM_FPA_FILE_MANAPLOT:
-        pmFPAviewWriteMANAPLOT (view, file);
+        pmFPAviewWriteMANAPLOT (view, file, config);
         psTrace ("pmFPAfile", 5, "wrote MANAPLOT %s (fpa: %p)\n", file->filename, file->fpa);
         break;
