Index: trunk/psLib/src/collections/psArray.c
===================================================================
--- trunk/psLib/src/collections/psArray.c	(revision 1787)
+++ trunk/psLib/src/collections/psArray.c	(revision 1807)
@@ -9,6 +9,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-08-27 23:54:33 $
+ *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-09-14 20:01:52 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -26,4 +26,6 @@
 #include "psArray.h"
 #include "psLogMsg.h"
+
+#include "psCollectionsErrors.h"
 
 /*****************************************************************************/
@@ -43,9 +45,4 @@
     psArray* psArr = NULL;
 
-    // Invalid nalloc
-    if (nalloc < 1) {
-        psError(__func__, "Invalid value for nalloc. nalloc: %d\n", nalloc);
-        return NULL;
-    }
     // Create vector struct
     psArr = (psArray* ) psAlloc(sizeof(psArray));
@@ -63,10 +60,4 @@
 psArray* psArrayRealloc(unsigned int nalloc, psArray* restrict in)
 {
-    // Invalid nalloc
-    if (nalloc < 1) {
-        psError(__func__, "Invalid value for realloc (%d)\n", nalloc);
-        return NULL;
-    }
-
     if (in == NULL) {
         return psArrayAlloc(nalloc);
Index: trunk/psLib/src/collections/psBitSet.c
===================================================================
--- trunk/psLib/src/collections/psBitSet.c	(revision 1787)
+++ trunk/psLib/src/collections/psBitSet.c	(revision 1807)
@@ -1,3 +1,2 @@
-
 /** @file  psBitSet.c
  *
@@ -10,16 +9,12 @@
  *
  *  @author Ross Harman, MHPCC
- *
- *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-08-09 23:34:57 $
+ *  @author Robert DeSonia, MHPCC
+ *
+ *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-09-14 20:01:52 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  */
 
-/******************************************************************************/
-
-/*  INCLUDE FILES                                                             */
-
-/******************************************************************************/
 #include <string.h>
 #include <stdio.h>
@@ -32,43 +27,17 @@
 #include "psError.h"
 #include "psAbort.h"
-
-/******************************************************************************/
-
-/*  DEFINE STATEMENTS                                                         */
-
-/******************************************************************************/
-
-// None
-
-/******************************************************************************/
-
-/*  TYPE DEFINITIONS                                                          */
-
-/******************************************************************************/
-
-// None
-
-/*****************************************************************************/
-
-/*  GLOBAL VARIABLES                                                         */
-
-/*****************************************************************************/
-
-// None
-
-/*****************************************************************************/
-
-/*  FILE STATIC VARIABLES                                                    */
-
-/*****************************************************************************/
-
-// None
-
-/*****************************************************************************/
-
-/*  FUNCTION IMPLEMENTATION - LOCAL                                          */
-
-/*****************************************************************************/
-static void psBitSetFree(psBitSet* restrict inBitSet);
+#include "psString.h"
+
+#include "psCollectionsErrors.h"
+
+enum {
+    UNKNOWN_OP,
+    AND_OP,
+    OR_OP,
+    XOR_OP,
+    NOT_OP
+};
+
+static void bitSetFree(psBitSet* restrict inBitSet);
 
 /** Private function to create a mask.
@@ -90,9 +59,12 @@
 }
 
-/*****************************************************************************/
-
-/* FUNCTION IMPLEMENTATION - PUBLIC                                          */
-
-/*****************************************************************************/
+static void bitSetFree(psBitSet* restrict inBitSet)
+{
+    if (inBitSet == NULL) {
+        return;
+    }
+    psFree(inBitSet->bits);
+}
+
 psBitSet* psBitSetAlloc(int n)
 {
@@ -100,15 +72,15 @@
     psBitSet* newObj = NULL;
 
-    if (n <= 0) {
-        psError(__func__, " : Line %d - Allocation size must be > 0: size = %d", __LINE__, n);
-        return 0;
+    if (n < 0) {
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psBitSetAlloc",
+                   PS_ERR_BAD_PARAMETER_VALUE, true,
+                   PS_ERRORTEXT_psBitSet_ALLOC_NEG_SIZE,
+                   n);
+        return NULL;
     }
 
     numBytes = ceil(n / 8.0);
     newObj = psAlloc(sizeof(psBitSet));
-    if (newObj == NULL) {
-        psAbort(__func__, " : Line %d - Failed to allocate memory", __LINE__);
-    }
-    p_psMemSetDeallocator(newObj, (psFreeFcn) psBitSetFree);
+    p_psMemSetDeallocator(newObj, (psFreeFcn) bitSetFree);
     newObj->n = numBytes;
 
@@ -116,22 +88,10 @@
     /* @i@ */
     newObj->bits = psAlloc(sizeof(char) * numBytes);
-    if (newObj->bits == NULL) {
-        psAbort(__func__, " : Line %d - Failed to allocate memory", __LINE__);
-    }
-
-    memset(newObj->bits, numBytes, 0);
+
+    memset(newObj->bits, 0, numBytes);
 
     return newObj;
 }
 
-static void psBitSetFree(psBitSet* restrict inBitSet)
-{
-    if (inBitSet == NULL) {
-        psError(__func__, " : Line %d - Null psBitSet for inBitSet argument", __LINE__);
-        return;
-    }
-    psFree(inBitSet->bits);
-}
-
 psBitSet* psBitSetSet(psBitSet* inBitSet, int bit)
 {
@@ -139,11 +99,14 @@
 
     if (inBitSet == NULL) {
-        psError(__func__, " : Line %d - Null psBitSet for inBitSet argument", __LINE__);
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psBitSetSet",
+                   PS_ERR_BAD_PARAMETER_NULL, true,
+                   PS_ERRORTEXT_psBitSet_SET_NULL);
         return inBitSet;
-    } else if (bit < 0) {
-        psError(__func__, " : Line %d - Bit position too small: %d", __LINE__, bit);
-        return inBitSet;
-    } else if (bit > inBitSet->n * 8 - 1) {
-        psError(__func__, " : Line %d - Bit position too large: %d", __LINE__, bit);
+    } else if ( (bit < 0) ||
+                (bit > inBitSet->n * 8 - 1) ) {
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psBitSetSet",
+                   PS_ERR_BAD_PARAMETER_VALUE, true,
+                   PS_ERRORTEXT_psBitSet_BIT_OUTOFRANGE,
+                   bit,inBitSet->n * 8 - 1);
         return inBitSet;
     }
@@ -155,4 +118,28 @@
 }
 
