Index: trunk/psModules/src/astrom/pmAstrometryWCS.c
===================================================================
--- trunk/psModules/src/astrom/pmAstrometryWCS.c	(revision 41810)
+++ trunk/psModules/src/astrom/pmAstrometryWCS.c	(revision 41892)
@@ -501,4 +501,6 @@
     psPlaneTransform *toFPA;
 
+    int ExtraOrders = pmAstrometryGetExtraOrders();
+
     // create transformation with 0,0 reference pixel and units of degrees/pixel
     toFPA = psPlaneTransformSetCenter (NULL, wcs->trans, -wcs->crpix1, -wcs->crpix2);
@@ -552,5 +554,5 @@
         // apply the exiting fromTPA transformation to make the new toFPA consistent with the toTPA layter
         // XXX this only works if toTPA is at most a linear transformation
-        psPlaneTransform *toFPAnew = psPlaneTransformAlloc(toFPA->x->nX, toFPA->x->nY);
+        psPlaneTransform *toFPAnew = psPlaneTransformAlloc(toFPA->x->nX, toFPA->x->nY, PS_POLYNOMIAL_ORD);
         for (int i = 0; i <= toFPA->x->nX; i++) {
             for (int j = 0; j <= toFPA->x->nY; j++) {
@@ -608,5 +610,5 @@
     // as of r40806, psPlaneTransformInvert supplies the extra order (if non-linear)
     psFree (chip->fromFPA);
-    chip->fromFPA = psPlaneTransformInvert(NULL, chip->toFPA, *region, 100, 6);
+    chip->fromFPA = psPlaneTransformInvert(NULL, chip->toFPA, *region, 50, ExtraOrders);
     psFree (region);
 
@@ -648,9 +650,11 @@
      */
 
+    int ExtraOrders = pmAstrometryGetExtraOrders();
+
     psFree (chip->toFPA);
     if ((fabs(wcs->crpix1) > 0.01) || (fabs(wcs->crpix2) > 0.01)) {
       chip->toFPA = psPlaneTransformSetCenter (NULL, wcs->trans, -wcs->crpix1, -wcs->crpix2);
     } else {
-      chip->toFPA = psPlaneTransformAlloc(wcs->trans->x->nX, wcs->trans->x->nY);
+      chip->toFPA = psPlaneTransformAlloc(wcs->trans->x->nX, wcs->trans->x->nY, PS_POLYNOMIAL_ORD);
 
       // copy the toFPA x,y, transformations to the wcs version
@@ -668,5 +672,5 @@
     // as of r40806, psPlaneTransformInvert supplies the extra order (if non-linear)
     psFree (chip->fromFPA);
-    chip->fromFPA = psPlaneTransformInvert(NULL, chip->toFPA, *region, 100, 6);
+    chip->fromFPA = psPlaneTransformInvert(NULL, chip->toFPA, *region, 50, ExtraOrders);
     psFree (region);
 
@@ -700,5 +704,5 @@
     // the region defines the FPA pixels covered by the tranformation
     psFree (fpa->fromTPA);
-    int additional_orders = 4;  // This is the number of orders that should be added.
+    int additional_orders = pmAstrometryGetExtraOrders();  // This is the number of orders that should be added.
     bool status = false;
     int config_additional_orders = psMetadataLookupS32(&status,fpa->analysis, "ADDITIONAL_WCS_ORDERS");
@@ -706,5 +710,5 @@
       additional_orders = config_additional_orders; 
     }
-    fpa->fromTPA = psPlaneTransformInvert(NULL, fpa->toTPA, region, 100, additional_orders);
+    fpa->fromTPA = psPlaneTransformInvert(NULL, fpa->toTPA, region, 50, additional_orders);
     return true;
 }
@@ -739,5 +743,5 @@
     // XXX require fpa->toTPA->nX == 1
 
-    psPlaneTransform *toTPA = psPlaneTransformAlloc(chip->toFPA->x->nX, chip->toFPA->x->nY);
+    psPlaneTransform *toTPA = psPlaneTransformAlloc(chip->toFPA->x->nX, chip->toFPA->x->nY, PS_POLYNOMIAL_ORD);
 
     for (int i = 0; i <= toTPA->x->nX; i++) {
@@ -958,5 +962,5 @@
     }
 
-    psPlaneTransform *newTrans = psPlaneTransformAlloc(1, 1);
+    psPlaneTransform *newTrans = psPlaneTransformAlloc(1, 1, PS_POLYNOMIAL_ORD);
 
     if (!psPlaneTransformFit(newTrans, src, dst, 0, 0)) {
@@ -997,4 +1001,6 @@
     PS_ASSERT_PTR_NON_NULL(inChip, NULL);
 
+    int ExtraOrders = pmAstrometryGetExtraOrders();
+
     if (outFPA == NULL) {
         outFPA = inFPA;
@@ -1032,5 +1038,5 @@
 
     // NOTE: the extraOrders value (4) should be ignored since outToFPA is specified to be linear
-    psPlaneTransform *outFromFPA = psPlaneTransformInvert(NULL, outToFPA, *outputBounds, 100, 6);
+    psPlaneTransform *outFromFPA = psPlaneTransformInvert(NULL, outToFPA, *outputBounds, 50, ExtraOrders);
     if (!outFromFPA) {
         psFree(outToFPA);
@@ -1116,5 +1122,5 @@
     }
 
-    psPlaneTransform *newToFPA = psPlaneTransformAlloc(1, 1);
+    psPlaneTransform *newToFPA = psPlaneTransformAlloc(1, 1, PS_POLYNOMIAL_ORD);
     newToFPA->x->coeffMask[1][1] = 1;
     newToFPA->y->coeffMask[1][1] = 1;
@@ -1148,5 +1154,5 @@
     psFree(dst);
 
-    // this is a linear transformation
+    // this is a linear transformation, no extra orders are needed
     psPlaneTransform *newFromFPA = psPlaneTransformInvert(NULL, newToFPA, *bounds, 1, 0);
     if (!newFromFPA) {
@@ -1187,5 +1193,6 @@
     psMemSetDeallocator(wcs, (psFreeFunc) pmAstromWCSFree);
 
-    wcs->trans = psPlaneTransformAlloc (nXorder, nYorder);
+    // note: WCS transforms are always defined as chip to sky
+    wcs->trans = psPlaneTransformAlloc (nXorder, nYorder, PS_POLYNOMIAL_ORD);
     wcs->toSky = NULL;
     wcs->wcsCDkeys = 0;
