Index: /trunk/psLib/src/collections/psArray.c
===================================================================
--- /trunk/psLib/src/collections/psArray.c	(revision 1919)
+++ /trunk/psLib/src/collections/psArray.c	(revision 1920)
@@ -9,6 +9,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-09-14 20:01:52 $
+ *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-09-28 23:26:48 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -21,4 +21,5 @@
 /******************************************************************************/
 #include<stdlib.h>                         // for qsort, etc.
+#include<string.h>
 
 #include "psMemory.h"
@@ -58,5 +59,5 @@
 }
 
-psArray* psArrayRealloc(unsigned int nalloc, psArray* restrict in)
+psArray* psArrayRealloc(psArray* restrict in, unsigned int nalloc)
 {
     if (in == NULL) {
@@ -88,4 +89,27 @@
 }
 
+bool psArrayRemove(psArray* psArr,
+                   psPTR data)
+{
+    bool success = false;
+
+    if (psArr == NULL) {
+        return success;
+    }
+
+    int n = psArr->n;
+    psPTR* psArrData = psArr->data;
+    for (int i = n-1; i<0; i--) {
+        if (psArrData[i] == data) {
+            memmove(psArrData[i],psArrData[i+1],(n-i-1)*sizeof(psPTR));
+            n--;
+            success = true;
+        }
+    }
+    psArr->n = n; // reset the array size to indicate the removed item(s)
+
+    return success;
+}
+
 void psArrayElementFree(psArray* restrict psArr)
 {
Index: /trunk/psLib/src/collections/psArray.h
===================================================================
--- /trunk/psLib/src/collections/psArray.h	(revision 1919)
+++ /trunk/psLib/src/collections/psArray.h	(revision 1920)
@@ -12,6 +12,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-08-11 19:47:31 $
+ *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-09-28 23:26:48 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -20,4 +20,6 @@
 #ifndef PS_ARRAY_H
 #define PS_ARRAY_H
+
+#include<stdbool.h>
 
 #include "psType.h"
@@ -67,6 +69,19 @@
  */
 psArray* psArrayRealloc(
-    unsigned int nalloc,               ///< Total number of elements to make available.
-    psArray* restrict psArr            ///< array to reallocate.
+    psArray* restrict psArr,           ///< array to reallocate.
+    unsigned int nalloc                ///< Total number of elements to make available.
+);
+
+/** Remove an element from the array
+ *
+ *  Finds and removes the specified data pointer from the list.  
+ *
+ * @return bool:  TRUE if the specified data pointer was found and removed, 
+ *                otherwise FALSE.
+ *
+ */
+bool psArrayRemove(
+    psArray* psArr,                    ///< array to operate on
+    psPTR data                         ///< the data pointer to remove from psArray
 );
 
Index: /trunk/psLib/src/collections/psVector.c
===================================================================
--- /trunk/psLib/src/collections/psVector.c	(revision 1919)
+++ /trunk/psLib/src/collections/psVector.c	(revision 1920)
@@ -10,6 +10,6 @@
 *  @author Robert DeSonia, MHPCC
 *
-*  @version $Revision: 1.26 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2004-09-25 02:06:12 $
+*  @version $Revision: 1.27 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2004-09-28 23:26:48 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -64,5 +64,5 @@
 }
 
-psVector* psVectorRealloc(unsigned int nalloc, psVector* restrict in)
+psVector* psVectorRealloc(psVector* restrict in, unsigned int nalloc)
 {
     int elementSize = 0;
Index: /trunk/psLib/src/collections/psVector.h
===================================================================
--- /trunk/psLib/src/collections/psVector.h	(revision 1919)
+++ /trunk/psLib/src/collections/psVector.h	(revision 1920)
@@ -12,6 +12,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.21 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-09-25 02:06:12 $
+ *  @version $Revision: 1.22 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-09-28 23:26:48 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -83,6 +83,6 @@
  */
 psVector* psVectorRealloc(
-    unsigned int nalloc,               ///< Total number of elements to make available.
-    psVector* restrict psVec           ///< Vector to reallocate.
+    psVector* restrict psVec,          ///< Vector to reallocate.
+    unsigned int nalloc                ///< Total number of elements to make available.
 );
 
Index: /trunk/psLib/src/image/psImage.c
===================================================================
--- /trunk/psLib/src/image/psImage.c	(revision 1919)
+++ /trunk/psLib/src/image/psImage.c	(revision 1920)
@@ -10,6 +10,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.46 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-09-25 02:06:12 $
+ *  @version $Revision: 1.47 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-09-28 23:26:48 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -68,5 +68,4 @@
     *(psElemType* ) & image->type.type = type;
     image->parent = NULL;
-    image->nChildren = 0;
     image->children = NULL;
 
@@ -81,6 +80,5 @@
 
     if (image->type.type == PS_TYPE_PTR) {
-        // 2-D array of pointers -- must
-        // dereference
+        // 2-D array of pointers -- must dereference elements
         unsigned int oldNumRows = image->numRows;
         unsigned int oldNumCols = image->numCols;
@@ -95,9 +93,13 @@
     }
 
+    if (image->parent != NULL) {
+        psArrayRemove(image->parent->children,image);
+        image->parent = NULL;
+    }
+
     psImageFreeChildren(image);
 
     psFree(image->rawDataBuffer);
     psFree(image->data.V);
-    image->data.V = NULL;
 }
 
@@ -164,7 +166,4 @@
 int psImageFreeChildren(psImage* image)
 {
-    int i = 0;
-    int nChildren = 0;
-    psImage* *children = NULL;
     int numFreed = 0;
 
@@ -173,17 +172,17 @@
     }
 
-    nChildren = image->nChildren;
-    children = image->children;
-
-    for (i = 0; i < nChildren; i++) {
-        if (children[i] != NULL) {
-            numFreed++;
-            psFree(children[i]);
+    if (image->children != NULL) {
+        psImage** children = (psImage**)image->children->data;
+        numFreed = image->children->n;
+
+        // orphan the children first
+        // (so psFree doesn't try to modify the parent's children array while I'm using it)
+        for (int i=0;i<numFreed;i++) {
+            children[i]->parent = NULL;
         }
-    }
-    psFree(children);
-
-    image->nChildren = 0;
-    image->children = NULL;
+
+        psFree(image->children);
+        image->children = NULL;
+    }
 
     return numFreed;
Index: /trunk/psLib/src/image/psImage.h
===================================================================
--- /trunk/psLib/src/image/psImage.h	(revision 1919)
+++ /trunk/psLib/src/image/psImage.h	(revision 1920)
@@ -11,6 +11,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.37 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-09-25 02:06:12 $
+ *  @version $Revision: 1.38 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-09-28 23:26:48 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -22,4 +22,5 @@
 
 #include "psType.h"
+#include "psArray.h"
 
 /// @addtogroup Image
@@ -67,6 +68,5 @@
     } data;                            ///< Union for data types.
     const struct psImage* parent;      ///< Parent, if a subimage.
-    int nChildren;                     ///< Number of subimages.
-    struct psImage* *children;         ///< Children of this region.
+    psArray* children;                 ///< Children of this region.
 
     void* rawDataBuffer;
Index: /trunk/psLib/src/image/psImageExtraction.c
===================================================================
--- /trunk/psLib/src/image/psImageExtraction.c	(revision 1919)
+++ /trunk/psLib/src/image/psImageExtraction.c	(revision 1920)
@@ -1,19 +1,18 @@
-
 /** @file  psImageExtraction.c
-*
-*  @brief Contains basic image extraction operations, as specified in the 
-*         PSLIB SDRS sections "Image Pixel Extractions" and "Image Structure
-*         Manipulation".
-*
-*  @ingroup Image
-*
-*  @author Robert DeSonia, MHPCC
-*
-*  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2004-09-28 02:27:58 $
-*
-*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
-*
-*/
+ *
+ *  @brief Contains basic image extraction operations, as specified in the 
+ *         PSLIB SDRS sections "Image Pixel Extractions" and "Image Structure
+ *         Manipulation".
+ *
+ *  @ingroup Image
+ *
+ *  @author Robert DeSonia, MHPCC
+ *
+ *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-09-28 23:26:48 $
+ *
+ *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
+ *
+ */
 
 #include <string.h>
@@ -25,11 +24,12 @@
 #include "psImageErrors.h"
 
-psImage* psImageSubset(psImage* image,
-                       int col0,
-                       int row0,
-                       int col1,
-                       int row1)
+
+psImage* imageSubset(psImage* out,
+                     psImage* image,
+                     int col0,
+                     int row0,
+                     int col1,
+                     int row1)
 {
-    psImage* out;
     unsigned int elementSize;          // size of image element in bytes
     unsigned int inputColOffset;       // offset in bytes to first subset pixel in input row
@@ -70,9 +70,33 @@
     }
     int numRows = row1-row0;
-    int numCols = col1-row0;
+    int numCols = col1-col0;
 
     elementSize = PSELEMTYPE_SIZEOF(image->type.type);
 
-    out = psAlloc(sizeof(psImage));
+    if (image->parent != NULL) { // if this is a child, we need to start working with parent.
+        col0 += image->col0;
+        col1 += image->col0;
+        row0 += image->row0;
+        row1 += image->row0;
+        image = (psImage*)image->parent;
+    }
+
+    // increment the raw data buffer before freeing anything in the 'out'
+    void* rawData = psMemIncrRefCounter(image->rawDataBuffer);
+
+    if (out != NULL) {
+        // if a child, need to orphan (disassociate from parent) first
+        if (out->parent != NULL) {
+            psArrayRemove(out->parent->children,out); // remove from parent's knowledge
+            out->parent = NULL; // break link to parent
+        }
+
+        psFree(out->rawDataBuffer); // free the previous data reference
+    } else {
+        out = psAlloc(sizeof(psImage));
+        out->data.V = NULL;
+    }
+
+    out->data.V = psRealloc(out->data.V,sizeof(void*)*numRows); // resize row pointer array
     *(psType*)&out->type = image->type;
     *(unsigned int*)&out->numCols = numCols;
@@ -81,8 +105,6 @@
     *(int*)&out->col0 = col0;
     out->parent = image;
-    out->nChildren = 0;
     out->children = NULL;
-    out->rawDataBuffer = psMemIncrRefCounter(image->rawDataBuffer);
-    out->data.V = psAlloc(sizeof(void*)*numRows);
+    out->rawDataBuffer = rawData;
 
     // set the new psImage's deallocator to the same as the input image
@@ -94,11 +116,29 @@
     }
 
