Index: trunk/ippconfig/gpc1/ghost.model.mdc
===================================================================
--- trunk/ippconfig/gpc1/ghost.model.mdc	(revision 41363)
+++ trunk/ippconfig/gpc1/ghost.model.mdc	(revision 41367)
@@ -1,83 +1,25 @@
-# Original center models
-# GHOST.CENTER.X METADATA
-#   NORDER_X S32 3
-#   NORDER_Y S32 3
-#   VAL_X00_Y00  F64 -4.421024e+01
-#   VAL_X01_Y00  F64 1.216270e-02
-#   VAL_X02_Y00  F64 -9.721643e-08
-#   VAL_X03_Y00  F64 9.976554e-11
-#   VAL_X00_Y01  F64 -1.762476e-03
-#   VAL_X01_Y01  F64 1.247212e-07
-#   VAL_X02_Y01  F64 3.629557e-11
-#   VAL_X00_Y02  F64 -1.040174e-07
-#   VAL_X01_Y02  F64 1.074674e-10
-#   VAL_X00_Y03  F64 1.564112e-11
-#   NELEMENTS  S32 10
-# END
+# TdB20200522 ghost model fit for gpc1
+#Inner radii are left from the default gpc1 values
 
-# GHOST.CENTER.Y METADATA
-#   NORDER_X S32 3
-#   NORDER_Y S32 3
-#   VAL_X00_Y00  F64 -2.189470e+00
-#   VAL_X01_Y00  F64 -4.186514e-03
-#   VAL_X02_Y00  F64 1.131554e-07
-#   VAL_X03_Y00  F64 1.415192e-11
-#   VAL_X00_Y01  F64 1.569104e-02
-#   VAL_X01_Y01  F64 -1.782801e-07
-#   VAL_X02_Y01  F64 8.179602e-11
-#   VAL_X00_Y02  F64 2.577055e-07
-#   VAL_X01_Y02  F64 8.879423e-11
-#   VAL_X00_Y03  F64 5.767429e-11
-#   NELEMENTS  S32 10
-# END
+GHOST.MIRROR.RAD METADATA
+  NORDER_X S32 1
+  VAL_X00  F64 -329.27244159
+  VAL_X01  F64 2.0664288
+  NELEMENTS  S32 2
+END
 
-# Updated models of 2012-05-07
-# Corrected(?) parity
-# GHOST.CENTER.X METADATA
-#   NORDER_X S32 3
-#   NORDER_Y S32 3
-#   VAL_X00_Y00  F64  3.314569e+01
-#   VAL_X01_Y00  F64  1.110664e-02
-#   VAL_X02_Y00  F64 -1.904158e-07
-#   VAL_X03_Y00  F64  8.470224e-11
-#   VAL_X00_Y01  F64 -1.616877e-03
-#   VAL_X01_Y01  F64  1.646508e-07
-#   VAL_X02_Y01  F64  5.623381e-11
-#   VAL_X00_Y02  F64 -2.342888e-07
-#   VAL_X01_Y02  F64  1.023761e-10
-#   VAL_X00_Y03  F64  2.836980e-11
-#   NELEMENTS  S32 10
-# END
-
-# GHOST.CENTER.Y METADATA
-#   NORDER_X S32 3
-#   NORDER_Y S32 3
-#   VAL_X00_Y00  F64 -2.860068e+01
-#   VAL_X01_Y00  F64 -8.790076e-03
-#   VAL_X02_Y00  F64  2.456534e-07
-#   VAL_X03_Y00  F64  2.947749e-11
-#   VAL_X00_Y01  F64  1.948855e-02
-#   VAL_X01_Y01  F64 -2.639927e-07
-#   VAL_X02_Y01  F64  4.951474e-11
-#   VAL_X00_Y02  F64  4.341716e-07
-#   VAL_X01_Y02  F64  1.643046e-10
-#   VAL_X00_Y03  F64 -1.737983e-12
-#   NELEMENTS  S32 10
-# END
-
-# Switched order
 GHOST.CENTER.X METADATA
   NORDER_X S32 3
   NORDER_Y S32 3
-  VAL_X00_Y00  F64 -1.215661e+02
-  VAL_X01_Y00  F64  1.321875e-02
-  VAL_X02_Y00  F64 -4.017026e-09
-  VAL_X03_Y00  F64  1.148288e-10
-  VAL_X00_Y01  F64 -1.908074e-03
-  VAL_X01_Y01  F64  8.479150e-08
-  VAL_X02_Y01  F64  1.635732e-11
-  VAL_X00_Y02  F64  2.625405e-08
-  VAL_X01_Y02  F64  1.125586e-10
-  VAL_X00_Y03  F64  2.912432e-12
+  VAL_X00_Y00  F64 -1.67627557e+01
+  VAL_X01_Y00  F64 -1.15377631e-02
+  VAL_X02_Y00  F64 -9.88483348e-08
+  VAL_X03_Y00  F64  4.14561887e-11
+  VAL_X00_Y01  F64 -9.13131313e-05
+  VAL_X01_Y01  F64  1.40192992e-08
+  VAL_X02_Y01  F64  9.78192800e-12
+  VAL_X00_Y02  F64 -9.82584386e-09
+  VAL_X01_Y02  F64  5.48708364e-11
+  VAL_X00_Y03  F64  5.09109210e-13
   NELEMENTS  S32 10
 END
@@ -86,54 +28,17 @@
   NORDER_X S32 3
   NORDER_Y S32 3
-  VAL_X00_Y00  F64  2.422174e+01
-  VAL_X01_Y00  F64  4.170486e-04
-  VAL_X02_Y00  F64 -1.934260e-08
-  VAL_X03_Y00  F64 -1.173657e-12
-  VAL_X00_Y01  F64  1.189352e-02
-  VAL_X01_Y01  F64 -9.256748e-08
-  VAL_X02_Y01  F64  1.140772e-10
-  VAL_X00_Y02  F64  8.123932e-08
-  VAL_X01_Y02  F64  1.328378e-11
-  VAL_X00_Y03  F64  1.170865e-10
+  VAL_X00_Y00  F64  3.44511879e+00
+  VAL_X01_Y00  F64 -1.08538420e-03
+  VAL_X02_Y00  F64 -3.17872409e-08
+  VAL_X03_Y00  F64  5.29317184e-12
+  VAL_X00_Y01  F64 -1.22162715e-02
+  VAL_X01_Y01  F64 -2.30510155e-08
+  VAL_X02_Y01  F64  4.75814089e-11
+  VAL_X00_Y02  F64 -1.28748715e-07
+  VAL_X01_Y02  F64  5.78808885e-12
+  VAL_X00_Y03  F64  5.11500780e-11
   NELEMENTS  S32 10
 END
 
