Index: trunk/ippconfig/gpc1/pswarp.config
===================================================================
--- trunk/ippconfig/gpc1/pswarp.config	(revision 39980)
+++ trunk/ippconfig/gpc1/pswarp.config	(revision 39981)
@@ -3,2 +3,3 @@
 BKG.XGRID		S32	50
 BKG.YGRID		S32	50
+ADDITIONAL_WCS_ORDERS   S32     4               # By default, use a bilevel astrometric model with 4 additional orders.
Index: trunk/ippconfig/recipes/pswarp.config
===================================================================
--- trunk/ippconfig/recipes/pswarp.config	(revision 39980)
+++ trunk/ippconfig/recipes/pswarp.config	(revision 39981)
@@ -25,4 +25,6 @@
 BKG.YGRID              S32    4
 
+ADDITIONAL_WCS_ORDERS S32     4              # By default, use a bilevel astrometric model with 4 additional orders.
+
 # Default recipe for warping
 WARP	METADATA
Index: trunk/psModules/src/astrom/pmAstrometryWCS.c
===================================================================
--- trunk/psModules/src/astrom/pmAstrometryWCS.c	(revision 39980)
+++ trunk/psModules/src/astrom/pmAstrometryWCS.c	(revision 39981)
@@ -695,5 +695,13 @@
     // the region defines the FPA pixels covered by the tranformation
     psFree (fpa->fromTPA);
-    psPlaneTransform *myPT = psPlaneTransformAlloc(fpa->toTPA->x->nX+4, fpa->toTPA->x->nY+4);
+
+    int additional_orders = 4;  // This is the number of orders that should be added.
+    bool status = false;
+    int config_additional_orders = psMetadataLookupS32(&status,fpa->analysis, "ADDITIONAL_WCS_ORDERS");
+    if (status) { // If this keyword is found, then use that number of orders instead
+      additional_orders = config_additional_orders; 
+    }
+    
+    psPlaneTransform *myPT = psPlaneTransformAlloc(fpa->toTPA->x->nX+additional_orders, fpa->toTPA->x->nY+additional_orders);
     fpa->fromTPA = psPlaneTransformInvert(myPT, fpa->toTPA, region, 50);
     psFree (myPT);
Index: trunk/pswarp/src/pswarpLoadAstrometry.c
===================================================================
--- trunk/pswarp/src/pswarpLoadAstrometry.c	(revision 39980)
+++ trunk/pswarp/src/pswarpLoadAstrometry.c	(revision 39981)
@@ -96,4 +96,14 @@
     // apply the bilevel astrometry elements to the target
     if (bilevelAstrometry) {
+      int additional_orders = 4;
+      bool status = false;
+      int config_additional_orders = psMetadataLookupS32(&status,config->arguments,"ADDITIONAL_WCS_ORDERS");
+      if (status) {
+	additional_orders = config_additional_orders;
+      }
+      psMetadataAddS32(astrom->fpa->analysis,PS_LIST_TAIL, "ADDITIONAL_WCS_ORDERS", PS_META_REPLACE,
+		       "Additional orders for bilevel fit.", additional_orders);
+      
+	
 	if (!pmAstromReadBilevelMosaic(astrom->fpa, phu->header)) {
 	    psError(psErrorCodeLast(), false, "Unable to read bilevel mosaic astrometry for skycell.");
Index: trunk/pswarp/src/pswarpOptions.c
===================================================================
--- trunk/pswarp/src/pswarpOptions.c	(revision 39980)
+++ trunk/pswarp/src/pswarpOptions.c	(revision 39981)
@@ -92,4 +92,12 @@
     }
 
+    // See if we should use a more accurate WCS model.
+    int config_additional_orders = psMetadataLookupS32(&status,recipe, "ADDITIONAL_WCS_ORDERS");
+    if (!status) {
+      // We did not find this recipe option.  We are likely updating an old config.
+      config_additional_orders = 0;
+    }
+    
+
     
     // Set recipe values in the recipe (since we've possibly altered some)
@@ -114,4 +122,5 @@
     psMetadataAddS32(config->arguments, PS_LIST_TAIL, "BKG.XGRID", PS_META_REPLACE, "Xsize of background model", bkgXgrid);
     psMetadataAddS32(config->arguments, PS_LIST_TAIL, "BKG.YGRID", PS_META_REPLACE, "Ysize of background model", bkgYgrid);
+    psMetadataAddS32(config->arguments, PS_LIST_TAIL, "ADDITIONAL_WCS_ORDERS", PS_META_REPLACE, "Additional orders for bilevel fit.", config_additional_orders);
 
     psTrace("pswarp", 1, "Done with pswarpOptions...\n");