+psBitSet* psBitSetClear(psBitSet* inBitSet, int bit)
+{
+    char *byte = NULL;
+
+    if (inBitSet == NULL) {
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psBitSetClear",
+                   PS_ERR_BAD_PARAMETER_NULL, true,
+                   PS_ERRORTEXT_psBitSet_SET_NULL);
+        return inBitSet;
+    } else if ( (bit < 0) ||
+                (bit > inBitSet->n * 8 - 1) ) {
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psBitSetClear",
+                   PS_ERR_BAD_PARAMETER_VALUE, true,
+                   PS_ERRORTEXT_psBitSet_BIT_OUTOFRANGE,
+                   bit,inBitSet->n * 8 - 1);
+        return inBitSet;
+    }
+    // Variable byte is the byte in the array that contains the bit to be set
+    byte = inBitSet->bits + bit / 8;
+    *byte &= ! mask(bit);
+
+    return inBitSet;
+}
+
 bool psBitSetTest(const psBitSet* inBitSet, int bit)
 {
@@ -160,20 +147,20 @@
 
     if (inBitSet == NULL) {
-        psError(__func__, " : Line %d - Null psBitSet for inBitSet argument", __LINE__);
-        return 0;
-    } else if (bit < 0) {
-        psError(__func__, " : Line %d - Bit position too small: %d", __LINE__, bit);
-        return 0;
-    } else if (bit > inBitSet->n * 8 - 1) {
-        psError(__func__, " : Line %d - Bit position too large: %d", __LINE__, bit);
-        return 0;
-    }
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psBitSetTest",
+                   PS_ERR_BAD_PARAMETER_NULL, true,
+                   PS_ERRORTEXT_psBitSet_SET_NULL);
+        return false;
+    } else if ( (bit < 0) ||
+                (bit > inBitSet->n * 8 - 1) ) {
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psBitSetTest",
+                   PS_ERR_BAD_PARAMETER_VALUE, true,
+                   PS_ERRORTEXT_psBitSet_BIT_OUTOFRANGE,
+                   bit,inBitSet->n * 8 - 1);
+        return false;
+    }
+
     // Variable byte is the byte in the array that contains the bit to be tested
     byte = inBitSet->bits + bit / 8;
-    if ((int)(*byte & mask(bit)) == 0) {
-        return 0;
-    }
-
-    return 1;
+    return ((*byte & mask(bit)) != 0);
 }
 
@@ -183,57 +170,108 @@
     int i = 0;
     int n = 0;
