Index: trunk/psphot/src/psLibUtils.c
===================================================================
--- trunk/psphot/src/psLibUtils.c	(revision 4946)
+++ trunk/psphot/src/psLibUtils.c	(revision 4954)
@@ -1,3 +1,7 @@
-# include "psphot.h"
+# include <strings.h>  // for strncasecmp
+# include <pslib.h>
+
+// XXX EAM : this is NOT included in the C99 headers ??
+FILE *fdopen(int fildes, const char *mode);
 
 // XXX EAM : these utility functions should be added back into PSLib
@@ -29,5 +33,5 @@
     if (timers == NULL) timers = psHashAlloc (16);
 
-    start = psTimeGetTime (PS_TIME_UTC);
+    start = psTimeGetNow (PS_TIME_UTC);
     psHashAdd (timers, name, start);
     psFree (start); 
@@ -47,5 +51,5 @@
     if (start == NULL) return (0);
 
-    mark = psTimeGetTime (PS_TIME_UTC);
+    mark = psTimeGetNow (PS_TIME_UTC);
     delta = psTimeDelta (mark, start);
     psFree (mark);
@@ -53,4 +57,32 @@
 
     return (delta);
+}
+
+// find the location of the specified argument
+int psArgumentGet (int argc, char **argv, char *arg) {
+
+    int i;
+
+    for (i = 0; i < argc; i++) {
+	if (!strcmp(argv[i], arg))
+	    return (i);
+    }
+  
+    return ((int)NULL);
+}
+
+// remove the specified argument (by location)
+int psArgumentRemove (int N, int *argc, char **argv) {
+
+    int i;
+
+    if ((N != (int)NULL) && (N != 0)) {
+	(*argc)--;
+	for (i = N; i < *argc; i++) {
+	    argv[i] = argv[i+1];
+	}
+    }
+
+    return (N);
 }
 
@@ -114,38 +146,11 @@
 }
 
-// find the location of the specified argument
-int psArgumentGet (int argc, char **argv, char *arg) {
-
-    int i;
-
-    for (i = 0; i < argc; i++) {
-	if (!strcmp(argv[i], arg))
-	    return (i);
-    }
-  
-    return ((int)NULL);
-}
-
-// remove the specified argument (by location)
-int psArgumentRemove (int N, int *argc, char **argv) {
-
-    int i;
-
-    if ((N != (int)NULL) && (N != 0)) {
-	(*argc)--;
-	for (i = N; i < *argc; i++) {
-	    argv[i] = argv[i+1];
-	}
-    }
-
-    return (N);
-}
-
 // alternate implementation of this function from pmObjects.c
+// XXX EAM : move this to pmObjects_EAM.c
 psVector *psGetRowVectorFromImage(psImage *image,
 				  psU32 row)
 {
-    PS_IMAGE_CHECK_NULL(image, NULL);
-    PS_IMAGE_CHECK_TYPE(image, PS_TYPE_F32, NULL);
+    PS_ASSERT_IMAGE_NON_NULL(image, NULL);
+    PS_ASSERT_IMAGE_TYPE(image, PS_TYPE_F32, NULL);
 
     psVector *tmpVector = psVectorAlloc(image->numCols, PS_TYPE_F32);
@@ -201,5 +206,6 @@
 }
 
-void psImageSmooth (psImage *image, float sigma, float Nsigma) {
+// XXX EAM : this is now in psLib
+void psImageSmooth_EAM (psImage *image, float sigma, float Nsigma) {
 
     int Nx, Ny, Npixel, Nrange;
@@ -314,5 +320,22 @@
 }	    
 
+// count number of pixels with given mask value
+int psImageCountPixelMask (psImage *mask, psU8 value) 
+{
+    int Npixels = 0;
+  
+    for (int i = 0; i < mask->numRows; i++) {
+	for (int j = 0; j < mask->numCols; j++) {
+	    if (mask->data.U8[i][j] & value) {
+		Npixels ++;
+	    }
+	}
+    }
+    return (Npixels);
+}
+
 // define a square region centered on the given coordinate
+// XXX EAM : this is now in psLib
+# if (0)
 psRegion *psRegionSquare (psF32 x, psF32 y, psF32 radius) {
     psRegion *region;
@@ -321,4 +344,5 @@
     return (region);
 }
+# endif
 
 // set actual region based on image parameters:
@@ -327,7 +351,9 @@
 //     frame, which means the negative values should subtract from Nx,Ny of
 //     the parent, not the child.  but, we don't carry the dimensions of the 
-//     parent in the psImage container.  for now, us the child Nx,Ny
-// force range to be on this subimage 
-// XXX EAM : this needs to be changes to use psRegion rather than psRegion*
+//     parent in the psImage container.  for now, use the child Nx,Ny
+//     force range to be on this subimage 
+// XXX EAM : this needs to be changed to use psRegion rather than psRegion*
+// XXX EAM : this is now in psLib
+# if (0)
 psRegion *psRegionForImage (psRegion *out, psImage *image, psRegion *in) {
     
@@ -356,7 +382,10 @@
     return (out);
 }
+# endif
 
 // mask the area contained by the region
 // the region is defined wrt the parent image
+// XXX EAM : this is now in psLib
+# if (0)
 void psImageMaskRegion (psImage *image, psRegion *region, bool logical_and, int maskValue) {
 
@@ -375,7 +404,10 @@
     }
 }
+# endif
 
 // mask the area not contained by the region
 // the region is defined wrt the parent image
+// XXX EAM : this is now in psLib
+# if (0)
 void psImageKeepRegion (psImage *image, psRegion *region, bool logical_and, int maskValue) {
 
@@ -396,7 +428,10 @@
     }
 }
+# endif
 
 // mask the area contained by the region
 // the region is defined wrt the parent image
+// XXX EAM : this is now in psLib
+# if (0)
 void psImageMaskCircle (psImage *image, double x, double y, double radius, bool logical_and, int maskValue) {
 
@@ -419,7 +454,10 @@
     }
 }
+# endif
 
 // mask the area contained by the region
 // the region is defined wrt the parent image
+// XXX EAM : this is now in psLib
+# if (0)
 void psImageKeepCircle (psImage *image, double x, double y, double radius, bool logical_and, int maskValue) {
 
@@ -442,4 +480,5 @@
     }
 }
+# endif
 
 psVector *psVectorCreate (double lower, double upper, double delta, psElemType type) {
@@ -455,2 +494,19 @@
   return (out);
 }
+
+// XXX EAM a utility function
+bool p_psVectorPrintRow (int fd, psVector *a, char *name)
+{
+
+    FILE *f;
+    f = fdopen(fd, "a+");
+    fprintf (f, "vector: %s\n", name);
+
+    for (int i = 0; i < a[0].n; i++) {
+        fprintf (f, "%f  ", p_psVectorGetElementF64(a, i));
+    }
+    fprintf (f, "\n");
+    fclose(f);
+    return (true);
+}
+// XXX EAM is the use of fdopen here a good way to do this?