-    // add output image as a child of the input
-    // image.
-    image->nChildren++;
-    image->children = (psImage**) psRealloc(image->children, image->nChildren * sizeof(psImage* ));
-    image->children[image->nChildren - 1] = out;
+    // add output image as a child of the input image.
+    int n = 0;
+    psArray* children = image->children;
+    if (children == NULL) {
+        children = psArrayAlloc(16); // start with a reasonable size for growth
+    } else if (children->nalloc == children->n) { // full?
+        n = children->n;
+        children = psArrayRealloc(children,n*2); // double the array size
+    } else {
+        n = children->n;
+    }
+    children->data[n] = out;
+    children->n = n+1;
+    image->children = children; // push back any change (esp. if children==NULL before)
 
     return (out);
+}
+
+psImage* psImageSubset(psImage* image,
+                       int col0,
+                       int row0,
+                       int col1,
+                       int row1)
+{
+    return imageSubset(NULL,image,col0,row0,col1,row1);
 }
 
@@ -126,8 +166,8 @@
         return NULL;
     }
-    return psImageSubset(image,x1,y1,x2,y2);
+    return imageSubset(NULL,image,x1,y1,x2,y2);
 }
 
-psImage* psImageTrim(psImage* image, int x0, int x1, int y0, int y1)
+psImage* psImageTrim(psImage* image, int x0, int y0, int x1, int y1)
 {
     if (image == NULL || image->data.V == NULL) {
@@ -139,8 +179,10 @@
 
     if (image->parent != NULL) {
-        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageTrim",
-                   PS_ERR_BAD_PARAMETER_NULL, true,
-                   PS_ERRORTEXT_psImage_NOT_PARENT);
-        return NULL;
+        return imageSubset(image,
+                           (psImage*)image->parent,
+                           x0+image->col0,
+                           y0+image->row0,
+                           x1+image->col0,
+                           y1+image->row0);
     }
 
@@ -904,7 +946,7 @@
                     int n = buffer[r]->n;
                     if (n == buffer[r]->nalloc) { // in case buffers already full, expand
-                        buffer[r] = psVectorRealloc(n*2, buffer[r]);
+                        buffer[r] = psVectorRealloc(buffer[r], n*2);
                         if (bufferMask[r] != NULL) {
-                            bufferMask[r] = psVectorRealloc(n*2, bufferMask[r]);
+                            bufferMask[r] = psVectorRealloc(bufferMask[r], n*2);
                         }
                     }
Index: /trunk/psLib/src/image/psImageExtraction.h
===================================================================
--- /trunk/psLib/src/image/psImageExtraction.h	(revision 1919)
+++ /trunk/psLib/src/image/psImageExtraction.h	(revision 1920)
@@ -10,6 +10,6 @@
 *  @author Robert DeSonia, MHPCC
 *
-*  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2004-09-28 02:27:58 $
+*  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2004-09-28 23:26:48 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -76,9 +76,15 @@
  *
  *  Trim the specified image in-place, which involves shuffling the pixels 
- *  around in memory.  The pixels in the region [x0:x1,y0:y1] (inclusive)
- *  shall consist the output image.
- *
- *  N.b., An image that has a parent image will be orphaned from the parent 
- *  upon trimming.  Any children of the trimmed image will also be obliterated, 
+ *  around in memory.  The pixels in the region [col0:col1,row0:row1] shall consist
+ *  the output image.  The column col1 and row row1 are NOT included in the range.
+ *  In the event that x1 or y1 are non-positive, they shall be interpreted as
+ *  being relative to the size of the parent image in that dimension.
+ *
+ *  If the entire specified subimage is not contained within the parent 
+ *  image, an error results and the return value will be NULL.
+ *
+ *  N.B. If the input psImage is a child of another psImage, no pixel data 
+ *  will be trimmed, rather it equivalent to calling psImageSubset.  If the input 
+ *  psImage is, however, a parent psImage, any children will be obliterated,
  *  i.e., freed from memory.
  *
@@ -87,8 +93,8 @@
 psImage* psImageTrim(
     psImage* image,                    ///< image to trim
-    int x0,                            ///< column of trim region's left boundary
-    int x1,                            ///< column of trim region's right boundary
-    int y0,                            ///< row of trim region's lower boundary
-    int y1                             ///< row of trim region's upper boundary
+    int col0,                          ///< column of trim region's left boundary
+    int row0,                          ///< row of trim region's lower boundary
+    int col1,                          ///< column of trim region's right boundary
+    int row1                           ///< row of trim region's upper boundary
 );
 
Index: /trunk/psLib/src/mathtypes/psImage.c
===================================================================
--- /trunk/psLib/src/mathtypes/psImage.c	(revision 1919)
+++ /trunk/psLib/src/mathtypes/psImage.c	(revision 1920)
@@ -10,6 +10,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.46 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-09-25 02:06:12 $
+ *  @version $Revision: 1.47 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-09-28 23:26:48 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -68,5 +68,4 @@
     *(psElemType* ) & image->type.type = type;
     image->parent = NULL;
-    image->nChildren = 0;
     image->children = NULL;
 
@@ -81,6 +80,5 @@
 
     if (image->type.type == PS_TYPE_PTR) {
-        // 2-D array of pointers -- must
-        // dereference
+        // 2-D array of pointers -- must dereference elements
         unsigned int oldNumRows = image->numRows;
         unsigned int oldNumCols = image->numCols;
@@ -95,9 +93,13 @@
     }
 
+    if (image->parent != NULL) {
+        psArrayRemove(image->parent->children,image);
+        image->parent = NULL;
+    }
+
     psImageFreeChildren(image);
 
     psFree(image->rawDataBuffer);
     psFree(image->data.V);
-    image->data.V = NULL;
 }
 