-    char tempChar = '0';
-    char *outBits = NULL;
-    char *inBits1 = NULL;
-    char *inBits2 = NULL;
+    char* outBits = NULL;
+    char* inBits1 = NULL;
+    char* inBits2 = NULL;
+    int op = UNKNOWN_OP;
 
     if (inBitSet1 == NULL) {
-        psError(__func__, " : Line %d - Null psBitSet for inBitSet1 argument", __LINE__);
-        return outBitSet;
-    }
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psBitSetOp",
+                   PS_ERR_BAD_PARAMETER_NULL, true,
+                   PS_ERRORTEXT_psBitSet_FIRST_OPERAND_NULL);
+        psFree(outBitSet);
+        return NULL;
+    }
+    inBits1 = inBitSet1->bits;
 
     if (operator == NULL) {
-        psError(__func__, " : Line %d - Null input operator\n", __LINE__);
-        return outBitSet;
-    }
-
-    if (inBitSet2 == NULL) {
-        psError(__func__, " : Line %d - Null psBitSet for inBitSet2 argument", __LINE__);
-        return outBitSet;
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psBitSetOp",
+                   PS_ERR_BAD_PARAMETER_NULL, true,
+                   PS_ERRORTEXT_psBitSet_OPERATOR_NULL);
+        psFree(outBitSet);
+        return NULL;
+    }
+
+    // make operator all caps
+    int tempStrLen = strlen(operator);
+    char* tempStr = psAlloc(tempStrLen+1);
+
+    for (int lcv=0;lcv<tempStrLen;lcv++) {
+        tempStr[lcv] = (char)toupper(operator[lcv]);
+    }
+    tempStr[tempStrLen] = '\0';
+
+    // parse the operator
+    if (strcmp(operator,"AND")==0) {
+        op = AND_OP;
+    } else if (strcmp(operator,"OR")==0) {
+        op = OR_OP;
+    } else if (strcmp(operator,"XOR")==0) {
+        op = XOR_OP;
+    } else if (strcmp(operator,"NOT")==0) {
+        op = NOT_OP;
+    } else {
+        psFree(tempStr);
+        psFree(outBitSet);
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psBitSetOp",
+                   PS_ERR_BAD_PARAMETER_VALUE, true,
+                   PS_ERRORTEXT_psBitSet_OPERATOR_INVALID,
+                   operator);
+        return NULL;
+    }
+    psFree(tempStr);
+
+    if (op != NOT_OP) {
+        if (inBitSet2 == NULL) {
+            psErrorMsg(PS_ERRORNAME_DOMAIN "psBitSetOp",
+                       PS_ERR_BAD_PARAMETER_NULL, true,
+                       PS_ERRORTEXT_psBitSet_SECOND_OPERAND_NULL);
+            psFree(outBitSet);
+            return NULL;
+        }
+
+        if (inBitSet1->n != inBitSet2->n) {
+            psErrorMsg(PS_ERRORNAME_DOMAIN "psBitSetOp",
+                       PS_ERR_BAD_PARAMETER_SIZE, true,
+                       PS_ERRORTEXT_psBitSet_OPERANDS_SIZE_DIFFER);
+            psFree(outBitSet);
+            return NULL;
+        }
+        inBits2 = inBitSet2->bits;
     }
 
     if (outBitSet == NULL) {
-        outBitSet = psBitSetAlloc(inBitSet1->n * 8);
-    }
-
-    if (inBitSet1->n != inBitSet2->n || outBitSet->n != inBitSet1->n) {
-        psError(__func__, " : Line %d - psBitSet sizes not the same", __LINE__);
-        return outBitSet;
+        outBitSet = psBitSetAlloc(inBitSet1->n*8);
+    } else if (outBitSet->n != inBitSet1->n) {
+        outBitSet->n = inBitSet1->n;
+        outBitSet->bits = psRealloc(outBitSet->bits, inBitSet1->n);
     }
 
     n = outBitSet->n;
     outBits = outBitSet->bits;
-    inBits1 = inBitSet1->bits;
-    inBits2 = inBitSet2->bits;
-
-    tempChar = toupper(operator[0]);
-    switch (tempChar) {
-    case 'A':
+
+    switch (op) {
+    case AND_OP:
         for (i = 0; i < n; i++) {
             outBits[i] = inBits1[i] & inBits2[i];
         }
         break;
-    case 'O':
+    case OR_OP:
         for (i = 0; i < n; i++) {
             outBits[i] = inBits1[i] | inBits2[i];
         }
         break;
-    case 'X':
+    case XOR_OP:
         for (i = 0; i < n; i++) {
             outBits[i] = inBits1[i] ^ inBits2[i];
         }
         break;
+    case NOT_OP:
+        for (i = 0; i < n; i++) {
+            outBits[i] = ~inBits1[i];
+        }
+        break;
     default:
-        psError(__func__, " : Line %d - Invalid psBitMask binary operation: %s", __LINE__, operator);
+        psAbort(PS_ERRORNAME_DOMAIN "psBitSetOp",
+                "Unexpected error - operator parsed successfully but not valid?");
     }
 
@@ -243,34 +281,18 @@
 psBitSet* psBitSetNot(psBitSet* outBitSet, const psBitSet* restrict inBitSet)
 {
-    int i = 0;
-    int n = 0;
-    char *outBits = NULL;
-    char *inBits = NULL;
-
-    if (inBitSet == NULL) {
-        psError(__func__, " : Line %d - Null psBitSet for inBitSet argument", __LINE__);
-        return outBitSet;
-    }
-
-    n = inBitSet->n;
-    if (n == 0) {
-        psError(__func__, " : Line %d - No elements in inBitSet", __LINE__);
-        return outBitSet;
-    }
+    if (inBitSet == NULL) {
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psBitSetNot",
+                   PS_ERR_BAD_PARAMETER_NULL, true,
+                   PS_ERRORTEXT_psBitSet_OPERAND_NULL);
+        psFree(outBitSet);
+        return NULL;
+    }
+
+    outBitSet = psBitSetOp(outBitSet,inBitSet,"NOT",NULL);
 
     if (outBitSet == NULL) {
-        outBitSet = psBitSetAlloc(n * 8);
-    }
-
-    if (inBitSet->n != outBitSet->n) {
-        psError(__func__, " : Line %d - psBitSet sizes not the same", __LINE__);
-        return outBitSet;
-    }
-
-    outBits = outBitSet->bits;
-    inBits = inBitSet->bits;
-
-    for (i = 0; i < n; i++) {
-        outBits[i] = ~inBits[i];
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psBitSetNot",
+                   PS_ERR_UNKNOWN, false,
+                   PS_ERRORTEXT_psBitSet_NOT_OP_FAILED);
     }
 
