Index: trunk/psastro/src/psastroLoadGhosts.c
===================================================================
--- trunk/psastro/src/psastroLoadGhosts.c	(revision 41434)
+++ trunk/psastro/src/psastroLoadGhosts.c	(revision 41657)
@@ -120,5 +120,5 @@
 
     //We need to check whether we are dealing with an old style ghost_model, or a new style model. Check if the mirror_rad polynomial exists
-    float mirCheck = 0;
+    int mirCheck = 0;
     md = psMetadataLookupMetadata (&status, ghostModel, "GHOST.MIRROR.RAD"); 
     if (!md) { psLogMsg ("psastro", PS_LOG_INFO, "No ghost mirror_rad polynomial found. Assuming old-style ghost masking"); } 
@@ -144,4 +144,14 @@
     pmFPA *fpa = astrom->fpa;
 
+    // select the reference mask fpa :: we use this to determine cell boundaries
+    pmFPAfile *refMask = psMetadataLookupPtr (NULL, config->files, "PSASTRO.REFMASK");
+    if (!refMask) {
+      psError(PSASTRO_ERR_CONFIG, true, "Can't find mask reference");
+      return false;
+    }
+    // Activate the reference mask to generate an FPA structure we can use to map stars down to cells
+    pmFPAfileActivate (config->files, false, NULL);
+    pmFPAfileActivate (config->files, true, "PSASTRO.REFMASK");
+
     // raise an error if the config is broken
     if (!psastroZeroPointFromRecipe (&zeropt, &exptime, &INSTR_MAX_MAG, NULL, fpa, recipe)) {
@@ -161,4 +171,14 @@
         if (!chip->fromFPA) { continue; }
 
+        // Get the current chip's name, and parse out the grid location.
+        pmChip *refChip  = pmFPAviewThisChip (view, refMask->fpa);
+        const char *chipName = psMetadataLookupStr(NULL,refChip->concepts, "CHIP.NAME");
+        int X = chipName[2] - '0';
+        int Y = chipName[3] - '0';
+
+        //Check if we are in the central 8 chips, where old ghost-style locations work better
+        int cenChip = 0;
+        if ( (Y >= 3)&&(Y <=4)&&(X >= 2)&&(X <= 5) ) {cenChip = 0;}
+
         while ((cell = pmFPAviewNextCell (view, fpa, 1)) != NULL) {
             psTrace ("psastro", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
@@ -188,7 +208,7 @@
 
 		    double rSrc = hypot (cal->FP->x, cal->FP->y);
-     	            double theta0 = atan2(cal->FP->x,cal->FP->y);
-
-                    if(mirCheck) {
+     	            double theta0 = atan2(cal->FP->y,cal->FP->x);
+
+                    if((mirCheck) & (!cenChip)) {
                          //TdB: first mirror the reference star positions (around the 0,0 pixel) using the radial offset coefficients and the ghost/star angle
 		        double ghost_offset_rad = psPolynomial1DEval (mirrorRad, rSrc);
@@ -200,5 +220,5 @@
 		        ghost->FP->y = ghost_y_fpa_mirror + psPolynomial2DEval(centerY, ghost_x_fpa_mirror, ghost_y_fpa_mirror);
                     }  
-                    if(!mirCheck) {
+                    if((!mirCheck) | cenChip) {
                         //Use the old-style ghost position determination
                         ghost->FP->x = -cal->FP->x + psPolynomial2DEval(centerX, -cal->FP->x, -cal->FP->y);
@@ -312,5 +332,5 @@
      	            double theta0 = atan2(ref->FP->y,ref->FP->x);
 
-                    if(mirCheck) {
+                    if((mirCheck) & (!cenChip)) {
                          //TdB: first mirror the reference star positions (around the 0,0 pixel) using the radial offset coefficients and the ghost/star angle
 		        double ghost_offset_rad = psPolynomial1DEval (mirrorRad, rSrc);
@@ -322,5 +342,5 @@
 		        ghost->FP->y = ghost_y_fpa_mirror + psPolynomial2DEval(centerY, ghost_x_fpa_mirror, ghost_y_fpa_mirror);
                     }  
-                    if(!mirCheck) {
+                    if((!mirCheck) | cenChip) {
                         //Use the old-style ghost position determination
                         ghost->FP->x = -ref->FP->x + psPolynomial2DEval(centerX, -ref->FP->x, -ref->FP->y);
