Index: /branches/eam_branches/ipp-20121130/dbconfig/changes.txt
===================================================================
--- /branches/eam_branches/ipp-20121130/dbconfig/changes.txt	(revision 34839)
+++ /branches/eam_branches/ipp-20121130/dbconfig/changes.txt	(revision 34840)
@@ -2262,2 +2262,5 @@
 
 UPDATE dbversion set schema_version = '1.1.72', updated= CURRENT_TIMESTAMP();
+
+ALTER TABLE skycalResult ADD column n_forced INT after n_extended;
+UPDATE dbversion set schema_version = '1.1.73', updated= CURRENT_TIMESTAMP();
Index: /branches/eam_branches/ipp-20121130/dbconfig/staticsky.md
===================================================================
--- /branches/eam_branches/ipp-20121130/dbconfig/staticsky.md	(revision 34839)
+++ /branches/eam_branches/ipp-20121130/dbconfig/staticsky.md	(revision 34840)
@@ -56,4 +56,5 @@
     n_detections   S32    0
     n_extended     S32    0
+    n_forced       S32    0
     zpt_obs        F32    0.0
     zpt_stdev      F32    0.0
Index: /branches/eam_branches/ipp-20121130/ippMonitor/czartool/czartool/czarconfig.xml
===================================================================
--- /branches/eam_branches/ipp-20121130/ippMonitor/czartool/czartool/czarconfig.xml	(revision 34839)
+++ /branches/eam_branches/ipp-20121130/ippMonitor/czartool/czartool/czarconfig.xml	(revision 34840)
@@ -47,5 +47,5 @@
     <serverinterval>20 MINUTE</serverinterval>
     <!-- whitespace-separated server list for servers we want roboczar to check --> 
-    <interestedservers>stdscience distribution summitcopy registration pstamp</interestedservers>
+    <interestedservers>stdscience distribution summitcopy registration pstamp stack publishing</interestedservers>
     <!-- <interestedservers>pstamp</interestedservers> -->
   </roboczar>
Index: /branches/eam_branches/ipp-20121130/ippconfig/gpc1/psphot.config
===================================================================
--- /branches/eam_branches/ipp-20121130/ippconfig/gpc1/psphot.config	(revision 34839)
+++ /branches/eam_branches/ipp-20121130/ippconfig/gpc1/psphot.config	(revision 34840)
@@ -49,4 +49,14 @@
   DIFF_STATS			    BOOL TRUE	       # Calculate diff-specific stats
   OUTPUT.FORMAT		            STR  PS1_DV2       # Format of output file
+
+  PSPHOT.EXT.NSIGMA.LIMIT	    F32	 0.0
+  PSPHOT.EXT.DIFF.ALTERNATE	    BOOL TRUE
+  PSPHOT.EXT.DIFF.ALTERNATE.THRESH  F32	 1.25
+END
+
+SSTF_DIFF METADATA
+  PSPHOT.EXT.NSIGMA.LIMIT	    F32	 0.0
+  PSPHOT.EXT.DIFF.ALTERNATE	    BOOL TRUE
+  PSPHOT.EXT.DIFF.ALTERNATE.THRESH  F32	 1.25
 END
 
Index: /branches/eam_branches/ipp-20121130/ippconfig/gpc1/pswarp.config
===================================================================
--- /branches/eam_branches/ipp-20121130/ippconfig/gpc1/pswarp.config	(revision 34839)
+++ /branches/eam_branches/ipp-20121130/ippconfig/gpc1/pswarp.config	(revision 34840)
@@ -1,1 +1,4 @@
 ASTROM.SOURCE		STR	PSASTRO.OUTPUT	# Source file rule for astrometry, or NULL
+BACKGROUND.MODEL	BOOL	TRUE
+BKG.XGRID		S32	50
+BKG.YGRID		S32	50
Index: /branches/eam_branches/ipp-20121130/ippconfig/recipes/filerules-mef.mdc
===================================================================
--- /branches/eam_branches/ipp-20121130/ippconfig/recipes/filerules-mef.mdc	(revision 34839)
+++ /branches/eam_branches/ipp-20121130/ippconfig/recipes/filerules-mef.mdc	(revision 34840)
@@ -120,4 +120,5 @@
 PSWARP.SKYCELL          INPUT    @FILES        CHIP       IMAGE
 PSWARP.ASTROM           INPUT    @FILES        CHIP       CMF