-
-
-# These are semi-major/minor axes
-# These are my (CZW) quadratic solutions
-# GHOST.INNER.MAJOR METADATA
-#   NORDER_X S32 2
-#   VAL_X00  F64 2.2622e+01
-#   VAL_X01  F64 1.3822e-02
-#   VAL_X02  F64 -3.7005e-07
-#   NELEMENTS  S32 3
-# END
-
-# GHOST.INNER.MINOR METADATA
-#   NORDER_X S32 2
-#   VAL_X00  F64 4.9626e+01
-#   VAL_X01  F64 -2.4257e-04
-#   VAL_X02  F64 -1.2007e-07
-#   NELEMENTS  S32 3
-# END
-
-# GHOST.OUTER.MAJOR METADATA
-#   NORDER_X S32 2
-#   VAL_X00  F64 9.6490e+01
-#   VAL_X01  F64 9.4250e-03
-#   VAL_X02  F64 6.5680e-07
-#   NELEMENTS  S32 3
-# END
-
-# GHOST.OUTER.MINOR METADATA
-#   NORDER_X S32 2
-#   VAL_X00  F64 9.5450e+01
-#   VAL_X01  F64 2.8775e-03
-#   VAL_X02  F64 -3.1409e-07
-#   NELEMENTS  S32 3
-# END
-
-# These are the original linear solutions
 GHOST.INNER.MAJOR METADATA
   NORDER_X S32 1
@@ -151,14 +56,15 @@
 
 GHOST.OUTER.MAJOR METADATA
-  NORDER_X S32 1
-  VAL_X00  F64 7.928722e+01
-  VAL_X01  F64 1.722181e-02
-  NELEMENTS  S32 2
+  NORDER_X S32 2
+  VAL_X00  F64 8.99331326e+01
+  VAL_X01  F64 1.17511553e-02
+  VAL_X02  F64 6.21923231e-07
+  NELEMENTS  S32 3
 END
 
 GHOST.OUTER.MINOR METADATA
   NORDER_X S32 1
-  VAL_X00  F64 1.314265e+02
-  VAL_X01  F64 -2.627153e-03
+  VAL_X00  F64 1.36523263e+02
+  VAL_X01  F64 -3.5025434e-03
   NELEMENTS  S32 2
 END
Index: trunk/ippconfig/gpc1/psastro.config
===================================================================
--- trunk/ippconfig/gpc1/psastro.config	(revision 41363)
+++ trunk/ippconfig/gpc1/psastro.config	(revision 41367)
@@ -129,6 +129,6 @@
 DVO.GETSTAR.PHOTCODE        STR      i
 DVO.GETSTAR.MAX.RHO         F32      10000.0
-DVO.GETSTAR.MIN.MAG         F32      12.0
-DVO.GETSTAR.MIN.MAG.INST    F32     -25.0
+DVO.GETSTAR.MIN.MAG         F32      2.0
+DVO.GETSTAR.MIN.MAG.INST    F32     -35.0
 
 # rather than mean, use specified EDGE:
@@ -144,4 +144,5 @@
   PHOTCODE STR g
   GHOST_MAX_MAG                   F32 -16.5
+  GLINT_MAX_MAG                   F32 -23.0
 END
 PHOTCODE.DATA METADATA
@@ -150,4 +151,5 @@
   PHOTCODE STR r
   GHOST_MAX_MAG                   F32 -20.0
+  GLINT_MAX_MAG                   F32 -23.0
 END
 PHOTCODE.DATA METADATA
@@ -155,5 +157,6 @@
   ZEROPT   F32 24.611
   PHOTCODE STR i
-  GHOST_MAX_MAG                   F32 -25.0
+  GHOST_MAX_MAG                   F32 -22.0
+  GLINT_MAX_MAG                   F32 -23.4
 END
 PHOTCODE.DATA METADATA
@@ -161,5 +164,6 @@
   ZEROPT   F32 24.250
   PHOTCODE STR z
-  GHOST_MAX_MAG                   F32 -25.0
+  GHOST_MAX_MAG                   F32 -22.0
+  GLINT_MAX_MAG                   F32 -23.4
 END
 PHOTCODE.DATA METADATA
@@ -167,5 +171,6 @@
   ZEROPT   F32 23.320
   PHOTCODE STR y
-  GHOST_MAX_MAG                   F32 -25.0
+  GHOST_MAX_MAG                   F32 -21.5
+  GLINT_MAX_MAG                   F32 -23.0
 END
 PHOTCODE.DATA METADATA
@@ -173,5 +178,6 @@
   ZEROPT   F32 26.3
   PHOTCODE STR r
-  GHOST_MAX_MAG                   F32 -20.0
+  GHOST_MAX_MAG                   F32 -20.4
+  GLINT_MAX_MAG                   F32 -24.4
 END
 
@@ -180,11 +186,14 @@
 REFSTAR_MASK_SATSTAR_MAG_MAX    F32 -15.0
 REFSTAR_MASK_SATSTAR_MAG_SLOPE  F32  10.15
-# CZW: Original 2010-02-08 position angle offset
-REFSTAR_MASK_SATSTAR_POS_ZERO   F32  -0.798
-# CZW: Updated 2011-02-18 position angle offset. As above, offset 0.5 degree.
-# REFSTAR_MASK_SATSTAR_POS_ZERO   F32  -0.78927
-#REFSTAR_MASK_SATSTAR_POS_ZERO   F32  -0.80237
-#REFSTAR_MASK_SATSTAR_POS_ZERO   F32  -0.81109
-# Length = 10**(SLOPE*(MAG_MAX - InstMag)) - OFFSET
+
+# TdB20200430: Updated satspike position angle offset
+REFSTAR_MASK_SATSTAR_POS_ZERO   F32  -0.79451
+PSASTRO.MODEL.ROT.PARITY      S32     1
+
+#TdB20200229: The size of saturated star circles should be an exponential for gpc2
+#rad(mag) = REFSTAR_MASK_SATSTAR_RAD_OFFSET + REFSTAR_MASK_SATSTAR_EXP**(REFSTAR_MASK_SATSTAR_MAG_MAX-mag)
+REFSTAR_MASK_SATSTAR_MAG_MAX    F32 -11.363
+REFSTAR_MASK_SATSTAR_RAD_OFFSET F32  17.631
+REFSTAR_MASK_SATSTAR_EXP        F32   1.493
 
 REFSTAR_MASK_SATSPIKE_MAG_SLOPE F32  0.096
@@ -203,6 +212,4 @@
 
 
-
-
 REFSTAR_MASK_BLEED              BOOL FALSE
 REFSTAR_MASK_BLEED_MAG_MAX      F32 -15.0
@@ -218,24 +225,27 @@
 # GHOST_MAX_MAG                   F32 -20.0
 
-GLINT_LENGTH_MAG_SLOPE          F32 2500.0
-GLINT_LENGTH_MAG_ZERO           F32 -20.0
-GLINT_WIDTH                     F32  150.0
 REFSTAR_COUNT_GHOSTS            BOOL TRUE
 REFSTAR_MASK_GHOST              BOOL TRUE
