Index: trunk/psModules/src/camera/pmFPAfileDefine.c
===================================================================
--- trunk/psModules/src/camera/pmFPAfileDefine.c	(revision 17548)
+++ trunk/psModules/src/camera/pmFPAfileDefine.c	(revision 17634)
@@ -87,15 +87,16 @@
     }
 
-    pmFPAfile *file = pmFPAfileAlloc ();
+    pmFPAfile *file = pmFPAfileAlloc();
 
     // save the name of this pmFPAfile
-    file->name = psStringCopy (name);
+    file->name = psStringCopy(name);
 
     file->filerule = psMemIncrRefCounter(psMetadataLookupStr (&status, data, "FILENAME.RULE"));
 
-    type = psMetadataLookupStr (&status, data, "FILE.TYPE");
+    type = psMetadataLookupStr(&status, data, "FILE.TYPE");
     file->type = pmFPAfileTypeFromString(type);
     if (file->type == PM_FPA_FILE_NONE) {
         psError(PS_ERR_IO, true, "FILE.TYPE is not defined for %s\n", name);
+        psFree(file);
         return NULL;
     }
@@ -107,4 +108,5 @@
     if (file->dataLevel == PM_FPA_LEVEL_NONE) {
         psError(PS_ERR_IO, true, "DATA.LEVEL is not set for %s\n", name);
+        psFree(file);
         return NULL;
     }
@@ -125,11 +127,11 @@
     // XXX ppFocus wants to override the selection with the new selection
     // XXX require programs like ppFocus to remove existing files by hand
-    if (!psMetadataAddPtr (config->files, PS_LIST_TAIL, name,
-                           PS_DATA_UNKNOWN | PS_META_DUPLICATE_OK, "", file)) {
-        psError (PS_ERR_IO, false, "could not add %s to config files", name);
-        return NULL;
-    }
-    psFree (file);
-    return (file);
+    if (!psMetadataAddPtr(config->files, PS_LIST_TAIL, name,
+                          PS_DATA_UNKNOWN | PS_META_DUPLICATE_OK, "", file)) {
+        psError(PS_ERR_IO, false, "could not add %s to config files", name);
+        return NULL;
+    }
+    psFree(file);
+    return file;
 }
 
