Index: /branches/rel10_ifa/psLib/src/astro/psCoord.h
===================================================================
--- /branches/rel10_ifa/psLib/src/astro/psCoord.h	(revision 6727)
+++ /branches/rel10_ifa/psLib/src/astro/psCoord.h	(revision 6728)
@@ -11,6 +11,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.50 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-01-28 01:31:44 $
+ *  @version $Revision: 1.50.4.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-03-30 00:31:04 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -26,4 +26,5 @@
 #include "psPolynomial.h"
 #include "psPixels.h"
+#include "psRegion.h"
 //#include "psTime.h"
 
Index: /branches/rel10_ifa/psLib/src/fits/psFitsHeader.c
===================================================================
--- /branches/rel10_ifa/psLib/src/fits/psFitsHeader.c	(revision 6727)
+++ /branches/rel10_ifa/psLib/src/fits/psFitsHeader.c	(revision 6728)
@@ -7,6 +7,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.2.4.2 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-03-28 23:17:18 $
+ *  @version $Revision: 1.2.4.3 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-03-30 00:31:04 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -118,7 +118,8 @@
                     }
                     // Remove trailing spaces, which are not significant, according to the FITS standard
-                    // http://archive.stsci.edu/fits/fits_standard/node31.html#SECTION00921000000000000000
+                    // http://archive.stsci.edu/fits/fits_standard/node31.html
                     char *lastSpace = NULL; // The last space in the string
