Index: /trunk/psLib/test/mathtypes/tap_psImage.c
===================================================================
--- /trunk/psLib/test/mathtypes/tap_psImage.c	(revision 10808)
+++ /trunk/psLib/test/mathtypes/tap_psImage.c	(revision 10808)
@@ -0,0 +1,574 @@
+/** @file  tst_psImage.c
+ *
+ *  @brief Contains the tests for psImage.[ch]
+ *
+ *
+ *  @author Robert DeSonia, MHPCC
+ *
+ *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-12-18 19:10:56 $
+ *
+ *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
+ */
+
+#include <math.h>
+#include <float.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "pslib.h"
+#include "psType.h"
+
+#include "tap.h"
+#include "pstap.h"
+
+
+static int Okay = 1;
+
+static int setOkay( int okay )
+{
+    Okay = okay;
+    return okay;
+}
+
+#define OK(exp) \
+exp ? setOkay(1) : setOkay(0)
+
+#define RET_OK          \
+if ( ! Okay ) {     \
+    psFree(image);  \
+    return;         \
+}
+
+
+
+int main(int argc, char* argv[])
+{
+    plan_tests(1449971);
+
+    void testImageAlloc(void);
+    testImageAlloc();
+
+    void testRegion(void);
+    testRegion();
+
+    void testRegion2(void);
+    testRegion2();
+
+    void testRegion3(void);
+    testRegion3();
+
+    void testImageInit(void);
+    testImageInit();
+
+    void testImageSet(void);
+    testImageSet();
+}
+
+
+void testImageAlloc()
+{
+    diag("testImageAlloc");
+
+    psImage* image = NULL;
+    psU32 sizes = 6;
+    psU32 numCols[] = {
+                          0,1,1,100,100,150
+                      };
+    psU32 numRows[] = {
+                          0,1,100,1,150,100
+                      };
+    psU32 types = 12;
+    psElemType type[] = { PS_TYPE_S8, PS_TYPE_S16, PS_TYPE_S32, PS_TYPE_S64,
+                          PS_TYPE_U8, PS_TYPE_U16, PS_TYPE_U32, PS_TYPE_U64,
+                          PS_TYPE_F32, PS_TYPE_F64, PS_TYPE_C32, PS_TYPE_C64};
+
+    for (psU32 t=0;t<types;t++) {
+
+        for (psU32 i=0;i<sizes;i++) {
+
+            // Following should be an error if numRows[i] == 0 || numCols[i]==0
+
+            image = psImageAlloc(numCols[i],numRows[i],type[t]);
+
+            if (image == NULL) {
+                if (numRows[i] == 0 || numCols[i] == 0) {
+                    continue;
+                }
+                ok(0, "psImageAlloc returned NULL for type %x, size %dx%d.",
+                   type[t], numCols[i], numRows[i]);
+                psFree(image);
+                return;
+            }
+
+            ok (image->type.dimen==PS_DIMEN_IMAGE && image->type.type==type[t],
+                "psImageAlloc allocated dimen/type (%d/%d), expecting "
+                "PS_IMAGE_DIMEN/%d", image->type.dimen,
+                image->type.type, type[t]);
+            skip_start (!(image->type.dimen==PS_DIMEN_IMAGE && image->type.type==type[t]),
+                        4, "psImageAlloc allocated wrong dimen/type");
+
+            ok (image->numCols == numCols[i] && image->numRows == numRows[i],
+                "psImageAlloc allocated size %dx%d, expecting be %dx%d "
+                "(type = %d)", image->numCols, image->numRows, numCols[i],
+                numRows[i],type[t]);
+            skip_start (!(image->numCols == numCols[i] && image->numRows == numRows[i]),
+                        3, "psImageAlloc allocated wrong size");
+
+            ok (image->col0 == 0 && image->row0 == 0,
+                "psImageAlloc returned row0/col0 of %d/%d.  Expected 0/0.",
+                image->row0, image->row0);
+            skip_start (!(image->col0 == 0 && image->row0 == 0),
+                        2, "psImageAlloc returned wrong row0/col0");
+
+            ok (image->parent == NULL, "psImageAlloc returned NULL parent");
+            skip_start (image->parent != NULL,
+                        1, "psImageAlloc returned NULL parent");
+
+            ok (image->children == NULL,
+                "psImageAlloc returned NULL children array");
+
+            skip_end();
+            skip_end();
+            skip_end();
+            skip_end();
+
+            if (image->children != NULL) {
+                psFree(image);
+                return;
+            }
+
+            switch (type[t]) {
+            case PS_TYPE_U16: {
+                    psU32 rows = numRows[i];
+                    psU32 cols = numCols[i];
+
+                    for (psS32 r=0;r<rows;r++) {
+                        for (psS32 c=0;c<cols;c++) {
+                            image->data.U16[r][c] = 2*c+r;
+                        }
+                    }
+                    for (psS32 r=0;r<rows;r++) {
+                        for (psS32 c=0;c<cols;c++) {
+                            ok (OK(image->data.U16[r][c] == 2*c+r),
+                                "Could not set all pixels in uint16 image at "
+                                "(%d,%d)",c,r);
+                            RET_OK
+                        }
+                    }
+                }
+                break;
+            case PS_TYPE_F32: {
+                    psU32 rows = numRows[i];
+                    psU32 cols = numCols[i];
+
+                    for (psS32 r=0;r<rows;r++) {
+                        for (psS32 c=0;c<cols;c++) {
+                            image->data.F32[r][c] = 2.0f*c+r;
+                        }
+                    }
+                    for (psS32 r=0;r<rows;r++) {
+                        for (psS32 c=0;c<cols;c++) {
+                            ok (OK(!(fabsf(image->data.F32[r][c] - (2.0f*c+r)) > FLT_EPSILON)),
+                                "Set all pixels in float image at (%d,%d)",c,r);
+                            RET_OK
+                        }
+                    }
+                }
+                break;
+            case PS_TYPE_F64: {
+                    psU32 rows = numRows[i];
+                    psU32 cols = numCols[i];
+
+                    for (psS32 r=0;r<rows;r++) {
+                        for (psS32 c=0;c<cols;c++) {
+                            image->data.F64[r][c] = 2.0f*c+r;
+                        }
+                    }
+                    for (psS32 r=0;r<rows;r++) {
+                        for (psS32 c=0;c<cols;c++) {
+                            ok (OK(!(fabs(image->data.F64[r][c] - (2.0f*c+r)) > DBL_EPSILON)),
+                                "Set all pixels in double image at (%d,%d)",c,r);
+                            RET_OK
+                        }
+                    }
+                }
+                break;
+            case PS_TYPE_C32: {
+                    psU32 rows = numRows[i];
+                    psU32 cols = numCols[i];
+
+                    for (psS32 r=0;r<rows;r++) {
+                        for (psS32 c=0;c<cols;c++) {
+                            image->data.C32[r][c] = r + I * c;
+                        }
+                    }
+                    for (psS32 r=0;r<rows;r++) {
+                        for (psS32 c=0;c<cols;c++) {
+                            ok (OK(!(fabsf(crealf(image->data.C32[r][c]) - r) > FLT_EPSILON ||
+                                     fabsf(cimagf(image->data.C32[r][c]) - c) > FLT_EPSILON )),
+                                "Set all pixels in complex image at (%d,%d)",c,r);
+                            RET_OK
+                        }
+                    }
+                }
+                break;
+            default: {
+                    // ignore type and just use as byte bucket.
+                    psU32 rows = numRows[i];
+                    psU32 cols = numCols[i]*PSELEMTYPE_SIZEOF(type[t]);
+
+                    for (psS32 r=0;r<rows;r++) {
+                        for (psS32 c=0;c<cols;c++) {
+                            image->data.U8[r][c] = (uint8_t)(r + c);
+                        }
+                    }
+                    for (psS32 r=0;r<rows;r++) {
+                        for (psS32 c=0;c<cols;c++) {
+                            ok (OK(!(image->data.U8[r][c] != (uint8_t)(r + c))),
+                                "Set all pixels in image (type=%d) at (%d,%d)",
+                                type[t],c,r);
+                            RET_OK
+                        }
+                    }
+                }
+            }
+            psFree(image);
+        }
+    }
+
+    // #548: Verify no memory leaks or corruption are detected after a valid psImage structure with multiple
+    // children is freed.
+    image = psImageAlloc(100,100,PS_TYPE_F32);
+    psImageSubset(image,(psRegion) {
+                      50,0,70,20
+                  }
+                 );
+    psImageSubset(image,(psRegion) {
+                      70,20,90,40
+                  }
+                 );
+
+    psFree(image);
+}
+
+
+
+void testRegion()
+{
+    // Testpoint #790
+
+    diag("testRegion");
+
+    psRegion region = psRegionSet(1,2,3,4);
+    ok (!(region.x0 != 1 || region.x1 != 2 || region.y0 != 3 || region.y1 != 4),
+        "The region attributes are set to (%s)", psRegionToString(region));
+
+    // Testpoint #791
+
+    region = psRegionFromString("[1:2,3:4]");
+    ok (!(region.x0 != 0 || region.x1 != 2 || region.y0 != 2 || region.y1 != 4),
+        "The region attributes are set to (%s)", psRegionToString(region));
+
+    region = psRegionFromString("[1:2,3:]");
+    ok (isnan(region.x0),
+        "psRegionFromString returned a NULL pointer given a malformed string.");
+}
+
+
+//psRegionForImage//
+void testRegion2()
+{
+    diag("testRegion2");
+
+    psImage *in;
+    psRegion inReg;
+    psRegion out;
+    in = psImageAlloc(1, 1, PS_TYPE_S32);
+    inReg = psRegionSet(1, 2, 1, 2);
+    out = psRegionForImage(in,inReg);
+    psRegion inReg2;
+    psRegion out2;
+    inReg2 = psRegionSet(-1, 0, -2, -1);
+    out2 = psRegionForImage(in, inReg2);
+
+    ok(!( out.x0 != 1 || out.x1 != 1 || out.y0 != 1 || out.y1 != 1 ),
+       "Region For Image returned correct values.\n");
+
+    ok(!( out2.x0 != 0 || out2.x1 != 1 || out2.y0 != 0 || out2.y1 != 0 ),
+       "Region For Image returned correct values.\n");
+
+    psFree(in);
+}
+
+
+//psRegionForSquare//
+void testRegion3()
+{
+    diag("testRegion3");
+
+    float X = 1;
+    float Y = 1;
+    float RAD = 1;
+    psRegion out;
+    out = psRegionForSquare(X, Y, RAD);
+    ok (!(out.x0 != 0 || out.x1 != 3 || out.y0 != 0 || out.y1!= 3),
+        "Region For Square returned correct values.\n");
+}
+
+
+//Initialize an image with a given value.//
+void testImageInit()
+{
+    diag("testImageInit");
+
+    psImage *in1 = NULL;
+    psImage *in2 = NULL;
+    psImage *in3 = NULL;
+    psImage *in4 = NULL;
+    int nRow = 1;
+    int nCol = 1;
+    in1 = psImageAlloc(nRow, nCol, PS_TYPE_U8);
+    ok ( psImageInit(in1, -1 ),
+         "ImageAlloc.  U8 Case - 1x1\n");
+
+    nRow = 5;
+    in2 = psImageAlloc(nRow, nCol, PS_TYPE_F32);
+    ok ( psImageInit(in2, 3),
+         "ImageAlloc.  F32 Case - 5x1\n");
+
+    nCol = 5;
+    in3 = psImageAlloc(nRow, nCol, PS_TYPE_F64);
+    ok ( psImageInit(in3, 3.141),
+         "ImageAlloc.  F64 Case - 5x5\n");
+
+    in4 = psImageAlloc(nRow, nCol, PS_TYPE_S32);
+    ok ( psImageInit(in4, 3),
+         "ImageAlloc.  S32 Case - 5x5\n");
+
+    psFree(in1);
+    psFree(in2);
+    psFree(in3);
+    psFree(in4);
+}
+
+
+void testImageSet()
+{
+    diag("testImageSet");
+
+    psImage *image = NULL;
+    image = psImageAlloc(5, 4, PS_TYPE_S32);
+
+    //Set the position of the subimage relative to the parent.
+    image->col0 = 10;
+    image->row0 = 10;
+    for (int i = 0; i < 4; i++) {
+        for (int j = 0; j < 5; j++) {
+            image->data.S32[i][j] = i+j;
+        }
+    }
+
+    //Attempt to set a position in a NULL psImage*
+    psImage *none = NULL;
+    ok (! psImageSet(none, 1, 1, 1),
+        "psImageSet returned non-null.\n");
+    skip_start ( psImageSet(none, 1, 1, 1),
+                 12, "psImageSet failed");
+
+    //Attempt to set a position in a psImage* with negative numCols, numRows
+    none = psImageAlloc(2, 2, PS_TYPE_S32);
+    *(int*)&none->numCols = -1;
+    ok (! psImageSet(none, 1, 1, 1),
+        "psImageSet return false when passed an image with negative numCols");
+    skip_start ( psImageSet(none, 1, 1, 1),
+                 11,"psImageSet return true when passed an image with negative numCols");
+
+    *(int*)&none->numCols = 2;
+    *(int*)&none->numRows = -1;
+    ok ( !psImageSet(none, 1, 1, 1),
+         "psImageSet failed to return false when passed an image with negative numRows.\n");
+    skip_start ( psImageSet(none, 1, 1, 1),
+                 10,"psImageSet return true when passed an image with negative numRows.");
+
+    //Attempt to set a position in a psImage* with negative col0, row0
+    *(int*)&none->numRows = 2;
+    none->row0 = -1;
+    ok ( !psImageSet(none, 1, 1, 1),
+         "psImageSet failed to return false when passed an image with negative col0.\n");
+    skip_start ( psImageSet(none, 1, 1, 1),
+                 9,"psImageSet return true when passed an image with negative col0.\n");
+
+    none->row0 = 0;
+    none->col0 = -1;
+    ok ( !psImageSet(none, 1, 1, 1),
+         "psImageSet failed to return false when passed an image with negative col0.\n");
+    skip_start ( psImageSet(none, 1, 1, 1),
+                 8,"psImageSet return true when passed an image with negative col0.\n");
+
+    psFree(none);
+
+    //Try to set a position inside of the subimage.
+    ok ( psImageSet(image, 14, 12, 666),
+         "psImageSet failed to return true when passed valid parameters.\n");
+    skip_start ( !psImageSet(image, 14, 12, 666),
+                 7,"psImageSet failed to return true when passed valid parameters.\n");
+
+    ok (image->data.S32[2][4] == 666,
+        "psImageSet set the data value. value=%d\n", image->data.S32[2][4]);
+    skip_start (image->data.S32[2][4] != 666,
+                6,"psImageSet set the data value. value=%d\n", image->data.S32[2][4]);
+
+    //Try to set a position inside of the subimage from the tail.
+    ok ( psImageSet(image, -1, -1, 666),
+         "psImageSet return true when passed valid parameters.\n");
+    skip_start ( !psImageSet(image, -1, -1, 666),
+                 5,"psImageSet failed to return true when passed valid parameters.\n");
+
+    ok (image->data.S32[3][4] == 666,
+        "psImageSet set (from the tail) the data values correctly.\n");
+    skip_start (image->data.S32[3][4] != 666,
+                4,"psImageSet set (from the tail) the data values incorrectly.\n");
+
+
+    //Try to set a position outside of the subimage but inside of the parent image.
+    ok ( !psImageSet(image, 0, 0, 666),
+         "psImageSet return false when passed an invalid location.\n");
+    skip_start ( psImageSet(image, 0, 0, 666),
+                 3,"psImageSet failed to return false when passed an invalid location");
+
+    ok ( !psImageSet(image, 9, 10, 666),
+         "psImageSet return false when passed an invalid location.\n");
+    skip_start ( psImageSet(image, 9, 10, 666),
+                 2,"psImageSet return false when passed an invalid location.\n");
+
+    //Try to set a position outside of the subimage.
+    ok ( !psImageSet(image, 15, 14, 666),
+         "psImageSet return false when passed an invalid location.\n");
+    skip_start ( psImageSet(image, 15, 14, 666),
+                 1,"psImageSet failed to return false when passed an invalid location");
+
+    //Try to set a position outside of the subimage, indexing from the tail.
+    ok ( !psImageSet(image, -6, -1, 666),
+         "psImageSet return false when passed an invalid location.\n");
+
+    skip_end();
+    skip_end();
+    skip_end();
+    skip_end();
+    skip_end();
+    skip_end();
+    skip_end();
+    skip_end();
+    skip_end();
+    skip_end();
+    skip_end();
+    skip_end();
+
+    psFree(image);
+}
+
+
+void testImageGet()
+{
+    diag("testImageGet");
+
+    psImage *image = NULL;
+    image = psImageAlloc(5, 3, PS_TYPE_S32);
+
+    //Set the position of the subimage relative to the parent.
+    image->col0 = 10;
+    image->row0 = 10;
+    for (int i = 0; i < 3; i++) {
+        for (int j = 0; j < 5; j++) {
+            image->data.S32[i][j] = i+j;
+        }
+    }
+
+    //Attempt to get a position in a NULL psImage*
+    psImage *none = NULL;
+    ok ( isnan( psImageGet(none, 1, 1) ),
+         "psImageGet return false when passed a NULL image.\n");
+    skip_start ( !isnan( psImageGet(none, 1, 1) ),
+                 10,"psImageGet failed to return false when passed a NULL image.\n");
+
+    //Attempt to get a position in a psImage* with negative numCols, numRows
+    none = psImageAlloc(2, 2, PS_TYPE_S32);
+    *(int*)&none->numCols = -1;
+    ok ( isnan( psImageGet(none, 1, 1) ),
+         "psImageGet return false when passed an image with negative numCols");
+    skip_start ( !isnan( psImageGet(none, 1, 1) ),
+                 9,"psImageGet return true when passed an image with negative numCols");
+
+    *(int*)&none->numCols = 2;
+    *(int*)&none->numRows = -1;
+    ok ( isnan( psImageGet(none, 1, 1) ),
+         "psImageGet return false when passed an image with negative numRows");
+    skip_start ( !isnan( psImageGet(none, 1, 1) ),
+                 8,"psImageGet failed to return false when passed an image with negative numRows.\n");
+
+    //Attempt to get a position in a psImage* with negative col0, row0
+    *(int*)&none->numRows = 2;
+    none->row0 = -1;
+    ok ( isnan( psImageGet(none, 1, 1) ),
+         "psImageGet return false when passed an image with negative col0.\n");
+    skip_start ( !isnan( psImageGet(none, 1, 1) ),
+                 7,"psImageGet return false when passed an image with negative col0.\n");
+
+    none->row0 = 0;
+    none->col0 = -1;
+    ok ( isnan( psImageGet(none, 1, 1) ),
+         "psImageGet return false when passed an image with negative col0.\n");
+    skip_start ( !isnan( psImageGet(none, 1, 1) ),
+                 6,"psImageGet failed to return false when passed an image with negative col0.\n");
+
+    psFree(none);
+
+
+    //Try to get a position inside of the subimage.
+    ok ( psImageGet(image, 14, 12) == 6,
+         "psImageGet return the correct value.\n");
+    skip_start ( psImageGet(image, 14, 12) != 6,
+                 5,"psImageGet failed to return the correct value.\n");
+
+    //Try to get a position inside of the subimage from the tail.
+    ok ( psImageGet(image, -1, -1) == 6,
+         "psImageGet return the correct value.\n");
+    skip_start ( psImageGet(image, -1, -1) == 6,
+                 4, "psImageGet failed to return the correct value.\n");
+
+    //Try to get a position outside of the subimage but inside of the parent image.
+    ok ( isnan( psImageGet(image, 1, 1) ),
+         "psImageGet return NAN when passed an invalid location.\n");
+    skip_start ( !isnan( psImageGet(image, 1, 1) ),
+                 3, "psImageGet didn't return NAN when passed an invalid location.\n");
+
+    ok ( isnan( psImageGet(image, 9, 10) ),
+         "psImageGet return NAN when passed an invalid location.\n");
+    skip_start ( ! isnan( psImageGet(image, 9, 10) ),
+                 2,"psImageGet failed to return NAN when passed an invalid location.\n");
+
+    //Try to set a position outside of the subimage.
+    ok ( isnan( psImageGet(image, 15, 14) ),
+         "psImageGet return NAN when passed an invalid location.\n");
+    skip_start ( !isnan( psImageGet(image, 15, 14) ),
+                 1, "psImageGet didn't return NAN when passed an invalid location.\n");
+
+    //Try to set a position outside of the subimage, indexing from the tail.
+    ok ( isnan( psImageGet(image, -6, -1) ),
+         "psImageGet failed to return NAN when passed an invalid location.\n");
+
+    skip_end();
+    skip_end();
+    skip_end();
+    skip_end();
+    skip_end();
+    skip_end();
+    skip_end();
+    skip_end();
+    skip_end();
+    skip_end();
+
+
+    psFree(image);
+}
Index: /trunk/psLib/test/mathtypes/tap_psScalar.c
===================================================================
--- /trunk/psLib/test/mathtypes/tap_psScalar.c	(revision 10808)
+++ /trunk/psLib/test/mathtypes/tap_psScalar.c	(revision 10808)
@@ -0,0 +1,126 @@
+/** @file  tst_psScalar.c
+ *
+ *  @brief Contains the tests for psScalar.[ch]
+ *
+ *  @author Eric Van Alst, MHPCC
+ *
+ *  @version $Revision: 1.1 $
+ *           $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-12-18 19:10:56 $
+ *
+ *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
+ */
+
+#include <pslib.h>
+
+#include "tap.h"
+#include "pstap.h"
+
+
+#define tstScalarAllocByType(datatype,value)            \
+{                                                       \
+    psScalar* scalar;                                   \
+    scalar = psScalarAlloc(value,PS_TYPE_##datatype);   \
+    ok(scalar != NULL, "psScalarAlloc successful");     \
+    skip_start(scalar==NULL,1,"Skipping 1 test because psScalarAlloc failed");\
+    ok(scalar->type.type==PS_TYPE_##datatype && scalar->data.datatype==value, \
+       "scalar datatype and value are legit" );        \
+    skip_end();                                         \
+    psFree(scalar);                                     \
+}
+
+
+#define tstScalarCopyByType(datatype,value)                 \
+{                                                           \
+    psScalar*  scalarOrig;                                  \
+    psScalar*  scalarCopy;                                  \
+    scalarOrig = psScalarAlloc(value,PS_TYPE_##datatype);   \
+    scalarCopy = psScalarCopy(scalarOrig);                  \
+    ok(scalarCopy != NULL, "psScalarCopy != NULL");         \
+    skip_start(scalarCopy==NULL,1,"Skipping 1 test since psScalarCopy failed");\
+    ok(scalarCopy->type.type == scalarOrig->type.type && scalarCopy->data.datatype == scalarOrig->data.datatype, "Scalar datatype and value legit"); \
+    skip_end();                                             \
+    psFree(scalarCopy);                                     \
+    psFree(scalarOrig);                                     \
+}
+
+
+
+int main(void)
+{
+    plan_tests(51);
+
+    void testScalarAlloc();
+    testScalarAlloc();
+    void testBadScalarAlloc();
+    testBadScalarAlloc();
+
+    void testScalarCopy();
+    testScalarCopy();
+    void testBadScalarCopy();
+    testBadScalarCopy();
+}
+
+void testScalarAlloc(void)
+{
+    diag("psTestScalarAlloc");
+
+    //Verify the proper allocation/deallocation of scalar objects of valid types
+    tstScalarAllocByType(S8,10);
+    tstScalarAllocByType(U8,12);
+    tstScalarAllocByType(S16,14);
+    tstScalarAllocByType(U16,16);
+    tstScalarAllocByType(S32,18);
+    tstScalarAllocByType(U32,20);
+    tstScalarAllocByType(S64,22);
+    tstScalarAllocByType(U64,24);
+    tstScalarAllocByType(F32,26);
+    tstScalarAllocByType(F64,28);
+    tstScalarAllocByType(C32,30);
+    tstScalarAllocByType(C64,32);
+}
+
+
+void testBadScalarAlloc(void)
+{
+    diag("psTestBadScalarAlloc");
+
+    // Verify return is null for invalid scalar type
+    psScalar* scalar = psScalarAlloc(true,PS_TYPE_BOOL);
+    ok(scalar == NULL, "psScalarAlloc returns null for invalid type");
+}
+
+
+void testScalarCopy(void)
+{
+    diag("psTestScalarCopy");
+
+    // Verify the proper copying of scalar objects for all valid types
+    tstScalarCopyByType(S8,100);
+    tstScalarCopyByType(U8,110);
+    tstScalarCopyByType(S16,120);
+    tstScalarCopyByType(U16,130);
+    tstScalarCopyByType(S32,140);
+    tstScalarCopyByType(U32,150);
+    tstScalarCopyByType(S64,160);
+    tstScalarCopyByType(U64,170);
+    tstScalarCopyByType(F32,180);
+    tstScalarCopyByType(F64,190);
+    tstScalarCopyByType(C32,200);
+    tstScalarCopyByType(C64,210);
+}
+
+
+void testBadScalarCopy(void)
+{
+    diag("psTestBadScalarCopy");
+
+    // Verify the return is null for invalid scalar type in the original
+    psScalar* scalarOrig = psScalarAlloc(0,PS_TYPE_S8);
+    scalarOrig->type.type = PS_TYPE_BOOL;
+    psScalar* scalarCopy = psScalarCopy(scalarOrig);
+    ok(scalarCopy == NULL, "psScalarCopy returns NULL for invalid type");
+
+    scalarCopy = psScalarCopy(NULL);
+    ok(scalarCopy == NULL, "psScalarCopy returns NULL for NULL argument");
+}
Index: /trunk/psLib/test/mathtypes/tap_psVectorSort_01.c
===================================================================
--- /trunk/psLib/test/mathtypes/tap_psVectorSort_01.c	(revision 10808)
+++ /trunk/psLib/test/mathtypes/tap_psVectorSort_01.c	(revision 10808)
@@ -0,0 +1,151 @@
+/** @file  tst_psVectorSort_01.c
+ *
+ *  @brief Test driver for psVectorSort functions
+ *
+ *  This test driver contains the following tests for psVectorSort test point 1:
+ *     A)  Sort input vector to output vector for all types
+ *     B)  Sort input float vector into itself
+ *     C)  Attempt to sort vector with invalid type (i.e. PS_TYPE_BOOL)
+ *     D)  Sort input vector with zero items
+ *     C)  Free float vectors
+ *
+ *  @author  Ross Harman, MHPCC
+ *
+ *  @version $Revision: 1.1 $  $Name: not supported by cvs2svn $
+ *  @date  $Date: 2006-12-18 19:10:56 $
+ *
+ *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
+ *
+ */
+
+#include <pslib.h>
+
+#include "tap.h"
+#include "pstap.h"
+
+
+#define tstVectorSortByType(datatype,value)   \
+diag( "tstVectorSortByType_" #datatype ); \
+in = psVectorAlloc(7,PS_TYPE_##datatype); \
+in->n = 7;  \
+out = psVectorAlloc(7,PS_TYPE_##datatype); \
+out->n = 7;  \
+in->data.datatype[0] = 7+value; \
+in->data.datatype[1] = 9+value; \
+in->data.datatype[2] = 3+value; \
+in->data.datatype[3] = 1+value; \
+in->data.datatype[4] = 5+value; \
+in->data.datatype[5] = 5+value; \
+in->data.datatype[6] = 0+value; \
+tempVec = out; \
+out = psVectorSort(out, in); \
+ok(tempVec == out, \
+   "Return value equal to orignal output argument passed to function"); \
+skip_start(tempVec != out, \
+           7,"Return value not equal to orignal output argument passed to function"); \
+ok(out->data.datatype[0] == in->data.datatype[6], \
+   "sort out[0] type %s",#datatype); \
+skip_start(out->data.datatype[0] != in->data.datatype[6], \
+           6,"sort out[0] type %s",#datatype); \
+ok(out->data.datatype[1] == in->data.datatype[3], \
+   "sort out[1] type %s",#datatype); \
+skip_start(out->data.datatype[1] != in->data.datatype[3], \
+           5,"Improper sort out[1] type %s",#datatype); \
+ok(out->data.datatype[2] == in->data.datatype[2], \
+   "sort out[2] type %s",#datatype); \
+skip_start(out->data.datatype[2] != in->data.datatype[2], \
+           4,"Improper sort out[2] type %s",#datatype); \
+ok(out->data.datatype[3] == in->data.datatype[4], \
+   "sort out[3] type %s",#datatype); \
+skip_start(out->data.datatype[3] != in->data.datatype[4], \
+           3,"Improper sort out[3] type %s",#datatype); \
+ok(out->data.datatype[4] == in->data.datatype[5], \
+   "sort out[4] %s",#datatype); \
+skip_start(out->data.datatype[4] != in->data.datatype[5], \
+           2,"Improper sort out[4] %s",#datatype); \
+ok(out->data.datatype[5] == in->data.datatype[0], \
+   "sort out[5] %s",#datatype); \
+skip_start(out->data.datatype[5] != in->data.datatype[0], \
+           1,"Improper sort out[5] %s",#datatype); \
+ok(out->data.datatype[6] == in->data.datatype[1], \
+   "sort out[6] %s",#datatype); \
+skip_end(); \
+skip_end(); \
+skip_end(); \
+skip_end(); \
+skip_end(); \
+skip_end(); \
+skip_end(); \
+psFree(in); \
+psFree(out);
+
+
+
+psS32 main(psS32 argc,
+           char* argv[])
+{
+    plan_tests(92);
+
+    psVector *in = NULL;
+    psVector *out = NULL;
+    psVector *tempVec = NULL;
+
+    // Test A - Verify the sort for all supported types
+
+    tstVectorSortByType(S8,0);
+    tstVectorSortByType(S16,1);
+    tstVectorSortByType(S32,2);
+    tstVectorSortByType(S64,3);
+    tstVectorSortByType(U8,4);
+    tstVectorSortByType(U16,5);
+    tstVectorSortByType(U32,6);
+    tstVectorSortByType(U64,7);
+    tstVectorSortByType(F32,8);
+    tstVectorSortByType(F64,9);
+
+
+    // Test B - Sort input vector into itself
+
+    in = psVectorAlloc(7, PS_TYPE_F32);
+    in->n = 7;
+    in->data.F32[0] = 0.7f;
+    in->data.F32[1] = 0.9f;
+    in->data.F32[2] = 0.3f;
+    in->data.F32[3] = 0.1f;
+    in->data.F32[4] = 0.5f;
+    in->data.F32[5] = 0.5f;
+    in->data.F32[6] = -2.0f;
+    in = psVectorSort(in, in);
+    ok(in->data.F32[0] == -2.0f,"self sort in[0]");
+    ok(in->data.F32[1] == 0.1f,"self sort in[1]");
+    ok(in->data.F32[2] == 0.3f, "self sort in[2]");
+    ok(in->data.F32[3] == 0.5f, "self sort in[3]");
+    ok(in->data.F32[4] == 0.5f, "self sort in[4]");
+    ok(in->data.F32[5] == 0.7f, "self sort in[5]");
+    ok(in->data.F32[6] == 0.9f, "self sort in[6]");
+
+    // Test C - Attempt to sort vector with invalid type
+    in->type.type = PS_TYPE_BOOL;
+    out = psVectorAlloc(7,PS_TYPE_F32);
+    tempVec = psVectorSort(out,in);
+    ok(tempVec == NULL, "Did return NULL on error");
+
+    // Test D - Sort vector with zero elements
+    out = psVectorAlloc(7,PS_TYPE_F32);
+    in->n = 0;
+    out = psVectorSort(out,in);
+    ok (out != NULL, "psVectorSort returned a non-NULL vector" );
+    skip_start (out == NULL, 1, "psVectorSort returned a NULL vector" );
+    ok (out->n == 0, "psVectorSort correctly return a 0-length vector.\n");
+    skip_end();
+
+    psFree(out);
+
+
+    // Test D - Free float vectors
+    psFree(in);
+    ok ( ! psMemCheckLeaks(0, NULL, stdout, false),"Memory leaks not detected");
+
+    psS32 nBad = psMemCheckCorruption(0);
+    ok(!nBad, "Found %d bad memory blocks\n", nBad);
+}
Index: /trunk/psLib/test/mathtypes/tap_psVectorSort_02.c
===================================================================
--- /trunk/psLib/test/mathtypes/tap_psVectorSort_02.c	(revision 10808)
+++ /trunk/psLib/test/mathtypes/tap_psVectorSort_02.c	(revision 10808)
@@ -0,0 +1,134 @@
+/** @file  tst_psVectorSort_02.c
+ *
+ *  @brief Test driver for psVectorSort functions
+ *
+ *  This test driver contains the following tests for psVectorSort test point 2:
+ *     A)  Create vectors
+ *     B)  Sort integer vector of indices based on pre-sort order of floating point vector
+ *     C)  Attempt to sort with null input vector
+ *     D)  Sort with output vector which needs to be resized
+ *     E)  Sort input vector with zero elements
+ *     F)  Attempt to sort input vector with invalid type
+ *     G)  Free vectors
+ *
+ *  @author  Ross Harman, MHPCC
+ *
+ *  @version $Revision: 1.1 $  $Name: not supported by cvs2svn $
+ *  @date  $Date: 2006-12-18 19:10:56 $
+ *
+ *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
+ *
+ */
+
+#include <pslib.h>
+
+#include "tap.h"
+#include "pstap.h"
+
+#define tstVectorSortIndexByType(datatype,value) \
+diag( "tstVectorSortIndexByType_" #datatype ); \
+in = psVectorAlloc( 5, PS_TYPE_##datatype ); \
+in->n = 5; \
+in->data.datatype[0] = 7+value; \
+in->data.datatype[1] = 9+value; \
+in->data.datatype[2] = 5+value; \
+in->data.datatype[3] = 1+value; \
+in->data.datatype[4] = 5+value; \
+out = psVectorSortIndex(out,in); \
+ok(out->type.type == PS_TYPE_S32, \
+   "Output vector is of type PS_TYPE_S32"); \
+ok(out->data.U32[0] == 3,  \
+   "index sort out[0] = %ld",out->data.U32[0]); \
+ok(out->data.U32[1] == 2, \
+   "index sort out[1] = %ld",out->data.U32[1]); \
+ok(out->data.U32[2] == 4, \
+   "index sort out[2] = %ld",out->data.U32[2]); \
+ok(out->data.U32[3] == 0, \
+   "index sort out[3] = %ld",out->data.U32[3]); \
+ok(out->data.U32[4] == 1, \
+   "index sort out[4] = %ld",out->data.U32[4]); \
+psFree(in);
+
+
+psS32 main(psS32 argc, char* argv[])
+{
+    plan_tests(71);
+
+    psVector *in = NULL;
+    psVector *out = NULL;
+    psVector *tempVect = NULL;
+
+    // Test A - Sort vectors by index for all types
+    tstVectorSortIndexByType(S8,0)
+    tstVectorSortIndexByType(U8,1)
+    tstVectorSortIndexByType(S16,2)
+    tstVectorSortIndexByType(U16,3)
+    tstVectorSortIndexByType(S32,4)
+    tstVectorSortIndexByType(U32,5)
+    tstVectorSortIndexByType(S64,6)
+    tstVectorSortIndexByType(U64,7)
+    tstVectorSortIndexByType(F32,8)
+    tstVectorSortIndexByType(F64,9)
+    psFree(out);
+
+    // Test  C  Attempt to sort with null input vector
+    in = NULL;
+    out = psVectorAlloc(5,PS_TYPE_U32);
+    out = psVectorSortIndex(out,in);
+    ok(out == NULL, "Did return NULL with NULL input specified");
+
+    // Test  D  Sort with output vector which needs to be resized
+    in = psVectorAlloc(5,PS_TYPE_U8);
+    in->n=5;
+    for(psS32 m=0; m<5; m++) {
+        in->data.U8[m]= 20-m;
+    }
+    out = psVectorAlloc(5,PS_TYPE_U32);
+    out->n = 5;
+    out = psVectorSortIndex(out,in);
+    ok(out->n == 5, "Did properly resize output vector...out->n=%d, in->n=%d", out->n, in->n);
+    ok(out->data.U32[0] == 4,
+       "Did properly sort index out[0] = %d",out->data.U32[0]);
+    ok(out->data.U32[1] == 3,
+       "Did properly sort index out[1] = %d",out->data.U32[1]);
+    ok(out->data.U32[2] == 2,
+       "Did properly sort index out[2] = %d",out->data.U32[2]);
+    ok(out->data.U32[3] == 1,
+       "Did properly sort index out[3] = %d",out->data.U32[3]);
+    ok(out->data.U32[4] == 0,
+       "Did properly sort index out[4] = %d",out->data.U32[4]);
+
+    psFree(in);
+    psFree(out);
+
+    // Test E - Sort input vector with zero elements
+    in = psVectorAlloc(5,PS_TYPE_U8);
+    out = psVectorAlloc(5,PS_TYPE_U32);
+    in->n = 0;
+    out->n = 0;
+    tempVect = out;
+    out = psVectorSortIndex(out,in);
+    ok ( out == tempVect, "Did not return the same output vector");
+    in->n=5;
+    out->n=5;
+    psFree(out);
+    psFree(in);
+
+    // Test F - Attempt to sort input vector with invalid type
+    in = psVectorAlloc(5,PS_TYPE_U8);
+    out = psVectorAlloc(5,PS_TYPE_U32);
+    in->n = 5;
+    out->n = 5;
+    tempVect = out;
+    in->type.type = PS_TYPE_BOOL;
+    out = psVectorSortIndex(out,in);
+    ok( out == NULL, "Did return NULL");
+    in->type.type = PS_TYPE_U8;
+    psFree(in);
+
+    // Test G - Free vectors
+    psS32 nLeaks = psMemCheckLeaks(0, NULL, stdout, false);
+    ok(!nLeaks, "Found %d memory leaks\n", nLeaks);
+    psS32 nBad = psMemCheckCorruption(0);
+    ok(!nBad, "Found %d bad memory blocks\n", nBad);
+}
Index: /trunk/psLib/test/mathtypes/tap_psVectorSort_03.c
===================================================================
--- /trunk/psLib/test/mathtypes/tap_psVectorSort_03.c	(revision 10808)
+++ /trunk/psLib/test/mathtypes/tap_psVectorSort_03.c	(revision 10808)
@@ -0,0 +1,72 @@
+/** @file  tst_psVectorSort_03.c
+ *
+ *  @brief Test driver for psVectorSort functions
+ *
+ *  This test driver contains the following tests for psVectorSort test point 3:
+ *     A)  Create float vectors of different sizes
+ *     B)  Attempt to sort vectors...should get errors
+ *     C)  Create float vector and double vector
+ *     D)  Attempt to sort vectors...should get errors
+ *     E)  Free float, double vectors
+ *
+ *  @author  Ross Harman, MHPCC
+ *
+ *  @version $Revision: 1.1 $  $Name: not supported by cvs2svn $
+ *  @date  $Date: 2006-12-18 19:10:56 $
+ *
+ *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
+ *
+ */
+
+#include <pslib.h>
+
+#include "tap.h"
+#include "pstap.h"
+
+
+psS32 main(psS32 argc,
+           char* argv[])
+{
+    plan_tests(2);
+
+    psVector *in = NULL;
+    psVector *out = NULL;
+    psVector *in2 = NULL;
+    psVector *out2 = NULL;
+
+    // Test A - Create float vectors
+    in = psVectorAlloc(5, PS_TYPE_F32);
+    in->n = 5;
+    out = psVectorAlloc(6, PS_TYPE_F32);
+    out->n = 6;
+    in->n = 5;
+    for(psS32 i=0; i<5; i++) {
+        //printf("arr[%d] = %f\n", i, in->data.F32[i]);
+    }
+
+
+    // Test B - Sort input float vector and put results into output float vector
+    out = psVectorSort(out, in);
+
+    // Test C - Create float vector and double vector
+    in2 = psVectorAlloc(5, PS_TYPE_F32);
+    in2->n = 5;
+    out2 = psVectorAlloc(5, PS_TYPE_F64);
+    out2->n = 5;
+    for(psS32 j=0; j<5; j++) {
+        //printf("vec[%d] = %f\n", j, in2->data.F32[j]);
+    }
+
+    // Test D - Attempt to sort vectors with output of different type should create error
+    out2 = psVectorSort(out2, in2);
+
+    // Test C - Free float vectors
+    psFree(in);
+    psFree(in2);
+    psFree(out);
+    psFree(out2);
+    psS32 nLeaks = psMemCheckLeaks(0, NULL, stdout, false);
+    ok(!nLeaks, "Found %d memory leaks\n", nLeaks);
+    psS32 nBad = psMemCheckCorruption(0);
+    ok(!nBad, "Found %d bad memory blocks\n", nBad);
+}
Index: /trunk/psLib/test/mathtypes/tap_psVectorSort_04.c
===================================================================
--- /trunk/psLib/test/mathtypes/tap_psVectorSort_04.c	(revision 10808)
+++ /trunk/psLib/test/mathtypes/tap_psVectorSort_04.c	(revision 10808)
@@ -0,0 +1,41 @@
+/** @file  tst_psVectorSort_04.c
+ *
+ *  @brief Test driver for psVectorSort functions
+ *
+ *  This test driver contains the following tests for psVectorSort test point 4:
+ *     A)  Attempt to sort with null input vector
+ *     B)  Free vectors
+ *
+ *  @author  Ross Harman, MHPCC
+ *
+ *  @version $Revision: 1.1 $  $Name: not supported by cvs2svn $
+ *  @date  $Date: 2006-12-18 19:10:56 $
+ *
+ *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
+ *
+ */
+
+#include <pslib.h>
+
+#include "tap.h"
+#include "pstap.h"
+
+
+psS32 main(psS32 argc,
+           char* argv[])
+{
+    plan_tests(2);
+
+    psVector *badIn = NULL;
+    psVector *goodOut = psVectorAlloc(5, PS_TYPE_F32);
+
+    // Test A - Attempt to sort with null input vector
+    goodOut = psVectorSort(goodOut, badIn);
+
+    // Test B - Free vectors
+    psFree(goodOut);
+    psS32 nLeaks = psMemCheckLeaks(0, NULL, stdout, false);
+    ok(!nLeaks, "Found %d memory blocks\n", nLeaks);
+    psS32 nBad = psMemCheckCorruption(0);
+    ok(!nBad, "Found %d bad memory blocks\n", nBad);
+}