@@ -242,8 +244,8 @@
     if (fitsType && strcasecmp(fitsType, "NONE") != 0) {
 
-	// load the FITSTYPE scheme for this file
-	psMetadata *scheme = pmConfigFitsType(config, camera, fitsType); // File rule
+        // load the FITSTYPE scheme for this file
+        psMetadata *scheme = pmConfigFitsType(config, camera, fitsType); // File rule
         if (!scheme) {
-	    // XXX change to a config error?
+            // XXX change to a config error?
             psWarning("Unable to find %s in FITS in camera configuration --- will use defaults.", fitsType);
             goto FITS_OPTIONS_DONE;
@@ -375,6 +377,6 @@
     // place the resulting file in the config system
     psMetadataAddPtr (config->files, PS_LIST_TAIL, name, PS_DATA_UNKNOWN, "", file);
-    psFree (file); // we free this copy of file, but 'files' still has a copy
-    return (file); // the returned value is a view into the version on 'files'
+    psFree(file);                       // we free this copy of file, but 'files' still has a copy
+    return file;                        // the returned value is a view into the version on 'files'
 }
 
@@ -429,10 +431,14 @@
 
     // use success to identify valid exit conditions (as opposed to 'argument not supplied')
-    if (success) *success = false;
+    if (success) {
+        *success = false;
+    }
 
     // we search the argument data for the named fileset (argname)
     psArray *infiles = psMetadataLookupPtr(&status, config->arguments, argname);
     if (!status) {
-        if (success) *success = true;
+        if (success) {
+            *success = true;
+        }
         return NULL;
     }
@@ -467,5 +473,5 @@
     // determine the current format from the header
     // determine camera if not specified already
-    format = pmConfigCameraFormatFromHeader (config, phu, true);
+    format = pmConfigCameraFormatFromHeader(config, phu, true);
     if (!format) {
         psError(PS_ERR_IO, false, "Failed to read CCD format from %s\n", realName);
@@ -476,5 +482,5 @@
 
     // build the template fpa, set up the basic view
-    fpa = pmFPAConstruct (config->camera);
+    fpa = pmFPAConstruct(config->camera);
     if (!fpa) {
         psError(PS_ERR_IO, false, "Failed to construct FPA from %s", realName);
@@ -486,5 +492,5 @@
     // load the given filerule (from config->camera) and bind it to the fpa
     // the returned file is just a view to the entry on config->files
-    file = pmFPAfileDefineInput (config, fpa, filename);
+    file = pmFPAfileDefineInput(config, fpa, filename);
     if (!file) {
         psError(PS_ERR_IO, false, "file %s not defined\n", filename);
@@ -500,6 +506,6 @@
     // adjust the rules to identify these files in the file->names data
     psFree (file->filerule);
-    file->filerule = psStringCopy ("@FILES");
-    file->filesrc = psStringCopy ("{CHIP.NAME}.{CELL.NAME}");
+    file->filerule = psStringCopy("@FILES");
+    file->filesrc = psStringCopy("{CHIP.NAME}.{CELL.NAME}");
 
     file->fileLevel = pmFPAPHULevel(format);
@@ -509,5 +515,4 @@
         psFree(fpa);
         psFree(format);
-        psFree(file);
         return NULL;
     }
@@ -528,5 +533,5 @@
             if (!fits) {
                 psError(PS_ERR_IO, false, "Failed to open file %s\n", realName);
-                psFree (realName);
+                psFree(realName);
                 return NULL;
             }
@@ -534,23 +539,23 @@
             if (!phu) {
                 psError(PS_ERR_IO, false, "Failed to read file header %s", realName);
-                psFree (realName);
-                psFitsClose (fits);
+                psFree(realName);
+                psFitsClose(fits);
                 return NULL;
             }
             bool valid = false;
             if (!pmConfigValidateCameraFormat (&valid, format, phu)) {
-                psError (PS_ERR_UNKNOWN, false, "Error in config scripts\n");
-                psFree (realName);
-                psFitsClose (fits);
+                psError(PS_ERR_UNKNOWN, false, "Error in config scripts\n");
+                psFree(realName);
+                psFitsClose(fits);
                 return NULL;
             }
             if (!valid) {
                 psError(PS_ERR_IO, false, "file %s is not from the required camera", realName);
-                psFree (realName);
-                psFitsClose (fits);
+                psFree(realName);
+                psFitsClose(fits);
                 return NULL;
             }
             psFree(realName);
-            psFitsClose (fits);
+            psFitsClose(fits);
         }
 
@@ -560,21 +565,23 @@
             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;
         }
 
         // associate the filename with the FPA element
-        char *name = pmFPAfileNameFromRule (file->filesrc, file, view);
+        char *name = pmFPAfileNameFromRule(file->filesrc, file, view);
 
         // save the name association in the pmFPAfile structure
-        psMetadataAddStr (file->names, PS_LIST_TAIL, name, 0, "", infiles->data[i]);
-
-        psFree (view);
-        psFree (name);
-        psFree (phu);
-    }
-    psFree (fpa);
-    if (success) *success = true;
+        psMetadataAddStr(file->names, PS_LIST_TAIL, name, 0, "", infiles->data[i]);
+
+        psFree(view);
+        psFree(name);
+        psFree(phu);
+    }
+    psFree(fpa);
+    if (success) {
+        *success = true;
+    }
 
     return file;
@@ -600,5 +607,7 @@
 
     // use success to identify valid exit conditions (as opposed to 'argument not supplied')
-    if (success) *success = false;
+    if (success) {
+        *success = false;
+    }
 
     // we search the argument data for the named fileset (argname)
@@ -606,5 +615,7 @@
     if (!status) {
         // this is not an error: this just means no matching argument was supplied
-        if (success) *success = true;
+        if (success) {
+            *success = true;
+        }
         return NULL;
     }
@@ -647,5 +658,5 @@
         if (!fits) {
             psError(PS_ERR_IO, false, "Failed to open file %s\n", realName);
-            psFree (realName);
+            psFree(realName);
             return NULL;
         }
@@ -653,6 +664,6 @@
         if (!phu) {
             psError(PS_ERR_IO, false, "Failed to read file header %s", realName);
-            psFree (realName);
-            psFitsClose (fits);
+            psFree(realName);
+            psFitsClose(fits);
             return NULL;
         }
@@ -665,5 +676,4 @@
                 psFree(realName);
                 psFitsClose(fits);
-                psFree(file);
                 return NULL;
             }
@@ -673,5 +683,4 @@
                 psError(PS_ERR_UNKNOWN, false, "Error in config scripts\n");
                 psFree(realName);
-                psFree(file);
                 psFitsClose(fits);
                 return NULL;