+PSWARP.BKGMODEL		  INPUT	   @FILES	 CHIP	    IMAGE
 
 ## files used by ppsub
@@ -138,4 +139,5 @@
 PPSTACK.INPUT.PSF       INPUT    @FILES        CHIP       PSF
 PPSTACK.INPUT.SOURCES   INPUT    @FILES        FPA        CMF
+PPSTACK.INPUT.BKGMODEL	  INPUT	   @FILES	 FPA	    IMAGE
 
 ## files used by ppstamp
@@ -296,4 +298,5 @@
 PSWARP.BIN2             OUTPUT {OUTPUT}.b2.fits                  IMAGE     COMP_IMG   FPA        TRUE      NONE
 PSWARP.CONFIG           OUTPUT {OUTPUT}.pswarp.mdc               TEXT      NONE       FPA        TRUE      NONE
+PSWARP.OUTPUT.BKGMODEL	OUTPUT {OUTPUT}.mdl.fits		      IMAGE	      NONE	 FPA	    TRUE      NONE
                                                                                      
 SKYCELL.STATS           OUTPUT {OUTPUT}.stats                    STATS     NONE       FPA        TRUE      NONE
@@ -342,4 +345,6 @@
 PPSTACK.OUTPUT.JPEG1    OUTPUT {OUTPUT}.b1.jpg                   JPEG      NONE       FPA        TRUE      NONE
 PPSTACK.OUTPUT.JPEG2    OUTPUT {OUTPUT}.b2.jpg                   JPEG      NONE       FPA        TRUE      NONE
+PPSTACK.OUTPUT.BKGMODEL OUTPUT {OUTPUT}.mdl.fits		 IMAGE	   NONE	      FPA	 TRUE      NONE
+PPSTACK.OUTPUT.BKGREST  OUTPUT {OUTPUT}.bkgrest.fits		 IMAGE	   	  NONE	     FPA	TRUE      NONE
 PPSTACK.CONFIG          OUTPUT {OUTPUT}.ppStack.mdc              TEXT      NONE       FPA        TRUE      NONE
                                                                                      
@@ -370,4 +375,6 @@
 PPSKYCELL.BIN1    	OUTPUT {OUTPUT}.{FILE.INDEX}.b1.fits     IMAGE     NONE       FPA        TRUE      NONE
 PPSKYCELL.BIN2    	OUTPUT {OUTPUT}.{FILE.INDEX}.b2.fits     IMAGE     NONE       FPA        TRUE      NONE
+PPSKYCELL.BIN1.MASK    	     OUTPUT {OUTPUT}.{FILE.INDEX}.b1.mk.fits     MASK     COMP_MASK       FPA        TRUE      NONE
+PPSKYCELL.BIN2.MASK    	     OUTPUT {OUTPUT}.{FILE.INDEX}.b2.mk.fits     MASK     COMP_MASK       FPA       TRUE      NONE
 
 LOG.IMFILE              OUTPUT {OUTPUT}.{CHIP.NAME}.log          TEXT      NONE       CHIP       TRUE      NONE
Index: /branches/eam_branches/ipp-20121130/ippconfig/recipes/filerules-simple.mdc
===================================================================
--- /branches/eam_branches/ipp-20121130/ippconfig/recipes/filerules-simple.mdc	(revision 34839)
+++ /branches/eam_branches/ipp-20121130/ippconfig/recipes/filerules-simple.mdc	(revision 34840)
@@ -90,4 +90,5 @@
 PSWARP.SKYCELL            INPUT    @FILES        FPA        IMAGE     
 PSWARP.ASTROM             INPUT    @FILES        FPA        CMF
+PSWARP.BKGMODEL		  INPUT	   @FILES	 CHIP	    IMAGE
 
 ## files used by ppsub
@@ -108,4 +109,5 @@
 PPSTACK.INPUT.PSF         INPUT    @FILES        CHIP       PSF
 PPSTACK.INPUT.SOURCES     INPUT    @FILES        FPA        CMF
+PPSTACK.INPUT.BKGMODEL	  INPUT	   @FILES	 FPA	    IMAGE
 
 ## files used by ppstamp