-
-# GHOST_CENTER_X_0         	F32   66.2
-# GHOST_CENTER_X_SLOPE         	F32   -0.02454
-# GHOST_CENTER_Y_0         	F32   16.6
-# GHOST_CENTER_Y_SLOPE         	F32   +0.01565
-# 
-# GHOST_INNER_MAJOR_0         	F32   32.9
-# GHOST_INNER_MAJOR_SLOPE         F32   +0.00612
-# GHOST_INNER_MINOR_0         	F32   58.7
-# GHOST_INNER_MINOR_SLOPE         F32   -0.00258
-# 
-# GHOST_OUTER_MAJOR_0         	F32   90.6
-# GHOST_OUTER_MAJOR_SLOPE         F32   +0.01548
-# GHOST_OUTER_MINOR_0         	F32  133.9
-# GHOST_OUTER_MINOR_SLOPE         F32   -0.00288
+PSASTRO.SAVE.GHOSTS             BOOL TRUE  # save ghost positions as table in output smf file
+
+#TdB20200305: The length of glints as function of mag is recomputed for gpc2
+#glint_length(mag) = GLINT_LENGTH_MAG_SLOPE*(GLINT_LENGTH_MAG_ZERO-mag)
+GLINT_LENGTH_MAG_SLOPE          F32 1901.0
+GLINT_LENGTH_MAG_ZERO           F32 -16.8
+#TdB20200308: The length of glints also depends on position off the focal plane (perpendicular to pixel FPA), out to GLINT_LENGTH_POS_CUT
+#glint_length(pos) = GLINT_LENGTH_POS_SLOPE*(GLINT_LENGTH_POS_REF-pos)
+GLINT_LENGTH_POS_SLOPE          F32 0.00019
+GLINT_LENGTH_POS_REF            F32 33821.
+GLINT_LENGTH_POS_CUT            F32 30700.
+GLINT_LENGTH_MIN_FPA            F32 1500.0
+#TdB20200312: The angle that glints have depends on position along the focal plane (parallel to pixel FPA)
+#glint_angle(pos) = GLINT_ANGLE_SLOPE*(GLINT_ANGLE_POS_REF-(pos/1000))
+GLINT_ANGLE_POS_SLOPE           F32  0.07903  
+GLINT_ANGLE_POS_REF             F32 -575.5
+GLINT_WIDTH                     F32  80.0
+
+# save glint positions?
+PSASTRO.SAVE.GLINTS             BOOL TRUE  # save glint positions as table in output smf file
+
 
 PR_RECIPE METADATA
@@ -244,14 +254,15 @@
 
 REFSTAR_MASK_GLINTS		BOOL  TRUE
-GLINT_MAX_MAG                   F32 -21.0
+GLINT_MAX_MAG                   F32 -21.
 GLINT.REGION			MULTI
 
+#TdB20200514: GPC1 does not show any glints coming from the left or right, at all, after searching thousands of images. So, shrinking the bounding boxes to zero.
 GLINT.REGION			METADATA
-  REGION			STR  [-38000:-24000,-20000:+20000]
+  REGION			STR  [-38000:-38000,-20000:+20000]
   GLINT.TYPE                    STR  LEFT
 END
 
 GLINT.REGION			METADATA
-  REGION			STR  [+24000:+38000,-20000:+20000]
+  REGION			STR  [+38000:+38000,-20000:+20000]
   GLINT.TYPE                    STR  RIGHT
 END
Index: trunk/ippconfig/gpc2/ghost.model.mdc
===================================================================
--- trunk/ippconfig/gpc2/ghost.model.mdc	(revision 41363)
+++ trunk/ippconfig/gpc2/ghost.model.mdc	(revision 41367)
@@ -1,5 +1,4 @@
 # TdB20200327 ghost model fit for gpc2
 
-# These are the original linear solutions for gpc1
 GHOST.MIRROR.RAD METADATA
   NORDER_X S32 1
@@ -41,5 +40,4 @@
 END
 
-# These are the original linear solutions for gpc1
 GHOST.INNER.MAJOR METADATA
   NORDER_X S32 1
Index: trunk/ippconfig/gpc2/psastro.config
===================================================================
--- trunk/ippconfig/gpc2/psastro.config	(revision 41363)
+++ trunk/ippconfig/gpc2/psastro.config	(revision 41367)
@@ -145,4 +145,5 @@
   PHOTCODE STR g
   GHOST_MAX_MAG                   F32 -16.5
+  GLINT_MAX_MAG                   F32 -23.0
 END
 PHOTCODE.DATA METADATA
@@ -151,4 +152,5 @@
   PHOTCODE STR r
   GHOST_MAX_MAG                   F32 -20.0
+  GLINT_MAX_MAG                   F32 -23.0
 END
 PHOTCODE.DATA METADATA
@@ -157,4 +159,5 @@
   PHOTCODE STR i
   GHOST_MAX_MAG                   F32 -23.5
+  GLINT_MAX_MAG                   F32 -21.0
 END
 PHOTCODE.DATA METADATA
@@ -163,4 +166,5 @@
   PHOTCODE STR z
   GHOST_MAX_MAG                   F32 -25.0
+  GLINT_MAX_MAG                   F32 -23.0
 END
 PHOTCODE.DATA METADATA
@@ -169,4 +173,5 @@
   PHOTCODE STR y
   GHOST_MAX_MAG                   F32 -25.0
+  GLINT_MAX_MAG                   F32 -23.0
 END
 PHOTCODE.DATA METADATA
@@ -175,4 +180,5 @@
   PHOTCODE STR r
   GHOST_MAX_MAG                   F32 -23.5
+  GLINT_MAX_MAG                   F32 -21.0
 END
 
@@ -229,8 +235,10 @@
 GLINT_LENGTH_MAG_SLOPE          F32 1901.0
 GLINT_LENGTH_MAG_ZERO           F32 -16.8
-#TdB20200308: The length of glints also depends on position off the focal plane (perpendicular to pixel FPA)
+#TdB20200308: The length of glints also depends on position off the focal plane (perpendicular to pixel FPA), out to GLINT_LENGTH_POS_CUT
 #glint_length(pos) = GLINT_LENGTH_POS_SLOPE*(GLINT_LENGTH_POS_REF-pos)
 GLINT_LENGTH_POS_SLOPE          F32 0.00019
-GLINT_LENGTH_POS_REF            F32 33821
+GLINT_LENGTH_POS_REF            F32 33821.
+GLINT_LENGTH_POS_CUT            F32 30000.
+GLINT_LENGTH_MIN_FPA            F32 1500.0
 #TdB20200312: The angle that glints have depends on position along the focal plane (parallel to pixel FPA)
 #glint_angle(pos) = GLINT_ANGLE_SLOPE*(GLINT_ANGLE_POS_REF-(pos/1000))
Index: trunk/ippconfig/recipes/psastro.config
===================================================================
--- trunk/ippconfig/recipes/psastro.config	(revision 41363)
+++ trunk/ippconfig/recipes/psastro.config	(revision 41367)
@@ -190,4 +190,6 @@
 GLINT_LENGTH_POS_SLOPE          F32 0.0
 GLINT_LENGTH_POS_REF            F32 0.0
+GLINT_LENGTH_POS_CUT            F32 0.0
+GLINT_LENGTH_MIN_FPA            F32 0.0
 GLINT_ANGLE_POS_SLOPE           F32 0.0
 GLINT_ANGLE_POS_REF             F32 0.0
Index: trunk/psModules/src/objects/pmSourceIO.h
===================================================================
--- trunk/psModules/src/objects/pmSourceIO.h	(revision 41363)
+++ trunk/psModules/src/objects/pmSourceIO.h	(revision 41367)
@@ -91,4 +91,5 @@
 bool pmSourceIO_ReadMatchedRefs (psFits *fits, pmFPA *fpa, const pmConfig *config);
 