@@ -681,5 +690,4 @@
                         realName);
                 psFree(realName);
-                psFree(file);
                 psFitsClose(fits);
                 return NULL;
@@ -704,7 +712,7 @@
         psMetadataAddStr (file->names, PS_LIST_TAIL, name, 0, "", infiles->data[i]);
 
-        psFree (view);
-        psFree (name);
-        psFree (phu);
+        psFree(view);
+        psFree(name);
+        psFree(phu);
     }
     psFree(file->format);
@@ -712,5 +720,7 @@
     file->formatName = psStringCopy(config->formatName);
 
-    if (success) *success = true;
+    if (success) {
+        *success = true;
+    }
     return file;
 }
@@ -736,5 +746,7 @@
     psMetadata *format = NULL;
 
-    if (success) *success = false;
+    if (success) {
+        *success = false;
+    }
 
     // we search the argument data for the named fileset (argname)
@@ -742,9 +754,12 @@
     if (!status) {
         psTrace("psModules.camera", 5, "Failed to find %s in argument list", argname);
-        if (success) *success = true;
+        if (success) {
+            *success = true;
+        }
         return NULL;
     }
     if (infiles->n <= entry) {
-        psError(PS_ERR_IO, false, "only %ld files in %s in argument, entry %d requested\n", infiles->n, argname, entry);
+        psError(PS_ERR_IO, false, "only %ld files in %s in argument, entry %d requested\n",
+                infiles->n, argname, entry);
         return NULL;
     }
@@ -802,5 +817,4 @@
         psFree(phu);
         psFree(fpa);
-        psFree(file);
         psFree(format);
         return NULL;
@@ -813,5 +827,4 @@
         psFree(phu);
         psFree(fpa);
-        psFree(file);
         psFree(format);
         return NULL;
@@ -830,5 +843,7 @@
     psFree(format);
 
-    if (success) *success = true;
+    if (success) {
+        *success = true;
+    }
     return file;
 }
@@ -841,5 +856,7 @@
     PS_ASSERT_STRING_NON_EMPTY(filename, NULL);
 
-    if (success) *success = false;
+    if (success) {
+        *success = false;
+    }
 
     // a camera config is needed (as source of file rule)
@@ -858,5 +875,5 @@
     // load the given filerule (from config->camera) and bind it to the fpa
     // the returned file is just a view to the entry on config->files