@@ -251,4 +253,5 @@
 PSWARP.BIN2                  OUTPUT {OUTPUT}.b2.fits              IMAGE           NONE       FPA        TRUE      NONE
 PSWARP.CONFIG                OUTPUT {OUTPUT}.pswarp.mdc           TEXT            NONE       FPA        TRUE      NONE
+PSWARP.OUTPUT.BKGMODEL	     OUTPUT {OUTPUT}.mdl.fits		  IMAGE	      	  NONE	 FPA	    TRUE      NONE
                                                      
 SKYCELL.STATS                OUTPUT {OUTPUT}.stats                STATS           NONE       FPA        TRUE      NONE
@@ -300,4 +303,6 @@
 PPSTACK.OUTPUT.JPEG1         OUTPUT {OUTPUT}.b1.jpg               JPEG            NONE       FPA        TRUE      NONE
 PPSTACK.OUTPUT.JPEG2         OUTPUT {OUTPUT}.b2.jpg               JPEG            NONE       FPA        TRUE      NONE
+PPSTACK.OUTPUT.BKGMODEL      OUTPUT {OUTPUT}.mdl.fits		  IMAGE	   	  NONE	     FPA	TRUE      NONE
+PPSTACK.OUTPUT.BKGREST       OUTPUT {OUTPUT}.bkgrest.fits	  IMAGE	   	  NONE       FPA	TRUE      NONE
 PPSTACK.CONFIG               OUTPUT {OUTPUT}.ppStack.mdc          TEXT            NONE       FPA        TRUE      NONE
                                              
@@ -327,4 +332,6 @@
 PPSKYCELL.BIN1    	     OUTPUT {OUTPUT}.{FILE.INDEX}.b1.fits     IMAGE     NONE       FPA        TRUE      NONE
 PPSKYCELL.BIN2    	     OUTPUT {OUTPUT}.{FILE.INDEX}.b2.fits     IMAGE     NONE       FPA        TRUE      NONE
+PPSKYCELL.BIN1.MASK    	     OUTPUT {OUTPUT}.b1.mk.fits     MASK     COMP_MASK       FPA        TRUE      NONE
+PPSKYCELL.BIN2.MASK    	     OUTPUT {OUTPUT}.b2.mk.fits     MASK     COMP_MASK       FPA       TRUE      NONE
 
 LOG.IMFILE                   OUTPUT {OUTPUT}.imfile.log           TEXT            NONE       FPA        TRUE      NONE
Index: /branches/eam_branches/ipp-20121130/ippconfig/recipes/filerules-split.mdc
===================================================================
--- /branches/eam_branches/ipp-20121130/ippconfig/recipes/filerules-split.mdc	(revision 34839)
+++ /branches/eam_branches/ipp-20121130/ippconfig/recipes/filerules-split.mdc	(revision 34840)
@@ -108,4 +108,5 @@
 PSWARP.SKYCELL            INPUT    @FILES        FPA        IMAGE
 PSWARP.ASTROM             INPUT    @FILES        CHIP       CMF
+PSWARP.BKGMODEL		  INPUT	   @FILES	 CHIP	    IMAGE
                           
 ## files used by ppsub    
@@ -126,4 +127,5 @@
 PPSTACK.INPUT.PSF         INPUT    @FILES        CHIP       PSF
 PPSTACK.INPUT.SOURCES     INPUT    @FILES        FPA        CMF
+PPSTACK.INPUT.BKGMODEL	  INPUT	   @FILES	 FPA	    IMAGE
                           
 ## files used by ppstamp  
@@ -278,4 +280,5 @@
 PSWARP.CONFIG                OUTPUT {OUTPUT}.pswarp.mdc               TEXT            NONE       FPA        TRUE      NONE
 PSWARP.OUTPUT.UNCOMPRESSED   OUTPUT {OUTPUT}.fits		      IMAGE	      NONE	 FPA	    TRUE      NONE
+PSWARP.OUTPUT.BKGMODEL	     OUTPUT {OUTPUT}.mdl.fits		      IMAGE	      NONE	 FPA	    TRUE      NONE
                                                                                                    
 SKYCELL.STATS                OUTPUT {OUTPUT}.stats                    STATS           NONE       FPA        TRUE      NONE
@@ -333,4 +336,6 @@
 PPSTACK.OUTPUT.JPEG1         OUTPUT {OUTPUT}.b1.jpg                   JPEG            NONE       FPA        TRUE      NONE
 PPSTACK.OUTPUT.JPEG2         OUTPUT {OUTPUT}.b2.jpg                   JPEG            NONE       FPA        TRUE      NONE
