Index: trunk/psLib/test/dataIO/tst_psFits.c
===================================================================
--- trunk/psLib/test/dataIO/tst_psFits.c	(revision 2993)
+++ trunk/psLib/test/dataIO/tst_psFits.c	(revision 3025)
@@ -6,6 +6,6 @@
 *  @author Robert DeSonia, MHPCC
 *
-*  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-01-14 19:21:55 $
+*  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-01-17 20:58:22 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -19,5 +19,8 @@
 
 static bool makeMulti(void);  // implicitly tests psFitsSetExtName
+static bool makeTable(void);
 const char* multiFilename = "multi.fits";
+const char* tableFilename = "table.fits";
+const int tableNumRows = 10;
 
 static psS32 tst_psFitsAlloc( void );
@@ -26,4 +29,5 @@
 static psS32 tst_psFitsReadHeader( void );
 static psS32 tst_psFitsReadHeaderSet( void );
+static psS32 tst_psFitsReadTable( void );
 
 testDescription tests[] = {
@@ -35,5 +39,6 @@
                               {tst_psFitsMoveExtNum, 803, "psFitsGetSize", 0, true},
                               {tst_psFitsReadHeader, 804, "psFitsReadHeader", 0, false},
-                              {tst_psFitsReadHeaderSet, 0, "psFitsReadHeaderSet", 0, false},
+                              {tst_psFitsReadHeaderSet,805, "psFitsReadHeaderSet", 0, false},
+                              {tst_psFitsReadTable,809, "psFitsReadTable", 0, false},
                               {NULL}
                           };
@@ -110,4 +115,62 @@
 }
 
+bool makeTable(void)
+{
+
+    if (access(tableFilename, F_OK) != 0) {
+        psFits* fitsFile = psFitsAlloc(tableFilename);
+
+        if (fitsFile == NULL) {
+            psError(PS_ERR_UNKNOWN, false,
+                    "Could not create 'table' FITS file.");
+            return false;
+        }
+
+        // make the PHU an image (per FITS standard, it must be)
+        psImage* image = psImageAlloc(16,16,PS_TYPE_F32);
+
+        if (! psFitsWriteImage(fitsFile,NULL,image,1) ) {
+            psError(PS_ERR_UNKNOWN, false,
+                    "Could not write PHU image.");
+            return false;
+        }
+
+        psFree(image);
+
+        // build a table structure
+        psArray* table = psArrayAlloc(tableNumRows);
+        table->n = 0;
+        for (int row = 0; row < tableNumRows; row++) {
+            psMetadata* header = psMetadataAlloc();
+
+            psMetadataAdd(header,PS_LIST_TAIL, "MYINT",
+                          PS_TYPE_S32, PS_META_PRIMITIVE,
+                          "psS32 Item", (psS32)row);
+
+            psMetadataAdd(header,PS_LIST_TAIL, "MYFLT",
+                          PS_TYPE_F32, PS_META_PRIMITIVE,
+                          "psF32 Item", (float)(1.0f/(float)(1+row)));
+
+            psMetadataAdd(header,PS_LIST_TAIL, "MYDBL",
+                          PS_TYPE_F64, PS_META_PRIMITIVE,
+                          "psF64 Item", (double)(1.0/(double)(1+row)));
+
+            psMetadataAdd(header,PS_LIST_TAIL, "MYBOOL",
+                          PS_TYPE_BOOL, PS_META_PRIMITIVE,
+                          "psBool Item",
+                          (row%2 == 0));
+
+            psArrayAdd(table,0,header);
+        }
+
+        psFitsWriteTable(fitsFile, NULL, table, "table-1");
+
+        psFree(table);
+        psFree(fitsFile);
+    }
+
+    return true;
+}
+
 psS32 tst_psFitsAlloc( void )
 {
@@ -176,4 +239,10 @@
     psFits* fits = psFitsAlloc(multiFilename);
 
+    if (fits == NULL) {
+        psError(PS_ERR_UNKNOWN, false,
+                "psFitsAlloc returned NULL on existing file.");
+        return 1;
+    }
+
     int numHDUs = psFitsGetSize(fits);
 
@@ -290,4 +359,10 @@
 
     psFits* fits = psFitsAlloc(multiFilename);
+
+    if (fits == NULL) {
+        psError(PS_ERR_UNKNOWN, false,
+                "psFitsAlloc returned NULL on existing file.");
+        return 1;
+    }
 
     int numHDUs = psFitsGetSize(fits);
@@ -489,4 +564,10 @@
     psFits* fits = psFitsAlloc(multiFilename);
 
+    if (fits == NULL) {
+        psError(PS_ERR_UNKNOWN, false,
+                "psFitsAlloc returned NULL on existing file.");
+        return 1;
+    }
+
     int numHDUs = psFitsGetSize(fits);
 
@@ -594,4 +675,10 @@
     psFits* fits = psFitsAlloc(multiFilename);
 
+    if (fits == NULL) {
+        psError(PS_ERR_UNKNOWN, false,
+                "psFitsAlloc returned NULL on existing file.");
+        return 1;
+    }
+
     int numHDUs = psFitsGetSize(fits);
 
@@ -701,2 +788,87 @@
     return 0;
 }