+bool psastroZeroPointFromRecipeGlint (float *zeropt, float *exptime, float *ghostMaxMag, double *glintMaxMag, pmFPA *fpa, psMetadata *recipe);
 bool pmSourceIO_WriteGlints (psFits *fits, pmFPA *fpa, pmConfig *config);
 bool pmSourceIO_WriteGhosts (psFits *fits, pmFPA *fpa, pmConfig *config);
Index: trunk/psModules/src/objects/pmSourceIO_Ghosts.c
===================================================================
--- trunk/psModules/src/objects/pmSourceIO_Ghosts.c	(revision 41363)
+++ trunk/psModules/src/objects/pmSourceIO_Ghosts.c	(revision 41367)
@@ -135,5 +135,13 @@
     pmFPAview *view = pmFPAviewAlloc (0);
 
-    GET_1D_POLY ("GHOST.MIRROR.RAD", mirrorRad);
+    //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;
+    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"); } 
+    if (md) {
+        GET_1D_POLY ("GHOST.MIRROR.RAD", mirrorRad);
+        mirCheck = 1;
+    }  
+
     GET_2D_POLY ("GHOST.CENTER.X", centerX);
     GET_2D_POLY ("GHOST.CENTER.Y", centerY);
@@ -143,4 +151,5 @@
     GET_1D_POLY ("GHOST.INNER.MAJOR", innerMajor);
     GET_1D_POLY ("GHOST.INNER.MINOR", innerMinor);
+
 
     // select the input astrometry data (also carries the refstars)
@@ -153,5 +162,5 @@
 
     // really error-out here?  or just skip?