@@ -284,10 +306,6 @@
     char *outString = psAlloc((size_t) numBits + 1);
 
-    if (outString == NULL) {
-        psAbort(__func__, " : Line %d - Failed to allocate memory", __LINE__);
-    }
-
     for (i = 0; i < numBits; i++) {
-        outString[numBits - i - 1] = (psBitSetTest(inBitSet, i) == 1) ? '1' : '0';
+        outString[numBits - i - 1] = psBitSetTest(inBitSet, i) ? '1' : '0';
     }
 
Index: trunk/psLib/src/collections/psBitSet.h
===================================================================
--- trunk/psLib/src/collections/psBitSet.h	(revision 1787)
+++ trunk/psLib/src/collections/psBitSet.h	(revision 1807)
@@ -1,3 +1,2 @@
-
 /** @file  psBitSet.h
  *
@@ -13,6 +12,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-08-11 19:53:33 $
+ *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-09-14 20:01:52 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -26,7 +25,5 @@
 
 /******************************************************************************/
-
 /*  TYPE DEFINITIONS                                                          */
-
 /******************************************************************************/
 
@@ -44,7 +41,5 @@
 
 /*****************************************************************************/
-
 /* FUNCTION PROTOTYPES                                                       */
-
 /*****************************************************************************/
 
@@ -64,5 +59,5 @@
 /** Set a bit.
  *
- *  Sets a bit at a given bit location, either one or zero. The bit is set based on a zero index with the
+ *  Sets a bit at a given bit location. The bit is set based on a zero index with the
  *  first bit set in the zero bit slot of the zero element of the byte array. As an example, setting bit 3 in
  *  an array with two elements would result in an psBitSet that looks like 00000000 00001000.
@@ -74,4 +69,18 @@
     psBitSet* restrict inMask,         ///< Pointer to psBitSet to be set.
     int bit                            ///< Bit to be set.
+);
+
+/** Clear a bit.
+ *
+ *  Clear a bit at a given bit location. The bit is cleared based on a zero 
+ *  index with the first bit set in the zero bit slot of the zero element of 
+ *  the byte array. 
+ *
+ *  @return  psBitSet* : Pointer to struct containing psBitSet.
+ */
+psBitSet* psBitSetClear(
+    /* @returned@ */
+    psBitSet* restrict inMask,         ///< Pointer to psBitSet to be cleared.
+    int bit                            ///< Bit to be cleared.
 );
 
Index: trunk/psLib/src/collections/psCollectionsErrors.dat
===================================================================
--- trunk/psLib/src/collections/psCollectionsErrors.dat	(revision 1787)
+++ trunk/psLib/src/collections/psCollectionsErrors.dat	(revision 1807)
@@ -7,3 +7,20 @@
 #  N.B. in code, the ERRORNAME appears as PS_ERRORTEXT_ERRORNAME
 ####################################################################
-psVector_NALLOC_NOT_POSITIVE    Parameter nalloc (%d) must be positive.
+#
+psVector_REALLOC_NULL                  psVectorRealloc must a given a non-NULL psVector to resize.  Desired datatype unknown.
+psVector_SORT_NULL                     psVectorSort can not sort a NULL psVector.
+psVector_UNSUPPORTED_TYPE              Input psVector is an unsupported type (%d).
+#
+psBitSet_ALLOC_NEG_SIZE                The number of bit in a psBitSet (%d) must be greater than zero.
+psBitSet_SET_NULL                      Can not operate on a NULL psBitSet.
+psBitSet_BIT_OUTOFRANGE                The specified bit position (%d) is invalid.  Position must be between 0 and %d.
+psBitSet_OPERATOR_NULL                 Specified operator is NULL.  Must specify desired operator.
+psBitSet_OPERATOR_INVALID              Specified operator, %s, is invalid.  Valid operators are AND, OR, and XOR.
+psBitSet_FIRST_OPERAND_NULL            First psBitSet operand can not be NULL.
+psBitSet_SECOND_OPERAND_NULL           Second psBitSet operand can not be NULL.
+psBitSet_OPERANDS_SIZE_DIFFER          The psBitSet operand must be the same size.
+psBitSet_NOT_OP_FAILED                 Could not perform NOT operation.
+psBitSet_OPERAND_NULL                  Operand can not be NULL.
+#
+psScalar_UNSUPPORTED_TYPE              Specified datatype (%d) is unsupported by psScalar.
+psScalar_COPY_NULL                     Can not copy a NULL psScalar.
Index: trunk/psLib/src/collections/psCollectionsErrors.h
===================================================================
--- trunk/psLib/src/collections/psCollectionsErrors.h	(revision 1787)
+++ trunk/psLib/src/collections/psCollectionsErrors.h	(revision 1807)
@@ -7,6 +7,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-09-11 00:43:54 $
+ *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-09-14 20:01:52 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -30,5 +30,19 @@
 
 //~Start #define PS_ERRORTEXT_$1 "$2"
