Index: /branches/czw_branch/20120906/pswarp/src/pswarp.c
===================================================================
--- /branches/czw_branch/20120906/pswarp/src/pswarp.c	(revision 34488)
+++ /branches/czw_branch/20120906/pswarp/src/pswarp.c	(revision 34489)
@@ -47,5 +47,4 @@
     }
     if (psMetadataLookupBool(NULL,config->arguments,"BACKGROUND.MODEL")) {
-      fprintf(stderr,"Here!\n");
       if (!pswarpDefineBackground(config)) {
 	goto DIE;
@@ -74,5 +73,4 @@
     }
     if (psMetadataLookupBool(NULL,config->arguments,"BACKGROUND.MODEL")) {
-      fprintf(stderr,"There!\n");
       if (!pswarpLoopBackground(config, stats)) {
 	fprintf(stderr,"Dying!\n");
Index: /branches/czw_branch/20120906/pswarp/src/pswarp.h
===================================================================
--- /branches/czw_branch/20120906/pswarp/src/pswarp.h	(revision 34488)
+++ /branches/czw_branch/20120906/pswarp/src/pswarp.h	(revision 34489)
@@ -62,4 +62,9 @@
     psImage *region;
 
+    /** values which are needed to control the background model warping. */
+    bool background_warping;
+    double offset_x;
+    double offset_y;
+  
     /** input values for this tile */
     int gridX;
Index: /branches/czw_branch/20120906/pswarp/src/pswarpLoop.c
===================================================================
--- /branches/czw_branch/20120906/pswarp/src/pswarpLoop.c	(revision 34488)
+++ /branches/czw_branch/20120906/pswarp/src/pswarpLoop.c	(revision 34489)
@@ -605,11 +605,39 @@
         }
 
+	// Pull information from the header of the background files so we can use it to set values.
+	pmHDU *hdu = pmFPAviewThisHDU(view,input->fpa);
+	psMetadata *header = hdu->header;
+	
+	int IMAXIS1 = psMetadataLookupS32(NULL,header,"IMNAXIS1");
+	int IMAXIS2 = psMetadataLookupS32(NULL,header,"IMNAXIS2");
+	int NAXIS1 = psMetadataLookupS32(NULL,header,"NAXIS1");
+	int NAXIS2 = psMetadataLookupS32(NULL,header,"NAXIS2");
+	char *CCDSUM = psMetadataLookupStr(NULL,header,"CCDSUM");
+	int CCDSUM1 = atoi(strtok(CCDSUM," "));
+	int CCDSUM2 = atoi(strtok(NULL," "));
+	
+	psMetadataAddF32(config->arguments,PS_LIST_TAIL,"BKG_WARP_XOFFSET", PS_META_REPLACE,
+			 "xoffset for background model data", (NAXIS1 * CCDSUM1 - IMAXIS1) / (2.0 * CCDSUM1));
+	psMetadataAddF32(config->arguments,PS_LIST_TAIL,"BKG_WARP_YOFFSET", PS_META_REPLACE,
+			 "yoffset for background model data", (NAXIS2 * CCDSUM2 - IMAXIS2) / (2.0 * CCDSUM2));
+	psTrace("pswarp",5,"%d %d %d %d %d %d %g %g %d %d",
+		psMetadataLookupS32(NULL,header,"IMNAXIS1"),
+		psMetadataLookupS32(NULL,header,"IMNAXIS2"),
+		psMetadataLookupS32(NULL,header,"NAXIS1"),
+		psMetadataLookupS32(NULL,header,"NAXIS2"),
+		CCDSUM1,CCDSUM2,
+		psMetadataLookupF32(NULL,config->arguments,"BKG_WARP_XOFFSET"),
+		psMetadataLookupF32(NULL,config->arguments,"BKG_WARP_YOFFSET"),
+		psMetadataLookupS32(NULL,config->arguments,"BKG.XGRID"),
+		psMetadataLookupS32(NULL,config->arguments,"BKG.YGRID"));
+	
+	
         // read WCS data from the corresponding header
-        pmHDU *hdu = pmFPAviewThisHDU (view, astrom->fpa);
+        hdu = pmFPAviewThisHDU (view, astrom->fpa);
 
 	pmAstromWCS *WCS = pmAstromWCSfromHeader(hdu->header);
 
-	double cd1f = 1.0 * 400;
-	double cd2f = 1.0 * 400;
+	double cd1f = (1.0 * CCDSUM1);// * (1.0 * psMetadataLookupS32(NULL,config->arguments,"BKG.XGRID"));
+	double cd2f = (1.0 * CCDSUM2);// * (1.0 * psMetadataLookupS32(NULL,config->arguments,"BKG.YGRID"));
 
 	WCS->cdelt1 *= cd1f;
@@ -681,9 +709,9 @@
 		
 		psMetadataAddS32(config->arguments,PS_LIST_TAIL, "INTERPOLATION.MODE", PS_META_REPLACE, "", 8);
-		fprintf(stderr,"Transforming Readout!\n");
 
 		psMetadataAddBool(config->arguments,PS_LIST_TAIL, "BACKGROUND_WARPING", PS_META_REPLACE, "", true);
                 pswarpTransformReadout(output, readout, config);
 		psMetadataAddBool(config->arguments,PS_LIST_TAIL, "BACKGROUND_WARPING", PS_META_REPLACE, "", false);
+
                 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
                     psError(psErrorCodeLast(), false, "Unable to write files.");
@@ -701,5 +729,4 @@
         }
     }
