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 2965)
@@ -6,6 +6,6 @@
 *  @author Robert DeSonia, MHPCC
 *
-*  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-01-12 22:18:25 $
+*  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-01-13 01:54:26 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -22,8 +22,10 @@
 static psS32 tst_psFitsAlloc( void );
 static psS32 tst_psFitsMoveExtName( void );
+static psS32 tst_psFitsMoveExtNum( void );
 
 testDescription tests[] = {
                               {tst_psFitsAlloc, 801, "psFitsAlloc", 0, false},
                               {tst_psFitsMoveExtName, 802, "psFitsMoveExtName", 0, false},
+                              {tst_psFitsMoveExtNum, 803, "psFitsMoveExtNum", 0, false},
                               {NULL}
                           };
@@ -181,4 +183,162 @@
                 "Operation of NULL extname didn't fail.");
         return 9;
+    }
+
+    psFree(fits);
+
+    return 0;
+}
+
+psS32 tst_psFitsMoveExtNum( 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;
+    }
+
+    psRegion region = {0,0,0,0};
+
+    // test absolute positioning
+    for (int lcv = 0; lcv < numHDUs; lcv++) {
+        // try to move to the extension
+        if (! psFitsMoveExtNum(fits, lcv, false) ) {
+            psError(PS_ERR_UNKNOWN, false,
+                    "Failed to move to extension %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--) {
+        // try to move to the extension
+        if (! psFitsMoveExtNum(fits, lcv, false) ) {
+            psError(PS_ERR_UNKNOWN, false,
+                    "Failed to move to extension %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);
+    }
+
+    // test relative positioning
+    psFitsMoveExtNum(fits,0,false);
+    for (int lcv = 1; lcv < numHDUs; lcv++) {
+        // try to move to the extension
+        if (! psFitsMoveExtNum(fits, 1, true) ) {
+            psError(PS_ERR_UNKNOWN, false,
+                    "Failed to move to extension %d.",
+                    lcv);
+            return 13;
+        }
+
+        // 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 14;
+        }
+        psFree(image);
+    }
+
+    for (int lcv = numHDUs-2; lcv >= 0; lcv--) {
+        // try to move to the extension
+        if (! psFitsMoveExtNum(fits, -1, true) ) {
+            psError(PS_ERR_UNKNOWN, false,
+                    "Failed to move to extension %d.",
+                    lcv);
+            return 15;
+        }
+
+        // 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 16;
+        }
+        psFree(image);
+    }
+
+    // check to see if given a negative extension number, it errors.
+    psLogMsg(__func__,PS_LOG_INFO, "Following should be an error.");
+    if (psFitsMoveExtNum(fits, -1, false) ) {
+        psError(PS_ERR_UNKNOWN, false,
+                "Moving to negative HDU didn't fail.");
+        return 21;
+    }
+
+    // check to see if relative positioning beyond PHU, it errors.
+    psFitsMoveExtNum(fits,0,false);
+    psLogMsg(__func__,PS_LOG_INFO, "Following should be an error.");
+    if (psFitsMoveExtNum(fits, -1, true) ) {
+        psError(PS_ERR_UNKNOWN, false,
+                "Moving to negative HDU didn't fail.");
+        return 22;
+    }
+
+
+    // check to see if given a extension greater than the total #HDUs, it errors.
+    psLogMsg(__func__,PS_LOG_INFO, "Following should be an error.");
+    if (psFitsMoveExtNum(fits, numHDUs, false) ) {
+        psError(PS_ERR_UNKNOWN, false,
+                "Moving to a HDU beyond the file's contents didn't fail.");
+        return 31;
+    }
+
+    // check to see if relative positioning beyond PHU, it errors.
+    psFitsMoveExtNum(fits,numHDUs-1,false);
+    psLogMsg(__func__,PS_LOG_INFO, "Following should be an error.");
+    if (psFitsMoveExtNum(fits, 1, true) ) {
+        psError(PS_ERR_UNKNOWN, false,
+                "Moving to negative HDU didn't fail.");
+        return 32;
+    }
+
+    // check to see if given a NULL psFits, it errors.
+    psLogMsg(__func__,PS_LOG_INFO, "Following should be an error.");
+    if (psFitsMoveExtNum(NULL, 0, false) ) {
+        psError(PS_ERR_UNKNOWN, false,
+                "Operation of NULL psFits didn't fail.");
+        return 40;
     }
 