+
+static psS32 tst_psFitsReadTable( void )
+{
+
+
+    if (! makeTable() ) {
+        return 1;
+    }
+
+    psFits* fits = psFitsAlloc(tableFilename);
+
+    if (fits == NULL) {
+        psError(PS_ERR_UNKNOWN, false,
+                "psFitsAlloc returned NULL on existing file.");
+        return 1;
+    }
+
+    psFitsMoveExtNum(fits,1,false);
+
+    psArray* table = psFitsReadTable(fits);
+
+    if (table == NULL) {
+        psError(PS_ERR_UNKNOWN, false,
+                "psFitsReadTable returned NULL unexpectedly.");
+        return 2;
+    }
+
+    if (table->n != tableNumRows) {
+        psError(PS_ERR_UNKNOWN, false,
+                "Expected %d rows, but read %d.",
+                tableNumRows, table->n);
+        return 3;
+    }
+
+
+    for (int row = 0; row < table->n; row++) {
+        psMetadata* rowData = table->data[row];
+
+        psS32 intItem = psMetadataLookupS32(rowData, "MYINT",NULL);
+        psF32 fltItem = psMetadataLookupF32(rowData, "MYFLT",NULL);
+        psF64 dblItem = psMetadataLookupF64(rowData, "MYDBL",NULL);
+        psBool boolItem = psMetadataLookupBool(rowData, "MYBOOL",NULL);
+
+        if (intItem != row) {
+            psError(PS_ERR_UNKNOWN, true,
+                    "Failed to retrieve psS32 metadata item from file.  Got %d vs %d",
+                    intItem, row);
+            return 20;
+        }
+
+        if (fabsf(fltItem - 1.0f/(float)(1+row)) > FLT_EPSILON) {
+            psError(PS_ERR_UNKNOWN, true,
+                    "Failed to retrieve psF32 metadata item from file.  Got %f vs %f",
+                    fltItem,1.0f/(float)(1+row));
+            return 21;
+        }
+
+        if (abs(dblItem - 1.0/(double)(1+row)) > DBL_EPSILON) {
+            psError(PS_ERR_UNKNOWN, true,
+                    "Failed to retrieve psF64 metadata item from file.  Got %g vs %g",
+                    dblItem, 1.0/(double)(1+row));
+            return 22;
+        }
+
+        if (boolItem != (row%2 == 0)) {
+            psError(PS_ERR_UNKNOWN, true,
+                    "Failed to retrieve psBool metadata item from file.");
+            return 23;
+        }
+
+    }
+
+    psFree(table);
+    psFree(fits);
+
+    psArray* nullTest = psFitsReadTable(NULL);
+
+    if (nullTest != NULL || psErrorGetStackSize() != 1) {
+        psError(PS_ERR_UNKNOWN, true,
+                "psFitsReadTable returned non-NULL when given NULL.");
+        return 30;
+    }
+
+    return 0;
+}
Index: trunk/psLib/test/dataIO/verified/tst_psFits.stderr
===================================================================
--- trunk/psLib/test/dataIO/verified/tst_psFits.stderr	(revision 2993)
+++ trunk/psLib/test/dataIO/verified/tst_psFits.stderr	(revision 3025)
@@ -91,2 +91,13 @@
 ---> TESTPOINT PASSED (psImage{psFitsReadHeaderSet} | tst_psFits.c)
 
+/***************************** TESTPOINT ******************************************\
+*             TestFile: tst_psFits.c                                               *
+*            TestPoint: psImage{psFitsReadTable}                                   *
+*             TestType: Positive                                                   *
+\**********************************************************************************/
+
+<DATE><TIME>|<HOST>|E|psFitsReadTable (psFits.c:<LINENO>)
+    The input psFits object can not NULL.
+
+---> TESTPOINT PASSED (psImage{psFitsReadTable} | tst_psFits.c)
+
