Index: trunk/psModules/test/camera/tap_pmFPAHeader.c
===================================================================
--- trunk/psModules/test/camera/tap_pmFPAHeader.c	(revision 14882)
+++ trunk/psModules/test/camera/tap_pmFPAHeader.c	(revision 15987)
@@ -5,12 +5,7 @@
 #include "tap.h"
 #include "pstap.h"
-// XXX: Use better name for the temporary FITS file
-// XXX: The code to generate and free the FPA hierarchy was copied from
-// tap-pmFPA.c.  EIther include it directly, or library, or something.
-// Also, get rid of the manual free functions and use psFree() once
-// it correctly frees child members
-// XXX: For the genSimpleFPA() code, add IDs to each function so that
-// the values set in each chip-?cell-?hdu-?image are unique
-// XXX: For the genSimpleFPA() code, write masks and weights as well
+/* STATUS:
+    All functions are tested.
+*/
 
 #define CHIP_ALLOC_NAME        "ChipName"
@@ -84,10 +79,14 @@
     cell->hdu = pmHDUAlloc(extname);
     for (int i = 0 ; i < NUM_READOUTS ; i++) {
-        cell->readouts->data[i] = generateSimpleReadout(cell);
-    }
-
-    bool rc = pmConfigFileRead(&cell->hdu->format, "data/camera0/format0.config", "Camera format 0");
+        cell->readouts->data[i] = psMemDecrRefCounter((psPtr) generateSimpleReadout(cell));
+    }
+
+    // First try to read data from ../dataFiles, then try dataFiles.
+    bool rc = pmConfigFileRead(&cell->hdu->format, "../dataFiles/camera0/format0.config", "Camera format 0");
     if (!rc) {
-        diag("pmConfigFileRead() was unsuccessful (from generateSimpleCell())");
+        rc = pmConfigFileRead(&cell->hdu->format, "dataFiles/camera0/format0.config", "Camera format 0");
+        if (!rc) {
+            diag("pmConfigFileRead() was unsuccessful (from generateSimpleCell())");
+	}
     }
 
@@ -104,8 +103,6 @@
     }
 
-    //XXX: Should the region be set some other way?  Like through the various config files?
-//    psRegion *region = psRegionAlloc(0.0, TEST_NUM_COLS-1, 0.0, TEST_NUM_ROWS-1);
     psRegion *region = psRegionAlloc(0.0, 0.0, 0.0, 0.0);
-    // You shouldn't have to remove the key from the metadata.  Find out how to simply change the key value.
+    // You shouldn't have to remove the key from the metadata.
     psMetadataRemoveKey(cell->concepts, "CELL.TRIMSEC");
     psMetadataAddPtr(cell->concepts, PS_LIST_TAIL|PS_META_REPLACE, "CELL.TRIMSEC", PS_DATA_REGION, "I am a region", region);
@@ -134,10 +131,6 @@
     psArrayRealloc(chip->cells, NUM_CELLS);
     for (int i = 0 ; i < NUM_CELLS ; i++) {
-        chip->cells->data[i] = generateSimpleCell(chip, i);
-    }
-
-    // XXX: Add code to initialize chip pmConcepts
-
-
+        chip->cells->data[i] = psMemDecrRefCounter((psPtr) generateSimpleCell(chip, i));
+    }
     return(chip);
 }
@@ -156,51 +149,13 @@
     psMetadataAddS32((psMetadata *) fpa->camera, PS_LIST_HEAD, MISC_NAME, 0, NULL, MISC_NUM);
     psMetadataAddS32(fpa->concepts, PS_LIST_HEAD, MISC_NAME, 0, NULL, MISC_NUM);
-//    fpa->hdu = pmHDUAlloc("fpaExtName");
-//
-//    bool rc = pmConfigFileRead(&fpa->hdu->format, "data/camera0/format0.config", "Camera format 0");
-//    if (!rc) {
-//        diag("pmConfigFileRead() was unsuccessful (from generateSimpleFPA())");
-//    }
 
     psArrayRealloc(fpa->chips, NUM_CHIPS);
     for (int i = 0 ; i < NUM_CHIPS ; i++) {
-        fpa->chips->data[i] = generateSimpleChip(fpa, i);
-    }
-
-    // XXX: Eventually, when you finish the pmConcepts tests, add full concept
-    // reading code from wherever.
+        fpa->chips->data[i] = psMemDecrRefCounter((psPtr) generateSimpleChip(fpa, i));
+    }
     pmConceptsBlankFPA(fpa);
-//    bool mdok;
-//    psMetadata *fileData = psMetadataLookupMetadata(&mdok, fpa->hdu->format, "FILE");
-//    char *fpaNameHdr = psMetadataLookupStr(&mdok, fileData, "FPA.NAME");
-//    psMetadataAddStr(fpa->concepts, PS_LIST_TAIL, "FPA.NAME", PS_META_REPLACE, NULL, fpaNameHdr);
-
     return(fpa);
 }
 
