Index: trunk/psastro/src/psastroModelAdjust.c
===================================================================
--- trunk/psastro/src/psastroModelAdjust.c	(revision 21409)
+++ trunk/psastro/src/psastroModelAdjust.c	(revision 39926)
@@ -28,4 +28,6 @@
     }
 
+
+    
     // if we have not measured the boresite position, no adjustment is needed
     bool fitBoresite = psMetadataLookupBool (&status, recipe, "PSASTRO.MODEL.FIT.BORESITE");
@@ -52,5 +54,14 @@
 	return false; 
     } 
-
+    float refChipAngleNominal = PS_RAD_DEG*psMetadataLookupF32 (&status, recipe, "PSASTRO.MODEL.REF.CHIP.ANGLE");
+    if (!refChipName) {
+	psError(PS_ERR_IO, true, "reference chip is missing from recipe"); 
+	return false; 
+    } 
+
+    int rotatorParity = psMetadataLookupS32(&status, recipe, "PSASTRO.MODEL.ROT.PARITY");
+    if (!status) psAbort ("Can't find recipe option PSASTRO.MODEL.ROT.PARITY");
+    psMetadataAddS32 (output->fpa->concepts, PS_LIST_TAIL, "FPA.ROT_PARITY", PS_META_REPLACE, "rotator parity parameter", rotatorParity);
+    
     // get reference chip from name
     pmChip *refChip = pmConceptsChipFromName (output->fpa, refChipName);
@@ -81,11 +92,18 @@
 	psFree (PT);
     }
-
+    
     // rotate the chip-to-FPA transforms to have 0.0 posangle for refChip; 
     // compensate by rotating fpa to TPA transform
 
     // get the current posangle of the ref chip
-    float chipAngle = atan2 (refChip->toFPA->y->coeff[1][0], refChip->toFPA->x->coeff[1][0]);
-    fprintf (stderr, "chipAngle: %f\n", chipAngle*PS_DEG_RAD);
+    // this should have a negative sign : chipAngle = -atan2 (dM/dy, dM/dx)
+    float chipAngle = -atan2 (refChip->toFPA->y->coeff[1][0], refChip->toFPA->x->coeff[1][0]);
+
+    // chipAngle should be refChipAngleNominal @ POSANGLE = 0.0
+    float posAngleOffset = rotatorParity * (chipAngle - refChipAngleNominal);
+
+    fprintf (stderr, "chipAngle is: %f, at PA = 0.0, it should be %f, rotating model by %f (parity %d)\n", 
+	     chipAngle*PS_DEG_RAD, refChipAngleNominal*PS_DEG_RAD, posAngleOffset*PS_DEG_RAD, rotatorParity);
+
     // psMetadataAddF32 (output->fpa->concepts, PS_LIST_TAIL, "FPA.POSANGLE", PS_META_REPLACE, "boresite parameter", posangle);
 
@@ -99,9 +117,11 @@
 	psRegion *region = pmChipPixels (chip);
 
-	psPlaneTransform *toFPA = psPlaneTransformRotate (NULL, chip->toFPA, chipAngle);
+	// this should ALSO have a negative sign: this rotates by +posAngleOffset
+	psPlaneTransform *toFPA = psPlaneTransformRotate (NULL, chip->toFPA, posAngleOffset);
 	psFree (chip->toFPA);
 	chip->toFPA = toFPA;
 
 	// invert the new fromFPA transform to get the new toFPA transform
+	// NOTE: when we call psPlaneTransformInvert here, we do not increase the order as in other places
 	psPlaneTransform *fromFPA = psPlaneTransformInvert(NULL, chip->toFPA, *region, 50);
 	psFree (chip->fromFPA);
@@ -125,4 +145,5 @@
 
     psFree (output->fpa->fromTPA);
+    // NOTE: when we call psPlaneTransformInvert here, we do not increase the order as in other places
     output->fpa->fromTPA = psPlaneTransformInvert(NULL, output->fpa->toTPA, *fpaRegion, 50);
 
@@ -131,4 +152,5 @@
 
     psMetadata *header = output->fpa->hdu->header;
+    
     pmAstromWriteBilevelMosaic (header, output->fpa, NONLIN_TOL);
 
@@ -172,4 +194,5 @@
 	// invert the new fromFPA transform to get the new toFPA transform
 	// the region used here is the region covered by the chip in the FPA
+	// NOTE: when we call psPlaneTransformInvert here, we do not increase the order as in other places
 	psPlaneTransform *fromFPA = psPlaneTransformInvert(NULL, chip->toFPA, *region, 50); 
 	psFree (chip->fromFPA);
