Index: /trunk/psModules/src/objects/pmSourcePhotometry.c
===================================================================
--- /trunk/psModules/src/objects/pmSourcePhotometry.c	(revision 9842)
+++ /trunk/psModules/src/objects/pmSourcePhotometry.c	(revision 9843)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA; GLG, MHPCC
  *
- *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-10-31 19:38:44 $
+ *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-11-03 15:21:15 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -182,5 +182,70 @@
 }
 
+// XXX the implemented version of psImageShift does not work (is inconsistent wrt psImageInterpolate frac pix def?)
+psImage *tmp_psImageShift (psImage *in, float dx, float dy)
+{
+
+    int nx = in->numCols;
+    int ny = in->numRows;
+
+    psImage *out = psImageAlloc (nx, ny, PS_TYPE_F32);
+
+    // we define an integer shift and a (positive) fractional shift
+    int dxi = floor(dx);
+    int dyi = floor(dy);
+    float dxf = dx - dxi;  // +2.3 -> 2 and 0.3; -2.3 -> -3 and +0.7
+    float dyf = dy - dyi;  // +2.3 -> 2 and 0.3; -2.3 -> -3 and +0.7
+
+    // apply the integer shift
+    int DXin = (dxi < 0) ? -dxi : 0;
+    int DXot = (dxi < 0) ?   0  : dxi;
+    int DYin = (dyi < 0) ? -dyi : 0;
+    int DYot = (dyi < 0) ?   0  : dyi;
+
+    for (int j = 0; j < ny - abs(dyi); j++) {
+        for (int i = 0; i < nx - abs(dxi); i++) {
+            out->data.F32[j+DYot][i+DXot] = in->data.F32[j+DYin][i+DXin];
+        }
+        // fill in the exposed x-border with 0.0
+        int pix = (dxi > 0) ? 0 : nx - abs(dxi);
+        for (int i = 0; i < abs(dxi); i++, pix++) {
+            out->data.F32[j+DYot][pix] = 0.0;
+        }
+    }
+
+    // fill in the exposed y-border with 0.0
+    int pix = (dyi > 0) ? 0 : ny - abs(dyi);
+    for (int j = 0; j < abs(dyi); j++, pix++) {
+        for (int i = 0; i < nx; i++) {
+            out->data.F32[pix][i] = 0.0;
+        }
+    }
+
+    // apply the fractional shift
+    if ((dxf > 0) || (dyf > 0)) {
+        float value;
+
+        double f00 =    dxf *   dyf;
+        double f01 =    dxf *(1-dyf);
+        double f10 = (1-dxf)*   dyf;
+        double f11 = (1-dxf)*(1-dyf);
+
+        for (int j = ny - 2; j >= 0; j--) {
+            psF32 *V0 = out->data.F32[j+0];
+            psF32 *V1 = out->data.F32[j+1];
+            for (int i = nx - 2; i >= 0; i--, V0--, V1--) {
+                value  = V0[0] * f00;
+                value += V0[1] * f10;
+                value += V1[0] * f01;
+                value += V1[1] * f11;
+                V1[1] = value;
+            }
+        }
+    }
+    return out;
+}
+
 // return source aperture magnitude
+// interpolate the image pixels to place the center at xi+0.5,yi+0.5
 bool pmSourcePhotometryAper (float *apMag, pmModel *model, psImage *image, psImage *mask)
 {
@@ -199,4 +264,14 @@
     }
 
+    // shift image to have centroid at xi+0.5, yi+0.5
+    # if (1)
+        float dx = 0.5 - model->params->data.F32[PM_PAR_XPOS] + (int)model->params->data.F32[PM_PAR_XPOS];
+    float dy = 0.5 - model->params->data.F32[PM_PAR_YPOS] + (int)model->params->data.F32[PM_PAR_YPOS];
+    psImage *tmpImage = tmp_psImageShift (image, dx, dy);
+    # else
+
+        psImage *tmpImage = psImageCopy (NULL, image, PS_TYPE_F32);
+    # endif
+
     // measure apMag
     for (int ix = 0; ix < image->numCols; ix++) {
@@ -204,7 +279,8 @@
             if (mask->data.U8[iy][ix])
                 continue;
-            apSum += image->data.F32[iy][ix] - sky;
-        }
-    }
+            apSum += tmpImage->data.F32[iy][ix] - sky;
+        }
+    }
+    psFree (tmpImage);
     if (apSum <= 0)
         return false;
Index: /trunk/psModules/src/objects/pmSourcePhotometry.h
===================================================================
--- /trunk/psModules/src/objects/pmSourcePhotometry.h	(revision 9842)
+++ /trunk/psModules/src/objects/pmSourcePhotometry.h	(revision 9843)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA; GLG, MHPCC
  *
- *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-10-13 02:24:34 $
+ *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-11-03 15:21:15 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -51,3 +51,5 @@
 bool pmSourcePixelWeight (float *pixWeight, pmModel *model, psImage *image, psImage *mask);
 
+psImage *tmp_psImageShift (psImage *in, float dx, float dy);
+
 # endif /* PM_SOURCE_PHOTOMETRY_H */
