Index: branches/eam_branches/ipp-20151113/ippToPsps/test/fulltest.sh
===================================================================
--- branches/eam_branches/ipp-20151113/ippToPsps/test/fulltest.sh	(revision 39135)
+++ branches/eam_branches/ipp-20151113/ippToPsps/test/fulltest.sh	(revision 39224)
@@ -561,4 +561,5 @@
 
   rm -rf $OUTDIR/FO
+  rm -rf $OUTDIR/FG
 
   ippjython loader.py $options $forcedobjqueuename once -simtest < /dev/null
Index: branches/eam_branches/ipp-20151113/ippToPsps/test/gpc1schema.sql
===================================================================
--- branches/eam_branches/ipp-20151113/ippToPsps/test/gpc1schema.sql	(revision 39135)
+++ branches/eam_branches/ipp-20151113/ippToPsps/test/gpc1schema.sql	(revision 39224)
@@ -21,5 +21,5 @@
   CREATE TABLE diffRun             ( diff_id INT, tess_id CHAR(64), state CHAR(16), diff_mode INT, software_ver CHAR(16) );
   CREATE TABLE diffInputSkyfile    ( diff_id INT, warp1 INT, stack2 INT, diff_skyfile_id INT, tess_id CHAR(64), skycell_id CHAR(64) );
-  CREATE TABLE diffSkyfile         ( diff_id INT, diff_skyfile_id INT, tess_id CHAR(64), skycell_id CHAR(64), path_base CHAR(255) );
+  CREATE TABLE diffSkyfile         ( diff_id INT, skycell_id CHAR(64), path_base CHAR(255) );
 
   CREATE TABLE addRun              ( add_id INT, stage CHAR(64), stage_extra1 INT, state CHAR(64), stage_id INT, minidvodb_name CHAR(64) );
Index: branches/eam_branches/ipp-20151113/ippToPsps/test/mkgpc1data.dvo
===================================================================
--- branches/eam_branches/ipp-20151113/ippToPsps/test/mkgpc1data.dvo	(revision 39135)
+++ branches/eam_branches/ipp-20151113/ippToPsps/test/mkgpc1data.dvo	(revision 39224)
@@ -654,5 +654,5 @@
   dbinsert diffRun (diff_id, tess_id, state, diff_mode, software_ver) values ($difID, $TESS_ID, "full", 2, "38000M")
   dbinsert diffInputSkyfile (diff_id, warp1, stack2, diff_skyfile_id, tess_id, skycell_id) values ($difID, $wrpID, $stkID, $diffSkyfileID, $TESS_ID,  $SKYCELL )
-  dbinsert diffSkyfile (diff_id, diff_skyfile_id, tess_id, skycell_id, path_base) values ($difID, $diffSkyfileID, $TESS_ID, $SKYCELL, "$filename")
+  dbinsert diffSkyfile (diff_id, skycell_id, path_base) values ($difID, $SKYCELL, "$filename")
 end
 