-    pmFPAfile *file = pmFPAfileDefineInput (config, fpa, filename);
+    pmFPAfile *file = pmFPAfileDefineInput(config, fpa, filename);
     psFree (fpa);
     if (!file) {
@@ -866,17 +883,18 @@
 
     // image names may not come from file->names
-    if (!strcasecmp (file->filerule, "@FILES")) {
+    if (!strcasecmp(file->filerule, "@FILES")) {
         psError(PS_ERR_IO, true, "supplied filerule uses illegal value @FILES");
         // XXX remove the file from config->files
-        psFree(file);
         return NULL;
     }
 
     // image names may come from the detrend database
-    if (!strcasecmp (file->filerule, "@DETDB")) {
+    if (!strcasecmp(file->filerule, "@DETDB")) {
         psTrace ("pmFPAfile", 5, "requiring use of detrend database source\n");
         // don't free the file here: it is left on config->files
         // to be used optionally by pmFPAfileDefineFromDetDB (or others)
-        if (success) *success = true;
+        if (success) {
+            *success = true;
+        }
         return NULL;
     }
@@ -884,9 +902,11 @@
     // Prepend the global path to the file rule
     // this function is implicitly an INPUT operation: do not create the file
-    psString tmpName = pmConfigConvertFilename (file->filerule, config, false);
+    psString tmpName = pmConfigConvertFilename(file->filerule, config, false);
     psFree (file->filerule);
     file->filerule = tmpName;
 
-    if (success) *success = true;
+    if (success) {
+        *success = true;
+    }
 
     return file;
@@ -911,5 +931,7 @@
     pmFPAfile *file = NULL;
 
-    if (success) *success = false;
+    if (success) {
+        *success = false;
+    }
 
     // a camera config is needed (as source of file rule)
@@ -937,5 +959,5 @@
         if (!file) {
             psError(PS_ERR_IO, false, "file %s not defined\n", filename);
-            psFree (fpa);
+            psFree(fpa);
             return NULL;
         }
@@ -1054,5 +1076,7 @@
     psFree (options);
 
-    if (success) *success = true;
+    if (success) {
+        *success = true;
+    }
     return file;
 }
@@ -1202,5 +1226,4 @@
         if (!pmConceptsCopyFPA(file->fpa, src, true, false)) {
             psError(PS_ERR_UNKNOWN, false, "Unable to copy concepts from source to new FPA");
-            psFree(file);
             return NULL;
         }
@@ -1254,5 +1277,4 @@
         if (!pmConceptsCopyFPA(file->fpa, src, false, false)) {
             psError(PS_ERR_UNKNOWN, false, "Unable to copy concepts from source to new FPA");
-            psFree(file);
             return NULL;
         }
@@ -1294,5 +1316,5 @@
     bool status = false;
 
-    pmFPAfile *file = psMetadataLookupPtr (&status, files, name);
+    pmFPAfile *file = psMetadataLookupPtr(&status, files, name);
     if (!status) {
         psTrace("psModules.camera", 6, "Internal File %s not in file list", name);
@@ -1309,5 +1331,5 @@
 
     psTrace("psModules.camera", 6, "dropping Internal FPA File %s", name);
-    psMetadataRemoveKey (files, name);
+    psMetadataRemoveKey(files, name);
     return true;
 }
Index: trunk/psModules/src/camera/pmFPAfileDefine.h
===================================================================
--- trunk/psModules/src/camera/pmFPAfileDefine.h	(revision 17548)
+++ trunk/psModules/src/camera/pmFPAfileDefine.h	(revision 17634)
@@ -4,6 +4,6 @@
  * @author EAM, IfA
  *
- * @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-12-27 02:08:19 $
+ * @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2008-05-12 21:41:55 $
  * Copyright 2004-2005 Institute for Astronomy, University of Hawaii
  */
@@ -39,4 +39,7 @@
 
 /// Define the FPA file using the provided camera and format names.
+///
+/// Note that the returned pmFPAfile is a view only, so it should not be freed by the caller --- the only
+/// reference count is held by the config->files metadata.
 pmFPAfile *pmFPAfileDefineOutputForFormat(const pmConfig *config, // Configuration
                                           pmFPA *fpa, // Optional FPA to bind
@@ -78,4 +81,7 @@
 
 /// Same as pmFPAfileDefineFromFPA, except it uses an FPA file instead of an FPA
+///
+/// The new pmFPAfile is inserted into the config->files metadata, freed and returned; so that the user does
+/// not have to (and should not!) free the result.
 pmFPAfile *pmFPAfileDefineFromFile(const pmConfig *config, // Configuration
                                    pmFPAfile *src, // Source file for this file
@@ -122,8 +128,11 @@
 // create a file with the given name, assign it type "INTERNAL", and supply it with an image
 // of the requested dimensions. (image only, mask and weight are ignored)
-pmReadout *pmFPAfileDefineInternal (psMetadata *files, const char *name, int Nx, int Ny, int type);
+///
+/// The new pmFPAfile is inserted into the config->files metadata, freed and returned; so that the user does
+/// not have to (and should not!) free the result.
+pmReadout *pmFPAfileDefineInternal(psMetadata *files, const char *name, int Nx, int Ny, int type);
 
 // delete the INTERNAL file of the given name (if it exists)
-bool pmFPAfileDropInternal (psMetadata *files, const char *name);
+bool pmFPAfileDropInternal(psMetadata *files, const char *name);
 
 // look for the given argname on the argument list.  find the give filename from the file rules
@@ -131,6 +140,6 @@
 // Note that the returned pmFPAfile is a view only, so it should not be freed by the caller --- the only
 // reference count is held by the config->files metadata.
-pmFPAfile *pmFPAfileDefineSingleFromArgs (bool *found, pmConfig *config, const char *filename,
-        const char *argname, int entry);
+pmFPAfile *pmFPAfileDefineSingleFromArgs(bool *found, pmConfig *config, const char *filename,
+                                         const char *argname, int entry);
 
 // Select or construct the requested readout.  If the named entry does not exist, generate it based
@@ -139,8 +148,8 @@
 // pmFPAfile is being used internally.
 pmReadout *pmFPAGenerateReadout(const pmConfig *config, // configuration information
-				const pmFPAview *view, // select background for this entry
-				const char *name, // name of internal/external file
-				const pmFPA *fpa, // use this fpa to generate
-				const psImageBinning *binning);
+                                const pmFPAview *view, // select background for this entry
+                                const char *name, // name of internal/external file
+                                const pmFPA *fpa, // use this fpa to generate
+                                const psImageBinning *binning);
 
 /// @}