@@ -164,7 +166,4 @@
 int psImageFreeChildren(psImage* image)
 {
-    int i = 0;
-    int nChildren = 0;
-    psImage* *children = NULL;
     int numFreed = 0;
 
@@ -173,17 +172,17 @@
     }
 
-    nChildren = image->nChildren;
-    children = image->children;
-
-    for (i = 0; i < nChildren; i++) {
-        if (children[i] != NULL) {
-            numFreed++;
-            psFree(children[i]);
+    if (image->children != NULL) {
+        psImage** children = (psImage**)image->children->data;
+        numFreed = image->children->n;
+
+        // orphan the children first
+        // (so psFree doesn't try to modify the parent's children array while I'm using it)
+        for (int i=0;i<numFreed;i++) {
+            children[i]->parent = NULL;
         }
-    }
-    psFree(children);
-
-    image->nChildren = 0;
-    image->children = NULL;
+
+        psFree(image->children);
+        image->children = NULL;
+    }
 
     return numFreed;
Index: /trunk/psLib/src/mathtypes/psImage.h
===================================================================
--- /trunk/psLib/src/mathtypes/psImage.h	(revision 1919)
+++ /trunk/psLib/src/mathtypes/psImage.h	(revision 1920)
@@ -11,6 +11,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.37 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-09-25 02:06:12 $
+ *  @version $Revision: 1.38 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-09-28 23:26:48 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -22,4 +22,5 @@
 
 #include "psType.h"
+#include "psArray.h"
 
 /// @addtogroup Image
@@ -67,6 +68,5 @@
     } data;                            ///< Union for data types.
     const struct psImage* parent;      ///< Parent, if a subimage.