-                    while ((lastSpace = strrchr(keyValueFixed, ' ')) && lastSpace[1] == '\0') {
+                    while (strlen(keyValueFixed) > 1 && (lastSpace = strrchr(keyValueFixed, ' ')) &&
+                            lastSpace[1] == '\0') {
                         // This is a trailing space, not a leading space.
                         lastSpace[0] = '\0'; // Truncate the string here
Index: /branches/rel10_ifa/psLib/src/imageops/psImageStats.c
===================================================================
--- /branches/rel10_ifa/psLib/src/imageops/psImageStats.c	(revision 6727)
+++ /branches/rel10_ifa/psLib/src/imageops/psImageStats.c	(revision 6728)
@@ -9,6 +9,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.90.4.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-02-16 07:50:03 $
+ *  @version $Revision: 1.90.4.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-03-30 00:31:04 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -29,4 +29,6 @@
 #include "psPolynomial.h"
 #include "psImageStats.h"
+#include "psRegion.h"
+#include "psRegionForImage.h"
 #include "psConstants.h"
 #include "psErrorText.h"
Index: /branches/rel10_ifa/psLib/src/imageops/psImageStats.h
===================================================================
--- /branches/rel10_ifa/psLib/src/imageops/psImageStats.h	(revision 6727)
+++ /branches/rel10_ifa/psLib/src/imageops/psImageStats.h	(revision 6728)
@@ -9,6 +9,6 @@
 *  @author GLG, MHPCC
 *
-*  @version $Revision: 1.27 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-09-26 22:35:53 $
+*  @version $Revision: 1.27.20.1 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2006-03-30 00:31:04 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -20,4 +20,5 @@
 #include "psVector.h"
 #include "psImage.h"
+#include "psRegion.h"
 #include "psStats.h"
 #include "psPolynomial.h"
Index: /branches/rel10_ifa/psLib/src/imageops/psImageStructManip.h
===================================================================
--- /branches/rel10_ifa/psLib/src/imageops/psImageStructManip.h	(revision 6727)
+++ /branches/rel10_ifa/psLib/src/imageops/psImageStructManip.h	(revision 6728)
@@ -8,6 +8,6 @@
 *  @author Robert DeSonia, MHPCC
 *
-*  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-06-08 23:40:45 $
+*  @version $Revision: 1.3.24.1 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2006-03-30 00:31:04 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -18,4 +18,5 @@
 
 #include "psImage.h"
+#include "psRegion.h"
 
 /// @addtogroup Image
Index: /branches/rel10_ifa/psLib/src/math/Makefile.am
===================================================================
--- /branches/rel10_ifa/psLib/src/math/Makefile.am	(revision 6727)
+++ /branches/rel10_ifa/psLib/src/math/Makefile.am	(revision 6728)
@@ -13,4 +13,6 @@
 	psMinimizePolyFit.c \
 	psRandom.c \
+	psRegion.c \
+	psRegionForImage.c \
 	psPolynomial.c \
 	psSpline.c \
@@ -31,4 +33,6 @@
 	psMinimizePolyFit.h \
 	psRandom.h \
+	psRegion.h \
+	psRegionForImage.h \
 	psPolynomial.h \
 	psSpline.h \
Index: /branches/rel10_ifa/psLib/src/mathtypes/psImage.c
===================================================================
--- /branches/rel10_ifa/psLib/src/mathtypes/psImage.c	(revision 6727)
+++ /branches/rel10_ifa/psLib/src/mathtypes/psImage.c	(revision 6728)
@@ -9,6 +9,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.95.4.2 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-02-24 03:59:10 $
+ *  @version $Revision: 1.95.4.3 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-03-30 00:31:04 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -103,113 +103,4 @@
 }
 
-
-psRegion psRegionSet(float x0,
-                     float x1,
-                     float y0,
-                     float y1)
-{
-    psRegion out;
-
-    out.x0 = x0;
-    out.y0 = y0;
-    out.x1 = x1;
-    out.y1 = y1;
-
-    return out;
-}
-
-psRegion psRegionFromString(const char* region)
-{
-    psS32 col0;
-    psS32 col1;
-    psS32 row0;
-    psS32 row1;
-
-    // section should be of the form '[col0:col1,row0:row1]'
-    if (region == NULL) {
-        return psRegionSet(0,0,0,0);
-    }
-
-    if (sscanf(region,"[%d:%d,%d:%d]",&col0,&col1,&row0,&row1) < 4) {
-        psError(PS_ERR_BAD_PARAMETER_NULL, true,
-                PS_ERRORTEXT_psImage_SUBSECTION_INVALID,
-                region);
-        return psRegionSet(NAN,NAN,NAN,NAN);
-    }
-
-    if (col0 > col1 || row0 > row1) {
-        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
-                PS_ERRORTEXT_psImage_SUBSET_RANGE_MALFORMED,
-                col0,col1,row0,row1);
-        return psRegionSet(NAN,NAN,NAN,NAN);
-    }
-
-    return psRegionSet(col0-1,col1,row0-1,row1);
-}
-
-psString psRegionToString(const psRegion region)
-{
-    char tmpText[256]; // big enough to store any region as text
-
-    snprintf(tmpText,256,"[%g:%g,%g:%g]",
-             region.x0+1, region.x1,
-             region.y0+1, region.y1);
-
-    return psStringCopy(tmpText);
-}
-
-
-// set actual region based on image parameters:
-// - compensate for negative upper limits
-// - force range to be on this image
-// - saturate on upper and lower limits of image
-// - flip x0,x1 if x0>x1
-// - flip y0,y1 if y0>y1
-// psRegion in refers to coordinates in the
-psRegion psRegionForImage(psImage *image,
-                          psRegion in)
-{
-
-    if (image == NULL) {
-        return in;
-    }
-
-    // convert non-positive upper-limits
-    // XXX note that the upper limit in these cases is defined relative to the subimage
-    // also note that truncation limits to the valid subimage pixels
-    in.x1 = (in.x1 <= 0) ? (image->col0 + image->numCols + in.x1) : in.x1;
-    in.y1 = (in.y1 <= 0) ? (image->row0 + image->numRows + in.y1) : in.y1;
-
-    // force the upper-limits to be on the image
-    in.x1 = PS_MIN(image->col0 + image->numCols, in.x1);
-    in.y1 = PS_MIN(image->row0 + image->numRows, in.y1);
-
-    // force the lower-limits to be on the image
-    in.x0 = PS_MAX(image->col0, in.x0);
-    in.y0 = PS_MAX(image->row0, in.y0);
-    in.x0 = PS_MIN(image->col0 + image->numCols, in.x0);
-    in.y0 = PS_MIN(image->row0 + image->numRows, in.y0);
-
-    // flip start and end if out of order
-    if (in.x0 > in.x1) {
-        PS_SWAP (in.x0, in.x1);
-    }
-    if (in.y0 > in.y1) {
-        PS_SWAP (in.y0, in.y1);
-    }
-
-    return (in);
-}
-
-// define a square region centered on the given coordinate
-psRegion psRegionForSquare(double x,
-                           double y,
-                           double radius)
-{
-    psRegion region;
-    region = psRegionSet (x - radius, x + radius + 1,
-                          y - radius, y + radius + 1);
-    return (region);
-}
 
 bool psImageInit (psImage *image,...)