-#define PS_ERRORTEXT_psVector_NALLOC_NOT_POSITIVE "Parameter nalloc (%d) must be positive"
+#define PS_ERRORTEXT_psVector_REALLOC_NULL "psVectorRealloc must a given a non-NULL psVector to resize.  Desired datatype unknown."
+#define PS_ERRORTEXT_psVector_SORT_NULL "psVectorSort can not sort a NULL psVector."
+#define PS_ERRORTEXT_psVector_UNSUPPORTED_TYPE "Input psVector is an unsupported type (%d)."
+#define PS_ERRORTEXT_psBitSet_ALLOC_NEG_SIZE "The number of bit in a psBitSet (%d) must be greater than zero."
+#define PS_ERRORTEXT_psBitSet_SET_NULL "Can not operate on a NULL psBitSet."
+#define PS_ERRORTEXT_psBitSet_BIT_OUTOFRANGE "The specified bit position (%d) is invalid.  Position must be between 0 and %d."
+#define PS_ERRORTEXT_psBitSet_OPERATOR_NULL "Specified operator is NULL.  Must specify desired operator."
+#define PS_ERRORTEXT_psBitSet_OPERATOR_INVALID "Specified operator, %s, is invalid.  Valid operators are AND, OR, and XOR."
+#define PS_ERRORTEXT_psBitSet_FIRST_OPERAND_NULL "First psBitSet operand can not be NULL."
+#define PS_ERRORTEXT_psBitSet_SECOND_OPERAND_NULL "Second psBitSet operand can not be NULL."
+#define PS_ERRORTEXT_psBitSet_OPERANDS_SIZE_DIFFER "The psBitSet operand must be the same size."
+#define PS_ERRORTEXT_psBitSet_NOT_OP_FAILED "Could not perform NOT operation."
+#define PS_ERRORTEXT_psBitSet_OPERAND_NULL "Operand can not be NULL."
+#define PS_ERRORTEXT_psScalar_UNSUPPORTED_TYPE "Specified datatype (%d) is unsupported by psScalar."
+#define PS_ERRORTEXT_psScalar_COPY_NULL "Can not copy a NULL psScalar."
 //~End
 
Index: trunk/psLib/src/collections/psList.c
===================================================================
--- trunk/psLib/src/collections/psList.c	(revision 1787)
+++ trunk/psLib/src/collections/psList.c	(revision 1807)
@@ -1,3 +1,2 @@
-
 /** @file psList.c
  *  @brief Support for doubly linked lists
@@ -7,6 +6,6 @@
  *  @author Robert Daniel DeSonia, MHPCC
  *
- *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-09-09 02:23:27 $
+ *  @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-09-14 20:01:52 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -24,4 +23,6 @@
 #include "psTrace.h"
 #include "psLogMsg.h"
+
+#include "psCollectionsErrors.h"
 
 #define ITER_INIT_HEAD ((void *)1)         // next iteration should return head
Index: trunk/psLib/src/collections/psScalar.c
===================================================================
--- trunk/psLib/src/collections/psScalar.c	(revision 1787)
+++ trunk/psLib/src/collections/psScalar.c	(revision 1807)
@@ -1,3 +1,2 @@
-
 /** @file  psScalar.c
  *
@@ -9,15 +8,10 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-08-27 23:34:05 $
+ *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-09-14 20:01:52 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  */
 
-/******************************************************************************/
-
-/*  INCLUDE FILES                                                             */
-
-/******************************************************************************/
 #include "psMemory.h"
 #include "psError.h"
@@ -26,49 +20,6 @@
 #include "psAbort.h"
 
-/******************************************************************************/
+#include "psCollectionsErrors.h"
 
