Index: /branches/eam_branches/ipp-20150112/Ohana/src/uniphot/include/setastrom.h
===================================================================
--- /branches/eam_branches/ipp-20150112/Ohana/src/uniphot/include/setastrom.h	(revision 37909)
+++ /branches/eam_branches/ipp-20150112/Ohana/src/uniphot/include/setastrom.h	(revision 37910)
@@ -15,6 +15,7 @@
   int Nvalues;
   int Nfilters; // number of filters
-  int Nx; // number of chips in x
-  int Ny; // number of chips in y
+  int NchipX;   // number of chips in x
+  int NchipY;   // number of chips in y
+  int NxCCD;	// number of pixels
   Matrix **matrix; // allocate an array of pointers
   // index = ix + iy*Nx + filter*Nx*Ny + dir*Nx*Ny*Nfilter
Index: /branches/eam_branches/ipp-20150112/Ohana/src/uniphot/src/cam_correction.c
===================================================================
--- /branches/eam_branches/ipp-20150112/Ohana/src/uniphot/src/cam_correction.c	(revision 37909)
+++ /branches/eam_branches/ipp-20150112/Ohana/src/uniphot/src/cam_correction.c	(revision 37910)
@@ -40,6 +40,15 @@
   if (!gfits_scan (&theader, "NX_CHIP", "%d", 1, &Nx)) 	    return (NULL);
   if (!gfits_scan (&theader, "NY_CHIP", "%d", 1, &Ny)) 	    return (NULL);
+  if (!gfits_scan (&theader, "DX_CHIP", "%d", 1, &dX)) 	    return (NULL);
+  if (!gfits_scan (&theader, "DY_CHIP", "%d", 1, &dY)) 	    return (NULL);
 
   ALLOCATE (cam->matrix, Matrix *, Ndir*Nfilter*Nx*Ny);
+
+  cam->Nx      = Nx;  	   // for gpc1, should be 8
+  cam->Ny      = Ny;  	   // for gpc1, should be 8
+  cam->dX      = dX;  	   // superpixel sampling, x-dir
+  cam->dY      = dY;  	   // superpixel sampling, y-dir
+  cam->Ndir    = Ndir;     // for gpc1, should be 2
+  cam->Nfilter = Nfilter;  // for gpc1, should be 5
 
   while (TRUE) {
@@ -66,22 +75,26 @@
 }
 
-int get_kh_correction (int sub, int chip, double *dX, double *dY, float Minst) {
-
-  Spline *spline = NULL;
+int get_cam_correction (CamCorrection *cam, int chip, int filter, double *dX, double *dY, float Xccd, float Yccd) {
 
   *dX = 0.0;
   *dY = 0.0;
 
-  // XXX need to include some limits on Minst?
+  // split out the chip number (eg 43 for XY43) into X and Y elements
+  int ix = (int) (chip / 10);
+  int iy = (int) (chip % 10);
 
-  spline = splineset[sub][0][chip];
-  if (spline) {
-    *dX = spline_apply_dbl (spline->xk, spline->yk, spline->y2, spline->Nknots, Minst);
-  }
+  int dir = 0; // dX
+  int index = ix + iy*cam->Nx + filter*cam->Nx*cam->Ny + dir*cam->Nx*cam->Ny*cam->Nfilter;
 
-  spline = splineset[sub][1][chip];
-  if (spline) {
-    *dY = spline_apply_dbl (spline->xk, spline->yk, spline->y2, spline->Nknots, Minst);
-  }
+  Matrix *matrix = cam->matrix[index];
+
+  float *buffer = (float *) matrix->buffer;
+
+  int jx = MAX(MIN(Nx, Xccd / cam->dX), 0);
+  int jy = MAX(MIN(Nx, Yccd / cam->dY), 0);
+
+  float value = buffer[jx + jy*Nx];
+
+  *dX = isnan(value) ? 0.0 : value;
   return (TRUE);
 }