-    int nChildren;                     ///< Number of subimages.
-    struct psImage* *children;         ///< Children of this region.
+    psArray* children;                 ///< Children of this region.
 
     void* rawDataBuffer;
Index: /trunk/psLib/src/mathtypes/psVector.c
===================================================================
--- /trunk/psLib/src/mathtypes/psVector.c	(revision 1919)
+++ /trunk/psLib/src/mathtypes/psVector.c	(revision 1920)
@@ -10,6 +10,6 @@
 *  @author Robert DeSonia, MHPCC
 *
-*  @version $Revision: 1.26 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2004-09-25 02:06:12 $
+*  @version $Revision: 1.27 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2004-09-28 23:26:48 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -64,5 +64,5 @@
 }
 
-psVector* psVectorRealloc(unsigned int nalloc, psVector* restrict in)
+psVector* psVectorRealloc(psVector* restrict in, unsigned int nalloc)
 {
     int elementSize = 0;
Index: /trunk/psLib/src/mathtypes/psVector.h
===================================================================
--- /trunk/psLib/src/mathtypes/psVector.h	(revision 1919)
+++ /trunk/psLib/src/mathtypes/psVector.h	(revision 1920)
@@ -12,6 +12,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.21 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-09-25 02:06:12 $
+ *  @version $Revision: 1.22 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-09-28 23:26:48 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -83,6 +83,6 @@
  */
 psVector* psVectorRealloc(
-    unsigned int nalloc,               ///< Total number of elements to make available.
-    psVector* restrict psVec           ///< Vector to reallocate.
+    psVector* restrict psVec,          ///< Vector to reallocate.
+    unsigned int nalloc                ///< Total number of elements to make available.
 );
 
Index: /trunk/psLib/src/types/psArray.c
===================================================================
--- /trunk/psLib/src/types/psArray.c	(revision 1919)
+++ /trunk/psLib/src/types/psArray.c	(revision 1920)
@@ -9,6 +9,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-09-14 20:01:52 $
+ *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-09-28 23:26:48 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -21,4 +21,5 @@
 /******************************************************************************/
 #include<stdlib.h>                         // for qsort, etc.
+#include<string.h>
 
 #include "psMemory.h"
@@ -58,5 +59,5 @@
 }
 