-    if (!psastroZeroPointFromRecipe (&zeropt, &exptime, &MAX_MAG, fpa_ast, recipe)) {
+    if (!psastroZeroPointFromRecipeGlint (&zeropt, &exptime, &MAX_MAG,NULL, fpa_ast, recipe)) {
         psLogMsg ("psastro", PS_LOG_INFO, "failed to load zeropt data from recipe");
 	goto escape;
@@ -201,11 +210,19 @@
      	                double theta0 = atan2(ref->FP->y,ref->FP->x);
 
-		        double ghost_offset_rad = psPolynomial1DEval (mirrorRad, rSrc);
-		        double ghost_x_fpa_mirror = ref->FP->x + ((ref->FP->x*-1.)/abs(ref->FP->x)*abs(cos(theta0)*ghost_offset_rad));
-		        double ghost_y_fpa_mirror = ref->FP->y + ((ref->FP->y*-1.)/abs(ref->FP->y)*abs(sin(theta0)*ghost_offset_rad));
-
-		        // Now use the mirrored position together with the 2D ghost center fitting to get the actual ghost position in FPA coords 
-		        ghost->FP->x = ghost_x_fpa_mirror + psPolynomial2DEval(centerX, ghost_x_fpa_mirror, ghost_y_fpa_mirror);
-		        ghost->FP->y = ghost_y_fpa_mirror + psPolynomial2DEval(centerY, ghost_x_fpa_mirror, ghost_y_fpa_mirror);
+                        if(mirCheck) {
+                            //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);
+		            double ghost_x_fpa_mirror = ref->FP->x + ((ref->FP->x*-1.)/abs(ref->FP->x)*abs(cos(theta0)*ghost_offset_rad));
+		            double ghost_y_fpa_mirror = ref->FP->y + ((ref->FP->y*-1.)/abs(ref->FP->y)*abs(sin(theta0)*ghost_offset_rad));
+
+		            // Now use the mirrored position together with the 2D ghost center fitting to get the actual ghost position in FPA coords 
+		            ghost->FP->x = ghost_x_fpa_mirror + psPolynomial2DEval(centerX, ghost_x_fpa_mirror, ghost_y_fpa_mirror);
+		            ghost->FP->y = ghost_y_fpa_mirror + psPolynomial2DEval(centerY, ghost_x_fpa_mirror, ghost_y_fpa_mirror);
+                        }  
+                        if(!mirCheck) {
+                            //Use the old-style ghost position determination
+                            ghost->FP->x = -ref->FP->x + psPolynomial2DEval(centerX, -ref->FP->x, -ref->FP->y);
+                            ghost->FP->y = -ref->FP->y + psPolynomial2DEval(centerY, -ref->FP->x, -ref->FP->y);
+                        }
 
  			ghost->inner.major = psPolynomial1DEval (innerMajor, rSrc);
@@ -503,2 +520,4 @@
   return true;
 }
+
+
Index: trunk/psModules/src/objects/pmSourceIO_Glints.c
===================================================================
--- trunk/psModules/src/objects/pmSourceIO_Glints.c	(revision 41363)
+++ trunk/psModules/src/objects/pmSourceIO_Glints.c	(revision 41367)
@@ -78,13 +78,19 @@
     if (!REFSTAR_MASK_GLINTS) return true;
 
-    // select the limiting magnitude
+    // select relevant keywords
     double GLINT_MAX_MAG = psMetadataLookupF32 (&status, recipe, "GLINT_MAX_MAG");
     double GLINT_LENGTH_MAG_SLOPE = psMetadataLookupF32 (&status, recipe, "GLINT_LENGTH_MAG_SLOPE");
     double GLINT_LENGTH_MAG_ZERO = psMetadataLookupF32 (&status, recipe, "GLINT_LENGTH_MAG_ZERO");
+    double glintWidth = psMetadataLookupF32 (&status, recipe, "GLINT_WIDTH");
+
+    //we will use one of the new keywords to differentiate between an old and new style glint treatment
+    float glintCheck = 0;
     double GLINT_LENGTH_POS_SLOPE = psMetadataLookupF32 (&status, recipe, "GLINT_LENGTH_POS_SLOPE");
+    if (!status) { glintCheck = 1; }
     double GLINT_LENGTH_POS_REF = psMetadataLookupF32 (&status, recipe, "GLINT_LENGTH_POS_REF");
+    double GLINT_LENGTH_POS_CUT = psMetadataLookupF32 (&status, recipe, "GLINT_LENGTH_POS_CUT");
     double GLINT_ANGLE_POS_SLOPE = psMetadataLookupF32 (&status, recipe, "GLINT_ANGLE_POS_SLOPE");
     double GLINT_ANGLE_POS_REF = psMetadataLookupF32 (&status, recipe, "GLINT_ANGLE_POS_REF");
-    double glintWidth = psMetadataLookupF32 (&status, recipe, "GLINT_WIDTH");
+
     bool GLINT_OUTPUT = psMetadataLookupBool(&status, recipe, "PSASTRO.SAVE.GLINTS");
     if (!GLINT_OUTPUT) return true;
@@ -111,5 +117,5 @@
     // use the zero point and exposure time to convert to apparent mags: M_ap = M_inst + C_0 + 2.5*log(exptime)
     pmFPA *fpa_ast = astrom->fpa;
-    if (!psastroZeroPointFromRecipe (&zeropt, &exptime, NULL, fpa_ast, recipe)) {
+    if (!psastroZeroPointFromRecipeGlint (&zeropt, &exptime, NULL,&GLINT_MAX_MAG, fpa_ast, recipe)) {
         psLogMsg ("psastro", PS_LOG_INFO, "failed to load zeropt data from recipe");
         return false;
@@ -167,21 +173,22 @@
 	        }
 
+	        double glintLength = GLINT_LENGTH_MAG_SLOPE*(GLINT_LENGTH_MAG_ZERO - star->Mag);
                 double glintAngle = 0;
-                //compute the angle of the glint, which depends on position parallel to the FPX
-	        if (!strcasecmp(glintType, "TOP") || !strcasecmp(glintType, "BOTTOM") ){ 
-	          glintAngle = PM_RAD_DEG * (GLINT_ANGLE_POS_SLOPE*((GLINT_ANGLE_POS_REF - star->FP->x)/1000.));
-                }
-	        if (!strcasecmp(glintType, "LEFT") || !strcasecmp(glintType, "RIGHT") ) {
- 	          glintAngle = PM_RAD_DEG * (GLINT_ANGLE_POS_SLOPE*((GLINT_ANGLE_POS_REF - star->FP->y)/1000.));
-                }
-
-	        double glintLength = GLINT_LENGTH_MAG_SLOPE*(GLINT_LENGTH_MAG_ZERO - star->Mag);
-                //Besides brightness, the length of the glints also depends on the position of the star compared to the focal plane. But, seemingly only for stars closer than 30k pixels     
-	        if ((!strcasecmp(glintType, "TOP") || !strcasecmp(glintType, "BOTTOM")) && abs(star->FP->y) < 30000 ){ 
-                  glintLength /= GLINT_LENGTH_POS_SLOPE*(GLINT_LENGTH_POS_REF - abs(star->FP->y));
-
-                }
-	        if ((!strcasecmp(glintType, "LEFT") || !strcasecmp(glintType, "RIGHT")) && abs(star->FP->x) < 30000 ) {
-                  glintLength /= GLINT_LENGTH_POS_SLOPE*(GLINT_LENGTH_POS_REF - abs(star->FP->x));
+
+                //Besides brightness, the length of the glints also depends on the position of the star compared to the focal plane. But, seemingly only for stars closer than about 30k pixels
+                if(glintCheck) {
+	            if ((!strcasecmp(glintType, "TOP") || !strcasecmp(glintType, "BOTTOM")) && abs(star->FP->y) < GLINT_LENGTH_POS_CUT ){ 
+                      glintLength /= GLINT_LENGTH_POS_SLOPE*(GLINT_LENGTH_POS_REF - abs(star->FP->y));
+                    }
+	            if ((!strcasecmp(glintType, "LEFT") || !strcasecmp(glintType, "RIGHT")) && abs(star->FP->x) < GLINT_LENGTH_POS_CUT ) {
+                      glintLength /= GLINT_LENGTH_POS_SLOPE*(GLINT_LENGTH_POS_REF - abs(star->FP->x));
+                    }
+                    //also compute the angle of the glint, which depends on position parallel to the FPX
+	            if (!strcasecmp(glintType, "TOP") || !strcasecmp(glintType, "BOTTOM") ){ 
+	              glintAngle = PM_RAD_DEG * (GLINT_ANGLE_POS_SLOPE*((GLINT_ANGLE_POS_REF - star->FP->x)/1000.));
+                    }
+	            if (!strcasecmp(glintType, "LEFT") || !strcasecmp(glintType, "RIGHT") ) {
+ 	              glintAngle = PM_RAD_DEG * (GLINT_ANGLE_POS_SLOPE*((GLINT_ANGLE_POS_REF - star->FP->y)/1000.));
+                    }
                 }
 
@@ -230,6 +237,5 @@
 }
 
-
-bool psastroZeroPointFromRecipe (float *zeropt, float *exptime, float *ghostMaxMag, pmFPA *fpa, psMetadata *recipe) {
+bool psastroZeroPointFromRecipeGlint (float *zeropt, float *exptime, float *ghostMaxMag, double *glintMaxMag, pmFPA *fpa, psMetadata *recipe) {
 
     bool status;
@@ -279,4 +285,13 @@
             psLogMsg ("psastro", PS_LOG_INFO, "found GHOST_MAX_MAG %f",*ghostMaxMag);
         }
+        if (glintMaxMag) {
+            float MaxMag = psMetadataLookupF32 (&status, refItem->data.md, "GLINT_MAX_MAG");
+            if (status) {
+                *glintMaxMag = MaxMag ;
+	        //MEH null is a pain.. so only log if set
+                psLogMsg ("psastro", PS_LOG_INFO, "found GLINT_MAX_MAG %f",*glintMaxMag);
+            }
+        }
+
 	//MEH what zpt is set to 
         psLogMsg ("psastro", PS_LOG_INFO, "found ZEROPT  %f",*zeropt);
Index: trunk/psastro/src/psastro.h
===================================================================
--- trunk/psastro/src/psastro.h	(revision 41363)
+++ trunk/psastro/src/psastro.h	(revision 41367)
@@ -156,5 +156,5 @@
 psVector         *psastroZeroPointReadoutAccum(psVector *dMag, pmReadout *readout, float exptime, float refminMag, float refmaxMag);
 bool              psastroZeroPointAnalysis (psMetadata *header, psVector *dMag, float zeropt, psMetadata *recipe);
-bool 		  psastroZeroPointFromRecipe (float *zeropt, float *exptime, float *ghostMaxMag, pmFPA *fpa, psMetadata *recipe);
+bool 		  psastroZeroPointFromRecipe (float *zeropt, float *exptime, float *ghostMaxMag, double *glintMaxMag, pmFPA *fpa, psMetadata *recipe);
 bool              psastroZeroPointRefMagLimitFromRecipe (float *refminMag, float *refmaxMag, pmFPA *fpa, psMetadata *recipe);
 
Index: trunk/psastro/src/psastroChooseGlintStars.c
===================================================================
--- trunk/psastro/src/psastroChooseGlintStars.c	(revision 41363)
+++ trunk/psastro/src/psastroChooseGlintStars.c	(revision 41367)
@@ -37,5 +37,5 @@
 
     // really error-out here?  or just skip?
-    if (!psastroZeroPointFromRecipe (&zeropt, &exptime, NULL, fpa, recipe)) {
+    if (!psastroZeroPointFromRecipe (&zeropt, &exptime, NULL, NULL, fpa, recipe)) {
         psLogMsg ("psastro", PS_LOG_INFO, "failed to load zeropt data from recipe");
         return false;
Index: trunk/psastro/src/psastroConvert.c
===================================================================
--- trunk/psastro/src/psastroConvert.c	(revision 41363)
+++ trunk/psastro/src/psastroConvert.c	(revision 41367)
@@ -65,5 +65,5 @@
 
       // really error-out here?  or just skip?
-      if (!psastroZeroPointFromRecipe (&zeropt, &exptime, NULL, fpa, recipe)) {
+      if (!psastroZeroPointFromRecipe (&zeropt, &exptime, NULL, NULL, fpa, recipe)) {
         psLogMsg ("psastro", PS_LOG_INFO, "failed to load zeropt data from recipe");
 	zeropt = 0.0;
Index: trunk/psastro/src/psastroExtractGhosts.c
===================================================================
--- trunk/psastro/src/psastroExtractGhosts.c	(revision 41363)
+++ trunk/psastro/src/psastroExtractGhosts.c	(revision 41367)
@@ -53,5 +53,5 @@
 
     // really error-out here?  or just skip?
-    if (!psastroZeroPointFromRecipe (&zeropt, &exptime, NULL, fpa, recipe)) {
+    if (!psastroZeroPointFromRecipe (&zeropt, &exptime, NULL, NULL, fpa, recipe)) {
         psLogMsg ("psastro", PS_LOG_INFO, "failed to load zeropt data from recipe");
         return false;
Index: trunk/psastro/src/psastroExtractStars.c
===================================================================
--- trunk/psastro/src/psastroExtractStars.c	(revision 41363)
+++ trunk/psastro/src/psastroExtractStars.c	(revision 41367)
@@ -65,5 +65,5 @@
 
     // really error-out here?  or just skip?
-    if (!psastroZeroPointFromRecipe (&zeropt, &exptime, NULL, fpa, recipe)) {
+    if (!psastroZeroPointFromRecipe (&zeropt, &exptime, NULL, NULL, fpa, recipe)) {
         psLogMsg ("psastro", PS_LOG_INFO, "failed to load zeropt data from recipe");
         return false;
Index: trunk/psastro/src/psastroLoadCrosstalk.c
===================================================================
--- trunk/psastro/src/psastroLoadCrosstalk.c	(revision 41363)
+++ trunk/psastro/src/psastroLoadCrosstalk.c	(revision 41367)
@@ -94,5 +94,5 @@
 
   // really error-out here?  or just skip?
-  if (!psastroZeroPointFromRecipe (&zeropt, &exptime, &MAX_MAG, fpa, recipe)) {
+  if (!psastroZeroPointFromRecipe (&zeropt, &exptime, &MAX_MAG, NULL, fpa, recipe)) {
     psLogMsg ("psastro", PS_LOG_INFO, "failed to load zeropt data from recipe");
     goto escape;
Index: trunk/psastro/src/psastroLoadGhosts.c
===================================================================
--- trunk/psastro/src/psastroLoadGhosts.c	(revision 41363)
+++ trunk/psastro/src/psastroLoadGhosts.c	(revision 41367)
@@ -113,5 +113,13 @@
     pmFPAview *view = pmFPAviewAlloc (0);
 
-    GET_1D_POLY ("GHOST.MIRROR.RAD", mirrorRad);
+    //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;
+    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"); } 
+    if (md) {
+        GET_1D_POLY ("GHOST.MIRROR.RAD", mirrorRad);
+        mirCheck = 1;
+    }
+
     GET_2D_POLY ("GHOST.CENTER.X", centerX);
     GET_2D_POLY ("GHOST.CENTER.Y", centerY);
@@ -131,5 +139,5 @@
 
     // raise an error if the config is broken
-    if (!psastroZeroPointFromRecipe (&zeropt, &exptime, &MAX_MAG, fpa, recipe)) {
+    if (!psastroZeroPointFromRecipe (&zeropt, &exptime, &MAX_MAG, NULL, fpa, recipe)) {
         psError(PSASTRO_ERR_CONFIG, true, "failed to load zeropt data from recipe");
 	goto escape;
@@ -179,15 +187,22 @@
 		    ghost->srcFP->y = ref->FP->y;
 
-                    //TdB: first mirror the reference star positions (around the 0,0 pixel) using the radial offset coefficients and the ghost/star angle
 		    double rSrc = hypot (ref->FP->x, ref->FP->y);
      	            double theta0 = atan2(ref->FP->y,ref->FP->x);
 
-		    double ghost_offset_rad = psPolynomial1DEval (mirrorRad, rSrc);
-		    double ghost_x_fpa_mirror = ref->FP->x + ((ref->FP->x*-1.)/abs(ref->FP->x)*abs(cos(theta0)*ghost_offset_rad));
-		    double ghost_y_fpa_mirror = ref->FP->y + ((ref->FP->y*-1.)/abs(ref->FP->y)*abs(sin(theta0)*ghost_offset_rad));
-
-		    // Now use the mirrored position together with the 2D ghost center fitting to get the actual ghost position in FPA coords 
-		    ghost->FP->x = ghost_x_fpa_mirror + psPolynomial2DEval(centerX, ghost_x_fpa_mirror, ghost_y_fpa_mirror);
-		    ghost->FP->y = ghost_y_fpa_mirror + psPolynomial2DEval(centerY, ghost_x_fpa_mirror, ghost_y_fpa_mirror);
+                    if(mirCheck) {
+                         //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);
+		        double ghost_x_fpa_mirror = ref->FP->x + ((ref->FP->x*-1.)/abs(ref->FP->x)*abs(cos(theta0)*ghost_offset_rad));
+		        double ghost_y_fpa_mirror = ref->FP->y + ((ref->FP->y*-1.)/abs(ref->FP->y)*abs(sin(theta0)*ghost_offset_rad));
+
+		        // Now use the mirrored position together with the 2D ghost center fitting to get the actual ghost position in FPA coords 
+		        ghost->FP->x = ghost_x_fpa_mirror + psPolynomial2DEval(centerX, ghost_x_fpa_mirror, ghost_y_fpa_mirror);
+		        ghost->FP->y = ghost_y_fpa_mirror + psPolynomial2DEval(centerY, ghost_x_fpa_mirror, ghost_y_fpa_mirror);
+                    }  
+                    if(!mirCheck) {
+                        //Use the old-style ghost position determination
+                        ghost->FP->x = -ref->FP->x + psPolynomial2DEval(centerX, -ref->FP->x, -ref->FP->y);
+                        ghost->FP->y = -ref->FP->y + psPolynomial2DEval(centerY, -ref->FP->x, -ref->FP->y);
+                    }
 
 		    ghost->inner.major = psPolynomial1DEval (innerMajor, rSrc);
@@ -210,4 +225,5 @@
 		    ghostChip = psastroFindChip (&ghost->chip->x, &ghost->chip->y, fpa, ghost->FP->x, ghost->FP->y);
 		    // fprintf (stderr, "-> model chip position: %f, %f\n", ghost->chip->x, ghost->chip->y);
+
 
 		    if (ghostChip) {
@@ -356,5 +372,5 @@
   
   // if a filter is defined, but the recipe elements are missing, the config is broken.
-  if (!psastroZeroPointFromRecipe (&zeropt, &exptime, &MAX_MAG, fpa, recipe)) {
+  if (!psastroZeroPointFromRecipe (&zeropt, &exptime, &MAX_MAG, NULL, fpa, recipe)) {
 	psError(PSASTRO_ERR_CONFIG, true, "failed to load zeropt data from recipe");
 	goto escape;
Index: trunk/psastro/src/psastroLoadGlints.c
===================================================================
--- trunk/psastro/src/psastroLoadGlints.c	(revision 41363)
+++ trunk/psastro/src/psastroLoadGlints.c	(revision 41367)
@@ -26,4 +26,6 @@
     bool status;
     float zeropt, exptime;
+    psVector *x_glint = psVectorAlloc(2,PS_TYPE_F32);
+    psVector *y_glint = psVectorAlloc(2,PS_TYPE_F32);
 
     psLogMsg ("psastro", PS_LOG_INFO, "determine glint positions");
@@ -39,14 +41,25 @@
     if (!REFSTAR_MASK_GLINTS) return true;
 
-    // select the limiting magnitude
+    // select relevant keywords
     double GLINT_MAX_MAG = psMetadataLookupF32 (&status, recipe, "GLINT_MAX_MAG");
     double GLINT_LENGTH_MAG_SLOPE = psMetadataLookupF32 (&status, recipe, "GLINT_LENGTH_MAG_SLOPE");
     double GLINT_LENGTH_MAG_ZERO = psMetadataLookupF32 (&status, recipe, "GLINT_LENGTH_MAG_ZERO");
+    double glintWidth = psMetadataLookupF32 (&status, recipe, "GLINT_WIDTH");
+    double pixelScale = psMetadataLookupF32 (&status, recipe, "PSASTRO.PIXEL.SCALE");
+
+    //we will use one of the new keywords to differentiate between an old and new style glint treatment
+    float glintCheck = 0;
     double GLINT_LENGTH_POS_SLOPE = psMetadataLookupF32 (&status, recipe, "GLINT_LENGTH_POS_SLOPE");
+    if (!status) {
+        psLogMsg ("psastro", PS_LOG_INFO, "Assuming old-style glint masking, given the recipe keywords");
+        glintCheck = 1;
+    }
     double GLINT_LENGTH_POS_REF = psMetadataLookupF32 (&status, recipe, "GLINT_LENGTH_POS_REF");
+    double GLINT_LENGTH_POS_CUT = psMetadataLookupF32 (&status, recipe, "GLINT_LENGTH_POS_CUT");
+    double GLINT_LENGTH_MIN_FPA = psMetadataLookupF32 (&status, recipe, "GLINT_LENGTH_MIN_FPA");
+    if (!status) GLINT_LENGTH_MIN_FPA=1000.;
     double GLINT_ANGLE_POS_SLOPE = psMetadataLookupF32 (&status, recipe, "GLINT_ANGLE_POS_SLOPE");
     double GLINT_ANGLE_POS_REF = psMetadataLookupF32 (&status, recipe, "GLINT_ANGLE_POS_REF");
-    double glintWidth = psMetadataLookupF32 (&status, recipe, "GLINT_WIDTH");
-    double pixelScale = psMetadataLookupF32 (&status, recipe, "PSASTRO.PIXEL.SCALE");
+
 
     // select the set of glint regions (GLINT.REGION is a MULTI of METADATA items)
@@ -70,5 +83,5 @@
 
     // really error-out here?  or just skip?
-    if (!psastroZeroPointFromRecipe (&zeropt, &exptime, NULL, fpa, recipe)) {
+    if (!psastroZeroPointFromRecipe (&zeropt, &exptime, NULL, &GLINT_MAX_MAG, fpa, recipe)) {
         psLogMsg ("psastro", PS_LOG_INFO, "failed to load zeropt data from recipe");
         return false;
@@ -79,5 +92,5 @@
     float MagOffset = zeropt + 2.5*log10(exptime);
     GLINT_MAX_MAG += MagOffset;
-    GLINT_LENGTH_MAG_ZERO += MagOffset;
+    //GLINT_LENGTH_MAG_ZERO += MagOffset;
 
     // select the raw objects for this readout (loaded in psastroExtract.c)
@@ -91,5 +104,4 @@
     psastroChipBounds (fpa);
 
-
     // find the possible glint stars, and convert the position to FPA coordinates.
     // search for stars within the glint regions
@@ -97,10 +109,10 @@
 
 	pmAstromObj *star = glintStars->data[i];
-	if (star->Mag > GLINT_MAX_MAG) continue; // XXX should not be needed...
+	if (star->Mag > GLINT_MAX_MAG) continue; 
 
 	// project glint star to the focal-plane
 	psProject (star->TP, star->sky, fpa->toSky);
 	psPlaneTransformApply (star->FP, fpa->fromTPA, star->TP);
-	fprintf (stderr, "glint: %7.2f @ %8.1f, %8.1f (%f %f) %8.1f %8.1f\n", star->Mag, star->FP->x, star->FP->y, star->sky->r * PS_DEG_RAD, star->sky->d * PS_DEG_RAD, star->TP->x,star->TP->y);
+	//fprintf (stderr, "glint: %7.2f @ %8.1f, %8.1f (%f %f) %8.1f %8.1f\n", star->Mag, star->FP->x, star->FP->y, star->sky->r * PS_DEG_RAD, star->sky->d * PS_DEG_RAD, star->TP->x,star->TP->y);
 
 	// find the GLINT.REGION this star lands in (if any)
@@ -132,22 +144,24 @@
 	    }
 
-	    double glintLength = GLINT_LENGTH_MAG_SLOPE*(GLINT_LENGTH_MAG_ZERO - star->Mag);
+	    //double glintLength = GLINT_LENGTH_MAG_SLOPE*(GLINT_LENGTH_MAG_ZERO - star->Mag);
+            //glint length should depend on the brightness on image, i.e. in instrumental mag. The same instrumental mag in different filters should likely give the same glint length.
+	    double glintLength = GLINT_LENGTH_MAG_SLOPE*(GLINT_LENGTH_MAG_ZERO - (star->Mag-MagOffset));
             double glintAngle = 0;
 
-            //Besides brightness, the length of the glints also depends on the position of the star compared to the focal plane. But, seemingly only for stars closer than 30k pixels     
-	    if ((!strcasecmp(glintType, "TOP") || !strcasecmp(glintType, "BOTTOM")) && abs(star->FP->y) < 30000 ){ 
-              glintLength /= GLINT_LENGTH_POS_SLOPE*(GLINT_LENGTH_POS_REF - abs(star->FP->y));
-
-            }
-	    if ((!strcasecmp(glintType, "LEFT") || !strcasecmp(glintType, "RIGHT")) && abs(star->FP->x) < 30000 ) {
-              glintLength /= GLINT_LENGTH_POS_SLOPE*(GLINT_LENGTH_POS_REF - abs(star->FP->x));
-            }
-            //also compute the angle of the glint, which depends on position parallel to the FPX
-	    if (!strcasecmp(glintType, "TOP") || !strcasecmp(glintType, "BOTTOM") ){ 
-	      glintAngle = PM_RAD_DEG * (GLINT_ANGLE_POS_SLOPE*((GLINT_ANGLE_POS_REF - star->FP->x)/1000.));
-
-            }
-	    if (!strcasecmp(glintType, "LEFT") || !strcasecmp(glintType, "RIGHT") ) {
- 	      glintAngle = PM_RAD_DEG * (GLINT_ANGLE_POS_SLOPE*((GLINT_ANGLE_POS_REF - star->FP->y)/1000.));
+            //Besides brightness, the length of the glints also depends on the position of the star compared to the focal plane. But, seemingly only for stars closer than about 30k pixels
+            if(glintCheck) {
+	        if ((!strcasecmp(glintType, "TOP") || !strcasecmp(glintType, "BOTTOM")) && abs(star->FP->y) < GLINT_LENGTH_POS_CUT ){ 
+                  glintLength /= GLINT_LENGTH_POS_SLOPE*(GLINT_LENGTH_POS_REF - abs(star->FP->y));
+                }
+	        if ((!strcasecmp(glintType, "LEFT") || !strcasecmp(glintType, "RIGHT")) && abs(star->FP->x) < GLINT_LENGTH_POS_CUT ) {
+                  glintLength /= GLINT_LENGTH_POS_SLOPE*(GLINT_LENGTH_POS_REF - abs(star->FP->x));
+                }
+                //also compute the angle of the glint, which depends on position parallel to the FPX
+	        if (!strcasecmp(glintType, "TOP") || !strcasecmp(glintType, "BOTTOM") ){ 
+	          glintAngle = PM_RAD_DEG * (GLINT_ANGLE_POS_SLOPE*((GLINT_ANGLE_POS_REF - star->FP->x)/1000.));
+                }
+	        if (!strcasecmp(glintType, "LEFT") || !strcasecmp(glintType, "RIGHT") ) {
+ 	          glintAngle = PM_RAD_DEG * (GLINT_ANGLE_POS_SLOPE*((GLINT_ANGLE_POS_REF - star->FP->y)/1000.));
+                }
             }
 
@@ -157,7 +171,4 @@
             if (!strcasecmp(glintType, "LEFT")   && ((star->FP->x + glintLength) < -20000.))  continue;
             if (!strcasecmp(glintType, "RIGHT")  && ((star->FP->x - glintLength) > 20000.))  continue;
-
-	    psVector *x_glint = psVectorAlloc(2,PS_TYPE_F32);
-	    psVector *y_glint = psVectorAlloc(2,PS_TYPE_F32);
 
 	    if (!strcasecmp(glintType, "TOP") || !strcasecmp(glintType, "BOTTOM")) {
@@ -220,4 +231,6 @@
                     yFPA1 = yFPA0 + glintLength*cos(glintAngle);
 		}
+
+                if(glintLength < GLINT_LENGTH_MIN_FPA) continue;
 
 	        x_glint->data.F32[0] = xFPA0;
@@ -294,7 +307,5 @@
 		   	  psFree (glints);
 		   	}
-		   	
-		   	fprintf (stderr, "glint %s : %d %f,%f to %f,%f (%f %f %f)\n", glintType, nChip, xChip0, yChip0, xChip1, yChip1, glint_length, glintWidth, chip_angle);
-		   	psVector *glint = psVectorAlloc(5,PS_TYPE_F32);
+		   			   	psVector *glint = psVectorAlloc(5,PS_TYPE_F32);
 		   	glint->data.F32[0] = xChip0;
 		   	glint->data.F32[1] = yChip0;
@@ -369,4 +380,6 @@
                     yFPA1 = yFPA0 + glintLength*sin(glintAngle*-1.);
 		}
+
+                if(glintLength < GLINT_LENGTH_MIN_FPA) continue;
 
 	        x_glint->data.F32[0] = xFPA0;
@@ -441,6 +454,4 @@
 		   	}
 		   	
-		   	fprintf (stderr, "glint %s : %d %f,%f to %f,%f (%f %f %f)\n", glintType, nChip, xChip0, yChip0, xChip1, yChip1, glint_length, glintWidth, chip_angle);
-
 		   	psVector *glint = psVectorAlloc(5,PS_TYPE_F32);
 		   	glint->data.F32[0] = xChip0;
Index: trunk/psastro/src/psastroMaskUpdates.Mosaic.c
===================================================================
--- trunk/psastro/src/psastroMaskUpdates.Mosaic.c	(revision 41363)
+++ trunk/psastro/src/psastroMaskUpdates.Mosaic.c	(revision 41367)
@@ -56,5 +56,5 @@
 
     // really error-out here?  or just skip?
-    if (!psastroZeroPointFromRecipe (&zeropt, &exptime, fpa, recipe)) {
+    if (!psastroZeroPointFromRecipe (&zeropt, &exptime, NULL, NULL, fpa, recipe)) {
 	psLogMsg ("psastro", PS_LOG_INFO, "failed to load zeropt data from recipe");
 	return false;
Index: trunk/psastro/src/psastroMaskUpdates.c
===================================================================
--- trunk/psastro/src/psastroMaskUpdates.c	(revision 41363)
+++ trunk/psastro/src/psastroMaskUpdates.c	(revision 41367)
@@ -184,5 +184,5 @@
 
     // really error-out here?  or just skip?
-    if (!psastroZeroPointFromRecipe (&zeropt, &exptime, &GHOST_MAX_MAG, fpa, recipe)) {
+    if (!psastroZeroPointFromRecipe (&zeropt, &exptime, &GHOST_MAX_MAG, NULL, fpa, recipe)) {
         psLogMsg ("psastro", PS_LOG_INFO, "failed to load zeropt data from recipe");
         return false;
@@ -443,6 +443,4 @@
                         //psLogMsg ("psastro", 3, "glint: %f %f %f %f\n", glint->x0, glint->y0, glint->x1, glint->y1);
                         //psastroMaskRectangle (readoutMask->mask, glintMaskValue, glint->x0, glint->y0, glint->x1, glint->y1);
-
-                        psLogMsg ("psastro", 3, "glint: %d %f %f %f %f %f\n",i, glint->data.F32[0], glint->data.F32[1],glint->data.F32[2], glint->data.F32[3], glint->data.F32[4]);
 		        psastroMaskBox (readoutMask->mask, glintMaskValue, glint->data.F32[0], glint->data.F32[1],
 				    glint->data.F32[2], glint->data.F32[3], glint->data.F32[4]);
Index: trunk/psastro/src/psastroZeroPoint.c
===================================================================
--- trunk/psastro/src/psastroZeroPoint.c	(revision 41363)
+++ trunk/psastro/src/psastroZeroPoint.c	(revision 41367)
@@ -55,5 +55,5 @@
 
     // really error-out here?  or just skip?
-    if (!psastroZeroPointFromRecipe (&zeropt, &exptime, NULL, fpa, recipe)) {
+    if (!psastroZeroPointFromRecipe (&zeropt, &exptime, NULL, NULL, fpa, recipe)) {
         psLogMsg ("psastro", PS_LOG_INFO, "failed to load zeropt data from recipe");
         return false;
@@ -480,5 +480,5 @@
   return false; }
 
-bool psastroZeroPointFromRecipe (float *zeropt, float *exptime, float *ghostMaxMag, pmFPA *fpa, psMetadata *recipe) {
+bool psastroZeroPointFromRecipe (float *zeropt, float *exptime, float *ghostMaxMag, double *glintMaxMag, pmFPA *fpa, psMetadata *recipe) {
 
     bool status;
@@ -527,4 +527,12 @@
 	    //MEH null is a pain.. so only log if set
             psLogMsg ("psastro", PS_LOG_INFO, "found GHOST_MAX_MAG %f",*ghostMaxMag);
+        }
+        if (glintMaxMag) {
+            float MaxMag = psMetadataLookupF32 (&status, refItem->data.md, "GLINT_MAX_MAG");
+            if (status) {
+                *glintMaxMag = MaxMag ;
+	        //MEH null is a pain.. so only log if set
+                psLogMsg ("psastro", PS_LOG_INFO, "found GLINT_MAX_MAG %f",*glintMaxMag);
+            }
         }
 	//MEH what zpt is set to 
