Index: /branches/neb/archive/scripts/src/phase2/pmFPAWrite.c
===================================================================
--- /branches/neb/archive/scripts/src/phase2/pmFPAWrite.c	(revision 5648)
+++ /branches/neb/archive/scripts/src/phase2/pmFPAWrite.c	(revision 5649)
@@ -7,5 +7,7 @@
 #include "pmFPARead.h"
 
-static bool writeHDU(psFits *fits,  // FITS file to which to write
+static psString p_pmFPAGetExtName(psString name, pmCell *cell, psString filename);
+
+static bool writeHDU(psFits *fits,   // FITS file to which to write
                      p_pmHDU *hdu // Pixel data to write
                     )
@@ -22,6 +24,6 @@
 
 
-bool pmFPAWrite(psFits *fits,   // FITS file to which to write
-                pmFPA *fpa,   // FPA to write
+bool pmFPAWrite(psFits *fits,    // FITS file to which to write
+                pmFPA *fpa,    // FPA to write
                 psDB *db  // Database to update
                )
@@ -78,5 +80,5 @@
 
 
-bool pmFPAWriteMask(pmFPA *fpa,   // FPA containing mask to write
+bool pmFPAWriteMask(pmFPA *fpa,    // FPA containing mask to write
                     psFits *fits // FITS file for image
                    )
@@ -136,20 +138,7 @@
                     {
                         // 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);
-                        }
+                        extname = p_pmFPAGetExtName(name, cell, filename);
 
                         psFree(maskDest);
@@ -161,5 +150,4 @@
                         psFree(filename);
                         psFree(extname);
-                        psFree(filenameExt);
                     }
                     else if (strncasecmp(sourceType, "EXT", 3) == 0)
@@ -203,5 +191,5 @@
 
 
-bool pmFPAWriteWeight(pmFPA *fpa,   // FPA containing mask to write
+bool pmFPAWriteWeight(pmFPA *fpa,    // FPA containing mask to write
                       psFits *fits // FITS file for image
                      )
@@ -261,20 +249,7 @@
                     {
                         // 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);
-                        }
+                        extname = p_pmFPAGetExtName(name, cell, filename);
 
                         psFree(weightDest);
@@ -286,5 +261,4 @@
                         psFree(filename);
                         psFree(extname);
-                        psFree(filenameExt);
                     }
                     else if (strncasecmp(sourceType, "EXT", 3) == 0)
@@ -325,2 +299,26 @@
     return true;
 }
+
+static psString p_pmFPAGetExtName(psString name, pmCell *cell, psString filename)
+{
+    psString filenameExt = p_pmFPATranslateName(name, cell);
+    char *colon = strchr(filenameExt, ':');    // Pointer to a colon in the filename-extn
+    psString extname = NULL;            // The extenstion name
+    filename = NULL;                    // The filename
+    if (colon)
+    {
+        filename = psStringNCopy(filenameExt, strlen(filenameExt) - strlen(colon));
+        if (strlen(colon) > 1)
+        {
+            extname = psStringCopy(colon + 1);
+        }
+    }
+    else
+    {
+        filename = psMemIncrRefCounter(filenameExt);
+    }
+
+    psFree(filenameExt);
+
+    return extname;
+}
