Index: /trunk/archive/scripts/src/phase2/pmFPARead.c
===================================================================
--- /trunk/archive/scripts/src/phase2/pmFPARead.c	(revision 5788)
+++ /trunk/archive/scripts/src/phase2/pmFPARead.c	(revision 5789)
@@ -219,6 +219,6 @@
 
 // Translate a name from the configuration file, containing something like "%a_%d" to a real value
-psString p_pmFPATranslateName(psString name, // The name to translate
-                              pmCell *cell // The cell for which to translate
+psString p_pmFPATranslateName(const psString name, // The name to translate
+                              const pmCell *cell // The cell for which to translate
     )
 {
@@ -338,4 +338,34 @@
 }
 
+// Get filename and extension out of "somefile.fits:ext"
+psString p_pmFPATranslateFileExt(psString *extName, // Extension name, to be returned
+                                 const psString name, // The string to be translated and then parsed
+                                 const pmCell *cell // The cell
+    )
+{
+    psString filenameExt = p_pmFPATranslateName(name, cell);
+    const char *colon = strchr(filenameExt, ':'); // Pointer to a colon in the filename-extn
+    psString filename = NULL;           // The filename
+    if (extName && *extName) {
+        psFree(*extName);
+    }
+    if (extName) {
+        *extName = NULL;
+    }
+
+    if (colon) {
+        filename = psStringNCopy(filenameExt, strlen(filenameExt) - strlen(colon));
+        if (strlen(colon) > 1) {
+            if (extName) {
+                *extName = psStringCopy(colon + 1);
+            }
+        }
+    } else {
+        filename = psMemIncrRefCounter(filenameExt);
+    }
+
+    return filename;
+}
+
 // Read a mask into the FPA
 bool pmFPAReadMask(pmFPA *fpa,          // FPA to read into
@@ -386,16 +416,6 @@
                     if (strcasecmp(sourceType, "FILE") == 0) {
                         // Source is a file (with optional extension, e.g., "myMaskFile.fits:thisExt"
-                        psString filenameExt = p_pmFPATranslateName(name, cell);
-                        char *colon = strchr(filenameExt, ':'); // Pointer to a colon in the filename-extn
-                        psString filename = NULL; // The filename
-                        psString extname = NULL;// The extenstion name
-                        if (colon) {
-                            filename = psStringNCopy(filenameExt, strlen(filenameExt) - strlen(colon));
-                            if (strlen(colon) > 1) {
-                                extname = psStringCopy(colon + 1);
-                            }
-                        } else {
-                            filename = psMemIncrRefCounter(filenameExt);
-                        }
+                        psString extname = NULL; // Extension name
+                        psString filename = p_pmFPATranslateFileExt(&extname, name, cell); // The filename
 
                         psFree(maskSource);
@@ -410,5 +430,4 @@
                         psFree(filename);
                         psFree(extname);
-                        psFree(filenameExt);
                     } else if (strncasecmp(sourceType, "EXT", 3) == 0) {
                         // Source is an extension in the original file
@@ -536,16 +555,6 @@
                     if (strcasecmp(sourceType, "FILE") == 0) {
                         // Source is a file (with optional extension, e.g., "myWeightFile.fits:thisExt"
-                        psString filenameExt = p_pmFPATranslateName(name, cell);
-                        char *colon = strchr(filenameExt, ':'); // Pointer to a colon in the filename-extn
-                        psString filename = NULL; // The filename
-                        psString extname = NULL;// The extenstion name
-                        if (colon) {
-                            filename = psStringNCopy(filenameExt, strlen(filenameExt) - strlen(colon));
-                            if (strlen(colon) > 1) {
-                                extname = psStringCopy(colon + 1);
-                            }
-                        } else {
-                            filename = psMemIncrRefCounter(filenameExt);
-                        }
+                        psString extname = NULL; // Extension name
+                        psString filename = p_pmFPATranslateFileExt(&extname, name, cell); // The filename
 
                         psFree(weightSource);
@@ -560,5 +569,4 @@
                         psFree(filename);
                         psFree(extname);
-                        psFree(filenameExt);
                     } else if (strncasecmp(sourceType, "EXT", 3) == 0) {
                         // Source is an extension in the original file
Index: /trunk/archive/scripts/src/phase2/pmFPARead.h
===================================================================
--- /trunk/archive/scripts/src/phase2/pmFPARead.h	(revision 5788)
+++ /trunk/archive/scripts/src/phase2/pmFPARead.h	(revision 5789)
@@ -4,20 +4,25 @@
 #include "pmFPA.h"
 
-bool pmFPARead(pmFPA *fpa,		// FPA to read into
-	       psFits *fits,		// FITS file from which to read
-	       psMetadata *phu,		// Primary header
-	       psDB *db			// Database handle, for concept ingest
+bool pmFPARead(pmFPA *fpa,              // FPA to read into
+               psFits *fits,            // FITS file from which to read
+               psMetadata *phu,         // Primary header
+               psDB *db                 // Database handle, for concept ingest
     );
 
-psString p_pmFPATranslateName(psString name, // The name to translate
-			      pmCell *cell // The cell for which to translate
+psString p_pmFPATranslateName(const psString name, // The name to translate
+                              const pmCell *cell // The cell for which to translate
     );
 
-bool pmFPAReadMask(pmFPA *fpa,		// FPA to read into
-		   psFits *source	// Source FITS file (for the original data)
+psString p_pmFPATranslateFileExt(psString *extName, // Extension name, to be returned
+                                 const psString filenameExt, // The string to parse into filename and ext
+                                 const pmCell *cell // The cell
     );
 
-bool pmFPAReadWeight(pmFPA *fpa,	// FPA to read into
-		     psFits *source	// Source FITS file (for the original data)
+bool pmFPAReadMask(pmFPA *fpa,          // FPA to read into
+                   psFits *source       // Source FITS file (for the original data)
+    );
+
+bool pmFPAReadWeight(pmFPA *fpa,        // FPA to read into
+                     psFits *source     // Source FITS file (for the original data)
     );
 
Index: /trunk/archive/scripts/src/phase2/pmFPAWrite.c
===================================================================
--- /trunk/archive/scripts/src/phase2/pmFPAWrite.c	(revision 5788)
+++ /trunk/archive/scripts/src/phase2/pmFPAWrite.c	(revision 5789)
@@ -124,17 +124,6 @@
                     if (strcasecmp(sourceType, "FILE") == 0) {
                         // Source is a file (with optional extension, e.g., "myMaskFile.fits:thisExt"
-                        psString filenameExt = p_pmFPATranslateName(name, cell);
-                        char *colon = strchr(filenameExt, ':'); // Pointer to a colon in the filename-extn
-                        psString filename = NULL; // The filename
-                        psString extname = NULL;// The extenstion name
-                        if (colon) {
-                            filename = psStringNCopy(filenameExt, strlen(filenameExt) - strlen(colon));
-                            if (strlen(colon) > 1) {
-                                extname = psStringCopy(colon + 1);
-                            }
-                        } else {
-                            filename = psMemIncrRefCounter(filenameExt);
-                        }
-
+                        psString extname = NULL; // Extension name
+                        psString filename = p_pmFPATranslateFileExt(&extname, name, cell); // The filename
                         psFree(maskDest);
                         maskDest = psFitsOpen(filename, "rw");
@@ -144,5 +133,4 @@
                         psFree(filename);
                         psFree(extname);
-                        psFree(filenameExt);
                     } else if (strncasecmp(sourceType, "EXT", 3) == 0) {
                         // Source is an extension in the original file
@@ -227,16 +215,6 @@
                     if (strcasecmp(sourceType, "FILE") == 0) {
                         // Source is a file (with optional extension, e.g., "myWeightFile.fits:thisExt"
-                        psString filenameExt = p_pmFPATranslateName(name, cell);
-                        char *colon = strchr(filenameExt, ':'); // Pointer to a colon in the filename-extn
-                        psString filename = NULL; // The filename
-                        psString extname = NULL;// The extenstion name
-                        if (colon) {
-                            filename = psStringNCopy(filenameExt, strlen(filenameExt) - strlen(colon));
-                            if (strlen(colon) > 1) {
-                                extname = psStringCopy(colon + 1);
-                            }
-                        } else {
-                            filename = psMemIncrRefCounter(filenameExt);
-                        }
+                        psString extname = NULL; // Extension name
+                        psString filename = p_pmFPATranslateFileExt(&extname, name, cell); // The filename
 
                         psFree(weightDest);
@@ -247,5 +225,4 @@
                         psFree(filename);
                         psFree(extname);
-                        psFree(filenameExt);
                     } else if (strncasecmp(sourceType, "EXT", 3) == 0) {
                         // Source is an extension in the original file