-/*  DEFINE STATEMENTS                                                         */
-
-/******************************************************************************/
-
-// None
-
-/******************************************************************************/
-
-/*  TYPE DEFINITIONS                                                          */
-
-/******************************************************************************/
-
-// None
-
-/*****************************************************************************/
-
-/*  GLOBAL VARIABLES                                                         */
-
-/*****************************************************************************/
-
-// None
-
-/*****************************************************************************/
-
-/*  FILE STATIC VARIABLES                                                    */
-
-/*****************************************************************************/
-
-// None
-
-/*****************************************************************************/
-
-/*  FUNCTION IMPLEMENTATION - LOCAL                                          */
-
-/*****************************************************************************/
-
-// None
-
-/*****************************************************************************/
-
-/* FUNCTION IMPLEMENTATION - PUBLIC                                          */
-
-/*****************************************************************************/
 psScalar* psScalarAlloc(psC64 value, psElemType dataType)
 {
@@ -77,7 +28,4 @@
     // Create scalar
     scalar = (psScalar* ) psAlloc(sizeof(psScalar));
-    if (scalar == NULL) {
-        psAbort(__func__, " : Line %d - Failed to allocate memory", __LINE__);
-    }
 
     scalar->type.dimen = PS_DIMEN_SCALAR;
@@ -122,5 +70,8 @@
         break;
     default:
-        psError(__func__, ": Line %d - Invalid PS_TYPE: %d", __LINE__, dataType);
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psScalarAlloc",
+                   PS_ERR_BAD_PARAMETER_TYPE, true,
+                   PS_ERRORTEXT_psScalar_UNSUPPORTED_TYPE,
+                   dataType);
     }
 
@@ -134,5 +85,8 @@
 
     if (scalar == NULL) {
-        psError(__func__, "Null scalar not allowed");
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psScalarCopy",
+                   PS_ERR_BAD_PARAMETER_NULL, true,
+                   PS_ERRORTEXT_psScalar_COPY_NULL);
+        return NULL;
     }
 
@@ -176,5 +130,8 @@
         break;
     default:
-        psError(__func__, ": Line %d - Invalid PS_TYPE: %d", __LINE__, dataType);
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psScalarCopy",
+                   PS_ERR_BAD_PARAMETER_TYPE, true,
+                   PS_ERRORTEXT_psScalar_UNSUPPORTED_TYPE,
+                   dataType);
     }
 
Index: trunk/psLib/src/collections/psVector.c
===================================================================
--- trunk/psLib/src/collections/psVector.c	(revision 1787)
+++ trunk/psLib/src/collections/psVector.c	(revision 1807)
@@ -10,6 +10,6 @@
 *  @author Robert DeSonia, MHPCC
 *
-*  @version $Revision: 1.23 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2004-09-09 21:59:03 $
+*  @version $Revision: 1.24 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2004-09-14 20:01:52 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -25,7 +25,18 @@
 #include "psLogMsg.h"
 #include "psCompare.h"
+
 #include "psCollectionsErrors.h"
 
 static void vectorFree(psVector* restrict psVec);
+
+
+static void vectorFree(psVector* restrict psVec)
+{
+    if (psVec == NULL) {
+        return;
+    }
+
+    psFree(psVec->data.V);
+}
 
 // FUNCTION IMPLEMENTATION - PUBLIC
@@ -35,10 +46,4 @@
     psVector* psVec = NULL;
     int elementSize = 0;
-
-    // Invalid nalloc
-    if (nalloc < 1) {
-        psError(__func__, "Invalid value for nalloc. nalloc: %d\n", nalloc);
-        return NULL;
-    }
 
     elementSize = PSELEMTYPE_SIZEOF(elemType);
@@ -64,12 +69,8 @@
     psElemType elemType;
 
-    // Invalid nalloc
-    if (nalloc < 1) {
-        psError(__func__, "Invalid value for realloc (%d)\n", nalloc);
-        return NULL;
-    }
-
     if (in == NULL) {
-        psError(__func__, "Null input vector\n");
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psVectorRealloc",
+                   PS_ERR_BAD_PARAMETER_NULL, true,
+                   PS_ERRORTEXT_psVector_REALLOC_NULL);
         return NULL;
     } else if (in->nalloc != nalloc) {     // No need to realloc to same size
@@ -101,10 +102,4 @@
         return in;
     }
-    // Invalid nalloc
-    if (nalloc < 1) {
-        psError(__func__, "Invalid value for nalloc (%d)\n", nalloc);
-        psFree(in);
-        return NULL;
-    }
 
     in->data.V = psRealloc(in->data.V, nalloc * PSELEMTYPE_SIZEOF(type));
@@ -119,6 +114,5 @@
 psVector* psVectorSort(psVector* restrict outVector, const psVector* restrict inVector)
 {
-    int inN = 0;
-    int outN = 0;
+    int N = 0;
     int elSize = 0;
     void *inVec = NULL;
@@ -127,79 +121,76 @@
 
     if (inVector == NULL) {
-        psError(__func__, " : Line %d - Null input vector\n", __LINE__);
-        return outVector;
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psVectorSort",
+                   PS_ERR_BAD_PARAMETER_NULL, true,
+                   PS_ERRORTEXT_psVector_SORT_NULL);
+        psFree(outVector);
+        return NULL;
     }
 
     inType = inVector->type.type;