+PPSTACK.OUTPUT.BKGMODEL      OUTPUT {OUTPUT}.mdl.fits		      IMAGE	      NONE	 FPA	    TRUE      NONE
+PPSTACK.OUTPUT.BKGREST       OUTPUT {OUTPUT}.bkgrest.fits	      IMAGE	      NONE	 FPA	    TRUE      NONE
 PPSTACK.CONFIG               OUTPUT {OUTPUT}.ppStack.mdc              TEXT            NONE       FPA        TRUE      NONE
 
@@ -360,6 +365,8 @@
 PPSKYCELL.JPEG1              OUTPUT {OUTPUT}.0.b1.jpeg     JPEG            NONE       CHIP       TRUE      NONE
 PPSKYCELL.JPEG2              OUTPUT {OUTPUT}.0.b2.jpeg     JPEG            NONE       CHIP       TRUE      NONE
-PPSKYCELL.BIN1    	OUTPUT {OUTPUT}.0.b1.fits     IMAGE     COMP_IMG       FPA        TRUE      NONE
-PPSKYCELL.BIN2    	OUTPUT {OUTPUT}.0.b2.fits     IMAGE     COMP_IMG       FPA       TRUE      NONE
+PPSKYCELL.BIN1    	     OUTPUT {OUTPUT}.b1.fits     IMAGE     COMP_IMG       FPA        TRUE      NONE
+PPSKYCELL.BIN2    	     OUTPUT {OUTPUT}.b2.fits     IMAGE     COMP_IMG       FPA       TRUE      NONE
+PPSKYCELL.BIN1.MASK    	     OUTPUT {OUTPUT}.b1.mk.fits     MASK     COMP_MASK       FPA        TRUE      NONE
+PPSKYCELL.BIN2.MASK    	     OUTPUT {OUTPUT}.b2.mk.fits     MASK     COMP_MASK       FPA       TRUE      NONE
 
 LOG.IMFILE                   OUTPUT {OUTPUT}.{CHIP.NAME}.log          TEXT            NONE       CHIP       TRUE      NONE
Index: /branches/eam_branches/ipp-20121130/ippconfig/recipes/jpeg.mdc
===================================================================
--- /branches/eam_branches/ipp-20121130/ippconfig/recipes/jpeg.mdc	(revision 34839)
+++ /branches/eam_branches/ipp-20121130/ippconfig/recipes/jpeg.mdc	(revision 34840)
@@ -260,5 +260,5 @@
 	SCALE.MIN	F32	 -8.0
 	SCALE.MAX	F32	 +8.0
-	OPTIONS		STR	+SB,-X,+Y
+	OPTIONS		STR	+SB,+X,+Y
 END
 
@@ -268,5 +268,5 @@
 	SCALE.MIN	F32	 -8.0
 	SCALE.MAX	F32	 +8.0
-	OPTIONS		STR	-SB,-X,+Y
+	OPTIONS		STR	-SB,+X,+Y
 END
 
Index: /branches/eam_branches/ipp-20121130/ippconfig/recipes/nightly_science.config
===================================================================
--- /branches/eam_branches/ipp-20121130/ippconfig/recipes/nightly_science.config	(revision 34839)
+++ /branches/eam_branches/ipp-20121130/ippconfig/recipes/nightly_science.config	(revision 34840)
@@ -229,4 +229,5 @@
   DIFFABLE  BOOL TRUE
   REDUCTION STR SWEETSPOT
+  ADDITIONAL_STACK_LABEL STR ecliptic.rp
 #  REDUCTION STR SSTF_4SIG
 #  WARP      S16 60
@@ -240,4 +241,5 @@
   DIFFABLE    BOOL TRUE
   REDUCTION STR SWEETSPOT
+  ADDITIONAL_STACK_LABEL STR ecliptic.rp
 #  REDUCTION STR SSTF_4SIG
 END
@@ -250,4 +252,5 @@
   DIFFABLE    BOOL TRUE
   REDUCTION STR SWEETSPOT
+  ADDITIONAL_STACK_LABEL STR ecliptic.rp
 #  REDUCTION STR SSTF_4SIG
 END