-psArray* psArrayRealloc(unsigned int nalloc, psArray* restrict in)
+psArray* psArrayRealloc(psArray* restrict in, unsigned int nalloc)
 {
     if (in == NULL) {
@@ -88,4 +89,27 @@
 }
 
+bool psArrayRemove(psArray* psArr,
+                   psPTR data)
+{
+    bool success = false;
+
+    if (psArr == NULL) {
+        return success;
+    }
+
+    int n = psArr->n;
+    psPTR* psArrData = psArr->data;
+    for (int i = n-1; i<0; i--) {
+        if (psArrData[i] == data) {
+            memmove(psArrData[i],psArrData[i+1],(n-i-1)*sizeof(psPTR));
+            n--;
+            success = true;
+        }
+    }
+    psArr->n = n; // reset the array size to indicate the removed item(s)
+
+    return success;
+}
+
 void psArrayElementFree(psArray* restrict psArr)
 {
Index: /trunk/psLib/src/types/psArray.h
===================================================================
--- /trunk/psLib/src/types/psArray.h	(revision 1919)
+++ /trunk/psLib/src/types/psArray.h	(revision 1920)
@@ -12,6 +12,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-08-11 19:47:31 $
+ *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-09-28 23:26:48 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -20,4 +20,6 @@
 #ifndef PS_ARRAY_H
 #define PS_ARRAY_H
+
+#include<stdbool.h>
 
 #include "psType.h"
@@ -67,6 +69,19 @@
  */
 psArray* psArrayRealloc(
-    unsigned int nalloc,               ///< Total number of elements to make available.
-    psArray* restrict psArr            ///< array to reallocate.
+    psArray* restrict psArr,           ///< array to reallocate.
+    unsigned int nalloc                ///< Total number of elements to make available.
+);
+
+/** Remove an element from the array
+ *
+ *  Finds and removes the specified data pointer from the list.  
+ *
+ * @return bool:  TRUE if the specified data pointer was found and removed, 
+ *                otherwise FALSE.
+ *
+ */
+bool psArrayRemove(
+    psArray* psArr,                    ///< array to operate on
+    psPTR data                         ///< the data pointer to remove from psArray
 );
 
Index: /trunk/psLib/test/collections/tst_psArray.c
===================================================================
--- /trunk/psLib/test/collections/tst_psArray.c	(revision 1919)
+++ /trunk/psLib/test/collections/tst_psArray.c	(revision 1920)
@@ -12,6 +12,6 @@
  *  @author  Ross Harman, MHPCC
  *
- *  @version $Revision: 1.2 $  $Name: not supported by cvs2svn $
- *  @date  $Date: 2004-08-06 22:34:05 $
+ *  @version $Revision: 1.3 $  $Name: not supported by cvs2svn $
+ *  @date  $Date: 2004-09-28 23:26:49 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -83,5 +83,5 @@
     // Test C - Reallocate void pointer array bigger
     printPositiveTestHeader(stdout,"psArray", "Reallocate void pointer array bigger");
-    psArr = psArrayRealloc(10, psArr);
+    psArr = psArrayRealloc(psArr,10);
     printf("Adding more elements to void pointer array...\n");
     for(int i = 5; i < 10; i++) {
@@ -117,5 +117,5 @@
     // Test D - Reallocate void pointer array smaller
     printPositiveTestHeader(stdout,"psArray","Reallocate void pointer array smaller");
-    psArr = psArrayRealloc(3, psArr);
+    psArr = psArrayRealloc(psArr,3);
     for(int i = 0; i < 3; i++) {
         testStruct *ts = (testStruct*)psArr->data[i];
Index: /trunk/psLib/test/collections/tst_psVector.c
===================================================================
--- /trunk/psLib/test/collections/tst_psVector.c	(revision 1919)
+++ /trunk/psLib/test/collections/tst_psVector.c	(revision 1920)
@@ -14,6 +14,6 @@
  *  @author  Ross Harman, MHPCC
  *
- *  @version $Revision: 1.3 $  $Name: not supported by cvs2svn $
- *  @date  $Date: 2004-08-06 22:34:05 $
+ *  @version $Revision: 1.4 $  $Name: not supported by cvs2svn $
+ *  @date  $Date: 2004-09-28 23:26:49 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -51,5 +51,5 @@
     // Test C - Reallocate S32 vector bigger
     printPositiveTestHeader(stdout,"psVector", "Reallocate S32 vector bigger");
-    psVec = psVectorRealloc(10, psVec);
+    psVec = psVectorRealloc(psVec,10);
     printf("Adding more elements to S32 vector...\n");
     for(int i = 5; i < 10; i++) {
@@ -65,5 +65,5 @@
     // Test D - Reallocate S32 vector smaller
     printPositiveTestHeader(stdout,"psVector","Reallocate S32 vector smaller");
-    psVec = psVectorRealloc(3, psVec);
+    psVec = psVectorRealloc(psVec,3);
     printf("Vector size = %d\n", psVec->nalloc);
     for(int i = 0; i < 3; i++) {
@@ -104,5 +104,5 @@
                             "Null input vector", 0);
     psLogMsg(__func__,PS_LOG_INFO, "Following should be an error message.");
-    psVectorRealloc(6, NULL);
+    psVectorRealloc(NULL,6);
     printFooter(stdout, "psVector", "Attempt to realloc a null S32 vector", true);
 
Index: /trunk/psLib/test/image/tst_psImage.c
===================================================================
--- /trunk/psLib/test/image/tst_psImage.c	(revision 1919)
+++ /trunk/psLib/test/image/tst_psImage.c	(revision 1920)
@@ -6,6 +6,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.25 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-09-02 21:17:03 $
+ *  @version $Revision: 1.26 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-09-28 23:26:49 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -26,22 +26,10 @@
 
 testDescription tests[] = {
-                              {
-                                  testImageAlloc,546,"psImageAlloc",0,false
-                              },
-                              {
-                                  testImageAlloc,548,"psImageFree",0,true
-                              },
-                              {
-                                  testImageSubset,547,"psImageSubset",0,false
-                              },
-                              {
-                                  testImageSubset,550,"psImageSubset",0,true
-                              },
-                              {
-                                  testImageCopy,551,"psImageCopy",0,false
-                              },
-                              {
-                                  NULL
-                              }
+                              {testImageAlloc,546,"psImageAlloc",0,false},
+                              {testImageAlloc,548,"psImageFree",0,true},
+                              {testImageSubset,547,"psImageSubset",0,false},
+                              {testImageSubset,550,"psImageSubset",0,true},
+                              {testImageCopy,551,"psImageCopy",0,false},
+                              {NULL}
                           };
 
@@ -119,12 +107,6 @@
             }
 
-            if (image->nChildren != 0) {
-                psError(__func__,"psImageAlloc returned non-zero number of children");
-                psFree(image);
-                return 6;
-            }
-
             if (image->children != NULL) {
-                psError(__func__,"psImageAlloc returned non-NULL children vector");
+                psError(__func__,"psImageAlloc returned non-NULL children array");
                 psFree(image);
                 return 7;
@@ -259,19 +241,13 @@
                 }
             }
-
-            // #548: Verify no memory leaks or corruption are detected after a valid psImage structure with no
-            // children is freed.
             psFree(image);
         }
     }
 
-    // #548: Verify program execution doesn't stop, if the input psImage structure pointer is null.
-    psFree(NULL);
-
     // #548: Verify no memory leaks or corruption are detected after a valid psImage structure with multiple
-    // children isfreed.
+    // children is freed.
     image = psImageAlloc(100,100,PS_TYPE_F32);
-    psImageSubset(image,50,50,0,0);
-    psImageSubset(image,50,50,20,20);
+    psImageSubset(image,50,0,70,20);
+    psImageSubset(image,70,20,90,40);
 
     psFree(image);
@@ -300,7 +276,22 @@
     memcpy(&preSubsetStruct,original,sizeof(psImage));
 
-    subset2 = psImageSubset(original,c/2,r/2,c/4,r/4);
-
-    subset3 = psImageSubset(original,c/2,r/2,0,0);
+    subset2 = psImageSubset(original,c/4,r/4,c/4+c/2,r/4+r/2);
+
+    subset3 = psImageSubset(original,0,0,c/2,r/2);
+
+    psLogMsg(__func__,PS_LOG_INFO,"Verify the returned psImage structure members nrow and ncol are equal to "
+             "the input parameter nrow and ncol respectively.");
+
+    if (subset2->numCols != c/2 || subset2->numRows != r/2) {
+        psError(__func__,"psImageSubset output size was not proper(%dx%d, should be %dx%d).",
+                subset2->numCols, subset2->numRows, c/2,r/2);
+        return 1;
+    }
+
+    if (subset3->numCols != c/2 || subset3->numRows != r/2) {
+        psError(__func__,"psImageSubset output size was not proper(%dx%d, should be %dx%d).",
+                subset3->numCols, subset3->numRows, c/2,r/2);
+        return 2;
+    }
 
     psLogMsg(__func__,PS_LOG_INFO,"Verify the returned psImage structure contains expected values in the "
@@ -322,13 +313,4 @@
     }
 
-    psLogMsg(__func__,PS_LOG_INFO,"Verify the returned psImage structure members nrow and ncol are equal to "
-             "the input parameter nrow and ncol respectively.");
-
-    if (subset3->numCols != c/2 || subset3->numRows != r/2) {
-        psError(__func__,"psImageSubset output size was not proper(%dx%d, should be %dx%d).",
-                subset3->numCols, subset3->numRows, c/2,r/2);
-        return 5;
-    }
-
     psLogMsg(__func__,PS_LOG_INFO,"Verify the returned psImage structure member type is equal to the input "
              "psImage structure member type.");
@@ -367,12 +349,4 @@
     }
 