-    fprintf(stderr,"End readout transformations!\n");
     if (!output->data_exists) {
         psWarning("No overlap between input and skycell.");
Index: /branches/czw_branch/20120906/pswarp/src/pswarpTransformReadout.c
===================================================================
--- /branches/czw_branch/20120906/pswarp/src/pswarpTransformReadout.c	(revision 34488)
+++ /branches/czw_branch/20120906/pswarp/src/pswarpTransformReadout.c	(revision 34489)
@@ -132,4 +132,11 @@
             args->goodPixels = 0;
 
+	    if (psMetadataLookupBool(NULL,config->arguments,"BACKGROUND_WARPING")) {
+	      args->background_warping = true;
+	      args->offset_x = psMetadataLookupF32(NULL,config->arguments,"BKG_WARP_XOFFSET");
+	      args->offset_y = psMetadataLookupF32(NULL,config->arguments,"BKG_WARP_YOFFSET");
+	    }
+
+	    
             // allocate a job
             psThreadJob *job = psThreadJobAlloc ("PSWARP_TRANSFORM_TILE");
@@ -184,4 +191,6 @@
                 jacobian += args->jacobian * args->goodPixels;
             }
+
+	    
         }
         psFree(job);
Index: /branches/czw_branch/20120906/pswarp/src/pswarpTransformTile.c
===================================================================
--- /branches/czw_branch/20120906/pswarp/src/pswarpTransformTile.c	(revision 34488)
+++ /branches/czw_branch/20120906/pswarp/src/pswarpTransformTile.c	(revision 34489)
@@ -46,4 +46,8 @@
     args->jacobian = NAN;
 
+    args->background_warping = false;
+    args->offset_x = 0.0;
+    args->offset_y = 0.0;
+    
     return args;
 }
@@ -96,17 +100,18 @@
 
 	    // This needs to use a more reliable method to do this offset and limiting
-	    if (args->interp->mode == 8) {
-	      double xOffset = 177.0 / 400.0; // (modelsize * modelbinning - xsize) / 2.0
-	      double yOffset = 166.0 / 400.0; // (modelsize * modelbinning - ysize) / 2.0
-	      xIn += xOffset;
-	      yIn += yOffset;
+	    //	    if (args->interp->mode == 8) {
+	    if (args->background_warping) {
+	      //	      double xOffset = 177.0 / 400.0; // (modelsize * modelbinning - xsize) / 2.0
+	      //	      double yOffset = 166.0 / 400.0; // (modelsize * modelbinning - ysize) / 2.0
+	      xIn += args->offset_x;
+	      yIn += args->offset_y;
 
-	      if ((xIn > inNumCols - xOffset)||
-		  (yIn > inNumRows - yOffset)||
-		  (xIn < xOffset)||
-		  (yIn < yOffset)) {
+	      if ((xIn > inNumCols - args->offset_x)||
+		  (yIn > inNumRows - args->offset_y)||
+		  (xIn < args->offset_x)||
+		  (yIn < args->offset_y)) {
 		continue;
 	      }
-	    }		
+	    }
 	    
             if (xIn < 0 || xIn >= inNumCols || yIn < 0 || yIn >= inNumRows) {