@@ -260,4 +263,5 @@
   DIFFABLE    BOOL TRUE
   REDUCTION STR SWEETSPOT
+  ADDITIONAL_STACK_LABEL STR ecliptic.rp
 #  REDUCTION STR SSTF_4SIG
 END
Index: /branches/eam_branches/ipp-20121130/ippconfig/recipes/ppBackground.mdc
===================================================================
--- /branches/eam_branches/ipp-20121130/ippconfig/recipes/ppBackground.mdc	(revision 34839)
+++ /branches/eam_branches/ipp-20121130/ippconfig/recipes/ppBackground.mdc	(revision 34840)
@@ -1,4 +1,18 @@
 # Recipe options for ppBackground
 
+BINNING_RECIPE	STR	PSPHOT
+BINNING_XNAME	STR	BACKGROUND.XBIN
+BINNING_YNAME	STR	BACKGROUND.YBIN
+
+DEFAULT    METADATA
+END
+
+
+STACK	    METADATA
+  BINNING_RECIPE	STR	PSWARP
+  BINNING_XNAME	STR	BKG.XGRID	
+  BINNING_YNAME	STR	BKG.YGRID
+END
+	    
 
 BACKGROUND	 METADATA
Index: /branches/eam_branches/ipp-20121130/ippconfig/recipes/ppStack.config
===================================================================
--- /branches/eam_branches/ipp-20121130/ippconfig/recipes/ppStack.config	(revision 34839)
+++ /branches/eam_branches/ipp-20121130/ippconfig/recipes/ppStack.config	(revision 34840)
@@ -103,4 +103,6 @@
 STACK.TYPE      STR     DEEP_STACK
 
+DEFAULT.EXPTIME  F32    NAN
+
 # Recipe overrides for STACK
 STACK	METADATA
Index: /branches/eam_branches/ipp-20121130/ippconfig/recipes/ppStats.config
===================================================================
--- /branches/eam_branches/ipp-20121130/ippconfig/recipes/ppStats.config	(revision 34839)
+++ /branches/eam_branches/ipp-20121130/ippconfig/recipes/ppStats.config	(revision 34840)
@@ -127,4 +127,8 @@
   HEADER	STR	IMAGE_V
   HEADER	STR	STREAK_V
+  
+  HEADER        STR     NDET            # sources->n
+  HEADER        STR     NDET_EXT
+  HEADER        STR     NDET_FRC
 
   ANALYSIS      MULTI   # metadata blocks to search in chip/cell/readout->analysis
Index: /branches/eam_branches/ipp-20121130/ippconfig/recipes/ppStatsFromMetadata.config
===================================================================
--- /branches/eam_branches/ipp-20121130/ippconfig/recipes/ppStatsFromMetadata.config	(revision 34839)
+++ /branches/eam_branches/ipp-20121130/ippconfig/recipes/ppStatsFromMetadata.config	(revision 34840)
@@ -544,4 +544,7 @@
   ENTRY  VAL  DT_ASTR             F32  CONSTANT         -dtime_astrom      
   ENTRY  VAL  NASTRO              S32  CONSTANT         -n_astrom          
+  ENTRY  VAL  NDET                S32  CONSTANT         -n_detections
+  ENTRY  VAL  NDET_EXT            S32  CONSTANT         -n_extended
+  ENTRY  VAL  NDET_FRC            S32  CONSTANT         -n_forced
 
   ENTRY  VAL  ZPT_OBS             F32  CONSTANT         -zpt_obs
Index: /branches/eam_branches/ipp-20121130/ippconfig/recipes/psphot.config
===================================================================
--- /branches/eam_branches/ipp-20121130/ippconfig/recipes/psphot.config	(revision 34839)
+++ /branches/eam_branches/ipp-20121130/ippconfig/recipes/psphot.config	(revision 34840)
@@ -345,4 +345,6 @@
 PSPHOT.EXT.NSIGMA.LIMIT             F32   3.0  # sources with extNsigma greater that this get tagged as likely extended sources
 PSPHOT.EXT.NSIGMA.MOMENTS           F32   3.0  # sources with extNsigma greater that this get tagged as likely extended sources
