Index: /trunk/psLib/test/dataIO/tst_psFits.c
===================================================================
--- /trunk/psLib/test/dataIO/tst_psFits.c	(revision 2963)
+++ /trunk/psLib/test/dataIO/tst_psFits.c	(revision 2963)
@@ -0,0 +1,227 @@
+/** @file  tst_psFits.c
+*
+*  @brief Contains the tests for psFits.[ch]
+*
+*
+*  @author Robert DeSonia, MHPCC
+*
+*  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-01-12 22:18:25 $
+*
+*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
+*/
+
+#include "psTest.h"
+#include "pslib.h"
+
+#include <unistd.h>
+
+static bool makeMulti(void);
+const char* multiFilename = "multi.fits";
+
+static psS32 tst_psFitsAlloc( void );
+static psS32 tst_psFitsMoveExtName( void );
+
+testDescription tests[] = {
+                              {tst_psFitsAlloc, 801, "psFitsAlloc", 0, false},
+                              {tst_psFitsMoveExtName, 802, "psFitsMoveExtName", 0, false},
+                              {NULL}
+                          };
+
+psS32 main( psS32 argc, char* argv[] )
+{
+    psLogSetLevel( PS_LOG_INFO );
+
+    return ( ! runTestSuite( stderr, "psImage", tests, argc, argv ) );
+}
+
+psS32 tst_psFitsAlloc( void )
+{
+
+    if (! makeMulti() ) {
+        return 1;
+    }
+
+    psFits* fitsFile = psFitsAlloc(multiFilename);
+
+    if (fitsFile == NULL) {
+        psError(PS_ERR_UNKNOWN, false,
+                "psFitsAlloc returned NULL on existing file.");
+        return 1;
+    }
+
+    int extNum = psFitsGetExtNum(fitsFile);
+    if (extNum != 0) {
+        psError(PS_ERR_UNKNOWN, false,
+                "psFitsAlloc was not queued to the PHU, but to extension #%d.",
+                extNum);
+        return 2;
+    }
+
+    psFree(fitsFile);
+
+    // make sure the file doesn't already exist.
+    if (access("new.fits", F_OK) == 0) {
+        if (remove
+                ("new.fits") != 0) {
+            psError(PS_ERR_UNKNOWN, false,
+                    "Couldn't delete the new.fits file.");
+            return 3;
+        }
+    }
+
+    fitsFile = psFitsAlloc("new.fits");
+
+    if (fitsFile == NULL) {
+        psError(PS_ERR_UNKNOWN, false,
+                "psFitsAlloc returned NULL on existing file.");
+        return 4;
+    }
+
+    psFree(fitsFile);
+
+    // now, if psFitsAlloc actually created the file, I shouldn't error in removing it.
+    if (remove
+            ("new.fits") != 0) {
+        psError(PS_ERR_UNKNOWN, false,
+                "psFitsAlloc seemed to not have created a new file.");
+        return 5;
+    }
+
+
+    return 0;
+}
+
+psS32 tst_psFitsMoveExtName( void )
+{
+
+    if (! makeMulti() ) {
+        return 1;
+    }
+
+    psFits* fits = psFitsAlloc(multiFilename);
+
+    int numHDUs = psFitsGetSize(fits);
+
+    if (numHDUs < 2) {
+        psError(PS_ERR_UNKNOWN,true,
+                "The 'multi' FITS file does not have multiple HDUs.");
+        return 2;
+    }
+
+    char extName[80];
+    psRegion region = {0,0,0,0};
+
+    for (int lcv = 0; lcv < numHDUs; lcv++) {
+        snprintf(extName,80,"ext-%d",lcv);
+        // try to move to the named extension.
+        if (! psFitsMoveExtName(fits, extName) ) {
+            psError(PS_ERR_UNKNOWN, false,
+                    "Failed to move to ext-%d.",
+                    lcv);
+            return 3;
+        }
+
+        // check that the image is associated to the extension moved, i.e.,
+        // did we really move to the proper extension?
+        psImage* image = psFitsReadImage(NULL, fits,region,0);
+
+        if (image == NULL || abs(image->data.F32[0][0] - (float)lcv) > FLT_EPSILON) {
+            psError(PS_ERR_UNKNOWN, true,
+                    "The image pixel 0,0 of ext-%d was %g, expected %d.",
+                    lcv,image->data.F32[0][0],lcv);
+            return 4;
+        }
+        psFree(image);
+    }
+
+    for (int lcv = numHDUs-1; lcv >= 0; lcv--) {
+        snprintf(extName,80,"ext-%d",lcv);
+        // try to move to the named extension.
+        if (! psFitsMoveExtName(fits, extName) ) {
+            psError(PS_ERR_UNKNOWN, false,
+                    "Failed to move to ext-%d.",
+                    lcv);
+            return 5;
+        }
+
+        // check that the image is associated to the extension moved, i.e.,
+        // did we really move to the proper extension?
+        psImage* image = psFitsReadImage(NULL, fits,region,0);
+
+        if (abs(image->data.F32[0][0] - (float)lcv) > FLT_EPSILON) {
+            psError(PS_ERR_UNKNOWN, true,
+                    "The image pixel 0,0 of ext-%d was %g, expected %d.",
+                    lcv,image->data.F32[0][0],lcv);
+            return 6;
+        }
+        psFree(image);
+    }
+
+    // check to see if given a bogus extension name, it errors.
+    psLogMsg(__func__,PS_LOG_INFO, "Following should be an error.");
+    if (psFitsMoveExtName(fits, "bogus") ) {
+        psError(PS_ERR_UNKNOWN, false,
+                "Moving to non-existant HDU didn't fail.");
+        return 7;
+    }
+
+    // check to see if given a NULL psFits, it errors.
+    psLogMsg(__func__,PS_LOG_INFO, "Following should be an error.");
+    if (psFitsMoveExtName(NULL, "bogus") ) {
+        psError(PS_ERR_UNKNOWN, false,
+                "Operation of NULL psFits didn't fail.");
+        return 8;
+    }
+
+    // check to see if given a NULL extname, it errors.
+    psLogMsg(__func__,PS_LOG_INFO, "Following should be an error.");
+    if (psFitsMoveExtName(fits, NULL) ) {
+        psError(PS_ERR_UNKNOWN, false,
+                "Operation of NULL extname didn't fail.");
+        return 9;
+    }
+
+    psFree(fits);
+
+    return 0;
+}
+
+
+bool makeMulti(void)
+{
+
+    if (access(multiFilename, F_OK) != 0) {
+        psFits* fitsFile = psFitsAlloc(multiFilename);
+
+        if (fitsFile == NULL) {
+            psError(PS_ERR_UNKNOWN, false,
+                    "Could not create 'multi' FITS file.");
+            return false;
+        }
+
+        psImage* image = psImageAlloc(16,16,PS_TYPE_F32);
+
+        char extname[80];
+        for (int lcv = 0; lcv < 8; lcv++) {
+            // set the pixels in the image
+            psBinaryOp(image,image,"=",psScalarAlloc(lcv,PS_TYPE_F32));
+            if (! psFitsWriteImage(fitsFile,NULL,image,1) ) {
+                psError(PS_ERR_UNKNOWN, false,
+                        "Could not write image.");
+                return false;
+            }
+            snprintf(extname,80,"ext-%d", lcv);
+            if (! psFitsSetExtName(fitsFile,extname) ) {
+                psError(PS_ERR_UNKNOWN, false,
+                        "Could not write extension name.");
+                return false;
+            }
+        }
+        psFree(image);
+        psFree(fitsFile);
+    }
+
+    return true;
+}
+
Index: /trunk/psLib/test/fileUtils/tst_psFits.c
===================================================================
--- /trunk/psLib/test/fileUtils/tst_psFits.c	(revision 2963)
+++ /trunk/psLib/test/fileUtils/tst_psFits.c	(revision 2963)
@@ -0,0 +1,227 @@
+/** @file  tst_psFits.c
+*
+*  @brief Contains the tests for psFits.[ch]
+*
+*
+*  @author Robert DeSonia, MHPCC
+*
+*  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-01-12 22:18:25 $
+*
+*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
+*/
+
+#include "psTest.h"
+#include "pslib.h"
+
+#include <unistd.h>
+
+static bool makeMulti(void);
+const char* multiFilename = "multi.fits";
+
+static psS32 tst_psFitsAlloc( void );
+static psS32 tst_psFitsMoveExtName( void );
+
+testDescription tests[] = {
+                              {tst_psFitsAlloc, 801, "psFitsAlloc", 0, false},
+                              {tst_psFitsMoveExtName, 802, "psFitsMoveExtName", 0, false},
+                              {NULL}
+                          };
+
+psS32 main( psS32 argc, char* argv[] )
+{
+    psLogSetLevel( PS_LOG_INFO );
+
+    return ( ! runTestSuite( stderr, "psImage", tests, argc, argv ) );
+}
+
+psS32 tst_psFitsAlloc( void )
+{
+
+    if (! makeMulti() ) {
+        return 1;
+    }
+
+    psFits* fitsFile = psFitsAlloc(multiFilename);
+
+    if (fitsFile == NULL) {
+        psError(PS_ERR_UNKNOWN, false,
+                "psFitsAlloc returned NULL on existing file.");
+        return 1;
+    }
+
+    int extNum = psFitsGetExtNum(fitsFile);
+    if (extNum != 0) {
+        psError(PS_ERR_UNKNOWN, false,
+                "psFitsAlloc was not queued to the PHU, but to extension #%d.",
+                extNum);
+        return 2;
+    }
+
+    psFree(fitsFile);
+
+    // make sure the file doesn't already exist.
+    if (access("new.fits", F_OK) == 0) {
+        if (remove
+                ("new.fits") != 0) {
+            psError(PS_ERR_UNKNOWN, false,
+                    "Couldn't delete the new.fits file.");
+            return 3;
+        }
+    }
+
+    fitsFile = psFitsAlloc("new.fits");
+
+    if (fitsFile == NULL) {
+        psError(PS_ERR_UNKNOWN, false,
+                "psFitsAlloc returned NULL on existing file.");
+        return 4;
+    }
+
+    psFree(fitsFile);
+
+    // now, if psFitsAlloc actually created the file, I shouldn't error in removing it.
+    if (remove
+            ("new.fits") != 0) {
+        psError(PS_ERR_UNKNOWN, false,
+                "psFitsAlloc seemed to not have created a new file.");
+        return 5;
+    }
+
+
+    return 0;
+}
+
+psS32 tst_psFitsMoveExtName( void )
+{
+
+    if (! makeMulti() ) {
+        return 1;
+    }
+
+    psFits* fits = psFitsAlloc(multiFilename);
+
+    int numHDUs = psFitsGetSize(fits);
+
+    if (numHDUs < 2) {
+        psError(PS_ERR_UNKNOWN,true,
+                "The 'multi' FITS file does not have multiple HDUs.");
+        return 2;
+    }
+
+    char extName[80];
+    psRegion region = {0,0,0,0};
+
+    for (int lcv = 0; lcv < numHDUs; lcv++) {
+        snprintf(extName,80,"ext-%d",lcv);
+        // try to move to the named extension.
+        if (! psFitsMoveExtName(fits, extName) ) {
+            psError(PS_ERR_UNKNOWN, false,
+                    "Failed to move to ext-%d.",
+                    lcv);
+            return 3;
+        }
+
+        // check that the image is associated to the extension moved, i.e.,
+        // did we really move to the proper extension?
+        psImage* image = psFitsReadImage(NULL, fits,region,0);
+
+        if (image == NULL || abs(image->data.F32[0][0] - (float)lcv) > FLT_EPSILON) {
+            psError(PS_ERR_UNKNOWN, true,
+                    "The image pixel 0,0 of ext-%d was %g, expected %d.",
+                    lcv,image->data.F32[0][0],lcv);
+            return 4;
+        }
+        psFree(image);
+    }
+
+    for (int lcv = numHDUs-1; lcv >= 0; lcv--) {
+        snprintf(extName,80,"ext-%d",lcv);
+        // try to move to the named extension.
+        if (! psFitsMoveExtName(fits, extName) ) {
+            psError(PS_ERR_UNKNOWN, false,
+                    "Failed to move to ext-%d.",
+                    lcv);
+            return 5;
+        }
+
+        // check that the image is associated to the extension moved, i.e.,
+        // did we really move to the proper extension?
+        psImage* image = psFitsReadImage(NULL, fits,region,0);
+
+        if (abs(image->data.F32[0][0] - (float)lcv) > FLT_EPSILON) {
+            psError(PS_ERR_UNKNOWN, true,
+                    "The image pixel 0,0 of ext-%d was %g, expected %d.",
+                    lcv,image->data.F32[0][0],lcv);
+            return 6;
+        }
+        psFree(image);
+    }
+
+    // check to see if given a bogus extension name, it errors.
+    psLogMsg(__func__,PS_LOG_INFO, "Following should be an error.");
+    if (psFitsMoveExtName(fits, "bogus") ) {
+        psError(PS_ERR_UNKNOWN, false,
+                "Moving to non-existant HDU didn't fail.");
+        return 7;
+    }
+
+    // check to see if given a NULL psFits, it errors.
+    psLogMsg(__func__,PS_LOG_INFO, "Following should be an error.");
+    if (psFitsMoveExtName(NULL, "bogus") ) {
+        psError(PS_ERR_UNKNOWN, false,
+                "Operation of NULL psFits didn't fail.");
+        return 8;
+    }
+
+    // check to see if given a NULL extname, it errors.
+    psLogMsg(__func__,PS_LOG_INFO, "Following should be an error.");
+    if (psFitsMoveExtName(fits, NULL) ) {
+        psError(PS_ERR_UNKNOWN, false,
+                "Operation of NULL extname didn't fail.");
+        return 9;
+    }
+
+    psFree(fits);
+
+    return 0;
+}
+
+
+bool makeMulti(void)
+{
+
+    if (access(multiFilename, F_OK) != 0) {
+        psFits* fitsFile = psFitsAlloc(multiFilename);
+
+        if (fitsFile == NULL) {
+            psError(PS_ERR_UNKNOWN, false,
+                    "Could not create 'multi' FITS file.");
+            return false;
+        }
+
+        psImage* image = psImageAlloc(16,16,PS_TYPE_F32);
+
+        char extname[80];
+        for (int lcv = 0; lcv < 8; lcv++) {
+            // set the pixels in the image
+            psBinaryOp(image,image,"=",psScalarAlloc(lcv,PS_TYPE_F32));
+            if (! psFitsWriteImage(fitsFile,NULL,image,1) ) {
+                psError(PS_ERR_UNKNOWN, false,
+                        "Could not write image.");
+                return false;
+            }
+            snprintf(extname,80,"ext-%d", lcv);
+            if (! psFitsSetExtName(fitsFile,extname) ) {
+                psError(PS_ERR_UNKNOWN, false,
+                        "Could not write extension name.");
+                return false;
+            }
+        }
+        psFree(image);
+        psFree(fitsFile);
+    }
+
+    return true;
+}
+