Index: branches/eam_branches/ipp-20151113/ippToPsps/test/sascheck.v0.sql
===================================================================
--- branches/eam_branches/ipp-20151113/ippToPsps/test/sascheck.v0.sql	(revision 39135)
+++ 	(revision )
@@ -1,25 +1,0 @@
-
--- get a set of measurements matched by detID
-select 
-   gra,
-   gdec,
-   objID,             
-   HEX(ippObjID),          
-   surveyID,          
-   tessID,            
-   projectionID,      
-   skyCellID,         
-   randomStackObjID,  
-   stackDetectRowID,  
-   primaryDetection,  
--- bestDetection,     
-   dvoRegionID,       
-   dataRelease,       
-   gippDetectID,      
-   gstackDetectID,    
-   gstackMetaID,      
-   HEX(ginfoFlag),        
-   HEX(ginfoFlag2),       
-   gnFrames         
-from StackObjectThin 
-limit 50
Index: branches/eam_branches/ipp-20151113/ippToPsps/test/sascheck.v1.sql
===================================================================
--- branches/eam_branches/ipp-20151113/ippToPsps/test/sascheck.v1.sql	(revision 39135)
+++ 	(revision )
@@ -1,44 +1,0 @@
--- compare g mags across stack tables
-select 
-       gra,
-       gdec,
-       graErr,
-       gdecErr,
-       gPSFMag,
-       gKronMag,
-       gApMag,
-       gExpMag,
-       gSerMag,
-       gDeVMag,
-       gpetMag,
-       gPSFMagErr,
-       gKronMagErr,
-       gApMagErr,
-       gExpMagErr,
-       gSerMagErr,
-       gDeVMagErr,
-       gpetMagErr,
-       gpsfLikelihood,    
-       gpsfQf,            
-       gpsfQfPerfect,     
-       gippDetectID
-       from StackObjectThin 
-       -- left join StackObjectRaw   using (gippDetectID)
-       -- left join StackModelFitExp using (gippDetectID)
-       -- left join StackModelFitDeV using (gippDetectID)
-       -- left join StackModelFitSer using (gippDetectID)
-       -- left join StackPetrosian   using (gippDetectID)
-       -- left join StackApFlxFull   using (gippDetectID)
-       -- left join StackApFlxFullC1 using (gippDetectID)
-       -- left join StackApFlxFullC2 using (gippDetectID)
-       join StackObjectRaw   using (gippDetectID)
-       join StackModelFitExp using (gippDetectID)
-       join StackModelFitDeV using (gippDetectID)
-       join StackModelFitSer using (gippDetectID)
-       join StackPetrosian   using (gippDetectID)
-       join StackApFlxFull   using (gippDetectID)
-       join StackApFlxFullC1 using (gippDetectID)
-       join StackApFlxFullC2 using (gippDetectID)
-       -- where (gippDetectID = 189)
-       -- where (gpsfQfPerfect > 0.85)
-       limit 50
Index: branches/eam_branches/ipp-20151113/ippToPsps/test/sascheck.v2.sql
===================================================================
--- branches/eam_branches/ipp-20151113/ippToPsps/test/sascheck.v2.sql	(revision 39135)
+++ 	(revision )
@@ -1,29 +1,0 @@
--- compare g raw PSF values
-select 
-  gippDetectID,
-  gxPos,             
-  gyPos,             
-  gxPosErr,          
-  gyPosErr,          
-  gpsfMajorFWHM,     
-  gpsfMinorFWHM,     
-  gpsfTheta,         
-  gpsfCore,          
-  gpsfLikelihood,    
-  gpsfQf,            
-  gpsfQfPerfect,     
-  gpsfChiSq,         
-  gmomentXX,         
-  gmomentXY,         
-  gmomentYY,         
-  gmomentR1,         
-  gmomentRH,         
-  gApFillFac,        
-  gKronRad,          
-  gsky,
-  gskyErr,
-  gexpTime,          
-  gzp              
-  from StackObjectThin 
-  join StackObjectRaw using (gippDetectID)
-  limit 80
Index: branches/eam_branches/ipp-20151113/ippToPsps/test/sascheck.v3.sql
===================================================================
--- branches/eam_branches/ipp-20151113/ippToPsps/test/sascheck.v3.sql	(revision 39135)
+++ 	(revision )
@@ -1,32 +1,0 @@
--- compare g fluxes across tables
-select 
-       gra,
-       gdec,
-       gPSFFlux,
-       gKronFlux,
-       gApFlux,
-       gPSFFluxErr,
-       gKronFluxErr,
-       gApFluxErr,
-       gApFillFac,
-       gflxR1,
-       gflxR2,
-       gflxR3,
-       gflxR4,
-       gflxR5,
-       gflxR6,
-       gflxR7,
-       gflxR8,
-       gflxR9,
-       gflxR10,
-       gippDetectID
-       from StackObjectThin 
-       join StackObjectRaw   using (gippDetectID)
-       join StackModelFitExp using (gippDetectID)
-       join StackModelFitDeV using (gippDetectID)
-       join StackModelFitSer using (gippDetectID)
-       join StackPetrosian   using (gippDetectID)
-       join StackApFlxFull   using (gippDetectID)
-       join StackApFlxFullC1 using (gippDetectID)
-       join StackApFlxFullC2 using (gippDetectID)
-       limit 50
Index: branches/eam_branches/ipp-20151113/ippToPsps/test/sascheck.v4.sql
===================================================================
--- branches/eam_branches/ipp-20151113/ippToPsps/test/sascheck.v4.sql	(revision 39135)
+++ 	(revision )
@@ -1,38 +1,0 @@
--- compare g fluxes across tables
-select 
-       gra,
-       gdec,
-       gPSFFlux,
-       gKronFlux,
-       gApFlux,
-       gflxR1,
-       gc1flxR1,
-       gc2flxR1,
-       gflxR2,
-       gc1flxR2,
-       gc2flxR2,
-       gflxR3,
-       gc1flxR3,
-       gc2flxR3,
-       gflxR4,
-       gc1flxR4,
-       gc2flxR4,
-       gflxR5,
-       gc1flxR5,
-       gc2flxR5,
-       gPSFFluxErr,
-       gKronFluxErr,
-       gApFluxErr,
-       gApFillFac,
-       gpsfQfPerfect,
-       gippDetectID
-       from StackObjectThin 
-       join StackObjectRaw   using (gippDetectID)
-       join StackModelFitExp using (gippDetectID)
-       join StackModelFitDeV using (gippDetectID)
-       join StackModelFitSer using (gippDetectID)
-       join StackPetrosian   using (gippDetectID)
-       join StackApFlxFull   using (gippDetectID)
-       join StackApFlxFullC1 using (gippDetectID)
-       join StackApFlxFullC2 using (gippDetectID)
-       limit 50
Index: branches/eam_branches/ipp-20151113/ippToPsps/test/sascheck.v5.sql
===================================================================
--- branches/eam_branches/ipp-20151113/ippToPsps/test/sascheck.v5.sql	(revision 39135)
+++ 	(revision )
@@ -1,32 +1,0 @@
--- compare g mags across stack tables
-select 
-       gra,
-       gdec,
-       gExpMag,
-       gSerMag,
-       gDeVMag,
-       gExpRadius,
-       gSerRadius,
-       gDeVRadius,
-       gExpAb,
-       gSerAb,
-       gDeVAb,
-       gExpPhi,
-       gSerPhi,
-       gDeVPhi,
-       gippDetectID
-       from StackObjectThin 
-       -- left join StackObjectRaw   using (gippDetectID)
-       -- left join StackModelFitExp using (gippDetectID)
-       -- left join StackModelFitDeV using (gippDetectID)
-       -- left join StackModelFitSer using (gippDetectID)
-       -- left join StackPetrosian   using (gippDetectID)
-       -- left join StackApFlxFull   using (gippDetectID)
-       -- left join StackApFlxFullC1 using (gippDetectID)
-       -- left join StackApFlxFullC2 using (gippDetectID)
-       join StackObjectRaw   using (gippDetectID)
-       join StackModelFitExp using (gippDetectID)
-       join StackModelFitDeV using (gippDetectID)
-       join StackModelFitSer using (gippDetectID)
-       -- where (gpsfQfPerfect > 0.85)
-       limit 50
Index: branches/eam_branches/ipp-20151113/ippToPsps/test/sascheck.v6.sql
===================================================================
--- branches/eam_branches/ipp-20151113/ippToPsps/test/sascheck.v6.sql	(revision 39135)
+++ 	(revision )
@@ -1,25 +1,0 @@
--- compare g mags across stack tables
-select 
-       gra,
-       gdec,
-       gExpMag,
-       gExpMagErr,
-       gExpRadius,
-       gExpRadiusErr,
-       gExpAb,
-       gExpAbErr,
-       gExpPhi,
-       gExpPhiErr,
-       gExpRa,
-       gExpDec,
-       gExpRaErr,
-       gExpDecErr,
-       gExpCf,
-       gExpLikelihood,
-       gippDetectID
-       from StackObjectThin 
-       join StackModelFitExp using (gippDetectID)
-       join StackModelFitDeV using (gippDetectID)
-       join StackModelFitSer using (gippDetectID)
-       -- where (gpsfQfPerfect > 0.85)
-       limit 50
Index: branches/eam_branches/ipp-20151113/ippToPsps/test/sascheck.v7.sql
===================================================================
--- branches/eam_branches/ipp-20151113/ippToPsps/test/sascheck.v7.sql	(revision 39135)
+++ 	(revision )
@@ -1,25 +1,0 @@
--- compare g mags across stack tables
-select 
-       gra,
-       gdec,
-       gDeVMag,
-       gDeVMagErr,
-       gDeVRadius,
-       gDeVRadiusErr,
-       gDeVAb,
-       gDeVAbErr,
-       gDeVPhi,
-       gDeVPhiErr,
-       gDeVRa,
-       gDeVDec,
-       gDeVRaErr,
-       gDeVDecErr,
-       gDeVCf,
-       gDeVLikelihood,
-       gippDetectID
-       from StackObjectThin 
-       join StackModelFitExp using (gippDetectID)
-       join StackModelFitDeV using (gippDetectID)
-       join StackModelFitSer using (gippDetectID)
-       -- where (gpsfQfPerfect > 0.85)
-       limit 50
Index: branches/eam_branches/ipp-20151113/ippToPsps/test/sascheck.v8.sql
===================================================================
--- branches/eam_branches/ipp-20151113/ippToPsps/test/sascheck.v8.sql	(revision 39135)
+++ 	(revision )
@@ -1,27 +1,0 @@
--- compare g mags across stack tables
-select 
-       gra,
-       gdec,
-       gSerMag,
-       gSerMagErr,
-       gSerRadius,
-       gSerRadiusErr,
-       gSerAb,
-       gSerAbErr,
-       gSerNu,
-       gSerNuErr,
-       gSerPhi,
-       gSerPhiErr,
-       gSerRa,
-       gSerDec,
-       gSerRaErr,
-       gSerDecErr,
-       gSerCf,
-       gSerLikelihood,
-       gippDetectID
-       from StackObjectThin 
-       join StackModelFitExp using (gippDetectID)
-       join StackModelFitDeV using (gippDetectID)
-       join StackModelFitSer using (gippDetectID)
-       -- where (gpsfQfPerfect > 0.85)
-       limit 50
Index: branches/eam_branches/ipp-20151113/ippToPsps/test/sascheck.v9.sql
===================================================================
--- branches/eam_branches/ipp-20151113/ippToPsps/test/sascheck.v9.sql	(revision 39135)
+++ 	(revision )
@@ -1,29 +1,0 @@
--- compare g fluxes across tables
-select 
-       gra,
-       gdec,
-       gxPos,
-       gyPos,
-       gPSFFlux,
-       gApFlux,
-       gPSFFluxErr,
-       gApFluxErr,
-       gApFillFac,
-       gflxR3,
-       gflxR4,
-       gflxR5,
-       gflxR3Err,
-       gflxR4Err,
-       gflxR5Err,
-       gflxR3Std,
-       gflxR4Std,
-       gflxR5Std,
-       gflxR3Fill,
-       gflxR4Fill,
-       gflxR5Fill,
-       gippDetectID
-       from StackObjectThin 
-       join StackObjectRaw   using (gippDetectID)
-       join StackApFlx       using (gippDetectID)
-       where gPSFFlux > 1000
-       limit 50
Index: branches/eam_branches/ipp-20151113/ippToPsps/test/testscripts/force.sh
===================================================================
--- branches/eam_branches/ipp-20151113/ippToPsps/test/testscripts/force.sh	(revision 39224)
+++ branches/eam_branches/ipp-20151113/ippToPsps/test/testscripts/force.sh	(revision 39224)
@@ -0,0 +1,26 @@
+#!/bin/csh
+
+set catdir = catdir.test
+
+mkcmf -forcedwarp -photcode SIMTEST.g.ForcedWarp testdata/test.01.txt testdata/warp.01.cmf -extroot SkyChip -date 2010/01/01 -time 01:00:00 -mjd 55197.0416667 -radec 10.0 20.0 -type PS1_V5_Lensing -imageID 1 -sourceID 2 -tess_id RINGS.V3 -skycell skycell.1133.081 -bad-psfqf-frac 0.2
+mkcmf -forcedwarp -photcode SIMTEST.g.ForcedWarp testdata/test.02.txt testdata/warp.02.cmf -extroot SkyChip -date 2010/01/01 -time 02:00:00 -mjd 55197.0833333 -radec 10.0 20.0 -type PS1_V5_Lensing -imageID 2 -sourceID 2 -tess_id RINGS.V3 -skycell skycell.1133.081 -bad-psfqf-frac 0.2
+mkcmf -forcedwarp -photcode SIMTEST.g.ForcedWarp testdata/test.03.txt testdata/warp.03.cmf -extroot SkyChip -date 2010/01/01 -time 03:00:00 -mjd 55197.125 -radec 10.0 20.0 -type PS1_V5_Lensing -imageID 3 -sourceID 2 -tess_id RINGS.V3 -skycell skycell.1133.081 -bad-psfqf-frac 0.2
+mkcmf -forcedwarp -photcode SIMTEST.g.ForcedWarp testdata/test.04.txt testdata/warp.04.cmf -extroot SkyChip -date 2010/01/01 -time 04:00:00 -mjd 55197.1666667 -radec 10.0 20.0 -type PS1_V5_Lensing -imageID 4 -sourceID 2 -tess_id RINGS.V3 -skycell skycell.1133.081 -bad-psfqf-frac 0.2
+mkcmf -forcedwarp -photcode SIMTEST.r.ForcedWarp testdata/test.13.txt testdata/warp.13.cmf -extroot SkyChip -date 2010/01/02 -time 01:00:00 -mjd 55198.0416667 -radec 10.0 20.0 -type PS1_V5_Lensing -imageID 13 -sourceID 2 -tess_id RINGS.V3 -skycell skycell.1133.081 -bad-psfqf-frac 0.2
+mkcmf -forcedwarp -photcode SIMTEST.r.ForcedWarp testdata/test.14.txt testdata/warp.14.cmf -extroot SkyChip -date 2010/01/02 -time 02:00:00 -mjd 55198.0833333 -radec 10.0 20.0 -type PS1_V5_Lensing -imageID 14 -sourceID 2 -tess_id RINGS.V3 -skycell skycell.1133.081 -bad-psfqf-frac 0.2
+mkcmf -forcedwarp -photcode SIMTEST.r.ForcedWarp testdata/test.15.txt testdata/warp.15.cmf -extroot SkyChip -date 2010/01/02 -time 03:00:00 -mjd 55198.125 -radec 10.0 20.0 -type PS1_V5_Lensing -imageID 15 -sourceID 2 -tess_id RINGS.V3 -skycell skycell.1133.081 -bad-psfqf-frac 0.2
+mkcmf -forcedwarp -photcode SIMTEST.r.ForcedWarp testdata/test.16.txt testdata/warp.16.cmf -extroot SkyChip -date 2010/01/02 -time 04:00:00 -mjd 55198.1666667 -radec 10.0 20.0 -type PS1_V5_Lensing -imageID 16 -sourceID 2 -tess_id RINGS.V3 -skycell skycell.1133.081 -bad-psfqf-frac 0.2
+mkcmf -forcedgalaxy -photcode SIMTEST.g.ForcedWarp testdata/test.01.txt testdata/fgal.01.cmf -extroot SkyChip -date 2008/1/1 -time 0:00:00 -mjd 54466.0 -radec 10.0 20.0 -type PS1_V5_Lensing -imageID 1 -sourceID 1 -tess_id RINGS.V3 -skycell skycell.1133.081
+mkcmf -forcedgalaxy -photcode SIMTEST.r.ForcedWarp testdata/test.04.txt testdata/fgal.04.cmf -extroot SkyChip -date 2008/1/1 -time 3:00:00 -mjd 54466.0 -radec 10.0 20.0 -type PS1_V5_Lensing -imageID 4 -sourceID 1 -tess_id RINGS.V3 -skycell skycell.1133.081
+
+addstar -D SKY_DEPTH 4 -D CATDIR $catdir -D CAMERA simtest testdata/warp.01.cmf -D CATFORMAT PS1_V5 -quick-airmass -xrad
+addstar -D SKY_DEPTH 4 -D CATDIR $catdir -D CAMERA simtest testdata/warp.02.cmf -D CATFORMAT PS1_V5 -quick-airmass -xrad
+addstar -D SKY_DEPTH 4 -D CATDIR $catdir -D CAMERA simtest testdata/warp.03.cmf -D CATFORMAT PS1_V5 -quick-airmass -xrad
+addstar -D SKY_DEPTH 4 -D CATDIR $catdir -D CAMERA simtest testdata/warp.04.cmf -D CATFORMAT PS1_V5 -quick-airmass -xrad
+addstar -D SKY_DEPTH 4 -D CATDIR $catdir -D CAMERA simtest testdata/warp.13.cmf -D CATFORMAT PS1_V5 -quick-airmass -xrad
+addstar -D SKY_DEPTH 4 -D CATDIR $catdir -D CAMERA simtest testdata/warp.14.cmf -D CATFORMAT PS1_V5 -quick-airmass -xrad
+addstar -D SKY_DEPTH 4 -D CATDIR $catdir -D CAMERA simtest testdata/warp.15.cmf -D CATFORMAT PS1_V5 -quick-airmass -xrad
+addstar -D SKY_DEPTH 4 -D CATDIR $catdir -D CAMERA simtest testdata/warp.16.cmf -D CATFORMAT PS1_V5 -quick-airmass -xrad
+
+loadgalphot -D CATDIR $catdir testdata/fgal.01.cmf
+loadgalphot -D CATDIR $catdir testdata/fgal.04.cmf
Index: branches/eam_branches/ipp-20151113/ippToPsps/test/testscripts/input.gdb
===================================================================
--- branches/eam_branches/ipp-20151113/ippToPsps/test/testscripts/input.gdb	(revision 39224)
+++ branches/eam_branches/ipp-20151113/ippToPsps/test/testscripts/input.gdb	(revision 39224)
@@ -0,0 +1,77 @@
+
+define showdata
+  set $i = 0
+  while $i < Npts
+    printf "%6.3f %6.3f   %10.6f  %d\n", Xpt[$i], Ypt[$i], chisq[$i], mask[$i]
+    set $i = $i + 1
+  end
+end
+
+define showlg
+  set $ix = 0
+  while $ix < fit->mterm
+    set $iy = 0
+    while $iy < fit->mterm
+      printf "%6.3f \n", fit->s[$ix][$iy]
+      set $iy = $iy + 1
+    end
+    set $ix = $ix + 1
+    printf "\n"
+  end
+end
+
+define showmn
+  set $ix = 0
+  while $ix < mterm
+    set $iy = 0
+    while $iy < mterm
+      printf "%6.3f \n", s[$ix][$iy]
+      set $iy = $iy + 1
+    end
+    set $ix = $ix + 1
+    printf "\n"
+  end
+end
+
+define showlB
+  set $iy = 0
+  while $iy < fit->wterm
+    printf "%6.3f \n", fit->b[$iy][0]
+    set $iy = $iy + 1
+  end
+end
+
+define showmB
+  set $iy = 0
+  while $iy < wterm
+    printf "%6.3f \n", b[$iy][0]
+    set $iy = $iy + 1 
+  end
+end
+
+define showlc
+  set $ix = 0
+  while $ix < fit->wterm
+    set $iy = 0
+    while $iy < fit->wterm
+      printf "%6.3f ", fit->c[$ix][$iy]
+      set $iy = $iy + 1
+    end
+    set $ix = $ix + 1
+    printf "\n"
+  end
+end
+
+define showmc
+  set $ix = 0
+  while $ix < wterm
+    set $iy = 0
+    while $iy < wterm
+      printf "%6.3f ", c[$ix][$iy]
+      set $iy = $iy + 1
+    end
+    set $ix = $ix + 1
+    printf "\n"
+  end
+end
+
Index: branches/eam_branches/ipp-20151113/ippToPsps/test/testscripts/mana.sh
===================================================================
--- branches/eam_branches/ipp-20151113/ippToPsps/test/testscripts/mana.sh	(revision 39224)
+++ branches/eam_branches/ipp-20151113/ippToPsps/test/testscripts/mana.sh	(revision 39224)
@@ -0,0 +1,87 @@
+
+if (not($?VERBOSE)) set VERBOSE = 0
+if (not($?SHOW_PLOTS)) set SHOW_PLOTS = 1
+
+macro checkfit
+  if ($0 != 3)
+    echo "USAGE: checkfit (file) (number)"
+    break
+  end
+
+  data $1
+  read -fits SkyChip.xgal FR_MINOR_MIN FR_MINOR_MAX FR_MINOR_DEL FR_MAJOR_MIN FR_MAJOR_MAX FR_MAJOR_DEL GAL_CHISQ GAL_FLUX NPIX
+
+  delete -q Xi Yi Xv Yv Zv
+
+  local ix iy
+
+  $N = 0
+  for ix 0 5
+    for iy 0 5
+      $Vx = FR_MAJOR_MIN[$2] + FR_MAJOR_DEL[$2]*$ix
+      $Vy = FR_MINOR_MIN[$2] + FR_MINOR_DEL[$2]*$iy
+
+      concat $ix Xi
+      concat $iy Yi
+      concat $Vx Xv
+      concat $Vy Yv
+ 
+      # echo concat GAL_CHISQ:$N[0] Zv
+      concat GAL_CHISQ:$N[$2] Zv
+      if ($VERBOSE)
+        fprintf "%1d %1d %5.3f %5.3f %7.3f" Xi[$N] Yi[$N] Xv[$N] Yv[$N] Zv[$N]
+      end
+      $N ++
+    end
+  end
+
+  vstat -q Zv
+  set Zv = Zv * NPIX[$2] / $MIN
+
+  if ($VERBOSE)
+    fit2d Xv Yv Zv 2 -clip 5 3
+  else
+    fit2d Xv Yv Zv 2 -clip 5 3  -q
+  end
+
+  $DET = 1 / (4*$CX0Y2*$CX2Y0 - $CX1Y1^2)
+  $Xm = ($CX1Y1*$CX0Y1 - 2*$CX0Y2*$CX1Y0) * $DET
+  $Ym = ($CX1Y1*$CX1Y0 - 2*$CX2Y0*$CX0Y1) * $DET
+  # echo $Xm $Ym
+
+  applyfit2d Xv Yv Zvf
+  set dZ = Zv - Zvf
+
+  if ($SHOW_PLOTS)
+    lim -n 0 Xv Yv; clear; box -ticks 1111
+    vstat -q Zv
+    $Range = $MAX - $MIN
+    $Midpt = 0.5*($MAX + $MIN)
+    zplot -pt  2 Xv Yv Zv  {$Midpt - 0.55*$Range} {$Midpt - 0.3*$Range} -c blue
+    zplot -pt  7 Xv Yv Zvf {$Midpt - 0.55*$Range} {$Midpt - 0.3*$Range} -c red
+    
+    dot $Xm $Ym -pt 7 -sz 3 -c red
+
+    lim -n 1 Xv Yv; clear; box -ticks 1111
+    vstat -q dZ
+    $Range = $MAX - $MIN
+    $Midpt = 0.5*($MAX + $MIN)
+    zplot -pt 10 Xv Yv dZ {$Midpt - 0.8*$Range} {$Midpt + 0.6*$Range}
+    
+    dot $Xm $Ym -pt 7 -sz 3 -c red
+  end
+
+  $A = $CX2Y0
+  $B = $CX1Y0 + 2*$CX2Y0*$Xm + $CX1Y1*$Ym
+  $C = -1
+
+  $dXm = (sqrt($B^2 - 4*$A*$C) - $B) / (2*$A)
+
+  $A = $CX0Y2
+  $B = $CX0Y1 + 2*$CX0Y2*$Ym + $CX1Y1*$Xm
+  $C = -1
+
+  $dYm = (sqrt($B^2 - 4*$A*$C) - $B) / (2*$A)
+
+  echo ($Xm, $Ym) +/- ($dXm, $dYm)
+end
Index: branches/eam_branches/ipp-20151113/ippToPsps/test/testscripts/sascheck.v0.sql
===================================================================
--- branches/eam_branches/ipp-20151113/ippToPsps/test/testscripts/sascheck.v0.sql	(revision 39224)
+++ branches/eam_branches/ipp-20151113/ippToPsps/test/testscripts/sascheck.v0.sql	(revision 39224)
@@ -0,0 +1,25 @@
+
+-- get a set of measurements matched by detID
+select 
+   gra,
+   gdec,
+   objID,             
+   HEX(ippObjID),          
+   surveyID,          
+   tessID,            
+   projectionID,      
+   skyCellID,         
+   randomStackObjID,  
+   stackDetectRowID,  
+   primaryDetection,  
+-- bestDetection,     
+   dvoRegionID,       
+   dataRelease,       
+   gippDetectID,      
+   gstackDetectID,    
+   gstackMetaID,      
+   HEX(ginfoFlag),        
+   HEX(ginfoFlag2),       
+   gnFrames         
+from StackObjectThin 
+limit 50
Index: branches/eam_branches/ipp-20151113/ippToPsps/test/testscripts/sascheck.v1.sql
===================================================================
--- branches/eam_branches/ipp-20151113/ippToPsps/test/testscripts/sascheck.v1.sql	(revision 39224)
+++ branches/eam_branches/ipp-20151113/ippToPsps/test/testscripts/sascheck.v1.sql	(revision 39224)
@@ -0,0 +1,44 @@
+-- compare g mags across stack tables
+select 
+       gra,
+       gdec,
+       graErr,
+       gdecErr,
+       gPSFMag,
+       gKronMag,
+       gApMag,
+       gExpMag,
+       gSerMag,
+       gDeVMag,
+       gpetMag,
+       gPSFMagErr,
+       gKronMagErr,
+       gApMagErr,
+       gExpMagErr,
+       gSerMagErr,
+       gDeVMagErr,
+       gpetMagErr,
+       gpsfLikelihood,    
+       gpsfQf,            
+       gpsfQfPerfect,     
+       gippDetectID
+       from StackObjectThin 
+       -- left join StackObjectRaw   using (gippDetectID)
+       -- left join StackModelFitExp using (gippDetectID)
+       -- left join StackModelFitDeV using (gippDetectID)
+       -- left join StackModelFitSer using (gippDetectID)
+       -- left join StackPetrosian   using (gippDetectID)
+       -- left join StackApFlxFull   using (gippDetectID)
+       -- left join StackApFlxFullC1 using (gippDetectID)
+       -- left join StackApFlxFullC2 using (gippDetectID)
+       join StackObjectRaw   using (gippDetectID)
+       join StackModelFitExp using (gippDetectID)
+       join StackModelFitDeV using (gippDetectID)
+       join StackModelFitSer using (gippDetectID)
+       join StackPetrosian   using (gippDetectID)
+       join StackApFlxFull   using (gippDetectID)
+       join StackApFlxFullC1 using (gippDetectID)
+       join StackApFlxFullC2 using (gippDetectID)
+       -- where (gippDetectID = 189)
+       -- where (gpsfQfPerfect > 0.85)
+       limit 50
Index: branches/eam_branches/ipp-20151113/ippToPsps/test/testscripts/sascheck.v2.sql
===================================================================
--- branches/eam_branches/ipp-20151113/ippToPsps/test/testscripts/sascheck.v2.sql	(revision 39224)
+++ branches/eam_branches/ipp-20151113/ippToPsps/test/testscripts/sascheck.v2.sql	(revision 39224)
@@ -0,0 +1,29 @@
+-- compare g raw PSF values
+select 
+  gippDetectID,
+  gxPos,             
+  gyPos,             
+  gxPosErr,          
+  gyPosErr,          
+  gpsfMajorFWHM,     
+  gpsfMinorFWHM,     
+  gpsfTheta,         
+  gpsfCore,          
+  gpsfLikelihood,    
+  gpsfQf,            
+  gpsfQfPerfect,     
+  gpsfChiSq,         
+  gmomentXX,         
+  gmomentXY,         
+  gmomentYY,         
+  gmomentR1,         
+  gmomentRH,         
+  gApFillFac,        
+  gKronRad,          
+  gsky,
+  gskyErr,
+  gexpTime,          
+  gzp              
+  from StackObjectThin 
+  join StackObjectRaw using (gippDetectID)
+  limit 80
Index: branches/eam_branches/ipp-20151113/ippToPsps/test/testscripts/sascheck.v3.sql
===================================================================
--- branches/eam_branches/ipp-20151113/ippToPsps/test/testscripts/sascheck.v3.sql	(revision 39224)
+++ branches/eam_branches/ipp-20151113/ippToPsps/test/testscripts/sascheck.v3.sql	(revision 39224)
@@ -0,0 +1,32 @@
+-- compare g fluxes across tables
+select 
+       gra,
+       gdec,
+       gPSFFlux,
+       gKronFlux,
+       gApFlux,
+       gPSFFluxErr,
+       gKronFluxErr,
+       gApFluxErr,
+       gApFillFac,
+       gflxR1,
+       gflxR2,
+       gflxR3,
+       gflxR4,
+       gflxR5,
+       gflxR6,
+       gflxR7,
+       gflxR8,
+       gflxR9,
+       gflxR10,
+       gippDetectID
+       from StackObjectThin 
+       join StackObjectRaw   using (gippDetectID)
+       join StackModelFitExp using (gippDetectID)
+       join StackModelFitDeV using (gippDetectID)
+       join StackModelFitSer using (gippDetectID)
+       join StackPetrosian   using (gippDetectID)
+       join StackApFlxFull   using (gippDetectID)
+       join StackApFlxFullC1 using (gippDetectID)
+       join StackApFlxFullC2 using (gippDetectID)
+       limit 50
Index: branches/eam_branches/ipp-20151113/ippToPsps/test/testscripts/sascheck.v4.sql
===================================================================
--- branches/eam_branches/ipp-20151113/ippToPsps/test/testscripts/sascheck.v4.sql	(revision 39224)
+++ branches/eam_branches/ipp-20151113/ippToPsps/test/testscripts/sascheck.v4.sql	(revision 39224)
@@ -0,0 +1,38 @@
+-- compare g fluxes across tables
+select 
+       gra,
+       gdec,
+       gPSFFlux,
+       gKronFlux,
+       gApFlux,
+       gflxR1,
+       gc1flxR1,
+       gc2flxR1,
+       gflxR2,
+       gc1flxR2,
+       gc2flxR2,
+       gflxR3,
+       gc1flxR3,
+       gc2flxR3,
+       gflxR4,
+       gc1flxR4,
+       gc2flxR4,
+       gflxR5,
+       gc1flxR5,
+       gc2flxR5,
+       gPSFFluxErr,
+       gKronFluxErr,
+       gApFluxErr,
+       gApFillFac,
+       gpsfQfPerfect,
+       gippDetectID
+       from StackObjectThin 
+       join StackObjectRaw   using (gippDetectID)
+       join StackModelFitExp using (gippDetectID)
+       join StackModelFitDeV using (gippDetectID)
+       join StackModelFitSer using (gippDetectID)
+       join StackPetrosian   using (gippDetectID)
+       join StackApFlxFull   using (gippDetectID)
+       join StackApFlxFullC1 using (gippDetectID)
+       join StackApFlxFullC2 using (gippDetectID)
+       limit 50
Index: branches/eam_branches/ipp-20151113/ippToPsps/test/testscripts/sascheck.v5.sql
===================================================================
--- branches/eam_branches/ipp-20151113/ippToPsps/test/testscripts/sascheck.v5.sql	(revision 39224)
+++ branches/eam_branches/ipp-20151113/ippToPsps/test/testscripts/sascheck.v5.sql	(revision 39224)
@@ -0,0 +1,32 @@
+-- compare g mags across stack tables
+select 
+       gra,
+       gdec,
+       gExpMag,
+       gSerMag,
+       gDeVMag,
+       gExpRadius,
+       gSerRadius,
+       gDeVRadius,
+       gExpAb,
+       gSerAb,
+       gDeVAb,
+       gExpPhi,
+       gSerPhi,
+       gDeVPhi,
+       gippDetectID
+       from StackObjectThin 
+       -- left join StackObjectRaw   using (gippDetectID)
+       -- left join StackModelFitExp using (gippDetectID)
+       -- left join StackModelFitDeV using (gippDetectID)
+       -- left join StackModelFitSer using (gippDetectID)
+       -- left join StackPetrosian   using (gippDetectID)
+       -- left join StackApFlxFull   using (gippDetectID)
+       -- left join StackApFlxFullC1 using (gippDetectID)
+       -- left join StackApFlxFullC2 using (gippDetectID)
+       join StackObjectRaw   using (gippDetectID)
+       join StackModelFitExp using (gippDetectID)
+       join StackModelFitDeV using (gippDetectID)
+       join StackModelFitSer using (gippDetectID)
+       -- where (gpsfQfPerfect > 0.85)
+       limit 50
Index: branches/eam_branches/ipp-20151113/ippToPsps/test/testscripts/sascheck.v6.sql
===================================================================
--- branches/eam_branches/ipp-20151113/ippToPsps/test/testscripts/sascheck.v6.sql	(revision 39224)
+++ branches/eam_branches/ipp-20151113/ippToPsps/test/testscripts/sascheck.v6.sql	(revision 39224)
@@ -0,0 +1,25 @@
+-- compare g mags across stack tables
+select 
+       gra,
+       gdec,
+       gExpMag,
+       gExpMagErr,
+       gExpRadius,
+       gExpRadiusErr,
+       gExpAb,
+       gExpAbErr,
+       gExpPhi,
+       gExpPhiErr,
+       gExpRa,
+       gExpDec,
+       gExpRaErr,
+       gExpDecErr,
+       gExpCf,
+       gExpLikelihood,
+       gippDetectID
+       from StackObjectThin 
+       join StackModelFitExp using (gippDetectID)
+       join StackModelFitDeV using (gippDetectID)
+       join StackModelFitSer using (gippDetectID)
+       -- where (gpsfQfPerfect > 0.85)
+       limit 50
Index: branches/eam_branches/ipp-20151113/ippToPsps/test/testscripts/sascheck.v7.sql
===================================================================
--- branches/eam_branches/ipp-20151113/ippToPsps/test/testscripts/sascheck.v7.sql	(revision 39224)
+++ branches/eam_branches/ipp-20151113/ippToPsps/test/testscripts/sascheck.v7.sql	(revision 39224)
@@ -0,0 +1,25 @@
+-- compare g mags across stack tables
+select 
+       gra,
+       gdec,
+       gDeVMag,
+       gDeVMagErr,
+       gDeVRadius,
+       gDeVRadiusErr,
+       gDeVAb,
+       gDeVAbErr,
+       gDeVPhi,
+       gDeVPhiErr,
+       gDeVRa,
+       gDeVDec,
+       gDeVRaErr,
+       gDeVDecErr,
+       gDeVCf,
+       gDeVLikelihood,
+       gippDetectID
+       from StackObjectThin 
+       join StackModelFitExp using (gippDetectID)
+       join StackModelFitDeV using (gippDetectID)
+       join StackModelFitSer using (gippDetectID)
+       -- where (gpsfQfPerfect > 0.85)
+       limit 50
Index: branches/eam_branches/ipp-20151113/ippToPsps/test/testscripts/sascheck.v8.sql
===================================================================
--- branches/eam_branches/ipp-20151113/ippToPsps/test/testscripts/sascheck.v8.sql	(revision 39224)
+++ branches/eam_branches/ipp-20151113/ippToPsps/test/testscripts/sascheck.v8.sql	(revision 39224)
@@ -0,0 +1,27 @@
+-- compare g mags across stack tables
+select 
+       gra,
+       gdec,
+       gSerMag,
+       gSerMagErr,
+       gSerRadius,
+       gSerRadiusErr,
+       gSerAb,
+       gSerAbErr,
+       gSerNu,
+       gSerNuErr,
+       gSerPhi,
+       gSerPhiErr,
+       gSerRa,
+       gSerDec,
+       gSerRaErr,
+       gSerDecErr,
+       gSerCf,
+       gSerLikelihood,
+       gippDetectID
+       from StackObjectThin 
+       join StackModelFitExp using (gippDetectID)
+       join StackModelFitDeV using (gippDetectID)
+       join StackModelFitSer using (gippDetectID)
+       -- where (gpsfQfPerfect > 0.85)
+       limit 50
Index: branches/eam_branches/ipp-20151113/ippToPsps/test/testscripts/sascheck.v9.sql
===================================================================
--- branches/eam_branches/ipp-20151113/ippToPsps/test/testscripts/sascheck.v9.sql	(revision 39224)
+++ branches/eam_branches/ipp-20151113/ippToPsps/test/testscripts/sascheck.v9.sql	(revision 39224)
@@ -0,0 +1,29 @@
+-- compare g fluxes across tables
+select 
+       gra,
+       gdec,
+       gxPos,
+       gyPos,
+       gPSFFlux,
+       gApFlux,
+       gPSFFluxErr,
+       gApFluxErr,
+       gApFillFac,
+       gflxR3,
+       gflxR4,
+       gflxR5,
+       gflxR3Err,
+       gflxR4Err,
+       gflxR5Err,
+       gflxR3Std,
+       gflxR4Std,
+       gflxR5Std,
+       gflxR3Fill,
+       gflxR4Fill,
+       gflxR5Fill,
+       gippDetectID
+       from StackObjectThin 
+       join StackObjectRaw   using (gippDetectID)
+       join StackApFlx       using (gippDetectID)
+       where gPSFFlux > 1000
+       limit 50