-    psLogMsg(__func__,PS_LOG_INFO,"Verify the returned psImage structure member Nchildren is equal to "
-             "zero.");
-
-    if (subset2->nChildren != 0 || subset3->nChildren != 0) {
-        psError(__func__,"psImageSubset didn't set nChildren to zero.");
-        return 11;
-    }
-
     psLogMsg(__func__,PS_LOG_INFO,"Verify the returned psImage structure member children is null.");
 
@@ -386,9 +360,9 @@
              "out at parent[Nchildren-1].");
 
-    if (original->nChildren != preSubsetStruct.nChildren+2) {
-        psError(__func__,"psImageSubset didn't increment nChildren by one per subset.");
+    if (original->children == NULL || original->children->n != 2) {
+        psError(__func__,"psImageSubset didn't increment number of children by one per subset.");
         return 12;
     }
-    if (original->children[0] != subset2 || original->children[1] != subset3) {
+    if (original->children->data[0] != subset2 || original->children->data[1] != subset3) {
         psError(__func__,"psImageSubset didn't properly store the children pointers.");
         return 13;
@@ -400,5 +374,5 @@
 
     psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
-    subset1 = psImageSubset(NULL,c/2,r/2,0,0);
+    subset1 = psImageSubset(NULL,0,0,c/2,r/2);
     if (subset1 != NULL) {
         psError(__func__,"psImageSubset didn't return NULL when input image was NULL.");
@@ -412,5 +386,5 @@
     memcpy(&preSubsetStruct,original,sizeof(psImage));
     psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
-    subset1 = psImageSubset(original,c/2,0,0,0);
+    subset1 = psImageSubset(original,0,r/2,c/2,r/2);
     if (subset1 != NULL) {
         psError(__func__,"psImageSubset didn't return NULL when numRows=0.");
@@ -418,5 +392,5 @@
     }
     psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
-    subset1 = psImageSubset(original,0,r/2,0,0);
+    subset1 = psImageSubset(original,c/2,0,c/2,r/2);
     if (subset1 != NULL) {
         psError(__func__,"psImageSubset didn't return NULL when numCols=0.");
@@ -434,5 +408,5 @@
 
     psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
-    subset1 = psImageSubset(original,c/2,r/2,c,0);
+    subset1 = psImageSubset(original,0,0,c/2,r*2);
     if (subset1 != NULL) {
         psError(__func__,"psImageSubset didn't return NULL when subset origin was outside of "
@@ -441,5 +415,5 @@
     }
     psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
-    subset1 = psImageSubset(original,c/2,r/2,0,r);
+    subset1 = psImageSubset(original,0,0,c*2,r/2);
     if (subset1 != NULL) {
         psError(__func__,"psImageSubset didn't return NULL when subset origin was outside of "
@@ -448,5 +422,5 @@
     }
     psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
-    subset1 = psImageSubset(original,c/2,r/2,-1,0);
+    subset1 = psImageSubset(original,-1,0,c/2,r/2);
     if (subset1 != NULL) {
         psError(__func__,"psImageSubset didn't return NULL when subset origin was outside of "
@@ -455,5 +429,5 @@
     }
     psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
-    subset1 = psImageSubset(original,c/2,r/2,0,-1);
+    subset1 = psImageSubset(original,0,-1,c/2,r/2);
     if (subset1 != NULL) {
         psError(__func__,"psImageSubset didn't return NULL when subset origin was outside of "
@@ -468,5 +442,5 @@
 
     psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
-    subset1 = psImageSubset(original,c/2,r/2,c/2,0);
+    subset1 = psImageSubset(original,0,0,c/2,r+1);
     if (subset1 != NULL) {
         psError(__func__,"psImageSubset didn't return NULL when subset was outside of image (via rows).");
@@ -474,5 +448,5 @@
     }
     psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
-    subset1 = psImageSubset(original,c/2,r/2,0,r/2);
+    subset1 = psImageSubset(original,0,0,c+1,r/2);
     if (subset1 != NULL) {
         psError(__func__,"psImageSubset didn't return NULL when subset was outside of image (via cols).");
@@ -480,5 +454,5 @@
     }
     psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
-    subset1 = psImageSubset(original,c/2,r/2,c/2,r/2);
+    subset1 = psImageSubset(original,0,0,c+1,r+1);
     if (subset1 != NULL) {
         psError(__func__,"psImageSubset didn't return NULL when subset was outside of image (via row+cols).");
@@ -494,13 +468,7 @@
 
     // Verify the returned psImage structure member Nchildren is set to zero.
-    if (original->nChildren != 0) {
-        psError(__func__,"psImageFreeChildren didn't set nChildren to zero.");
+    if (original->children != NULL && original->children->n > 0) {
+        psError(__func__,"psImageFreeChildren didn't set number of children to zero.");
         return 25;
-    }
-
-    // Verify the returned psImage structure member children pointer is set to null.
-    if (original->children != NULL) {
-        psError(__func__,"psImageFreeChildren didn't set children ptr to NULL.");
-        return 26;
     }
 
Index: /trunk/psLib/test/image/verified/tst_psImage.stderr
===================================================================
--- /trunk/psLib/test/image/verified/tst_psImage.stderr	(revision 1919)
+++ /trunk/psLib/test/image/verified/tst_psImage.stderr	(revision 1920)
@@ -95,7 +95,7 @@
 
 <DATE><TIME>|<HOST>|I|testImageSubset
+    Verify the returned psImage structure members nrow and ncol are equal to the input parameter nrow and ncol respectively.
+<DATE><TIME>|<HOST>|I|testImageSubset
     Verify the returned psImage structure contains expected values in the row member, if the input psImage structure image contains known values.
-<DATE><TIME>|<HOST>|I|testImageSubset
-    Verify the returned psImage structure members nrow and ncol are equal to the input parameter nrow and ncol respectively.
 <DATE><TIME>|<HOST>|I|testImageSubset
     Verify the returned psImage structure member type is equal to the input psImage structure member type.
@@ -104,6 +104,4 @@
 <DATE><TIME>|<HOST>|I|testImageSubset
     Verify the returned psImage structure member parent is equal to the input psImage structure pointer image.
-<DATE><TIME>|<HOST>|I|testImageSubset
-    Verify the returned psImage structure member Nchildren is equal to zero.
 <DATE><TIME>|<HOST>|I|testImageSubset
     Verify the returned psImage structure member children is null.
@@ -121,9 +119,9 @@
     An error should follow...
 <DATE><TIME>|<HOST>|E|psLib.image.psImageSubset
-    Specified number of rows (64) or columns (0) is invalid.
+    Specified subset range, [0:<LINENO>,128:<LINENO>], is invalid or outside input psImage's boundaries, [0:<LINENO>,0:<LINENO>].
 <DATE><TIME>|<HOST>|I|testImageSubset
     An error should follow...
 <DATE><TIME>|<HOST>|E|psLib.image.psImageSubset
-    Specified number of rows (0) or columns (128) is invalid.
+    Specified subset range, [64:<LINENO>,0:<LINENO>], is invalid or outside input psImage's boundaries, [0:<LINENO>,0:<LINENO>].
 <DATE><TIME>|<HOST>|I|testImageSubset
     Verify the returned psImage structure pointer is null and program execution doesn't stop, if the input parameters row0 and col0 are not within the range of values of psImage structure image.
@@ -131,17 +129,17 @@
     An error should follow...
 <DATE><TIME>|<HOST>|E|psLib.image.psImageSubset
-    Specified subset range, [128:<LINENO>,0:<LINENO>], lies outside psImage's boundaries, [0:<LINENO>,0:<LINENO>].
+    Specified subset range, [0:<LINENO>,0:<LINENO>], is invalid or outside input psImage's boundaries, [0:<LINENO>,0:<LINENO>].
 <DATE><TIME>|<HOST>|I|testImageSubset
     An error should follow...
 <DATE><TIME>|<HOST>|E|psLib.image.psImageSubset
-    Specified subset range, [0:<LINENO>,256:<LINENO>], lies outside psImage's boundaries, [0:<LINENO>,0:<LINENO>].
+    Specified subset range, [0:<LINENO>,0:<LINENO>], is invalid or outside input psImage's boundaries, [0:<LINENO>,0:<LINENO>].
 <DATE><TIME>|<HOST>|I|testImageSubset
     An error should follow...
 <DATE><TIME>|<HOST>|E|psLib.image.psImageSubset
-    Specified subset range, [-1:<LINENO>,0:<LINENO>], lies outside psImage's boundaries, [0:<LINENO>,0:<LINENO>].
+    Specified subset range, [-1:<LINENO>,0:<LINENO>], is invalid or outside input psImage's boundaries, [0:<LINENO>,0:<LINENO>].
 <DATE><TIME>|<HOST>|I|testImageSubset
     An error should follow...
 <DATE><TIME>|<HOST>|E|psLib.image.psImageSubset
-    Specified subset range, [0:<LINENO>,-1:<LINENO>], lies outside psImage's boundaries, [0:<LINENO>,0:<LINENO>].
+    Specified subset range, [0:<LINENO>,-1:<LINENO>], is invalid or outside input psImage's boundaries, [0:<LINENO>,0:<LINENO>].
 <DATE><TIME>|<HOST>|I|testImageSubset
     Verify the returned psImage structure pointer is null and program execution doesn't stop if the input parameters nrow, ncol, row0 and col0 specify a range of data not within the input psImage structure image.  Also verify the input psImage structure is not modified.
@@ -149,13 +147,13 @@
     An error should follow...
 <DATE><TIME>|<HOST>|E|psLib.image.psImageSubset
-    Specified subset range, [64:<LINENO>,0:<LINENO>], lies outside psImage's boundaries, [0:<LINENO>,0:<LINENO>].
+    Specified subset range, [0:<LINENO>,0:<LINENO>], is invalid or outside input psImage's boundaries, [0:<LINENO>,0:<LINENO>].
 <DATE><TIME>|<HOST>|I|testImageSubset
     An error should follow...
 <DATE><TIME>|<HOST>|E|psLib.image.psImageSubset
-    Specified subset range, [0:<LINENO>,128:<LINENO>], lies outside psImage's boundaries, [0:<LINENO>,0:<LINENO>].
+    Specified subset range, [0:<LINENO>,0:<LINENO>], is invalid or outside input psImage's boundaries, [0:<LINENO>,0:<LINENO>].
 <DATE><TIME>|<HOST>|I|testImageSubset
     An error should follow...
 <DATE><TIME>|<HOST>|E|psLib.image.psImageSubset
-    Specified subset range, [64:<LINENO>,128:<LINENO>], lies outside psImage's boundaries, [0:<LINENO>,0:<LINENO>].
+    Specified subset range, [0:<LINENO>,0:<LINENO>], is invalid or outside input psImage's boundaries, [0:<LINENO>,0:<LINENO>].
 <DATE><TIME>|<HOST>|I|testImageSubset
     psImageFreeChildren shall deallocate any children images of a psImage structure
Index: /trunk/psLib/test/image/verified/tst_psImageExtraction.stderr
===================================================================
--- /trunk/psLib/test/image/verified/tst_psImageExtraction.stderr	(revision 1919)
+++ /trunk/psLib/test/image/verified/tst_psImageExtraction.stderr	(revision 1920)
@@ -24,17 +24,17 @@
     Following should be an error.
 <DATE><TIME>|<HOST>|E|psLib.image.psImageSlice
-    Specified subset range, [2001:<LINENO>,2002:<LINENO>], lies outside psImage's boundaries, [0:<LINENO>,0:<LINENO>].
+    Specified subset range, [2001:<LINENO>,2002:<LINENO>], is invalid or outside input psImage's boundaries, [0:<LINENO>,0:<LINENO>].
 <DATE><TIME>|<HOST>|I|testImageSlice
     Following should be an error.
 <DATE><TIME>|<HOST>|E|psLib.image.psImageSlice
-    Specified subset range, [200:<LINENO>,201:<LINENO>], lies outside psImage's boundaries, [0:<LINENO>,0:<LINENO>].
+    Specified subset range, [200:<LINENO>,201:<LINENO>], is invalid or outside input psImage's boundaries, [0:<LINENO>,0:<LINENO>].
 <DATE><TIME>|<HOST>|I|testImageSlice
     Following should be an error.
 <DATE><TIME>|<HOST>|E|psLib.image.psImageSlice
-    Specified subset range, [200:<LINENO>,2200:<LINENO>], lies outside psImage's boundaries, [0:<LINENO>,0:<LINENO>].
+    Specified subset range, [200:<LINENO>,2200:<LINENO>], is invalid or outside input psImage's boundaries, [0:<LINENO>,0:<LINENO>].
 <DATE><TIME>|<HOST>|I|testImageSlice
     Following should be an error.
 <DATE><TIME>|<HOST>|E|psLib.image.psImageSlice
-    Specified subset range, [200:<LINENO>,201:<LINENO>], lies outside psImage's boundaries, [0:<LINENO>,0:<LINENO>].
+    Specified subset range, [200:<LINENO>,201:<LINENO>], is invalid or outside input psImage's boundaries, [0:<LINENO>,0:<LINENO>].
 <DATE><TIME>|<HOST>|I|testImageSlice
     Following should be an error.
Index: /trunk/psLib/test/image/verified/tst_psImageManip.stderr
===================================================================
--- /trunk/psLib/test/image/verified/tst_psImageManip.stderr	(revision 1919)
+++ /trunk/psLib/test/image/verified/tst_psImageManip.stderr	(revision 1920)
@@ -125,5 +125,5 @@
     Following should error as overlay isn't within image boundaries
 <DATE><TIME>|<HOST>|E|psLib.image.psImageOverlaySection
-    Specified subset range, [32:<LINENO>,64:<LINENO>], lies outside psImage's boundaries, [0:<LINENO>,0:<LINENO>].
+    Specified subset range, [32:<LINENO>,64:<LINENO>], is invalid or outside input psImage's boundaries, [0:<LINENO>,0:<LINENO>].
 <DATE><TIME>|<HOST>|I|testImageOverlay
     Following should error as overlay is NULL