+PSPHOT.EXT.DIFF.ALTERNATE	    BOOL  FALSE           # use alternate extended source calculation; designed for diff trails
+PSPHOT.EXT.DIFF.ALTERNATE.THRESH    F32	  1.5		  # threshold for alternate extended source calculations
 PSPHOT.CR.GROW                      S32   1               # Number of pixels to grow CR mask
 PSPHOT.CR.NSIGMA.SOFTEN             F32   0.0025          # Softening parameter for weights
@@ -382,11 +384,11 @@
 # Note: if an input has a filter not in this list it will be processed after all of the others with MATCH.ALL = FALSE
 PSPHOT.STACK.MATCH.FILTERS   METADATA
-    TYPE        PSPHOT_STACK.MATCH.FILTER FILTER.ID ORDER MATCH.ALL
-    gband       PSPHOT_STACK.MATCH.FILTER   g        4       FALSE
-    rband       PSPHOT_STACK.MATCH.FILTER   r        2       FALSE
-    iband       PSPHOT_STACK.MATCH.FILTER   i        1       FALSE
-    zband       PSPHOT_STACK.MATCH.FILTER   z        3       FALSE
-    yband       PSPHOT_STACK.MATCH.FILTER   y        5       TRUE
-    wband       PSPHOT_STACK.MATCH.FILTER   w        0       FALSE
+    TYPE        PSPHOT_STACK.MATCH.FILTER FILTER.ID ORDER MATCH.ALL Y.RATIO.MAX
+    gband       PSPHOT_STACK.MATCH.FILTER   g        4       FALSE      0
+    rband       PSPHOT_STACK.MATCH.FILTER   r        2       FALSE      1.7
+    iband       PSPHOT_STACK.MATCH.FILTER   i        1       FALSE      1.6
+    zband       PSPHOT_STACK.MATCH.FILTER   z        3       FALSE      1.65
+    yband       PSPHOT_STACK.MATCH.FILTER   y        5       TRUE       0
+    wband       PSPHOT_STACK.MATCH.FILTER   w        0       FALSE      0
 END
 
Index: /branches/eam_branches/ipp-20121130/ippconfig/recipes/pswarp.config
===================================================================
--- /branches/eam_branches/ipp-20121130/ippconfig/recipes/pswarp.config	(revision 34839)
+++ /branches/eam_branches/ipp-20121130/ippconfig/recipes/pswarp.config	(revision 34840)
@@ -19,4 +19,7 @@
 MASKSTAT.ADVISORY   U32 0x080
 
+BACKGROUND.MODEL    BOOL   FALSE             # Construct a warped version of the chip stage background
+BKG.XGRID              S32    4               # These need to be tuned
+BKG.YGRID              S32    4
 
 # Default recipe for warping