Index: /branches/rel10_ifa/psLib/src/mathtypes/psImage.h
===================================================================
--- /branches/rel10_ifa/psLib/src/mathtypes/psImage.h	(revision 6727)
+++ /branches/rel10_ifa/psLib/src/mathtypes/psImage.h	(revision 6728)
@@ -11,6 +11,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.74 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-01-28 01:12:14 $
+ *  @version $Revision: 1.74.4.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-03-30 00:31:04 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -84,32 +84,19 @@
                 #define P_PSIMAGE_SET_TYPE(img,t) *(psMathType*)&img->type = t
 
-                        /** Basic image region structure.
+
+                        /** Create an image of the specified size and type.
                          *
-                         * Struct for specifying a rectangular area in an image.
+                         * Uses psLib memory allocation functions to create an image struct of the
+                         * specified size and type.
+                         *
+                         * @return psImage* : Pointer to psImage.
                          *
                          */
-                        typedef struct
-                        {
-                            float x0;                         ///< the first column of the region.
-                            float x1;                         ///< the last column of the region.
-                            float y0;                         ///< the first row of the region.
-                            float y1;                         ///< the last row of the region.
-                        }
-                        psRegion;
-
-/** Create an image of the specified size and type.
- *
- * Uses psLib memory allocation functions to create an image struct of the
- * specified size and type.
- *
- * @return psImage* : Pointer to psImage.
- *
- */
-psImage* psImageAlloc(
-    int numCols,                       ///< Number of rows in image.
-    int numRows,                       ///< Number of columns in image.
-    psElemType type                    ///< Type of data for image.
-)
-;
+                        psImage* psImageAlloc(
+                            int numCols,                       ///< Number of rows in image.
+                            int numRows,                       ///< Number of columns in image.
+                            psElemType type                    ///< Type of data for image.
+                        )
+                        ;
 
 /** Checks the type of a particular pointer.
@@ -123,65 +110,4 @@
 );
 
-
-/** Create a psRegion with the specified attributes.
- *
- *  @return psRegion : a cooresponding psRegion.
- */
-psRegion psRegionSet(
-    float x0,                          ///< the first column of the region.
-    float x1,                          ///< the last column of the region + 1.
-    float y0,                          ///< the first row of the region.
-    float y1                           ///< the last row of the region + 1.
-);
-
-/** Create a psRegion with the attribute values given as a string.
- *
- *  Create a psRegion with the attribute values given as a string.  The format
- *  shall be of the standard IRAF form '[x0:x1,y0:y1]'
- *
- *  @return psRegion:  A new psRegion struct, or NULL is not successful.
- */
-psRegion psRegionFromString(
-    const char* region                 ///< image rectangular region in the form '[x0:x1,y0:y1]'
-);
-
-/** Create a string of the standard IRAF form '[x0:x1,y0:y1]' from a psRegion.
- *
- *  @return psString:  A new string representing the psRegion as text, or NULL
- *                  is not successful.
- */
-psString psRegionToString(
-    const psRegion region              ///< the psRegion to convert to a string
-);
-
-/** Sets an actual region based on image parameters.
- *
- *  An image region defined with negative upper limits may be rationalized for the bounds of a
- *  specific image with psRegionForImage.  The output of this function is a region with negative
- *  upper limits replaced by their corrected value appropriate to the given image.  In addition,
- *  the lower and upper limits are foced to lie within the bounds of the image.  If the lower-
- *  limit coordinates are lewss than the lower bound of the image, they are limited to the lower
- *  bound of the image.  Conversely, if the upper-limit coordinates are greater than the upper
- *  bound of the image, they are truncated to define only valid pixels.  If the lower-limit
- *  coordinates are greater than the upper bounds of the image, or the upper-limit coordinates
- *  are less than the lower bounds of the image, the coordinates should saturate on those limits.
- *
- *  @return psRegion:       A region with negative upper limits replaced by the corrected
- */
-psRegion psRegionForImage(
-    psImage *image,                    ///< the image for which the region is to be set
-    psRegion in                        ///< the image region limits
-);
-
-/** Defines a region corresponding to the square with center at coordinate x,y
- *  and with coderadius.  The width of the square is 2radius + 1.
- *
- *  @return psRegion:       the newly defined psRegion.
- */
-psRegion psRegionForSquare(
-    double x,                           ///< x coordinate at square-center
-    double y,                           ///< y coordinate at square-center
-    double radius                       ///< radius of square
-);
 
 /** Initializes the image with the given value.
Index: /branches/rel10_ifa/psLib/src/pslib_strict.h
===================================================================
--- /branches/rel10_ifa/psLib/src/pslib_strict.h	(revision 6727)
+++ /branches/rel10_ifa/psLib/src/pslib_strict.h	(revision 6728)
@@ -9,6 +9,6 @@
 *  @author Eric Van Alst, MHPCC
 *
-*  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2006-02-02 21:11:13 $
+*  @version $Revision: 1.14.4.1 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2006-03-30 00:31:03 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -79,4 +79,6 @@
 #include "psMinimizePolyFit.h"
 #include "psRandom.h"
+#include "psRegion.h"
+#include "psRegionForImage.h"
 #include "psPolynomial.h"
 #include "psSpline.h"
Index: /branches/rel10_ifa/psLib/src/sys/psType.h
===================================================================
--- /branches/rel10_ifa/psLib/src/sys/psType.h	(revision 6727)
+++ /branches/rel10_ifa/psLib/src/sys/psType.h	(revision 6728)
@@ -10,6 +10,6 @@
 *  @author Ross Harman, MHPCC
 *
-*  @version $Revision: 1.46 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2006-02-08 00:00:35 $
+*  @version $Revision: 1.46.4.1 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2006-03-30 00:31:04 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -130,4 +130,5 @@
     PS_DATA_POLYNOMIAL4D,              ///< psPolynomial4D
     PS_DATA_PROJECTION,                ///< psProjection
+    PS_DATA_REGION,                    ///< psRegion
     PS_DATA_SCALAR,                    ///< psScalar
     PS_DATA_SPHERE,                    ///< psSphere
Index: /branches/rel10_ifa/psLib/src/types/psMetadata.c
===================================================================
--- /branches/rel10_ifa/psLib/src/types/psMetadata.c	(revision 6727)
+++ /branches/rel10_ifa/psLib/src/types/psMetadata.c	(revision 6728)
@@ -12,6 +12,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.99.4.5 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-03-28 22:19:15 $
+ *  @version $Revision: 1.99.4.6 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-03-30 00:31:04 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -293,4 +293,5 @@
     case     PS_DATA_POLYNOMIAL4D:              // psPolynomial4D
     case     PS_DATA_PROJECTION:                // psProjection
+    case     PS_DATA_REGION:                  // psRegion
     case     PS_DATA_SCALAR:                    // psScalar
     case     PS_DATA_SPHERE:                    // psSphere
@@ -341,4 +342,76 @@
 }
 
+
+psMetadataItem *psMetadataItemCopy(const psMetadataItem *in
+                                  )
+{
+    PS_ASSERT_PTR_NON_NULL(in,NULL);
+
+    psMetadataItem *newItem = NULL;     // New metadata item, to be returned
+
+    #define PS_METADATA_ITEM_COPY_CASE(NAME,TYPE) \
+case PS_DATA_##NAME: \
+    newItem = psMetadataItemAlloc(in->name, PS_DATA_##NAME, in->comment, in->data.TYPE); \
+    break; \
+
+    switch (in->type) {
+        // Simple types
+        PS_METADATA_ITEM_COPY_CASE(BOOL,B);
+        PS_METADATA_ITEM_COPY_CASE(S8,S8);
+        PS_METADATA_ITEM_COPY_CASE(S16,S16);
+        PS_METADATA_ITEM_COPY_CASE(S32,S32);
+        PS_METADATA_ITEM_COPY_CASE(U8,U8);
+        PS_METADATA_ITEM_COPY_CASE(U16,U16);
+        PS_METADATA_ITEM_COPY_CASE(U32,U32);
+        PS_METADATA_ITEM_COPY_CASE(F32,F32);
+        PS_METADATA_ITEM_COPY_CASE(F64,F64);
+        PS_METADATA_ITEM_COPY_CASE(STRING,V); // This will copy the string, not point at it.
+    case PS_DATA_VECTOR: {
+            psVector *vecCopy = psVectorCopy(NULL, (psVector*)(in->data.V),
+                                             ((psVector*)(in->data.V))->type.type);
+            if (vecCopy == NULL) {
+                psError(PS_ERR_BAD_PARAMETER_NULL, false,
+                        "Error copying vector.  Vector skipped.\n");
+            } else {
+                newItem = psMetadataItemAlloc(in->name, PS_DATA_VECTOR, in->comment, vecCopy);
+                psFree(vecCopy);    // Drop reference
+            }
+            break;
+        }
+    case PS_DATA_TIME: {
+            psTime *timeCopy = p_psTimeCopy( (psTime*)(in->data.V) );
+            if (timeCopy == NULL) {
+                psError(PS_ERR_BAD_PARAMETER_NULL, false,
+                        "Error copying time.  Time skipped.\n");
+            } else {
+                newItem = psMetadataItemAlloc(in->name, PS_DATA_TIME, in->comment, timeCopy);
+                psFree(timeCopy);   // Drop reference
+            }
+            break;
+        }
+    case PS_DATA_METADATA: {
+            // Metadata: copy the next level and stuff that in too
+            psMetadata *metadata = psMetadataCopy(NULL, in->data.md);
+            newItem = psMetadataItemAlloc(in->name, PS_DATA_METADATA, in->comment, metadata);
+            psFree(metadata);       // Drop reference
+            break;
+        }
+    case PS_DATA_REGION: {
+            psRegion *region = in->data.V; // The region
+            psRegion *new = psRegionAlloc(region->x0, region->x1, region->y0, region->y1); // Copy of the region
+            newItem = psMetadataItemAlloc(in->name, PS_DATA_REGION, in->comment, new);
+            psFree(new);                  // Drop reference
+            break;
+        }
+    default:
+        // Other kinds of pointers
+        psLogMsg(__func__, PS_LOG_WARN, "Copying a pointer in the metadata item: %x\n", in->type);
+        newItem = psMetadataItemAlloc(in->name, in->type, in->comment, in->data.V);
+        break;
+    }
+
+    return newItem;
+}
+
 psMetadata *psMetadataCopy(psMetadata *out,
                            const psMetadata *in)
@@ -349,19 +422,6 @@
         out = psMetadataAlloc();
     }
-    //    psMetadataItem *item = NULL;
-    psMetadataIterator *iter = NULL;
-    iter = psMetadataIteratorAlloc(*(psMetadata**)&in, PS_LIST_HEAD, NULL);
-    /*
-        item = psMetadataGetAndIncrement(iter);
-        while (item != NULL) {
-            psMetadataAddItem(out, item, PS_LIST_TAIL, 0);
-            item = psMetadataGetAndIncrement(iter);
-        }
-        psFree(item);
-        psFree(iter);
-        return out;
-    */
+    psMetadataIterator *iter = psMetadataIteratorAlloc(*(psMetadata**)&in, PS_LIST_HEAD, NULL);
     psMetadataItem *inItem = NULL;
