Index: trunk/psphot/src/setup.c
===================================================================
--- trunk/psphot/src/setup.c	(revision 4216)
+++ trunk/psphot/src/setup.c	(revision 4251)
@@ -13,6 +13,6 @@
     psImage *noise = NULL;
     psImage *mask = NULL;
-
-    psRegion  region = {0,0,0,0};	// a region representing the entire array
+    psRegion region = {0,0,0,0};	// a region representing the entire array
+    bool status;
 
     psTimerStart ("psphot");
@@ -24,5 +24,5 @@
 
     // read header and image data from INPUT 
-    char *input = psMetadataLookupSTR (&status, config, "INPUT");
+    char *input = psMetadataLookupPtr (&status, config, "INPUT");
     psFits *file = psFitsAlloc (input);
     header = psFitsReadHeader (header, file);
@@ -31,5 +31,4 @@
 
     // grab these values from the approrpiate location (image header if necessary)
-    bool  status   = false;
     float RDNOISE  = pmConfigLookupF32 (&status, config, header, "RDNOISE");
     float GAIN     = pmConfigLookupF32 (&status, config, header, "GAIN");
@@ -38,5 +37,5 @@
 
     // load the noise image if it is supplied, otherwise build from input
-    char *noiseName = psMetadataLookupSTR (&status, config, "NOISE");
+    char *noiseName = psMetadataLookupPtr (&status, config, "NOISE");
     if (status == true) {
       file = psFitsAlloc (noiseName);
@@ -44,14 +43,26 @@
       psFree (file);
     } else {
-      psScalar *value = psScalarAlloc (1.0 / GAIN, PS_TYPE_F64);
-      noise = BinaryOp (NULL, image, '/', value);
+      psScalar *value;
+
+      noise = psImageAlloc (image->numCols, image->numRows, PS_TYPE_F32);
+      for (int iy = 0; iy < image->numRows; iy++) {
+	for (int ix = 0; ix < image->numCols; ix++) {
+	  noise->data.F32[iy][ix] = image->data.F32[iy][ix] / GAIN + PS_SQR(RDNOISE/GAIN);
+	}
+      }
+
+      // XXX EAM it looks like psBinaryOp is broken for (image op scalar)
+      # if (0)
+      value = psScalarAlloc (1.0 / GAIN, PS_TYPE_F64);
+      noise = (psImage *) psBinaryOp (NULL, image, "/", value);
       psFree (value);
 
-      psScalar *value = psScalarAlloc (PS_SQR(RDNOISE/GAIN), PS_TYPE_F64);
-      noise = BinaryOp (noise, noise, '+', value);
+      value = psScalarAlloc (PS_SQR(RDNOISE/GAIN), PS_TYPE_F64);
+      noise = (psImage *) psBinaryOp (noise, noise, "+", value);
       psFree (value);
+      # endif
     }
 
-    char *maskName = psMetadataLookupSTR (&status, config, "MASK");
+    char *maskName = psMetadataLookupPtr (&status, config, "MASK");
     if (status == true) {
       file = psFitsAlloc (maskName);
@@ -67,5 +78,5 @@
     psRegion *keep = psRegionAlloc (XBORDER, -XBORDER, YBORDER, -YBORDER);
     keep           = psRegionForImage (keep, image, keep);
-    psImageKeepRegion (mask, keep, 0x01);
+    psImageKeepRegion (mask, keep, OR, 0x01);
 
     // mask the saturated pixels
@@ -87,4 +98,4 @@
     imdata->mask = mask;
 
-    return (true);
+    return (imdata);
 }