-// XXX: This should only be necessary until the psFree() functions for
-// FPA/chip/cell/readout correctly free all child chips/cells/readouts
-void myFreeCell(pmCell *cell)
-{
-    for (int k = 0 ; k < cell->readouts->n ; k++) {
-        psFree(cell->readouts->data[k]);
-    }
-    psFree(cell);
-}
-
-void myFreeChip(pmChip *chip) {
-    for (int j = 0 ; j < chip->cells->n ; j++) {
-        myFreeCell(chip->cells->data[j]);
-    }
-    psFree(chip);
-}
-
-void myFreeFPA(pmFPA *fpa)
-{
-    for (int i = 0 ; i < fpa->chips->n ; i++) {
-        myFreeChip(fpa->chips->data[i]);
-    }
-    psFree(fpa);
-}
 
 
@@ -210,5 +165,5 @@
     psLogSetLevel(PS_LOG_INFO);
     psTraceSetLevel("err", ERR_TRACE_LEVEL);
-    plan_tests(25);
+    plan_tests(75);
 
 
@@ -225,5 +180,5 @@
         ok(cell != NULL, "Allocated a pmCell successfully");
         ok(!pmCellReadHeader(cell, NULL), "pmCellReadHeader(cell, NULL) returned FALSE");
-        myFreeFPA(fpa);
+        psFree(fpa);
         psFree(camera);
         ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
@@ -245,5 +200,4 @@
     {
         psMemId id = psMemGetId();
-
         // Create a FITS file for this test
         psFits* fitsFileW = psFitsOpen(fitsFilename, "w");
@@ -264,5 +218,8 @@
             psMetadataAdd(hdu->header, PS_LIST_TAIL, "MYSTR", PS_DATA_STRING,
                          "String Item", extname);
-            bool rc = pmConfigFileRead(&hdu->format, "data/camera0/format0.config", "Camera 0 Config Format");
+            bool rc = pmConfigFileRead(&hdu->format, "../dataFiles/camera0/format0.config", "Camera 0 Config Format");
+            if (!rc) {
+                rc = pmConfigFileRead(&hdu->format, "dataFiles/camera0/format0.config", "Camera 0 Config Format");
+	    }
             ok(rc == true, "pmConfigFileRead() was successful");
             rc = pmHDUWrite(hdu, fitsFileW);
@@ -289,5 +246,5 @@
         // elsewhere.  However, if we should test it, test it here.
 
-        myFreeFPA(fpa);
+        psFree(fpa);
         psFree(camera);
         psFree(fitsFileR);
@@ -308,5 +265,5 @@
         ok(cell != NULL, "Allocated a pmCell successfully");
         ok(!pmChipReadHeader(chip, NULL), "pmChipReadHeader(chip, NULL) returned FALSE");
-        myFreeFPA(fpa);
+        psFree(fpa);
         psFree(camera);
         ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
@@ -347,5 +304,8 @@
             psMetadataAdd(hdu->header, PS_LIST_TAIL, "MYSTR", PS_DATA_STRING,
                          "String Item", extname);
-            bool rc = pmConfigFileRead(&hdu->format, "data/camera0/format0.config", "Camera 0 Config Format");
+            bool rc = pmConfigFileRead(&hdu->format, "../dataFiles/camera0/format0.config", "Camera 0 Config Format");
+            if (!rc) {
+               rc = pmConfigFileRead(&hdu->format, "dataFiles/camera0/format0.config", "Camera 0 Config Format");
+	    }
             ok(rc == true, "pmConfigFileRead() was successful");
             rc = pmHDUWrite(hdu, fitsFileW);
@@ -382,5 +342,5 @@
         // elsewhere.  However, if we should test it, test it here.
 
-        myFreeFPA(fpa);
+        psFree(fpa);
         psFree(camera);
         psFree(fitsFileR);
@@ -401,5 +361,5 @@
         ok(cell != NULL, "Allocated a pmCell successfully");
         ok(!pmFPAReadHeader(fpa, NULL), "pmFPAReadHeader(fpa, NULL) returned FALSE");
-        myFreeFPA(fpa);
+        psFree(fpa);
         psFree(camera);
         ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
@@ -440,5 +400,8 @@
             psMetadataAdd(hdu->header, PS_LIST_TAIL, "MYSTR", PS_DATA_STRING,
                          "String Item", extname);
-            bool rc = pmConfigFileRead(&hdu->format, "data/camera0/format0.config", "Camera 0 Config Format");
+            bool rc = pmConfigFileRead(&hdu->format, "../dataFiles/camera0/format0.config", "Camera 0 Config Format");
+            if (!rc) {
+                rc = pmConfigFileRead(&hdu->format, "dataFiles/camera0/format0.config", "Camera 0 Config Format");
+	    }
             ok(rc == true, "pmConfigFileRead() was successful");
             rc = pmHDUWrite(hdu, fitsFileW);
@@ -476,13 +439,9 @@
         // elsewhere.  However, if we should test it, test it here.
 
-        myFreeFPA(fpa);
+        psFree(fpa);
         psFree(camera);
         psFree(fitsFileR);
         ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     }
-
-
-
-
-}
-
+}
+