-    inN = inVector->n;
+    N = inVector->n;
     inVec = inVector->data.V;
     elSize = PSELEMTYPE_SIZEOF(inType);
 
     if (outVector == NULL) {
-        outVector = psVectorAlloc(inN, inType);
-        outVector->n = inVector->n;
-    }
-
-    outN = outVector->n;
+        outVector = psVectorAlloc(N, inType);
+    }
+
+    // check to see if output vector needs to be resized/retyped
+    if ( (N > outVector->nalloc) ||
+            (inType != outVector->type.type) ) {
+        // reshape the output vector to match the input vector's size/type.
+        outVector = psVectorRecycle(outVector,N,inType);
+    }
+    outVector->n = N;
     outVec = outVector->data.V;
 
-    if (inN != outN) {
-        psError(__func__, " : Line %d - Input and output vector sizes are not equal: in=%d out=%d\n",
-                __LINE__, inN, outN);
+    if (N == 0) {
+        // no need to sort anything, as there are no elements in input vector.
         return outVector;
     }
 
-    if (inType != outVector->type.type) {
-        psError(__func__, " : Line %d - Input and output vectors are not same type: in=%d out=%d\n", __LINE__,
-                inType, outVector->type.type);
-        return outVector;
-    }
-
-    if (inN == 0) {
-        psError(__func__, " : Line %d - No elements in use for input vector\n", __LINE__);
-        return outVector;
-    }
-
-    if (outN == 0) {
-        psError(__func__, " : Line %d - No elements in use for output vector\n", __LINE__);
-        return outVector;
-    }
-    // Copy input vector values into output vector
-    memcpy(outVec, inVec, elSize * outN);
+    // Copy input vector values into output vector if not in-place sorting
+    if (inVector != outVector) {
+        memcpy(outVec, inVec, elSize * N);
+    }
 
     // Sort output vector
     switch (inType) {
     case PS_TYPE_U8:
-        qsort(outVec, inN, elSize, psCompareU8);
+        qsort(outVec, N, elSize, psCompareU8);
         break;
     case PS_TYPE_U16:
-        qsort(outVec, inN, elSize, psCompareU16);
+        qsort(outVec, N, elSize, psCompareU16);
         break;
     case PS_TYPE_U32:
-        qsort(outVec, inN, elSize, psCompareU32);
+        qsort(outVec, N, elSize, psCompareU32);
         break;
     case PS_TYPE_U64:
-        qsort(outVec, inN, elSize, psCompareU64);
+        qsort(outVec, N, elSize, psCompareU64);
         break;
     case PS_TYPE_S8:
-        qsort(outVec, inN, elSize, psCompareS8);
+        qsort(outVec, N, elSize, psCompareS8);
         break;
     case PS_TYPE_S16:
-        qsort(outVec, inN, elSize, psCompareS16);
+        qsort(outVec, N, elSize, psCompareS16);
         break;
     case PS_TYPE_S32:
-        qsort(outVec, inN, elSize, psCompareS32);
+        qsort(outVec, N, elSize, psCompareS32);
         break;
     case PS_TYPE_S64:
-        qsort(outVec, inN, elSize, psCompareS64);
+        qsort(outVec, N, elSize, psCompareS64);
         break;
     case PS_TYPE_F32:
-        qsort(outVec, inN, elSize, psCompareF32);
+        qsort(outVec, N, elSize, psCompareF32);
         break;
     case PS_TYPE_F64:
-        qsort(outVec, inN, elSize, psCompareF64);
+        qsort(outVec, N, elSize, psCompareF64);
         break;
     default:
-        psError(__func__, " : Line %d - Invalid psType\n", __LINE__);
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psVectorSort",
+                   PS_ERR_BAD_PARAMETER_TYPE, true,
+                   PS_ERRORTEXT_psVector_UNSUPPORTED_TYPE,
+                   inType);
     }
 
@@ -207,94 +198,99 @@
 }
 
-#define SORT_INDICES(TYPE)                                                                                   \
-for(i=0; i<inN; i++) {                                                                                       \
-    for(j=0; j<inN; j++) {                                                                                   \
-        diff = fabs((double)tmpVector->data.TYPE[i] - inVec[j]);                                             \
-        if(diff < FLT_EPSILON) {                                                                             \
-            outVec[i] = j;                                                                                   \
-            break;                                                                                           \
-        }                                                                                                    \
-    }                                                                                                        \
-}
-
 psVector* psVectorSortIndex(psVector* restrict outVector, const psVector* restrict inVector)
 {
-    int inN = 0;
-    int outN = 0;
-    int i = 0;
-    int j = 0;
-    float *inVec = NULL;
-    int *outVec = NULL;
-    double diff = 0.0f;
+    int N = 0;
     psVector* tmpVector = NULL;
     psElemType inType = 0;
+    psU32* outVec;
 
     if (inVector == NULL) {
-        psError(__func__, " : Line %d - Null input vector\n", __LINE__);
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psVectorSortIndex",
+                   PS_ERR_BAD_PARAMETER_NULL, true,
+                   PS_ERRORTEXT_psVector_SORT_NULL);
+        psFree(outVector);
+        return NULL;
+    }
+
+    N = inVector->n;
+
+    if (outVector == NULL) {
+        outVector = psVectorAlloc(N, PS_TYPE_U32);
+    }
+
+    // check to see if output vector needs to be resized/retyped
+    if ( (N > outVector->nalloc) ||
+            (outVector->type.type != PS_TYPE_U32) ) {
+        // reshape the output vector to match the input vector's size/type.
+        outVector = psVectorRecycle(outVector,N,PS_TYPE_U32);
+    }
+    outVector->n = N;
+    outVec = outVector->data.U32;
+
+    if (N == 0) {
+        // no need to sort anything, as there are no elements in input vector.
         return outVector;
     }
 