Index: /branches/eam_branches/ipp-20121130/tools/ghostbuster.pl
===================================================================
--- /branches/eam_branches/ipp-20121130/tools/ghostbuster.pl	(revision 34840)
+++ /branches/eam_branches/ipp-20121130/tools/ghostbuster.pl	(revision 34840)
@@ -0,0 +1,257 @@
+#! /usr/local/bin/perl -w
+
+use Getopt::Std;
+
+getopts('hvxC',\%opt);
+
+if (exists($opt{h})) {
+    print STDERR "./ghostbuster.pl <inlist>\n";
+    print STDERR "   inlist format: exp_name RA DEC\n";
+    print STDERR "   options:       -h    This help.\n";
+    print STDERR "                  -v    Be more verbose.\n";
+    print STDERR "                  -x    Don't bother with images.\n";
+
+    exit(1);
+}
+
+open (L,">>ghostbuster.log");
+
+while (<>) {
+    chomp;
+    ($exp_name,$ra,$dec) = split /\s+/;
+    if (exists($opt{v})) {
+	print "Working on $exp_name at position $ra $dec\n";
+    }
+    
+    $smf = (split /\n/, `find_images.pl -EVFD -n $exp_name`)[-1];
+    if (exists($opt{v})) {
+	print "  Found SMF: $smf\n";
+    }
+
+    open(C,">./${exp_name}.coord");
+    print C "$ra $dec\n";
+    close(C);
+    
+    $coords = (split /\n/, `ppCoord -astrom $smf -radec ${exp_name}.coord`)[-1];
+    @results = split /\s+/,$coords;
+
+    if (exists($opt{v})) {
+	print "  Obtained coordinate transform: $coords\n";
+    }
+    
+    unless (defined($results[5])&&
+	    (abs($results[0] - $ra) < 1e-3)&&
+	    (abs($results[1] - $dec) < 1e-3)) {
+	warn "$exp_name $ra $dec: failed to do astrometry: $coords\n";
+    }
+    $x_pos = $results[3];
+    $y_pos = $results[4];
+    $chip  = $results[5];
+    $ota   = $chip;
+    $ota =~ s/XY/ota/;
+
+    $raw_file = '';
+    unless(exists($opt{x})) {
+	chomp($raw_file = `find_images.pl -RY -n $exp_name -O $ota`);
+	if ($opt{C}) {
+	    system("ppImage -file neb:///${raw_file} ./${exp_name} -recipe PPIMAGE CHIP  -Db CHIP.FITS TRUE ");
+	}
+	else {
+	    system("ppImage -file neb:///${raw_file} ./${exp_name} -recipe PPIMAGE QUICKMOSAIC -Db CHIP.FITS TRUE -Db BACKGROUND FALSE");
+	    print("ppImage -file neb:///${raw_file} ./${exp_name} -recipe PPIMAGE QUICKMOSAIC -Db CHIP.FITS TRUE -Db BACKGROUND FALSE\n");
+	}
+	open(R,">./${exp_name}.reg");
+	print R "$x_pos $y_pos\n";
+	close(R);
+	push @ds9s, "./${exp_name}.${chip}.ch.fits -regions format xy -regions system image -regions ./${exp_name}.reg -pan to $x_pos $y_pos image ";	
+    }
+    if (exists($opt{v})) {
+	print "  Summary: $exp_name $ra $dec $x_pos $y_pos $chip $ota $smf $raw_file\n";
+    }
+    # Determine if cross talk and extract magnitudes
+    $cell_x = -1;
+    $cell_y = -1;
+    
+    $limit = 590;
+    $cell = 0;
+    while ($cell_x == -1) {
+	if ($x_pos <= $limit) {
+	    $cell_x = $cell;
+	}
+	$cell++;
+	$limit += 18;
+	$limit += 590;
+    }
+    $limit = 598;
+    $cell = 0;
+    while ($cell_y == -1) {
+	if ($y_pos <= $limit) {
+	    $cell_y = $cell;
+	}
+	$cell++;
+	$limit += 12;
+	$limit += 598;
+    }
+    
+    $ota_x = $ota;
+    $ota_y = $ota;
+    $ota_x =~ s/ota(.)./$1/;
+    $ota_y =~ s/ota.(.)/$1/;
+
+    $can_cross_talk = 0;
+    $ct_ota_x = -1;
+    $ct_ota_y = -1;
+    $ct_cell_x = -1;
+    $ct_cell_y = -1;
+    #rule 1
+    
+    if ($opt{v}) {
+	print ">> $ota_x $ota_y $cell_x $cell_y\n";
+    }
+
+    if (($ota_x == 2)&&($cell_x == 3)) {
+	$can_cross_talk = 1;
+	$ct_ota_x = 3;
+	$ct_ota_y = $ota_y;
+	$ct_cell_x = 3;
+	$ct_cell_y = $cell_y;
+	$ct_x = $x_pos;
+	$ct_y = $y_pos;
+    }
+    if (($ota_x == 3)&&($cell_x == 3)) {
+	$can_cross_talk = 1;
+	$ct_ota_x = 2;
+	$ct_ota_y = $ota_y;
+	$ct_cell_x = 3;
+	$ct_cell_y = $cell_y;
+	$ct_x = $x_pos;
+	$ct_y = $y_pos;
+    }
+    #rule 2
+    if (($ota_x == 4)&&($cell_x == 3)) {
+	$can_cross_talk = 1;
+	$ct_ota_x = 5;
+	$ct_ota_y = $ota_y;
+	$ct_cell_x = 3;
+	$ct_cell_y = $cell_y;
+	$ct_x = $x_pos;
+	$ct_y = $y_pos;
+    }
+    if (($ota_x == 5)&&($cell_x == 3)) {
+	$can_cross_talk = 1;
+	$ct_ota_x = 4;
+	$ct_ota_y = $ota_y;
+	$ct_cell_x = 3;
+	$ct_cell_y = $cell_y;
+	$ct_x = $x_pos;
+	$ct_y = $y_pos;
+    }
+    #rule 3
+    if (($ota_x == 2)&&($cell_x == 5)) {
+	$can_cross_talk = 1;
+	$ct_ota_x = 2;
+	$ct_ota_y = $ota_y;
+	$ct_cell_x = 6;
+	$ct_cell_y = $cell_y;
+	$ct_x = $x_pos + 590 + 18;
+	$ct_y = $y_pos;
+    }
+    if (($ota_x == 2)&&($cell_x == 6)) {
+	$can_cross_talk = 1;
+	$ct_ota_x = 2;
+	$ct_ota_y = $ota_y;
+	$ct_cell_x = 5;
+	$ct_cell_y = $cell_y;
+	$ct_x = $x_pos - 590 - 18;
+	$ct_y = $y_pos;
+    }
+    #rule 4
+    if (($ota_x == 5)&&($cell_x == 5)) {
+	$can_cross_talk = 1;
+	$ct_ota_x = 5;
+	$ct_ota_y = $ota_y;
+	$ct_cell_x = 6;
+	$ct_cell_y = $cell_y;
+	$ct_x = $x_pos + 590 + 18;
+	$ct_y = $y_pos;
+    }
+    if (($ota_x == 5)&&($cell_x == 6)) {
+	$can_cross_talk = 1;
+	$ct_ota_x = 5;
+	$ct_ota_y = $ota_y;
+	$ct_cell_x = 6;
+	$ct_cell_y = $cell_y;
+	$ct_x = $x_pos - 590 - 18;
+	$ct_y = $y_pos;
+    }
+    
+    $ct_rule = "NO_CT";
+    if ($can_cross_talk) {
+	$ct_rule = "OTA${ota_x}${ota_y}xy${cell_x}${cell_y}<->OTA${ct_ota_x}${ct_ota_y}xy${ct_cell_x}${ct_cell_y}";
+	$ct_chip  = "XY${ct_ota_x}${ct_ota_y}";
+    }
+    if ($opt{L}) {
+	print "$ct_rule $ct_chip\n";
+    }
+
+    # Find magnitudes
+    if ($smf) {
+	$RR = 5;
+	
+	$mag_det = 'NAN';
+	$mag_ct  = 'NAN';
+
+	open(FD,"fdump $smf ${chip}.psf |");
+	while (<FD>) {
+	    chomp;
+	    if ($_ =~ /IDET/) { next; }
+	    @data = split /\s+/;
+	    if ((abs($x_pos - $data[1]))&&(abs($y_pos - $data[2]))) {
+		$RR_test = sqrt( ($x_pos - $data[1])**2 + 
+				 ($y_pos - $data[2])**2);
+		if ($RR_test < $RR) {
+		    $RR = $RR_test;
+		    $mag_det = $data[7];
+		    $xx_det  = $data[31];
+		    $xy_det  = $data[32];
+		    $yy_det  = $data[33];
+		}
+	    }
+	}
+	close(FD);
+	$r_det = $RR;
+	$r_ct  = 'NAN';
+	$RR = 5;
+	if ($can_cross_talk) {
+	    open(FD,"fdump $smf ${ct_chip}.psf |");
+	    while (<FD>) {
+		chomp;
+		if ($_ =~ /IDET/) { next; }
+		@data = split /\s+/;
+		if ((abs($ct_x - $data[1]))&&(abs($ct_y - $data[2]))) {
+		    $RR_test = sqrt( ($ct_x - $data[1])**2 + 
+				     ($ct_y - $data[2])**2);
+		    if ($RR_test < $RR) {
+			$RR = $RR_test;
+			$mag_ct = $data[7];
+			$xx_ct  = $data[31];
+			$xy_ct  = $data[32];
+			$yy_ct  = $data[33];
+		    }
+		}
+	    }
+	    close(FD);
+	    $r_ct = $RR;
+	}
+    }		    
+
+    print L "$exp_name $ra $dec $x_pos $y_pos $chip $mag_det $xx_det $yy_det $xy_det $r_det $ct_rule $ct_x $ct_y $mag_ct $xx_ct $yy_ct $xy_ct $r_ct\n";
+
+#    system("ds9 ./${exp_name}.${chip}.ch.fits -regions format xy -regions system image -regions ./${exp_name}.reg");
+}
+close(L);
+
+unless(exists($opt{x})) {
+    $options = join " ", @ds9s;
+    system("ds9 $options");
+}