-    unsigned long numPointers = 0;      // Number of pointers we were forced to copy
     while ((inItem = psMetadataGetAndIncrement(iter))) {
         // Need to look for MULTI, which won't be picked up using the iterator.
@@ -374,81 +434,12 @@
         psTrace(__func__, 5, "Copying %s (%s)...\n", inItem->name, inItem->comment);
 
-
-        //        case PS_TYPE_##NAME:
-        #define PS_METADATA_COPY_CASE(NAME,TYPE) \
-    case PS_DATA_##NAME: \
-        if (! psMetadataAdd(out, PS_LIST_TAIL, inItem->name, \
-                            PS_DATA_##NAME | flag, inItem->comment, inItem->data.TYPE)) { \
-            psErrorStackPrint(stderr, "Error copying %s (%s) in the metadata\n", \
-                              inItem->name, inItem->comment); \
-        } \
-        break;
-
-        switch (inItem->type) {
-            // Numerical types
-            PS_METADATA_COPY_CASE(BOOL,B);
-            PS_METADATA_COPY_CASE(S8,S8);
-            PS_METADATA_COPY_CASE(S16,S16);
-            PS_METADATA_COPY_CASE(S32,S32);
-            PS_METADATA_COPY_CASE(U8,U8);
-            PS_METADATA_COPY_CASE(U16,U16);
-            PS_METADATA_COPY_CASE(U32,U32);
-            PS_METADATA_COPY_CASE(F32,F32);
-            PS_METADATA_COPY_CASE(F64,F64);
-
-        case PS_DATA_VECTOR: {
-                psVector *vecCopy = psVectorCopy(NULL, (psVector*)(inItem->data.V),
-                                                 ((psVector*)(inItem->data.V))->type.type);
-                if (vecCopy == NULL) {
-                    psError(PS_ERR_BAD_PARAMETER_NULL, false,
-                            "Error copying vector.  Vector skipped.\n");
-                } else {
-                    psMetadataAddVector(out, PS_LIST_TAIL, inItem->name, flag,
-                                        inItem->comment, vecCopy);
-                    psFree(vecCopy);
-                }
-                break;
-            }
-        case PS_DATA_TIME: {
-                psTime *timeCopy = p_psTimeCopy( (psTime*)(inItem->data.V) );
-                if (timeCopy == NULL) {
-                    psError(PS_ERR_BAD_PARAMETER_NULL, false,
-                            "Error copying time.  Time skipped.\n");
-                } else {
-                    psMetadataAddTime(out, PS_LIST_TAIL, inItem->name, flag,
-                                      inItem->comment, timeCopy);
-                    psFree(timeCopy);
-                }
-                break;
-            }
-            // String: relying on the fact that this will copy the string, not point at it.
-        case PS_DATA_STRING:
-            psMetadataAdd(out, PS_LIST_TAIL, inItem->name, PS_DATA_STRING |
-                          flag, inItem->comment, inItem->data.V);
-            break;
-            // Metadata: copy the next level and stuff that in too
-        case PS_DATA_METADATA: {
-                psMetadata *metadata = psMetadataCopy(NULL, inItem->data.md);
-                psMetadataAdd(out, PS_LIST_TAIL, inItem->name,
-                              PS_DATA_METADATA | flag, inItem->comment, metadata);
-                psFree(metadata);
-                break;
-            }
-            // Other kinds of pointers
-        default:
-            numPointers++;
-            psTrace(__func__, 10, "Copying a pointer in the metadata: %x\n", inItem->type);
-            psMetadataAdd(out, PS_LIST_TAIL, inItem->name, inItem->type | flag,
-                          inItem->comment, inItem->data.V);
-            break;
+        // Copy the item and add it on
+        psMetadataItem *newItem = psMetadataItemCopy(inItem); // Copied item
+        if (!psMetadataAddItem(out, newItem, PS_LIST_TAIL, flag)) {
+            psErrorStackPrint(stderr, "Error copying %s (%s) in the metadata\n", inItem->name,
+                              inItem->comment);
         }
     }
     psFree(iter);
-
-    if (numPointers > 0) {
-        psLogMsg(__func__, PS_LOG_WARN,
-                 "Forced to copy %d pointers when copying metadata.  Updating the "
-                 "copied psMetadata will affect the original!\n", numPointers);
-    }
 
     return out;
@@ -558,5 +549,5 @@
                    int format,
                    const char *comment,
-                   ...)
+                   -..)
 {
     PS_ASSERT_PTR_NON_NULL(md,false);
Index: /branches/rel10_ifa/psLib/src/types/psMetadata.h
===================================================================
--- /branches/rel10_ifa/psLib/src/types/psMetadata.h	(revision 6727)
+++ /branches/rel10_ifa/psLib/src/types/psMetadata.h	(revision 6728)
@@ -11,6 +11,6 @@
 *  @author Ross Harman, MHPCC
 *
-*  @version $Revision: 1.74.4.2 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2006-03-28 02:17:08 $
+*  @version $Revision: 1.74.4.3 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2006-03-30 00:31:04 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -343,4 +343,12 @@
 );
 
+/** Creates a new copy of a psMetadataItem.
+ *
+ * @return psMetadataItem*: the copy of the psMetadataItem
+ */
+psMetadataItem *psMetadataItemCopy(const psMetadataItem *in ///< metadata item to be copied
+                                  );
+
+
 /** Creates a new copy of all the psMetadataItems in the psMetadata collection, in, and
  *  returns them in out, or creates a new container if out is NULL.
Index: /branches/rel10_ifa/psLib/src/types/psPixels.h
===================================================================
--- /branches/rel10_ifa/psLib/src/types/psPixels.h	(revision 6727)
+++ /branches/rel10_ifa/psLib/src/types/psPixels.h	(revision 6728)
@@ -7,6 +7,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-01-28 01:31:44 $
+ *  @version $Revision: 1.18.4.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-03-30 00:31:04 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -17,4 +17,5 @@
 #include "psImage.h"
 #include "psVector.h"
+#include "psRegion.h"
 
 /// @addtogroup Image