-    inN = inVector->n;
-    inVec = inVector->data.V;
-    inType = inVector->type.type;
-
-    if (outVector == NULL) {
-        outVector = psVectorAlloc(inN, PS_TYPE_U32);
-        outVector->n = inN;
-    }
-
-    outN = outVector->n;
-    outVec = outVector->data.V;
-
-    if (inN != outN) {
-        psError(__func__, " : Line %d - Input and output vector sizes are not equal: in=%d out=%d\n",
-                __LINE__, inN, outN);
-        return outVector;
-    }
-
-    if (outVector->type.type != PS_TYPE_U32) {
-        psError(__func__, " : Line %d - Output vector is not of type U32: out=%d\n",
-                __LINE__, outVector->type.type);
-        return outVector;
-    }
-
-    tmpVector = psVectorAlloc(inN, inType);
-    tmpVector->n = inN;
     tmpVector = psVectorSort(tmpVector, inVector);
+
+    #define SORT_INDICES(TYPE,absfcn,maxError) {                              \
+        ps##TYPE* inVec = inVector->data.TYPE;                                \
+        ps##TYPE* tmpVec = tmpVector->data.TYPE;                              \
+        ps##TYPE  diff;                                                       \
+        for(int i=0; i<N; i++) {                                              \
+            for(int j=0; j<N; j++) {                                          \
+                diff = absfcn(tmpVec[i] - inVec[j]);                          \
+                if(diff < maxError) {                                         \
+                    outVec[i] = j;                                            \
+                    break;                                                    \
+                }                                                             \
+            }                                                                 \
+        }                                                                     \
+    }
 
     // Sort output vector
     switch (inType) {
     case PS_TYPE_U8:
-        SORT_INDICES(U8);
+        SORT_INDICES(U8,/* no absfcn needed */,1);
         break;
     case PS_TYPE_U16:
-        SORT_INDICES(U16);
+        SORT_INDICES(U16,/* no absfcn needed */,1);
         break;
     case PS_TYPE_U32:
-        SORT_INDICES(U32);
+        SORT_INDICES(U32,/* no absfcn needed */,1);
         break;
     case PS_TYPE_U64:
-        SORT_INDICES(U64);
+        SORT_INDICES(U64,/* no absfcn needed */,1);
         break;
     case PS_TYPE_S8:
-        SORT_INDICES(S8);
+        SORT_INDICES(S8,/* no absfcn needed */,1);
         break;
     case PS_TYPE_S16:
-        SORT_INDICES(S16);
+        SORT_INDICES(S16,/* no absfcn needed */,1);
         break;
     case PS_TYPE_S32:
-        SORT_INDICES(S32);
+        SORT_INDICES(S32,/* no absfcn needed */,1);
         break;
     case PS_TYPE_S64:
-        SORT_INDICES(S64);
+        SORT_INDICES(S64,/* no absfcn needed */,1);
         break;
     case PS_TYPE_F32:
-        SORT_INDICES(F32);
+        SORT_INDICES(F32,fabsf,FLT_EPSILON);
         break;
     case PS_TYPE_F64:
-        SORT_INDICES(F64);
+        SORT_INDICES(F64,fabs,DBL_EPSILON);
+        break;
+    case PS_TYPE_C32:
+        SORT_INDICES(F64,cabsf,FLT_EPSILON);
+        break;
+    case PS_TYPE_C64:
+        SORT_INDICES(F64,cabs,DBL_EPSILON);
         break;
     default:
-        psError(__func__, " : Line %d - Invalid psType\n", __LINE__);
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psVectorSortIndex",
+                   PS_ERR_BAD_PARAMETER_TYPE, true,
+                   PS_ERRORTEXT_psVector_UNSUPPORTED_TYPE,
+                   inType);
     }
 
@@ -304,11 +300,2 @@
     return outVector;
 }
-
-static void vectorFree(psVector* restrict psVec)
-{
-    if (psVec == NULL) {
-        return;
-    }
-
-    psFree(psVec->data.V);
-}
