Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/config/Makefile.am
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/config/Makefile.am	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/config/Makefile.am	(revision 37066)
@@ -5,4 +5,8 @@
   tables.P2.vot \
   tables.ST.vot \
+  tables.DF.vot \
+  tables.DO.vot \
+  tables.FW.vot \
+  tables.FO.vot \
   settings.xml
 
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/config/README
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/config/README	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/config/README	(revision 37066)
@@ -1,3 +1,4 @@
-ippToPspsDbSchema.sql  : SQL commands to build the real (not scratch) ipptopsps database
+ippToPspsDbSchema.sql  : SQL commands to build the real (not scratch) ipptopsps
+database ( the database that tracks/queues the batch creation)
 settings.xml           : locations of things such as mysql dbs of interest
 tables.IN.full.vot     : original version of the init batch tables, with invalid SkyCell, ProjectionCell, Regions
@@ -6,2 +7,21 @@
 tables.P2.vot          : P2 detection batch table
 tables.ST.vot          : stack detection batch table
+tables.DF.vot	       : diff detection batch table
+tables.DO.vot	       : diff object batch table
+tables.FW.vot	       : forced warp measurement table
+tables.FO.vot	       : forced mean object table
+
+
+Heather's Vague Instructions:
+
+to create a new batch db:
+
+create database ipptopsps2
+cut and paste the sql file - should be no problems, I tried to reorganize them so no foriegn key constraint fails.
+
+to make a scratch db:
+ check settings.xml if necessary and recompile
+ mysql -h localhost -u dvo -pdvo -e "create database ipptopsps2_scratch"
+ ippjython setupScratchDb.py
+
+should be good to go!    
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/config/changes.txt
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/config/changes.txt	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/config/changes.txt	(revision 37066)
@@ -0,0 +1,10 @@
+--these are because we do the update process 
+
+alter table skychunk add column P2_smf_version varchar(16) after parallel;
+alter table skychunk add column ST_cmf_version varchar(16) after P2_smf_version;
+
+
+alter table skychunk add trange_start timestamp after ST_cmf_version;
+alter table skychunk add trange_end timestamp after trange_start; 	     	     
+
+-- not yet alter table batch add column smf_version varchar(16) after comment;
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/config/ippToPspsDbSchema.sql
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/config/ippToPspsDbSchema.sql	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/config/ippToPspsDbSchema.sql	(revision 37066)
@@ -45,4 +45,6 @@
   `stage_id` bigint(20) default NULL,
   `total_detections` bigint(20) default NULL,
+  `skychunk` varchar(400) default NULL,
+  `datastore_file` varchar(400) default NULL,
   `comment` varchar(400) default NULL,
   `purged` tinyint(4) NOT NULL default '0',
@@ -51,24 +53,4 @@
 SET character_set_client = @saved_cs_client;
 
---
--- Table structure for table `box`
---
-
-DROP TABLE IF EXISTS `box`;
-SET @saved_cs_client     = @@character_set_client;
-SET character_set_client = utf8;
-CREATE TABLE `box` (
-  `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
-  `id` bigint(20) unsigned NOT NULL auto_increment,
-  `skychunk` varchar(30) default NULL,
-  `ra_center` float default NULL,
-  `dec_center` float default NULL,
-  `box_side` float default NULL,
-  `ingested` varchar(64) default 'none',
-  PRIMARY KEY  (`id`),
-  KEY `fk_skychunk` (`skychunk`),
-  CONSTRAINT `fk_skychunk` FOREIGN KEY (`skychunk`) REFERENCES `skychunk` (`name`) ON DELETE CASCADE
-) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
-SET character_set_client = @saved_cs_client;
 
 --
@@ -125,6 +107,14 @@
   `queue_ST` tinyint(1) default '0',
   `queue_OB` tinyint(1) default '0',
+  `queue_DF` tinyint(1) default '0',
+  `queue_DO` tinyint(1) default '0',
+  `queue_FW` tinyint(1) default '0',
+  `queue_FO` tinyint(1) default '0',
   `active` tinyint(1) default '1',
   `parallel` tinyint(1) default '0',
+  `P2_smf_version` varchar(16) default NULL,
+  `ST_cmf_version` varchar(16) default NULL, 
+  `trange_start`  timestamp NOT NULL default '0000-00-00 00:00:00',
+  `trange_end` timestamp NOT NULL default '0000-00-00 00:00:00',  
   UNIQUE KEY `name` (`name`)
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
@@ -132,4 +122,25 @@
 
 --
+-- Table structure for table `box` needs to be after skychunk or get err:150
+--
+
+DROP TABLE IF EXISTS `box`;
+SET @saved_cs_client     = @@character_set_client;
+SET character_set_client = utf8;
+CREATE TABLE `box` (
+  `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
+  `id` bigint(20) unsigned NOT NULL auto_increment,
+  `skychunk` varchar(30) default NULL,
+  `ra_center` float default NULL,
+  `dec_center` float default NULL,
+  `box_side` float default NULL,
+  `ingested` varchar(64) default 'none',
+  PRIMARY KEY  (`id`),
+  KEY `fk_skychunk` (`skychunk`),
+  CONSTRAINT `fk_skychunk` FOREIGN KEY (`skychunk`) REFERENCES `skychunk` (`name`) ON DELETE CASCADE
+) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
+SET character_set_client = @saved_cs_client;
+
+--
 -- Table structure for table `detection`
 --
@@ -148,4 +159,20 @@
 
 --
+-- Table structure for table `forcedwarp`
+--
+
+DROP TABLE IF EXISTS `forcedwarp`;
+SET @saved_cs_client     = @@character_set_client;
+SET character_set_client = utf8;
+CREATE TABLE `forcedwarp` (
+  `batch_id` bigint(20) unsigned NOT NULL,
+  `exp_id` bigint(20) default NULL,
+  `filter` varchar(1) default NULL,
+  KEY `batch_id` (`batch_id`),
+  CONSTRAINT `forcedwarpd_ibfk_1` FOREIGN KEY (`batch_id`) REFERENCES `batch` (`batch_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+SET character_set_client = @saved_cs_client;
+
+--
 -- Table structure for table `object`
 --
@@ -159,4 +186,18 @@
   KEY `batch_id` (`batch_id`),
   CONSTRAINT `object_fk_1` FOREIGN KEY (`batch_id`) REFERENCES `batch` (`batch_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+SET character_set_client = @saved_cs_client;
+--
+-- Table structure for table `diffobject`
+--
+
+DROP TABLE IF EXISTS `diffobject`;
+SET @saved_cs_client     = @@character_set_client;
+SET character_set_client = utf8;
+CREATE TABLE `diffobject` (
+  `batch_id` bigint(20) unsigned NOT NULL,
+  `region` varchar(50) default NULL,
+  KEY `batch_id` (`batch_id`),
+  CONSTRAINT `diffobject_fk_1` FOREIGN KEY (`batch_id`) REFERENCES `batch` (`batch_id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
 SET character_set_client = @saved_cs_client;
@@ -196,4 +237,20 @@
 
 --
+-- Table structure for table `diff`
+--
+
+DROP TABLE IF EXISTS `diff`;
+SET @saved_cs_client     = @@character_set_client;
+SET character_set_client = utf8;
+CREATE TABLE `diff` (
+  `batch_id` bigint(20) unsigned NOT NULL,
+  `filter` varchar(1) default NULL,
+  `diff_type` varchar(20) default NULL,
+  KEY `batch_id` (`batch_id`),
+  CONSTRAINT `diff_ibfk_1` FOREIGN KEY (`batch_id`) REFERENCES `batch` (`batch_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+SET character_set_client = @saved_cs_client;
+
+--
 -- Table structure for table `stripe`
 --
@@ -221,2 +278,19 @@
 
 -- Dump completed on 2012-04-10  6:00:59
+
+
+DROP TABLE IF EXISTS `dvodb`;
+SET @saved_cs_client     = @@character_set_client;
+SET character_set_client = utf8;
+CREATE TABLE `dvodb` (
+  `dvo_db` varchar(30) default NULL,
+  `batch_type` varchar(10) default NULL,
+  `stage_id` bigint(20) unsigned default NULL,
+  `ra_center` float default NULL,
+  `dec_center` float default NULL,
+  `uniq_key` varchar(30) default NULL,
+  UNIQUE KEY `uniq_key` (`uniq_key`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+SET character_set_client = @saved_cs_client;
+
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/config/parse_vot.pl
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/config/parse_vot.pl	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/config/parse_vot.pl	(revision 37066)
@@ -0,0 +1,120 @@
+#!/usr/bin/env perl
+
+# this thing will just parse the votables and print out in 'ken schema style'
+
+$wiki=1;
+#$csv = 1;
+$infield = 0;
+$intable = 0;
+while (<>) {
+    
+    if ($_ =~/\<FIELD/) {
+	#print "here\n";
+	chomp $_;
+	$name = $_;
+	$name =~ s/.*name=\"//;
+	$name =~ s/\".*//g;
+#	print "\nxxx$name","xxx\n";
+
+	$arraysize = $_;
+	$arraysize =~ s/.*arraysize=\"//;
+	$arraysize =~ s/\".*//g;
+	$datatype = $_;
+	$datatype =~ s/.*datatype=\"//;
+	$datatype =~ s/\".*//g;
+	#this sets all the sizes
+	$datatype1 = "$datatype($arraysize)";
+	if($datatype eq "float") {$datatype1 = "REAL 4";}
+	if($datatype eq "double") {$datatype1 = "FLOAT 8";}
+	if($datatype eq "char") {$datatype1 = "VARCHAR($arraysize)";}
+	if($datatype eq "int") {$datatype1 = "INT 4";}
+	if($datatype eq "short") {$datatype1 = "SMALLINT 2";}
+	if($datatype eq "unsignedByte") {$datatype1 = "TINYINT 1";}
+	if($datatype eq "long") {$datatype1 = "BIGINT 8";}
+
+	if ($csv) {
+	    $datatype1 =~ s/ .//;
+
+	}
+
+	if ($_ =~ /.*default=\"/) {
+
+	    $default = $_;
+	    $default =~ s/.*default=\"//;
+	    $default =~ s/\".*//g;
+
+	} else {$default="";}
+	if ($_ =~ /.*unit=\"/) {
+	    $unit = $_;
+	    $unit =~ s/.*unit=\"//;
+	    $unit =~ s/\".*//g;
+	} else {$unit = "";}
+	if ($wiki) {
+	printf("||%-17s||   %-15s||   %-15s ||   %-5s||",$name, $unit, $datatype1, $default);
+	} elsif ($csv) {
+	    printf("%s,%s,%s,%s,\"",$name, $unit, $datatype1, $default);
+	}
+	
+
+	$infield = 1;
+    } else {
+	if ($infield) {
+	    if ($_ =~ /\<\/DESCRIPTION/) {
+		$t = $_;
+		chomp $t;
+		$t =~ s/\s+\<DESCRIPTION\>//;
+		$t =~ s/\<\/DESCRIPTION\>//;
+		print $t;
+		$infield = 1;
+	    }
+	    
+	    if ($_ =~ /\<\/FIELD/) {
+		if ($wiki) { print "||";}
+		if ($csv) {print "\"";}
+		print "\n";
+		$infield = 0;
+	    }
+	    
+	} else {
+	    #not in field something new
+	    if ($_ =~ /\<TABLE /) {
+		chomp $_;
+		$name = $_;
+		$name =~ s/.*name=\"//;
+		$name =~ s/\".*//g;
+		$intable = 1;
+	        if ($csv) {
+		    print "$name\n";
+		} else {
+		    print "---------------------------\n";
+		    printf ("%-16s   ", $name);
+		}
+	    } else {
+		if ($intable) {
+		    if ($_ =~ /\<\/DESCRIPTION/) {
+			$t = $_;
+			chomp $t;
+			$t =~ s/\s+\<DESCRIPTION\>//;
+			$t =~ s/\<\/DESCRIPTION\>//;
+			if ($csv) {
+			    $dostuff = 1;
+			} else {
+			    print "$t\n";
+			    print "---------------------------\n";
+			}
+			$intable = 1;
+			
+		    }
+		    
+		}
+	    }
+	    if ($_ =~ /\<\/TABLE\>/) {
+		$intable = 0;
+	    }
+
+	    
+	}
+    }
+    
+
+}
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/config/settings.xml
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/config/settings.xml	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/config/settings.xml	(revision 37066)
@@ -6,9 +6,9 @@
   <!-- path for storing logs -->
   <!-- XXX Need to make this different for tests and real, also for different installations -->
-  <logPath>SAS15</logPath>
+  <logPath>ipptopsps_pv2_logs</logPath>
   <!-- local scratch Db section (REAL version) -->
   <localdatabase>
     <loader mach="ipp006">
-      <name>ipptopsps_scratch</name>
+      <name>ipptopsps2_scratch</name>
       <host>ipp006</host>
       <user>dvo</user>
@@ -16,188 +16,6 @@
       <memory>16</memory>
     </loader>
-    <loader mach="ipp007">
-      <name>ipptopsps_scratch</name>
-      <host>ipp007</host>
-      <user>dvo</user>
-      <password>dvo</password>
-      <memory>16</memory>
-    </loader>
-    <loader mach="ipp008">
-      <name>ipptopsps_scratch</name>
-      <host>ipp008</host>
-      <user>dvo</user>
-      <password>dvo</password>
-      <memory>16</memory>
-    </loader>
-    <loader mach="ipp009">
-      <name>ipptopsps_scratch</name>
-      <host>ipp009</host>
-      <user>dvo</user>
-      <password>dvo</password>
-      <memory>16</memory>
-    </loader>
-    <loader mach="ipp010">
-      <name>ipptopsps_scratch</name>
-      <host>ipp010</host>
-      <user>dvo</user>
-      <password>dvo</password>
-      <memory>16</memory>
-    </loader>
-    <loader mach="ipp045">
-      <name>ipptopsps_scratch</name>
-      <host>ipp045</host>
-      <user>dvo</user>
-      <password>dvo</password>
-      <memory>32</memory>
-    </loader>
-    <loader mach="ipp046">
-      <name>ipptopsps_scratch</name>
-      <host>ipp046</host>
-      <user>dvo</user>
-      <password>dvo</password>
-      <memory>32</memory>
-    </loader>
-    <loader mach="ipp047">
-      <name>ipptopsps_scratch</name>
-      <host>ipp047</host>
-      <user>dvo</user>
-      <password>dvo</password>
-      <memory>32</memory>
-    </loader>
-    <loader mach="ipp048">
-      <name>ipptopsps_scratch</name>
-      <host>ipp048</host>
-      <user>dvo</user>
-      <password>dvo</password>
-      <memory>32</memory>
-    </loader>
-    <loader mach="ipp049">
-      <name>ipptopsps_scratch</name>
-      <host>ipp049</host>
-      <user>dvo</user>
-      <password>dvo</password>
-      <memory>32</memory>
-    </loader>
-    <loader mach="ipp050">
-      <name>ipptopsps_scratch</name>
-      <host>ipp050</host>
-      <user>dvo</user>
-      <password>dvo</password>
-      <memory>32</memory>
-    </loader>
-    <loader mach="ipp051">
-      <name>ipptopsps_scratch</name>
-      <host>ipp051</host>
-      <user>dvo</user>
-      <password>dvo</password>
-      <memory>32</memory>
-    </loader>
-    <loader mach="ipp052">
-      <name>ipptopsps_scratch</name>
-      <host>ipp052</host>
-      <user>dvo</user>
-      <password>dvo</password>
-      <memory>32</memory>
-    </loader>
-    <loader mach="ipp053">
-      <name>ipptopsps_scratch</name>
-      <host>ipp053</host>
-      <user>dvo</user>
-      <password>dvo</password>
-      <memory>32</memory>
-    </loader>
-    <loader mach="ipp054">
-      <name>ipptopsps_scratch</name>
-      <host>ipp054</host>
-      <user>dvo</user>
-      <password>dvo</password>
-      <memory>32</memory>
-    </loader>
-    <loader mach="ipp055">
-      <name>ipptopsps_scratch</name>
-      <host>ipp055</host>
-      <user>dvo</user>
-      <password>dvo</password>
-      <memory>32</memory>
-    </loader>
-    <loader mach="ipp056">
-      <name>ipptopsps_scratch</name>
-      <host>ipp056</host>
-      <user>dvo</user>
-      <password>dvo</password>
-      <memory>32</memory>
-    </loader>
-    <loader mach="ipp057">
-      <name>ipptopsps_scratch</name>
-      <host>ipp057</host>
-      <user>dvo</user>
-      <password>dvo</password>
-      <memory>32</memory>
-    </loader>
-    <loader mach="ipp058">
-      <name>ipptopsps_scratch</name>
-      <host>ipp058</host>
-      <user>dvo</user>
-      <password>dvo</password>
-      <memory>32</memory>
-    </loader>
-    <loader mach="ipp059">
-      <name>ipptopsps_scratch</name>
-      <host>ipp059</host>
-      <user>dvo</user>
-      <password>dvo</password>
-      <memory>32</memory>
-    </loader>
-    <loader mach="ipp060">
-      <name>ipptopsps_scratch</name>
-      <host>ipp060</host>
-      <user>dvo</user>
-      <password>dvo</password>
-      <memory>32</memory>
-    </loader>
-    <loader mach="ipp061">
-      <name>ipptopsps_scratch</name>
-      <host>ipp061</host>
-      <user>dvo</user>
-      <password>dvo</password>
-      <memory>32</memory>
-    </loader>
-    <loader mach="ipp062">
-      <name>ipptopsps_scratch</name>
-      <host>ipp062</host>
-      <user>dvo</user>
-      <password>dvo</password>
-      <memory>32</memory>
-    </loader>
-    <loader mach="ipp063">
-      <name>ipptopsps_scratch</name>
-      <host>ipp063</host>
-      <user>dvo</user>
-      <password>dvo</password>
-      <memory>32</memory>
-    </loader>
-    <loader mach="ipp064">
-      <name>ipptopsps_scratch</name>
-      <host>ipp064</host>
-      <user>dvo</user>
-      <password>dvo</password>
-      <memory>32</memory>
-    </loader>
-    <loader mach="ipp065">
-      <name>ipptopsps_scratch</name>
-      <host>ipp065</host>
-      <user>dvo</user>
-      <password>dvo</password>
-      <memory>32</memory>
-    </loader>
-    <loader mach="ipp066">
-      <name>ipptopsps_scratch</name>
-      <host>ipp066</host>
-      <user>dvo</user>
-      <password>dvo</password>
-      <memory>32</memory>
-    </loader>
     <loader mach="stare00">
-      <name>ipptopsps_scratch</name>
+      <name>ipptopsps2_scratch</name>
       <host>stare00</host>
       <user>dvo</user>
@@ -206,5 +24,5 @@
     </loader>
     <loader mach="stare01">
-      <name>ipptopsps_scratch</name>
+      <name>ipptopsps2_scratch</name>
       <host>stare01</host>
       <user>dvo</user>
@@ -213,5 +31,5 @@
     </loader>
     <loader mach="stare02">
-      <name>ipptopsps_scratch</name>
+      <name>ipptopsps2_scratch</name>
       <host>stare02</host>
       <user>dvo</user>
@@ -220,5 +38,5 @@
     </loader>
     <loader mach="stare03">
-      <name>ipptopsps_scratch</name>
+      <name>ipptopsps2_scratch</name>
       <host>stare03</host>
       <user>dvo</user>
@@ -227,5 +45,5 @@
     </loader>
     <loader mach="stare04">
-      <name>ipptopsps_scratch</name>
+      <name>ipptopsps2_scratch</name>
       <host>stare04</host>
       <user>dvo</user>
@@ -259,5 +77,5 @@
   <!-- ippToPsps Db section (REAL version) -->
   <ipptopspsdatabase>
-    <name>ipptopsps</name>
+    <name>ipptopsps2</name>
     <host>ipp006</host>
     <user>dvo</user>
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/config/tables.DF.vot
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/config/tables.DF.vot	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/config/tables.DF.vot	(revision 37066)
@@ -0,0 +1,306 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<VOTABLE version="1.1">
+  <RESOURCE>
+    <TABLE name="DiffMeta">
+      <DESCRIPTION>VOTable description of PSPS table DiffMeta</DESCRIPTION>
+      <PARAM arraysize="1" datatype="char" ucd="meta.bib.author" name="Author" value="PSPS"></PARAM>           
+      <FIELD name="diffMetaID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>diff identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="batchID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+	<DESCRIPTION>batch identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="surveyID" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="NA">
+        <DESCRIPTION>survey flag identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="filterID" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="NA">
+        <DESCRIPTION>filter identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="diffTypeID" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="0">
+        <DESCRIPTION>diff type identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="posImageID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+	<DESCRIPTION>positive image identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="negImageID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+	<DESCRIPTION>negative image identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="skyCellID" arraysize="1" datatype="float" unit="dimensionless" default="NA">
+	<DESCRIPTION>single float givijng PrimaryCell.SkyCell identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="photoCalID" arraysize="1" datatype="int" unit="dimensionless" default="NA">
+	<DESCRIPTION>photometry code</DESCRIPTION>
+      </FIELD>
+      <FIELD name="magSat" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>saturation magnitude level</DESCRIPTION>
+      </FIELD>
+      <FIELD name="analVer" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+        <DESCRIPTION>analysis version index</DESCRIPTION>
+      </FIELD>
+      <FIELD name="expTime" arraysize="1" datatype="float" unit="seconds" default="-999">
+	<DESCRIPTION>exposure time of positive image</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ctype1" arraysize="100" datatype="char" unit="alphanumeric" default="8000">
+        <DESCRIPTION>name of astrometric projection in RA</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ctype2" arraysize="100" datatype="char" unit="alphanumeric" default="8000">
+        <DESCRIPTION>name of astrometric projection in DEC</DESCRIPTION>
+      </FIELD>
+      <FIELD name="crval1" arraysize="1" datatype="double" unit="degrees" default="-999">
+        <DESCRIPTION> RA corresponding to reference pixel</DESCRIPTION>
+      </FIELD>
+      <FIELD name="crval2" arraysize="1" datatype="double" unit="degrees" default="-999">
+        <DESCRIPTION> DEC corresponding to reference pixel</DESCRIPTION>
+      </FIELD>
+      <FIELD name="crpix1" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>reference pixel value for RA</DESCRIPTION>
+      </FIELD>
+      <FIELD name="crpix2" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>reference pixel value for DEC</DESCRIPTION>
+      </FIELD>
+      <FIELD name="cdelt1" arraysize="1" datatype="double" unit="degrees/pixel" default="-999">
+        <DESCRIPTION>scale factor for RA</DESCRIPTION>
+      </FIELD>
+      <FIELD name="cdelt2" arraysize="1" datatype="double" unit="degrees/pixel" default="-999">
+        <DESCRIPTION>scale factor for DEC</DESCRIPTION>
+      </FIELD>
+      <FIELD name="pc001001" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>elements of rotation/scale matrix</DESCRIPTION>
+      </FIELD>
+      <FIELD name="pc001002" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>elements of rotation/scale matrix</DESCRIPTION>
+      </FIELD>
+      <FIELD name="pc002001" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>elements of rotation/scale matrix</DESCRIPTION>
+      </FIELD>
+      <FIELD name="pc002002" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>elements of rotation/scale matrix</DESCRIPTION>
+      </FIELD>
+      <FIELD name="calibModNum" arraysize="1" datatype="short" unit="dimensionless" default="NA">
+        <DESCRIPTION>calibration modification number</DESCRIPTION>
+      </FIELD>
+      <FIELD name="dataRelease" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="NA">
+        <DESCRIPTION>Data release</DESCRIPTION>
+      </FIELD>
+      <DATA>
+        <TABLEDATA></TABLEDATA>
+      </DATA>
+    </TABLE>
+    <TABLE name="DiffDetection">
+      <DESCRIPTION>VOTable description of PSPS table DiffDetection</DESCRIPTION>
+      <PARAM arraysize="1" datatype="char" ucd="meta.bib.author" name="Author" value="PSPS"></PARAM>
+      <FIELD name="diffObjID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>ODM diff object identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="diffgcobjID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>galactic coordinates ODM object identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="diffDetID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>ODM diff detection identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="diffDetMetaID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+	<DESCRIPTION>diff detection meta identifer</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ippDetectID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>detection id generated by IPP</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ippObjID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>object id generated by IPP</DESCRIPTION>
+      </FIELD>
+      <FIELD name="filterID" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="NA">
+        <DESCRIPTION>filter ID: g=1, r=2, i=3, z=4, y=5, w=6, ...</DESCRIPTION>
+      </FIELD>
+      <FIELD name="surveyID" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="NA">
+        <DESCRIPTION>survey flag identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="randomDiffID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION> random diff id</DESCRIPTION>
+      </FIELD>
+      <FIELD name="skyCellID" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>single float givijng PrimaryCell.SkyCell identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="dvoRegionID" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION> identifier to dvo spacial region</DESCRIPTION>
+      </FIELD>
+      <FIELD name="obsTime" arraysize="1" datatype="double" unit="MeanJulianDays" default="-999">
+        <DESCRIPTION> Time of mid observation of positive detection in Mean Julian Days</DESCRIPTION>
+      </FIELD>
+      <FIELD name="xPos" arraysize="1" datatype="float" unit="pixels" default="-999">
+        <DESCRIPTION> measured x on CCD from PSF fit</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yPos" arraysize="1" datatype="float" unit="pixels" default="-999">
+        <DESCRIPTION> measured y on CCD from PSF fit</DESCRIPTION>
+      </FIELD>
+      <FIELD name="xPosErr" arraysize="1" datatype="float" unit="pixels" default="-999">
+        <DESCRIPTION> estimated error in x</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yPosErr" arraysize="1" datatype="float" unit="pixels" default="-999">
+        <DESCRIPTION> estimated error in y</DESCRIPTION>
+      </FIELD>
+      <FIELD name="pltScale" arraysize="1" datatype="float" unit="arcsec/pix" default="-999">
+	<DESCRIPTION>plate scale at this location (from DVO)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="posAngle" arraysize="1" datatype="float" unit="degrees" default="-999">
+	<DESCRIPTION>position angle (sky-to-chip) at this location (from DVO)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ra" arraysize="1" datatype="double" unit="degrees" default="NA">
+        <DESCRIPTION>right ascension</DESCRIPTION>
+      </FIELD>
+      <FIELD name="dec" arraysize="1" datatype="double" unit="degrees" default="NA">
+        <DESCRIPTION>declination</DESCRIPTION>
+      </FIELD>
+      <FIELD name="raErr" arraysize="1" datatype="float" unit="arcsec" default="NA">
+        <DESCRIPTION>right ascension error</DESCRIPTION>
+      </FIELD>
+      <FIELD name="decErr" arraysize="1" datatype="float" unit="arcsec" default="NA">
+        <DESCRIPTION>declination error</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zp" arraysize="1" datatype="float" unit="magnitude" default="0">
+        <DESCRIPTION>zeropoint</DESCRIPTION>
+      </FIELD>
+      <FIELD name="telluricExt" arraysize="1" datatype="float" unit="magnitude" default="NA">
+        <DESCRIPTION>estimated extinction due to non-photometric conditions</DESCRIPTION>
+      </FIELD>
+      <FIELD name="expTime" arraysize="1" datatype="float" unit="seconds" default="-999">
+        <DESCRIPTION>exposure time (informational)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="airMass" arraysize="1" datatype="float" unit="dimensionless" default="0">
+        <DESCRIPTION>airmass (informational)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="psfFlux" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION> PSF instrumental flux (in analog-to-digital units/sec) or	adu/sec</DESCRIPTION>
+      </FIELD>
+      <FIELD name="psfFluxErr" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION> estimated error in flux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="psfMajorFWHM" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION> model PSF width in major axis</DESCRIPTION>
+      </FIELD>
+      <FIELD name="psfMinorFWHM" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION> model PSF width in minor axis</DESCRIPTION>
+      </FIELD>
+      <FIELD name="psfTheta" arraysize="1" datatype="float" unit="degrees" default="-999">
+        <DESCRIPTION> model PSF orientation angle degrees East of North</DESCRIPTION>
+      </FIELD>
+      <FIELD name="psfCore" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>model PSF core parameter [k in (1 + kz + z^1.66)]</DESCRIPTION>
+      </FIELD>
+      <FIELD name="psfQf" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>PSF coverage factor</DESCRIPTION>
+      </FIELD>
+      <FIELD name="psfQfPerfect" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>PSF-weighted fraction of pixels totally unmasked</DESCRIPTION>
+      </FIELD>
+      <FIELD name="psfChiSq" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>reduced-chisq of the psf model fit. (ndof?, npix?)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="psfLikelihood" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>PSF likelihood</DESCRIPTION>
+      </FIELD>
+      <FIELD name="momentXX" arraysize="1" datatype="float" unit="raw pixels" default="-999">
+        <DESCRIPTION> moment XX</DESCRIPTION>
+      </FIELD>
+      <FIELD name="momentXY" arraysize="1" datatype="float" unit="raw pixels" default="-999">
+        <DESCRIPTION> moment XY</DESCRIPTION>
+      </FIELD>
+      <FIELD name="momentYY" arraysize="1" datatype="float" unit="raw pixels" default="-999">
+        <DESCRIPTION> moment YY</DESCRIPTION>
+      </FIELD>
+      <FIELD name="momentR1" arraysize="1" datatype="float" unit="raw pixels" default="-999">
+        <DESCRIPTION> first radial moment</DESCRIPTION>
+      </FIELD>
+      <FIELD name="momentRH" arraysize="1" datatype="float" unit="raw pixels" default="-999">
+        <DESCRIPTION> half radial moment</DESCRIPTION>
+      </FIELD>
+      <FIELD name="momentM3C" arraysize="1" datatype="float" unit="raw pixels" default="-999">
+        <DESCRIPTION> 3rd moment cos(theta)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="momentM3S" arraysize="1" datatype="float" unit="raw pixels" default="-999">
+        <DESCRIPTION> 3rd moment sin(theta)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="momentM4C" arraysize="1" datatype="float" unit="raw pixels" default="-999">
+        <DESCRIPTION> 4th moment cos(theta)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="momentM4S" arraysize="1" datatype="float" unit="raw pixels" default="-999">
+        <DESCRIPTION> 4th moment sin(theta)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="apFlux" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION> Aperture Flux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="apFluxErr" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION> Aperture Flux error</DESCRIPTION>
+      </FIELD>
+      <FIELD name="apFillF" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION> Aperture fill factor</DESCRIPTION>
+      </FIELD>
+      <FIELD name="kronFlux" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION> Kron flux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="kronFluxErr" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION> Kron flux error</DESCRIPTION>
+      </FIELD>
+      <FIELD name="kronRad" arraysize="1" datatype="float" unit="raw pixels" default="-999">
+        <DESCRIPTION> Kron radius</DESCRIPTION>
+      </FIELD>
+      <FIELD name="kronRadErr" arraysize="1" datatype="float" unit="raw pixels" default="-999">
+        <DESCRIPTION> Kron radius error</DESCRIPTION>
+      </FIELD>
+      <FIELD name="diffNPos" arraysize="1" datatype="int" unit="dimensionless" default="-999">
+	<DESCRIPTION>NPix > 3sigma</DESCRIPTION>
+      </FIELD>
+      <FIELD name="diffFRatio" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>fPos/(fPos + fNeg)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="diffNBad" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>nPos/(nPos + nNeg)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="diffNMask" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>nPos/(nPos + nMask)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="diffNAll" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>nPos/(nPos + nMask + nNeg)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="diffPdist" arraysize="1" datatype="float" unit="pixels" default="-999">
+	<DESCRIPTION>distance to positive match source</DESCRIPTION>
+      </FIELD>
+      <FIELD name="diffNdist" arraysize="1" datatype="float" unit="pixels" default="-999">
+	<DESCRIPTION>distance to negative match source</DESCRIPTION>
+      </FIELD>
+      <FIELD name="diffPSN" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>signal to noise of pos match source</DESCRIPTION>
+      </FIELD>
+      <FIELD name="diffNSN" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>signal to noise of neg match source</DESCRIPTION>
+      </FIELD>
+      <FIELD name="sky" arraysize="1" datatype="float" unit="adu/sec/pixel" default="-999">
+        <DESCRIPTION> PSF sky level at source</DESCRIPTION>
+      </FIELD>
+      <FIELD name="skyErr" arraysize="1" datatype="float" unit="adu/sec/pixel" default="-999">
+        <DESCRIPTION> estimated error in sky</DESCRIPTION>
+      </FIELD>
+      <FIELD name="infoFlag" arraysize="1" datatype="long" unit="dimensionless" default="-999">
+        <DESCRIPTION>flag indicating provenance information</DESCRIPTION>
+      </FIELD>
+      <FIELD name="dataRelease" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="NA">
+        <DESCRIPTION>Data release when this detection was originally taken. Recalibrations do not affect this value.</DESCRIPTION>
+      </FIELD>
+      <DATA>
+        <TABLEDATA></TABLEDATA>
+      </DATA>
+    </TABLE>
+    <TABLE name="DiffToImage">
+      <DESCRIPTION>VOTable description of PSPS table DiffToImage</DESCRIPTION>
+      <PARAM arraysize="1" datatype="char" ucd="meta.bib.author" name="Author" value="PSPS"></PARAM>
+      <FIELD name="diffMetaID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>diff identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="imageID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>hashed exposure-ccdID identifier</DESCRIPTION>
+      </FIELD>
+      <DATA>
+        <TABLEDATA></TABLEDATA>
+      </DATA>
+    </TABLE>
+  </RESOURCE>
+</VOTABLE>
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/config/tables.DO.vot
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/config/tables.DO.vot	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/config/tables.DO.vot	(revision 37066)
@@ -0,0 +1,112 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<VOTABLE version="1.1">
+  <RESOURCE>
+    <TABLE name="DiffDetObject">
+      <DESCRIPTION>VOTable description of PSPS table DifDetObject</DESCRIPTION>
+      <PARAM arraysize="1" datatype="char" ucd="meta.bib.author" name="Author" value="PSPS"></PARAM>
+      <FIELD name="diffObjName" arraysize="100" datatype="char" unit="alphanumeric" default="NA">
+        <DESCRIPTION>IAU Name constructed from objID position PS1.x JHHMMSS.SS+/-</DESCRIPTION>
+      </FIELD>
+      <FIELD name="diffObjID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>ODM object identifier index</DESCRIPTION>
+      </FIELD>
+      <FIELD name="diffgcobjID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>galactic coordinates ODM object identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ippObjID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>IPP object number</DESCRIPTION>
+      </FIELD>
+      <FIELD name="surveyID" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="255">
+	<DESCRIPTION>Survey ID</DESCRIPTION>
+      </FIELD>
+      <FIELD name="skyCellID" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>single float giving PrimaryCell.SkyCell identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="htmID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>HTM index</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zoneID" arraysize="1" datatype="int" unit="dimensionless" default="NA">
+        <DESCRIPTION>Zone index</DESCRIPTION>
+      </FIELD>
+      <FIELD name="randomID" arraysize="1" datatype="long" unit="dimensionless" default="0">
+	<DESCRIPTION>Random integer between 0 and 2^32 = 4,394,967,296</DESCRIPTION>
+      </FIELD>
+      <FIELD name="batchID" arraysize="1" datatype="long" unit="dimensionless" default="-999">
+	<DESCRIPTION>batchID</DESCRIPTION>
+      </FIELD>
+      <FIELD name="dvoRegionID" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>identifier to dvo spatial region</DESCRIPTION>
+      </FIELD>
+      <FIELD name="objInfoFlag" arraysize="1" datatype="long" unit="dimensionless" default="-999">
+        <DESCRIPTION>flag indicating odd properties</DESCRIPTION>
+      </FIELD>
+      <FIELD name="qualityFlag" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="0">
+        <DESCRIPTION>subset of objInfoFlag - flags related to goodness of object</DESCRIPTION>
+      </FIELD>
+      <FIELD name="consistencyFlag" arraysize="1" datatype="short" unit="dimensionless" default="0">
+        <DESCRIPTION>Value computed from associated detections, it is originally given by IPP and should agree with the ODM validation</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ra" arraysize="1" datatype="double" unit="degrees" default="NA">
+        <DESCRIPTION> Right Ascension</DESCRIPTION>
+      </FIELD>
+      <FIELD name="dec" arraysize="1" datatype="double" unit="degrees" default="NA">
+        <DESCRIPTION> Declination</DESCRIPTION>
+      </FIELD>
+      <FIELD name="raErr" arraysize="1" datatype="float" unit="arcsec" default="0.0">
+        <DESCRIPTION> Right Ascension error</DESCRIPTION>
+      </FIELD>
+      <FIELD name="decErr" arraysize="1" datatype="float" unit="arcsec" default="0.0">
+        <DESCRIPTION> Declination error</DESCRIPTION>
+      </FIELD>
+      <FIELD name="cx" arraysize="1" datatype="double" unit="dimensionless" default="NA"> 
+	<DESCRIPTION>Cartesian x</DESCRIPTION> 
+      </FIELD> 
+      <FIELD name="cy" arraysize="1" datatype="double" unit="dimensionless" default="NA"> 
+        <DESCRIPTION>Cartesian y</DESCRIPTION> 
+      </FIELD> 
+      <FIELD name="cz" arraysize="1" datatype="double" unit="dimensionless" default="NA"> 
+        <DESCRIPTION>Cartesian z</DESCRIPTION> 
+      </FIELD> 
+      <FIELD name="lambda" arraysize="1" datatype="double" unit="degrees" default="-999">
+        <DESCRIPTION> ecliptic longitude</DESCRIPTION>
+      </FIELD>
+      <FIELD name="beta" arraysize="1" datatype="double" unit="degrees" default="-999">
+        <DESCRIPTION> ecliptic latitude</DESCRIPTION>
+      </FIELD>
+      <FIELD name="l" arraysize="1" datatype="double" unit="degrees" default="-999">
+        <DESCRIPTION> galactic longitude</DESCRIPTION>
+      </FIELD>
+      <FIELD name="b" arraysize="1" datatype="double" unit="degrees" default="-999">
+        <DESCRIPTION> galactic latitude</DESCRIPTION>
+      </FIELD>
+      <FIELD name="qfPerfect" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>qf perfect</DESCRIPTION>
+      </FIELD>
+      <FIELD name="dataRelease" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="NA">
+        <DESCRIPTION>Data release</DESCRIPTION>
+      </FIELD>
+      <FIELD name="nDetections" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+        <DESCRIPTION>total number of detection measurements in all filters</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ng" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+        <DESCRIPTION>number of measures in g filter</DESCRIPTION>
+      </FIELD>
+      <FIELD name="nr" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+        <DESCRIPTION>number of measures in r filter</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ni" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+        <DESCRIPTION>number of measures in i filter</DESCRIPTION>
+      </FIELD>
+      <FIELD name="nz" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+        <DESCRIPTION>number of measures in z filter</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ny" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+        <DESCRIPTION>number of measures in y filter</DESCRIPTION>
+      </FIELD>
+      <DATA>
+        <TABLEDATA></TABLEDATA>
+      </DATA>
+    </TABLE>
+  </RESOURCE>
+</VOTABLE>
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/config/tables.FO.vot
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/config/tables.FO.vot	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/config/tables.FO.vot	(revision 37066)
@@ -0,0 +1,748 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<VOTABLE version="1.1">
+  <RESOURCE>
+    <TABLE name="ForcedMeanObject">
+      <DESCRIPTION>VOTable description of PSPS table ForcedMeanObject</DESCRIPTION>
+      <PARAM arraysize="1" datatype="char" ucd="meta.bib.author" name="Author" value="PSPS"></PARAM>
+      <FIELD name="objID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>ODM object identifier index</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gcobjID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>galactic coordinates ODM object identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ippObjID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>IPP object number</DESCRIPTION>
+      </FIELD>
+      <FIELD name="nDetections" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+        <DESCRIPTION>total number of detection measurements in all filters</DESCRIPTION>
+      </FIELD>
+      <FIELD name="batchID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>batch id</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gStackID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+	<DESCRIPTION>stack image id (how to carry through IPP+DVO</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gnTotal" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+        <DESCRIPTION>number of detections in g filter</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gnIncPSFMag" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+        <DESCRIPTION>number of detections included in robust psf mean in g filter</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gnIncKronMag" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+        <DESCRIPTION>number of detections included in robust mean of Kron mag in g filter</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gnIncApMag" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+        <DESCRIPTION>number of detections included in robust mean of Ap Mag in g filter</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gnIncR5" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+        <DESCRIPTION>number of detections included in robust mean of ApFlx 5 in g filter</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gnIncR6" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+        <DESCRIPTION>number of detections included in robust mean of ApFlx 6 in g filter</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gPSFMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION> robust mean g psf AB magnitude (sigma clipping or MAP or go to 5 or 7 number summary? 1/12 is ~9th percentile</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gPSFMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION> estimated error of g psf AB magnitude mean(individual errors added in quadrature)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gPSFMagStd" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>standard deviation of measurements included in the robust mean</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gKronMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>mean g kron AB magnitude</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gKronMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION> estimated error of g kron AB magnitude mean</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gKronMagStd" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>standard deviation of measurements included in the robust mean</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gApMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>mean g aperture AB magnitude</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gApMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION> estimated error of g aperture AB magnitude mean</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gApMagStd" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>standard deviation of measurements included in the robust mean</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gFmeanflxR5" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 5 in g unconvolved stack</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gFmeanflxR5Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gFmeanflxR5Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gFmeanflxR5Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gFmeanflxR6" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 6 in g unconvolved stack</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gFmeanflxR6Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in flxR6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gFmeanflxR6Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gFmeanflxR6Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gFlags" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>flags for g forced</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gLensObjSmearX11" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>per-object smear polarizability X11 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gLensObjSmearX12" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>per-object smear polarizability X12 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gLensObjSmearX22" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>per-object smear polarizability X22 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gLensObjSmearE1" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>per-object smear polarizability E1 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gLensObjSmearE2" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>per-object smear polarizability E2 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gLensObjShearX11" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>per-object shear polarizability X11 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gLensObjShearX12" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>per-object shear polarizability X12 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gLensObjShearX22" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>per-object shear polarizability X22 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gLensObjShearE1" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>per-object shear polarizability E1 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gLensObjShearE2" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>per-object shear polarizability E2 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gLensPSFSmearX11" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>psf model smear polarizability X11 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gLensPSFSmearX12" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>psf model smear polarizability X12 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gLensPSFSmearX22" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>psf model smear polarizability X22 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gLensPSFSmearE1" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>psf model smear polarizability E1 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gLensPSFSmearE2" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>psf model smear polarizability E2 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gLensPSFShearX11" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>psf model shear polarizability X11 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gLensPSFShearX12" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>psf model shear polarizability X12 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gLensPSFShearX22" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>psf model shear polarizability X22 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gLensPSFShearE1" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>psf model shear polarizability E1 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gLensPSFShearE2" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>psf model shear polarizability E2 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gGamma" arraysize="1" datatype="float" unit="arcsec^2" default="-999">
+	<DESCRIPTION>second moment (Mxx+Myy)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gE1" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>polarization, KSB-corrected (Mxx - Myy) / (Mxx + Myy)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gE2" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>polarization, KSB-corrected 2Mxy / (Mxx + Myy)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rStackID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+	<DESCRIPTION>stack image id (how to carry through IPP+DVO</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rnTotal" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+        <DESCRIPTION>number of detections in r filter</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rnIncPSFMag" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+        <DESCRIPTION>number of detections included in robust psf mean in r filter</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rnIncKronMag" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+        <DESCRIPTION>number of detections included in robust mean of Kron mag in r filter</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rnIncApMag" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+        <DESCRIPTION>number of detections included in robust mean of Ap Mag in r filter</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rnIncR5" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+        <DESCRIPTION>number of detections included in robust mean of ApFlx 5 in r filter</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rnIncR6" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+        <DESCRIPTION>number of detections included in robust mean of ApFlx 6 in r filter</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rPSFMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION> robust mean r psf AB magnitude (sigma clipping or MAP or go to 5 or 7 number summary? 1/12 is ~9th percentile</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rPSFMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION> estimated error of g psf AB magnitude mean(individual errors added in quadrature)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rPSFMagStd" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>standard deviation of measurements included in the robust mean</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rKronMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>mean r kron AB magnitude</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rKronMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION> estimated error of r kron AB magnitude mean</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rKronMagStd" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>standard deviation of measurements included in the robust mean</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rApMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>mean r aperture AB magnitude</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rApMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION> estimated error of r aperture AB magnitude mean</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rApMagStd" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>standard deviation of measurements included in the robust mean</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rFmeanflxR5" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 5 in r unconvolved stack</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rFmeanflxR5Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rFmeanflxR5Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rFmeanflxR5Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rFmeanflxR6" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 6 in r unconvolved stack</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rFmeanflxR6Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in flxR6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rFmeanflxR6Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rFmeanflxR6Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rFlags" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>flags for r forced</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rLensObjSmearX11" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>per-object smear polarizability X11 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rLensObjSmearX12" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>per-object smear polarizability X12 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rLensObjSmearX22" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>per-object smear polarizability X22 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rLensObjSmearE1" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>per-object smear polarizability E1 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rLensObjSmearE2" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>per-object smear polarizability E2 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rLensObjShearX11" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>per-object shear polarizability X11 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rLensObjShearX12" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>per-object shear polarizability X12 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rLensObjShearX22" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>per-object shear polarizability X22 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rLensObjShearE1" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>per-object shear polarizability E1 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rLensObjShearE2" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>per-object shear polarizability E2 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rLensPSFSmearX11" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>psf model smear polarizability X11 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rLensPSFSmearX12" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>psf model smear polarizability X12 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rLensPSFSmearX22" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>psf model smear polarizability X22 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rLensPSFSmearE1" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>psf model smear polarizability E1 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rLensPSFSmearE2" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>psf model smear polarizability E2 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rLensPSFShearX11" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>psf model shear polarizability X11 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rLensPSFShearX12" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>psf model shear polarizability X12 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rLensPSFShearX22" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>psf model shear polarizability X22 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rLensPSFShearE1" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>psf model shear polarizability E1 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rLensPSFShearE2" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>psf model shear polarizability E2 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rGamma" arraysize="1" datatype="float" unit="arcsec^2" default="-999">
+	<DESCRIPTION>second moment (Mxx+Myy)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rE1" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>polarization, KSB-corrected (Mxx - Myy) / (Mxx + Myy)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rE2" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>polarization, KSB-corrected 2Mxy / (Mxx + Myy)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iStackID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+	<DESCRIPTION>stack image id (how to carry through IPP+DVO</DESCRIPTION>
+      </FIELD>
+      <FIELD name="inTotal" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+        <DESCRIPTION>number of detections in i filter</DESCRIPTION>
+      </FIELD>
+      <FIELD name="inIncPSFMag" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+        <DESCRIPTION>number of detections included in robust psf mean in i filter</DESCRIPTION>
+      </FIELD>
+      <FIELD name="inIncKronMag" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+        <DESCRIPTION>number of detections included in robust mean of Kron mag in i filter</DESCRIPTION>
+      </FIELD>
+      <FIELD name="inIncApMag" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+        <DESCRIPTION>number of detections included in robust mean of Ap Mag in i filter</DESCRIPTION>
+      </FIELD>
+      <FIELD name="inIncR5" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+        <DESCRIPTION>number of detections included in robust mean of ApFlx 5 in i filter</DESCRIPTION>
+      </FIELD>
+      <FIELD name="inIncR6" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+        <DESCRIPTION>number of detections included in robust mean of ApFlx 6 in i filter</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iPSFMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION> robust mean i psf AB magnitude (sigma clipping or MAP or go to 5 or 7 number summary? 1/12 is ~9th percentile</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iPSFMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION> estimated error of i psf AB magnitude mean(individual errors added in quadrature)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iPSFMagStd" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>standard deviation of measurements included in the robust mean</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iKronMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>mean i kron AB magnitude</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iKronMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION> estimated error of i kron AB magnitude mean</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iKronMagStd" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>standard deviation of measurements included in the robust mean</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iApMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>mean i aperture AB magnitude</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iApMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION> estimated error of i aperture AB magnitude mean</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iApMagStd" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>standard deviation of measurements included in the robust mean</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iFmeanflxR5" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 5 in i unconvolved stack</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iFmeanflxR5Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iFmeanflxR5Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iFmeanflxR5Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iFmeanflxR6" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 6 in i unconvolved stack</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iFmeanflxR6Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in flxR6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iFmeanflxR6Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iFmeanflxR6Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iFlags" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>flags for i forced</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iLensObjSmearX11" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>per-object smear polarizability X11 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iLensObjSmearX12" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>per-object smear polarizability X12 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iLensObjSmearX22" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>per-object smear polarizability X22 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iLensObjSmearE1" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>per-object smear polarizability E1 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iLensObjSmearE2" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>per-object smear polarizability E2 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iLensObjShearX11" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>per-object shear polarizability X11 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iLensObjShearX12" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>per-object shear polarizability X12 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iLensObjShearX22" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>per-object shear polarizability X22 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iLensObjShearE1" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>per-object shear polarizability E1 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iLensObjShearE2" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>per-object shear polarizability E2 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iLensPSFSmearX11" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>psf model smear polarizability X11 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iLensPSFSmearX12" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>psf model smear polarizability X12 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iLensPSFSmearX22" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>psf model smear polarizability X22 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iLensPSFSmearE1" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>psf model smear polarizability E1 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iLensPSFSmearE2" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>psf model smear polarizability E2 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iLensPSFShearX11" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>psf model shear polarizability X11 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iLensPSFShearX12" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>psf model shear polarizability X12 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iLensPSFShearX22" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>psf model shear polarizability X22 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iLensPSFShearE1" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>psf model shear polarizability E1 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iLensPSFShearE2" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>psf model shear polarizability E2 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iGamma" arraysize="1" datatype="float" unit="arcsec^2" default="-999">
+	<DESCRIPTION>second moment (Mxx+Myy)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iE1" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>polarization, KSB-corrected (Mxx - Myy) / (Mxx + Myy)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iE2" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>polarization, KSB-corrected 2Mxy / (Mxx + Myy)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zStackID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+	<DESCRIPTION>stack image id (how to carry through IPP+DVO</DESCRIPTION>
+      </FIELD>
+      <FIELD name="znTotal" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+        <DESCRIPTION>number of detections in z filter</DESCRIPTION>
+      </FIELD>
+      <FIELD name="znIncPSFMag" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+        <DESCRIPTION>number of detections included in robust psf mean in z filter</DESCRIPTION>
+      </FIELD>
+      <FIELD name="znIncKronMag" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+        <DESCRIPTION>number of detections included in robust mean of Kron mag in z filter</DESCRIPTION>
+      </FIELD>
+      <FIELD name="znIncApMag" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+        <DESCRIPTION>number of detections included in robust mean of Ap Mag in z filter</DESCRIPTION>
+      </FIELD>
+      <FIELD name="znIncR5" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+        <DESCRIPTION>number of detections included in robust mean of ApFlx 5 in z filter</DESCRIPTION>
+      </FIELD>
+      <FIELD name="znIncR6" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+        <DESCRIPTION>number of detections included in robust mean of ApFlx 6 in z filter</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zPSFMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION> robust mean z psf AB magnitude (sigma clipping or MAP or go to 5 or 7 number summary? 1/12 is ~9th percentile</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zPSFMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION> estimated error of z psf AB magnitude mean(individual errors added in quadrature)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zPSFMagStd" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>standard deviation of measurements included in the robust mean</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zKronMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>mean z kron AB magnitude</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zKronMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION> estimated error of z kron AB magnitude mean</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zKronMagStd" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>standard deviation of measurements included in the robust mean</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zApMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>mean z aperture AB magnitude</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zApMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION> estimated error of z aperture AB magnitude mean</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zApMagStd" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>standard deviation of measurements included in the robust mean</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zFmeanflxR5" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 5 in z unconvolved stack</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zFmeanflxR5Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zFmeanflxR5Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zFmeanflxR5Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zFmeanflxR6" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 6 in z unconvolved stack</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zFmeanflxR6Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in flxR6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zFmeanflxR6Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zFmeanflxR6Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zFlags" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>flags for z forced</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zLensObjSmearX11" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>per-object smear polarizability X11 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zLensObjSmearX12" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>per-object smear polarizability X12 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zLensObjSmearX22" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>per-object smear polarizability X22 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zLensObjSmearE1" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>per-object smear polarizability E1 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zLensObjSmearE2" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>per-object smear polarizability E2 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zLensObjShearX11" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>per-object shear polarizability X11 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zLensObjShearX12" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>per-object shear polarizability X12 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zLensObjShearX22" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>per-object shear polarizability X22 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zLensObjShearE1" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>per-object shear polarizability E1 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zLensObjShearE2" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>per-object shear polarizability E2 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zLensPSFSmearX11" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>psf model smear polarizability X11 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zLensPSFSmearX12" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>psf model smear polarizability X12 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zLensPSFSmearX22" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>psf model smear polarizability X22 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zLensPSFSmearE1" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>psf model smear polarizability E1 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zLensPSFSmearE2" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>psf model smear polarizability E2 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zLensPSFShearX11" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>psf model shear polarizability X11 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zLensPSFShearX12" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>psf model shear polarizability X12 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zLensPSFShearX22" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>psf model shear polarizability X22 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zLensPSFShearE1" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>psf model shear polarizability E1 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zLensPSFShearE2" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>psf model shear polarizability E2 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zGamma" arraysize="1" datatype="float" unit="arcsec^2" default="-999">
+	<DESCRIPTION>second moment (Mxx+Myy)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zE1" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>polarization, KSB-corrected (Mxx - Myy) / (Mxx + Myy)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zE2" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>polarization, KSB-corrected 2Mxy / (Mxx + Myy)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yStackID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+	<DESCRIPTION>stack image id (how to carry through IPP+DVO</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ynTotal" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+        <DESCRIPTION>number of detections in y filter</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ynIncPSFMag" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+        <DESCRIPTION>number of detections included in robust psf mean in y filter</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ynIncKronMag" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+        <DESCRIPTION>number of detections included in robust mean of Kron mag in y filter</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ynIncApMag" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+        <DESCRIPTION>number of detections included in robust mean of Ap Mag in y filter</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ynIncR5" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+        <DESCRIPTION>number of detections included in robust mean of ApFlx 5 in y filter</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ynIncR6" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+        <DESCRIPTION>number of detections included in robust mean of ApFlx 6 in y filter</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yPSFMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION> robust mean y psf AB magnitude (sigma clipping or MAP or go to 5 or 7 number summary? 1/12 is ~9th percentile</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yPSFMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION> estimated error of y psf AB magnitude mean(individual errors added in quadrature)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yPSFMagStd" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>standard deviation of measurements included in the robust mean</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yKronMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>mean y kron AB magnitude</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yKronMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION> estimated error of y kron AB magnitude mean</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yKronMagStd" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>standard deviation of measurements included in the robust mean</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yApMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>mean y aperture AB magnitude</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yApMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION> estimated error of y aperture AB magnitude mean</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yApMagStd" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>standard deviation of measurements included in the robust mean</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yFmeanflxR5" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 5 in y unconvolved stack</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yFmeanflxR5Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yFmeanflxR5Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yFmeanflxR5Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yFmeanflxR6" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 6 in y unconvolved stack</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yFmeanflxR6Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in flxR6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yFmeanflxR6Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yFmeanflxR6Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yFlags" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>flags for y forced</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yLensObjSmearX11" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>per-object smear polarizability X11 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yLensObjSmearX12" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>per-object smear polarizability X12 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yLensObjSmearX22" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>per-object smear polarizability X22 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yLensObjSmearE1" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>per-object smear polarizability E1 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yLensObjSmearE2" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>per-object smear polarizability E2 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yLensObjShearX11" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>per-object shear polarizability X11 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yLensObjShearX12" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>per-object shear polarizability X12 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yLensObjShearX22" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>per-object shear polarizability X22 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yLensObjShearE1" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>per-object shear polarizability E1 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yLensObjShearE2" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>per-object shear polarizability E2 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yLensPSFSmearX11" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>psf model smear polarizability X11 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yLensPSFSmearX12" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>psf model smear polarizability X12 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yLensPSFSmearX22" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>psf model smear polarizability X22 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yLensPSFSmearE1" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>psf model smear polarizability E1 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yLensPSFSmearE2" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+	<DESCRIPTION>psf model smear polarizability E2 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yLensPSFShearX11" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>psf model shear polarizability X11 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yLensPSFShearX12" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>psf model shear polarizability X12 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yLensPSFShearX22" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>psf model shear polarizability X22 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yLensPSFShearE1" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>psf model shear polarizability E1 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yLensPSFShearE2" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>psf model shear polarizability E2 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yGamma" arraysize="1" datatype="float" unit="arcsec^2" default="-999">
+	<DESCRIPTION>second moment (Mxx+Myy)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yE1" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>polarization, KSB-corrected (Mxx - Myy) / (Mxx + Myy)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yE2" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>polarization, KSB-corrected 2Mxy / (Mxx + Myy)</DESCRIPTION>
+      </FIELD>
+      <DATA>
+        <TABLEDATA></TABLEDATA>
+      </DATA>
+    </TABLE>
+  </RESOURCE>
+</VOTABLE>
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/config/tables.FW.vot
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/config/tables.FW.vot	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/config/tables.FW.vot	(revision 37066)
@@ -0,0 +1,355 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<VOTABLE version="1.1">
+  <RESOURCE>
+    <TABLE name="ForcedWarpMeta">
+      <DESCRIPTION>VOTable description of PSPS table ForcedWarpMeta</DESCRIPTION>
+      <PARAM arraysize="1" datatype="char" ucd="meta.bib.author" name="Author" value="PSPS"></PARAM>
+      <FIELD name="forcedWarpID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>forced warp identifier identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="batchID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+	<DESCRIPTION>batch identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="surveyID" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="NA">
+        <DESCRIPTION>survey flag identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="filterID" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="NA">
+        <DESCRIPTION>filter identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="skyCellID" arraysize="1" datatype="float" unit="dimensionless" default="NA">
+	<DESCRIPTION>single float giving PrimaryCell.SkyCell identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="photoCalID" arraysize="1" datatype="int" unit="dimensionless" default="NA">
+	<DESCRIPTION>photometry code</DESCRIPTION>
+      </FIELD>
+      <FIELD name="magSat" arraysize="1" datatype="float" unit="magnitude" default="-999">
+	<DESCRIPTION>saturation magnitude level</DESCRIPTION>
+      </FIELD>
+      <FIELD name="analVer" arraysize="100" datatype="char" unit="alphanumeric" default="-999">
+        <DESCRIPTION>IPP software analysis release</DESCRIPTION>
+      </FIELD>
+      <FIELD name="expTime" arraysize="1" datatype="float" unit="seconds" default="-999">
+	<DESCRIPTION>exposure time of positive image</DESCRIPTION>
+      </FIELD>
+      <FIELD name="completMag" arraysize="1" datatype="float" unit="magnitude" default="-999">
+	<DESCRIPTION>95% completion level in mag</DESCRIPTION>
+      </FIELD>
+      <FIELD name="astroScat" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>astrometric scatter for warp</DESCRIPTION>
+      </FIELD>
+      <FIELD name="photoScat" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>photometric scatter for warp</DESCRIPTION>
+      </FIELD>
+      <FIELD name="nAstroRef" arraysize="1" datatype="int" unit="dimensionless" default="-999">
+	<DESCRIPTION>number of astrometric reference sources</DESCRIPTION>
+      </FIELD>
+      <FIELD name="nPhoRef" arraysize="1" datatype="int" unit="dimensionless" default="-999">
+	<DESCRIPTION>number of photometric reference sources</DESCRIPTION>
+      </FIELD>
+      <FIELD name="psfModelID" arraysize="100" datatype="char" unit="dimensionless" default="8000">
+	<DESCRIPTION>PSF model identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="psfFwhm_mean" arraysize="1" datatype="double" unit="arcsec" default="-999">
+	<DESCRIPTION>mean PSF FWHM in the stack</DESCRIPTION>
+      </FIELD>
+      <FIELD name="psfFwhm_max" arraysize="1" datatype="double" unit="arcsec" default="-999">
+	<DESCRIPTION>maximum PSF FWHM in the stack</DESCRIPTION>
+      </FIELD>
+      <FIELD name="photoZero" arraysize="1" datatype="float" unit="magnitude" default="-999">
+	<DESCRIPTION>local derived photometric zero point</DESCRIPTION>
+      </FIELD>
+      <FIELD name="photoColor" arraysize="1" datatype="float" unit="magnitude" default="-999">
+	<DESCRIPTION>local derived photometric color term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ctype1" arraysize="100" datatype="char" unit="alphanumeric" default="8000">
+        <DESCRIPTION>name of astrometric projection in RA</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ctype2" arraysize="100" datatype="char" unit="alphanumeric" default="8000">
+        <DESCRIPTION>name of astrometric projection in DEC</DESCRIPTION>
+      </FIELD>
+      <FIELD name="crval1" arraysize="1" datatype="double" unit="degrees" default="-999">
+        <DESCRIPTION> RA corresponding to reference pixel</DESCRIPTION>
+      </FIELD>
+      <FIELD name="crval2" arraysize="1" datatype="double" unit="degrees" default="-999">
+        <DESCRIPTION> DEC corresponding to reference pixel</DESCRIPTION>
+      </FIELD>
+      <FIELD name="crpix1" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>reference pixel value for RA</DESCRIPTION>
+      </FIELD>
+      <FIELD name="crpix2" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>reference pixel value for DEC</DESCRIPTION>
+      </FIELD>
+      <FIELD name="cdelt1" arraysize="1" datatype="double" unit="degrees/pixel" default="-999">
+        <DESCRIPTION>scale factor for RA</DESCRIPTION>
+      </FIELD>
+      <FIELD name="cdelt2" arraysize="1" datatype="double" unit="degrees/pixel" default="-999">
+        <DESCRIPTION>scale factor for DEC</DESCRIPTION>
+      </FIELD>
+      <FIELD name="pc001001" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>elements of rotation/scale matrix</DESCRIPTION>
+      </FIELD>
+      <FIELD name="pc001002" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>elements of rotation/scale matrix</DESCRIPTION>
+      </FIELD>
+      <FIELD name="pc002001" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>elements of rotation/scale matrix</DESCRIPTION>
+      </FIELD>
+      <FIELD name="pc002002" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>elements of rotation/scale matrix</DESCRIPTION>
+      </FIELD>
+      <FIELD name="calibModNum" arraysize="1" datatype="short" unit="dimensionless" default="NA">
+        <DESCRIPTION>calibration modification number</DESCRIPTION>
+      </FIELD>
+      <FIELD name="dataRelease" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="NA">
+        <DESCRIPTION>Data release</DESCRIPTION>
+      </FIELD>
+      <DATA>
+        <TABLEDATA></TABLEDATA>
+      </DATA>
+    </TABLE>
+    <TABLE name="ForcedWarpMeasurement">
+      <DESCRIPTION>VOTable description of PSPS table ForcedWarpMeasurement</DESCRIPTION>
+      <PARAM arraysize="1" datatype="char" ucd="meta.bib.author" name="Author" value="PSPS"></PARAM>
+      <FIELD name="objID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>ODM object identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gcobjID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>galactic coordinates ODM object identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="detectID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>ODM  detection identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ippObjID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>object id generated by IPP</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ippDetectID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>detection id generated by IPP</DESCRIPTION>
+      </FIELD>
+      <FIELD name="filterID" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="NA">
+        <DESCRIPTION>filter ID: g=1, r=2, i=3, z=4, y=5, w=6, ...</DESCRIPTION>
+      </FIELD>
+      <FIELD name="surveyID" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="NA">
+        <DESCRIPTION>survey flag identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="forcedWarpID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+	<DESCRIPTION>forced warp measurement meta identifer</DESCRIPTION>
+      </FIELD>
+      <FIELD name="randomWarpID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION> random warp id</DESCRIPTION>
+      </FIELD>
+      <FIELD name="skyCellID" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>single float givijng PrimaryCell.SkyCell identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="dvoRegionID" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION> identifier to dvo spacial region</DESCRIPTION>
+      </FIELD>
+      <FIELD name="obsTime" arraysize="1" datatype="double" unit="MeanJulianDays" default="-999">
+        <DESCRIPTION> Time of mid observation of positive detection in Mean Julian Days</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zp" arraysize="1" datatype="float" unit="magnitude" default="0">
+	<DESCRIPTION>zeropoint (only thing needed to convert adu/sec to AB
+	mag), note no zpErr</DESCRIPTION>
+      </FIELD>
+      <FIELD name="telluricExt" arraysize="1" datatype="float" unit="magnitude" default="NA">
+	<DESCRIPTION>estimated extinction due to non-photometric conditions</DESCRIPTION>
+      </FIELD>
+      <FIELD name="expTime" arraysize="1" datatype="float" unit="seconds" default="-999">
+	<DESCRIPTION>exposure time (informational)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="airMass" arraysize="1" datatype="float" unit="dimensionless" default="0">
+	<DESCRIPTION>airmass (informational)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="psfFlux" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION> PSF instrumental flux (in analog-to-digital units/sec) or	adu/sec</DESCRIPTION>
+      </FIELD>
+      <FIELD name="psfFluxErr" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION> estimated error in flux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="psfMajorFWHM" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>model PSF width in major axis</DESCRIPTION>
+      </FIELD>
+      <FIELD name="psfMinorFWHM" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>model PSF width in minor axis</DESCRIPTION>
+      </FIELD>
+      <FIELD name="psfTheta" arraysize="1" datatype="float" unit="degrees" default="-999">
+        <DESCRIPTION>model PSF orientation angles degrees East of North</DESCRIPTION>
+      </FIELD>
+      <FIELD name="psfCore" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>model PSF core parameter [k in (1 + kz + z^1.66)]</DESCRIPTION>
+      </FIELD>
+      <FIELD name="psfQf" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>PSF coverage factor</DESCRIPTION>
+      </FIELD>
+      <FIELD name="psfQfPerfect" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>PSF-weighted fraction of pixels totally unmasked</DESCRIPTION>
+      </FIELD>
+      <FIELD name="psfChiSq" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>reduced-chisq of the psf model fit. (ndof?, npix?)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="psfLikelihood" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>PSF likelihood</DESCRIPTION>
+      </FIELD>
+      <FIELD name="momentXX" arraysize="1" datatype="float" unit="warp pixels" default="-999">
+        <DESCRIPTION> moment XX</DESCRIPTION>
+      </FIELD>
+      <FIELD name="momentXY" arraysize="1" datatype="float" unit="warp pixels" default="-999">
+        <DESCRIPTION> moment XY</DESCRIPTION>
+      </FIELD>
+      <FIELD name="momentYY" arraysize="1" datatype="float" unit="warp pixels" default="-999">
+        <DESCRIPTION> moment YY</DESCRIPTION>
+      </FIELD>
+      <FIELD name="momentR1" arraysize="1" datatype="float" unit="warp pixels" default="-999">
+        <DESCRIPTION> first radial moment</DESCRIPTION>
+      </FIELD>
+      <FIELD name="momentRH" arraysize="1" datatype="float" unit="warp pixels" default="-999">
+        <DESCRIPTION> half radial moment</DESCRIPTION>
+      </FIELD>
+      <FIELD name="momentM3C" arraysize="1" datatype="float" unit="warp pixels" default="-999">
+        <DESCRIPTION> 3rd moment cos(theta)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="momentM3S" arraysize="1" datatype="float" unit="warp pixels" default="-999">
+        <DESCRIPTION> 3rd moment sin(theta)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="momentM4C" arraysize="1" datatype="float" unit="warp pixels" default="-999">
+        <DESCRIPTION> 4th moment cos(theta)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="momentM4S" arraysize="1" datatype="float" unit="warp pixels" default="-999">
+        <DESCRIPTION> 4th moment sin(theta)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="lensObjSmearX11" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+        <DESCRIPTION>per-object smear polarizability X11 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="lensObjSmearX12" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+        <DESCRIPTION>per-object smear polarizability X12 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="lensObjSmearX22" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+        <DESCRIPTION>per-object smear polarizability X22 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="lensObjSmearE1" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+        <DESCRIPTION>per-object smear polarizability E1 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="lensObjSmearE2" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+        <DESCRIPTION>per-object smear polarizability E2 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="lensObjShearX11" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>per-object shear polarizability X11 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="lensObjShearX12" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>per-object shear polarizability X12 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="lensObjShearX22" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>per-object shear polarizability X22 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="lensObjShearE1" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>per-object shear polarizability E1 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="lensObjShearE2" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>per-object shear polarizability E2 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="lensPSFSmearX11" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+        <DESCRIPTION>psf model smear polarizability X11 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="lensPSFSmearX12" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+        <DESCRIPTION>psf model smear polarizability X12 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="lensPSFSmearX22" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+        <DESCRIPTION>psf model smear polarizability X22 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="lensPSFSmearE1" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+        <DESCRIPTION>psf model smear polarizability E1 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="lensPSFSmearE2" arraysize="1" datatype="float" unit="arcsec^-2" default="-999">
+        <DESCRIPTION>psf model smear polarizability E2 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="lensPSFShearX11" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>psf model shear polarizability X11 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="lensPSFShearX12" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>psf model shear polarizability X12 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="lensPSFShearX22" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>psf model shear polarizability X22 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="lensPSFShearE1" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>psf model shear polarizability E1 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="lensPSFShearE2" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>psf model shear polarizability E2 term</DESCRIPTION>
+      </FIELD>
+      <FIELD name="apFlux" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION> Aperture Flux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="apFluxErr" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION> Aperture Flux error</DESCRIPTION>
+      </FIELD>
+      <FIELD name="apFillF" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION> Aperture fill factor</DESCRIPTION>
+      </FIELD>
+      <FIELD name="kronFlux" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION> Kron flux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="kronFluxErr" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION> Kron flux error</DESCRIPTION>
+      </FIELD>
+      <FIELD name="kronRad" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION> Kron radius</DESCRIPTION>
+      </FIELD>
+      <FIELD name="kronRadErr" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION> Kron radius error</DESCRIPTION>
+      </FIELD>
+      <FIELD name="flxR5" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="flxR5Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="flxR5Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="flxR5Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="flxR6" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="flxR6Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in flxR6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="flxR6Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="flxR6Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="sky" arraysize="1" datatype="float" unit="adu/sec/pixel" default="-999">
+        <DESCRIPTION> PSF sky level at source</DESCRIPTION>
+      </FIELD>
+      <FIELD name="skyErr" arraysize="1" datatype="float" unit="adu/sec/pixel" default="-999">
+        <DESCRIPTION> estimated error in sky</DESCRIPTION>
+      </FIELD>
+       <FIELD name="infoFlag" arraysize="1" datatype="long" unit="dimensionless" default="-999">
+        <DESCRIPTION>flag indicating provenance information</DESCRIPTION>
+      </FIELD>
+      <FIELD name="dataRelease" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="NA">
+        <DESCRIPTION>Data release when this detection was originally taken. Recalibrations do not affect this value.</DESCRIPTION>
+      </FIELD>
+      <DATA>
+        <TABLEDATA></TABLEDATA>
+      </DATA>
+    </TABLE>
+    <TABLE name="ForcedWarpToImage">
+      <DESCRIPTION>VOTable description of PSPS table ForcedWarpToImage</DESCRIPTION>
+      <PARAM arraysize="1" datatype="char" ucd="meta.bib.author" name="Author" value="PSPS"></PARAM>
+      <FIELD name="forcedWarpID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>forced warp identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="imageID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>hashed exposure-ccdID identifier</DESCRIPTION>
+      </FIELD>
+      <DATA>
+        <TABLEDATA></TABLEDATA>
+      </DATA>
+    </TABLE>
+  </RESOURCE>
+</VOTABLE>
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/config/tables.IN.full.vot
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/config/tables.IN.full.vot	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/config/tables.IN.full.vot	(revision 37066)
@@ -49784,14 +49784,14 @@
       </FIELD>
       <FIELD name="pc001001" arraysize="1" datatype="double">
-        <DESCRIPTION>elements of rotation/Dcale matrix</DESCRIPTION>
+        <DESCRIPTION>elements of rotation/scale matrix</DESCRIPTION>
       </FIELD>
       <FIELD name="pc001002" arraysize="1" datatype="double">
-        <DESCRIPTION>elements of rotation/Dcale matrix</DESCRIPTION>
+        <DESCRIPTION>elements of rotation/scale matrix</DESCRIPTION>
       </FIELD>
       <FIELD name="pc002001" arraysize="1" datatype="double">
-        <DESCRIPTION>elements of rotation/Dcale matrix</DESCRIPTION>
+        <DESCRIPTION>elements of rotation/scale matrix</DESCRIPTION>
       </FIELD>
       <FIELD name="pc002002" arraysize="1" datatype="double">
-        <DESCRIPTION>elements of rotation/Dcale matrix</DESCRIPTION>
+        <DESCRIPTION>elements of rotation/scale matrix</DESCRIPTION>
       </FIELD>
       <DATA>
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/config/tables.OB.vot
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/config/tables.OB.vot	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/config/tables.OB.vot	(revision 37066)
@@ -3,303 +3,379 @@
 <VOTABLE version="1.1">
   <RESOURCE>
-    <TABLE name="Object">
-      <DESCRIPTION>VOTable description of PSPS table Object</DESCRIPTION>
+    <TABLE name="ObjectThin">
+      <DESCRIPTION>VOTable description of PSPS table ObjectThin</DESCRIPTION>
       <PARAM arraysize="1" datatype="char" ucd="meta.bib.author" name="Author" value="PSPS"></PARAM>
-      <FIELD name="objID" arraysize="1" datatype="long" unit="unknown">
+      <FIELD name="objName" arraysize="32" datatype="char" unit="dimensionless"  default="NA">
+        <DESCRIPTION>IAU Name constructed from objID postion PS1.x JHHMMSS.SS+/-DDMMSS.S where x is leading number of procesing version</DESCRIPTION>
+      </FIELD>
+      <FIELD name="objID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
         <DESCRIPTION>ODM object identifier index</DESCRIPTION>
       </FIELD>
-      <FIELD name="ippObjID" arraysize="1" datatype="long" unit="unknown">
+      <FIELD name="gcobjID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>galactic coordinates ODM object identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ippObjID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
         <DESCRIPTION>IPP object number</DESCRIPTION>
       </FIELD>
-      <FIELD name="projectionCellID" arraysize="1" datatype="int" unit="unknown">
-        <DESCRIPTION>projection cell identifier at discovery time</DESCRIPTION>
-      </FIELD>
-      <FIELD name="htmID" arraysize="1" datatype="long" unit="unknown">
+      <FIELD name="surveyID" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="255">
+        <DESCRIPTION>Survey ID</DESCRIPTION>
+      </FIELD>
+      <FIELD name="skyCellID" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>single float giving PrimaryCell.SkyCell identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="htmID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
         <DESCRIPTION>HTM index</DESCRIPTION>
       </FIELD>
-      <FIELD name="zoneID" arraysize="1" datatype="int" unit="unknown">
+      <FIELD name="zoneID" arraysize="1" datatype="int" unit="dimensionless" default="NA">
         <DESCRIPTION>Zone index</DESCRIPTION>
       </FIELD>
-      <FIELD name="stackVer" arraysize="1" datatype="short" unit="unknown">
-        <DESCRIPTION>static stack version number</DESCRIPTION>
-      </FIELD>
-      <FIELD name="objInfoFlag" arraysize="1" datatype="long" unit="unknown">
+      <FIELD name="randomID" arraysize="1" datatype="long" unit="dimensionless" default="0">
+	<DESCRIPTION>Random integer between 0 and 2^32 - 4,394,967,296</DESCRIPTION>
+      </FIELD>
+      <FIELD name="batchID" arraysize="1" datatype="long" unit="dimensionless" default="-999">
+        <DESCRIPTION>batch id</DESCRIPTION>
+      </FIELD>
+      <FIELD name="dvoRegionID" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>identifier of dvo spatial region -dvo cat id</DESCRIPTION>
+      </FIELD>
+      <FIELD name="dataRelease" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="NA">
+	<DESCRIPTION>Data release version of this table</DESCRIPTION>
+      </FIELD>
+      <FIELD name="objInfoFlag" arraysize="1" datatype="long" unit="dimensionless" default="-999">
         <DESCRIPTION>flag indicating odd properties</DESCRIPTION>
       </FIELD>
-      <FIELD name="qualityFlag" arraysize="1" datatype="unsignedByte" unit="unknown">
+      <FIELD name="qualityFlag" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="0">
         <DESCRIPTION>subset of objInfoFlag - flags related to goodness of object</DESCRIPTION>
       </FIELD>
-      <FIELD name="surveyID" arraysize="1" datatype="unsignedByte" unit="unknown">
-        <DESCRIPTION>Survey ID</DESCRIPTION>
-      </FIELD>
-      <FIELD name="ra" arraysize="1" datatype="double" unit="degree">
-        <DESCRIPTION> Right Ascension</DESCRIPTION>
-      </FIELD>
-      <FIELD name="dec" arraysize="1" datatype="double" unit="degree">
-        <DESCRIPTION> Declination</DESCRIPTION>
-      </FIELD>
-      <FIELD name="raErr" arraysize="1" datatype="float" unit="arcsec">
-        <DESCRIPTION> Right Ascension error</DESCRIPTION>
-      </FIELD>
-      <FIELD name="decErr" arraysize="1" datatype="float" unit="arcsec">
-        <DESCRIPTION> Declination error</DESCRIPTION>
-      </FIELD>
-      <FIELD name="cx" arraysize="1" datatype="double" unit="unknown"> 
-	<DESCRIPTION>Cartesian x</DESCRIPTION> 
+      <FIELD name="consistencyFlag" arraysize="1" datatype="short" unit="dimensionless" default="0">
+        <DESCRIPTION>Value computed from associated detections, it is originally given by IPP and should agree with the ODM validation</DESCRIPTION>
+      </FIELD>
+      <FIELD name="raStack" arraysize="1" datatype="double" unit="degrees" default="-999">
+        <DESCRIPTION>Right Ascension - best weighted RA across filters from stack WHENEVER an object is detected in the stack</DESCRIPTION>
+      </FIELD>
+      <FIELD name="decStack" arraysize="1" datatype="double" unit="degrees" default="-999">
+        <DESCRIPTION>Declination - best weighted DEC across filters from stack WHENEVER an object is detected in the stack</DESCRIPTION>
+      </FIELD>
+      <FIELD name="raStackErr" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>Error in stack Right Ascension, note will have a systematic floor, and is not necessarily the best ra,dec for all objects</DESCRIPTION>
+      </FIELD>
+      <FIELD name="decStackErr" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>Error in stack Declination, note will have a systematic floor, and is not necessarily the best ra,dec for all objects</DESCRIPTION>
+      </FIELD>
+      <FIELD name="raMean" arraysize="1" datatype="double" unit="degrees" default="-999">
+        <DESCRIPTION>Right Ascension from the Mean of RA from individual detections if it exists. This is for information only</DESCRIPTION>
+      </FIELD>
+      <FIELD name="decMean" arraysize="1" datatype="double" unit="degrees" default="-999">
+        <DESCRIPTION>Declination from the Mean of Dec from individual detections if it exists. This is for information only</DESCRIPTION>
+      </FIELD>
+      <FIELD name="raMeanErr" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>Combination of the measurement errors in the Right Ascension from the mean detections if they exist</DESCRIPTION>
+      </FIELD>
+      <FIELD name="decMeanErr" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>Combination of the measurement errors in the Declination measurements if they exist</DESCRIPTION>
+      </FIELD>
+      <FIELD name="raMeanStd" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>standard deviation of Right Ascension measuments in detections if they exist</DESCRIPTION>
+      </FIELD>
+      <FIELD name="decMeanStd" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>standard deviation of Declination measurements in detections if they exist</DESCRIPTION>
+      </FIELD>
+      <FIELD name="cx" arraysize="1" datatype="double" unit="dimensionless" default="NA"> 
+	<DESCRIPTION>Cartesian x from stack Ra, Dec WENEVER a stack detection exists, and Mean Ra, Dec (mean of one?) when it doesn't</DESCRIPTION> 
       </FIELD> 
-      <FIELD name="cy" arraysize="1" datatype="double" unit="unknown"> 
-        <DESCRIPTION>Cartesian y</DESCRIPTION> 
+      <FIELD name="cy" arraysize="1" datatype="double" unit="dimensionless" default="NA"> 
+        <DESCRIPTION>Cartesian y from stack Ra, Dec WENEVER a stack detection exists, and Mean Ra, Dec (mean of one?) when it doesn't</DESCRIPTION> 
       </FIELD> 
-      <FIELD name="cz" arraysize="1" datatype="double" unit="unknown"> 
-        <DESCRIPTION>Cartesian z</DESCRIPTION> 
+      <FIELD name="cz" arraysize="1" datatype="double" unit="dimensionless" default="NA"> 
+        <DESCRIPTION>Cartesian z from stack Ra, Dec WENEVER a stack detection exists, and Mean Ra, Dec (mean of one?) when it doesn't</DESCRIPTION> 
       </FIELD> 
-      <FIELD name="lambda" arraysize="1" datatype="double" unit="degree">
-        <DESCRIPTION> ecliptic longitude</DESCRIPTION>
-      </FIELD>
-      <FIELD name="beta" arraysize="1" datatype="double" unit="degree">
-        <DESCRIPTION> ecliptic latitude</DESCRIPTION>
-      </FIELD>
-      <FIELD name="l" arraysize="1" datatype="double" unit="degree">
-        <DESCRIPTION> galactic longitude</DESCRIPTION>
-      </FIELD>
-      <FIELD name="b" arraysize="1" datatype="double" unit="degree">
-        <DESCRIPTION> galactic latitude</DESCRIPTION>
-      </FIELD>
-      <FIELD name="nDetections" arraysize="1" datatype="short" unit="unknown">
+      <FIELD name="lambda" arraysize="1" datatype="double" unit="degrees" default="-999">
+        <DESCRIPTION> ecliptic longitude from stack Ra, Dec WENEVER a stack detection exists, and Mean Ra, Dec (mean of one?) when it doesn't</DESCRIPTION>
+      </FIELD>
+      <FIELD name="beta" arraysize="1" datatype="double" unit="degrees" default="-999">
+        <DESCRIPTION> ecliptic latitude from stack Ra, Dec WENEVER a stack detection exists, and Mean Ra, Dec (mean of one?) when it doesn't</DESCRIPTION>
+      </FIELD>
+      <FIELD name="l" arraysize="1" datatype="double" unit="degrees" default="-999">
+        <DESCRIPTION> galactic longitude from stack Ra, Dec WENEVER a stack detection exists, and Mean Ra, Dec (mean of one?) when it doesn't</DESCRIPTION>
+      </FIELD>
+      <FIELD name="b" arraysize="1" datatype="double" unit="degrees" default="-999">
+        <DESCRIPTION> galactic latitude from stack Ra, Dec WENEVER a stack detection exists, and Mean Ra, Dec (mean of one?) when it doesn't</DESCRIPTION>
+      </FIELD>
+      <FIELD name="nStackObjectRows" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+        <DESCRIPTION>number of independent StackObjectRows this object has. 0 if not detected in the stack, 1 if there is a primary, 2 or more if it is in an overlap region</DESCRIPTION>
+      </FIELD>
+      <FIELD name="nStackDetections" arraysize="1" datatype="short" unit="dimensionless" default="255">
+        <DESCRIPTION>which filter bands it is detected in (not forced) or if it was masked in a band.</DESCRIPTION>
+      </FIELD>
+      <FIELD name="nDetections" arraysize="1" datatype="short" unit="dimensionless" default="-999">
         <DESCRIPTION>total number of detection measurements in all filters</DESCRIPTION>
       </FIELD>
-      <FIELD name="ng" arraysize="1" datatype="short" unit="unknown">
+      <FIELD name="ng" arraysize="1" datatype="short" unit="dimensionless" default="-999">
         <DESCRIPTION>number of measures in g filter</DESCRIPTION>
       </FIELD>
-      <FIELD name="gMeanPSFMag" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> mean g psf magnitude</DESCRIPTION>
-      </FIELD>
-      <FIELD name="gMeanPSFMagErr" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> estimated error of g psf magnitude mean</DESCRIPTION>
-      </FIELD>
-      <FIELD name="gMeanKronMag" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> mean g kron mag</DESCRIPTION>
-      </FIELD>
-      <FIELD name="gMeanKronMagErr" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> estimated error of g kron mean mag</DESCRIPTION>
-      </FIELD>
-      <FIELD name="g20pct" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> 20 pct g magnitude</DESCRIPTION>
-      </FIELD>
-      <FIELD name="g80pct" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> 80 pct g magnitude</DESCRIPTION>
-      </FIELD>
-      <FIELD name="nr" arraysize="1" datatype="short" unit="unknown">
+      <FIELD name="nr" arraysize="1" datatype="short" unit="dimensionless" default="-999">
         <DESCRIPTION>number of measures in r filter</DESCRIPTION>
       </FIELD>
-      <FIELD name="rMeanPSFMag" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> mean r psf magnitude</DESCRIPTION>
-      </FIELD>
-      <FIELD name="rMeanPSFMagErr" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> estimated error of r psf magnitude mean</DESCRIPTION>
-      </FIELD>
-      <FIELD name="rMeanKronMag" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> mean r kron mag</DESCRIPTION>
-      </FIELD>
-      <FIELD name="rMeanKronMagErr" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> estimated error of r mean kron mag</DESCRIPTION>
-      </FIELD>
-      <FIELD name="r20pct" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> 20 pct r magnitude</DESCRIPTION>
-      </FIELD>
-      <FIELD name="r80pct" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> 80 pct r magnitude</DESCRIPTION>
-      </FIELD>
-      <FIELD name="ni" arraysize="1" datatype="short" unit="unknown">
+      <FIELD name="ni" arraysize="1" datatype="short" unit="dimensionless" default="-999">
         <DESCRIPTION>number of measures in i filter</DESCRIPTION>
       </FIELD>
-      <FIELD name="iMeanPSFMag" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> mean psf i magnitude</DESCRIPTION>
-      </FIELD>
-      <FIELD name="iMeanPSFMagErr" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> estimated error of i psf magitude mean</DESCRIPTION>
-      </FIELD>
-      <FIELD name="iMeanKronMag" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> mean i kron mag</DESCRIPTION>
-      </FIELD>
-      <FIELD name="iMeanKronMagErr" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> estimated error of i kron mag mean</DESCRIPTION>
-      </FIELD>
-      <FIELD name="i20pct" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> 20 pct i magniutde</DESCRIPTION>
-      </FIELD>
-      <FIELD name="i80pct" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> 80 pct i magnitude</DESCRIPTION>
-      </FIELD>
-      <FIELD name="nz" arraysize="1" datatype="short" unit="mag">
-        <DESCRIPTION> number of measures in z filter</DESCRIPTION>
-      </FIELD>
-      <FIELD name="zMeanPSFMag" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> mean z psf magnitude</DESCRIPTION>
-      </FIELD>
-      <FIELD name="zMeanPSFMagErr" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> estimated error of z psf magnitude mean</DESCRIPTION>
-      </FIELD>
-      <FIELD name="zMeanKronMag" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> mean z kron mag</DESCRIPTION>
-      </FIELD>
-      <FIELD name="zMeanKronMagErr" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> estimated error of z mean kron mag</DESCRIPTION>
-      </FIELD>
-      <FIELD name="z20pct" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> 20 pct z magnitude</DESCRIPTION>
-      </FIELD>
-      <FIELD name="z80pct" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> 80 pct z magnitude</DESCRIPTION>
-      </FIELD>
-      <FIELD name="ny" arraysize="1" datatype="short" unit="unknown">
+      <FIELD name="nz" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+        <DESCRIPTION>number of measures in z filter</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ny" arraysize="1" datatype="short" unit="dimensionless" default="-999">
         <DESCRIPTION>number of measures in y filter</DESCRIPTION>
       </FIELD>
-      <FIELD name="yMeanPSFMag" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> mean y psf magnitude</DESCRIPTION>
-      </FIELD>
-     <FIELD name="yMeanPSFMagErr" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> estimated error of y psf magnitude mean</DESCRIPTION>
-      </FIELD>
-      <FIELD name="yMeanKronMag" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> mean y kron mag</DESCRIPTION>
-      </FIELD>
-       <FIELD name="yMeanKronMagErr" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> estimated error of y kron mag mean</DESCRIPTION>
-      </FIELD>
-      <FIELD name="y20pct" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> 20 pct y magnitude</DESCRIPTION>
-      </FIELD>
-      <FIELD name="y80pct" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> 80 pct y magnitude</DESCRIPTION>
-      </FIELD>
-      <FIELD name="nw" arraysize="1" datatype="short" unit="unknown">
-        <DESCRIPTION>number of measures in the wide (w) solar system filter</DESCRIPTION>
-      </FIELD>
-      <FIELD name="wMeanPSFMag" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> mean w psf magnitude</DESCRIPTION>
-      </FIELD>
-      <FIELD name="wMeanPSFMagErr" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> estimated error of w psf magnitude mean</DESCRIPTION>
-      </FIELD>
-      <FIELD name="wMeanKronMag" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> mean w kron mag</DESCRIPTION>
-      </FIELD>
-      <FIELD name="wMeanKronMagErr" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> estimated error of w kron mag mean</DESCRIPTION>
-      </FIELD>
-      <FIELD name="w20pct" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> 20 pct w magnitude</DESCRIPTION>
-      </FIELD>
-      <FIELD name="w80pct" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> 80 pct w magnitude</DESCRIPTION>
-      </FIELD>
-      <FIELD name="gStackPSFMag" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> g stack psf flux </DESCRIPTION>
-      </FIELD>
-      <FIELD name="gStackPSFMagErr" arraysize="1" datatype="double" unit="mag">
-	<DESCRIPTION> estimated error in g stack psf flux</DESCRIPTION>
-      </FIELD>
-      <FIELD name="gStackKronMag" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> g kron magnitude from stack frames</DESCRIPTION>
-      </FIELD>
-      <FIELD name="gStackKronMagErr" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> error from g stack kron mag</DESCRIPTION>
-      </FIELD>
-      <FIELD name="gFlags" arraysize="1" datatype="short" unit="unknown">
-        <DESCRIPTION>flags for g stack</DESCRIPTION>
-      </FIELD>
-      <FIELD name="gStackDetectID" arraysize="1" datatype="long" unit="unknown">
-        <DESCRIPTION>ODM detection identifier</DESCRIPTION>
-      </FIELD>
-      <FIELD name="rStackPSFMag" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> r stack psf flux </DESCRIPTION>
-      </FIELD>
-      <FIELD name="rStackPSFMagErr" arraysize="1" datatype="double" unit="mag">
-        <DESCRIPTION> estimated error in r stack psf flux</DESCRIPTION>
-      </FIELD>
-      <FIELD name="rStackKronMag" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> r kron magnitude from stack frames</DESCRIPTION>
-      </FIELD>
-      <FIELD name="rStackKronMagErr" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> error from r stack kron mag</DESCRIPTION>
-      </FIELD>
-      <FIELD name="rFlags" arraysize="1" datatype="short" unit="unknown">
-        <DESCRIPTION>flags for r stack</DESCRIPTION>
-      </FIELD>
-      <FIELD name="rStackDetectID" arraysize="1" datatype="long" unit="unknown">
-        <DESCRIPTION>ODM detection identifier</DESCRIPTION>
-      </FIELD>
-      <FIELD name="iStackPSFMag" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> i stack psf flux </DESCRIPTION>
-      </FIELD>
-      <FIELD name="iStackPSFMagErr" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> estimated error in i stack psf flux</DESCRIPTION>
-      </FIELD>
-      <FIELD name="iStackKronMag" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> i kron magnitude from stack frames</DESCRIPTION>
-      </FIELD>
-      <FIELD name="iStackKronMagErr" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> error from i stack kron mag</DESCRIPTION>
-      </FIELD>
-      <FIELD name="iFlags" arraysize="1" datatype="short" unit="unknown">
-        <DESCRIPTION>flags for i stack</DESCRIPTION>
-      </FIELD>
-      <FIELD name="iStackDetectID" arraysize="1" datatype="long" unit="unknown">
-        <DESCRIPTION>ODM detection identifier</DESCRIPTION>
-      </FIELD>
-      <FIELD name="zStackPSFMag" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> z stack psf flux </DESCRIPTION>
-      </FIELD>
-      <FIELD name="zStackPSFMagErr" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> estimated error in z stack psf flux</DESCRIPTION>
-      </FIELD>
-      <FIELD name="zStackKronMag" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> z kron magnitude from stack frames</DESCRIPTION>
-      </FIELD>
-      <FIELD name="zStackKronMagErr" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> error from z stack kron mag</DESCRIPTION>
-      </FIELD>
-      <FIELD name="zFlags" arraysize="1" datatype="short" unit="unknown">
-        <DESCRIPTION>flags for z stack</DESCRIPTION>
-      </FIELD>
-      <FIELD name="zStackDetectID" arraysize="1" datatype="long" unit="unknown">
-        <DESCRIPTION>ODM detection identifier</DESCRIPTION>
-      </FIELD>
-      <FIELD name="yStackPSFMag" arraysize="1" datatype="float" unit="unknown">
-        <DESCRIPTION>y band stack PSF flux</DESCRIPTION>
-      </FIELD>
-      <FIELD name="yStackPSFMagErr" arraysize="1" datatype="float" unit="unknown">
-        <DESCRIPTION>y band stack psf flux err</DESCRIPTION>
-      </FIELD>
-      <FIELD name="yStackKronMag" arraysize="1" datatype="float" unit="mag">
-        <DESCRIPTION> y kron magnitude from stack frames</DESCRIPTION>
-      </FIELD>
-      <FIELD name="yStackKronMagErr" arraysize="1" datatype="float" unit="unknown">
-        <DESCRIPTION>y band stack kron mag err</DESCRIPTION>
-      </FIELD>
-      <FIELD name="yFlags" arraysize="1" datatype="short" unit="unknown">
-        <DESCRIPTION>flags for y stack</DESCRIPTION>
-      </FIELD>
-      <FIELD name="yStackDetectID" arraysize="1" datatype="long" unit="unknown">
-        <DESCRIPTION>ODM detection identifier</DESCRIPTION>
-      </FIELD>
-      <FIELD name="qfPerfect" arraysize="1" datatype="float" unit="unknown">
-        <DESCRIPTION>qf perfect</DESCRIPTION>
-      </FIELD>
-      <FIELD name="sgSep" arraysize="1" datatype="float" unit="unknown">
-        <DESCRIPTION>star/galaxy separator - true if any one color is</DESCRIPTION>
-      </FIELD>
-      <FIELD name="consistencyFlag" arraysize="1" datatype="short" unit="unknown">
-        <DESCRIPTION>Value computed from associated detections, it is originally given by IPP and should agree with the ODM validation</DESCRIPTION>
-      </FIELD>
-      <FIELD name="Random" arraysize="1" datatype="double" unit="unknown">
-        <DESCRIPTION>Random number between 0 and 1</DESCRIPTION>
-      </FIELD>
-      <FIELD name="dataRelease" arraysize="1" datatype="unsignedByte" unit="unknown">
-        <DESCRIPTION>Data release</DESCRIPTION>
-      </FIELD>
-      <FIELD name="batchID" arraysize="1" datatype="int" unit="unknown">
-        <DESCRIPTION>batch id</DESCRIPTION>
+      <DATA>
+        <TABLEDATA></TABLEDATA>
+      </DATA>
+    </TABLE>
+    <TABLE name="MeanObject">
+      <DESCRIPTION>VOTable description of PSPS table MeanObject</DESCRIPTION>
+      <PARAM arraysize="1" datatype="char" ucd="meta.bib.author" name="Author" value="PSPS"></PARAM>
+      <FIELD name="objID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>ODM object identifier index</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gcobjID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>galactic coordinates ODM object identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gQfPerfect" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>maximum psf QfPerfect from best available g band detections</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gMeanPSFMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>mean g psf AB magnitude from best available measurements (best available as currently defined by ipp "waterfall logic"</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gMeanPSFMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>estimated error of best available g-band psf AB magnitudes</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gnIncPSFMag" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+	<DESCRIPTION>number of best available detections included in mean psfMag</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gMeanPSFMagStd" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>standard deviation of best available measurements - compared with MeanErr this is one measure of true variability</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gMinPSFMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>minimum best available PSFMag - min and max are given for PSFMag as they may indicate variability</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gMaxPSFMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>maxiumum best available PSFMag</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gMeanKronMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>mean g kron AB magnitude from best available measurements</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gMeanKronMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>estimated error of mean g kron AB magnitude</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gnIncKronMag" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+	<DESCRIPTION>number of best available detections included in mean Kron Mag</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gMeanKronMagStd" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>standard deviation of best available measurements</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gMeanApMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>mean g aperture AB magnitude from best available measurements</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gMeanApMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>estimated error of mean g aperture AB magnitude</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gnIncApMag" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+	<DESCRIPTION>number of best available detections included in mean Ap Mag</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gMeanApMagStd" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>standard deviation of best available measurements</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gFlags" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>flags for g mean</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rQfPerfect" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>maximum psf QfPerfect from best available r band detections</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rMeanPSFMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>mean r psf AB magnitude from best available measurements (best available as currently defined by ipp "waterfall logic"</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rMeanPSFMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>estimated error of best available r-band psf AB magnitudes</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rnIncPSFMag" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+	<DESCRIPTION>number of best available detections included in mean psfMag</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rMeanPSFMagStd" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>standard deviation of best available measurements - compared with MeanErr this is one measure of true variability</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rMinPSFMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>minimum best available PSFMag - min and max are given for PSFMag as they may indicate variability</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rMaxPSFMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>maxiumum best available PSFMag</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rMeanKronMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>mean r kron AB magnitude from best available measurements</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rMeanKronMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>estimated error of mean r kron AB magnitude</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rnIncKronMag" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+	<DESCRIPTION>number of best available detections included in mean Kron Mag</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rMeanKronMagStd" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>standard deviation of best available measurements</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rMeanApMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>mean r aperture AB magnitude from best available measurements</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rMeanApMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>estimated error of mean r aperture AB magnitude</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rnIncApMag" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+	<DESCRIPTION>number of best available detections included in mean Ap Mag</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rMeanApMagStd" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>standard deviation of best available measurements</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rFlags" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>flags for r mean</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iQfPerfect" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>maximum psf QfPerfect from best available i band detections</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iMeanPSFMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>mean i psf AB magnitude from best available measurements (best available as currently defined by ipp "waterfall logic"</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iMeanPSFMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>estimated error of best available i-band psf AB magnitudes</DESCRIPTION>
+      </FIELD>
+      <FIELD name="inIncPSFMag" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+	<DESCRIPTION>number of best available detections included in mean psfMag</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iMeanPSFMagStd" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>standard deviation of best available measurements - compared with MeanErr this is one measure of true variability</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iMinPSFMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>minimum best available PSFMag - min and max are given for PSFMag as they may indicate variability</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iMaxPSFMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>maxiumum best available PSFMag</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iMeanKronMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>mean i kron AB magnitude from best available measurements</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iMeanKronMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>estimated error of mean i kron AB magnitude</DESCRIPTION>
+      </FIELD>
+      <FIELD name="inIncKronMag" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+	<DESCRIPTION>number of best available detections included in mean Kron Mag</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iMeanKronMagStd" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>standard deviation of best available measurements</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iMeanApMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>mean i aperture AB magnitude from best available measurements</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iMeanApMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>estimated error of mean i aperture AB magnitude</DESCRIPTION>
+      </FIELD>
+      <FIELD name="inIncApMag" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+	<DESCRIPTION>number of best available detections included in mean Ap Mag</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iMeanApMagStd" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>standard deviation of best available measurements</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iFlags" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>flags for i mean</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zQfPerfect" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>maximum psf QfPerfect from best available z band detections</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zMeanPSFMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>mean z psf AB magnitude from best available measurements (best available as currently defined by ipp "waterfall logic"</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zMeanPSFMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>estimated error of best available z-band psf AB magnitudes</DESCRIPTION>
+      </FIELD>
+      <FIELD name="znIncPSFMag" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+	<DESCRIPTION>number of best available detections included in mean psfMag</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zMeanPSFMagStd" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>standard deviation of best available measurements - compared with MeanErr this is one measure of true variability</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zMinPSFMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>minimum best available PSFMag - min and max are given for PSFMag as they may indicate variability</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zMaxPSFMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>maxiumum best available PSFMag</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zMeanKronMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>mean z kron AB magnitude from best available measurements</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zMeanKronMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>estimated error of mean z kron AB magnitude</DESCRIPTION>
+      </FIELD>
+      <FIELD name="znIncKronMag" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+	<DESCRIPTION>number of best available detections included in mean Kron Mag</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zMeanKronMagStd" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>standard deviation of best available measurements</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zMeanApMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>mean z aperture AB magnitude from best available measurements</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zMeanApMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>estimated error of mean z aperture AB magnitude</DESCRIPTION>
+      </FIELD>
+      <FIELD name="znIncApMag" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+	<DESCRIPTION>number of best available detections included in mean Ap Mag</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zMeanApMagStd" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>standard deviation of best available measurements</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zFlags" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>flags for z mean</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yQfPerfect" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>maximum psf QfPerfect from best available y band detections</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yMeanPSFMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>mean y psf AB magnitude from best available measurements (best available as currently defined by ipp "waterfall logic"</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yMeanPSFMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>estimated error of best available y-band psf AB magnitudes</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ynIncPSFMag" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+	<DESCRIPTION>number of best available detections included in mean psfMag</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yMeanPSFMagStd" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>standard deviation of best available measurements - compared with MeanErr this is one measure of true variability</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yMinPSFMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>minimum best available PSFMag - min and max are given for PSFMag as they may indicate variability</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yMaxPSFMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>maxiumum best available PSFMag</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yMeanKronMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>mean y kron AB magnitude from best available measurements</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yMeanKronMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>estimated error of mean y kron AB magnitude</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ynIncKronMag" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+	<DESCRIPTION>number of best available detections included in mean Kron Mag</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yMeanKronMagStd" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>standard deviation of best available measurements</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yMeanApMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>mean y aperture AB magnitude from best available measurements</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yMeanApMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>estimated error of mean y aperture AB magnitude</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ynIncApMag" arraysize="1" datatype="short" unit="dimensionless" default="-999">
+	<DESCRIPTION>number of best available detections included in mean Ap Mag</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yMeanApMagStd" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>standard deviation of best available measurements</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yFlags" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>flags for y mean</DESCRIPTION>
       </FIELD>
       <DATA>
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/config/tables.P2.vot
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/config/tables.P2.vot	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/config/tables.P2.vot	(revision 37066)
@@ -6,149 +6,149 @@
       <DESCRIPTION>VOTable description of PSPS table FrameMeta</DESCRIPTION>
       <PARAM arraysize="1" datatype="char" ucd="meta.bib.author" name="Author" value="PSPS"></PARAM>
-      <FIELD name="frameID" arraysize="1" datatype="int" unit="unknown">
+      <FIELD name="frameID" arraysize="1" datatype="int" unit="dimensionless" default="NA">
         <DESCRIPTION>unique exposure/frame identifier.</DESCRIPTION>
       </FIELD>
-      <FIELD name="frameName" arraysize="100" datatype="char" unit="unknown">
+      <FIELD name="frameName" arraysize="32" datatype="char" unit="dimensionless" default="NA">
         <DESCRIPTION>frame name provided by camera software</DESCRIPTION>
       </FIELD>
-      <FIELD name="surveyID" arraysize="1" datatype="unsignedByte" unit="unknown">
+      <FIELD name="surveyID" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="NA">
         <DESCRIPTION>survey flag identifier</DESCRIPTION>
       </FIELD>
-      <FIELD name="filterID" arraysize="1" datatype="unsignedByte" unit="unknown">
+      <FIELD name="filterID" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="NA">
         <DESCRIPTION>filter identifier</DESCRIPTION>
       </FIELD>
-      <FIELD name="cameraID" arraysize="1" datatype="short" unit="unknown">
+      <FIELD name="cameraID" arraysize="1" datatype="short" unit="dimensionless" default="NA">                          
         <DESCRIPTION>camera identifier</DESCRIPTION>
       </FIELD>
-      <FIELD name="cameraConfigID" arraysize="1" datatype="short" unit="unknown">
+      <FIELD name="cameraConfigID" arraysize="1" datatype="short" unit="dimensionless" default="NA">
         <DESCRIPTION>camera configuration identifier</DESCRIPTION>
       </FIELD>
-      <FIELD name="telescopeID" arraysize="1" datatype="short" unit="unknown">
+      <FIELD name="telescopeID" arraysize="1" datatype="short" unit="dimensionless" default="NA">
         <DESCRIPTION>telescope identifier</DESCRIPTION>
       </FIELD>
-      <FIELD name="analysisVer" arraysize="100" datatype="char" unit="unknown">
+      <FIELD name="analysisVer" arraysize="100" datatype="char" unit="alphanumeric" default="8000">
         <DESCRIPTION>IPP software analysis release</DESCRIPTION>
       </FIELD>
-      <FIELD name="p1Recip" arraysize="100" datatype="char" unit="unknown">
+      <FIELD name="p1Recip" arraysize="100" datatype="char" unit="alphanumeric" default="8000">
         <DESCRIPTION>IPP phase 1 MD5 Checksum</DESCRIPTION>
       </FIELD>
-      <FIELD name="p2Recip" arraysize="100" datatype="char" unit="unknown">
+      <FIELD name="p2Recip" arraysize="100" datatype="char" unit="alphanumeric" default="8000">
         <DESCRIPTION>IPP phase 2 MD5 Checksum</DESCRIPTION>
       </FIELD>
-      <FIELD name="p3Recip" arraysize="100" datatype="char" unit="unknown">
+      <FIELD name="p3Recip" arraysize="100" datatype="char" unit="alphanumeric" default="8000">
         <DESCRIPTION>IPP phase 3 MD5 Checksum</DESCRIPTION>
       </FIELD>
-      <FIELD name="nOTA" arraysize="1" datatype="short" unit="unknown">
+      <FIELD name="nOTA" arraysize="1" datatype="short" unit="alphanumeric" default="-999">
         <DESCRIPTION>number of valid OTA/CCD images in this exposure</DESCRIPTION>
       </FIELD>
-      <FIELD name="photoScat" arraysize="1" datatype="float" unit="mag">
+      <FIELD name="photoScat" arraysize="1" datatype="float" unit="magnitude" default="-999">
         <DESCRIPTION> global photometric scatter</DESCRIPTION>
       </FIELD>
-      <FIELD name="numPhotoRef" arraysize="1" datatype="int" unit="unknown">
+      <FIELD name="numPhotoRef" arraysize="1" datatype="int" unit="dimensionless" default="-999">
         <DESCRIPTION>number of photometric reference sources</DESCRIPTION>
       </FIELD>
-      <FIELD name="expStart" arraysize="1" datatype="double" unit="day">
+      <FIELD name="expStart" arraysize="1" datatype="double" unit="days" default="-999">
         <DESCRIPTION> exposure start time in MJD</DESCRIPTION>
       </FIELD>
-      <FIELD name="expTime" arraysize="1" datatype="float" unit="s">
+      <FIELD name="expTime" arraysize="1" datatype="float" unit="seconds" default="-999">
         <DESCRIPTION> exposure time</DESCRIPTION>
       </FIELD>
-      <FIELD name="airmass" arraysize="1" datatype="float" unit="unknown">
+      <FIELD name="airmass" arraysize="1" datatype="float" unit="dimensionless" default="-999">
         <DESCRIPTION>airmass at mid-exposure</DESCRIPTION>
       </FIELD>
-      <FIELD name="raBore" arraysize="1" datatype="double" unit="deg">
+      <FIELD name="raBore" arraysize="1" datatype="double" unit="degrees" default="-999">
         <DESCRIPTION> RA of telescope boresight</DESCRIPTION>
       </FIELD>
-      <FIELD name="decBore" arraysize="1" datatype="double" unit="deg">
+      <FIELD name="decBore" arraysize="1" datatype="double" unit="degrees" default="-999">
         <DESCRIPTION> DEC of telescope boresight</DESCRIPTION>
       </FIELD>
-      <FIELD name="ctype1" arraysize="100" datatype="char" unit="unknown">
+      <FIELD name="ctype1" arraysize="100" datatype="char" unit="alphanumeric" default="8000">
         <DESCRIPTION>name of astrometric projection in RA</DESCRIPTION>
       </FIELD>
-      <FIELD name="ctype2" arraysize="100" datatype="char" unit="unknown">
+      <FIELD name="ctype2" arraysize="100" datatype="char" unit="alphanumeric" default="8000">
         <DESCRIPTION>name of astrometric projection in DEC</DESCRIPTION>
       </FIELD>
-      <FIELD name="crval1" arraysize="1" datatype="double" unit="deg">
+      <FIELD name="crval1" arraysize="1" datatype="double" unit="degrees" default="-999">
         <DESCRIPTION> RA corresponding to reference pixel</DESCRIPTION>
       </FIELD>
-      <FIELD name="crval2" arraysize="1" datatype="double" unit="deg">
+      <FIELD name="crval2" arraysize="1" datatype="double" unit="degrees" default="-999">
         <DESCRIPTION> DEC corresponding to reference pixel</DESCRIPTION>
       </FIELD>
-      <FIELD name="crpix1" arraysize="1" datatype="double" unit="unknown">
+      <FIELD name="crpix1" arraysize="1" datatype="double" unit="dimensionless" default="-999">
         <DESCRIPTION>reference pixel value for RA</DESCRIPTION>
       </FIELD>
-      <FIELD name="crpix2" arraysize="1" datatype="double" unit="unknown">
+      <FIELD name="crpix2" arraysize="1" datatype="double" unit="dimensionless" default="-999">
         <DESCRIPTION>reference pixel value for DEC</DESCRIPTION>
       </FIELD>
-      <FIELD name="cdelt1" arraysize="1" datatype="double" unit="unknown">
+      <FIELD name="cdelt1" arraysize="1" datatype="double" unit="degrees/pixel" default="-999">
         <DESCRIPTION>scale factor for RA</DESCRIPTION>
       </FIELD>
-      <FIELD name="cdelt2" arraysize="1" datatype="double" unit="unknown">
+      <FIELD name="cdelt2" arraysize="1" datatype="double" unit="degrees/pixel" default="-999">
         <DESCRIPTION>scale factor for DEC</DESCRIPTION>
       </FIELD>
-      <FIELD name="pc001001" arraysize="1" datatype="double" unit="unknown">
-        <DESCRIPTION>elements of rotation/Dcale matrix</DESCRIPTION>
-      </FIELD>
-      <FIELD name="pc001002" arraysize="1" datatype="double" unit="unknown">
-        <DESCRIPTION>elements of rotation/Dcale matrix</DESCRIPTION>
-      </FIELD>
-      <FIELD name="pc002001" arraysize="1" datatype="double" unit="unknown">
-        <DESCRIPTION>elements of rotation/Dcale matrix</DESCRIPTION>
-      </FIELD>
-      <FIELD name="pc002002" arraysize="1" datatype="double" unit="unknown">
-        <DESCRIPTION>elements of rotation/Dcale matrix</DESCRIPTION>
-      </FIELD>
-      <FIELD name="polyOrder" arraysize="1" datatype="unsignedByte" unit="unknown">
+      <FIELD name="pc001001" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>elements of rotation/scale matrix</DESCRIPTION>
+      </FIELD>
+      <FIELD name="pc001002" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>elements of rotation/scale matrix</DESCRIPTION>
+      </FIELD>
+      <FIELD name="pc002001" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>elements of rotation/scale matrix</DESCRIPTION>
+      </FIELD>
+      <FIELD name="pc002002" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>elements of rotation/scale matrix</DESCRIPTION>
+      </FIELD>
+      <FIELD name="polyOrder" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="255">
         <DESCRIPTION>polynomial order of astrometry fit</DESCRIPTION>
       </FIELD>
-      <FIELD name="pca1x3y0" arraysize="1" datatype="double" unit="unknown">
-        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="pca1x2y1" arraysize="1" datatype="double" unit="unknown">
-        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="pca1x1y2" arraysize="1" datatype="double" unit="unknown">
-        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="pca1x0y3" arraysize="1" datatype="double" unit="unknown">
-        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="pca1x2y0" arraysize="1" datatype="double" unit="unknown">
-        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="pca1x1y1" arraysize="1" datatype="double" unit="unknown">
-        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="pca1x0y2" arraysize="1" datatype="double" unit="unknown">
-        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="pca2x3y0" arraysize="1" datatype="double" unit="unknown">
-        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="pca2x2y1" arraysize="1" datatype="double" unit="unknown">
-        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="pca2x1y2" arraysize="1" datatype="double" unit="unknown">
-        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="pca2x0y3" arraysize="1" datatype="double" unit="unknown">
-        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="pca2x2y0" arraysize="1" datatype="double" unit="unknown">
-        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="pca2x1y1" arraysize="1" datatype="double" unit="unknown">
-        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="pca2x0y2" arraysize="1" datatype="double" unit="unknown">
-        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="calibModNum" arraysize="1" datatype="short" unit="unknown">
+      <FIELD name="pca1x3y0" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
+      </FIELD>
+      <FIELD name="pca1x2y1" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
+      </FIELD>
+      <FIELD name="pca1x1y2" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
+      </FIELD>
+      <FIELD name="pca1x0y3" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
+      </FIELD>
+      <FIELD name="pca1x2y0" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
+      </FIELD>
+      <FIELD name="pca1x1y1" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
+      </FIELD>
+      <FIELD name="pca1x0y2" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
+      </FIELD>
+      <FIELD name="pca2x3y0" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
+      </FIELD>
+      <FIELD name="pca2x2y1" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
+      </FIELD>
+      <FIELD name="pca2x1y2" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
+      </FIELD>
+      <FIELD name="pca2x0y3" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
+      </FIELD>
+      <FIELD name="pca2x2y0" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
+      </FIELD>
+      <FIELD name="pca2x1y1" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
+      </FIELD>
+      <FIELD name="pca2x0y2" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
+      </FIELD>
+      <FIELD name="calibModNum" arraysize="1" datatype="short" unit="dimensionless" default="NA">
         <DESCRIPTION>calibration modification number</DESCRIPTION>
       </FIELD>
-      <FIELD name="batchID" arraysize="1" datatype="int" unit="unknown">
+      <FIELD name="batchID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
         <DESCRIPTION>batchID</DESCRIPTION>
       </FIELD>
-      <FIELD name="dataRelease" arraysize="1" datatype="unsignedByte" unit="unknown">
+      <FIELD name="dataRelease" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="NA">
         <DESCRIPTION>Data release</DESCRIPTION>
       </FIELD>
@@ -160,206 +160,224 @@
       <DESCRIPTION>VOTable description of PSPS table ImageMeta</DESCRIPTION>
       <PARAM arraysize="1" datatype="char" ucd="meta.bib.author" name="Author" value="PSPS"></PARAM>
-      <FIELD name="imageID" arraysize="1" datatype="long" unit="unknown">
+      <FIELD name="imageID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
         <DESCRIPTION>unique ID for each image, hashed from frameID and ccdID (ALEX)</DESCRIPTION>
       </FIELD>
-      <FIELD name="frameID" arraysize="1" datatype="int" unit="unknown">
+      <FIELD name="frameID" arraysize="1" datatype="int" unit="dimensionless" default="NA">
         <DESCRIPTION>frame identifier, also known as exposure number</DESCRIPTION>
       </FIELD>
-      <FIELD name="ccdID" arraysize="1" datatype="short" unit="unknown">
+      <FIELD name="ccdID" arraysize="1" datatype="short" unit="dimensionless" default="NA">
         <DESCRIPTION>ccd cell identifier in the focal plane</DESCRIPTION>
       </FIELD>
-      <FIELD name="photoCalID" arraysize="1" datatype="int" unit="unknown">
+      <FIELD name="photoCalID" arraysize="1" datatype="int" unit="dimensionless" default="NA">
         <DESCRIPTION>photometry reduction code identifier</DESCRIPTION>
       </FIELD>
-      <FIELD name="filterID" arraysize="1" datatype="unsignedByte" unit="unknown">
+      <FIELD name="filterID" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="NA">
         <DESCRIPTION>filter ID</DESCRIPTION>
       </FIELD>
-      <FIELD name="bias" arraysize="1" datatype="float" unit="ADU">
+      <FIELD name="bias" arraysize="1" datatype="float" unit="ADU" default="-999">
         <DESCRIPTION> detector bias level</DESCRIPTION>
       </FIELD>
-      <FIELD name="biasScat" arraysize="1" datatype="float" unit="ADU">
+      <FIELD name="biasScat" arraysize="1" datatype="float" unit="ADU" default="-999">
         <DESCRIPTION> scatter in bias level</DESCRIPTION>
       </FIELD>
-      <FIELD name="sky" arraysize="1" datatype="float" unit="ADU">
+      <FIELD name="sky" arraysize="1" datatype="float" unit="ADU/pixel" default="-999">
         <DESCRIPTION> mean sky level</DESCRIPTION>
       </FIELD>
-      <FIELD name="skyScat" arraysize="1" datatype="float" unit="ADU">
+      <FIELD name="skyScat" arraysize="1" datatype="float" unit="ADU/pixel" default="-999">
         <DESCRIPTION> scatter in mean sky level</DESCRIPTION>
       </FIELD>
-      <FIELD name="nDetect" arraysize="1" datatype="int" unit="unknown">
+      <FIELD name="nDetect" arraysize="1" datatype="int" unit="dimensionless" default="-999">
         <DESCRIPTION>number of detections on CCD</DESCRIPTION>
       </FIELD>
-      <FIELD name="magSat" arraysize="1" datatype="float" unit="mag">
+      <FIELD name="magSat" arraysize="1" datatype="float" unit="magnitude" default="-999">
         <DESCRIPTION> saturation magnitude level</DESCRIPTION>
       </FIELD>
-      <FIELD name="completMag" arraysize="1" datatype="float" unit="mag">
+      <FIELD name="completMag" arraysize="1" datatype="float" unit="magnitude" default="-999">
         <DESCRIPTION> 95% completion level in mag</DESCRIPTION>
       </FIELD>
-      <FIELD name="astroScat" arraysize="1" datatype="float" unit="mag">
+      <FIELD name="astroScat" arraysize="1" datatype="float" unit="arcsec" default="-999">
         <DESCRIPTION> astrometric scatter for chip</DESCRIPTION>
       </FIELD>
-      <FIELD name="photoScat" arraysize="1" datatype="float" unit="unknown">
+      <FIELD name="photoScat" arraysize="1" datatype="float" unit="magnitude" default="-999">
         <DESCRIPTION>photometric scatter for chip</DESCRIPTION>
       </FIELD>
-      <FIELD name="numAstroRef" arraysize="1" datatype="int" unit="unknown">
+      <FIELD name="numAstroRef" arraysize="1" datatype="int" unit="dimensionless" default="-999">
         <DESCRIPTION>number of astrometric reference sources</DESCRIPTION>
       </FIELD>
-      <FIELD name="numPhotoRef" arraysize="1" datatype="int" unit="unknown">
+      <FIELD name="numPhotoRef" arraysize="1" datatype="int" unit="dimensionless" default="-999">
         <DESCRIPTION>number of photometric reference sources</DESCRIPTION>
       </FIELD>
-      <FIELD name="nx" arraysize="1" datatype="short" unit="unknown">
+      <FIELD name="nx" arraysize="1" datatype="short" unit="pixels" default="-999">
         <DESCRIPTION>chip dimension in x</DESCRIPTION>
       </FIELD>
-      <FIELD name="ny" arraysize="1" datatype="short" unit="unknown">
+      <FIELD name="ny" arraysize="1" datatype="short" unit="pixels" default="-999">
         <DESCRIPTION>chip dimension in y</DESCRIPTION>
       </FIELD>
-      <FIELD name="psfModelID" arraysize="1" datatype="int" unit="unknown">
+      <FIELD name="psfModelID" arraysize="1" datatype="int" unit="dimensionless" default="-999">
         <DESCRIPTION>PSF model identifier</DESCRIPTION>
       </FIELD>
-      <FIELD name="psfFwhm" arraysize="1" datatype="float" unit="arcsec">
+      <FIELD name="psfFwhm" arraysize="1" datatype="float" unit="arcsec" default="-999">
         <DESCRIPTION> model psf full width at half maximum at chip center</DESCRIPTION>
       </FIELD>
-      <FIELD name="psfWidMajor" arraysize="1" datatype="float" unit="arcsec">
+      <FIELD name="psfWidMajor" arraysize="1" datatype="float" unit="arcsec" default="-999">
         <DESCRIPTION> model PSF parameters at chip center</DESCRIPTION>
       </FIELD>
-      <FIELD name="psfWidMinor" arraysize="1" datatype="float" unit="arcsec">
+      <FIELD name="psfWidMinor" arraysize="1" datatype="float" unit="arcsec" default="-999">
         <DESCRIPTION> model PSF parameters at chip center</DESCRIPTION>
       </FIELD>
-      <FIELD name="psfTheta" arraysize="1" datatype="float" unit="deg">
+      <FIELD name="psfTheta" arraysize="1" datatype="float" unit="degrees" default="-999">
         <DESCRIPTION> model PSF parameters at chip center</DESCRIPTION>
       </FIELD>
-      <FIELD name="momentFwhm" arraysize="1" datatype="float" unit="arcsec">
-        <DESCRIPTION> average PSF full width at half maximum from moments</DESCRIPTION>
-      </FIELD>
-      <FIELD name="momentWidMajor" arraysize="1" datatype="float" unit="arcsec">
-        <DESCRIPTION> average PSF parameters from moments</DESCRIPTION>
-      </FIELD>
-      <FIELD name="momentWidMinor" arraysize="1" datatype="float" unit="arcsec">
-        <DESCRIPTION> average PSF parameters from moments</DESCRIPTION>
-      </FIELD>
-      <FIELD name="apResid" arraysize="1" datatype="float" unit="unknown">
+      <FIELD name="momentXX" arraysize="1" datatype="float" unit="pixels" default="-999">
+        <DESCRIPTION> moment XX</DESCRIPTION>
+      </FIELD>
+      <FIELD name="momentXY" arraysize="1" datatype="float" unit="pixels" default="-999">
+        <DESCRIPTION> moment XY</DESCRIPTION>
+      </FIELD>
+      <FIELD name="momentYY" arraysize="1" datatype="float" unit="pixels" default="-999">
+        <DESCRIPTION> moment YY</DESCRIPTION>
+      </FIELD>
+      <FIELD name="momentM3C" arraysize="1" datatype="float" unit="pixels squared" default="-999">
+        <DESCRIPTION> moment M3C</DESCRIPTION>
+      </FIELD>
+      <FIELD name="momentM3S" arraysize="1" datatype="float" unit="pixels squared" default="-999">
+        <DESCRIPTION> moment M3S</DESCRIPTION>
+      </FIELD>
+      <FIELD name="momentM4C" arraysize="1" datatype="float" unit="pixels squared" default="-999">
+        <DESCRIPTION> moment M4C</DESCRIPTION>
+      </FIELD>
+      <FIELD name="momentM4S" arraysize="1" datatype="float" unit="pixels squared" default="-999">
+        <DESCRIPTION> moment M4S</DESCRIPTION>
+      </FIELD>
+      <FIELD name="momentR1" arraysize="1" datatype="float" unit="pixels" default="-999">
+        <DESCRIPTION> moment R1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="momentRH" arraysize="1" datatype="float" unit="sqrt pixels" default="-999">
+        <DESCRIPTION> moment RH</DESCRIPTION>
+      </FIELD>
+      <FIELD name="apResid" arraysize="1" datatype="float" unit="magnitude" default="-999">
         <DESCRIPTION>corrected aperture residual</DESCRIPTION>
       </FIELD>
-      <FIELD name="dapResid" arraysize="1" datatype="float" unit="unknown">
+      <FIELD name="dapResid" arraysize="1" datatype="float" unit="magnitude" default="-999">
         <DESCRIPTION>scatter of aperture corrections</DESCRIPTION>
       </FIELD>
-      <FIELD name="detectorID" arraysize="100" datatype="char" unit="unknown">
+      <FIELD name="detectorID" arraysize="100" datatype="char" unit="alphanumeric" default="">
         <DESCRIPTION>identifier for actual CCD chip</DESCRIPTION>
       </FIELD>
-      <FIELD name="qaFlags" arraysize="1" datatype="long" unit="unknown">
+      <FIELD name="qaFlags" arraysize="1" datatype="long" unit="alphanumeric" default="-999">
         <DESCRIPTION>Q/A flags for this OTA</DESCRIPTION>
       </FIELD>
-      <FIELD name="detrend1" arraysize="100" datatype="char" unit="unknown">
+      <FIELD name="detrend1" arraysize="100" datatype="char" unit="alphanumeric" default="8000">
         <DESCRIPTION>identifier of detrend image 1</DESCRIPTION>
       </FIELD>
-      <FIELD name="detrend2" arraysize="100" datatype="char" unit="unknown">
+      <FIELD name="detrend2" arraysize="100" datatype="char" unit="alphanumeric" default="8000">
         <DESCRIPTION>identifier of detrend image 2</DESCRIPTION>
       </FIELD>
-      <FIELD name="detrend3" arraysize="100" datatype="char" unit="unknown">
+      <FIELD name="detrend3" arraysize="100" datatype="char" unit="alphanumeric" default="8000">
         <DESCRIPTION>identifier of detrend image 3</DESCRIPTION>
       </FIELD>
-      <FIELD name="detrend4" arraysize="100" datatype="char" unit="unknown">
+      <FIELD name="detrend4" arraysize="100" datatype="char" unit="alphanumeric" default="8000">
         <DESCRIPTION>identifier of detrend image 4</DESCRIPTION>
       </FIELD>
-      <FIELD name="detrend5" arraysize="100" datatype="char" unit="unknown">
+      <FIELD name="detrend5" arraysize="100" datatype="char" unit="alphanumeric" default="8000">
         <DESCRIPTION>identifier of detrend image 5</DESCRIPTION>
       </FIELD>
-      <FIELD name="detrend6" arraysize="100" datatype="char" unit="unknown">
+      <FIELD name="detrend6" arraysize="100" datatype="char" unit="alphanumeric" default="8000">
         <DESCRIPTION>identifier of detrend image 6</DESCRIPTION>
       </FIELD>
-      <FIELD name="detrend7" arraysize="100" datatype="char" unit="unknown">
+      <FIELD name="detrend7" arraysize="100" datatype="char" unit="alphanumeric" default="8000">
         <DESCRIPTION>identifier of detrend image 7</DESCRIPTION>
       </FIELD>
-      <FIELD name="detrend8" arraysize="100" datatype="char" unit="unknown">
+      <FIELD name="detrend8" arraysize="100" datatype="char" unit="alphanumeric" default="8000">
         <DESCRIPTION>identifier of detrend image 8</DESCRIPTION>
       </FIELD>
-      <FIELD name="photoZero" arraysize="1" datatype="float" unit="mag">
+      <FIELD name="photoZero" arraysize="1" datatype="float" unit="magnitude" default="-999">
         <DESCRIPTION> local derived photometric zero point</DESCRIPTION>
       </FIELD>
-      <FIELD name="ctype1" arraysize="100" datatype="char" unit="unknown">
+      <FIELD name="ctype1" arraysize="100" datatype="char" unit="alphanumeric" default="8000">
         <DESCRIPTION>name of astrometric projection in RA</DESCRIPTION>
       </FIELD>
-      <FIELD name="ctype2" arraysize="100" datatype="char" unit="unknown">
+      <FIELD name="ctype2" arraysize="100" datatype="char" unit="alphanumeric" default="8000">
         <DESCRIPTION>name of astrometric projection in DEC</DESCRIPTION>
       </FIELD>
-      <FIELD name="crval1" arraysize="1" datatype="double" unit="deg">
+      <FIELD name="crval1" arraysize="1" datatype="double" unit="degrees" default="-999">
         <DESCRIPTION> RA corresponding to reference pixel</DESCRIPTION>
       </FIELD>
-      <FIELD name="crval2" arraysize="1" datatype="double" unit="deg">
+      <FIELD name="crval2" arraysize="1" datatype="double" unit="degrees" default="-999">
         <DESCRIPTION> DEC corresponding to reference pixel</DESCRIPTION>
       </FIELD>
-      <FIELD name="crpix1" arraysize="1" datatype="double" unit="pix">
+      <FIELD name="crpix1" arraysize="1" datatype="double" unit="pixels" default="-999">
         <DESCRIPTION> reference pixel value for RA</DESCRIPTION>
       </FIELD>
-      <FIELD name="crpix2" arraysize="1" datatype="double" unit="pix">
+      <FIELD name="crpix2" arraysize="1" datatype="double" unit="pixels" default="-999">
         <DESCRIPTION> reference pixel value for DEC</DESCRIPTION>
       </FIELD>
-      <FIELD name="cdelt1" arraysize="1" datatype="double" unit="unknown">
+      <FIELD name="cdelt1" arraysize="1" datatype="double" unit="degrees/pixel" default="-999">
         <DESCRIPTION>scale factor for RA</DESCRIPTION>
       </FIELD>
-      <FIELD name="cdelt2" arraysize="1" datatype="double" unit="unknown">
+      <FIELD name="cdelt2" arraysize="1" datatype="double" unit="degrees/pixel" default="-999">
         <DESCRIPTION>scale factor for DEC</DESCRIPTION>
       </FIELD>
-      <FIELD name="pc001001" arraysize="1" datatype="double" unit="unknown">
-        <DESCRIPTION>elements of rotation/Dcale matrix</DESCRIPTION>
-      </FIELD>
-      <FIELD name="pc001002" arraysize="1" datatype="double" unit="unknown">
-        <DESCRIPTION>elements of rotation/Dcale matrix</DESCRIPTION>
-      </FIELD>
-      <FIELD name="pc002001" arraysize="1" datatype="double" unit="unknown">
-        <DESCRIPTION>elements of rotation/Dcale matrix</DESCRIPTION>
-      </FIELD>
-      <FIELD name="pc002002" arraysize="1" datatype="double" unit="unknown">
-        <DESCRIPTION>elements of rotation/Dcale matrix</DESCRIPTION>
-      </FIELD>
-      <FIELD name="polyOrder" arraysize="1" datatype="unsignedByte" unit="unknown">
+      <FIELD name="pc001001" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>elements of rotation/scale matrix</DESCRIPTION>
+      </FIELD>
+      <FIELD name="pc001002" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>elements of rotation/scale matrix</DESCRIPTION>
+      </FIELD>
+      <FIELD name="pc002001" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>elements of rotation/scale matrix</DESCRIPTION>
+      </FIELD>
+      <FIELD name="pc002002" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>elements of rotation/scale matrix</DESCRIPTION>
+      </FIELD>
+      <FIELD name="polyOrder" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="255">
         <DESCRIPTION>polynomial order of astrometry fit</DESCRIPTION>
       </FIELD>
-      <FIELD name="pca1x3y0" arraysize="1" datatype="double" unit="unknown">
-        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="pca1x2y1" arraysize="1" datatype="double" unit="unknown">
-        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="pca1x1y2" arraysize="1" datatype="double" unit="unknown">
-        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="pca1x0y3" arraysize="1" datatype="double" unit="unknown">
-        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="pca1x2y0" arraysize="1" datatype="double" unit="unknown">
-        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="pca1x1y1" arraysize="1" datatype="double" unit="unknown">
-        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="pca1x0y2" arraysize="1" datatype="double" unit="unknown">
-        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="pca2x3y0" arraysize="1" datatype="double" unit="unknown">
-        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="pca2x2y1" arraysize="1" datatype="double" unit="unknown">
-        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="pca2x1y2" arraysize="1" datatype="double" unit="unknown">
-        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="pca2x0y3" arraysize="1" datatype="double" unit="unknown">
-        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="pca2x2y0" arraysize="1" datatype="double" unit="unknown">
-        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="pca2x1y1" arraysize="1" datatype="double" unit="unknown">
-        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="pca2x0y2" arraysize="1" datatype="double" unit="unknown">
-        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="calibModNum" arraysize="1" datatype="short" unit="unknown">
+      <FIELD name="pca1x3y0" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
+      </FIELD>
+      <FIELD name="pca1x2y1" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
+      </FIELD>
+      <FIELD name="pca1x1y2" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
+      </FIELD>
+      <FIELD name="pca1x0y3" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
+      </FIELD>
+      <FIELD name="pca1x2y0" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
+      </FIELD>
+      <FIELD name="pca1x1y1" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
+      </FIELD>
+      <FIELD name="pca1x0y2" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
+      </FIELD>
+      <FIELD name="pca2x3y0" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
+      </FIELD>
+      <FIELD name="pca2x2y1" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
+      </FIELD>
+      <FIELD name="pca2x1y2" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
+      </FIELD>
+      <FIELD name="pca2x0y3" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
+      </FIELD>
+      <FIELD name="pca2x2y0" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
+      </FIELD>
+      <FIELD name="pca2x1y1" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
+      </FIELD>
+      <FIELD name="pca2x0y2" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>polynomial coefficients for the astrometric fit</DESCRIPTION>
+      </FIELD>
+      <FIELD name="calibModNum" arraysize="1" datatype="short" unit="dimensionless" default="NA">
         <DESCRIPTION>calibration modification number</DESCRIPTION>
       </FIELD>
-      <FIELD name="dataRelease" arraysize="1" datatype="unsignedByte" unit="unknown">
+      <FIELD name="dataRelease" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="NA">
         <DESCRIPTION>Data release</DESCRIPTION>
       </FIELD>
@@ -371,194 +389,168 @@
       <DESCRIPTION>VOTable description of PSPS table Detection</DESCRIPTION>
       <PARAM arraysize="1" datatype="char" ucd="meta.bib.author" name="Author" value="PSPS"></PARAM>
-      <FIELD name="objID" arraysize="1" datatype="long" unit="unknown">
+      <FIELD name="objID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
         <DESCRIPTION>ODM object identifier</DESCRIPTION>
       </FIELD>
-      <FIELD name="detectID" arraysize="1" datatype="long" unit="unknown">
+      <FIELD name="gcobjID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>galactic coordinates ODM object identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="detectID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
         <DESCRIPTION>ODM detection identifier</DESCRIPTION>
       </FIELD>
-      <FIELD name="ippObjID" arraysize="1" datatype="long" unit="unknown">
+      <FIELD name="ippObjID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
         <DESCRIPTION>object id generated by IPP</DESCRIPTION>
       </FIELD>
-      <FIELD name="ippDetectID" arraysize="1" datatype="long" unit="unknown">
+      <FIELD name="ippDetectID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
         <DESCRIPTION>detection id generated by IPP</DESCRIPTION>
       </FIELD>
-      <FIELD name="filterID" arraysize="1" datatype="unsignedByte" unit="unknown">
+      <FIELD name="filterID" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="NA">
         <DESCRIPTION>filter ID: g=1, r=2, i=3, z=4, y=5, w=6, ...</DESCRIPTION>
       </FIELD>
-      <FIELD name="surveyID" arraysize="1" datatype="unsignedByte" unit="unknown">
+      <FIELD name="surveyID" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="NA">
         <DESCRIPTION>survey flag identifier</DESCRIPTION>
       </FIELD>
-      <FIELD name="imageID" arraysize="1" datatype="long" unit="unknown">
+      <FIELD name="imageID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
         <DESCRIPTION>image id hash of frame identifier &amp; OTA/CCD number</DESCRIPTION>
       </FIELD>
-      <FIELD name="obsTime" arraysize="1" datatype="double" unit="day">
-        <DESCRIPTION> Time of mid observation</DESCRIPTION>
-      </FIELD>
-      <FIELD name="xPos" arraysize="1" datatype="float" unit="pix">
+      <FIELD name="randomDetID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION> random detection Id</DESCRIPTION>
+      </FIELD>
+      <FIELD name="dvoRegionID" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION> identifier to dvo spacial region</DESCRIPTION>
+      </FIELD>
+      <FIELD name="obsTime" arraysize="1" datatype="double" unit="MeanJulianDays" default="-999">
+        <DESCRIPTION> Time of mid observation in Mean Julian Days</DESCRIPTION>
+      </FIELD>
+      <FIELD name="xPos" arraysize="1" datatype="float" unit="raw pixels" default="-999">
         <DESCRIPTION> measured x on CCD from PSF fit</DESCRIPTION>
       </FIELD>
-      <FIELD name="yPos" arraysize="1" datatype="float" unit="pix">
+      <FIELD name="yPos" arraysize="1" datatype="float" unit="raw pixels" default="-999">
         <DESCRIPTION> measured y on CCD from PSF fit</DESCRIPTION>
       </FIELD>
-      <FIELD name="xPosErr" arraysize="1" datatype="float" unit="pix">
+      <FIELD name="xPosErr" arraysize="1" datatype="float" unit="raw pixels" default="-999">
         <DESCRIPTION> estimated error in x</DESCRIPTION>
       </FIELD>
-      <FIELD name="yPosErr" arraysize="1" datatype="float" unit="pix">
+      <FIELD name="yPosErr" arraysize="1" datatype="float" unit="raw pixels" default="-999">
         <DESCRIPTION> estimated error in y</DESCRIPTION>
       </FIELD>
-      <FIELD name="psfFlux" arraysize="1" datatype="float" unit="adu/s">
-        <DESCRIPTION> PSF instrumental flux</DESCRIPTION>
-      </FIELD>
-      <FIELD name="psfFluxErr" arraysize="1" datatype="float" unit="adu/s">
+      <FIELD name="pltScale" arraysize="1" datatype="float" unit="arcsec/pix" default="-999">
+	<DESCRIPTION> plate scale at this location (from DVO)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="posAngle" arraysize="1" datatype="float" unit="degrees" default="-999">
+	<DESCRIPTION> position angle (sky-to-chip) at this location (from DVO)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ra" arraysize="1" datatype="double" unit="degrees" default="NA">
+        <DESCRIPTION>right ascension</DESCRIPTION>
+      </FIELD>
+      <FIELD name="dec" arraysize="1" datatype="double" unit="degrees" default="NA">
+        <DESCRIPTION>declination</DESCRIPTION>
+      </FIELD>
+      <FIELD name="raErr" arraysize="1" datatype="float" unit="arcsec" default="NA">
+        <DESCRIPTION>right ascension error</DESCRIPTION>
+      </FIELD>
+      <FIELD name="decErr" arraysize="1" datatype="float" unit="arcsec" default="NA">
+        <DESCRIPTION>declination error</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zp" arraysize="1" datatype="float" unit="magnitude" default="0">
+        <DESCRIPTION>zeropoint</DESCRIPTION>
+      </FIELD>
+      <FIELD name="telluricExt" arraysize="1" datatype="float" unit="magnitude" default="NA">
+        <DESCRIPTION>estimated extinction due to non-photometric conditions</DESCRIPTION>
+      </FIELD>
+      <FIELD name="expTime" arraysize="1" datatype="float" unit="seconds" default="-999">
+        <DESCRIPTION>exposure time (informational)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="airMass" arraysize="1" datatype="float" unit="dimensionless" default="0">
+        <DESCRIPTION>airmass (informational)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="psfFlux" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION> PSF instrumental flux (in analog-to-digital units/sec) or	adu/sec</DESCRIPTION>
+      </FIELD>
+      <FIELD name="psfFluxErr" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
         <DESCRIPTION> estimated error in flux</DESCRIPTION>
       </FIELD>
-      <FIELD name="peakADU" arraysize="1" datatype="float" unit="adu">
-        <DESCRIPTION> peak count in source pixel</DESCRIPTION>
-      </FIELD>
-      <FIELD name="psfWidMajor" arraysize="1" datatype="float" unit="arcsec">
+      <FIELD name="psfMajorFWHM" arraysize="1" datatype="float" unit="arcsec" default="-999">
         <DESCRIPTION> model PSF width in major axis</DESCRIPTION>
       </FIELD>
-      <FIELD name="psfWidMinor" arraysize="1" datatype="float" unit="arcsec">
+      <FIELD name="psfMinorFWHM" arraysize="1" datatype="float" unit="arcsec" default="-999">
         <DESCRIPTION> model PSF width in minor axis</DESCRIPTION>
       </FIELD>
-      <FIELD name="psfTheta" arraysize="1" datatype="float" unit="deg">
-        <DESCRIPTION> model PSF orientation angle</DESCRIPTION>
-      </FIELD>
-      <FIELD name="psfLikelihood" arraysize="1" datatype="float" unit="unknown">
+      <FIELD name="psfTheta" arraysize="1" datatype="float" unit="degrees" default="-999">
+        <DESCRIPTION> model PSF orientation angle degrees East of North</DESCRIPTION>
+      </FIELD>
+      <FIELD name="psfCore" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>model PSF core parameter [k in 1 + kz + z^1.66)]</DESCRIPTION>
+      </FIELD>
+      <FIELD name="psfQf" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>PSF coverage factor</DESCRIPTION>
+      </FIELD>
+      <FIELD name="psfQfPerfect" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>PSF-weighted fraction of pixels totally unmasked</DESCRIPTION>
+      </FIELD>
+      <FIELD name="psfChiSq" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>reduced-chisq of the psf model fit. (ndof?, npix?)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="psfLikelihood" arraysize="1" datatype="float" unit="dimensionless" default="-999">
         <DESCRIPTION>PSF likelihood</DESCRIPTION>
       </FIELD>
-      <FIELD name="psfQf" arraysize="1" datatype="float" unit="unknown">
-        <DESCRIPTION>PSF qf</DESCRIPTION>
-      </FIELD>
-      <FIELD name="momentXX" arraysize="1" datatype="float" unit="arcsec">
+      <FIELD name="momentXX" arraysize="1" datatype="float" unit="raw pixels" default="-999">
         <DESCRIPTION> moment XX</DESCRIPTION>
       </FIELD>
-      <FIELD name="momentXY" arraysize="1" datatype="float" unit="arcsec">
+      <FIELD name="momentXY" arraysize="1" datatype="float" unit="raw pixels" default="-999">
         <DESCRIPTION> moment XY</DESCRIPTION>
       </FIELD>
-      <FIELD name="momentYY" arraysize="1" datatype="float" unit="arcsec">
-        <DESCRIPTION> momeny YY</DESCRIPTION>
-      </FIELD>
-      <FIELD name="apFlux" arraysize="1" datatype="float" unit="adu/s">
+      <FIELD name="momentYY" arraysize="1" datatype="float" unit="raw pixels" default="-999">
+        <DESCRIPTION> moment YY</DESCRIPTION>
+      </FIELD>
+      <FIELD name="momentR1" arraysize="1" datatype="float" unit="raw pixels" default="-999">
+        <DESCRIPTION> first radial moment</DESCRIPTION>
+      </FIELD>
+      <FIELD name="momentRH" arraysize="1" datatype="float" unit="raw pixels" default="-999">
+        <DESCRIPTION> half radial moment</DESCRIPTION>
+      </FIELD>
+      <FIELD name="momentM3C" arraysize="1" datatype="float" unit="raw pixels" default="-999">
+        <DESCRIPTION> 3rd moment cos(theta)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="momentM3S" arraysize="1" datatype="float" unit="raw pixels" default="-999">
+        <DESCRIPTION> 3rd moment sin(theta)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="momentM4C" arraysize="1" datatype="float" unit="raw pixels" default="-999">
+        <DESCRIPTION> 4th moment cos(theta)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="momentM4S" arraysize="1" datatype="float" unit="raw pixels" default="-999">
+        <DESCRIPTION> 4th moment sin(theta)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="apFlux" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
         <DESCRIPTION> Aperture Flux</DESCRIPTION>
       </FIELD>
-      <FIELD name="apFluxErr" arraysize="1" datatype="float" unit="adu/s">
+      <FIELD name="apFluxErr" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
         <DESCRIPTION> Aperture Flux error</DESCRIPTION>
       </FIELD>
-      <FIELD name="kronFlux" arraysize="1" datatype="float" unit="adu/s">
+      <FIELD name="apFillF" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION> Aperture fill factor</DESCRIPTION>
+      </FIELD>
+      <FIELD name="kronFlux" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
         <DESCRIPTION> Kron flux</DESCRIPTION>
       </FIELD>
-      <FIELD name="kronFluxErr" arraysize="1" datatype="float" unit="adu/s">
+      <FIELD name="kronFluxErr" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
         <DESCRIPTION> Kron flux error</DESCRIPTION>
       </FIELD>
-      <FIELD name="kronRad" arraysize="1" datatype="float" unit="arcsecs">
+      <FIELD name="kronRad" arraysize="1" datatype="float" unit="raw pixels" default="-999">
         <DESCRIPTION> Kron radius</DESCRIPTION>
       </FIELD>
-      <FIELD name="kronRadErr" arraysize="1" datatype="float" unit="arcsecs">
+      <FIELD name="kronRadErr" arraysize="1" datatype="float" unit="raw pixels" default="-999">
         <DESCRIPTION> Kron radius error</DESCRIPTION>
       </FIELD>
-      <FIELD name="psfQfPerfect" arraysize="1" datatype="float" unit="unknown">
-        <DESCRIPTION>psf QF Perfect</DESCRIPTION>
-      </FIELD>
-      <FIELD name="psfChiSq" arraysize="1" datatype="float" unit="unknown">
-        <DESCRIPTION>PSF Chi sq</DESCRIPTION>
-      </FIELD>
-      <FIELD name="infoFlag" arraysize="1" datatype="long" unit="unknown">
+      <FIELD name="sky" arraysize="1" datatype="float" unit="adu/sec/pixel" default="-999">
+        <DESCRIPTION> PSF sky level at source</DESCRIPTION>
+      </FIELD>
+      <FIELD name="skyErr" arraysize="1" datatype="float" unit="adu/sec/pixel" default="-999">
+        <DESCRIPTION> estimated error in sky</DESCRIPTION>
+      </FIELD>
+      <FIELD name="infoFlag" arraysize="1" datatype="long" unit="dimensionless" default="-999">
         <DESCRIPTION>flag indicating provenance information</DESCRIPTION>
       </FIELD>
-      <FIELD name="sky" arraysize="1" datatype="float" unit="adu/s/pixel">
-        <DESCRIPTION> PSF sky level at source</DESCRIPTION>
-      </FIELD>
-      <FIELD name="skyErr" arraysize="1" datatype="float" unit="adu/s/pixel">
-        <DESCRIPTION> estimated error in sky</DESCRIPTION>
-      </FIELD>
-      <FIELD name="sgSep" arraysize="1" datatype="float" unit="unknown">
-        <DESCRIPTION>star/galaxy separator</DESCRIPTION>
-      </FIELD>
-      <FIELD name="activeFlag" arraysize="1" datatype="unsignedByte" unit="unknown">
-        <DESCRIPTION>indicates whether this detection/orphan is still a detection/orphan</DESCRIPTION>
-      </FIELD>
-      <FIELD name="assocDate" arraysize="100" datatype="char" unit="unknown">
-        <DESCRIPTION>date object association assigned</DESCRIPTION>
-      </FIELD>
-      <FIELD name="historyModNum" arraysize="1" datatype="short" unit="unknown">
-        <DESCRIPTION>modification number in the O-D association history</DESCRIPTION>
-      </FIELD>
-      <FIELD name="dataRelease" arraysize="1" datatype="unsignedByte" unit="unknown">
+      <FIELD name="dataRelease" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="NA">
         <DESCRIPTION>Data release when this detection was originally taken. Recalibrations do not affect this value.</DESCRIPTION>
-      </FIELD>
-      <DATA>
-        <TABLEDATA></TABLEDATA>
-      </DATA>
-    </TABLE>
-    <TABLE name="SkinnyObject">
-      <DESCRIPTION>VOTable description of PSPS table SkinnyObject</DESCRIPTION>
-      <PARAM arraysize="1" datatype="char" ucd="meta.bib.author" name="Author" value="PSPS"></PARAM>
-      <FIELD name="objID" arraysize="1" datatype="long" unit="unknown">
-        <DESCRIPTION>ODM object identifier index</DESCRIPTION>
-      </FIELD>
-      <FIELD name="ippObjID" arraysize="1" datatype="long" unit="unknown">
-        <DESCRIPTION>IPP object number</DESCRIPTION>
-      </FIELD>
-      <FIELD name="projectionCellID" arraysize="1" datatype="int" unit="unknown">
-        <DESCRIPTION>projection cell identifier at discovery time</DESCRIPTION>
-      </FIELD>
-      <FIELD name="dataRelease" arraysize="1" datatype="unsignedByte" unit="unknown">
-        <DESCRIPTION>Data release to propagate to the object</DESCRIPTION>
-      </FIELD>
-      <FIELD name="surveyID" arraysize="1" datatype="unsignedByte" unit="unknown">
-        <DESCRIPTION>surveyID &lt;/coluumn&gt;</DESCRIPTION>
-      </FIELD>
-      <DATA>
-        <TABLEDATA></TABLEDATA>
-      </DATA>
-    </TABLE>
-    <TABLE name="DetectionCalib">
-      <DESCRIPTION>VOTable description of PSPS table DetectionCalib</DESCRIPTION>
-      <PARAM arraysize="1" datatype="char" ucd="meta.bib.author" name="Author" value="PSPS"></PARAM>
-      <FIELD name="objID" arraysize="1" datatype="long" unit="unknown">
-        <DESCRIPTION>ODM object identifier index</DESCRIPTION>
-      </FIELD>
-      <FIELD name="detectID" arraysize="1" datatype="long" unit="unknown">
-        <DESCRIPTION>ODM detection identifier index</DESCRIPTION>
-      </FIELD>
-      <FIELD name="ippObjID" arraysize="1" datatype="long" unit="unknown">
-        <DESCRIPTION>IPP object number</DESCRIPTION>
-      </FIELD>
-      <FIELD name="ippDetectID" arraysize="1" datatype="long" unit="unknown">
-        <DESCRIPTION>detection ID generated by IPP</DESCRIPTION>
-      </FIELD>
-      <FIELD name="filterID" arraysize="1" datatype="unsignedByte" unit="unknown">
-        <DESCRIPTION>filter identifier</DESCRIPTION>
-      </FIELD>
-      <FIELD name="surveyID" arraysize="1" datatype="unsignedByte" unit="unknown">
-        <DESCRIPTION>survey identifier</DESCRIPTION>
-      </FIELD>
-      <FIELD name="ra" arraysize="1" datatype="double" unit="degrees">
-        <DESCRIPTION>right ascension</DESCRIPTION>
-      </FIELD>
-      <FIELD name="dec" arraysize="1" datatype="double" unit="degrees">
-        <DESCRIPTION>declination</DESCRIPTION>
-      </FIELD>
-      <FIELD name="raErr" arraysize="1" datatype="float" unit="arcsec">
-        <DESCRIPTION>right ascension error</DESCRIPTION>
-      </FIELD>
-      <FIELD name="decErr" arraysize="1" datatype="float" unit="arcsec">
-        <DESCRIPTION>declination error</DESCRIPTION>
-      </FIELD>
-      <FIELD name="zp" arraysize="1" datatype="float" unit="magnitude">
-        <DESCRIPTION>zero point offset</DESCRIPTION>
-      </FIELD>
-      <FIELD name="zpErr" arraysize="1" datatype="float" unit="magnitude">
-        <DESCRIPTION>zerop point offset error</DESCRIPTION>
-      </FIELD>
-      <FIELD name="expTime" arraysize="1" datatype="float" unit="s">
-        <DESCRIPTION>exposure time</DESCRIPTION>
-      </FIELD>
-      <FIELD name="airMass" arraysize="1" datatype="float" unit="unknown">
-        <DESCRIPTION>airmass</DESCRIPTION>
-      </FIELD>
-      <FIELD name="dataRelease" arraysize="1" datatype="unsignedByte" unit="unknown">
-        <DESCRIPTION>Data release to propagate to the object</DESCRIPTION>
       </FIELD>
       <DATA>
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/config/tables.ST.vot
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/config/tables.ST.vot	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/config/tables.ST.vot	(revision 37066)
@@ -5,108 +5,108 @@
     <TABLE name="StackMeta">
       <DESCRIPTION>VOTable description of PSPS table StackMeta</DESCRIPTION>
-      <PARAM arraysize="1" datatype="char" ucd="meta.bib.author" name="Author" value="PSPS"></PARAM>
-      <FIELD name="stackMetaID" arraysize="1" datatype="long">
+      <PARAM arraysize="1" datatype="char" ucd="meta.bib.author" name="Author" value="PSPS"></PARAM>              
+      <FIELD name="stackMetaID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
         <DESCRIPTION>stack identifier</DESCRIPTION>
       </FIELD>
-      <FIELD name="skycellID" arraysize="1" datatype="int">
+      <FIELD name="batchID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>batchID</DESCRIPTION>
+      </FIELD>
+      <FIELD name="surveyID" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="NA">
+        <DESCRIPTION>survey flag identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="filterID" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="NA">
+        <DESCRIPTION>filter identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="stackTypeID" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="0">
+        <DESCRIPTION>stack type identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="skyCellID" arraysize="1" datatype="float" unit="dimensionless" default="NA">
         <DESCRIPTION>skycell region identifier</DESCRIPTION>
       </FIELD>
-      <FIELD name="surveyID" arraysize="1" datatype="unsignedByte">
-        <DESCRIPTION>survey flag identifier</DESCRIPTION>
-      </FIELD>
-      <FIELD name="photoCalID" arraysize="1" datatype="int">
+      <FIELD name="photoCalID" arraysize="1" datatype="int" unit="dimensionless" default="NA">
         <DESCRIPTION>photometry code numerical id</DESCRIPTION>
       </FIELD>
-      <FIELD name="filterID" arraysize="1" datatype="unsignedByte">
-        <DESCRIPTION>filter identifier</DESCRIPTION>
-      </FIELD>
-      <FIELD name="stackTypeID" arraysize="1" datatype="unsignedByte">
-        <DESCRIPTION>stack type identifier</DESCRIPTION>
-      </FIELD>
-      <FIELD name="magSat" arraysize="1" datatype="float">
+      <FIELD name="magSat" arraysize="1" datatype="float" unit="dimensionless" default="-999">
         <DESCRIPTION>saturation magnitude level</DESCRIPTION>
       </FIELD>
-      <FIELD name="analVer" arraysize="1" datatype="short">
+      <FIELD name="analVer" arraysize="1" datatype="short" unit="dimensionless" default="-999">
         <DESCRIPTION>analysis version index</DESCRIPTION>
       </FIELD>
-      <FIELD name="expTime" arraysize="1" datatype="float">
+      <FIELD name="expTime" arraysize="1" datatype="float" unit="seconds" default="-999">
         <DESCRIPTION> exposure time (unit = s)</DESCRIPTION>
       </FIELD>
-      <FIELD name="nP2Images" arraysize="1" datatype="short">
+      <FIELD name="nP2Images" arraysize="1" datatype="short" unit="dimensionless" default="-999">
         <DESCRIPTION>number of P2 images contributing to this cell</DESCRIPTION>
       </FIELD>
-      <FIELD name="completMag" arraysize="1" datatype="float">
+      <FIELD name="completMag" arraysize="1" datatype="float" unit="magnitudes" default="-999">
         <DESCRIPTION>95% completion level in mag</DESCRIPTION>
       </FIELD>
-      <FIELD name="astroScat" arraysize="1" datatype="float">
+      <FIELD name="astroScat" arraysize="1" datatype="float" unit="dimensionless" default="-999">
         <DESCRIPTION>astrometric scatter for chip</DESCRIPTION>
       </FIELD>
-      <FIELD name="photoScat" arraysize="1" datatype="float">
+      <FIELD name="photoScat" arraysize="1" datatype="float" unit="dimensionless" default="-999">
         <DESCRIPTION>photometric scatter for chip</DESCRIPTION>
       </FIELD>
-      <FIELD name="nAstroRef" arraysize="1" datatype="int">
+      <FIELD name="nAstroRef" arraysize="1" datatype="int" unit="dimensionless" default="-999">
         <DESCRIPTION>number of astrometric reference sources</DESCRIPTION>
       </FIELD>
-      <FIELD name="nPhoRef" arraysize="1" datatype="int">
+      <FIELD name="nPhoRef" arraysize="1" datatype="int" unit="dimensionless" default="-999">
         <DESCRIPTION>number of photometric reference sources</DESCRIPTION>
       </FIELD>
-      <FIELD name="psfModelID" arraysize="100" datatype="char">
+      <FIELD name="psfModelID" arraysize="100" datatype="char" unit="dimensionless" default="8000">
         <DESCRIPTION>PSF model identifier</DESCRIPTION>
       </FIELD>
-      <FIELD name="psfFwhm_mean" arraysize="1" datatype="double">
+      <FIELD name="psfFwhm_mean" arraysize="1" datatype="double" unit="arcsec" default="-999">
         <DESCRIPTION>mean PSF FWHM in the stack</DESCRIPTION>
       </FIELD>
-      <FIELD name="psfFwhm_max" arraysize="1" datatype="double">
+      <FIELD name="psfFwhm_max" arraysize="1" datatype="double" unit="arcsec" default="-999">
         <DESCRIPTION>maximum PSF FWHM in the stack</DESCRIPTION>
       </FIELD>
-      <FIELD name="photoZero" arraysize="1" datatype="float">
+      <FIELD name="photoZero" arraysize="1" datatype="float" unit="magnitudes" default="-999">
         <DESCRIPTION>local derived photometric zero point</DESCRIPTION>
       </FIELD>
-      <FIELD name="photoColor" arraysize="1" datatype="float">
+      <FIELD name="photoColor" arraysize="1" datatype="float" unit="magnitudes" default="-999">
         <DESCRIPTION>local derived photometric color term</DESCRIPTION>
       </FIELD>
-      <FIELD name="ctype1" arraysize="100" datatype="char">
+      <FIELD name="ctype1" arraysize="100" datatype="char" unit="alphanumeric" default="8000">
         <DESCRIPTION>name of astrometric projection in RA</DESCRIPTION>
       </FIELD>
-      <FIELD name="ctype2" arraysize="100" datatype="char">
+      <FIELD name="ctype2" arraysize="100" datatype="char" unit="alphanumeric" default="8000">
         <DESCRIPTION>name of astrometric projection in DEC</DESCRIPTION>
       </FIELD>
-      <FIELD name="crval1" arraysize="1" datatype="double">
+      <FIELD name="crval1" arraysize="1" datatype="double" unit="degrees" default="-999">
         <DESCRIPTION>RA corresponding to reference pixel</DESCRIPTION>
       </FIELD>
-      <FIELD name="crval2" arraysize="1" datatype="double">
+      <FIELD name="crval2" arraysize="1" datatype="double" unit="degrees" default="-999">
         <DESCRIPTION>DEC corresponding to reference pixel</DESCRIPTION>
       </FIELD>
-      <FIELD name="crpix1" arraysize="1" datatype="double">
+      <FIELD name="crpix1" arraysize="1" datatype="double" unit="dimensionless" default="-999">
         <DESCRIPTION>reference pixel value for RA</DESCRIPTION>
       </FIELD>
-      <FIELD name="crpix2" arraysize="1" datatype="double">
+      <FIELD name="crpix2" arraysize="1" datatype="double" unit="dimensionless" default="-999">
         <DESCRIPTION>reference pixel value for DEC</DESCRIPTION>
       </FIELD>
-      <FIELD name="cdelt1" arraysize="1" datatype="double">
+      <FIELD name="cdelt1" arraysize="1" datatype="double" unit="deg/pixel" default="-999">
         <DESCRIPTION>scale factor for RA</DESCRIPTION>
       </FIELD>
-      <FIELD name="cdelt2" arraysize="1" datatype="double">
+      <FIELD name="cdelt2" arraysize="1" datatype="double" unit="deg/pixel" default="-999">
         <DESCRIPTION>scale factor for DEC</DESCRIPTION>
       </FIELD>
-      <FIELD name="pc001001" arraysize="1" datatype="double">
-        <DESCRIPTION>elements of rotation/Dcale matrix</DESCRIPTION>
-      </FIELD>
-      <FIELD name="pc001002" arraysize="1" datatype="double">
-        <DESCRIPTION>elements of rotation/Dcale matrix</DESCRIPTION>
-      </FIELD>
-      <FIELD name="pc002001" arraysize="1" datatype="double">
-        <DESCRIPTION>elements of rotation/Dcale matrix</DESCRIPTION>
-      </FIELD>
-      <FIELD name="pc002002" arraysize="1" datatype="double">
-        <DESCRIPTION>elements of rotation/Dcale matrix</DESCRIPTION>
-      </FIELD>
-      <FIELD name="calibModNum" arraysize="1" datatype="short">
+      <FIELD name="pc001001" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>elements of rotation/scale matrix</DESCRIPTION>
+      </FIELD>
+      <FIELD name="pc001002" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>elements of rotation/scale matrix</DESCRIPTION>
+      </FIELD>
+      <FIELD name="pc002001" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>elements of rotation/scale matrix</DESCRIPTION>
+      </FIELD>
+      <FIELD name="pc002002" arraysize="1" datatype="double" unit="dimensionless" default="-999">
+        <DESCRIPTION>elements of rotation/scale matrix</DESCRIPTION>
+      </FIELD>
+      <FIELD name="calibModNum" arraysize="1" datatype="short" unit="dimensionless" default="NA">
         <DESCRIPTION>calibration modification number</DESCRIPTION>
       </FIELD>
-      <FIELD name="batchID" arraysize="1" datatype="int" unit="unknown">
-        <DESCRIPTION>batchID</DESCRIPTION>
-      </FIELD>
-      <FIELD name="dataRelease" arraysize="1" datatype="unsignedByte">
+      <FIELD name="dataRelease" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="NA">
         <DESCRIPTION>Data release</DESCRIPTION>
       </FIELD>
@@ -115,151 +115,712 @@
       </DATA>
     </TABLE>
-    <TABLE name="StackDetection">
-      <DESCRIPTION>VOTable description of PSPS table StackDetection</DESCRIPTION>
+    <TABLE name="StackObject">
+      <DESCRIPTION>VOTable description of PSPS table StackObject</DESCRIPTION>
       <PARAM arraysize="1" datatype="char" ucd="meta.bib.author" name="Author" value="PSPS"></PARAM>
-      <FIELD name="objID" arraysize="1" datatype="long">
+      <FIELD name="objID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
         <DESCRIPTION>ODM object identifier</DESCRIPTION>
       </FIELD>
-      <FIELD name="stackDetectID" arraysize="1" datatype="long">
+      <FIELD name="gcobjID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>galactic coordinates ODM object identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="surveyID" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="NA">
+        <DESCRIPTION>survey flag identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="skyCellID" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>single float giving PrimaryCell.SkyCell identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="randomStackObjID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+	<DESCRIPTION>random stack id</DESCRIPTION>
+      </FIELD>
+      <FIELD name="stackDetectRowID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+	<DESCRIPTION>identifies which of up to 5 possible stackdetections this row refers to: primary, up to 3 Secondary, 1 best</DESCRIPTION>
+      </FIELD>
+      <FIELD name="primaryDetection" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="255">
+        <DESCRIPTION>identifies if this row is a primary stack detection. True about 80 percent of time</DESCRIPTION>
+      </FIELD>
+      <FIELD name="bestDetection" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="255">
+        <DESCRIPTION>identifies if this row is a best detection or not. Also set if only a primary detection exists.</DESCRIPTION>
+      </FIELD>
+      <FIELD name="dvoRegionID" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>identifier to dvo spatial region</DESCRIPTION>
+      </FIELD>
+      <FIELD name="dataRelease" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="NA">
+        <DESCRIPTION>Data release when this table was loaded.</DESCRIPTION>
+      </FIELD> 
+      <FIELD name="gippObjID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>IPP object identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gippDetectID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>ipp identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gstackDetectID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
         <DESCRIPTION>ODM detection identifier</DESCRIPTION>
       </FIELD>
-      <FIELD name="ippObjID" arraysize="1" datatype="long">
+      <FIELD name="gstackMetaID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>stack identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gxPos" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>measured x on skycell from PSF fit</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gyPos" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>measured y on skycell from PSF fit</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gxPosErr" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>estimated error in x</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gyPosErr" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>estimated error in y</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gra" arraysize="1" datatype="double" unit="degrees" default="NA">
+        <DESCRIPTION>right ascension</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gdec" arraysize="1" datatype="double" unit="degrees" default="NA">
+        <DESCRIPTION>declination</DESCRIPTION>
+      </FIELD>
+      <FIELD name="graErr" arraysize="1" datatype="float" unit="arcsec" default="NA">
+        <DESCRIPTION>right ascension error</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gdecErr" arraysize="1" datatype="float" unit="arcsec" default="NA">
+        <DESCRIPTION>declination error</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gzp" arraysize="1" datatype="float" unit="magnitude" default="0">
+        <DESCRIPTION>zero point offset</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gexpTime" arraysize="1" datatype="float" unit="seconds" default="-999">
+        <DESCRIPTION>exposure time (informational)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gpsfMajorFWHM" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>PSF width in major axis</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gpsfMinorFWHM" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>PSF width in minor axis</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gpsfTheta" arraysize="1" datatype="float" unit="degrees" default="-999">
+        <DESCRIPTION>PSF orientation angle</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gpsfCore" arraysize="1" datatype="float" unit="degrees" default="-999">
+        <DESCRIPTION>PSF core parameter [k in (1 + kz * z^1.66)]</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gpsfLikelihood" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>PSF likelihood</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gpsfQf" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>PSF coverage factor</DESCRIPTION>
+      </FIELD>
+       <FIELD name="gpsfQfPerfect" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>PSF-weighted fraction of arcsec totally unmasked</DESCRIPTION>
+      </FIELD> 
+      <FIELD name="gpsfChiSq" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>PSF-weighted fraction of arcsec to.</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gmomentXX" arraysize="1" datatype="float" unit="arcsec squared" default="-999">
+        <DESCRIPTION> moment XX</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gmomentXY" arraysize="1" datatype="float" unit="arcsec squared" default="-999">
+        <DESCRIPTION> moment XY</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gmomentYY" arraysize="1" datatype="float" unit="arcsec squared" default="-999">
+        <DESCRIPTION> moment YY</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gmomentR1" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION> moment R1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gmomentRH" arraysize="1" datatype="float" unit="sqrt arcsec" default="-999">
+        <DESCRIPTION> moment RH</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gPSFFlux" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>PSF instrumental flux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gPSFFluxErr" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in instrumental flux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gApFlux" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION> Aperture flux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gApFluxErr" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION> Aperture flux error</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gApFillFac" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Aperture fill factor - redundant with psfQF, keep?</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gKronFlux" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION> Kron flux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gKronFluxErr" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION> Kron flux error</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gKronRad" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION> Kron radius</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gPSFMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>g psf AB magnitude from stack</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gPSFMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>estimated error of g psf AB magnitude from stack</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gApMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>g Aperture AB magnitude from stack</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gApMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>estimated error of g Ap AB magnitude from stack</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gKronMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>g kron AB magnitude from stack</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gKronMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>estimated error of g kron AB magnitude from stack</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gsky" arraysize="1" datatype="float" unit="adu/s/arcsec" default="-999">
+        <DESCRIPTION>PSF sky level at source (adu)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gskyErr" arraysize="1" datatype="float" unit="adu/s/arcsec" default="-999">
+        <DESCRIPTION>estimated error in sky</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ginfoFlag" arraysize="1" datatype="long" unit="dimensionless" default="-999">
+        <DESCRIPTION>indicator of strange propeties</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gnFrames" arraysize="1" datatype="int" unit="dimensionless" default="-999">
+        <DESCRIPTION>number of frames contributing to source</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rippObjID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
         <DESCRIPTION>IPP object identifier</DESCRIPTION>
       </FIELD>
-      <FIELD name="ippDetectID" arraysize="1" datatype="long">
-        <DESCRIPTION>detection ID generated by IPP</DESCRIPTION>
-      </FIELD>
-      <FIELD name="filterID" arraysize="1" datatype="unsignedByte">
-        <DESCRIPTION>filter identifier</DESCRIPTION>
-      </FIELD>
-      <FIELD name="stackTypeID" arraysize="1" datatype="unsignedByte">
-        <DESCRIPTION>stack type identifier</DESCRIPTION>
-      </FIELD>
-      <FIELD name="surveyID" arraysize="1" datatype="unsignedByte">
-        <DESCRIPTION>survey flag identifier</DESCRIPTION>
-      </FIELD>
-      <FIELD name="primaryF" arraysize="1" datatype="unsignedByte">
-        <DESCRIPTION>identifies best stack detection for Stacks overlapping the same region of the sky.</DESCRIPTION>
-      </FIELD>
-      <FIELD name="stackMetaID" arraysize="1" datatype="long">
+      <FIELD name="rippDetectID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>ipp identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rstackDetectID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>ODM detection identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rstackMetaID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
         <DESCRIPTION>stack identifier</DESCRIPTION>
       </FIELD>
-      <FIELD name="skyCellID" arraysize="1" datatype="int">
-        <DESCRIPTION>skycell identifier</DESCRIPTION>
-      </FIELD>
-      <FIELD name="projectionCellID" arraysize="1" datatype="int">
-        <DESCRIPTION>projection cell identifier</DESCRIPTION>
-      </FIELD>
-      <FIELD name="xPos" arraysize="1" datatype="float">
-        <DESCRIPTION>measured x on CCD from PSF fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="yPos" arraysize="1" datatype="float">
-        <DESCRIPTION>measured y on CCD from PSF fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="xPosErr" arraysize="1" datatype="float">
+      <FIELD name="rxPos" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>measured x on skycell from PSF fit</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ryPos" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>measured y on skycell from PSF fit</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rxPosErr" arraysize="1" datatype="float" unit="arcsec" default="-999">
         <DESCRIPTION>estimated error in x</DESCRIPTION>
       </FIELD>
-      <FIELD name="yPosErr" arraysize="1" datatype="float">
+      <FIELD name="ryPosErr" arraysize="1" datatype="float" unit="arcsec" default="-999">
         <DESCRIPTION>estimated error in y</DESCRIPTION>
       </FIELD>
-      <FIELD name="psfFlux" arraysize="1" datatype="float">
+      <FIELD name="rra" arraysize="1" datatype="double" unit="degrees" default="NA">
+        <DESCRIPTION>right ascension</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rdec" arraysize="1" datatype="double" unit="degrees" default="NA">
+        <DESCRIPTION>declination</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rraErr" arraysize="1" datatype="float" unit="arcsec" default="NA">
+        <DESCRIPTION>right ascension error</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rdecErr" arraysize="1" datatype="float" unit="arcsec" default="NA">
+        <DESCRIPTION>declination error</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rzp" arraysize="1" datatype="float" unit="magnitude" default="0">
+        <DESCRIPTION>zero point offset</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rexpTime" arraysize="1" datatype="float" unit="seconds" default="-999">
+        <DESCRIPTION>exposure time (informational)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rpsfMajorFWHM" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>PSF width in major axis</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rpsfMinorFWHM" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>PSF width in minor axis</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rpsfTheta" arraysize="1" datatype="float" unit="degrees" default="-999">
+        <DESCRIPTION>PSF orientation angle</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rpsfCore" arraysize="1" datatype="float" unit="degrees" default="-999">
+        <DESCRIPTION>PSF core parameter [k in (1 + kz * z^1.66)]</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rpsfLikelihood" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>PSF likelihood</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rpsfQf" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>PSF coverage factor</DESCRIPTION>
+      </FIELD>
+       <FIELD name="rpsfQfPerfect" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>PSF-weighted fraction of arcsec totally unmasked</DESCRIPTION>
+      </FIELD> 
+      <FIELD name="rpsfChiSq" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>PSF-weighted fraction of arcsec to.</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rmomentXX" arraysize="1" datatype="float" unit="arcsec squared" default="-999">
+        <DESCRIPTION> moment XX</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rmomentXY" arraysize="1" datatype="float" unit="arcsec squared" default="-999">
+        <DESCRIPTION> moment XY</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rmomentYY" arraysize="1" datatype="float" unit="arcsec squared" default="-999">
+        <DESCRIPTION> moment YY</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rmomentR1" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION> moment R1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rmomentRH" arraysize="1" datatype="float" unit="sqrt arcsec" default="-999">
+        <DESCRIPTION> moment RH</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rPSFFlux" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
         <DESCRIPTION>PSF instrumental flux</DESCRIPTION>
       </FIELD>
-      <FIELD name="psfFluxErr" arraysize="1" datatype="float">
+      <FIELD name="rPSFFluxErr" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
         <DESCRIPTION>estimated error in instrumental flux</DESCRIPTION>
       </FIELD>
-      <FIELD name="peakFlux" arraysize="1" datatype="float">
-        <DESCRIPTION>ratio of peak flux to total flux</DESCRIPTION>
-      </FIELD>
-      <FIELD name="sky" arraysize="1" datatype="float">
+      <FIELD name="rApFlux" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION> Aperture flux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rApFluxErr" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION> Aperture flux error</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rApFillFac" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Aperture fill factor - redundant with psfQF, keep?</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rKronFlux" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION> Kron flux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rKronFluxErr" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION> Kron flux error</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rKronRad" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION> Kron radius</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rPSFMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>psf AB mag from stack</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rPSFMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>estimated error of psf mag from stack</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rApMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>aperture AB mag from stack</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rApMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>estimated error of aperture mag from stack</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rKronMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>kron AB mag from stack</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rKronMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>estimated error of kron mag from stack</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rsky" arraysize="1" datatype="float" unit="adu/s/arcsec" default="-999">
         <DESCRIPTION>PSF sky level at source (adu)</DESCRIPTION>
       </FIELD>
-      <FIELD name="skyErr" arraysize="1" datatype="float">
+      <FIELD name="rskyErr" arraysize="1" datatype="float" unit="adu/s/arcsec" default="-999">
         <DESCRIPTION>estimated error in sky</DESCRIPTION>
       </FIELD>
-      <FIELD name="sgSep" arraysize="1" datatype="float">
-        <DESCRIPTION>star/galaxy separator</DESCRIPTION>
-      </FIELD>
-      <FIELD name="psfWidMajor" arraysize="1" datatype="float">
+      <FIELD name="rinfoFlag" arraysize="1" datatype="long" unit="dimensionless" default="-999">
+        <DESCRIPTION>indicator of strange propeties</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rnFrames" arraysize="1" datatype="int" unit="dimensionless" default="-999">
+        <DESCRIPTION>number of frames contributing to source</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iippObjID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>IPP object identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iippDetectID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>ipp identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="istackDetectID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>ODM detection identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="istackMetaID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>stack identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ixPos" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>measured x on skycell from PSF fit</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iyPos" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>measured y on skycell from PSF fit</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ixPosErr" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>estimated error in x</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iyPosErr" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>estimated error in y</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ira" arraysize="1" datatype="double" unit="degrees" default="NA">
+        <DESCRIPTION>right ascension</DESCRIPTION>
+      </FIELD>
+      <FIELD name="idec" arraysize="1" datatype="double" unit="degrees" default="NA">
+        <DESCRIPTION>declination</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iraErr" arraysize="1" datatype="float" unit="arcsec" default="NA">
+        <DESCRIPTION>right ascension error</DESCRIPTION>
+      </FIELD>
+      <FIELD name="idecErr" arraysize="1" datatype="float" unit="arcsec" default="NA">
+        <DESCRIPTION>declination error</DESCRIPTION>
+      </FIELD>
+      <FIELD name="izp" arraysize="1" datatype="float" unit="magnitude" default="0">
+        <DESCRIPTION>zero point offset</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iexpTime" arraysize="1" datatype="float" unit="seconds" default="-999">
+        <DESCRIPTION>exposure time (informational)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ipsfMajorFWHM" arraysize="1" datatype="float" unit="arcsec" default="-999">
         <DESCRIPTION>PSF width in major axis</DESCRIPTION>
       </FIELD>
-      <FIELD name="psfWidMinor" arraysize="1" datatype="float">
+      <FIELD name="ipsfMinorFWHM" arraysize="1" datatype="float" unit="arcsec" default="-999">
         <DESCRIPTION>PSF width in minor axis</DESCRIPTION>
       </FIELD>
-      <FIELD name="psfTheta" arraysize="1" datatype="float">
+      <FIELD name="ipsfTheta" arraysize="1" datatype="float" unit="degrees" default="-999">
         <DESCRIPTION>PSF orientation angle</DESCRIPTION>
       </FIELD>
-      <FIELD name="psfLikelihood" arraysize="1" datatype="float">
+      <FIELD name="ipsfCore" arraysize="1" datatype="float" unit="degrees" default="-999">
+        <DESCRIPTION>PSF core parameter [k in (1 + kz * z^1.66)]</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ipsfLikelihood" arraysize="1" datatype="float" unit="dimensionless" default="-999">
         <DESCRIPTION>PSF likelihood</DESCRIPTION>
       </FIELD>
-      <FIELD name="psfQf" arraysize="1" datatype="float">
-        <DESCRIPTION>PSF Q factor</DESCRIPTION>
-      </FIELD>
-       <FIELD name="psfQfPerfect" arraysize="1" datatype="float">
-        <DESCRIPTION>PSF QF Perfect</DESCRIPTION>
+      <FIELD name="ipsfQf" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>PSF coverage factor</DESCRIPTION>
+      </FIELD>
+       <FIELD name="ipsfQfPerfect" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>PSF-weighted fraction of arcsec totally unmasked</DESCRIPTION>
       </FIELD> 
-      <FIELD name="psfChiSq" arraysize="1" datatype="float">
-        <DESCRIPTION> psf chi sq</DESCRIPTION>
-      </FIELD>
-      <FIELD name="momentXX" arraysize="1" datatype="float">
-        <DESCRIPTION> moment XX (unit = arcsec)</DESCRIPTION>
-      </FIELD>
-      <FIELD name="momentXY" arraysize="1" datatype="float">
-        <DESCRIPTION> moment XY (unit = arcsec)</DESCRIPTION>
-      </FIELD>
-      <FIELD name="momentYY" arraysize="1" datatype="float">
-        <DESCRIPTION> moment YY (unit = arcsec)</DESCRIPTION>
-      </FIELD>
-      <FIELD name="momentM3C" arraysize="1" datatype="float">
-        <DESCRIPTION> moment M3C (unit = arcsec)</DESCRIPTION>
-      </FIELD>
-      <FIELD name="momentM3S" arraysize="1" datatype="float">
-        <DESCRIPTION> moment M3S (unit = arcsec)</DESCRIPTION>
-      </FIELD>
-      <FIELD name="momentM4C" arraysize="1" datatype="float">
-        <DESCRIPTION> moment M4C (unit = arcsec)</DESCRIPTION>
-      </FIELD>
-      <FIELD name="momentM4S" arraysize="1" datatype="float">
-        <DESCRIPTION> moment M4S (unit = arcsec)</DESCRIPTION>
-      </FIELD>
-      <FIELD name="momentR1" arraysize="1" datatype="float">
-        <DESCRIPTION> moment R1 (unit = arcsec)</DESCRIPTION>
-      </FIELD>
-      <FIELD name="momentRH" arraysize="1" datatype="float">
-        <DESCRIPTION> moment RH (unit = arcsec)</DESCRIPTION>
-      </FIELD>
-      <FIELD name="apFlux" arraysize="1" datatype="float">
-        <DESCRIPTION> Aperture flux (unit = adu/s)</DESCRIPTION>
-      </FIELD>
-      <FIELD name="apFluxErr" arraysize="1" datatype="float">
-        <DESCRIPTION> Aperture flux error (unit = adu/s)</DESCRIPTION>
-      </FIELD>
-      <FIELD name="kronFlux" arraysize="1" datatype="float">
-        <DESCRIPTION> Kron flux (unit = adu/s)</DESCRIPTION>
-      </FIELD>
-      <FIELD name="kronFluxErr" arraysize="1" datatype="float">
-        <DESCRIPTION> Kron flux error (unit = adu/s)</DESCRIPTION>
-      </FIELD>
-      <FIELD name="kronRad" arraysize="1" datatype="float">
-        <DESCRIPTION> Kron radius (unit = arcsecs)</DESCRIPTION>
-      </FIELD>
-      <FIELD name="infoFlag" arraysize="1" datatype="long">
+      <FIELD name="ipsfChiSq" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>PSF-weighted fraction of arcsec to.</DESCRIPTION>
+      </FIELD>
+      <FIELD name="imomentXX" arraysize="1" datatype="float" unit="arcsec squared" default="-999">
+        <DESCRIPTION> moment XX</DESCRIPTION>
+      </FIELD>
+      <FIELD name="imomentXY" arraysize="1" datatype="float" unit="arcsec squared" default="-999">
+        <DESCRIPTION> moment XY</DESCRIPTION>
+      </FIELD>
+      <FIELD name="imomentYY" arraysize="1" datatype="float" unit="arcsec squared" default="-999">
+        <DESCRIPTION> moment YY</DESCRIPTION>
+      </FIELD>
+      <FIELD name="imomentR1" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION> moment R1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="imomentRH" arraysize="1" datatype="float" unit="sqrt arcsec" default="-999">
+        <DESCRIPTION> moment RH</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iPSFFlux" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>PSF instrumental flux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iPSFFluxErr" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in instrumental flux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iApFlux" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION> Aperture flux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iApFluxErr" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION> Aperture flux error</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iApFillFac" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Aperture fill factor - redundant with psfQF, keep?</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iKronFlux" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION> Kron flux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iKronFluxErr" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION> Kron flux error</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iKronRad" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION> Kron radius</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iPSFMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>psf AB mag from stack</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iPSFMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>estimated error of psf mag from stack</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iApMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>aperture AB mag from stack</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iApMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>estimated error of aperture mag from stack</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iKronMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>kron AB mag from stack</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iKronMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>estimated error of kron mag from stack</DESCRIPTION>
+      </FIELD>
+      <FIELD name="isky" arraysize="1" datatype="float" unit="adu/s/arcsec" default="-999">
+        <DESCRIPTION>PSF sky level at source (adu)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iskyErr" arraysize="1" datatype="float" unit="adu/s/arcsec" default="-999">
+        <DESCRIPTION>estimated error in sky</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iinfoFlag" arraysize="1" datatype="long" unit="dimensionless" default="-999">
         <DESCRIPTION>indicator of strange propeties</DESCRIPTION>
       </FIELD>
-      <FIELD name="nFrames" arraysize="1" datatype="int">
+      <FIELD name="inFrames" arraysize="1" datatype="int" unit="dimensionless" default="-999">
         <DESCRIPTION>number of frames contributing to source</DESCRIPTION>
       </FIELD>
-      <FIELD name="activeFlag" arraysize="1" datatype="unsignedByte">
-        <DESCRIPTION>indicates whether this detection/orphan is still a detection/orphan</DESCRIPTION>
-      </FIELD>
-      <FIELD name="assocDate" arraysize="100" datatype="char">
-        <DESCRIPTION>date object association assigned</DESCRIPTION>
-      </FIELD>
-      <FIELD name="historyModNum" arraysize="1" datatype="short">
-        <DESCRIPTION>modification number in the O-D association history</DESCRIPTION>
-      </FIELD>
-      <FIELD name="dataRelease" arraysize="1" datatype="unsignedByte">
-        <DESCRIPTION>Data release when this detection was originally taken.</DESCRIPTION>
-      </FIELD>
+      <FIELD name="zippObjID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>IPP object identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zippDetectID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>ipp identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zstackDetectID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>ODM detection identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zstackMetaID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>stack identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zxPos" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>measured x on skycell from PSF fit</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zyPos" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>measured y on skycell from PSF fit</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zxPosErr" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>estimated error in x</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zyPosErr" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>estimated error in y</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zra" arraysize="1" datatype="double" unit="degrees" default="NA">
+        <DESCRIPTION>right ascension</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zdec" arraysize="1" datatype="double" unit="degrees" default="NA">
+        <DESCRIPTION>declination</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zraErr" arraysize="1" datatype="float" unit="arcsec" default="NA">
+        <DESCRIPTION>right ascension error</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zdecErr" arraysize="1" datatype="float" unit="arcsec" default="NA">
+        <DESCRIPTION>declination error</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zzp" arraysize="1" datatype="float" unit="magnitude" default="0">
+        <DESCRIPTION>zero point offset</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zexpTime" arraysize="1" datatype="float" unit="seconds" default="-999">
+        <DESCRIPTION>exposure time (informational)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zpsfMajorFWHM" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>PSF width in major axis</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zpsfMinorFWHM" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>PSF width in minor axis</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zpsfTheta" arraysize="1" datatype="float" unit="degrees" default="-999">
+        <DESCRIPTION>PSF orientation angle</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zpsfCore" arraysize="1" datatype="float" unit="degrees" default="-999">
+        <DESCRIPTION>PSF core parameter [k in (1 + kz * z^1.66)]</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zpsfLikelihood" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>PSF likelihood</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zpsfQf" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>PSF coverage factor</DESCRIPTION>
+      </FIELD>
+       <FIELD name="zpsfQfPerfect" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>PSF-weighted fraction of arcsec totally unmasked</DESCRIPTION>
+      </FIELD> 
+      <FIELD name="zpsfChiSq" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>PSF-weighted fraction of arcsec to.</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zmomentXX" arraysize="1" datatype="float" unit="arcsec squared" default="-999">
+        <DESCRIPTION> moment XX</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zmomentXY" arraysize="1" datatype="float" unit="arcsec squared" default="-999">
+        <DESCRIPTION> moment XY</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zmomentYY" arraysize="1" datatype="float" unit="arcsec squared" default="-999">
+        <DESCRIPTION> moment YY</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zmomentR1" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION> moment R1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zmomentRH" arraysize="1" datatype="float" unit="sqrt arcsec" default="-999">
+        <DESCRIPTION> moment RH</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zPSFFlux" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>PSF instrumental flux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zPSFFluxErr" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in instrumental flux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zApFlux" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION> Aperture flux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zApFluxErr" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION> Aperture flux error</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zApFillFac" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Aperture fill factor - redundant with psfQF, keep?</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zKronFlux" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION> Kron flux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zKronFluxErr" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION> Kron flux error</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zKronRad" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION> Kron radius</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zPSFMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>psf AB mag from stack</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zPSFMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>estimated error of psf mag from stack</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zApMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>aperture AB mag from stack</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zApMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>estimated error of aperture mag from stack</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zKronMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>kron AB mag from stack</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zKronMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>estimated error of kron mag from stack</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zsky" arraysize="1" datatype="float" unit="adu/s/arcsec" default="-999">
+        <DESCRIPTION>PSF sky level at source (adu)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zskyErr" arraysize="1" datatype="float" unit="adu/s/arcsec" default="-999">
+        <DESCRIPTION>estimated error in sky</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zinfoFlag" arraysize="1" datatype="long" unit="dimensionless" default="-999">
+        <DESCRIPTION>indicator of strange propeties</DESCRIPTION>
+      </FIELD>
+      <FIELD name="znFrames" arraysize="1" datatype="int" unit="dimensionless" default="-999">
+        <DESCRIPTION>number of frames contributing to source</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yippObjID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>IPP object identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yippDetectID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>ipp identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ystackDetectID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>ODM detection identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ystackMetaID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>stack identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yxPos" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>measured x on skycell from PSF fit</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yyPos" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>measured y on skycell from PSF fit</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yxPosErr" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>estimated error in x</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yyPosErr" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>estimated error in y</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yra" arraysize="1" datatype="double" unit="degrees" default="NA">
+        <DESCRIPTION>right ascension</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ydec" arraysize="1" datatype="double" unit="degrees" default="NA">
+        <DESCRIPTION>declination</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yraErr" arraysize="1" datatype="float" unit="arcsec" default="NA">
+        <DESCRIPTION>right ascension error</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ydecErr" arraysize="1" datatype="float" unit="arcsec" default="NA">
+        <DESCRIPTION>declination error</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yzp" arraysize="1" datatype="float" unit="magnitude" default="0">
+        <DESCRIPTION>zero point offset</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yexpTime" arraysize="1" datatype="float" unit="seconds" default="-999">
+        <DESCRIPTION>exposure time (informational)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ypsfMajorFWHM" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>PSF width in major axis</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ypsfMinorFWHM" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>PSF width in minor axis</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ypsfTheta" arraysize="1" datatype="float" unit="degrees" default="-999">
+        <DESCRIPTION>PSF orientation angle</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ypsfCore" arraysize="1" datatype="float" unit="degrees" default="-999">
+        <DESCRIPTION>PSF core parameter [k in (1 + kz * z^1.66)]</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ypsfLikelihood" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>PSF likelihood</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ypsfQf" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>PSF coverage factor</DESCRIPTION>
+      </FIELD>
+       <FIELD name="ypsfQfPerfect" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>PSF-weighted fraction of arcsec totally unmasked</DESCRIPTION>
+      </FIELD> 
+      <FIELD name="ypsfChiSq" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>PSF-weighted fraction of arcsec to.</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ymomentXX" arraysize="1" datatype="float" unit="arcsec squared" default="-999">
+        <DESCRIPTION> moment XX</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ymomentXY" arraysize="1" datatype="float" unit="arcsec squared" default="-999">
+        <DESCRIPTION> moment XY</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ymomentYY" arraysize="1" datatype="float" unit="arcsec squared" default="-999">
+        <DESCRIPTION> moment YY</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ymomentR1" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION> moment R1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ymomentRH" arraysize="1" datatype="float" unit="sqrt arcsec" default="-999">
+        <DESCRIPTION> moment RH</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yPSFFlux" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>PSF instrumental flux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yPSFFluxErr" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in instrumental flux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yApFlux" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION> Aperture flux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yApFluxErr" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION> Aperture flux error</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yApFillFac" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Aperture fill factor - redundant with psfQF, keep?</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yKronFlux" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION> Kron flux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yKronFluxErr" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION> Kron flux error</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yKronRad" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION> Kron radius</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yPSFMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>psf AB mag from stack</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yPSFMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>estimated error of psf mag from stack</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yApMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>aperture AB mag from stack</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yApMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>estimated error of aperture mag from stack</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yKronMag" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>kron AB mag from stack</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yKronMagErr" arraysize="1" datatype="float" unit="AB magnitude" default="-999">
+        <DESCRIPTION>estimated error of kron mag from stack</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ysky" arraysize="1" datatype="float" unit="adu/s/arcsec" default="-999">
+        <DESCRIPTION>PSF sky level at source (adu)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yskyErr" arraysize="1" datatype="float" unit="adu/s/arcsec" default="-999">
+        <DESCRIPTION>estimated error in sky</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yinfoFlag" arraysize="1" datatype="long" unit="dimensionless" default="-999">
+        <DESCRIPTION>indicator of strange propeties</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ynFrames" arraysize="1" datatype="int" unit="dimensionless" default="-999">
+        <DESCRIPTION>number of frames contributing to source</DESCRIPTION>
+      </FIELD>      
       <DATA>
         <TABLEDATA></TABLEDATA>
@@ -269,462 +830,633 @@
       <DESCRIPTION>VOTable description of PSPS table StackApFlx</DESCRIPTION>
       <PARAM arraysize="1" datatype="char" ucd="meta.bib.author" name="Author" value="PSPS"></PARAM>
-      <FIELD name="objID" arraysize="1" datatype="long">
+      <FIELD name="objID" arraysize="1" datatype="long" unit="dimensionless"  default="NA">
         <DESCRIPTION>ODM object identifier</DESCRIPTION>
       </FIELD>
-      <FIELD name="stackDetectID" arraysize="1" datatype="long">
+      <FIELD name="gcobjID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>galactic coordinates ODM object identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="surveyID" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="0">
+        <DESCRIPTION>survey flag identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="skyCellID" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>single float giving PrimaryCell.SkyCell identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="randomStackObjID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+	<DESCRIPTION>random stack id</DESCRIPTION>
+      </FIELD>
+      <FIELD name="stackDetectRowID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+	<DESCRIPTION>identifies which of up to 5 possible stackdetections thisrow refers to: primary, up to 3 Secondary, 1 best</DESCRIPTION>
+      </FIELD>
+      <FIELD name="primaryDetection" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="255">
+        <DESCRIPTION>identifies if this row is a primary stack detection. True about 80 percent of time</DESCRIPTION>
+      </FIELD>
+      <FIELD name="bestDetection" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="255">
+        <DESCRIPTION>identifies if this row is a best detection or not. Also set if only a primary detection exists.</DESCRIPTION>
+      </FIELD>
+      <FIELD name="dvoRegionID" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>identifier to dvo spatial region</DESCRIPTION>
+      </FIELD>
+      <FIELD name="dataRelease" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="NA">
+        <DESCRIPTION>Data release when this table was loaded.</DESCRIPTION>
+      </FIELD> 
+      <FIELD name="gstackDetectID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
         <DESCRIPTION>ODM detection identifier</DESCRIPTION>
       </FIELD>
-      <FIELD name="ippObjID" arraysize="1" datatype="long">
+      <FIELD name="gstackMetaID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>stack identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gippObjID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
         <DESCRIPTION>IPP object identifier</DESCRIPTION>
       </FIELD>
-      <FIELD name="ippDetectID" arraysize="1" datatype="long">
-        <DESCRIPTION>detection ID generated by IPP</DESCRIPTION>
-      </FIELD>
-      <FIELD name="filterID" arraysize="1" datatype="unsignedByte">
-        <DESCRIPTION>filter identifier</DESCRIPTION>
-      </FIELD>
-      <FIELD name="stackTypeID" arraysize="1" datatype="unsignedByte">
-        <DESCRIPTION>stack type identifier</DESCRIPTION>
-      </FIELD>
-      <FIELD name="surveyID" arraysize="1" datatype="unsignedByte">
-        <DESCRIPTION>survey flag identifier</DESCRIPTION>
-      </FIELD>
-      <FIELD name="primaryF" arraysize="1" datatype="unsignedByte">
-        <DESCRIPTION>identifies best stack detection for Stacks overlapping the same region of the sky.</DESCRIPTION>
-      </FIELD>
-      <FIELD name="stackMetaID" arraysize="1" datatype="long">
+      <FIELD name="gippDetectID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>ipp identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR3" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR3Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR3Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR3Fill" arraysize="1" datatype="float"  unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR4" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR4Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR4Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR4Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR5" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR5Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is gflxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR5Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in gflxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR5Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR3" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR3Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR3Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR3Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR4" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR4Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR4Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR4Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR5" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR5Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR5Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR5Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR3" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR3Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in c2flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR3Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR3Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR4" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR4Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in c2flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR4Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR4Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR5" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR5Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in c2flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR5Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR5Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rstackDetectID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>ODM detection identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rstackMetaID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
         <DESCRIPTION>stack identifier</DESCRIPTION>
       </FIELD>
-      <FIELD name="isophotFlux" arraysize="1" datatype="float">
-        <DESCRIPTION>isophotal flux</DESCRIPTION>
-      </FIELD>
-      <FIELD name="isophotFluxErr" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated error in isophotal flux</DESCRIPTION>
-      </FIELD>
-      <FIELD name="isophotMajAxis" arraysize="1" datatype="float">
-        <DESCRIPTION>isophotal Major Axis</DESCRIPTION>
-      </FIELD>
-      <FIELD name="isophotMajAxisErr" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated error in isophotal Major Axis</DESCRIPTION>
-      </FIELD>
-      <FIELD name="isophotMinAxis" arraysize="1" datatype="float">
-        <DESCRIPTION>isophotal Minor Axis</DESCRIPTION>
-      </FIELD>
-      <FIELD name="isophotMinAxisErr" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated error in isophotal Minor Axis</DESCRIPTION>
-      </FIELD>
-      <FIELD name="isophotMajAxisGrad" arraysize="1" datatype="float">
-        <DESCRIPTION>isophotal major axis gradient</DESCRIPTION>
-      </FIELD>
-      <FIELD name="isophotMinAxisGrad" arraysize="1" datatype="float">
-        <DESCRIPTION>isophotal minor axis gradient</DESCRIPTION>
-      </FIELD>
-      <FIELD name="isophotPA" arraysize="1" datatype="float">
-        <DESCRIPTION>isophotal position angle</DESCRIPTION>
-      </FIELD>
-      <FIELD name="isophotPAErr" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated error in isophotal position angle</DESCRIPTION>
-      </FIELD>
-      <FIELD name="isophotPAGrad" arraysize="1" datatype="float">
-        <DESCRIPTION>isophotal position angle gradient</DESCRIPTION>
-      </FIELD>
-      <FIELD name="petRadius" arraysize="1" datatype="float">
-        <DESCRIPTION>Petrosian radius</DESCRIPTION>
-      </FIELD>
-      <FIELD name="petRadiusErr" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated error inPetrosian radius</DESCRIPTION>
-      </FIELD>
-      <FIELD name="petFlux" arraysize="1" datatype="float">
-        <DESCRIPTION>Petrosian Flux</DESCRIPTION>
-      </FIELD>
-      <FIELD name="petFluxErr" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated error in petFlux</DESCRIPTION>
-      </FIELD>
-      <FIELD name="petR50" arraysize="1" datatype="float">
-        <DESCRIPTION>Petrosian radius at 50% light</DESCRIPTION>
-      </FIELD>
-      <FIELD name="petR50Err" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated error inPetrosian radius at 50% light</DESCRIPTION>
-      </FIELD>
-      <FIELD name="petR90" arraysize="1" datatype="float">
-        <DESCRIPTION>Petrosian radius at 90% light</DESCRIPTION>
-      </FIELD>
-      <FIELD name="petR90Err" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated error in Petrosian radius at 90% light</DESCRIPTION>
-      </FIELD>
-      <FIELD name="petCf" arraysize="1" datatype="float">
-        <DESCRIPTION>Petrosian fit coverage factor</DESCRIPTION>
-      </FIELD>
-      <FIELD name="flxR1" arraysize="1" datatype="float">
-        <DESCRIPTION>Flux inside r = 1</DESCRIPTION>
-      </FIELD>
-      <FIELD name="flxR1Err" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated error is flxR1</DESCRIPTION>
-      </FIELD>
-      <FIELD name="flxR1Std" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated standard deviation in flxR1</DESCRIPTION>
-      </FIELD>
-      <FIELD name="flxR1Fill" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated filling factor at R1</DESCRIPTION>
-      </FIELD>
-      <FIELD name="flxR2" arraysize="1" datatype="float">
-        <DESCRIPTION>Flux inside r = 2</DESCRIPTION>
-      </FIELD>
-      <FIELD name="flxR2Err" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated error is flxR2</DESCRIPTION>
-      </FIELD>
-      <FIELD name="flxR2Std" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated standard deviation in flxR2</DESCRIPTION>
-      </FIELD>
-      <FIELD name="flxR2Fill" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated filling factor at R1</DESCRIPTION>
-      </FIELD>
-      <FIELD name="flxR3" arraysize="1" datatype="float">
+      <FIELD name="rippObjID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>IPP object identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rippDetectID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>ipp identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR3" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
         <DESCRIPTION>Flux inside r = 3</DESCRIPTION>
       </FIELD>
-      <FIELD name="flxR3Err" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated error is flxR3</DESCRIPTION>
-      </FIELD>
-      <FIELD name="flxR3Std" arraysize="1" datatype="float">
+      <FIELD name="rflxR3Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR3Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
         <DESCRIPTION>estimated standard deviation in flxR3</DESCRIPTION>
       </FIELD>
-      <FIELD name="flxR3Fill" arraysize="1" datatype="float">
+      <FIELD name="rflxR3Fill" arraysize="1" datatype="float"  unit="dimensionless" default="-999">
         <DESCRIPTION>estimated filling factor at R3</DESCRIPTION>
       </FIELD>
-      <FIELD name="flxR4" arraysize="1" datatype="float">
+      <FIELD name="rflxR4" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
         <DESCRIPTION>Flux inside r = 4</DESCRIPTION>
       </FIELD>
-      <FIELD name="flxR4Err" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated error is flxR4</DESCRIPTION>
-      </FIELD>
-      <FIELD name="flxR4Std" arraysize="1" datatype="float">
+      <FIELD name="rflxR4Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR4Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
         <DESCRIPTION>estimated standard deviation in flxR4</DESCRIPTION>
       </FIELD>
-      <FIELD name="flxR4Fill" arraysize="1" datatype="float">
+      <FIELD name="rflxR4Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
         <DESCRIPTION>estimated filling factor at R4</DESCRIPTION>
       </FIELD>
-      <FIELD name="flxR5" arraysize="1" datatype="float">
+      <FIELD name="rflxR5" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
         <DESCRIPTION>Flux inside r = 5</DESCRIPTION>
       </FIELD>
-      <FIELD name="flxR5Err" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated error is flxR5</DESCRIPTION>
-      </FIELD>
-      <FIELD name="flxR5Std" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated standard deviation in flxR5</DESCRIPTION>
-      </FIELD>
-      <FIELD name="flxR5Fill" arraysize="1" datatype="float">
+      <FIELD name="rflxR5Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is gflxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR5Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in gflxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR5Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
         <DESCRIPTION>estimated filling factor at R5</DESCRIPTION>
       </FIELD>
-      <FIELD name="flxR6" arraysize="1" datatype="float">
-        <DESCRIPTION>Flux inside r = 6</DESCRIPTION>
-      </FIELD>
-      <FIELD name="flxR6Err" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated error is flxR6</DESCRIPTION>
-      </FIELD>
-      <FIELD name="flxR6Std" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated standard deviation in flxR6</DESCRIPTION>
-      </FIELD>
-      <FIELD name="flxR6Fill" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated filling factor at R6</DESCRIPTION>
-      </FIELD>
-      <FIELD name="flxR7" arraysize="1" datatype="float">
-        <DESCRIPTION>Flux inside r = 7</DESCRIPTION>
-      </FIELD>
-      <FIELD name="flxR7Err" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated error is flxR7</DESCRIPTION>
-      </FIELD>
-      <FIELD name="flxR7Std" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated standard deviation in flxR7</DESCRIPTION>
-      </FIELD>
-      <FIELD name="flxR7Fill" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated filling factor at R7</DESCRIPTION>
-      </FIELD>
-      <FIELD name="flxR8" arraysize="1" datatype="float">
-        <DESCRIPTION>Flux inside r = 8</DESCRIPTION>
-      </FIELD>
-      <FIELD name="flxR8Err" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated error is flxR8</DESCRIPTION>
-      </FIELD>
-      <FIELD name="flxR8Std" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated standard deviation in flxR8</DESCRIPTION>
-      </FIELD>
-      <FIELD name="flxR8Fill" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated filling factor at R8</DESCRIPTION>
-      </FIELD>
-      <FIELD name="flxR9" arraysize="1" datatype="float">
-        <DESCRIPTION>Flux inside r = 9</DESCRIPTION>
-      </FIELD>
-      <FIELD name="flxR9Err" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated error is flxR9</DESCRIPTION>
-      </FIELD>
-      <FIELD name="flxR9Std" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated standard deviation in flxR9</DESCRIPTION>
-      </FIELD>
-      <FIELD name="flxR9Fill" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated filling factor at R9</DESCRIPTION>
-      </FIELD>
-      <FIELD name="flxR10" arraysize="1" datatype="float">
-        <DESCRIPTION>Flux inside r = 10</DESCRIPTION>
-      </FIELD>
-      <FIELD name="flxR10Err" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated error is flxR10</DESCRIPTION>
-      </FIELD>
-      <FIELD name="flxR10Std" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated standard deviation in flxR10</DESCRIPTION>
-      </FIELD>
-      <FIELD name="flxR10Fill" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated filling factor at R10</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c1flxR1" arraysize="1" datatype="float">
-        <DESCRIPTION>Flux inside r = 1</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c1flxR1Err" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated error is c1flxR1</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c1flxR1Std" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated standard deviation in c1flxR1</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c1flxR1Fill" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated filling factor at R1</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c1flxR2" arraysize="1" datatype="float">
-        <DESCRIPTION>Flux inside r = 2</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c1flxR2Err" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated error is c1flxR2</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c1flxR2Std" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated standard deviation in c1flxR2</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c1flxR2Fill" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated filling factor at R1</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c1flxR3" arraysize="1" datatype="float">
+      <FIELD name="rc1flxR3" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
         <DESCRIPTION>Flux inside r = 3</DESCRIPTION>
       </FIELD>
-      <FIELD name="c1flxR3Err" arraysize="1" datatype="float">
+      <FIELD name="rc1flxR3Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
         <DESCRIPTION>estimated error is c1flxR3</DESCRIPTION>
       </FIELD>
-      <FIELD name="c1flxR3Std" arraysize="1" datatype="float">
+      <FIELD name="rc1flxR3Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
         <DESCRIPTION>estimated standard deviation in c1flxR3</DESCRIPTION>
       </FIELD>
-      <FIELD name="c1flxR3Fill" arraysize="1" datatype="float">
+      <FIELD name="rc1flxR3Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
         <DESCRIPTION>estimated filling factor at R3</DESCRIPTION>
       </FIELD>
-      <FIELD name="c1flxR4" arraysize="1" datatype="float">
+      <FIELD name="rc1flxR4" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
         <DESCRIPTION>Flux inside r = 4</DESCRIPTION>
       </FIELD>
-      <FIELD name="c1flxR4Err" arraysize="1" datatype="float">
+      <FIELD name="rc1flxR4Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
         <DESCRIPTION>estimated error is c1flxR4</DESCRIPTION>
       </FIELD>
-      <FIELD name="c1flxR4Std" arraysize="1" datatype="float">
+      <FIELD name="rc1flxR4Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
         <DESCRIPTION>estimated standard deviation in c1flxR4</DESCRIPTION>
       </FIELD>
-      <FIELD name="c1flxR4Fill" arraysize="1" datatype="float">
+      <FIELD name="rc1flxR4Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
         <DESCRIPTION>estimated filling factor at R4</DESCRIPTION>
       </FIELD>
-      <FIELD name="c1flxR5" arraysize="1" datatype="float">
+      <FIELD name="rc1flxR5" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
         <DESCRIPTION>Flux inside r = 5</DESCRIPTION>
       </FIELD>
-      <FIELD name="c1flxR5Err" arraysize="1" datatype="float">
+      <FIELD name="rc1flxR5Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
         <DESCRIPTION>estimated error is c1flxR5</DESCRIPTION>
       </FIELD>
-      <FIELD name="c1flxR5Std" arraysize="1" datatype="float">
+      <FIELD name="rc1flxR5Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
         <DESCRIPTION>estimated standard deviation in c1flxR5</DESCRIPTION>
       </FIELD>
-      <FIELD name="c1flxR5Fill" arraysize="1" datatype="float">
+      <FIELD name="rc1flxR5Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
         <DESCRIPTION>estimated filling factor at R5</DESCRIPTION>
       </FIELD>
-      <FIELD name="c1flxR6" arraysize="1" datatype="float">
-        <DESCRIPTION>Flux inside r = 6</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c1flxR6Err" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated error is c1flxR6</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c1flxR6Std" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated standard deviation in c1flxR6</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c1flxR6Fill" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated filling factor at R6</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c1flxR7" arraysize="1" datatype="float">
-        <DESCRIPTION>Flux inside r = 7</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c1flxR7Err" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated error is c1flxR7</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c1flxR7Std" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated standard deviation in c1flxR7</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c1flxR7Fill" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated filling factor at R7</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c1flxR8" arraysize="1" datatype="float">
-        <DESCRIPTION>Flux inside r = 8</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c1flxR8Err" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated error is c1flxR8</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c1flxR8Std" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated standard deviation in c1flxR8</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c1flxR8Fill" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated filling factor at R8</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c1flxR9" arraysize="1" datatype="float">
-        <DESCRIPTION>Flux inside r = 9</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c1flxR9Err" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated error is c1flxR9</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c1flxR9Std" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated standard deviation in c1flxR9</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c1flxR9Fill" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated filling factor at R9</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c1flxR10" arraysize="1" datatype="float">
-        <DESCRIPTION>Flux inside r = 10</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c1flxR10Err" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated error is c1flxR10</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c1flxR10Std" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated standard deviation in c1flxR10</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c1flxR10Fill" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated filling factor at R10</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c2flxR1" arraysize="1" datatype="float">
-        <DESCRIPTION>Flux inside r = 1</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c2flxR1Err" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated error is c2flxR1</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c2flxR1Std" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated standard deviation in c2flxR1</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c2flxR1Fill" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated filling factor at R1</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c2flxR2" arraysize="1" datatype="float">
-        <DESCRIPTION>Flux inside r = 2</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c2flxR2Err" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated error is c2flxR2</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c2flxR2Std" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated standard deviation in c2flxR2</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c2flxR2Fill" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated filling factor at R1</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c2flxR3" arraysize="1" datatype="float">
+      <FIELD name="rc2flxR3" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
         <DESCRIPTION>Flux inside r = 3</DESCRIPTION>
       </FIELD>
-      <FIELD name="c2flxR3Err" arraysize="1" datatype="float">
+      <FIELD name="rc2flxR3Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
         <DESCRIPTION>estimated error is c2flxR3</DESCRIPTION>
       </FIELD>
-      <FIELD name="c2flxR3Std" arraysize="1" datatype="float">
+      <FIELD name="rc2flxR3Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
         <DESCRIPTION>estimated standard deviation in c2flxR3</DESCRIPTION>
       </FIELD>
-      <FIELD name="c2flxR3Fill" arraysize="1" datatype="float">
+      <FIELD name="rc2flxR3Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
         <DESCRIPTION>estimated filling factor at R3</DESCRIPTION>
       </FIELD>
-      <FIELD name="c2flxR4" arraysize="1" datatype="float">
+      <FIELD name="rc2flxR4" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
         <DESCRIPTION>Flux inside r = 4</DESCRIPTION>
       </FIELD>
-      <FIELD name="c2flxR4Err" arraysize="1" datatype="float">
+      <FIELD name="rc2flxR4Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
         <DESCRIPTION>estimated error is c2flxR4</DESCRIPTION>
       </FIELD>
-      <FIELD name="c2flxR4Std" arraysize="1" datatype="float">
+      <FIELD name="rc2flxR4Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
         <DESCRIPTION>estimated standard deviation in c2flxR4</DESCRIPTION>
       </FIELD>
-      <FIELD name="c2flxR4Fill" arraysize="1" datatype="float">
+      <FIELD name="rc2flxR4Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
         <DESCRIPTION>estimated filling factor at R4</DESCRIPTION>
       </FIELD>
-      <FIELD name="c2flxR5" arraysize="1" datatype="float">
+      <FIELD name="rc2flxR5" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
         <DESCRIPTION>Flux inside r = 5</DESCRIPTION>
       </FIELD>
-      <FIELD name="c2flxR5Err" arraysize="1" datatype="float">
+      <FIELD name="rc2flxR5Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
         <DESCRIPTION>estimated error is c2flxR5</DESCRIPTION>
       </FIELD>
-      <FIELD name="c2flxR5Std" arraysize="1" datatype="float">
+      <FIELD name="rc2flxR5Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
         <DESCRIPTION>estimated standard deviation in c2flxR5</DESCRIPTION>
       </FIELD>
-      <FIELD name="c2flxR5Fill" arraysize="1" datatype="float">
+      <FIELD name="rc2flxR5Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
         <DESCRIPTION>estimated filling factor at R5</DESCRIPTION>
       </FIELD>
-      <FIELD name="c2flxR6" arraysize="1" datatype="float">
-        <DESCRIPTION>Flux inside r = 6</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c2flxR6Err" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated error is c2flxR6</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c2flxR6Std" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated standard deviation in c2flxR6</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c2flxR6Fill" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated filling factor at R6</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c2flxR7" arraysize="1" datatype="float">
-        <DESCRIPTION>Flux inside r = 7</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c2flxR7Err" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated error is c2flxR7</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c2flxR7Std" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated standard deviation in c2flxR7</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c2flxR7Fill" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated filling factor at R7</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c2flxR8" arraysize="1" datatype="float">
-        <DESCRIPTION>Flux inside r = 8</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c2flxR8Err" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated error is c2flxR8</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c2flxR8Std" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated standard deviation in c2flxR8</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c2flxR8Fill" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated filling factor at R8</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c2flxR9" arraysize="1" datatype="float">
-        <DESCRIPTION>Flux inside r = 9</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c2flxR9Err" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated error is c2flxR9</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c2flxR9Std" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated standard deviation in c2flxR9</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c2flxR9Fill" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated filling factor at R9</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c2flxR10" arraysize="1" datatype="float">
-        <DESCRIPTION>Flux inside r = 10</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c2flxR10Err" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated error is c2flxR10</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c2flxR10Std" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated standard deviation in c2flxR10</DESCRIPTION>
-      </FIELD>
-      <FIELD name="c2flxR10Fill" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated filling factor at R10</DESCRIPTION>
-      </FIELD>
-      <FIELD name="logC" arraysize="1" datatype="float">
-        <DESCRIPTION>Abraham concentration index</DESCRIPTION>
-      </FIELD>
-      <FIELD name="logA" arraysize="1" datatype="float">
-        <DESCRIPTION>Abraham asymmetry index</DESCRIPTION>
-      </FIELD>
-      <FIELD name="activeFlag" arraysize="1" datatype="unsignedByte">
-        <DESCRIPTION>indicates whether this detection/orphan is still a detection/orphan</DESCRIPTION>
-      </FIELD>
-      <FIELD name="dataRelease" arraysize="1" datatype="unsignedByte">
-        <DESCRIPTION>Data release when this detection was taken</DESCRIPTION>
+      <FIELD name="istackDetectID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>ODM detection identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="istackMetaID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>stack identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iippObjID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>IPP object identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iippDetectID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>ipp identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR3" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR3Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR3Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR3Fill" arraysize="1" datatype="float"  unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR4" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR4Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR4Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR4Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR5" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR5Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is gflxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR5Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in gflxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR5Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR3" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR3Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR3Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR3Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR4" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR4Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR4Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR4Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR5" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR5Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR5Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR5Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR3" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR3Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR3Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR3Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR4" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR4Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR4Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR4Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR5" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR5Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR5Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR5Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zstackDetectID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>ODM detection identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zstackMetaID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>stack identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zippObjID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>IPP object identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zippDetectID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>ipp identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR3" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR3Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR3Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR3Fill" arraysize="1" datatype="float"  unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR4" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR4Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR4Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR4Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR5" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR5Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is gflxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR5Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in gflxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR5Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR3" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR3Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR3Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR3Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR4" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR4Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR4Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR4Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR5" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR5Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR5Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR5Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR3" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR3Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR3Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR3Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR4" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR4Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR4Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR4Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR5" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR5Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR5Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR5Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ystackDetectID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>ODM detection identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ystackMetaID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>stack identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yippObjID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>IPP object identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yippDetectID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>ipp identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR3" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR3Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR3Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR3Fill" arraysize="1" datatype="float"  unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR4" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR4Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR4Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR4Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR5" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR5Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is gflxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR5Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in gflxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR5Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR3" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR3Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR3Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR3Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR4" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR4Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR4Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR4Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR5" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR5Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR5Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR5Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR3" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR3Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR3Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR3Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR4" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR4Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR4Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR4Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR5" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR5Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR5Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR5Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R5</DESCRIPTION>
       </FIELD>
       <DATA>
@@ -735,447 +1467,2736 @@
       <DESCRIPTION>VOTable description of PSPS table StackModelFit</DESCRIPTION>
       <PARAM arraysize="1" datatype="char" ucd="meta.bib.author" name="Author" value="PSPS"></PARAM>
-      <FIELD name="objID" arraysize="1" datatype="long">
+      <FIELD name="objID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
         <DESCRIPTION>ODM object identifier</DESCRIPTION>
       </FIELD>
-      <FIELD name="stackDetectID" arraysize="1" datatype="long">
+      <FIELD name="gcobjID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>galactic coordinates ODM object identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="surveyID" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="NA">
+        <DESCRIPTION>survey flag identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="skyCellID" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+	<DESCRIPTION>single float giving PrimaryCell.SkyCell identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="randomStackObjID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+	<DESCRIPTION>random stack id</DESCRIPTION>
+      </FIELD>
+      <FIELD name="stackDetectRowID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+	<DESCRIPTION>identifies which of up to 5 possible stackdetections thisrow refers to: primary, up to 3 Secondary, 1 best</DESCRIPTION>
+      </FIELD>
+      <FIELD name="primaryDetection" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="255">
+        <DESCRIPTION>identifies if this row is a primary stack detection. True about 80 percent of time</DESCRIPTION>
+      </FIELD>
+      <FIELD name="bestDetection" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="255">
+        <DESCRIPTION>identifies if this row is a best detection or not. Also set if only a primary detection exists.</DESCRIPTION>
+      </FIELD>
+      <FIELD name="dvoRegionID" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>identifier to dvo spatial region</DESCRIPTION>
+      </FIELD>
+      <FIELD name="dataRelease" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="NA">
+        <DESCRIPTION>Data release when this table was loaded.</DESCRIPTION>
+      </FIELD>
+      <FIELD name="glogC" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>concentration index</DESCRIPTION>
+      </FIELD>
+      <FIELD name="glogA" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>asymmetry index</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gclump" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>clumpiness factor</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gstackDetectID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
         <DESCRIPTION>ODM detection identifier</DESCRIPTION>
       </FIELD>
-      <FIELD name="ippObjID" arraysize="1" datatype="long">
+      <FIELD name="gstackMetaID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>stack identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gippObjID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
         <DESCRIPTION>IPP object identifier</DESCRIPTION>
       </FIELD>
-      <FIELD name="ippDetectID" arraysize="1" datatype="long">
-        <DESCRIPTION>detection ID generated by IPP</DESCRIPTION>
-      </FIELD>
-      <FIELD name="filterID" arraysize="1" datatype="unsignedByte">
-        <DESCRIPTION>filter identifier</DESCRIPTION>
-      </FIELD>
-      <FIELD name="stackTypeID" arraysize="1" datatype="unsignedByte">
-        <DESCRIPTION>stack type identifier</DESCRIPTION>
-      </FIELD>
-      <FIELD name="surveyID" arraysize="1" datatype="unsignedByte">
-        <DESCRIPTION>survey flag identifier</DESCRIPTION>
-      </FIELD>
-      <FIELD name="primaryF" arraysize="1" datatype="unsignedByte">
-        <DESCRIPTION>identifies best stack detection for Stacks overlapping the same region of the sky.</DESCRIPTION>
-      </FIELD>
-      <FIELD name="stackMetaID" arraysize="1" datatype="long">
+      <FIELD name="gippDetectID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>ipp detect identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gdeVRadius" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>deVaucouleurs radius</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gdeVRadiusErr" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>estimated error in deVaucouleurs radius</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gdeVFlux" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>deVaucouleurs magntiude</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gdeVFluxErr" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in deV_mag</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gdeVAb" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>deVaucoulerus axis ratio</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gdeVAbErr" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated error in deVaucoulerus axis ratio</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gdeVPhi" arraysize="1" datatype="float" unit="degrees" default="-999">
+        <DESCRIPTION>estmated phi of deVaucouleurs axis</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gdeVPhiErr" arraysize="1" datatype="float" unit="degrees" default="-999">
+        <DESCRIPTION>estmated error of phi of deVaucouleurs axis</DESCRIPTION>
+      </FIELD>
+      <FIELD name="graDeVOff" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>Offset in RA of deVaucouleurs fit from PSF RA</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gdecDeVOff" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>Offset in DEC of deVaucouleurs fit from PSF DEC</DESCRIPTION>
+      </FIELD>
+      <FIELD name="graDeVOffErr" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>estimated error in ra offset</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gdecDeVOffErr" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>estimated error in dec offset</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gdeVCf" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>deVaucouleurs fit coverage factor</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gdeVLikelihood" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>deVaucouleurs fit likelihood factor</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gexpRadius" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>Exponential fit radius</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gexpRadiusErr" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>estimated error in Exponential fit radius</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gexpFlux" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Exponential fit flux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gexpFluxErr" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in expFlux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gexpAb" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Exponential fit axis ratio</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gexpAbErr" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated error in Exponential fit axis ratio</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gexpPhi" arraysize="1" datatype="float" unit="degrees" default="-999">
+        <DESCRIPTION>estmated phi of Exponential axis</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gexpPhiErr" arraysize="1" datatype="float" unit="degrees" default="-999">
+        <DESCRIPTION>estmated error of phi of Exponential axis</DESCRIPTION>
+      </FIELD>
+      <FIELD name="graExpOff" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Offset in RA of Exponential fit from PSF RA</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gdecExpOff" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Offset in DEC of Exponential fit from PSF DEC</DESCRIPTION>
+      </FIELD>
+      <FIELD name="graExpOffErr" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated error in raExpOff</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gdecExpOffErr" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated error in decExpOff</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gexpCf" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Exponential fit coverage factor</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gexpLikelihood" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Exponential fit likelihood factor</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gserRadius" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>Sersic radius</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gserRadiusErr" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>estimated error in Sersic radius</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gserFlux" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Sersic Flux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gserFluxErr" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in serFlux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gserAb" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Sersic axis ratio</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gserAbErr" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated error in Sersic axis ratio</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gserNu" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Sersic index</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gserNuErr" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated error in Sersic index</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gserPhi" arraysize="1" datatype="float" unit="degrees" default="-999">
+        <DESCRIPTION>estmated phi of Sersic axis</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gserPhiErr" arraysize="1" datatype="float" unit="degrees" default="-999">
+        <DESCRIPTION>estmated error of phi of Sersic axis</DESCRIPTION>
+      </FIELD>
+      <FIELD name="graSerOff" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Offset in RA of Sersic fit from PSF RA</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gdecSerOff" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Offset in DEC of Sersic fit from PSF DEC</DESCRIPTION>
+      </FIELD>
+      <FIELD name="graSerOffErr" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated error in raSerOff</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gdecSerOffErr" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated error in decSerOff</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gserCf" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Sersic fit coverage factor</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gserLikelihood" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Sersic fit likelihood factor</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gpetRadius" arraysize="1" datatype="float" unit="pixels" default="-999">
+        <DESCRIPTION>Petrosian radius</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gpetRadiusErr" arraysize="1" datatype="float" unit="pixels" default="-999">
+        <DESCRIPTION>estimated error inPetrosian radius</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gpetFlux" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Petrosian Flux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gpetFluxErr" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in petFlux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gpetR50" arraysize="1" datatype="float" unit="pixels" default="-999">
+        <DESCRIPTION>Petrosian radius at 50% light</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gpetR50Err" arraysize="1" datatype="float" unit="pixels" default="-999">
+        <DESCRIPTION>estimated error inPetrosian radius at 50% light</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gpetR90" arraysize="1" datatype="float" unit="pixels" default="-999">
+        <DESCRIPTION>Petrosian radius at 90% light</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gpetR90Err" arraysize="1" datatype="float" unit="pixels" default="-999">
+        <DESCRIPTION>estimated error in Petrosian radius at 90% light</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gpetCf" arraysize="1" datatype="float" unit="pixels" default="-999">
+        <DESCRIPTION>Petrosian fit coverage factor</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR1" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR1Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR1Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR1Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR2" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR2Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR2Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR2Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR3" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR3Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR3Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR3Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR4" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR4Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR4Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR4Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR5" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR5Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR5Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR5Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR6" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR6Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR6Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR6Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR7" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR7Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR7Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR7Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR8" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR8Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR8Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR8Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR9" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR9Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR9Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR9Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR10" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR10Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR10Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gflxR10Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR1" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR1Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR1Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR1Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR2" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR2Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR2Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR2Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR3" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR3Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR3Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR3Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR4" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR4Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR4Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR4Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR5" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR5Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR5Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR5Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR6" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR6Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR6Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR6Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR7" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR7Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR7Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR7Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR8" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR8Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR8Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR8Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR9" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR9Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR9Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR9Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR10" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR10Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR10Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc1flxR10Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR1" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR1Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR1Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR1Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR2" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR2Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR2Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR2Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR3" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR3Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR3Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR3Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR4" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR4Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR4Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR4Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR5" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR5Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR5Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR5Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR6" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR6Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR6Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR6Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR7" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR7Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR7Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR7Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR8" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR8Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR8Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR8Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR9" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR9Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR9Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR9Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR10" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR10Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR10Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="gc2flxR10Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rlogC" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>concentration index</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rlogA" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>asymmetry index</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rclump" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>clumpiness factor</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rstackDetectID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>ODM detection identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rstackMetaID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
         <DESCRIPTION>stack identifier</DESCRIPTION>
       </FIELD>
-      <FIELD name="deVRadius" arraysize="1" datatype="float">
+      <FIELD name="rippObjID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>IPP object identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rippDetectID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>ipp detect identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rdeVRadius" arraysize="1" datatype="float" unit="arcsec" default="-999">
         <DESCRIPTION>deVaucouleurs radius</DESCRIPTION>
       </FIELD>
-      <FIELD name="deVRadiusErr" arraysize="1" datatype="float">
+      <FIELD name="rdeVRadiusErr" arraysize="1" datatype="float" unit="arcsec" default="-999">
         <DESCRIPTION>estimated error in deVaucouleurs radius</DESCRIPTION>
       </FIELD>
-      <FIELD name="deVFlux" arraysize="1" datatype="float">
+      <FIELD name="rdeVFlux" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
         <DESCRIPTION>deVaucouleurs magntiude</DESCRIPTION>
       </FIELD>
-      <FIELD name="deVFluxErr" arraysize="1" datatype="float">
+      <FIELD name="rdeVFluxErr" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
         <DESCRIPTION>estimated error in deV_mag</DESCRIPTION>
       </FIELD>
-      <FIELD name="deVAb" arraysize="1" datatype="float">
+      <FIELD name="rdeVAb" arraysize="1" datatype="float" unit="dimensionless" default="-999">
         <DESCRIPTION>deVaucoulerus axis ratio</DESCRIPTION>
       </FIELD>
-      <FIELD name="deVAbErr" arraysize="1" datatype="float">
+      <FIELD name="rdeVAbErr" arraysize="1" datatype="float" unit="dimensionless" default="-999">
         <DESCRIPTION>estimated error in deVaucoulerus axis ratio</DESCRIPTION>
       </FIELD>
-      <FIELD name="deVPhi" arraysize="1" datatype="float">
+      <FIELD name="rdeVPhi" arraysize="1" datatype="float" unit="degrees" default="-999">
         <DESCRIPTION>estmated phi of deVaucouleurs axis</DESCRIPTION>
       </FIELD>
-      <FIELD name="deVPhiErr" arraysize="1" datatype="float">
+      <FIELD name="rdeVPhiErr" arraysize="1" datatype="float" unit="degrees" default="-999">
         <DESCRIPTION>estmated error of phi of deVaucouleurs axis</DESCRIPTION>
       </FIELD>
-      <FIELD name="raDeVOff" arraysize="1" datatype="float">
+      <FIELD name="rraDeVOff" arraysize="1" datatype="float" unit="arcsec" default="-999">
         <DESCRIPTION>Offset in RA of deVaucouleurs fit from PSF RA</DESCRIPTION>
       </FIELD>
-      <FIELD name="decDeVOff" arraysize="1" datatype="float">
+      <FIELD name="rdecDeVOff" arraysize="1" datatype="float" unit="arcsec" default="-999">
         <DESCRIPTION>Offset in DEC of deVaucouleurs fit from PSF DEC</DESCRIPTION>
       </FIELD>
-      <FIELD name="raDeVOffErr" arraysize="1" datatype="float">
+      <FIELD name="rraDeVOffErr" arraysize="1" datatype="float" unit="arcsec" default="-999">
         <DESCRIPTION>estimated error in ra offset</DESCRIPTION>
       </FIELD>
-      <FIELD name="decDeVOffErr" arraysize="1" datatype="float">
+      <FIELD name="rdecDeVOffErr" arraysize="1" datatype="float" unit="arcsec" default="-999">
         <DESCRIPTION>estimated error in dec offset</DESCRIPTION>
       </FIELD>
-      <FIELD name="deVCf" arraysize="1" datatype="float">
+      <FIELD name="rdeVCf" arraysize="1" datatype="float" unit="dimensionless" default="-999">
         <DESCRIPTION>deVaucouleurs fit coverage factor</DESCRIPTION>
       </FIELD>
-      <FIELD name="deVLikelihood" arraysize="1" datatype="float">
+      <FIELD name="rdeVLikelihood" arraysize="1" datatype="float" unit="dimensionless" default="-999">
         <DESCRIPTION>deVaucouleurs fit likelihood factor</DESCRIPTION>
       </FIELD>
-      <FIELD name="deVCovar11" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for deVaucouleurs fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="deVCovar12" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for deVaucouleurs fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="deVCovar13" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for deVaucouleurs fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="deVCovar14" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for deVaucouleurs fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="deVCovar15" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for deVaucouleurs fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="deVCovar16" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for deVaucouleurs fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="deVCovar17" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for deVaucouleurs fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="deVCovar22" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for deVaucouleurs fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="deVCovar23" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for deVaucouleurs fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="deVCovar24" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for deVaucouleurs fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="deVCovar25" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for deVaucouleurs fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="deVCovar26" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for deVaucouleurs fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="deVCovar27" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for deVaucouleurs fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="deVCovar33" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for deVaucouleurs fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="deVCovar34" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for deVaucouleurs fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="deVCovar35" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for deVaucouleurs fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="deVCovar36" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for deVaucouleurs fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="deVCovar37" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for deVaucouleurs fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="deVCovar44" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for deVaucouleurs fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="deVCovar45" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for deVaucouleurs fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="deVCovar46" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for deVaucouleurs fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="deVCovar47" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for deVaucouleurs fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="deVCovar55" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for deVaucouleurs fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="deVCovar56" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for deVaucouleurs fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="deVCovar57" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for deVaucouleurs fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="deVCovar66" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for deVaucouleurs fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="deVCovar67" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for deVaucouleurs fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="deVCovar77" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for deVaucouleurs fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="expRadius" arraysize="1" datatype="float">
+      <FIELD name="rexpRadius" arraysize="1" datatype="float" unit="arcsec" default="-999">
         <DESCRIPTION>Exponential fit radius</DESCRIPTION>
       </FIELD>
-      <FIELD name="expRadiusErr" arraysize="1" datatype="float">
+      <FIELD name="rexpRadiusErr" arraysize="1" datatype="float" unit="arcsec" default="-999">
         <DESCRIPTION>estimated error in Exponential fit radius</DESCRIPTION>
       </FIELD>
-      <FIELD name="expFlux" arraysize="1" datatype="float">
+      <FIELD name="rexpFlux" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
         <DESCRIPTION>Exponential fit flux</DESCRIPTION>
       </FIELD>
-      <FIELD name="expFluxErr" arraysize="1" datatype="float">
+      <FIELD name="rexpFluxErr" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
         <DESCRIPTION>estimated error in expFlux</DESCRIPTION>
       </FIELD>
-      <FIELD name="expAb" arraysize="1" datatype="float">
+      <FIELD name="rexpAb" arraysize="1" datatype="float" unit="dimensionless" default="-999">
         <DESCRIPTION>Exponential fit axis ratio</DESCRIPTION>
       </FIELD>
-      <FIELD name="expAbErr" arraysize="1" datatype="float">
+      <FIELD name="rexpAbErr" arraysize="1" datatype="float" unit="dimensionless" default="-999">
         <DESCRIPTION>estimated error in Exponential fit axis ratio</DESCRIPTION>
       </FIELD>
-      <FIELD name="expPhi" arraysize="1" datatype="float">
+      <FIELD name="rexpPhi" arraysize="1" datatype="float" unit="degrees" default="-999">
         <DESCRIPTION>estmated phi of Exponential axis</DESCRIPTION>
       </FIELD>
-      <FIELD name="expPhiErr" arraysize="1" datatype="float">
+      <FIELD name="rexpPhiErr" arraysize="1" datatype="float" unit="degrees" default="-999">
         <DESCRIPTION>estmated error of phi of Exponential axis</DESCRIPTION>
       </FIELD>
-      <FIELD name="raExpOff" arraysize="1" datatype="float">
+      <FIELD name="rraExpOff" arraysize="1" datatype="float" unit="dimensionless" default="-999">
         <DESCRIPTION>Offset in RA of Exponential fit from PSF RA</DESCRIPTION>
       </FIELD>
-      <FIELD name="decExpOff" arraysize="1" datatype="float">
+      <FIELD name="rdecExpOff" arraysize="1" datatype="float" unit="dimensionless" default="-999">
         <DESCRIPTION>Offset in DEC of Exponential fit from PSF DEC</DESCRIPTION>
       </FIELD>
-      <FIELD name="raExpOffErr" arraysize="1" datatype="float">
+      <FIELD name="rraExpOffErr" arraysize="1" datatype="float" unit="dimensionless" default="-999">
         <DESCRIPTION>estimated error in raExpOff</DESCRIPTION>
       </FIELD>
-      <FIELD name="decExpOffErr" arraysize="1" datatype="float">
+      <FIELD name="rdecExpOffErr" arraysize="1" datatype="float" unit="dimensionless" default="-999">
         <DESCRIPTION>estimated error in decExpOff</DESCRIPTION>
       </FIELD>
-      <FIELD name="expCf" arraysize="1" datatype="float">
+      <FIELD name="rexpCf" arraysize="1" datatype="float" unit="dimensionless" default="-999">
         <DESCRIPTION>Exponential fit coverage factor</DESCRIPTION>
       </FIELD>
-      <FIELD name="expLikelihood" arraysize="1" datatype="float">
+      <FIELD name="rexpLikelihood" arraysize="1" datatype="float" unit="dimensionless" default="-999">
         <DESCRIPTION>Exponential fit likelihood factor</DESCRIPTION>
       </FIELD>
-      <FIELD name="expCovar11" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Exponential fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="expCovar12" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Exponential fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="expCovar13" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Exponential fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="expCovar14" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Exponential fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="expCovar15" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Exponential fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="expCovar16" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Exponential fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="expCovar17" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Exponential fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="expCovar22" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Exponential fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="expCovar23" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Exponential fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="expCovar24" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Exponential fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="expCovar25" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Exponential fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="expCovar26" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Exponential fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="expCovar27" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Exponential fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="expCovar33" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Exponential fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="expCovar34" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Exponential fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="expCovar35" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Exponential fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="expCovar36" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Exponential fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="expCovar37" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Exponential fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="expCovar44" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Exponential fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="expCovar45" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Exponential fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="expCovar46" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Exponential fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="expCovar47" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Exponential fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="expCovar55" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Exponential fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="expCovar56" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Exponential fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="expCovar57" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Exponential fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="expCovar66" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Exponential fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="expCovar67" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Exponential fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="expCovar77" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Exponential fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="serRadius" arraysize="1" datatype="float">
+      <FIELD name="rserRadius" arraysize="1" datatype="float" unit="arcsec" default="-999">
         <DESCRIPTION>Sersic radius</DESCRIPTION>
       </FIELD>
-      <FIELD name="serRadiusErr" arraysize="1" datatype="float">
+      <FIELD name="rserRadiusErr" arraysize="1" datatype="float" unit="arcsec" default="-999">
         <DESCRIPTION>estimated error in Sersic radius</DESCRIPTION>
       </FIELD>
-      <FIELD name="serFlux" arraysize="1" datatype="float">
+      <FIELD name="rserFlux" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
         <DESCRIPTION>Sersic Flux</DESCRIPTION>
       </FIELD>
-      <FIELD name="serFluxErr" arraysize="1" datatype="float">
+      <FIELD name="rserFluxErr" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
         <DESCRIPTION>estimated error in serFlux</DESCRIPTION>
       </FIELD>
-      <FIELD name="serAb" arraysize="1" datatype="float">
+      <FIELD name="rserAb" arraysize="1" datatype="float" unit="dimensionless" default="-999">
         <DESCRIPTION>Sersic axis ratio</DESCRIPTION>
       </FIELD>
-      <FIELD name="serAbErr" arraysize="1" datatype="float">
+      <FIELD name="rserAbErr" arraysize="1" datatype="float" unit="dimensionless" default="-999">
         <DESCRIPTION>estimated error in Sersic axis ratio</DESCRIPTION>
       </FIELD>
-      <FIELD name="serNu" arraysize="1" datatype="float">
+      <FIELD name="rserNu" arraysize="1" datatype="float" unit="dimensionless" default="-999">
         <DESCRIPTION>Sersic index</DESCRIPTION>
       </FIELD>
-      <FIELD name="serNuErr" arraysize="1" datatype="float">
+      <FIELD name="rserNuErr" arraysize="1" datatype="float" unit="dimensionless" default="-999">
         <DESCRIPTION>estimated error in Sersic index</DESCRIPTION>
       </FIELD>
-      <FIELD name="serPhi" arraysize="1" datatype="float">
+      <FIELD name="rserPhi" arraysize="1" datatype="float" unit="degrees" default="-999">
         <DESCRIPTION>estmated phi of Sersic axis</DESCRIPTION>
       </FIELD>
-      <FIELD name="serPhiErr" arraysize="1" datatype="float">
+      <FIELD name="rserPhiErr" arraysize="1" datatype="float" unit="degrees" default="-999">
         <DESCRIPTION>estmated error of phi of Sersic axis</DESCRIPTION>
       </FIELD>
-      <FIELD name="raSerOff" arraysize="1" datatype="float">
+      <FIELD name="rraSerOff" arraysize="1" datatype="float" unit="dimensionless" default="-999">
         <DESCRIPTION>Offset in RA of Sersic fit from PSF RA</DESCRIPTION>
       </FIELD>
-      <FIELD name="decSerOff" arraysize="1" datatype="float">
+      <FIELD name="rdecSerOff" arraysize="1" datatype="float" unit="dimensionless" default="-999">
         <DESCRIPTION>Offset in DEC of Sersic fit from PSF DEC</DESCRIPTION>
       </FIELD>
-      <FIELD name="raSerOffErr" arraysize="1" datatype="float">
+      <FIELD name="rraSerOffErr" arraysize="1" datatype="float" unit="dimensionless" default="-999">
         <DESCRIPTION>estimated error in raSerOff</DESCRIPTION>
       </FIELD>
-      <FIELD name="decSerOffErr" arraysize="1" datatype="float">
+      <FIELD name="rdecSerOffErr" arraysize="1" datatype="float" unit="dimensionless" default="-999">
         <DESCRIPTION>estimated error in decSerOff</DESCRIPTION>
       </FIELD>
-      <FIELD name="serCf" arraysize="1" datatype="float">
+      <FIELD name="rserCf" arraysize="1" datatype="float" unit="dimensionless" default="-999">
         <DESCRIPTION>Sersic fit coverage factor</DESCRIPTION>
       </FIELD>
-      <FIELD name="serLikelihood" arraysize="1" datatype="float">
+      <FIELD name="rserLikelihood" arraysize="1" datatype="float" unit="dimensionless" default="-999">
         <DESCRIPTION>Sersic fit likelihood factor</DESCRIPTION>
       </FIELD>
-      <FIELD name="sersicCovar11" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Sersic fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="sersicCovar12" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Sersic fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="sersicCovar13" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Sersic fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="sersicCovar14" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Sersic fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="sersicCovar15" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Sersic fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="sersicCovar16" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Sersic fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="sersicCovar17" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Sersic fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="sersicCovar18" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Sersic fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="sersicCovar22" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Sersic fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="sersicCovar23" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Sersic fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="sersicCovar24" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Sersic fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="sersicCovar25" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Sersic fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="sersicCovar26" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Sersic fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="sersicCovar27" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Sersic fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="sersicCovar28" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Sersic fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="sersicCovar33" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Sersic fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="sersicCovar34" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Sersic fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="sersicCovar35" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Sersic fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="sersicCovar36" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Sersic fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="sersicCovar37" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Sersic fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="sersicCovar38" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Sersic fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="sersicCovar44" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Sersic fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="sersicCovar45" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Sersic fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="sersicCovar46" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Sersic fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="sersicCovar47" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Sersic fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="sersicCovar48" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Sersic fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="sersicCovar55" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Sersic fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="sersicCovar56" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Sersic fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="sersicCovar57" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Sersic fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="sersicCovar58" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Sersic fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="sersicCovar66" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Sersic fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="sersicCovar67" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Sersic fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="sersicCovar68" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Sersic fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="sersicCovar77" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Sersic fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="sersicCovar78" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Sersic fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="sersicCovar88" arraysize="1" datatype="float">
-        <DESCRIPTION>covariance for Sersic fit</DESCRIPTION>
-      </FIELD>
-      <FIELD name="activeFlag" arraysize="1" datatype="unsignedByte">
-        <DESCRIPTION>indicates whether this detection/orphan is still a detection/orphan</DESCRIPTION>
-      </FIELD>
-      <FIELD name="dataRelease" arraysize="1" datatype="unsignedByte">
-        <DESCRIPTION>Data release when this detection was taken</DESCRIPTION>
+      <FIELD name="rpetRadius" arraysize="1" datatype="float" unit="pixels" default="-999">
+        <DESCRIPTION>Petrosian radius</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rpetRadiusErr" arraysize="1" datatype="float" unit="pixels" default="-999">
+        <DESCRIPTION>estimated error inPetrosian radius</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rpetFlux" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Petrosian Flux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rpetFluxErr" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in petFlux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rpetR50" arraysize="1" datatype="float" unit="pixels" default="-999">
+        <DESCRIPTION>Petrosian radius at 50% light</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rpetR50Err" arraysize="1" datatype="float" unit="pixels" default="-999">
+        <DESCRIPTION>estimated error inPetrosian radius at 50% light</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rpetR90" arraysize="1" datatype="float" unit="pixels" default="-999">
+        <DESCRIPTION>Petrosian radius at 90% light</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rpetR90Err" arraysize="1" datatype="float" unit="pixels" default="-999">
+        <DESCRIPTION>estimated error in Petrosian radius at 90% light</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rpetCf" arraysize="1" datatype="float" unit="pixels" default="-999">
+        <DESCRIPTION>Petrosian fit coverage factor</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR1" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR1Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR1Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR1Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR2" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR2Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR2Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR2Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR3" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR3Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR3Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR3Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR4" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR4Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR4Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR4Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR5" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR5Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR5Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR5Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR6" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR6Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR6Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR6Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR7" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR7Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR7Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR7Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR8" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR8Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR8Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR8Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR9" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR9Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR9Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR9Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR10" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR10Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR10Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rflxR10Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc1flxR1" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc1flxR1Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc1flxR1Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc1flxR1Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc1flxR2" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc1flxR2Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc1flxR2Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc1flxR2Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc1flxR3" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc1flxR3Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc1flxR3Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc1flxR3Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc1flxR4" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc1flxR4Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc1flxR4Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc1flxR4Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc1flxR5" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc1flxR5Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc1flxR5Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc1flxR5Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc1flxR6" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc1flxR6Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc1flxR6Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc1flxR6Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc1flxR7" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc1flxR7Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc1flxR7Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc1flxR7Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc1flxR8" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc1flxR8Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc1flxR8Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc1flxR8Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc1flxR9" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc1flxR9Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc1flxR9Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc1flxR9Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc1flxR10" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc1flxR10Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc1flxR10Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc1flxR10Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc2flxR1" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc2flxR1Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc2flxR1Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc2flxR1Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc2flxR2" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc2flxR2Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc2flxR2Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc2flxR2Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc2flxR3" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc2flxR3Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc2flxR3Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc2flxR3Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc2flxR4" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc2flxR4Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc2flxR4Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc2flxR4Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc2flxR5" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc2flxR5Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc2flxR5Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc2flxR5Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc2flxR6" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc2flxR6Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc2flxR6Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc2flxR6Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc2flxR7" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc2flxR7Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc2flxR7Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc2flxR7Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc2flxR8" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc2flxR8Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc2flxR8Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc2flxR8Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc2flxR9" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc2flxR9Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc2flxR9Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc2flxR9Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc2flxR10" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc2flxR10Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc2flxR10Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rc2flxR10Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ilogC" arraysize="1" datatype="float" unit="dimensionless" default="NA">
+        <DESCRIPTION>concentration index</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ilogA" arraysize="1" datatype="float" unit="dimensionless" default="NA">
+        <DESCRIPTION>asymmetry index</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iclump" arraysize="1" datatype="float" unit="dimensionless" default="NA">
+        <DESCRIPTION>clumpiness factor</DESCRIPTION>
+      </FIELD>
+      <FIELD name="istackDetectID" arraysize="1" datatype="long" unit="dimensionless" default="-999">
+        <DESCRIPTION>ODM detection identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="istackMetaID" arraysize="1" datatype="long" unit="dimensionless" default="-999">
+        <DESCRIPTION>stack identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iippObjID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>IPP object identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iippDetectID" arraysize="1" datatype="long" unit="dimensionless" default="-999">
+        <DESCRIPTION>ipp detect identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ideVRadius" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>deVaucouleurs radius</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ideVRadiusErr" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>estimated error in deVaucouleurs radius</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ideVFlux" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>deVaucouleurs magntiude</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ideVFluxErr" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in deV_mag</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ideVAb" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>deVaucoulerus axis ratio</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ideVAbErr" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated error in deVaucoulerus axis ratio</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ideVPhi" arraysize="1" datatype="float" unit="degrees" default="-999">
+        <DESCRIPTION>estmated phi of deVaucouleurs axis</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ideVPhiErr" arraysize="1" datatype="float" unit="degrees" default="-999">
+        <DESCRIPTION>estmated error of phi of deVaucouleurs axis</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iraDeVOff" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>Offset in RA of deVaucouleurs fit from PSF RA</DESCRIPTION>
+      </FIELD>
+      <FIELD name="idecDeVOff" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>Offset in DEC of deVaucouleurs fit from PSF DEC</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iraDeVOffErr" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>estimated error in ra offset</DESCRIPTION>
+      </FIELD>
+      <FIELD name="idecDeVOffErr" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>estimated error in dec offset</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ideVCf" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>deVaucouleurs fit coverage factor</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ideVLikelihood" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>deVaucouleurs fit likelihood factor</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iexpRadius" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>Exponential fit radius</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iexpRadiusErr" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>estimated error in Exponential fit radius</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iexpFlux" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Exponential fit flux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iexpFluxErr" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in expFlux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iexpAb" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Exponential fit axis ratio</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iexpAbErr" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated error in Exponential fit axis ratio</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iexpPhi" arraysize="1" datatype="float" unit="degrees" default="-999">
+        <DESCRIPTION>estmated phi of Exponential axis</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iexpPhiErr" arraysize="1" datatype="float" unit="degrees" default="-999">
+        <DESCRIPTION>estmated error of phi of Exponential axis</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iraExpOff" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Offset in RA of Exponential fit from PSF RA</DESCRIPTION>
+      </FIELD>
+      <FIELD name="idecExpOff" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Offset in DEC of Exponential fit from PSF DEC</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iraExpOffErr" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated error in raExpOff</DESCRIPTION>
+      </FIELD>
+      <FIELD name="idecExpOffErr" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated error in decExpOff</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iexpCf" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Exponential fit coverage factor</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iexpLikelihood" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Exponential fit likelihood factor</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iserRadius" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>Sersic radius</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iserRadiusErr" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>estimated error in Sersic radius</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iserFlux" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Sersic Flux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iserFluxErr" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in serFlux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iserAb" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Sersic axis ratio</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iserAbErr" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated error in Sersic axis ratio</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iserNu" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Sersic index</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iserNuErr" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated error in Sersic index</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iserPhi" arraysize="1" datatype="float" unit="degrees" default="-999">
+        <DESCRIPTION>estmated phi of Sersic axis</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iserPhiErr" arraysize="1" datatype="float" unit="degrees" default="-999">
+        <DESCRIPTION>estmated error of phi of Sersic axis</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iraSerOff" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Offset in RA of Sersic fit from PSF RA</DESCRIPTION>
+      </FIELD>
+      <FIELD name="idecSerOff" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Offset in DEC of Sersic fit from PSF DEC</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iraSerOffErr" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated error in raSerOff</DESCRIPTION>
+      </FIELD>
+      <FIELD name="idecSerOffErr" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated error in decSerOff</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iserCf" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Sersic fit coverage factor</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iserLikelihood" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Sersic fit likelihood factor</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ipetRadius" arraysize="1" datatype="float" unit="pixels" default="-999">
+        <DESCRIPTION>Petrosian radius</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ipetRadiusErr" arraysize="1" datatype="float" unit="pixels" default="-999">
+        <DESCRIPTION>estimated error inPetrosian radius</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ipetFlux" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Petrosian Flux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ipetFluxErr" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in petFlux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ipetR50" arraysize="1" datatype="float" unit="pixels" default="-999">
+        <DESCRIPTION>Petrosian radius at 50% light</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ipetR50Err" arraysize="1" datatype="float" unit="pixels" default="-999">
+        <DESCRIPTION>estimated error inPetrosian radius at 50% light</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ipetR90" arraysize="1" datatype="float" unit="pixels" default="-999">
+        <DESCRIPTION>Petrosian radius at 90% light</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ipetR90Err" arraysize="1" datatype="float" unit="pixels" default="-999">
+        <DESCRIPTION>estimated error in Petrosian radius at 90% light</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ipetCf" arraysize="1" datatype="float" unit="pixels" default="-999">
+        <DESCRIPTION>Petrosian fit coverage factor</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR1" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR1Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR1Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR1Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR2" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR2Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR2Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR2Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR3" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR3Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR3Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR3Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR4" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR4Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR4Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR4Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR5" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR5Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR5Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR5Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR6" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR6Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR6Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR6Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR7" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR7Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR7Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR7Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR8" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR8Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR8Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR8Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR9" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR9Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR9Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR9Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR10" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR10Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR10Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iflxR10Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR1" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR1Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR1Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR1Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR2" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR2Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR2Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR2Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR3" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR3Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR3Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR3Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR4" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR4Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR4Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR4Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR5" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR5Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR5Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR5Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR6" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR6Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR6Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR6Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR7" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR7Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR7Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR7Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR8" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR8Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR8Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR8Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR9" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR9Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR9Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR9Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR10" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR10Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR10Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic1flxR10Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR1" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR1Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR1Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR1Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR2" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR2Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR2Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR2Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR3" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR3Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR3Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR3Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR4" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR4Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR4Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR4Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR5" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR5Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR5Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR5Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR6" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR6Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR6Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR6Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR7" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR7Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR7Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR7Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR8" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR8Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR8Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR8Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR9" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR9Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR9Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR9Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR10" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR10Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR10Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ic2flxR10Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zlogC" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>concentration index</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zlogA" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>asymmetry index</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zclump" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>clumpiness factor</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zstackDetectID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>ODM detection identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zstackMetaID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>stack identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zippObjID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>IPP object identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zippDetectID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>ipp detect identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zdeVRadius" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>deVaucouleurs radius</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zdeVRadiusErr" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>estimated error in deVaucouleurs radius</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zdeVFlux" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>deVaucouleurs magntiude</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zdeVFluxErr" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in deV_mag</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zdeVAb" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>deVaucoulerus axis ratio</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zdeVAbErr" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated error in deVaucoulerus axis ratio</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zdeVPhi" arraysize="1" datatype="float" unit="degrees" default="-999">
+        <DESCRIPTION>estmated phi of deVaucouleurs axis</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zdeVPhiErr" arraysize="1" datatype="float" unit="degrees" default="-999">
+        <DESCRIPTION>estmated error of phi of deVaucouleurs axis</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zraDeVOff" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>Offset in RA of deVaucouleurs fit from PSF RA</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zdecDeVOff" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>Offset in DEC of deVaucouleurs fit from PSF DEC</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zraDeVOffErr" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>estimated error in ra offset</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zdecDeVOffErr" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>estimated error in dec offset</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zdeVCf" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>deVaucouleurs fit coverage factor</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zdeVLikelihood" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>deVaucouleurs fit likelihood factor</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zexpRadius" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>Exponential fit radius</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zexpRadiusErr" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>estimated error in Exponential fit radius</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zexpFlux" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Exponential fit flux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zexpFluxErr" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in expFlux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zexpAb" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Exponential fit axis ratio</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zexpAbErr" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated error in Exponential fit axis ratio</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zexpPhi" arraysize="1" datatype="float" unit="degrees" default="-999">
+        <DESCRIPTION>estmated phi of Exponential axis</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zexpPhiErr" arraysize="1" datatype="float" unit="degrees" default="-999">
+        <DESCRIPTION>estmated error of phi of Exponential axis</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zraExpOff" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Offset in RA of Exponential fit from PSF RA</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zdecExpOff" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Offset in DEC of Exponential fit from PSF DEC</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zraExpOffErr" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated error in raExpOff</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zdecExpOffErr" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated error in decExpOff</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zexpCf" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Exponential fit coverage factor</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zexpLikelihood" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Exponential fit likelihood factor</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zserRadius" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>Sersic radius</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zserRadiusErr" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>estimated error in Sersic radius</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zserFlux" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Sersic Flux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zserFluxErr" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in serFlux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zserAb" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Sersic axis ratio</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zserAbErr" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated error in Sersic axis ratio</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zserNu" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Sersic index</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zserNuErr" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated error in Sersic index</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zserPhi" arraysize="1" datatype="float" unit="degrees" default="-999">
+        <DESCRIPTION>estmated phi of Sersic axis</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zserPhiErr" arraysize="1" datatype="float" unit="degrees" default="-999">
+        <DESCRIPTION>estmated error of phi of Sersic axis</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zraSerOff" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Offset in RA of Sersic fit from PSF RA</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zdecSerOff" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Offset in DEC of Sersic fit from PSF DEC</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zraSerOffErr" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated error in raSerOff</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zdecSerOffErr" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated error in decSerOff</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zserCf" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Sersic fit coverage factor</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zserLikelihood" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Sersic fit likelihood factor</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zpetRadius" arraysize="1" datatype="float" unit="pixels" default="-999">
+        <DESCRIPTION>Petrosian radius</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zpetRadiusErr" arraysize="1" datatype="float" unit="pixels" default="-999">
+        <DESCRIPTION>estimated error inPetrosian radius</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zpetFlux" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Petrosian Flux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zpetFluxErr" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in petFlux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zpetR50" arraysize="1" datatype="float" unit="pixels" default="-999">
+        <DESCRIPTION>Petrosian radius at 50% light</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zpetR50Err" arraysize="1" datatype="float" unit="pixels" default="-999">
+        <DESCRIPTION>estimated error inPetrosian radius at 50% light</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zpetR90" arraysize="1" datatype="float" unit="pixels" default="-999">
+        <DESCRIPTION>Petrosian radius at 90% light</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zpetR90Err" arraysize="1" datatype="float" unit="pixels" default="-999">
+        <DESCRIPTION>estimated error in Petrosian radius at 90% light</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zpetCf" arraysize="1" datatype="float" unit="pixels" default="-999">
+        <DESCRIPTION>Petrosian fit coverage factor</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR1" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR1Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR1Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR1Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR2" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR2Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR2Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR2Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR3" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR3Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR3Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR3Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR4" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR4Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR4Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR4Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR5" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR5Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR5Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR5Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR6" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR6Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR6Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR6Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR7" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR7Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR7Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR7Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR8" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR8Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR8Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR8Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR9" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR9Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR9Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR9Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR10" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR10Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR10Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zflxR10Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR1" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR1Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR1Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR1Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR2" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR2Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR2Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR2Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR3" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR3Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR3Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR3Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR4" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR4Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR4Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR4Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR5" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR5Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR5Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR5Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR6" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR6Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR6Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR6Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR7" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR7Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR7Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR7Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR8" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR8Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR8Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR8Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR9" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR9Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR9Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR9Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR10" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR10Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR10Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc1flxR10Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR1" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR1Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR1Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR1Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR2" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR2Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR2Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR2Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR3" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR3Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR3Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR3Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR4" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR4Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR4Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR4Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR5" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR5Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR5Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR5Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR6" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR6Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR6Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR6Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR7" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR7Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR7Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR7Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR8" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR8Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR8Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR8Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR9" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR9Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR9Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR9Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR10" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR10Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR10Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zc2flxR10Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ylogC" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>concentration index</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ylogA" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>asymmetry index</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yclump" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>clumpiness factor</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ystackDetectID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>ODM detection identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ystackMetaID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>stack identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yippObjID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>IPP object identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yippDetectID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
+        <DESCRIPTION>ipp detect identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ydeVRadius" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>deVaucouleurs radius</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ydeVRadiusErr" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>estimated error in deVaucouleurs radius</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ydeVFlux" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>deVaucouleurs magntiude</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ydeVFluxErr" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in deV_mag</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ydeVAb" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>deVaucoulerus axis ratio</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ydeVAbErr" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated error in deVaucoulerus axis ratio</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ydeVPhi" arraysize="1" datatype="float" unit="degrees" default="-999">
+        <DESCRIPTION>estmated phi of deVaucouleurs axis</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ydeVPhiErr" arraysize="1" datatype="float" unit="degrees" default="-999">
+        <DESCRIPTION>estmated error of phi of deVaucouleurs axis</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yraDeVOff" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>Offset in RA of deVaucouleurs fit from PSF RA</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ydecDeVOff" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>Offset in DEC of deVaucouleurs fit from PSF DEC</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yraDeVOffErr" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>estimated error in ra offset</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ydecDeVOffErr" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>estimated error in dec offset</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ydeVCf" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>deVaucouleurs fit coverage factor</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ydeVLikelihood" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>deVaucouleurs fit likelihood factor</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yexpRadius" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>Exponential fit radius</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yexpRadiusErr" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>estimated error in Exponential fit radius</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yexpFlux" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Exponential fit flux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yexpFluxErr" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in expFlux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yexpAb" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Exponential fit axis ratio</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yexpAbErr" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated error in Exponential fit axis ratio</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yexpPhi" arraysize="1" datatype="float" unit="degrees" default="-999">
+        <DESCRIPTION>estmated phi of Exponential axis</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yexpPhiErr" arraysize="1" datatype="float" unit="degrees" default="-999">
+        <DESCRIPTION>estmated error of phi of Exponential axis</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yraExpOff" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Offset in RA of Exponential fit from PSF RA</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ydecExpOff" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Offset in DEC of Exponential fit from PSF DEC</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yraExpOffErr" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated error in raExpOff</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ydecExpOffErr" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated error in decExpOff</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yexpCf" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Exponential fit coverage factor</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yexpLikelihood" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Exponential fit likelihood factor</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yserRadius" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>Sersic radius</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yserRadiusErr" arraysize="1" datatype="float" unit="arcsec" default="-999">
+        <DESCRIPTION>estimated error in Sersic radius</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yserFlux" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Sersic Flux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yserFluxErr" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in serFlux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yserAb" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Sersic axis ratio</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yserAbErr" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated error in Sersic axis ratio</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yserNu" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Sersic index</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yserNuErr" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated error in Sersic index</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yserPhi" arraysize="1" datatype="float" unit="degrees" default="-999">
+        <DESCRIPTION>estmated phi of Sersic axis</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yserPhiErr" arraysize="1" datatype="float" unit="degrees" default="-999">
+        <DESCRIPTION>estmated error of phi of Sersic axis</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yraSerOff" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Offset in RA of Sersic fit from PSF RA</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ydecSerOff" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Offset in DEC of Sersic fit from PSF DEC</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yraSerOffErr" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated error in raSerOff</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ydecSerOffErr" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated error in decSerOff</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yserCf" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Sersic fit coverage factor</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yserLikelihood" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>Sersic fit likelihood factor</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ypetRadius" arraysize="1" datatype="float" unit="pixels" default="-999">
+        <DESCRIPTION>Petrosian radius</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ypetRadiusErr" arraysize="1" datatype="float" unit="pixels" default="-999">
+        <DESCRIPTION>estimated error inPetrosian radius</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ypetFlux" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Petrosian Flux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ypetFluxErr" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error in petFlux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ypetR50" arraysize="1" datatype="float" unit="pixels" default="-999">
+        <DESCRIPTION>Petrosian radius at 50% light</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ypetR50Err" arraysize="1" datatype="float" unit="pixels" default="-999">
+        <DESCRIPTION>estimated error inPetrosian radius at 50% light</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ypetR90" arraysize="1" datatype="float" unit="pixels" default="-999">
+        <DESCRIPTION>Petrosian radius at 90% light</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ypetR90Err" arraysize="1" datatype="float" unit="pixels" default="-999">
+        <DESCRIPTION>estimated error in Petrosian radius at 90% light</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ypetCf" arraysize="1" datatype="float" unit="pixels" default="-999">
+        <DESCRIPTION>Petrosian fit coverage factor</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR1" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR1Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR1Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR1Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR2" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR2Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR2Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR2Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR3" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR3Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR3Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR3Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR4" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR4Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR4Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR4Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR5" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR5Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR5Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR5Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR6" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR6Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR6Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR6Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR7" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR7Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR7Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR7Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR8" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR8Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR8Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR8Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR9" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR9Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR9Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR9Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR10" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR10Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is flxR10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR10Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in flxR10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yflxR10Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR1" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR1Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR1Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR1Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR2" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR2Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR2Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR2Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR3" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR3Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR3Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR3Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR4" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR4Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR4Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR4Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR5" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR5Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR5Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR5Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR6" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR6Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR6Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR6Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR7" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR7Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR7Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR7Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR8" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR8Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR8Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR8Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR9" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR9Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR9Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR9Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR10" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR10Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c1flxR10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR10Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c1flxR10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc1flxR10Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR1" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR1Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR1Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR1Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR2" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR2Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR2Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR2</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR2Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R1</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR3" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR3Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR3Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR3Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R3</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR4" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR4Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR4Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR4Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R4</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR5" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR5Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR5Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR5Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R5</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR6" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR6Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR6Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR6Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R6</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR7" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR7Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR7Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR7Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R7</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR8" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR8Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR8Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR8Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R8</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR9" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR9Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR9Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR9Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R9</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR10" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>Flux inside r = 10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR10Err" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated error is c2flxR10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR10Std" arraysize="1" datatype="float" unit="adu/seconds" default="-999">
+        <DESCRIPTION>estimated standard deviation in c2flxR10</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yc2flxR10Fill" arraysize="1" datatype="float" unit="dimensionless" default="-999">
+        <DESCRIPTION>estimated filling factor at R10</DESCRIPTION>
       </FIELD>
       <DATA>
-        <TABLEDATA></TABLEDATA>
+	<TABLEDATA></TABLEDATA>
       </DATA>
     </TABLE>
@@ -1183,83 +4204,9 @@
       <DESCRIPTION>VOTable description of PSPS table StackToImage</DESCRIPTION>
       <PARAM arraysize="1" datatype="char" ucd="meta.bib.author" name="Author" value="PSPS"></PARAM>
-      <FIELD name="stackMetaID" arraysize="1" datatype="long">
+      <FIELD name="stackMetaID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
         <DESCRIPTION>stack identifier</DESCRIPTION>
       </FIELD>
-      <FIELD name="imageID" arraysize="1" datatype="long">
+      <FIELD name="imageID" arraysize="1" datatype="long" unit="dimensionless" default="NA">
         <DESCRIPTION>hashed exposure-ccdID identifier</DESCRIPTION>
-      </FIELD>
-      <DATA>
-        <TABLEDATA></TABLEDATA>
-      </DATA>
-    </TABLE>
-    <TABLE name="SkinnyObject">
-      <DESCRIPTION>VOTable description of PSPS table SkinnyObject</DESCRIPTION>
-      <PARAM arraysize="1" datatype="char" ucd="meta.bib.author" name="Author" value="PSPS"></PARAM>
-      <FIELD name="objID" arraysize="1" datatype="long">
-        <DESCRIPTION>ODM object identifier index</DESCRIPTION>
-      </FIELD>
-      <FIELD name="ippObjID" arraysize="1" datatype="long">
-        <DESCRIPTION>IPP object number</DESCRIPTION>
-      </FIELD>
-      <FIELD name="projectionCellID" arraysize="1" datatype="int">
-        <DESCRIPTION>projection cell identifier at discovery time</DESCRIPTION>
-      </FIELD>
-      <FIELD name="dataRelease" arraysize="1" datatype="unsignedByte">
-        <DESCRIPTION>Data release to propagate to the object</DESCRIPTION>
-      </FIELD>
-      <FIELD name="surveyID" arraysize="1" datatype="unsignedByte">
-        <DESCRIPTION>surveyID &lt;/coluumn&gt;</DESCRIPTION>
-      </FIELD>
-      <DATA>
-        <TABLEDATA></TABLEDATA>
-      </DATA>
-    </TABLE>
-      <TABLE name="StackDetectionCalib">
-      <DESCRIPTION>VOTable description of PSPS table StackDetectionCalib</DESCRIPTION>
-      <PARAM arraysize="1" datatype="char" ucd="meta.bib.author" name="Author" value="PSPS"></PARAM>
-      <FIELD name="objID" arraysize="1" datatype="long" unit="unknown">
-        <DESCRIPTION>ODM object identifier index</DESCRIPTION>
-      </FIELD>
-      <FIELD name="stackDetectID" arraysize="1" datatype="long" unit="unknown">
-        <DESCRIPTION>ODM detection identifier index</DESCRIPTION>
-      </FIELD>
-      <FIELD name="ippObjID" arraysize="1" datatype="long" unit="unknown">
-        <DESCRIPTION>IPP object number</DESCRIPTION>
-      </FIELD>
-      <FIELD name="ippDetectID" arraysize="1" datatype="long" unit="unknown">
-        <DESCRIPTION>detection ID generated by IPP</DESCRIPTION>
-      </FIELD>
-      <FIELD name="filterID" arraysize="1" datatype="unsignedByte" unit="unknown">
-        <DESCRIPTION>filter identifier</DESCRIPTION>
-      </FIELD>
-      <FIELD name="surveyID" arraysize="1" datatype="unsignedByte" unit="unknown">
-        <DESCRIPTION>survey identifier</DESCRIPTION>
-      </FIELD>
-      <FIELD name="ra" arraysize="1" datatype="double" unit="degrees">
-        <DESCRIPTION>right ascension</DESCRIPTION>
-      </FIELD>
-      <FIELD name="dec" arraysize="1" datatype="double" unit="degrees">
-        <DESCRIPTION>declination</DESCRIPTION>
-      </FIELD>
-      <FIELD name="raErr" arraysize="1" datatype="float" unit="arcsec">
-        <DESCRIPTION>right ascension error</DESCRIPTION>
-      </FIELD>
-      <FIELD name="decErr" arraysize="1" datatype="float" unit="arcsec">
-        <DESCRIPTION>declination error</DESCRIPTION>
-      </FIELD>
-      <FIELD name="zp" arraysize="1" datatype="float" unit="magnitude">
-        <DESCRIPTION>zero point offset</DESCRIPTION>
-      </FIELD>
-      <FIELD name="zpErr" arraysize="1" datatype="float" unit="magnitude">
-        <DESCRIPTION>zerop point offset error</DESCRIPTION>
-      </FIELD>
-      <FIELD name="expTime" arraysize="1" datatype="float" unit="s">
-        <DESCRIPTION>exposure time</DESCRIPTION>
-      </FIELD>
-      <FIELD name="airMass" arraysize="1" datatype="float" unit="unknown">
-        <DESCRIPTION>airmass</DESCRIPTION>
-      </FIELD>
-      <FIELD name="dataRelease" arraysize="1" datatype="unsignedByte" unit="unknown">
-        <DESCRIPTION>Data release to propagate to the object</DESCRIPTION>
       </FIELD>
       <DATA>
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/Makefile.am
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/Makefile.am	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/Makefile.am	(revision 37066)
@@ -11,4 +11,6 @@
   datastoreRemover.py \
   detectionbatch.py \
+  diffbatch.py \
+  diffobjectbatch.py \
   dvodetections.py \
   dvoobjects.py \
@@ -16,6 +18,9 @@
   dxlayer.py \
   fits.py \
+  forcedobjectbatch.py \
+  forcedwarpbatch.py \
   gpc1db.py \
   initbatch.py \
+  insert.dvodb.info.py \	
   ipptopspsdb.py \
   ipptopsps.py \
@@ -30,4 +35,5 @@
   pslogger.py \
   queue.py \
+  removepending.py \ 
   scratchdb.py \
   setupScratchDb.py \
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/batch.py
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/batch.py	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/batch.py	(revision 37066)
@@ -412,4 +412,6 @@
           if not match: continue
           self.logger.debugPair("Reading IPP table", table.name)
+          table = stilts.tpipe(table, cmd='addcol table_index $0')
+
           table = stilts.tpipe(table, cmd='explodeall')
 
@@ -437,4 +439,94 @@
       self.indexIppTables()
 
+      return True
+    '''
+    Imports IPP tables from FITS file
+
+    Accepts a regular expression filter so not all tables need to be imported
+    '''
+    def importIppSTTables(self, columns="*", filter=""):
+
+      self.logger.infoPair("Importing ST tables with filter", filter)
+
+      # print "trying to read ", self.fits.getPath()
+
+      # ST has 5 cmf files - all with the same table names. To counter this we do it like this.
+
+      filters = ["g","r","i","z","y"]
+      count = 0
+      for f in filters:
+          skip = 0
+          if (f == "g"):
+              if self.gstackID > 0:  
+                  fileName = self.gfits.getPath()
+              else:
+                  skip = 1
+          if (f == "r"):
+              if self.rstackID > 0:
+                  fileName = self.rfits.getPath()
+              else:
+                  skip = 1
+          if (f == "i"):
+              if self.istackID > 0:
+                  fileName = self.ifits.getPath()
+              else:
+                  skip = 1
+          if (f == "z"):
+              if self.zstackID > 0:
+                  fileName = self.zfits.getPath()
+              else:
+                  skip = 1
+          if (f == "y"):
+              if self.ystackID > 0:
+                  fileName = self.yfits.getPath()
+              else:
+                  skip = 1
+
+          if skip == 1:
+              self.logger.infoPair("no files for filter" , f) 
+          else:
+             self.logger.infoPair("using filename:",fileName)
+          
+             try:
+              tables = stilts.treads(fileName)
+             except:
+              self.logger.errorPair("STILTS could not import from", fileName)
+              return False
+              
+             #count = 0
+             for table in tables:
+              
+              # print "import smf table ", table
+              match = re.match(filter, table.name)
+              
+              if not match: continue
+              self.logger.infoPair("Reading IPP table", f + table.name)
+              table = stilts.tpipe(table, cmd='addcol table_index $0')
+                  
+              table = stilts.tpipe(table, cmd='explodeall')
+                  
+              # print "read smf table ", table
+                  
+              # drop any previous tables before import
+              self.scratchDb.dropTable(f + table.name)
+                  
+              # IPP FITS files are littered with infinities, so remove these
+              self.logger.debug("Removing Infinity values from all columns")
+              table = stilts.tpipe(table, cmd='keepcols "' + columns + '"')
+              table = stilts.tpipe(table, cmd='replaceval -Infinity null *')
+              table = stilts.tpipe(table, cmd='replaceval Infinity null *')
+              # print "cleaned up values ", table
+                  
+              try:
+                  table.write(self.scratchDb.url + '#' + f + table.name)
+                  # XXX this one is not needed
+                  # self.scratchDb.killLastConnectionID()
+                  count = count + 1
+              except:
+                  self.logger.exception("Problem writing table '" + f + table.name + "' to the database")
+                      
+      self.logger.infoPair("Done. Imported", "%d tables" % count)
+      self.indexIppTables()
+                      
       return True
 
@@ -465,6 +557,7 @@
            # replace nulls and empty fields with weird PSPS -999 pseudo-null
            _table = stilts.tpipe(_table, cmd='replaceval "" -999 *')
-
-           match = re.match(regex, table)
+           self.logger.infoPair('regex', regex)
+           self.logger.infoPair('table', table)
+           match = re.search(regex, table)
            newTableName = match.group(1)
 
@@ -549,14 +642,22 @@
         # for P2/ST, this reads the detection tables from the CMF/SMF file(s)
         # for OB, this imports object data from DVO
-        if not self.importIppTables():
-            if self.batchType == "OB":
-                self.logger.errorPair("skipping this batch", "no dvo tables for this region")
-                self.ippToPspsDb.updateProcessed(self.batchID, 1)
-                return True
-
-            self.logger.errorPair("Aborting this batch", "could not import IPP tables")
-            self.ippToPspsDb.updateProcessed(self.batchID, -1)
-            raise
-
+        if self.batchType == "ST":
+            self.logger.infoPair("did we get here","?")  
+            if not self.importIppSTTables():
+                self.logger.errorPair("skipping this batch", "could not import ST IPP tables")
+                self.ippToPspsDb.updateProcessed(self.batchID, -1)
+                raise
+            self.logger.infoPair("we did the ST","yes")
+        else:    
+            # if not ST we do this 
+            if not self.importIppTables():
+                if self.batchType == "OB":
+                    self.logger.errorPair("skipping this batch", "no dvo tables for this region")
+                    self.ippToPspsDb.updateProcessed(self.batchID, 1)
+                    return True
+                self.logger.errorPair("Aborting this batch", "could not import IPP tables")
+                self.ippToPspsDb.updateProcessed(self.batchID, -1)
+                raise
+        self.logger.infoPair("populatePspsTables","ok")
         if not self.populatePspsTables():
             if self.skipBatch:
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/cleanup.py
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/cleanup.py	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/cleanup.py	(revision 37066)
@@ -46,4 +46,8 @@
             self.clean("ST")
             self.clean("OB")
+            self.clean("DF")
+            self.clean("DO")
+            self.clean("FW")
+            self.clean("FO")
 
             self.checkClientStatus()
@@ -87,5 +91,5 @@
         self.logger.infoPair("To delete from DXLayer", "%d" % len(deleteFromDxLayerIDs))
         self.logger.infoPair("To delete from local disk", "%d" % len(deleteFromLocalIDs))
-    
+    #    self.logger.infoPair("Did I get here", "yes?")
         # delete stuff from local disk
         if self.skychunk.deleteLocal:
@@ -110,11 +114,13 @@
     
             self.reportResults("datastore", deleteFromDatastoreIDs, count) 
-        
+       # self.logger.infoPair("here","here")
         # remove stuff from DXLayer
         if self.skychunk.deleteDxLayer:
+#            self.logger.infoPair ("skip remove from dxlayer", "HAF")
             count = 0
             for id in deleteFromDxLayerIDs:
-        
+                self.logger.infoPair("delete from dxlayer", id);
                 if self.dxlayer.deleteBatch(id):
+                    self.logger.infoPair("delete dxlayer",id);
                     self.ippToPspsDb.updateDeletedDxlayer(id, 1)
                     count = count + 1
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/detectionbatch.py
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/detectionbatch.py	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/detectionbatch.py	(revision 37066)
@@ -54,5 +54,5 @@
                batchID,
                "P2", 
-               gpc1Db.getCameraStageSmf(camID),
+               gpc1Db.getCameraStageSmf(camID,skychunk.P2_smf_version),
                useFullTables)
 
@@ -257,7 +257,13 @@
                ,psfWidMinor \
                ,psfTheta \
-               ,momentFwhm \
-               ,momentWidMajor \
-               ,momentWidMinor \
+               ,momentXX \
+               ,momentXY \
+               ,momentYY \
+               ,momentM3C \
+               ,momentM3S \
+               ,momentM4C \
+               ,momentM4S \
+               ,momentR1 \
+               ,momentRH \
                ,apResid \
                ,dapResid \
@@ -319,7 +325,13 @@
                ," + self.safeDictionaryAccess(header, 'FWHM_MIN') + " \
                ," + self.safeDictionaryAccess(header, 'ANGLE') + " \
-               , ( " + self.safeDictionaryAccess(header, 'IQ_FW1') + " + " + self.safeDictionaryAccess(header, 'IQ_FW2') + " ) / 2.0  \
-               ," + self.safeDictionaryAccess(header, 'IQ_FW1') + " \
-               ," + self.safeDictionaryAccess(header, 'IQ_FW2') + " \
+               ,-999 \
+               ,-999 \
+               ,-999 \
+               ,-999 \
+               ,-999 \
+               ,-999 \
+               ,-999 \
+               ,-999 \
+               ,-999 \
                ," + self.safeDictionaryAccess(header, 'APMIFIT') + " \
                ," + self.safeDictionaryAccess(header, 'DAPMIFIT') + " \
@@ -398,4 +410,5 @@
         sql = "INSERT IGNORE INTO " + pspsTableName + " ( \
                ippDetectID \
+               ,randomDetID \
                ,filterID \
                ,surveyID \
@@ -407,8 +420,8 @@
                ,psfFlux \
                ,psfFluxErr \
-               ,peakADU \
-               ,psfWidMajor \
-               ,psfWidMinor \
+               ,psfMajorFWHM \
+               ,psfMinorFWHM \
                ,psfTheta \
+               ,psfCore \
                ,psfLikelihood \
                ,psfQf \
@@ -416,4 +429,10 @@
                ,momentXY \
                ,momentYY \
+               ,momentR1 \
+               ,momentRH \
+               ,momentM3C \
+               ,momentM3S \
+               ,momentM4C \
+               ,momentM4S \
                ,apFlux \
                ,kronFlux \
@@ -424,12 +443,11 @@
                ,sky \
                ,skyErr \
-               ,sgSep \
-               ,activeFlag \
-               ,assocDate \
-               ,historyModNum \
+               ,pltScale \
+               ,posAngle \
                ,dataRelease \
                ) \
                SELECT \
                IPP_IDET \
+               , FLOOR(RAND()*9223372036854775807) \
                , " + str(self.filterID) + "\
                , " + str(self.surveyID) + " \
@@ -441,8 +459,8 @@
                ,PSF_INST_FLUX / " + self.header['EXPTIME'] + " \
                ,PSF_INST_FLUX_SIG / " + self.header['EXPTIME'] + " \
-               ,POW(10.0, (-0.4*PEAK_FLUX_AS_MAG)) / " + self.header['EXPTIME'] + " \
                ,PSF_MAJOR \
                ,PSF_MINOR \
                ,PSF_THETA \
+               ,-999 \
                ,psfLikelihood(EXT_NSIGMA) \
                ,PSF_QF \
@@ -450,4 +468,10 @@
                ,MOMENTS_XY \
                ,MOMENTS_YY \
+               ,MOMENTS_R1 \
+               ,MOMENTS_RH \
+               ,MOMENTS_M3C \
+               ,MOMENTS_M3S \
+               ,MOMENTS_M4C \
+               ,MOMENTS_M4S \
                ,POW(10.0, -0.4 *AP_MAG) / " + self.header['EXPTIME'] + " \
                ,KRON_FLUX / " + self.header['EXPTIME'] + " \
@@ -458,8 +482,6 @@
                ,SKY  / " + self.header['EXPTIME'] + " \
                ,SKY_SIGMA  / " + self.header['EXPTIME'] + " \
-               ,EXT_NSIGMA \
-               , 0 \
-               , '" + self.dateStr + "' \
-               , 0 \
+               ,PLTSCALE \
+               ,POSANGLE \
                , " + str(self.skychunk.dataRelease) + "\
                FROM " + ippTableName
@@ -496,5 +518,5 @@
         # we don't delete these anymore
         results['NULLINSTFLUX'] = 0;
-        results['NULLPEAKADU'] = 0;
+        
 
     '''
@@ -531,10 +553,10 @@
     def populateDetectionCalibTableUpdateInsert(self, ota):
 
-        tableName = "DetectionCalib_" + ota
+        tableName = "Detection_" + ota
         # drop then re-create table
-        self.scratchDb.dropTable(tableName)
-        sql = "CREATE TABLE " + tableName + " LIKE DetectionCalib"
-        try: self.scratchDb.execute(sql)
-        except: pass
+        #self.scratchDb.dropTable(tableName)
+        #sql = "CREATE TABLE " + tableName + " LIKE DetectionCalib"
+        #try: self.scratchDb.execute(sql)
+        #except: pass
 
         # insert all detections into table
@@ -555,5 +577,5 @@
                ,surveyID \
                FROM Detection_" + ota
-        self.scratchDb.execute(sql)
+#        self.scratchDb.execute(sql)
 
         # insert calibration information from dvoDetections into the Table
@@ -564,5 +586,4 @@
             a.decErr = b.decErr, \
             a.zp = b.zp, \
-            a.zpErr = b.zpErr, \
             a.expTime = b.expTime, \
             a.airMass = b.airMass   \
@@ -577,66 +598,33 @@
 
         # target table name:
-        tableName = "DetectionCalib_" + ota
+        tableName = "Detection_" + ota
         # drop then re-create table
-        self.scratchDb.dropTable(tableName)
-        sql = "CREATE TABLE " + tableName + " LIKE DetectionCalib"
-        try: self.scratchDb.execute(sql)
-        except: pass
+        #self.scratchDb.dropTable(tableName)
+        #sql = "CREATE TABLE " + tableName + " LIKE Detection"
+        #try: self.scratchDb.execute(sql)
+        #except: pass
 
         externID = self.imageIDs[ota]
 
         imageID = self.scratchDb.getImageIDFromExternID(externID)
-        self.logger.infoPair("obtained","imageID")
-
-        # check for & create output directory first
-        datadumpDir = "/tmp/datadump"
-        try:
-            statinfo = os.stat(datadumpDir)
-            # check on the stat results?
-        except:
-            print "making the data dump directory ", datadumpDir
-            os.mkdir(datadumpDir)
-            os.chmod(datadumpDir, 0777)
-            statinfo = os.stat(datadumpDir)
-
-        dumpFile = datadumpDir + "/genetest.xx.dat"
-        files = glob.glob(dumpFile)
-        if len(files) > 0:
-            os.unlink(dumpFile)
+        self.logger.infoPair("obtained imageID",imageID)
+        self.logger.infoPair("obtained externID",externID)
 
         # insert all detections into table
-        sql = "SELECT \
-          a.objID,    \
-          a.detectID, \
-          a.ippObjID,      \
-          a.ippDetectID,   \
-          a.filterID,      \
-          a.surveyID,      \
-          b.ra,            \
-          b.dec_,          \
-          b.raErr,         \
-          b.decErr,        \
-          b.zp,            \
-          b.zpErr,         \
-          b.expTime,       \
-          b.airMass,       \
-          " + str(self.skychunk.dataRelease) + " \
-         FROM              \
-           Detection_" + ota + " as a \
-         JOIN " + self.scratchDb.dvoDetectionTable + " as b \
-         ON (a.objID = b.objID AND a.detectID = b.detectID) \
-         WHERE b.imageID = " + str(imageID) + \
-         " INTO OUTFILE '" + dumpFile + "'"
+        sql = "Update Detection_" + ota + " AS a, "+ self.scratchDb.dvoDetectionTable + " as b \
+          set a.ra=b.ra,            \
+          a.dec = b.dec_,          \
+          a.raErr = b.raErr,         \
+          a.decErr = b.decErr,        \
+          a.zp = b.zp,            \
+          a.expTime = b.expTime,       \
+          a.airMass = b.airMass       \
+          WHERE (a.objID = b.objID AND a.detectID = b.detectID) \
+          AND b.imageID = " + str(imageID)  \
+ 
 
         try: self.scratchDb.execute(sql)
         except:
-            self.logger.info("failed to select data for detectionCalib")
-            self.logger.infoPair("sql: ", sql)
-            raise
-
-        sql = "LOAD DATA INFILE '" + dumpFile + "' INTO TABLE " + tableName
-        try: self.scratchDb.execute(sql)
-        except:
-            self.logger.info("failed to load data from infile for detectionCalib")
+            self.logger.info("failed to update data for detectionCalib")
             self.logger.infoPair("sql: ", sql)
             raise
@@ -751,5 +739,5 @@
         # dec is reserved in MySQL, so STILTS replaces if with dec_, which is not the name of 
         # the column in PSPS
-        self.scratchDb.execute("ALTER TABLE DetectionCalib CHANGE dec_ `dec` double")
+        self.scratchDb.execute("ALTER TABLE Detection CHANGE dec_ `dec` double")
 
         return True
@@ -818,23 +806,22 @@
             return False
 
-        self.logger.info("populate stuff ");
+        #self.logger.info("populate stuff ");
         # populate remainder of tables
         self.populateDetectionTable(chipname, results)
-        self.logger.info("successful populate ");
+        #self.logger.info("successful populate ");
         # now add DVO IDs
         self.updateDvoIDs("Detection_" + chipname, self.imageIDs[chipname])
-        self.logger.info("updated dvoids")
+        #self.logger.info("updated dvoids")
         results['NULLOBJID'] = self.scratchDb.reportAndDeleteRowsWithNULLS("Detection_" + chipname, "objID")
         #self.logger.info("deleted nulls")
         self.updateImageID("Detection_" + chipname, x, y)
-        self.logger.info("updateImageId")
+        #self.logger.info("updateImageId")
         rowCount = self.scratchDb.getRowCount("Detection_" + chipname) 
-        self.logger.info("got row count")
-        self.logger.info("| %5s | %13d | %13d | %13d | %13d | %13d | %13d |", 
+        #self.logger.info("got row count")
+        self.logger.info("| %5s | %13d | %13d | %13d | %13d | %13d |", 
                 chipname, 
                 results['ORIGINALTOTAL'], 
                 results['SATDET'], 
                 results['NULLINSTFLUX'], 
-                results['NULLPEAKADU'], 
                 results['NULLOBJID'],
                 rowCount)
@@ -842,5 +829,4 @@
         self.totalSatDet       = self.totalSatDet + results['SATDET']
         self.totalNulIInstFlux = self.totalNulIInstFlux + results['NULLINSTFLUX']
-        self.totalNullPeakFlux = self.totalNullPeakFlux + results['NULLPEAKADU']
         self.totalNullObjID    = self.totalNullObjID + results['NULLOBJID']
         self.totalDetections   = self.totalDetections + rowCount
@@ -867,11 +853,8 @@
         self.scratchDb.execute(sql)
         
-        self.logger.info("updated imagedata")
-        self.populateSkinnyObjectTable(chipname)
-        self.logger.info("updated skinnyobject")
-        #self.populateObjectCalColorTable(chipname)
-        #self.logger.info("updated objectcalcolor")
+        #self.logger.info("updated imagedata")
+        
         self.populateDetectionCalibTable(chipname)
-        self.logger.info("updated detectioncalibtable")
+        #self.logger.info("updated detectioncalibtable")
         
         # add these to list of tables to export later
@@ -882,11 +865,5 @@
         self.logger.info("export Detection")
 
-        self.tablesToExport.append("SkinnyObject_" + chipname)
-        self.logger.info("export Skinny")
-
-        #self.tablesToExport.append("ObjectCalColor_" + chipname)
-        self.tablesToExport.append("DetectionCalib_" + chipname)
-        self.logger.info("export DetectionCalib")
-
+        
         tables.append("Detection_" + chipname)
         self.logger.info("updated detectioncalibtable")
@@ -910,7 +887,7 @@
         results = {}
         self.totalOriginal = self.totalSatDet = self.totalNulIInstFlux = self.totalNullPeakFlux = self.totalNullObjID = self.totalDetections = 0
-        self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+---------------+")
-        self.logger.info("|  OTA  | Initial total |   Sat Det     | NULL instFlux | NULL peak ADU | NULL obj ID   |  Remainder    |")
-        self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+---------------+")
+        self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+")
+        self.logger.info("|  OTA  | Initial total |   Sat Det     | NULL instFlux | NULL obj ID   |  Remainder    |")
+        self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+")
         for x in range(self.startX, self.endX):
             for y in range(self.startY, self.endY):
@@ -937,5 +914,5 @@
 
         # print totals
-        self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+---------------+")
+        self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+")
         self.logger.info("| Total | %13d | %13d | %13d | %13d | %13d | %13d |", 
                 self.totalOriginal, 
@@ -945,5 +922,5 @@
                 self.totalNullObjID,
                 self.totalDetections)
-        self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+---------------+")
+        self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+")
 
         # if we only have one table export, i.e. FrameMeta, then get out of here (skip batch, but do not abort)
@@ -961,4 +938,7 @@
         sql = "UPDATE FrameMeta SET nOTA = %d, numPhotoRef = %d" % (otaCount, self.totalNumPhotoRef)
         self.scratchDb.execute(sql)
+        #to make it stop
+        #test = self.scratchDb.getRowCount("Object")
+        #return False
         
         return True
@@ -1040,5 +1020,5 @@
 
        # XXX EAM NOTE : this is fragile : requires PS1_V4
-       columns = "IPP_IDET X_PSF Y_PSF X_PSF_SIG Y_PSF_SIG PSF_INST_MAG PSF_INST_MAG_SIG PSF_INST_FLUX PSF_INST_FLUX_SIG PEAK_FLUX_AS_MAG PSF_MAJOR PSF_MINOR PSF_THETA EXT_NSIGMA PSF_QF MOMENTS_XX MOMENTS_XY MOMENTS_YY AP_MAG KRON_FLUX KRON_FLUX_ERR FLAGS FLAGS2 SKY SKY_SIGMA EXT_NSIGMA PSF_QF_PERFECT PSF_CHISQ"
+       columns = "IPP_IDET X_PSF Y_PSF X_PSF_SIG Y_PSF_SIG PSF_INST_MAG PSF_INST_MAG_SIG PSF_INST_FLUX PSF_INST_FLUX_SIG PEAK_FLUX_AS_MAG PSF_MAJOR PSF_MINOR PSF_THETA EXT_NSIGMA PSF_QF MOMENTS_XX MOMENTS_XY MOMENTS_YY MOMENTS_R1 MOMENTS_RH MOMENTS_M3C MOMENTS_M3S MOMENTS_M4C MOMENTS_M4S AP_MAG KRON_FLUX KRON_FLUX_ERR FLAGS FLAGS2 SKY SKY_SIGMA EXT_NSIGMA PSF_QF_PERFECT PSF_CHISQ POSANGLE PLTSCALE"
 
        return super(DetectionBatch, self).importIppTables(columns, regex)
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/dvo.py
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/dvo.py	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/dvo.py	(revision 37066)
@@ -65,5 +65,5 @@
         if not self.correctDvo:
             print "*******************************************************************************"
-            self.logger.warning("switching to a new dvo: " + self.skychunk.dvoLocation)
+            self.logger.warning("switching to a new dvo: '" + self.skychunk.dvoLocation + "'")
             # response = raw_input("(y/n) ")
             # if response == "y":
@@ -518,5 +518,7 @@
           self.logger.debugPair("Reading IPP table", table.name)
           table = stilts.tpipe(table, cmd='explodeall')
-     
+          #adds an index to all the tables 
+       #   table = stilts.tpipe(table, cmd='addcol table_index $0')
+
           # IPP FITS files are littered with infinity values. Remove them
           self.logger.debugPair("Removing", "infinity values")
@@ -628,4 +630,17 @@
         maxDEC = boxDim['maxDEC'] + dD_border
 
+        #find out if we use a time_range or not
+        valid_trange_start = 0
+        valid_trange_end = 0
+        use_trange = 0 
+        if (self.skychunk.trange_start != '0000-00-00 00:00:00'):
+            valid_trange_start = 1
+        if (self.skychunk.trange_end != '0000-00-00 00:00:00'):
+            valid_trange_end = 1             
+
+        if (valid_trange_start and valid_trange_end):
+            use_trange = 1
+
+
         # TODO path to DVO prog hardcoded temporarily
         cmd = "dvopsps detections"
@@ -644,4 +659,34 @@
             cmd += " -parallel"
 
+        if use_trange:
+            # make tranges valid for dvopsps
+            time_start1 = self.skychunk.trange_start
+            time_end1 = self.skychunk.trange_end
+            time_start=re.sub('\s+',',',time_start1)
+            time_end=re.sub('\s+',',',time_end1)
+           
+            # make command
+            cmd += " -time-start " + time_start
+            cmd += " -time-end " + time_end
+
+        useP2 = 0    
+        useST = 0
+        
+        for batchType in self.skychunk.batchTypes:
+            self.logger.infoPair("batchType", batchType)
+            if batchType == "ST":
+                useST = 1
+            if batchType == "P2":
+                useP2 = 1
+
+        if (useP2 ==0 and useST ==1):
+            #grab only stacks
+            cmd += " -photcode-start 11000 -photcode-end 11500"
+
+        if (useP2 ==1 and useST==0):
+            #grabd only P2s    
+            cmd += " -photcode-start 10000 -photcode-end 10577"
+
+
         self.logger.infoPair("Running dvopsps", cmd)
         p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/dxlayer.py
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/dxlayer.py	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/dxlayer.py	(revision 37066)
@@ -25,4 +25,5 @@
     '''
     def deleteBatch(self, batchID):
+        #HAF This is really lazy to do this way, but for the time, will check both dx layers and try the first, if no go try the second.
 
         batch = Batch.getNameFromID(batchID)
@@ -36,5 +37,29 @@
        
         if p.returncode != 0:
-           self.logger.debugPair("DXLayer webservice", "failed")
+           self.logger.infoPair("DXLayer webservice", "failed")
+           return 0
+        else:
+           self.logger.infoPair("DXLayer webservice", "successful")
+
+        ret = self.decodeDXLayerResponse(tempFile.name)
+
+        tempFile.close()
+        p.stdout.close()
+
+        if ret: self.logger.infoPair("Deleted batch from DXLayer 1", batch) 
+        else: self.logger.infoPair("Unable to delete batch from DXLayer 1" , batch)
+
+
+       
+
+        tempFile = tempfile.NamedTemporaryFile(mode='w+b')
+
+        p = Popen("deleteFromDXLayer2.pl -b " + batch + " -f " + tempFile.name, 
+                shell=True, 
+                stdout=PIPE)
+        p.wait()
+       
+        if p.returncode != 0:
+           self.logger.infoPair("DXLayer webservice", "failed")
            return 0
         else:
@@ -46,8 +71,12 @@
         p.stdout.close()
 
-        if ret: self.logger.infoPair("Deleted batch from DXLayer", batch) 
-        else: self.logger.errorPair("Unable to delete batch from DXLayer", batch)
+        if ret: self.logger.infoPair("Deleted batch from DXLayer 2", batch) 
+        else: self.logger.infoPair("Unable to delete batch from DXLayer 2" , batch)
+
+
+
 
         return ret
+
 
     '''
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/gpc1db.py
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/gpc1db.py	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/gpc1db.py	(revision 37066)
@@ -49,9 +49,9 @@
     NB this uses Bill's potentially temporary 'skycells' database when finding RA/Dec for stacks.
     '''
-    def getItemsInThisDVODbForThisStage(self, dvoDb, batchType, minRA=-999, maxRA=999, minDec=-999, maxDec=999):
+    def getItemsInThisDVODbForThisStage(self, dvoDb, batchType, minRA=-999, maxRA=999, minDec=-999, maxDec=999, tstart="0000-00-00 00:00:00", tend = "0000-00-00 00:00:00"):
 
         self.logger.debugPair("GPC1 RA range", "%.2f -> %.2f" % (minRA, maxRA))
         self.logger.debugPair("GPC1 Dec range", "%.2f -> %.2f" % (minDec, maxDec))
-
+        
         rows = []
 
@@ -80,10 +80,12 @@
                    AND addRun.state = 'full' \
                    AND decl BETWEEN RADIANS(" + str(minDec) + ") AND RADIANS(" + str(maxDec) + ") \
-                   AND ra BETWEEN RADIANS(" + str(minRA) + ") AND RADIANS(" + str(maxRA) + ")"
+                   AND ra BETWEEN RADIANS(" + str(minRA) + ") AND RADIANS(" + str(maxRA) + ") \
+                   AND dateobs >= '" + tstart + "'\
+                   AND dateobs <= '" + tend  + "'"
 
         elif batchType == "ST":       
 
             stage = "skycal"
-            sql = "SELECT DISTINCT stack_id, radeg, decdeg FROM skycalRun \
+            sql = "SELECT DISTINCT sky_id, radeg, decdeg FROM skycalRun \
                    JOIN addRun ON(skycalRun.skycal_id = addRun.stage_id) \
                    JOIN minidvodbRun USING(minidvodb_name) \
@@ -91,5 +93,7 @@
                    JOIN mergedvodbRun USING(minidvodb_id) \
                    JOIN mergedvodbProcessed USING (merge_id) \
-                   JOIN  stackRun USING(stack_id) JOIN skycell USING(skycell_id) \
+                   JOIN stackRun USING(stack_id) \
+                   JOIN stackSumSkyfile using (stack_id) \
+                   JOIN skycell USING(skycell_id) \
                    WHERE mergedvodbRun.mergedvodb = '" + dvoDb + "' \
                    AND minidvodbRun.state = 'merged' \
@@ -100,6 +104,18 @@
                    AND addRun.state = 'full' \
                    AND decdeg BETWEEN " + str(minDec) + " AND " + str(maxDec) + " \
-                   AND radeg BETWEEN " + str(minRA) + " AND " + str(maxRA) 
+                   AND radeg BETWEEN " + str(minRA) + " AND " + str(maxRA) + " \
+                   AND mjd_obs >= (to_days('" + tstart + "')-678941) \
+                   AND mjd_obs <= (to_days('" + tend + "') - 678941) "
+           # self.logger.infoPair("sql",sql)      
+        elif batchType == "DF":
+
+            stage = "diff"
+            sql = "SELECT stuff from stufftable"
+
+        elif batchType == "FW":
             
+            stage = "forcedwarp"
+            sql = "SELECT differentStuff from Stufftable"
+
         try:
             # XXX EAM : test output
@@ -212,6 +228,6 @@
     Gets a camera-stage smf for this cam_id
     '''
-    def getCameraStageSmf(self, camID):
-
+    def getCameraStageSmf(self, camID, smfversion):
+        self.logger.infoPair("using", smfversion)
         self.logger.debug("Querying GPC1 for camera smf files with cam_id = " + str(camID))
 
@@ -237,14 +253,89 @@
         # list all smf files if a neb path
         files = []
-        if path.startswith("neb"):
-
-            # XXX EAM : this should just use the name (path.smf) instead of a wildcard, right?
-            f=os.popen("neb-ls -p "+path+"%smf")
-            for i in f.readlines():
-                files.append(i.rstrip())
-
-        # or not a neb path
-        else:
-            files = glob.glob(path + ".smf")
+
+
+        #there are a couple of states for smfversion
+
+        # "use_new" => we have reprocessed the data, use the .smf file
+
+        # "not_reproc" => this has not been reprocessed, use the .smf file
+
+        # "use_original" => we *may* have reprocessed the data, 
+        #    use (file).smf.original if camRun.state = 'full' and if there is a .smf and .orig
+        #    use (file).smf if camRun.state = 'full' and if there is only a .smf
+        #    fault out if camRun.state != 'full' -- that is a race condition we don't want.
+       
+        
+        if (smfversion == "not_reproc") or (smfversion == "use_new"):
+            if path.startswith("neb"):
+
+                # XXX EAM : this should just use the name (path.smf) instead of a wildcard, right?
+                f=os.popen("neb-ls -p "+path+"%smf")
+                for i in f.readlines():
+                    files.append(i.rstrip())
+
+                # or not a neb path
+            else:
+                files = glob.glob(path + ".smf")
+
+        if (smfversion == "use_original"):
+            # get state of camRun
+            sql = "SELECT state \
+               FROM camProcessedExp \
+               JOIN camRun USING(cam_id) \
+               WHERE camRun.cam_id = %d" % camID
+            try:
+                rs = self.executeQuery(sql)
+                rs.first()
+            except:
+                self.logger.errorPair("Can't query for camRun.state for cam_id",  str(camID))
+                return None
+
+            try:
+                # get state of camRun.cam_id
+                camrunstate = rs.getString(1)
+            except:
+                self.logger.errorPair("No state found for cam_id", str(camID) )
+                return None
+            
+            if (camrunstate == "full"):
+              self.logger.infoPair("camRun.state is ",camrunstate)   
+                 # if full find smf files
+              if path.startswith("neb"):
+
+                 # XXX EAM : this should just use the name (path.smf) instead of a wildcard, right?
+                 fsmf=os.popen("neb-ls -p "+path+"%smf")
+                 fsmfs = fsmf.readlines()
+                 fsmforig=os.popen("neb-ls -p "+path+"%smf.original")
+                 fsmforigs = fsmforig.readlines()
+                 smfCount = len(fsmfs)
+                 smfOrigCount = len (fsmforigs)
+
+                 if (smfCount > 0  and smfOrigCount > 0):
+                     #smf and original  so use original
+                     self.logger.infoPair("using:", path+"%smf.original")
+                     for i in fsmforigs:
+                         files.append(i.rstrip())
+
+                 if (smfCount > 0 and smfOrigCount == 0):
+                     self.logger.infoPair("using:", path+"%smf")
+                     #smf file and no smf.original use .smf
+                     for i in fsmfs:
+                         files.append(i.rstrip())
+
+                 #if not smf dont' find files ??)        
+                 # or not a neb path
+
+              else:
+                # this is broken for non neb - on the other hand we probably won't do .original if so
+                files = glob.glob(path + ".smf")
+
+
+
+            # if .smf and .original use .original
+            else:
+                self.logger.infoPair("camRun.state not full, can't ingest", str(camID) )
+                return None
+
 
         # XXX EAM : test output
@@ -307,5 +398,5 @@
 
         # print "staring stack stage cmf"
-
+        #self.logger.infoPair("in stackstagecmf - sql is: ", sql) 
         # get single path base for the directory containing all cmf files, one of which is hopefully for our stack_id
         try:
@@ -408,2 +499,47 @@
 
 
+    '''
+    grabs the stackID for a particular skyId, filter, and dvodb
+    the mapping of stack_id from sky_id is not unique unless
+    joined to the dvodb 
+    '''
+    def getStackIDFromSkyIDAndFilter(self,dvoDb,skyID,filter):
+
+        self.logger.infoPair("finding stack_ids from gpc1 for sky_id ", skyID)
+
+        sql = "SELECT DISTINCT stack_id from skycalRun \
+               JOIN addRun ON(skycalRun.skycal_id = addRun.stage_id) \
+               JOIN minidvodbRun USING(minidvodb_name) \
+               JOIN minidvodbProcessed USING(minidvodb_id) \
+               JOIN mergedvodbRun USING(minidvodb_id) \
+               JOIN mergedvodbProcessed USING(merge_id) \
+               JOIN stackRun USING (stack_id) \
+               WHERE mergedvodbRun.mergedvodb = '" + dvoDb + "' \
+               AND minidvodbRun.state = 'merged' \
+               AND minidvodbProcessed.fault = 0 \
+               AND mergedvodbRun.state = 'full' \
+               AND mergedvodbProcessed.fault = 0  \
+               AND addRun.stage = 'skycal' \
+               AND addRun.state = 'full' \
+               AND filter = '" + filter + "' \
+               AND sky_id = %d" % skyID 
+
+#        self.logger.infoPair("sql",sql)
+
+        try:
+            rs = self.executeQuery(sql)
+                         
+        except:    
+            self.logger.exception("can't query for stackid in DVO")
+            self.logger.infoPair("failed sql:", sql)
+            return 0
+
+        rs.first()
+        try:
+            stackid = rs.getInt(1)
+            self.logger.infoPair("found stack_ID", stackid)
+        except:
+            stackid = -999
+            self.logger.infoPair("using stack_ID",stackid)
+            
+        return stackid    
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/insert.dvodb.info.py
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/insert.dvodb.info.py	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/insert.dvodb.info.py	(revision 37066)
@@ -0,0 +1,150 @@
+#!/usr/bin/env jython
+
+#
+# The main loading program for ippToPsps. See usage below.
+#
+
+import time
+import sys
+import os
+import math
+import logging.config
+
+from ipptopsps import IppToPsps
+from gpc1db import Gpc1Db
+from datastore import Datastore
+from dvoobjects import DvoObjects
+from batch import Batch
+from scratchdb import ScratchDb
+
+'''
+Queue class
+'''
+class Queue(IppToPsps):
+
+    '''
+    Constructor
+    '''
+    def __init__(self, argv):
+        super(Queue, self).__init__(argv)
+
+        # print "inited ipptopsps"
+
+        # create various objects
+        self.gpc1Db = Gpc1Db(self.logger, self.config)
+        # print "connect to gpc1"
+
+        self.datastore = Datastore(self.logger, self.skychunk, self.ippToPspsDb)
+
+        print "made datastore"
+
+        # connect to scratch database
+        self.scratchDb = ScratchDb(self.logger, self.config)
+
+        print "connect to scratchdb"
+
+        try:
+            print "why doesn't this work"
+            self.dvoObjects = DvoObjects(self.logger, self.config, self.skychunk, self.ippToPspsDb, self.scratchDb)
+        except:
+            self.exitProgram("Unable to create instance of DvoObject")
+            raise
+
+        print "got objects"
+
+        self.skychunk.printAll()
+
+        if len(argv) > 2: self.parsePollTimeArg(sys.argv[2])
+
+    '''
+    Main processing loop.
+    Tiled area is defined in 'skychunk' and looks for available stage_ids for each tile and writes them to ippToPsps database ready for processing
+    by one or more loading clients that may be running on any host
+    '''
+    def run(self):
+        print "here"
+        # this outer while loop simply waits a few minutes then starts queuing again (as more stuff may appear in DVO over time)
+        while True:
+
+      #      self.ippToPspsDb.removeAllBoxes()
+            print "remove boxes" 
+            # queue up batches that are processed but not loaded to datastore
+            for batchType in self.skychunk.batchTypes: 
+                self.logger.infoPair("BatchType",batchType)
+                #self.logger.infoTitle("Previous failed datastore loads")
+                #self.publishAnyUnpublishedBatches(batchType)
+
+                # get totals for whole area to check if there is anything to do
+                processedIDs = self.ippToPspsDb.getProcessedIDs(batchType)
+                print "got processed ids"
+                consistantlyFailedIDs = self.ippToPspsDb.getConsistentlyFailedIDs(batchType)
+                print "got here"
+                # for object batches, get full list of stuff from Dvo
+                # XXX : need to fix 'dvo.setSkyArea' or this may not return the full list for a parallel dvo
+            #for object-like batches, info comes from dvo
+                if (batchType == "OB" or batchType =="DO" or batchType =="FO"):
+                    self.dvoObjects.setSkyArea(
+                            self.skychunk.minRa,
+                            self.skychunk.maxRa,
+                            self.skychunk.minDec,
+                            self.skychunk.maxDec)
+                    rows = self.dvoObjects.allPopulatedRegionInfo
+                    self.dvoObjects.printSummary()
+
+                # for other batches, info comes from gpc1 database
+                else:
+                    rows = self.gpc1Db.getItemsInThisDVODbForThisStage(
+                            self.skychunk.dvoLabel, 
+                            batchType, 
+                            self.skychunk.minRa, 
+                            self.skychunk.maxRa, 
+                            self.skychunk.minDec, 
+                            self.skychunk.maxDec,
+                            self.skychunk.trange_start,
+                            self.skychunk.trange_end)
+
+                # EAM TEST I/O
+                self.logger.infoPair("received rows from db:", len(rows))
+
+                # first report total stuff
+                allIDs = []
+                for row in rows:
+                    try: allIDs.append(row[0])
+                    except: pass
+
+                ids = list(set(allIDs) - set(processedIDs) - set(consistantlyFailedIDs))
+                self.logger.infoPair("All unprocessed items", "%d" % len(ids))
+
+                # now trim full list down to only pending stuff
+                pending = [[], [], []]
+                for row in rows:
+                    try:
+                        findId = row[0]
+                    except: continue
+                    if findId in allIDs: pending.append([row[0], row[1], row[2]])
+
+                # store all items in temp table
+                self.logger.infoPair("Inserting all pending items into", "ippToPsps database")
+                self.ippToPspsDb.storeAllItemsInDvodb(pending, self.skychunk.dvoLabel, batchType)
+
+                self.logger.info("+-------------+-------------+-------------+-------------+")
+
+            self.checkClientStatus()
+            if not self.waitForPollTime(): break
+
+    '''
+    Overrides base-class version
+    '''
+    def printUsage(self):
+        super(Queue, self).printUsage("[<repeat time in hours>]")
+
+
+'''
+Start of program.
+'''
+try:
+    queue = Queue(sys.argv)
+    queue.run()
+    queue.exitProgram("completed")
+except: pass
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/ipptopspsdb.py
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/ipptopspsdb.py	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/ipptopspsdb.py	(revision 37066)
@@ -39,4 +39,6 @@
                AND batch_type = '" + batchType + "' \
                AND dvo_db = '" + self.skychunk.dvoLabel + "' \
+               AND comment = '" + self.skychunk.name + "' \
+               AND datastore_product = '" + self.skychunk.datastoreProduct + "' \
                AND merged = 1 \
                AND deleted_local = 0 \
@@ -65,4 +67,6 @@
                AND batch_type = '" + batchType + "' \
                AND dvo_db = '" + self.skychunk.dvoLabel + "' \
+               AND comment = '" + self.skychunk.name + "' \
+               AND datastore_product = '" + self.skychunk.datastoreProduct + "' \
                AND purged = 1 \
                AND deleted_local = 0 \
@@ -92,4 +96,6 @@
                AND batch_type = '" + batchType + "' \
                AND dvo_db = '" + self.skychunk.dvoLabel + "' \
+               AND comment = '" + self.skychunk.name + "' \
+               AND datastore_product = '" + self.skychunk.datastoreProduct + "' \
                AND purged = 1 \
                AND deleted_datastore = 0 \
@@ -119,5 +125,7 @@
                AND batch_type = '" + batchType + "' \
                AND dvo_db = '" + self.skychunk.dvoLabel + "' \
-               AND (loaded_to_ODM = -1 OR merge_worthy = 1) \
+               AND comment = '" + self.skychunk.name + "' \
+               AND datastore_product = '" + self.skychunk.datastoreProduct + "' \
+               AND (merge_worthy = 1) \
                AND deleted_datastore = 0 AND block_delete_datastore = 0"
 
@@ -144,5 +152,5 @@
                AND batch_type = '" + batchType + "' \
                AND dvo_db = '" + self.skychunk.dvoLabel + "' \
-               AND (loaded_to_ODM = -1 OR merge_worthy = 1) \
+               AND (merge_worthy = 1) \
                AND deleted_dxlayer = 0 and block_delete_dxlayer = 0"
 
@@ -1108,5 +1116,13 @@
         ,queue_ST \
         ,queue_OB \
+        ,queue_DF \
+        ,queue_DO \
+        ,queue_FW \
+        ,queue_FO \
         ,parallel \
+        ,P2_smf_version \
+        ,ST_cmf_version \
+        ,trange_start \
+        ,trange_end \
         FROM skychunk \
         WHERE name = '" + self.skychunk.name + "'"
@@ -1150,9 +1166,17 @@
             if rs.getInt(20) == 1: self.skychunk.batchTypes.append("ST")
             if rs.getInt(21) == 1: self.skychunk.batchTypes.append("OB")
+            if rs.getInt(22) == 1: self.skychunk.batchTypes.append("DF")
+            if rs.getInt(23) == 1: self.skychunk.batchTypes.append("DO")
+            if rs.getInt(24) == 1: self.skychunk.batchTypes.append("FW")
+            if rs.getInt(25) == 1: self.skychunk.batchTypes.append("FO")
 
             self.skychunk.force = True # TODO
             self.skychunk.parallel = False # TODO
 
-            if rs.getInt(22) == 1: self.skychunk.parallel = True
+            if rs.getInt(26) == 1: self.skychunk.parallel = True
+            self.skychunk.P2_smf_version = rs.getString(27)
+            self.skychunk.ST_cmf_version = rs.getString(28)
+            self.skychunk.trange_start = rs.getString(29)
+            self.skychunk.trange_end = rs.getString(30) 
 
             if self.skychunk.parallel: print "USING parallel"
@@ -1627,4 +1651,32 @@
         # self.logger.infoPair("Items written to alt Db", "%d" % count)
 
+
+    '''
+    Creates a temporary table and shoves it full of stage_ids and ra/dec coords
+    '''
+    def storeAllItemsInDvodb(self, rows, dvo_db, batchType):
+
+        #try:
+        #    self.execute("DROP TABLE all_pending")
+        #except:
+        #    pass
+
+        #self.execute("CREATE TEMPORARY TABLE all_pending (stage_id bigint(20), ra_bore float, dec_bore float)")
+        for row in rows:
+
+            try:
+                uniq = dvo_db + "."+ batchType + "." + str(row[0])
+                sql = "INSERT INTO dvodb (dvo_db, batch_type, stage_id, ra_center, dec_center, uniq_key) \
+                       VALUES ( '" + dvo_db + "', '" + batchType + "'," + str(row[0]) + "," + str(row[1]) + " \
+                       , " + str(row[2]) + ", '"+uniq+"' ) " 
+                print "sql 1: ", sql
+                self.execute(sql)
+            except: continue
+
+        #count = self.getRowCount("all_pending")
+        #self.logger.infoPair("Items written to Db", "%d" % count)
+
+
+
     '''
     Gets all items in the all_pending temporary table within the bounds of this box
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/loader.py
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/loader.py	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/loader.py	(revision 37066)
@@ -182,5 +182,5 @@
                             # XXXX EAM : in parallel model, this should happen for all P2 & Stack batches
                             # 
-                            if (batchType == 'P2' or batchType == 'ST') and smfsPerGB > 30:
+                            if (batchType == 'P2' or batchType == 'ST' or batchType == 'DF' or batchType == 'FW') and smfsPerGB > 30:
                                 if not self.dvoDetections.sync():
                                     self.logger.errorPair("Could not sync DVO with MySQL", "skipping")
@@ -234,24 +234,25 @@
         # loop round IDs of all items to be processed
         self.ippToPspsDb.lockBatchTable()
-        self.logger.infoPair("heather:","lockbatchtable")
+        #self.logger.infoPair("heather:","lockbatchtable")
         unattemptedCount = 0
         for id in ids:
-            self.logger.infoPair("heather:","in ids")
-            self.logger.infoPair("heather:id",str(id))
+            #self.logger.infoPair("heather:","in ids")
+            #self.logger.infoPair("heather:id",str(id))
             batchID = self.ippToPspsDb.createNewBatch(batchType, id)
-            self.logger.infoPair("heather:","creatednewbatch")
-            self.logger.infoPair("heather:batchId", str(batchID))
+            #self.logger.infoPair("heather:","creatednewbatch")
+            #self.logger.infoPair("heather:batchId", str(batchID))
             if batchID < 0: 
                 unattemptedCount += 1
                 continue
-            self.logger.infoPair("heather:","passed logic")
+            #self.logger.infoPair("heather:","passed logic")
             self.ippToPspsDb.unlockTables()
-            self.logger.infoPair("heather:","unlock table")
+            #self.logger.infoPair("heather:","unlock table")
             self.ippToPspsDb.deletePendingItem(batchType, id)
-            self.logger.infoPair("heather:","deleted pending item")
+            #self.logger.infoPair("heather:","deleted pending item")
 
             # catch any raised exceptions in batch constructors
             try:
                 if batchType == "P2":
+                    self.logger.infoPair("defining P2 batch for cam_id:",id)
                     batch = DetectionBatch(self.logger,
                             self.config,
@@ -264,4 +265,5 @@
                             useFullTables)
                 elif batchType == "ST":
+                    self.logger.infoPair("defining ST batch for sky_id:",id)
                     batch = StackBatch(self.logger,
                             self.config,
@@ -285,4 +287,48 @@
                             useFullTables)
     
+                elif batchType == "DF":
+                    batch = DiffBatch(self.logger,
+                            self.config,
+                            self.skychunk,
+                            self.gpc1Db,
+                            self.ippToPspsDb,
+                            self.scratchDb,
+                            id,
+                            batchID,
+                            useFullTables)
+    
+                elif batchType == "DO":
+                    batch = DiffObjectBatch(self.logger,
+                            self.config,
+                            self.skychunk,
+                            self.gpc1Db,
+                            self.ippToPspsDb,
+                            self.scratchDb,
+                            id,
+                            batchID,
+                            useFullTables)
+    
+                elif batchType == "FW":
+                    batch = ForcedWarpBatch(self.logger,
+                            self.config,
+                            self.skychunk,
+                            self.gpc1Db,
+                            self.ippToPspsDb,
+                            self.scratchDb,
+                            id,
+                            batchID,
+                            useFullTables)
+    
+                elif batchType == "FO":
+                    batch = ForcedObjectBatch(self.logger,
+                            self.config,
+                            self.skychunk,
+                            self.gpc1Db,
+                            self.ippToPspsDb,
+                            self.scratchDb,
+                            id,
+                            batchID,
+                            useFullTables)
+                    
                 batch.run()
    
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/metrics.py
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/metrics.py	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/metrics.py	(revision 37066)
@@ -48,4 +48,8 @@
             rateST = self.printStats("ST")
             rateOB = self.printStats("OB")
+            rateDF = self.printStats("DF")
+            rateDO = self.printStats("DO")
+            rateFW = self.printStats("FW")
+            rateFO = self.printStats("FO")
             self.logger.info("+----+------------------+---------------+-------------------+------------------+----------------+")
         
@@ -66,4 +70,8 @@
             pendSTProcessed = self.printTableRow(stages, "ST")
             pendOBProcessed = self.printTableRow(stages, "OB")
+            pendDFProcessed = self.printTableRow(stages, "DF")
+            pendDOProcessed = self.printTableRow(stages, "DO")
+            pendFWProcessed = self.printTableRow(stages, "FW")
+            pendFOProcessed = self.printTableRow(stages, "FO")
             self.writeTableSeparator(colCount)
 
@@ -75,12 +83,23 @@
             try: self.logger.infoPair("Estimated time for OBs", "%.1f hours" % (pendOBProcessed / rateOB)) 
             except: pass
+            try: self.logger.infoPair("Estimated time for DFs", "%.1f hours" % (pendDFProcessed / rateDF)) 
+            except: pass
+            try: self.logger.infoPair("Estimated time for DOs", "%.1f hours" % (pendDOProcessed / rateDO)) 
+            except: pass
+            try: self.logger.infoPair("Estimated time for FWs", "%.1f hours" % (pendFWProcessed / rateFW)) 
+            except: pass
+            try: self.logger.infoPair("Estimated time for FOs", "%.1f hours" % (pendFOProcessed / rateFO)) 
+            except: pass
        
             self.checkClientStatus()
-            self.logger.infoPair("here","yay")
+            self.logger.infoPair("creating density plots","")
             # create a density plot of pending stuff for czartool
             self.plot.createDensityPlot("P2", True)
             self.plot.createDensityPlot("ST", True)
             self.plot.createDensityPlot("OB", True)
-            self.logger.infoPair("here","yay2")
+            self.plot.createDensityPlot("DF", True)
+            self.plot.createDensityPlot("DO", True)
+            self.plot.createDensityPlot("FW", True)
+            self.plot.createDensityPlot("FO", True)
             # some clean-up before going to sleep
             self.ippToPspsDb.purgeDeadClients()
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/objectbatch.py
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/objectbatch.py	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/objectbatch.py	(revision 37066)
@@ -91,5 +91,6 @@
 
         # dec is reserved in MySQL, so STILTS replaces if with dec_, which PSPS doesn't like. so, force it back again using ``
-        self.scratchDb.execute("ALTER TABLE Object CHANGE dec_ `dec` double")
+      #  self.scratchDb.execute("ALTER TABLE MeanObject CHANGE dec_ `dec` double")
+      #  self.scratchDb.execute("ALTER TABLE ObjectThin CHANGE dec_ `dec` double")
 
         return True
@@ -107,5 +108,5 @@
     Inserts stuff for all mags
     '''
-    def insertMags(self, cpsTable):
+    def updateMeanObjectFromCps(self, cpsTable):
 
         # list of all filters PSPS is interested in
@@ -129,40 +130,28 @@
 	    # from bit 24 to bit 13 so that it fits into the SMALLINT Object.Flags
 
-            sql = "UPDATE Object JOIN \
-                   " + cpsTable + " AS cps ON (cps.row = (Object.row* " + str(filterCount) + ")-(" + str(filterCount) + " - " + str(filter[0]) + ")) \
+            sql = "UPDATE MeanObject JOIN \
+                   " + cpsTable + " AS cps ON (cps.row = (MeanObject.row* " + str(filterCount) + ")-(" + str(filterCount) + " - " + str(filter[0]) + ")) \
                    SET \
-                   n" + filter[1] + " = NCODE \
-                   ," + filter[1] + "MeanPSFMag = MAG \
-                   ," + filter[1] + "MeanPSFMagErr = MAG_ERR \
-                   ," + filter[1] + "MeanKronMag = MAG_KRON \
-                   ," + filter[1] + "MeanKronMagErr = MAG_KRON_ERR \
-                   ," + filter[1] + "StackPSFMag = STACK_PSF_MAG \
-                   ," + filter[1] + "StackPSFMagErr = STACK_PSF_MAG_ERR \
-                   ," + filter[1] + "StackKronMag = STACK_KRON_MAG \
-                   ," + filter[1] + "StackKronMagErr = STACK_KRON_MAG_ERR \
-                   ," + filter[1] + "20pct = MAG_20/1000 \
-                   ," + filter[1] + "80pct = MAG_80/1000 \
-                   ," + filter[1] + "Flags = (0x7fff & FLAGS) | ((FLAGS >> 11) & 0x2000) \
-                   ," + filter[1] + "StackDetectID = STACK_DETECT_ID"
-
-# old method for setting the Stack (PSF,Kron) Mags:
-#                  ," + filter[1] + "StackPSFMag = -2.5 * log10(FLUX_PSF) + 8.9 \
-#                  ," + filter[1] + "StackPSFMagErr = FLUX_PSF_ERR / FLUX_PSF \
-#                  ," + filter[1] + "StackKronMag = -2.5 * log10(FLUX_KRON) + 8.9 \
-#                  ," + filter[1] + "StackKronMagErr = FLUX_KRON_ERR / FLUX_KRON \
-
-            #self.logger.info(sql)
-            self.scratchDb.execute(sql)
-
-        self.logger.infoPair("Calculating nDetections from", "n[filters]")
-        for filter in filters:
-            # now do a sum of n[filters], but do not include the ones with -999
-            sql = "UPDATE Object \
-                   SET nDetections = nDetections + n" + filter[1] + " \
-                   WHERE n" + filter[1] + " != -999"
-            self.scratchDb.execute(sql)
-            
-
-
+                   MeanObject." + filter[1] + "QfPerfect = -999 \
+                   ,MeanObject." + filter[1] + "MeanPSFMag = MAG \
+                   ,MeanObject." + filter[1] + "MeanPSFMagErr = MAG_ERR \
+                   ,MeanObject." + filter[1] + "MeanKronMag = MAG_KRON \
+                   ,MeanObject." + filter[1] + "MeanKronMagErr = MAG_KRON_ERR \
+                   ,MeanObject." + filter[1] + "nIncPSFMag = -999 \
+                   ,MeanObject." + filter[1] + "MeanPSFMagStd = -999 \
+                   ,MeanObject." + filter[1] + "MinPSFMag = -999 \
+                   ,MeanObject." + filter[1] + "MaxPSFMag = -999 \
+                   ,MeanObject." + filter[1] + "nIncKronMag = -999 \
+                   ,MeanObject." + filter[1] + "MeanKronMag = -999 \
+                   ,MeanObject." + filter[1] + "MeanKronMagStd = -999 \
+                   ,MeanObject." + filter[1] + "MeanApMag = MAG_AP \
+                   ,MeanObject." + filter[1] + "MeanApMagErr = MAG_ERR \
+                   ,MeanObject." + filter[1] + "MeanApMagStd = MAG_STDEV \
+                   ,MeanObject." + filter[1] + "nIncApMag = -999 \
+                   ,MeanObject." + filter[1] + "Flags = (0x7fff & FLAGS) | ((FLAGS >> 11) & 0x2000) "
+
+
+            self.logger.info(sql)
+            self.scratchDb.execute(sql)
 
         # now set to null all MeanMagErr values > 0.5 (cut set by Gene, 2012-04-12)
@@ -171,51 +160,135 @@
         for filter in filters:
 
-            sql = "UPDATE Object \
+            sql = "UPDATE MeanObject \
                    SET " + filter[1] + "MeanPSFMagErr = null \
                    WHERE " + filter[1] + "MeanPSFMagErr > " + str(cut)
             self.scratchDb.execute(sql)
-
-        self.logger.infoPair("Setting to NULL all x20pct =", "32.767" ) 
+    '''
+    Inserts stuff for all mags
+    '''
+    def updateObjectThinFromCps(self, cpsTable):
+
+        # list of all filters PSPS is interested in
+        interestedFilters = ['g', 'r', 'i', 'z', 'y']
+        
+        filters = self.scratchDb.getOrderedListOfFiltersFromPhotcodesTable(interestedFilters)
+    
+        # get a count of the available filters
+        filterCount = self.scratchDb.getCountOfFiltersFromPhotcodesTable()
+        # filterCount = len(filters)
+
+        self.logger.infoPair("Available filters in Photcodes", filters)
+
+        # the 'code' now defines the order in the cps file that the mags are listed for a given filter
+        self.logger.infoPair("Adding magnitudes from", "cps table")
         for filter in filters:
-            sql  = "UPDATE Object \
-                   SET " + filter[1] + "20pct = null \
-                   WHERE " + filter[1] + "20pct > 32.766"
-            self.scratchDb.execute(sql)
-        self.logger.infoPair("Setting to NULL all x80pct =", "32.767" )
+
+            filterID = self.scratchDb.getFilterID(filter[1])
+
+            # NOTE: Manipulation of FLAGS from cpsTable is to move ID_SECF_OBJ_EXT flag (0x01000000)
+	    # from bit 24 to bit 13 so that it fits into the SMALLINT Object.Flags
+
+            sql = "UPDATE ObjectThin JOIN \
+                   " + cpsTable + " AS cps ON (cps.row = (ObjectThin.row* " + str(filterCount) + ")-(" + str(filterCount) + " - " + str(filter[0]) + ")) \
+                   SET \
+                   ObjectThin.n" + filter[1] + " = NCODE "
+            self.logger.info(sql)
+            self.scratchDb.execute(sql)
+
+        self.logger.infoPair("Calculating nDetections from", "n[filters]")
         for filter in filters:
-            sql  = "UPDATE Object \
-                    SET " + filter[1] + "80pct = null \
-                    WHERE " + filter[1] + "80pct > 32.766"
-            self.scratchDb.execute(sql)
-
-
-
-
-    '''
-    Inserts colors
-    '''
-    def updateColors(self):
-
-        self.logger.infoPair("Calculating", "colors")
-        sql = "UPDATE Object \
-               SET \
-               grMeanColor = (gMeanMag - rMeanMag) \
-               ,riMeanColor = (rMeanMag - iMeanMag) \
-               ,izMeanColor = (iMeanMag - zMeanMag) \
-               ,zyMeanColor = (zMeanMag - yMeanMag) \
-               ,grMeanColorErr = SQRT(POW(gMeanMagErr,2) + POW(rMeanMagErr,2)) \
-               ,riMeanColorErr = SQRT(POW(rMeanMagErr,2) + POW(iMeanMagErr,2)) \
-               ,izMeanColorErr = SQRT(POW(iMeanMagErr,2) + POW(zMeanMagErr,2)) \
-               ,zyMeanColorErr = SQRT(POW(zMeanMagErr,2) + POW(yMeanMagErr,2)) \
-                   "
-        try:
-            self.scratchDb.execute(sql)
-        except:
-            self.logger.errorPair("Couldn't calculate colors", sql)
+            # now do a sum of n[filters], but do not include the ones with -999
+            sql = "UPDATE ObjectThin   \
+                   SET nDetections = nDetections + n" + filter[1] + " \
+                   WHERE n" + filter[1] + " != -999"
+            self.scratchDb.execute(sql)
+            
+
+
+    '''
+    give objectName to objectThin
+    '''
+    def updateObjName(self):
+    ##this is a 4 part update:
+        self.logger.infoPair("updating objName", "using stacks")
+    ## if we have a stackra and dec, use stackra and dec , dec >=0
+
+        sql = "update ObjectThin set objName =  concat('PS1.2 J', \
+        lpad(floor(raStack/15.),2,'0'), \
+        lpad((raStack/15.-(floor(raStack/15.)))*60. ,2,'0'), \
+        lpad(format(((raStack/15.-(floor(raStack/15.)))*60.-floor((raStack/15.-(floor(raStack/15.)))*60.))*60.,2),4,'0'), \
+        '+', \
+        lpad(floor(decStack),2,'0'), \
+        lpad((decStack-(floor(decStack)))*60. ,2,'0'), \
+        lpad(format(((decStack-(floor(decStack)))*60.-floor((decStack-(floor(decStack)))*60.))*60.,2),4,'0') \
+        ) where raStack > -999 and decStack > -999 and decStack >= 0"
+        try:
+            self.scratchDb.execute(sql)
+        except:
+            self.logger.errorPair("failed sql", sql)
+            return False
+
+
+    ## if we have a stackra and dec, use stackra and dec, dec < 0
+
+        sql = "update ObjectThin set objName =  concat('PS1.2 J', \
+        lpad(floor(raStack/15.),2,'0'), \
+        lpad((raStack/15.-(floor(raStack/15.)))*60. ,2,'0'), \
+        lpad(format(((raStack/15.-(floor(raStack/15.)))*60.-floor((raStack/15.-(floor(raStack/15.)))*60.))*60.,2),4,'0'), \
+        '-', \
+        lpad(floor(decStack),2,'0'), \
+        lpad((decStack-(floor(decStack)))*60. ,2,'0'), \
+        lpad(format(((decStack-(floor(decStack)))*60.-floor((decStack-(floor(decStack)))*60.))*60.,2),4,'0') \
+        ) where raStack > -999 and decStack > -999 and decStack <= 0"
+        try:
+            self.scratchDb.execute(sql)
+        except:
+            self.logger.errorPair("failed sql", sql)
+            return False
+        self.logger.infoPair("updating objName", "using means")
+    ## use mean ra and dec (dec >= 0)
+        sql = "update ObjectThin set objName =  concat('PS1.2 J', \
+        lpad(floor(raMean/15.),2,'0'), \
+        lpad((raMean/15.-(floor(raMean/15.)))*60. ,2,'0'), \
+        lpad(format(((raMean/15.-(floor(raMean/15.)))*60.-floor((raMean/15.-(floor(raMean/15.)))*60.))*60.,2),4,'0'), \
+        '+', \
+        lpad(floor(decMean),2,'0'), \
+        lpad((decMean-(floor(decMean)))*60. ,2,'0'), \
+        lpad(format(((decMean-(floor(decMean)))*60.-floor((decMean-(floor(decMean)))*60.))*60.,2),4,'0') \
+        ) where raMean > -999 and decMean > -999 and decMean >= 0"
+        try:
+            self.scratchDb.execute(sql)
+        except:
+            self.logger.errorPair("failed sql", sql)
+            return False
+ 
+    ## use mean ra and dec (dec < 0)
+
+        sql = "update ObjectThin set objName =  concat('PS1.2 J', \
+        lpad(floor(raMean/15.),2,'0'), \
+        lpad((raMean/15.-(floor(raMean/15.)))*60. ,2,'0'), \
+        lpad(format(((raMean/15.-(floor(raMean/15.)))*60.-floor((raMean/15.-(floor(raMean/15.)))*60.))*60.,2),4,'0'), \
+        '-', \
+        lpad(floor(decMean),2,'0'), \
+        lpad((decMean-(floor(decMean)))*60. ,2,'0'), \
+        lpad(format(((decMean-(floor(decMean)))*60.-floor((decMean-(floor(decMean)))*60.))*60.,2),4,'0') \
+        ) where raMean > -999 and decMean > -999 and decMean < 0"
+
+        try:
+            self.scratchDb.execute(sql)
+        except:
+            self.logger.errorPair("failed sql", sql)
+            return False
+
+
+
+
+
+
 
     '''
     Populates the Object table
     '''
-    def populateObjectTable(self):
+    def populateObjectThinTable(self):
 
         cptTableName = self.scratchDb.getDbFriendlyTableName(self.region + ".cpt")
@@ -242,42 +315,62 @@
 
         
-        self.logger.infoPair("Populating", "Object s")
+        self.logger.infoPair("Populating", "ThinObject")
         self.logger.infoPair("Inserting objects from", "cpt file")
 
         # note `` around dec here, as this is a reserved word in MySQL
-        sql = "INSERT IGNORE INTO Object (\
+        sql = "INSERT IGNORE INTO ObjectThin (\
                objID \
+               ,gcobjID \
                ,ippObjID \
+               ,surveyID \
+               ,skyCellID \
+               ,randomID \
+               ,batchID \
+               ,dvoRegionID \
+               ,dataRelease \
                ,objInfoFlag \
                ,qualityFlag \
-               ,surveyID \
-               ,ra \
-               ,`dec` \
-               ,raErr \
-               ,decErr \
+               ,consistencyFlag \
+               ,raStack \
+               ,decStack \
+               ,raStackErr \
+               ,decStackErr \
+               ,raMean \
+               ,decMean \
+               ,raMeanErr \
+               ,decMeanErr \
+               ,raMeanStd \
+               ,decMeanStd \
+               ,nStackObjectRows \
+               ,nStackDetections \
                ,nDetections \
-               ,qfPerfect \
-               ,sgSep \
-               ,dataRelease \
-               ,Random \
-               ,batchID \
-               ) \
+                ) \
                SELECT \
                EXT_ID \
+               , -999 \
                ,CAT_ID*1000000000 + OBJ_ID \
+               ," + str(self.surveyID) + " \
+               , -999 \
+               , FLOOR(RAND()*9223372036854775807) \
+               , " + str(self.batchID) + "\
+               , -999 \
+               , " + str(self.skychunk.dataRelease) + "\
                ,FLAGS \
                ,FLAGS >> 24 & 0xFF \
-               ," + str(self.surveyID) + " \
+               , 0 \
+               , -999 \
+               , -999 \
+               , -999 \
+               , -999 \
                ,RA \
                ,DEC_ \
                ,RA_ERR \
                ,DEC_ERR \
+               , -999 \
+               , -999 \
                ,0 \
-               ,PSF_QF_PERF \
-               ,STARGAL_SEP \
-               , " + str(self.skychunk.dataRelease) + "\
-               , RAND() \
-               , " + str(self.batchID) + "\
-               FROM " + cptTableName
+               ,0 \
+               ,0 \
+                FROM " + cptTableName
 
         try:
@@ -289,11 +382,16 @@
         # add row count columns so we can perform joins to get colors
         self.logger.infoPair("Adding 'row' columns to", "Object and cps tables")
-        self.scratchDb.addRowCountColumn("Object", "row")
+        self.scratchDb.addRowCountColumn("ObjectThin", "row")
         self.scratchDb.addRowCountColumn(cpsTableName, "row")
 
-        self.insertMags(cpsTableName)
-
-#don't do this as we removed those columns.. 
-#        self.updateColors()
+##        self.insertMeanMags(cpsTableName)
+## this is the new version
+        self.logger.infoPair("update objName for ","objectThin")
+        self.updateObjName()
+
+
+        self.logger.infoPair("update ObjectThin from ","cps table")
+
+        self.updateObjectThinFromCps(cpsTableName)
 
         #objects can have out of range ra dec in dvo - need to find and kill them at the end
@@ -312,5 +410,9 @@
         #count out of range
 
-        sql = "SELECT count(*) FROM Object where Object.dec > " + str(decMax) + " or Object.dec < " + str(decMin) + " or Object.ra > " + str(raMax) + " or Object.ra < " + str(raMin)       
+        sql = "SELECT count(*) FROM ObjectThin where \
+              ObjectThin.decMean > " + str(decMax) + " \
+              or ObjectThin.decMean < " + str(decMin) + " \
+              or ObjectThin.raMean > " + str(raMax) + " \
+              or ObjectThin.raMean < " + str(raMin)       
     
         rs = self.scratchDb.executeQuery(sql)
@@ -321,5 +423,9 @@
         
  
-        sql = "DELETE FROM Object where Object.dec > " + str(decMax) + " or Object.dec < " + str(decMin) + " or Object.ra > " + str(raMax) + " or Object.ra < " + str(raMin) 
+        sql = "DELETE FROM ObjectThin where \
+              ObjectThin.decMean > " + str(decMax) + " or \
+              ObjectThin.decMean < " + str(decMin) + " or \
+              ObjectThin.raMean > " + str(raMax) + " or \
+              ObjectThin.raMean < " + str(raMin) 
         self.logger.infoPair("Deleting", str(nToDelete) + " objects outside of ra/dec range")
 
@@ -327,14 +433,15 @@
             self.scratchDb.execute(sql)
         except:
-            self.logger.errorPair("Couldn't cull outsiders from Object table", sql)
-            return False
-
-        self.logger.infoPair("Dropping row column from", "Object table")
-        self.scratchDb.dropColumn("Object", "row")
-        self.logger.infoPair("Purging from scratch Db", self.region + " region")
-
-        self.dvoObjects.purgeRegion(self.region)
-
-        self.setMinMaxObjID(["Object"])
+            self.logger.errorPair("Couldn't cull outsiders from ObjectThin table", sql)
+            return False
+
+        self.logger.infoPair("Dropping row column from", "ObjectThin table")
+        self.scratchDb.dropColumn("ObjectThin", "row")
+        ##self.logger.infoPair("Purging from scratch Db", self.region + " region")
+
+        ##Don't do this till after MeanObject
+        ##self.dvoObjects.purgeRegion(self.region)
+
+        self.setMinMaxObjID(["ObjectThin"])
 
         return True
@@ -343,23 +450,33 @@
     Populates the ObjectCalColor table
     '''
-    def populateObjectCalColorTable(self):
-
-        self.logger.infoPair("Populating", "ObjectCalColor")
-
-        sql = "INSERT INTO ObjectCalColor ( \
+    def populateMeanObjectTable(self):
+        cptTableName = self.scratchDb.getDbFriendlyTableName(self.region + ".cpt")
+        cpsTableName = self.scratchDb.getDbFriendlyTableName(self.region + ".cps")
+        self.logger.infoPair("Populating MeanObject from ", "ObjectThin")
+
+        sql = "INSERT INTO MeanObject ( \
                objID \
-               ,ippObjID \
-               ,dataRelease \
+               ,gcobjID \
                ) \
                SELECT \
                objID \
-               ,ippObjID \
-               ,dataRelease \
-               FROM Object"
-        try:
-            self.scratchDb.execute(sql)
-        except:
-            self.logger.errorPair("Couldn't populate ObjectCalColor table", sql)
-            return False
+               ,gcobjID \
+               FROM ObjectThin"
+        try:
+            self.scratchDb.execute(sql)
+        except:
+            self.logger.errorPair("Couldn't populate MeanObject table", sql)
+            return False
+
+        self.logger.infoPair("Adding 'row' columns to", "MeanObject table")
+        self.scratchDb.addRowCountColumn("MeanObject", "row")
+ 
+
+        ##self.scratchDb.addRowCountColumn(cpsTableName, "row")
+        self.logger.infoPair("update MeanObjects from ","cps table")
+        self.updateMeanObjectFromCps(cpsTableName)
+
+        self.logger.infoPair("Dropping row column from", "MeanObject table")
+        self.scratchDb.dropColumn("MeanObject", "row")
 
         return True
@@ -370,10 +487,11 @@
     def populatePspsTables(self):
 
-        if not self.populateObjectTable(): return False
+        if not self.populateObjectThinTable(): return False
         #if not self.populateObjectCalColorTable(): return False
+        if not self.populateMeanObjectTable(): return False
 
         # now remove the objID duplicates. We could not do this before as cpt/cps tables relate by row number
-        self.logger.infoPair("Forcing uniqueness on", "objID in Object table")
-        rowCountBefore = self.scratchDb.getRowCount("Object")
+        self.logger.infoPair("Forcing uniqueness on", "objID in ObjectThin table")
+        rowCountBefore = self.scratchDb.getRowCount("ObjectThin")
 
         # XXX EAM : note that in mysql versions later than 5.1, this fails
@@ -386,11 +504,35 @@
             self.scratchDb.execute("set session old_alter_table=1")
             
-        self.scratchDb.execute("ALTER IGNORE TABLE Object ADD UNIQUE INDEX(objID)")
+        self.scratchDb.execute("ALTER IGNORE TABLE ObjectThin ADD UNIQUE INDEX(objID)")
         if self.scratchDb.version > 5.1:
             self.scratchDb.execute("set session old_alter_table=0")
 
-        rowCountAfter = self.scratchDb.getRowCount("Object")
+        rowCountAfter = self.scratchDb.getRowCount("ObjectThin")
         self.logger.infoPair("Number of duplicated objIDs removed", "%d out of %d" % ((rowCountBefore - rowCountAfter), rowCountBefore))
 
+        self.logger.infoPair("Forcing uniqueness on", "objID in MeanObject table")
+        rowCountBefore = self.scratchDb.getRowCount("MeanObject")
+
+        # XXX EAM : note that in mysql versions later than 5.1, this fails
+        # unless the following is called first: 
+        # set session old_alter_table=1
+        # follow the command with 
+        # set session old_alter_table=0
+        # OF COURSE, this fails for mysql version < 5.5...
+        if self.scratchDb.version > 5.1:
+            self.scratchDb.execute("set session old_alter_table=1")
+            
+        self.scratchDb.execute("ALTER IGNORE TABLE MeanObject ADD UNIQUE INDEX(objID)")
+        if self.scratchDb.version > 5.1:
+            self.scratchDb.execute("set session old_alter_table=0")
+
+        rowCountAfter = self.scratchDb.getRowCount("MeanObject")
+        self.logger.infoPair("Number of duplicated objIDs removed", "%d out of %d" % ((rowCountBefore - rowCountAfter), rowCountBefore))
+
+        self.dvoObjects.purgeRegion(self.region)
+
+        #this is abuse of something but this is how I get the object batches to crash to further investigate them
+        
+#        rowCountAfter = self.scratchDb.getRowCount("Object")
         return True
-
+#        return False
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/odm.py
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/odm.py	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/odm.py	(revision 37066)
@@ -31,5 +31,5 @@
 
         tempFile = tempfile.NamedTemporaryFile(mode='w+b')
-
+        self.logger.infoPair("checkOdmStatus.pl -b " + batch + " -f " + tempFile.name, "")
         p = Popen("checkOdmStatus.pl -b " + batch + " -f " + tempFile.name, 
                 shell=True, 
@@ -78,5 +78,5 @@
                 DETAILS = doc.find("{%s}OdmBatchState/{%s}Details" % (NAMESPACE, NAMESPACE)).text
                 results['DETAILS'] = DETAILS
-            elif re.search("processing", STATE): 
+            elif re.search("processing", STATE):
                 loadedToODM = 1
             if re.search("MergeWorthy", MESSAGE): 
@@ -87,4 +87,12 @@
                 mergeWorthy = 1
                 merged = 1
+#            if re.search("released", STATE):
+#                loadedToODM = 1
+#                mergeWorthy = 1
+#                merged = 1
+#            if re.search("released", MESSAGE):
+#                loadedToODM = 1
+#                mergeWorthy = 1
+#                merged = 1
         except:
             pass
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/plotter.py
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/plotter.py	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/plotter.py	(revision 37066)
@@ -28,4 +28,8 @@
             self.plot.createDensityPlot("ST")
             self.plot.createDensityPlot("OB")
+            self.plot.createDensityPlot("DF")
+            self.plot.createDensityPlot("DO")
+            self.plot.createDensityPlot("FW")
+            self.plot.createDensityPlot("FO")
 
     '''
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/pollOdm.py
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/pollOdm.py	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/pollOdm.py	(revision 37066)
@@ -42,5 +42,5 @@
         else: self.stages = [self.STAGE]
 
-        if self.BATCHTYPE == "all": self.batchTypes = ['IN', 'P2', 'ST', 'OB']
+        if self.BATCHTYPE == "all": self.batchTypes = ['IN', 'P2', 'ST', 'OB', 'DF', 'DO', 'FW', 'FO']
         else: self.batchTypes = [self.BATCHTYPE]
 
@@ -126,5 +126,5 @@
     '''
     def printUsage(self):
-        super(PollOdm, self).printUsage("<IN|P2|ST|OB|all> <unloaded|unmergeworthy|unmerged|all> [hours]")
+        super(PollOdm, self).printUsage("<IN|P2|ST|OB|DF|DO|FW|FO|all> <unloaded|unmergeworthy|unmerged|all> [hours]")
     
     
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/queue.py
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/queue.py	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/queue.py	(revision 37066)
@@ -45,4 +45,5 @@
 
         try:
+            print "why doesn't this work"
             self.dvoObjects = DvoObjects(self.logger, self.config, self.skychunk, self.ippToPspsDb, self.scratchDb)
         except:
@@ -71,6 +72,6 @@
             for batchType in self.skychunk.batchTypes: 
                 self.logger.infoPair("BatchType",batchType)
-                # self.logger.infoTitle("Previous failed datastore loads")
-                # self.publishAnyUnpublishedBatches(batchType)
+                #self.logger.infoTitle("Previous failed datastore loads")
+                #self.publishAnyUnpublishedBatches(batchType)
 
                 # get totals for whole area to check if there is anything to do
@@ -81,5 +82,6 @@
                 # for object batches, get full list of stuff from Dvo
                 # XXX : need to fix 'dvo.setSkyArea' or this may not return the full list for a parallel dvo
-                if batchType == "OB":
+            #for object-like batches, info comes from dvo
+                if (batchType == "OB" or batchType =="DO" or batchType =="FO"):
                     self.dvoObjects.setSkyArea(
                             self.skychunk.minRa,
@@ -98,5 +100,7 @@
                             self.skychunk.maxRa, 
                             self.skychunk.minDec, 
-                            self.skychunk.maxDec)
+                            self.skychunk.maxDec,
+                            self.skychunk.trange_start,
+                            self.skychunk.trange_end)
 
                 # EAM TEST I/O
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/removepending.py
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/removepending.py	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/removepending.py	(revision 37066)
@@ -0,0 +1,86 @@
+#!/usr/bin/env jython
+
+#
+# This is a way to easily delete pending skychunks
+#
+
+import time
+import sys
+import os
+import math
+import logging.config
+
+from ipptopsps import IppToPsps
+from gpc1db import Gpc1Db
+from datastore import Datastore
+from dvoobjects import DvoObjects
+from batch import Batch
+from scratchdb import ScratchDb
+# basically, "ippjython removepending.py skychunk_name " will remove pending batches
+
+
+'''
+Queue class
+'''
+class Queue(IppToPsps):
+
+    '''
+    Constructor
+    '''
+    def __init__(self, argv):
+        super(Queue, self).__init__(argv)
+
+        # print "inited ipptopsps"
+
+        # create various objects
+        self.gpc1Db = Gpc1Db(self.logger, self.config)
+        # print "connect to gpc1"
+
+        self.datastore = Datastore(self.logger, self.skychunk, self.ippToPspsDb)
+
+        print "made datastore"
+
+        # connect to scratch database
+        self.scratchDb = ScratchDb(self.logger, self.config)
+
+        print "connect to scratchdb"
+
+        try:
+            self.dvoObjects = DvoObjects(self.logger, self.config, self.skychunk, self.ippToPspsDb, self.scratchDb)
+        except:
+            self.exitProgram("Unable to create instance of DvoObject")
+            raise
+
+        print "got objects"
+
+        self.skychunk.printAll()
+
+        if len(argv) > 2: self.parsePollTimeArg(sys.argv[2])
+
+    '''
+    Main processing loop.
+    Tiled area is defined in 'skychunk' and looks for available stage_ids for each tile and writes them to ippToPsps database ready for processing
+    by one or more loading clients that may be running on any host
+    '''
+    def run(self):
+
+        self.ippToPspsDb.removeAllBoxes()
+        print "remove boxes" 
+            
+
+    '''
+    Overrides base-class version
+    '''
+    def printUsage(self):
+        super(Queue, self).printUsage("[<repeat time in hours>]")
+
+
+'''
+Start of program.
+'''
+try:
+    queue = Queue(sys.argv)
+    queue.run()
+    queue.exitProgram("completed")
+except: pass
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/stackbatch.py
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/stackbatch.py	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/jython/stackbatch.py	(revision 37066)
@@ -4,4 +4,5 @@
 import glob
 import sys
+
 
 import stilts
@@ -37,5 +38,5 @@
                  ippToPspsDb,
                  scratchDb,
-                 stackID,
+                 skyID,
                  batchID,
                  useFullTables):
@@ -48,24 +49,128 @@
                ippToPspsDb,
                scratchDb,
-               stackID,
+               skyID,
                batchID,
                "ST", 
-               gpc1Db.getStackStageCmf(skychunk.dvoLabel, stackID),
+               "",
+               #gpc1Db.getStackStageCmf(skychunk.dvoLabel, stackID),
                useFullTables)
 
        # self.printline = 0
        # # self.testprint()
-
+#       self.logger.infoPair("did I get", "here");
        self.stackType = "DEEP_STACK" # TODO
-
+       ## = stuff I commented out for pv2 stacks
+       
+       #heather tasks
+
+       # get a list of stackIDs
+       self.logger.infoPair ("getting stackID for: ","g.00000")
+       gstackID = gpc1Db.getStackIDFromSkyIDAndFilter( skychunk.dvoLabel, skyID, "g.00000")
+       self.logger.infoPair ("getting stackID for: ","r.00000")
+       rstackID = gpc1Db.getStackIDFromSkyIDAndFilter( skychunk.dvoLabel, skyID, "r.00000")
+       self.logger.infoPair ("getting stackID for: ","i.00000")
+       istackID = gpc1Db.getStackIDFromSkyIDAndFilter( skychunk.dvoLabel, skyID, "i.00000")
+       self.logger.infoPair ("getting stackID for: ","z.00000")
+       zstackID = gpc1Db.getStackIDFromSkyIDAndFilter( skychunk.dvoLabel, skyID, "z.00000")
+       self.logger.infoPair ("getting stackID for: ","y.00000")
+       ystackID = gpc1Db.getStackIDFromSkyIDAndFilter( skychunk.dvoLabel, skyID, "y.00000")
+ #      self.logger.infoPair("g stackID ",gstackID)       
+ #      self.logger.infoPair("r stackID ",rstackID)
+ #      self.logger.infoPair("i stackID ",istackID)
+ #      self.logger.infoPair("z stackID ",zstackID)
+ #      self.logger.infoPair("y stackID ",ystackID)
+ #      raise
+       # from each stackget fits name from getStackStageCmf
+       if gstackID > 0:
+           self.logger.infoPair ("finding fits file for: ","g.00000")
+           gfits = gpc1Db.getStackStageCmf(skychunk.dvoLabel, gstackID)
+           self.gfits = gfits
+       if rstackID > 0:    
+           self.logger.infoPair ("finding fits file for: ","r.00000")
+           rfits = gpc1Db.getStackStageCmf(skychunk.dvoLabel, rstackID)
+           self.rfits = rfits
+       if istackID > 0:    
+           self.logger.infoPair ("finding fits file for: ","i.00000")
+           ifits = gpc1Db.getStackStageCmf(skychunk.dvoLabel, istackID)
+           self.ifits = ifits
+       if zstackID > 0:    
+           self.logger.infoPair ("finding fits file for: ","z.00000")
+           zfits = gpc1Db.getStackStageCmf(skychunk.dvoLabel, zstackID)
+           self.zfits = zfits
+       if ystackID > 0:    
+           self.logger.infoPair ("finding fits file for: ","y.00000")
+           yfits = gpc1Db.getStackStageCmf(skychunk.dvoLabel, ystackID)
+           self.yfits = yfits
+
+       #from each of those get self.gheader, self.rheader, etc.
+       if gstackID > 0:    
+           if gfits:
+               gheader = gfits.getPrimaryHeader()
+               if not gheader:
+                   self.logger.errorPair("could not read FITS PHU for ",gstackID)
+                   raise
+               self.gheader = gheader
+       if rstackID > 0:        
+           if rfits:
+               rheader = rfits.getPrimaryHeader()
+               if not rheader:
+                   self.logger.errorPair("could not read FITS PHU for ",rstackID)
+                   raise
+               self.rheader = rheader
+       if istackID > 0:        
+           if ifits:
+               iheader = ifits.getPrimaryHeader()
+               if not iheader:
+                   self.logger.errorPair("could not read FITS PHU for ",istackID)
+                   raise
+               self.iheader = iheader
+       if zstackID > 0:
+           if zfits:
+               zheader = zfits.getPrimaryHeader()
+               if not zheader:
+                   self.logger.errorPair("could not read FITS PHU for ",zstackID)
+                   raise
+               self.zheader = zheader
+       if ystackID > 0: 
+           if yfits:
+               yheader = yfits.getPrimaryHeader()
+               if not yheader:
+                   self.logger.errorPair("could not read FITS PHU for ",ystackID)
+                   raise
+               self.yheader = yheader
        # get stack meta data
-       meta = self.gpc1Db.getStackStageMeta(self.id)
+       self.gstackID = gstackID
+       self.rstackID = rstackID
+       self.istackID = istackID     
+       self.zstackID = zstackID
+       self.ystackID = ystackID
+
+       metastackid = -999
+       if gstackID > 0:
+           metastackid = gstackID
+       if rstackID > 0:
+           metastackid = rstackID
+       if istackID > 0:
+           metastackid = istackID    
+       if zstackID > 0:
+           metastackid = zstackID
+       if ystackID > 0:
+           metastackid = ystackID
+       #there is probably a better way to do this
+       if metastackid < 0:
+           self.logger.errorPair("can't find any stack ids...?? ","??")
+           raise
+    
+       meta = self.gpc1Db.getStackStageMeta(metastackid)  
+       ## this should be ok - it takes a stack_id and returns filter/skycell etc.
+
+
        if not meta:
            self.logger.errorPair("Could not get stack", "metadata")
            raise
 
-       self.filter = meta[0];
-       self.filter = self.filter[0:1]
-       self.filterID = self.scratchDb.getFilterID(self.filter)
+       #self.filter = meta[0];
+       #self.filter = self.filter[0:1]
+       #self.filterID = self.scratchDb.getFilterID(self.filter)
        self.skycell = meta[1];
 
@@ -75,5 +180,5 @@
        # we need 1133.081 for skycell, but store as an int, so instead store 1133081
        # projection cell is just the 1133 bit
-       # this is how it should be done
+       # This Is how it should be done
        #self.projectioncell = self.skycell[8:12]
        #self.skycell = self.skycell[8:]
@@ -82,5 +187,5 @@
 
        # TODO this is the wrong way, but is consistent with SkyCell table in IN data
-       self.skycell = self.skycell[8:12]
+       self.skycell = self.skycell[8:]
        self.projectioncell = self.skycell
 
@@ -94,37 +199,71 @@
 
        #self.expTime = gpc1Db.getStackExpTime(self.id)
-       self.expTime = self.header['EXPTIME']
-
+       
        # delete PSPS tables
-       self.scratchDb.dropTable("StackMeta")
-       self.scratchDb.dropTable("StackDetection")
+       self.logger.infoPair("dropping table:","gStackMeta")
+       self.scratchDb.dropTable("gStackMeta")
+       self.logger.infoPair("dropping table:","rStackMeta")
+       self.scratchDb.dropTable("rStackMeta")
+       self.logger.infoPair("dropping table:","iStackMeta")
+       self.scratchDb.dropTable("iStackMeta")
+       self.logger.infoPair("dropping table:","zStackMeta")
+       self.scratchDb.dropTable("zStackMeta")
+       self.logger.infoPair("dropping table:","yStackMeta")
+       self.scratchDb.dropTable("yStackMeta")
+       self.logger.infoPair("dropping table:","StackObject")
+
+       self.scratchDb.dropTable("StackObject")
+       self.logger.infoPair("dropping table:","StackModelFit")
+              
        self.scratchDb.dropTable("StackModelFit")
+       self.logger.infoPair("dropping table:","StackApFlx")
+
        self.scratchDb.dropTable("StackApFlx")
+       self.logger.infoPair("dropping table:","StackToImage")
+
        self.scratchDb.dropTable("StackToImage")
-       self.scratchDb.dropTable("SkinnyObject")
-       #self.scratchDb.dropTable("ObjectCalColor")
-       self.scratchDb.dropTable("StackDetectionCalib")
-
-       # self.testprint()
+             # self.testprint()
+
+       # for PV2 we will have (grizy) of stack meta and skychip      
+
 
        # delete IPP tables
-       self.scratchDb.dropTable("SkyChip_psf")
-       self.scratchDb.dropTable("SkyChip_xrad")
-       self.scratchDb.dropTable("SkyChip_xfit")
-       self.scratchDb.dropTable("SkyChip_xsrc")
+       self.scratchDb.dropTable("gSkyChip_psf")
+       self.scratchDb.dropTable("gSkyChip_xrad")
+       self.scratchDb.dropTable("gSkyChip_xfit")
+       self.scratchDb.dropTable("gSkyChip_xsrc")
+       self.scratchDb.dropTable("rSkyChip_psf")
+       self.scratchDb.dropTable("rSkyChip_xrad")
+       self.scratchDb.dropTable("rSkyChip_xfit")
+       self.scratchDb.dropTable("rSkyChip_xsrc")
+       self.scratchDb.dropTable("iSkyChip_psf")
+       self.scratchDb.dropTable("iSkyChip_xrad")
+       self.scratchDb.dropTable("iSkyChip_xfit")
+       self.scratchDb.dropTable("iSkyChip_xsrc")
+       self.scratchDb.dropTable("zSkyChip_psf")
+       self.scratchDb.dropTable("zSkyChip_xrad")
+       self.scratchDb.dropTable("zSkyChip_xfit")
+       self.scratchDb.dropTable("zSkyChip_xsrc")
+       self.scratchDb.dropTable("ySkyChip_psf")
+       self.scratchDb.dropTable("ySkyChip_xrad")
+       self.scratchDb.dropTable("ySkyChip_xfit")
+       self.scratchDb.dropTable("ySkyChip_xsrc")
 
        # create an output filename, which is {stackID}.FITS
+       self.logger.infoPair( "self.id", self.id)
+       self.logger.infoPair ("self.localOutPath",self.localOutPath)
        self.outputFitsFile = "%08d.FITS" % self.id
        self.outputFitsPath = "%s/%s" % (self.localOutPath, self.outputFitsFile)
-
+       self.logger.infoPair("self.outputFitsFile",self.outputFitsFile)
+       
        # set some constants
        self.historyModNum = "0"
 
        # insert what we know about this stack batch into the stack table
-       self.ippToPspsDb.insertStackMeta(self.batchID, self.filter, self.stackType)
+       self.ippToPspsDb.insertStackMeta(self.batchID, "x" , self.stackType)
 
        # insert sourceID/imageID combo so DVO can look it up
-       if not self.useFullTables:
-           self.scratchDb.insertNewDvoExternID(self.header['SOURCEID'], self.header['IMAGEID'])
+       ##if not self.useFullTables:
+       ##    self.scratchDb.insertNewDvoExternID(self.header['SOURCEID'], self.header['IMAGEID'])
 
        # self.testprint()
@@ -135,5 +274,5 @@
        self.logger.infoPair("Skycell", "%s" % self.skycell)
        self.logger.infoPair("Projectioncell", "%s" % self.projectioncell)
-       self.logger.infoPair("Filter", "%s" % self.filter)
+       ##self.logger.infoPair("Filter", "%s" % self.filter)
 
     '''
@@ -142,5 +281,10 @@
     def updateStackMetaID(self, table):
 
-        sql = "UPDATE " + table + "  SET stackMetaID=" + str(self.id)
+        sql = "UPDATE " + table + "  SET gstackMetaID=" + str(self.gstackID) + " \
+              , rstackMetaID=" + str(self.rstackID) + " \
+              , istackMetaID=" + str(self.istackID) + " \
+              , zstackMetaID=" + str(self.zstackID) + " \
+              , ystackMetaID=" + str(self.ystackID)   
+     
         self.scratchDb.execute(sql)
 
@@ -161,55 +305,56 @@
     Updates aperture fluxes for StackApFkx table
     '''
-    def updateApFlxs(self, prefix, psfCondition):
+    def updateModelFitFlxs(self, prefix, psfCondition, tablename, filter):
         #properly -999 these to start with:
-
-        sql = "UPDATE StackApFlx AS a, SkyChip_xrad AS b SET \
-        "+prefix+"flxR1=-999, \
-        "+prefix+"flxR1Err=-999, \
-        "+prefix+"flxR1Std=-999, \
-        "+prefix+"flxR1Fill=-999, \
-        "+prefix+"flxR2=-999, \
-        "+prefix+"flxR2Err=-999, \
-        "+prefix+"flxR2Std=-999, \
-        "+prefix+"flxR2Fill=-999, \
-        "+prefix+"flxR3=-999, \
-        "+prefix+"flxR3Err=-999, \
-        "+prefix+"flxR3Std=-999, \
-        "+prefix+"flxR3Fill=-999, \
-        "+prefix+"flxR4=-999, \
-        "+prefix+"flxR4Err=-999, \
-        "+prefix+"flxR4Std=-999, \
-        "+prefix+"flxR4Fill=-999, \
-        "+prefix+"flxR5=-999, \
-        "+prefix+"flxR5Err=-999, \
-        "+prefix+"flxR5Std=-999, \
-        "+prefix+"flxR5Fill=-999, \
-        "+prefix+"flxR6=-999, \
-        "+prefix+"flxR6Err=-999, \
-        "+prefix+"flxR6Std=-999, \
-        "+prefix+"flxR6Fill=-999, \
-        "+prefix+"flxR7=-999, \
-        "+prefix+"flxR7Err=-999, \
-        "+prefix+"flxR7Std=-999, \
-        "+prefix+"flxR7Fill=-999, \
-        "+prefix+"flxR8=-999, \
-        "+prefix+"flxR8Err=-999, \
-        "+prefix+"flxR8Std=-999, \
-        "+prefix+"flxR8Fill=-999, \
-        "+prefix+"flxR9=-999, \
-        "+prefix+"flxR9Err=-999, \
-        "+prefix+"flxR9Std=-999, \
-        "+prefix+"flxR9Fill=-999, \
-        "+prefix+"flxR10=-999, \
-        "+prefix+"flxR10Err=-999, \
-        "+prefix+"flxR10Std=-999, \
-        "+prefix+"flxR10Fill=-999 \
-        WHERE a.ippDetectID=b.IPP_IDET "
+        f = filter
+        if tablename == 'StackModelFit':
+            sql = "UPDATE " + tablename + " AS a, "+f+"SkyChip_xrad AS b SET \
+        "+f+prefix+"flxR1=-999, \
+        "+f+prefix+"flxR1Err=-999, \
+        "+f+prefix+"flxR1Std=-999, \
+        "+f+prefix+"flxR1Fill=-999, \
+        "+f+prefix+"flxR2=-999, \
+        "+f+prefix+"flxR2Err=-999, \
+        "+f+prefix+"flxR2Std=-999, \
+        "+f+prefix+"flxR2Fill=-999, \
+        "+f+prefix+"flxR3=-999, \
+        "+f+prefix+"flxR3Err=-999, \
+        "+f+prefix+"flxR3Std=-999, \
+        "+f+prefix+"flxR3Fill=-999, \
+        "+f+prefix+"flxR4=-999, \
+        "+f+prefix+"flxR4Err=-999, \
+        "+f+prefix+"flxR4Std=-999, \
+        "+f+prefix+"flxR4Fill=-999, \
+        "+f+prefix+"flxR5=-999, \
+        "+f+prefix+"flxR5Err=-999, \
+        "+f+prefix+"flxR5Std=-999, \
+        "+f+prefix+"flxR5Fill=-999, \
+        "+f+prefix+"flxR6=-999, \
+        "+f+prefix+"flxR6Err=-999, \
+        "+f+prefix+"flxR6Std=-999, \
+        "+f+prefix+"flxR6Fill=-999, \
+        "+f+prefix+"flxR7=-999, \
+        "+f+prefix+"flxR7Err=-999, \
+        "+f+prefix+"flxR7Std=-999, \
+        "+f+prefix+"flxR7Fill=-999, \
+        "+f+prefix+"flxR8=-999, \
+        "+f+prefix+"flxR8Err=-999, \
+        "+f+prefix+"flxR8Std=-999, \
+        "+f+prefix+"flxR8Fill=-999, \
+        "+f+prefix+"flxR9=-999, \
+        "+f+prefix+"flxR9Err=-999, \
+        "+f+prefix+"flxR9Std=-999, \
+        "+f+prefix+"flxR9Fill=-999, \
+        "+f+prefix+"flxR10=-999, \
+        "+f+prefix+"flxR10Err=-999, \
+        "+f+prefix+"flxR10Std=-999, \
+        "+f+prefix+"flxR10Fill=-999 \
+        WHERE a."+f+"ippDetectID=b.IPP_IDET "
         #self.logger.infoPair("sql", sql)
-        self.scratchDb.execute(sql)
+            self.scratchDb.execute(sql)
 
 
         #we have variable numbers of these columns. find out which are in use
-        sql = "DESCRIBE SkyChip_xrad 'aper_fill_%'"
+        sql = "DESCRIBE "+f+"SkyChip_xrad 'aper_fill_%'"
         rs = self.scratchDb.executeQuery(sql)
         rs.first()
@@ -225,135 +370,73 @@
 
         numbers = []
+        min = 1
+        max = 10
+        if tablename == 'StackApFlx':
+            min = 3
+            max = 5
         for column in columns: 
             number = re.sub("APER_FILL_","",column)
-            if (int(number) >= 1 and int(number) <=10):
+            if (int(number) >= min and int(number) <=max):
                 numbers.append(number)
                 self.logger.infoPair("Aperture Numbers",number)
 
         #generate the sql to do the necessary ops on the columns    
-        sql = "UPDATE StackApFlx AS a, SkyChip_xrad AS b SET "
+        sql = "UPDATE " + tablename + " AS a, "+f+"SkyChip_xrad AS b SET "
         cnt =0
+        exptime = self.safeDictionaryAccess(self.header, 'EXPTIME')
         for number in numbers:
             if (cnt>0):
                 sql=sql+" , "
-            sql=sql+prefix+"flxR"+number+"=b.APER_FLUX_"+number +" / " + str(self.expTime) + ", "
-            sql=sql+prefix+"flxR"+number+"Err=b.APER_FLUX_ERR_"+number +" / " + str(self.expTime) + ", "
-            sql=sql+prefix+"flxR"+number+"Std=b.APER_FLUX_STDEV_"+number +" / " + str(self.expTime) + ", "
-            sql=sql+prefix+"flxR"+number+"Fill=b.APER_FILL_"+number + " "
+            sql=sql+f+prefix+"flxR"+number+"=b.APER_FLUX_"+number +" / " + str(exptime) + ", "
+            sql=sql+f+prefix+"flxR"+number+"Err=b.APER_FLUX_ERR_"+number +" / " + str(exptime) + ", "
+            sql=sql+f+prefix+"flxR"+number+"Std=b.APER_FLUX_STDEV_"+number +" / " + str(exptime) + ", "
+            sql=sql+f+prefix+"flxR"+number+"Fill=b.APER_FILL_"+number + " "
             cnt=cnt+1
             
-        sql=sql+"WHERE a.ippDetectID=b.IPP_IDET AND b.PSF_FWHM "+psfCondition     
-        self.scratchDb.execute(sql)
-
-        #self.logger.infoPair("sql",sql)
-
-        #sql = "UPDATE StackApFlx AS a, SkyChip_xrad AS b SET \
-        #"+prefix+"flxR1=b.APER_FLUX_1 / " + str(self.expTime) + ", \
-        #"+prefix+"flxR1Err=b.APER_FLUX_ERR_1 / " + str(self.expTime) + ", \
-        #"+prefix+"flxR1Std=b.APER_FLUX_STDEV_1 / " + str(self.expTime) + ", \
-        #"+prefix+"flxR1Fill=b.APER_FILL_1, \
-        #"+prefix+"flxR2=b.APER_FLUX_2 / " + str(self.expTime) + ", \
-        ##"+prefix+"flxR2Err=b.APER_FLUX_ERR_2 / " + str(self.expTime) + ", \
-        #"+prefix+"flxR2Std=b.APER_FLUX_STDEV_2 / " + str(self.expTime) + ", \
-        #"+prefix+"flxR2Fill=b.APER_FILL_2, \
-        #"+prefix+"flxR3=b.APER_FLUX_3 / " + str(self.expTime) + ", \
-        #"+prefix+"flxR3Err=b.APER_FLUX_ERR_3 / " + str(self.expTime) + ", \
-        #"+prefix+"flxR3Std=b.APER_FLUX_STDEV_3 / " + str(self.expTime) + ", \
-        #"+prefix+"flxR3Fill=b.APER_FILL_3, \
-        #"+prefix+"flxR4=b.APER_FLUX_4 / " + str(self.expTime) + ", \
-        #"+prefix+"flxR4Err=b.APER_FLUX_ERR_4 / " + str(self.expTime) + ", \
-        #"+prefix+"flxR4Std=b.APER_FLUX_STDEV_4 / " + str(self.expTime) + ", \
-        #"+prefix+"flxR4Fill=b.APER_FILL_4, \
-        #"+prefix+"flxR5=b.APER_FLUX_5 / " + str(self.expTime) + ", \
-        #"+prefix+"flxR5Err=b.APER_FLUX_ERR_5 / " + str(self.expTime) + ", \
-        #"+prefix+"flxR5Std=b.APER_FLUX_STDEV_5 / " + str(self.expTime) + ", \
-        #"+prefix+"flxR5Fill=b.APER_FILL_5, \
-        #"+prefix+"flxR6=b.APER_FLUX_6 / " + str(self.expTime) + ", \
-        #"+prefix+"flxR6Err=b.APER_FLUX_ERR_6 / " + str(self.expTime) + ", \
-        #"+prefix+"flxR6Std=b.APER_FLUX_STDEV_6 / " + str(self.expTime) + ", \
-        #"+prefix+"flxR6Fill=b.APER_FILL_6, \
-        #"+prefix+"flxR7=b.APER_FLUX_7 / " + str(self.expTime) + ", \
-        #"+prefix+"flxR7Err=b.APER_FLUX_ERR_7 / " + str(self.expTime) + ", \
-        #"+prefix+"flxR7Std=b.APER_FLUX_STDEV_7 / " + str(self.expTime) + ", \
-        #"+prefix+"flxR7Fill=b.APER_FILL_7, \
-        #"+prefix+"flxR8=b.APER_FLUX_8 / " + str(self.expTime) + ", \
-        #"+prefix+"flxR8Err=b.APER_FLUX_ERR_8 / " + str(self.expTime) + ", \
-        #"+prefix+"flxR8Std=b.APER_FLUX_STDEV_8 / " + str(self.expTime) + ", \
-        #"+prefix+"flxR8Fill=b.APER_FILL_8, \
-        #"+prefix+"flxR9=b.APER_FLUX_9 / " + str(self.expTime) + ", \
-        #"+prefix+"flxR9Err=b.APER_FLUX_ERR_9 / " + str(self.expTime) + ", \
-        #"+prefix+"flxR9Std=b.APER_FLUX_STDEV_9 / " + str(self.expTime) + ", \
-        #"+prefix+"flxR9Fill=b.APER_FILL_9, \
-        #"+prefix+"flxR10=b.APER_FLUX_10 / " + str(self.expTime) + ", \
-        #"+prefix+"flxR10Err=b.APER_FLUX_ERR_10 / " + str(self.expTime) + ", \
-        #"+prefix+"flxR10Std=b.APER_FLUX_STDEV_10 / " + str(self.expTime) + ", \
-        #"+prefix+"flxR10Fill=b.APER_FILL_10 \
-        #WHERE a.ippDetectID=b.IPP_IDET AND b.PSF_FWHM "+psfCondition
-
-        #self.scratchDb.execute(sql)
+        sql=sql+"WHERE a."+f+"ippDetectID=b.IPP_IDET AND  "+psfCondition   
+        self.logger.infoPair("sql",sql)
+        self.scratchDb.execute(sql)
+
 
     '''
     Updates parameters for a particular model in the StackModelFit table
     '''
-    def updateModelFit(self, model, ippModelType):
-
-        if model == "ser":
-            modelLong = "sersic"
-        else:
-            modelLong = model;
-
-        sql = "UPDATE StackModelFit AS a, SkyChip_xfit AS b SET \
-        "+model+"Radius=b.EXT_WIDTH_MAJ,  \
-        "+model+"Flux=POW(10, -0.4 * b.EXT_INST_MAG) / " + str(self.expTime) + " ,  \
-        "+model+"FluxErr=ABS(b.EXT_INST_MAG_SIG) * POW(10, -0.4 * b.EXT_INST_MAG) / " + str(self.expTime) + " / 1.085736, \
-        "+model+"Ab=b.EXT_WIDTH_MAJ/b.EXT_WIDTH_MIN, \
-        "+model+"Phi=b.EXT_THETA,  \
-        "+modelLong+"Covar11=b.EXT_COVAR_00_00,  \
-        "+modelLong+"Covar12=b.EXT_COVAR_00_01,  \
-        "+modelLong+"Covar13=b.EXT_COVAR_00_02,  \
-        "+modelLong+"Covar14=b.EXT_COVAR_00_03,  \
-        "+modelLong+"Covar15=b.EXT_COVAR_00_04,  \
-        "+modelLong+"Covar16=b.EXT_COVAR_00_05,  \
-        "+modelLong+"Covar17=b.EXT_COVAR_00_06,  \
-        "+modelLong+"Covar22=b.EXT_COVAR_01_01,  \
-        "+modelLong+"Covar23=b.EXT_COVAR_01_02,  \
-        "+modelLong+"Covar24=b.EXT_COVAR_01_03,  \
-        "+modelLong+"Covar25=b.EXT_COVAR_01_04,  \
-        "+modelLong+"Covar26=b.EXT_COVAR_01_05,  \
-        "+modelLong+"Covar27=b.EXT_COVAR_01_06,  \
-        "+modelLong+"Covar33=b.EXT_COVAR_02_02,  \
-        "+modelLong+"Covar34=b.EXT_COVAR_02_03,  \
-        "+modelLong+"Covar35=b.EXT_COVAR_02_04,  \
-        "+modelLong+"Covar36=b.EXT_COVAR_02_05,  \
-        "+modelLong+"Covar37=b.EXT_COVAR_02_06,  \
-        "+modelLong+"Covar44=b.EXT_COVAR_03_03,  \
-        "+modelLong+"Covar45=b.EXT_COVAR_03_04,  \
-        "+modelLong+"Covar46=b.EXT_COVAR_03_05,  \
-        "+modelLong+"Covar47=b.EXT_COVAR_03_06,  \
-        "+modelLong+"Covar55=b.EXT_COVAR_04_04,  \
-        "+modelLong+"Covar56=b.EXT_COVAR_04_05,  \
-        "+modelLong+"Covar57=b.EXT_COVAR_04_06,  \
-        "+modelLong+"Covar66=b.EXT_COVAR_05_05,  \
-        "+modelLong+"Covar67=b.EXT_COVAR_05_06,  \
-        "+modelLong+"Covar77=b.EXT_COVAR_06_06   \
-        WHERE a.ippDetectID=b.IPP_IDET AND b.MODEL_TYPE = '"+ippModelType+"'"
-
-        self.scratchDb.execute(sql)
+    def updateModelFit(self, model, ippModelType, filter, exptime):
+        f = filter
+ 
+ # idk what to do about PET
+
+        sql = "DESCRIBE "+f+"SkyChip_xfit 'EXT_COVAR_%'"
+        rs = self.scratchDb.executeQuery(sql)
+        rs.first()
+        hasResult = rs.next()
+
+
+
+        sql = "UPDATE StackModelFit AS a, " + f + "SkyChip_xfit AS b SET \
+        "+f+model+"Radius=b.EXT_WIDTH_MAJ,  \
+        "+f+model+"Flux=POW(10, -0.4 * b.EXT_INST_MAG) / " + str(exptime) + " ,  \
+        "+f+model+"FluxErr=ABS(b.EXT_INST_MAG_SIG) * POW(10, -0.4 * b.EXT_INST_MAG) / " + str(exptime) + " / 1.085736, \
+        "+f+model+"Ab=b.EXT_WIDTH_MAJ/b.EXT_WIDTH_MIN, \
+        "+f+model+"Phi=b.EXT_THETA  \
+          \
+        WHERE a."+f+"ippDetectID=b.IPP_IDET AND b.MODEL_TYPE = '"+ippModelType+"'"
+
+        print sql
+        self.scratchDb.execute(sql)
+
+
 
         # sersic fit has an extra parameter
-        if ippModelType == "PS_MODEL_SERSIC":
-            sql = "UPDATE StackModelFit AS a, SkyChip_xfit AS b SET \
-            "+modelLong+"Covar18=b.EXT_COVAR_00_07,  \
-            "+modelLong+"Covar28=b.EXT_COVAR_01_07,  \
-            "+modelLong+"Covar38=b.EXT_COVAR_02_07,  \
-            "+modelLong+"Covar48=b.EXT_COVAR_03_07,  \
-            "+modelLong+"Covar58=b.EXT_COVAR_04_07,  \
-            "+modelLong+"Covar68=b.EXT_COVAR_05_07,  \
-            "+modelLong+"Covar78=b.EXT_COVAR_06_07,  \
-            "+modelLong+"Covar88=b.EXT_COVAR_07_07,   \
-            "+"serNu=b.EXT_PAR_07,   \
-            "+"serNuErr=SQRT(EXT_COVAR_07_07)  \
-            WHERE a.ippDetectID=b.IPP_IDET AND b.MODEL_TYPE = '"+ippModelType+"'"
-
+        if (ippModelType == "PS_MODEL_SERSIC"):
+            extra_sql = ""
+            if hasResult:
+                extra_sql = ","+f+"serNuErr=SQRT(EXT_COVAR_07_07)"
+            sql = "UPDATE StackModelFit AS a, "+ f+ "SkyChip_xfit AS b SET \
+            "+f+"serNu=b.EXT_PAR_07   \
+            "+extra_sql+" \
+            WHERE a."+f+"ippDetectID=b.IPP_IDET AND b.MODEL_TYPE = '"+ippModelType+"'"
+#           "+f+"serNuErr=SQRT(EXT_COVAR_07_07)  \
+            self.logger.infoPair("sql",sql)
             self.scratchDb.execute(sql)
 
@@ -362,7 +445,34 @@
     Populates the StackMeta table, mainly from dictionary values found in IPP FITS header
     '''
-    def populateStackMeta(self):
+    def populateStackMeta(self,filterName):
 
         self.logger.infoPair("Procesing table", "StackMeta")
+
+        # this should work : set header into (grizy)header and run from there
+        if filterName == 'g.00000':
+            f = "g"
+            self.header = self.gheader
+            tablename = 'gStackMeta'
+            stackmetaid = self.gstackID
+        if filterName == 'r.00000':
+            f = "r"
+            tablename = 'rStackMeta'
+            self.header = self.rheader
+            stackmetaid = self.rstackID
+        if filterName == 'i.00000':
+            f = "i"
+            tablename = 'iStackMeta'
+            self.header = self.iheader
+            stackmetaid = self.istackID
+        if filterName == 'z.00000':
+            f = "z"
+            tablename = 'zStackMeta'
+            self.header = self.zheader
+            stackmetaid = self.zstackID
+        if filterName == 'y.00000':
+            f = "y"
+            tablename = 'yStackMeta'
+            self.header = self.yheader
+            stackmetaid = self.ystackID
 
         self.fwhm_maj    = self.safeDictionaryAccess(self.header, 'FWHM_MAJ')
@@ -376,7 +486,17 @@
         # print "psfmodel    = ", self.psfmodel
 
-        sql = "INSERT INTO StackMeta (\
+        #make a table
+
+        filterid = self.scratchDb.getFilterID(f)
+        self.logger.infoPair("filterid is ",str(filterid))
+
+        sql = "CREATE TABLE " + tablename + " LIKE StackMeta"
+        try: self.scratchDb.execute(sql)
+        except: pass
+
+        sql = "INSERT INTO " + tablename + " (\
         stackMetaID \
-        ,skycellID \
+        ,filterID \
+        ,skyCellID \
         ,photoCalID \
         ,photoZero \
@@ -398,9 +518,10 @@
         ,pc002002 \
          ) VALUES ( \
-        " + str(self.id) + " \
+        " + str(stackmetaid) + " \
+        , " + str(filterid) + "  \
         ," + self.skycell + " \
         ," + str(self.scratchDb.getPhotoCalID(self.header['IMAGEID'])) + " \
         ," + self.header['FPA.ZP'] + " \
-        ," + self.expTime + " \
+        ," + self.header['EXPTIME'] + " \
         ,'" + self.psfmodel   + "' \
         ," + str(self.fwhm_maj)    + " \
@@ -420,137 +541,158 @@
         )"
         self.scratchDb.execute(sql)
-        self.scratchDb.updateAllRows("StackMeta", "batchID", str(self.batchID))
-        self.scratchDb.updateAllRows("StackMeta", "surveyID", str(self.surveyID))
-        self.scratchDb.updateFilterID("StackMeta", self.filter)
-        self.scratchDb.updateAllRows("StackMeta", "dataRelease", str(self.skychunk.dataRelease))
-        self.updateStackTypeID("StackMeta")
-
-    '''
-    Populates the StackDetection table
-    '''
-    def populateStackDetection(self):
-
-        self.logger.infoPair("Procesing table", "StackDetection")
-
-        # insert all the detections
-        sql = "INSERT INTO StackDetection (\
-               ippDetectID \
-               ,skyCellID \
-               ,projectionCellID \
-               ,xPos \
-               ,yPos \
-               ,xPosErr \
-               ,yPosErr \
-               ,psfFlux \
-               ,psfFluxErr \
-               ,peakFlux \
-               ,sky \
-               ,skyErr \
-               ,sgSep \
-               ,psfWidMajor \
-               ,psfWidMinor \
-               ,psfTheta \
-               ,psfLikelihood \
-               ,infoFlag \
-               ,psfQf \
-               ,psfQfPerfect \
-               ,psfChiSq \
-               ,momentXX \
-               ,momentXY \
-               ,momentYY \
-               ,momentM3C \
-               ,momentM3S \
-               ,momentM4C \
-               ,momentM4S \
-               ,momentR1 \
-               ,momentRH \
-               ,apFlux \
-               ,apFluxErr \
-               ,kronFlux \
-               ,kronFluxErr \
-               ,kronRad \
-               ,nFrames \
-               ,assocDate \
-               ,historyModNum \
-               ) \
-               SELECT \
-               IPP_IDET \
-               ," + self.skycell + " \
-               ," + self.projectioncell + " \
-               ,X_PSF \
-               ,Y_PSF \
-               ,X_PSF_SIG \
-               ,Y_PSF_SIG \
-               ,PSF_INST_FLUX / " + str(self.expTime) + " \
-               ,PSF_INST_FLUX_SIG / " + str(self.expTime) + " \
-               ,POW(10.0, (-0.4*PEAK_FLUX_AS_MAG)) / " + str(self.expTime) + " \
-               ,SKY / " + str(self.expTime) + " \
-               ,SKY_SIGMA / " + str(self.expTime) + " \
-               ,EXT_NSIGMA \
-               ,PSF_MAJOR \
-               ,PSF_MINOR \
-               ,PSF_THETA \
-               ,psfLikelihood(EXT_NSIGMA) \
-               , FLAGS2 << 32 | FLAGS \
-               ,PSF_QF \
-               ,PSF_QF_PERFECT \
-               ,PSF_CHISQ / PSF_NDOF \
-               ,MOMENTS_XX \
-               ,MOMENTS_XY \
-               ,MOMENTS_YY \
-               ,MOMENTS_M3C \
-               ,MOMENTS_M3S \
-               ,MOMENTS_M4C \
-               ,MOMENTS_M4S \
-               ,MOMENTS_R1 \
-               ,MOMENTS_RH \
-               ,POW(10.0, -0.4*AP_MAG) / " + str(self.expTime) + " \
-               ,NULL \
-               ,KRON_FLUX / " + str(self.expTime) + " \
-               ,KRON_FLUX_ERR / " + str(self.expTime) + " \
-               ,MOMENTS_R1 * 2.5 \
-               ,N_FRAMES \
-               , '" + self.dateStr + "' \
-               ," + self.historyModNum + " \
-               FROM SkyChip_psf"
-
-# these were used above (left over from before PSF_INST_FLUX, PSF_INST_FLUX_SIG were available?
-#               ,POW(10.0, (-0.4*PSF_INST_MAG)) / " + str(self.expTime) + " 
-#               ,ABS((PSF_INST_MAG_SIG*(POW(10.0, (-0.4*PSF_INST_MAG)) / " + str(self.expTime) + ")) / 1.085736) 
-#               ,POW(10.0, -0.4*AP_MAG) / " + str(self.expTime) + " 
-
-# I need a way to choose the sql above based on the cmf version: V3 (LAP.PV1) does not have AP_FLUX
-#               ,AP_FLUX / " + str(self.expTime) + " 
-
-        # print "sql: ", sql
-        # response = raw_input("ready to insert stack det ")
-
-        self.scratchDb.execute(sql)
-
-        #it is possible to drop some detections from dvo (that are present in the cmf). when that happens we get a 0 for objid
+
+
+        self.scratchDb.updateAllRows(tablename, "batchID", str(self.batchID))
+        self.scratchDb.updateAllRows(tablename, "surveyID", str(self.surveyID))
+    #    self.scratchDb.updateFilterID(tablename, self.scratchDb.getFilterID(filterName))
+        self.scratchDb.updateAllRows(tablename, "dataRelease", str(self.skychunk.dataRelease))
+        self.updateStackTypeID(tablename)
+
+    '''
+    Populates the StackObject table
+    '''
+    def populateStackObject(self):
+
+        self.logger.infoPair("Procesing table", "StackObject")
+        
+        self.logger.infoPair("inserting non-filter dependent items into", "StackObject")
+
+        #this is dvo crap
+        #sql = "INSERT INTO StackObject(\
+        #      objID, \
+        #      gcobjID, \
+        #      ippObjID, \
+        #      surveyID, \
+        #      skyCellID, \
+        #      randomStackObjID, \
+        #      stackDetectRowID, \
+        #      dvoRegionID, \
+        #      dataRelease) SELECT \
+        #      -999,
+        #      -999,
+        #      -999,
+        #      ,
+              
+        
+        
+
+        self.logger.infoPair("inserting filter dependent cmf items into", "StackObject")
+        filters =['g','r','i','z','y']
+        for f in filters:
+          skip = 0
+          if (f == "g"):
+              self.logger.infoPair("gstackID = ",self.gstackID)
+              if self.gstackID > 0:  
+                  stackid = self.gstackID
+                  exptime = self.gheader['EXPTIME']
+              else:
+                  skip = 1
+          if (f == "r"):
+              self.logger.infoPair("rstackID = ",self.rstackID)
+              if self.rstackID > 0:
+                  stackid = self.rstackID
+                  exptime = self.rheader['EXPTIME']
+              else:
+                  skip = 1
+          if (f == "i"):
+              self.logger.infoPair("istackID = ",self.istackID)
+              if self.istackID > 0:
+                  stackid = self.istackID
+                  exptime = self.iheader['EXPTIME']
+              else:
+                  skip = 1
+          if (f == "z"):
+              self.logger.infoPair("zstackID = ",self.zstackID)
+              if self.zstackID > 0:
+                  stackid = self.zstackID
+                  exptime = self.zheader['EXPTIME']
+              else:
+                  skip = 1
+          if (f == "y"):
+              self.logger.infoPair("ystackID = ",self.ystackID)
+              if self.ystackID > 0:
+                  stackid = self.ystackID
+                  exptime = self.yheader['EXPTIME']
+              else:
+                  skip = 1
+
+          if skip == 1:
+              self.logger.infoPair("nothing for filter" , f) 
+          else:
+             self.logger.infoPair("filter",f)
+
+
+
+             # insert all the detections
+             sql = "UPDATE StackObject as a , " + f + "SkyChip_psf as b set \
+                   a."+f+"xPos = b.X_PSF \
+                   ,a."+f+"yPos = b.Y_PSF \
+                   ,a."+f+"xPosErr = b.X_PSF_SIG \
+                   ,a."+f+"yPosErr = b.Y_PSF_SIG \
+                   ,a."+f+"PSFFlux = b.PSF_INST_FLUX / " + str(exptime) + " \
+                   ,a."+f+"PSFFluxErr = b.PSF_INST_FLUX_SIG / " + str(exptime) + " \
+                   ,a."+f+"sky = b.SKY / " + str(exptime) + " \
+                   ,a."+f+"skyErr = b.SKY_SIGMA / " + str(exptime) + " \
+                   ,a."+f+"psfMajorFWHM = b.PSF_MAJOR \
+                   ,a."+f+"psfMinorFWHM = b.PSF_MINOR \
+                   ,a."+f+"psfTheta = b.PSF_THETA \
+                   ,a."+f+"psfCore = NULL \
+                   ,a."+f+"psfLikelihood = psfLikelihood(b.EXT_NSIGMA) \
+                   ,a."+f+"infoFlag = b.FLAGS2 << 32 | FLAGS \
+                   ,a."+f+"psfQf = b.PSF_QF \
+                   ,a."+f+"psfQfPerfect = b.PSF_QF_PERFECT \
+                   ,a."+f+"psfChiSq = b.PSF_CHISQ / b.PSF_NDOF \
+                   ,a."+f+"momentXX = b.MOMENTS_XX \
+                   ,a."+f+"momentXY = b.MOMENTS_XY \
+                   ,a."+f+"momentYY = b.MOMENTS_YY \
+                   ,a."+f+"momentR1 = b.MOMENTS_R1 \
+                   ,a."+f+"momentRH = b.MOMENTS_RH \
+                   ,a."+f+"ApFlux = POW(10.0, -0.4*b.AP_MAG) / " + str(exptime) + " \
+                   ,a."+f+"ApFluxErr = NULL \
+                   ,a."+f+"ApFillFac = NULL \
+                   ,a."+f+"KronFlux = b.KRON_FLUX / " + str(exptime) + " \
+                   ,a."+f+"KronFluxErr = b.KRON_FLUX_ERR / " + str(exptime) + " \
+                   ,a."+f+"KronRad = b.MOMENTS_R1 * 2.5 \
+                   ,a."+f+"PSFMag = b.PSF_INST_MAG    \
+                   ,a."+f+"PSFMagErr = b.PSF_INST_MAG_SIG    \
+                   ,a."+f+"ApMag = b.AP_MAG    \
+                   ,a."+f+"ApMagErr = NULL    \
+                   ,a."+f+"KronMag = NULL    \
+                   ,a."+f+"KronMagErr = NULL    \
+                   ,a."+f+"nFrames = b. N_FRAMES \
+                   WHERE a." + f + "ippDetectID=b.IPP_IDET "
+             self.logger.infoPair('sql', sql)     
+             try:
+                 self.scratchDb.execute(sql)
+             except:
+                 self.logger.errorPair('failed sql',sql)
+                 return
+             #it is possible to drop some detections from dvo (that are present in the cmf). when that happens we get a 0 for objid
         #we drop those...
-        sql="DELETE FROM StackDetection where objID = 0"
-        self.scratchDb.execute(sql)
-        self.logger.infoPair("Deleting", "entries with StackDetection.objID = 0")
-        
-        # XXX EAM : this seems quite inefficient : these commands use updates to set 
-        # fields which are constant across all rows.  Why not just include these in 
-        # the original insert above?
-
-        self.scratchDb.updateAllRows("StackDetection", "surveyID", str(self.surveyID))
-        
-        self.scratchDb.updateFilterID("StackDetection", self.filter)
-        
-        self.scratchDb.updateAllRows("StackDetection", "dataRelease", str(self.skychunk.dataRelease))
-        #set primary F to 0
-        self.scratchDb.updateAllRows("StackDetection", "primaryF", "0")
-        
-        self.scratchDb.updateAllRows("StackDetection", "activeFlag", "0")
-        
-        self.updateStackMetaID("StackDetection")
-        
-        self.updateStackTypeID("StackDetection")
-        
-        self.updateDvoIDsAndFlags("StackDetection")
+
+        self.logger.infoPair("Deleting", "entries with StackObject.objID = 0")
+        sql="DELETE FROM StackObject where objID = 0"
+        try:
+            self.scratchDb.execute(sql)
+        except:
+            self.logger.errorPair('failed sql',sql)
+            return
+        
+        try:
+            self.scratchDb.updateAllRows("StackObject", "surveyID", str(self.surveyID))
+        except:
+            self.logger.errorPair('failed update surveyID on','StackObject')
+            raise
+#        self.scratchDb.updateFilterID("StackObject", f+".00000")
+        
+        self.scratchDb.updateAllRows("StackObject", "dataRelease", str(self.skychunk.dataRelease))
+        try:
+            self.updateStackMetaID("StackObject")
+        except:
+            self.logger.errorPair("failed update stack meta id on ", "StackObject")
+            raise
+        ##self.updateStackTypeID("StackObject")
+        
+        #self.updateDvoIDsAndFlags("StackObject")
         #this now updates primary F as well
         # response = raw_input("updated dvo ")
@@ -565,5 +707,5 @@
             self.scratchDb.execute("set session old_alter_table=1")
 
-        sql = "ALTER IGNORE TABLE StackDetection ADD PRIMARY KEY (objID)"
+        sql = "ALTER IGNORE TABLE StackObject ADD PRIMARY KEY (objID)"
         
         if self.scratchDb.version > 5.1:
@@ -575,7 +717,7 @@
         ### XXX this should not be a DEEP_STACK only case...
         if False and self.stackType == "DEEP_STACK": 
-
+            ## need to do for all filters?
             #if deep stack and instFlux = null and err not null
-            sql = "UPDATE StackDetection AS a, SkyChip_psf AS b \
+            sql = "UPDATE StackObject AS a, SkyChip_psf AS b \
                    SET psfFlux = 2*b.PSF_INST_FLUX_SIG / " + str(self.expTime) + " \
                    WHERE psfFlux IS NULL \
@@ -585,28 +727,61 @@
             self.scratchDb.execute(sql)
             # response = raw_input("add psf flux ")
-            
+         
+        #filter dependent
         # NOTE : Flux limits : in the current PSPS schema, negative fluxes 
         # cause problems for sql queries which work in mags as SQL cannot do
         # something like (f < 0.0) ? -999 : -2.5*log10(f)
         # as a result, the negative fluxes here result in floating point errors
-        sql = "UPDATE StackDetection SET psfFlux = 1e20 WHERE psfFlux <= 0.0"
-        self.scratchDb.execute(sql)
-        
-        sql = "UPDATE StackDetection SET apFlux = 1e20 WHERE apFlux <= 0.0"
-        self.scratchDb.execute(sql)
-
-        sql = "UPDATE StackDetection SET kronFlux = 1e20 WHERE kronFlux <= 0.0"
+        sql = "UPDATE StackObject SET gPSFFlux = 1e20 WHERE gPSFFlux <= 0.0"
+        self.scratchDb.execute(sql)
+        
+        sql = "UPDATE StackObject SET gApFlux = 1e20 WHERE gApFlux <= 0.0"
+        self.scratchDb.execute(sql)
+
+        sql = "UPDATE StackObject SET gKronFlux = 1e20 WHERE gKronFlux <= 0.0"
+        self.scratchDb.execute(sql)
+        sql = "UPDATE StackObject SET rPSFFlux = 1e20 WHERE rPSFFlux <= 0.0"
+        self.scratchDb.execute(sql)
+        
+        sql = "UPDATE StackObject SET rApFlux = 1e20 WHERE rApFlux <= 0.0"
+        self.scratchDb.execute(sql)
+
+        sql = "UPDATE StackObject SET rKronFlux = 1e20 WHERE rKronFlux <= 0.0"
+        self.scratchDb.execute(sql)
+        sql = "UPDATE StackObject SET iPSFFlux = 1e20 WHERE iPSFFlux <= 0.0"
+        self.scratchDb.execute(sql)
+        
+        sql = "UPDATE StackObject SET iApFlux = 1e20 WHERE iApFlux <= 0.0"
+        self.scratchDb.execute(sql)
+
+        sql = "UPDATE StackObject SET iKronFlux = 1e20 WHERE iKronFlux <= 0.0"
+        self.scratchDb.execute(sql)
+        sql = "UPDATE StackObject SET zPSFFlux = 1e20 WHERE zPSFFlux <= 0.0"
+        self.scratchDb.execute(sql)
+        
+        sql = "UPDATE StackObject SET zApFlux = 1e20 WHERE zApFlux <= 0.0"
+        self.scratchDb.execute(sql)
+
+        sql = "UPDATE StackObject SET zKronFlux = 1e20 WHERE zKronFlux <= 0.0"
+        self.scratchDb.execute(sql)
+        sql = "UPDATE StackObject SET yPSFFlux = 1e20 WHERE yPSFFlux <= 0.0"
+        self.scratchDb.execute(sql)
+        
+        sql = "UPDATE StackObject SET yApFlux = 1e20 WHERE yApFlux <= 0.0"
+        self.scratchDb.execute(sql)
+
+        sql = "UPDATE StackObject SET yKronFlux = 1e20 WHERE yKronFlux <= 0.0"
         self.scratchDb.execute(sql)
 
         #leave null instflux in
-        #self.scratchDb.reportAndDeleteRowsWithNULLS("StackDetection", "instFlux")
-        
-        self.scratchDb.reportAndDeleteRowsWithNULLS("StackDetection", "objID")
+        #self.scratchDb.reportAndDeleteRowsWithNULLS("StackObject", "instFlux")
+        
+        self.scratchDb.reportAndDeleteRowsWithNULLS("StackObject", "objID")
         # response = raw_input("delete nulls ")
         
-        sql="DELETE FROM StackDetection where objID = 0"
-        
-        self.scratchDb.execute(sql)
-        self.logger.infoPair("Deleting", "entries with StackDetection.objID = 0")
+        sql="DELETE FROM StackObject where objID = 0"
+        
+        self.scratchDb.execute(sql)
+        self.logger.infoPair("Deleting", "entries with StackObject.objID = 0")
         # response = raw_input("deleted objID is 0 ")
         
@@ -616,63 +791,46 @@
     '''
     def populateStackApFlx(self):
-        self.logger.infoPair("getting","imageID")
-        imageID = self.scratchDb.getImageIDFromExternID(self.header['IMAGEID'])
-        self.logger.infoPair("obtained","imageID")
-
-        self.logger.infoPair("Procesing", "StackApFlx")
- 
-        sql = "INSERT INTO StackApFlx \
-               (ippDetectID ) \
-               SELECT \
-               DISTINCT IPP_IDET \
-               FROM SkyChip_xrad"
-
-        try:
-            self.scratchDb.execute(sql)
-        except: return
-
-        # TODO temporarily loading 1st convolved fluxes into unconvolved fields
-        self.logger.infoPair("Adding fluxes", "un-convolved")
-        self.updateApFlxs("", "IS NULL")
-        self.logger.infoPair("Adding fluxes", "1st convolved")
-        self.updateApFlxs("c1", "< 7.0")
-        self.logger.infoPair("Adding fluxes", "2nd convolved")
-        self.updateApFlxs("c2", "> 7.0")
-
-        self.logger.infoPair("Adding", "petrosians for extended sources")
-        sql = "UPDATE StackApFlx AS a, SkyChip_xsrc AS b SET \
-        petRadius=b.PETRO_RADIUS \
-        ,petRadiusErr=b.PETRO_RADIUS_ERR \
-        ,petFlux=POW(10.0, -0.4 * b.PETRO_MAG) /" + str(self.expTime) + " \
-        ,petFluxErr=ABS(b.PETRO_MAG_ERR) * POW(10.0, (-0.4*b.PETRO_MAG)) / " + str(self.expTime) + " / 1.085736  \
-        ,petR50=b.PETRO_RADIUS_50 \
-        ,petR50Err=b.PETRO_RADIUS_50_ERR \
-        ,petR90=b.PETRO_RADIUS_90 \
-        ,petR90Err=b.PETRO_RADIUS_90_ERR \
-        ,petCf=b.PETRO_FILL \
-        WHERE a.ippDetectID=b.IPP_IDET"
-        self.scratchDb.execute(sql)
-
-        self.logger.infoPair("adding"," PrimaryF to stackApFlx")
-        sql = "UPDATE StackApFlx AS a, " + self.scratchDb.dvoDetectionTable + " AS b SET \
-               a.primaryF = ((b.flags & 0x10000) >> 16 ) \
-               WHERE a.ippDetectID = b.ippDetectID \
-               AND b.imageID = " + str(imageID)
-
-        print "update dvo sql: ", sql
-        # response = raw_input("update dvo...")
-        self.scratchDb.execute(sql)
-
-        
-
-        self.scratchDb.updateAllRows("StackApFlx", "surveyID", str(self.surveyID))
-        self.scratchDb.updateFilterID("StackApFlx", self.filter)
-        self.scratchDb.updateAllRows("StackApFlx", "dataRelease", str(self.skychunk.dataRelease))
-        self.scratchDb.updateAllRows("StackApFlx", "activeFlag", "0")
-        self.updateStackMetaID("StackApFlx")
-        self.updateStackTypeID("StackApFlx")
-        self.updateDvoIDs("StackApFlx")
+        filter = ['g','r','i','z','y']
+
+        for f in filter:
+            skip = 0 
+            if (f == 'g'):
+                if self.gstackID > 0:
+                    self.header = self.gheader
+                else:
+                    skip = 1
+            if (f == 'r'):
+                if self.rstackID > 0:
+                    self.header = self.rheader
+                else:
+                    skip = 1
+            if (f == 'i'):
+                if self.istackID > 0:
+                    self.header = self.iheader
+                else:
+                    skip = 1
+            if (f == 'z'):
+                if self.zstackID > 0:
+                    self.header = self.zheader
+                else:
+                    skip = 1
+            if (f == 'y'):
+                if self.ystackID > 0:
+                    self.header = self.yheader
+                else:
+                    skip =1 
+
+            if skip == 0:
+                self.logger.infoPair("Adding fluxes", "un-convolved")
+                self.updateModelFitFlxs("", "((b.table_index -1) % 3 = 0)", "StackApFlx", f)
+                self.logger.infoPair("Adding fluxes", "1st convolved")
+                self.updateModelFitFlxs("c1", "((b.table_index -1) % 3 = 1)","StackApFlx",f)
+                self.logger.infoPair("Adding fluxes", "2nd convolved")
+                self.updateModelFitFlxs("c2", "((b.table_index -1) % 3 = 2)","StackApFlx",f)
+
+                self.deleteDetectionsNotInStackObject("StackApFlx",f)
+
         self.scratchDb.reportAndDeleteRowsWithNULLS("StackApFlx", "objID")
-        self.deleteDetectionsNotInStackDetection("StackApFlx")
+       
 
 
@@ -680,5 +838,23 @@
     Populates the StackModelFit table
     '''
-    def populateStackModelFit(self):
+    def populateStackModelFit(self, filter):
+        # for each filter
+        f =filter
+        if (filter == 'g'):
+            self.header = self.gheader
+            
+        if (filter == 'r'):
+            self.header = self.rheader
+        if (filter == 'i'):
+            self.header = self.iheader
+        if (filter == 'z'):
+            self.header = self.zheader
+        if (filter == 'y'):
+            self.header = self.yheader
+            
+
+
+
+
         self.logger.infoPair("getting","imageID")
         imageID = self.scratchDb.getImageIDFromExternID(self.header['IMAGEID'])
@@ -688,23 +864,51 @@
 
         # insert all the detections
-        sql = "INSERT INTO StackModelFit (ippDetectID) SELECT DISTINCT IPP_IDET from SkyChip_xfit"
-        try:
-            self.scratchDb.execute(sql)
-        except:
-            return
 
         # populate model parameters
         self.logger.infoPair("Adding model fit", "deVaucouleurs")
-        self.updateModelFit("deV", "PS_MODEL_DEV")
+        self.updateModelFit("deV", "PS_MODEL_DEV", filter, self.header['EXPTIME'])
         self.logger.infoPair("Adding model fit", "exponential")
-        self.updateModelFit("exp", "PS_MODEL_EXP")
+        self.updateModelFit("deV", "PS_MODEL_EXP", filter, self.header['EXPTIME'])
         self.logger.infoPair("Adding model fit", "sersic")
-        self.updateModelFit("ser", "PS_MODEL_SERSIC")
+        self.updateModelFit("deV", "PS_MODEL_SERSIC", filter, self.header['EXPTIME'])
+ 
+
+        self.logger.infoPair("Adding fluxes", "un-convolved")
+        self.updateModelFitFlxs("", "((b.table_index -1) % 3 = 0)","StackModelFit",f)
+        self.logger.infoPair("Adding fluxes", "1st convolved")
+        self.updateModelFitFlxs("c1", "((b.table_index -1) % 3 = 1)","StackModelFit",f)
+        self.logger.infoPair("Adding fluxes", "2nd convolved")
+        self.updateModelFitFlxs("c2", "((b.table_index -1) % 3 = 2)","StackModelFit",f)
+
+ 
+        self.logger.infoPair("Adding", "petrosians for extended sources")
+        sql = "UPDATE StackModelFit as a, "+f+"SkyChip_xsrc AS b SET \
+        "+f+"petRadius=b.PETRO_RADIUS \
+        ,"+f+"petRadiusErr=b.PETRO_RADIUS_ERR \
+        ,"+f+"petFlux=POW(10.0, -0.4 * b.PETRO_MAG) /" + str(self.header['EXPTIME']) + " \
+        ,"+f+"petFluxErr=-999  \
+        ,"+f+"petR50=b.PETRO_RADIUS_50 \
+        ,"+f+"petR50Err=b.PETRO_RADIUS_50_ERR \
+        ,"+f+"petR90=b.PETRO_RADIUS_90 \
+        ,"+f+"petR90Err=b.PETRO_RADIUS_90_ERR \
+        ,"+f+"petCf=b.PETRO_FILL \
+        WHERE a."+f+"ippDetectID=b.IPP_IDET"
+        self.scratchDb.execute(sql)
+
+        self.logger.infoPair("Adding", "petFluxErr for non nulls")
+        sql = "UPDATE StackModelFit as a, "+f+"SkyChip_xsrc AS b SET \
+        "+f+"petFluxErr=ABS(b.PETRO_MAG_ERR) * POW(10.0, (-0.4*b.PETRO_MAG)) / " + str(self.header['EXPTIME']) + " / 1.085736  \
+        WHERE a."+f+"ippDetectID=b.IPP_IDET \
+        AND (b.PETRO_MAG_ERR is not NULL AND b.PETRO_MAG is not NULL AND PETRO_MAG_ERR < 1000.0)"
+        # added this because when the petromagerr is crazy large (10^29 it out of ranges the flux err calc)
+        self.logger.infoPair("sql", sql)
+        self.scratchDb.execute(sql)
+
+
 
         self.scratchDb.updateAllRows("StackModelFit", "surveyID", str(self.surveyID))
-        self.scratchDb.updateFilterID("StackModelFit", self.filter)
         self.scratchDb.updateAllRows("StackModelFit", "dataRelease", str(self.skychunk.dataRelease))
 
-        self.logger.infoPair("adding"," PrimaryF to stackApFlx")
+        self.logger.infoPair("not adding"," PrimaryF to stackApFlx")
         sql = "UPDATE StackModelFit AS a, " + self.scratchDb.dvoDetectionTable + " AS b SET \
                a.primaryF = ((b.flags & 0x10000) >> 16 ) \
@@ -712,24 +916,23 @@
                AND b.imageID = " + str(imageID)
 
-        print "update dvo sql: ", sql
-        # response = raw_input("update dvo...")
-        try:
-            self.scratchDb.execute(sql)
-        except:
-            return
-
-        self.scratchDb.updateAllRows("StackModelFit", "activeFlag", "0")
-        self.updateStackMetaID("StackModelFit")
-        self.updateStackTypeID("StackModelFit")
-        self.updateDvoIDs("StackModelFit")
+#        try:
+#            self.scratchDb.execute(sql)
+#        except:
+#            return
+
+##        self.scratchDb.updateAllRows("StackModelFit", "activeFlag", "0")
+        ##self.updateStackMetaID("StackModelFit")
+##        self.updateStackTypeID("StackModelFit")
+        
         self.scratchDb.reportAndDeleteRowsWithNULLS("StackModelFit", "objID")
-        self.deleteDetectionsNotInStackDetection("StackModelFit")
-
-    '''
-    Reports and deletes detections in this table that are not in StackDetection
-    '''
-    def deleteDetectionsNotInStackDetection(self, table):
-
-        sql = "SELECT COUNT(*) FROM " + table + " WHERE ippDetectID NOT IN (SELECT ippDetectID FROM StackDetection)"
+        self.deleteDetectionsNotInStackObject("StackModelFit", f)
+
+    '''
+    Reports and deletes detections in this table that are not in StackObject
+    '''
+    def deleteDetectionsNotInStackObject(self, table, filter):
+        f= filter
+
+        sql = "SELECT COUNT(*) FROM " + table + " WHERE "+f+"ippDetectID NOT IN (SELECT "+f+"ippDetectID FROM StackObject)"
         rs = self.scratchDb.executeQuery(sql)
         rs.first()
@@ -738,7 +941,7 @@
         if nMissing < 1: return
         
-        sql = "DELETE FROM " + table + " WHERE ippDetectID NOT IN (SELECT ippDetectID FROM StackDetection)"
-        self.scratchDb.execute(sql)
-        self.logger.infoPair("Detections not in StackDetection", "%d deleted from %s" % (nMissing, table))
+        sql = "DELETE FROM " + table + " WHERE "+f+"ippDetectID NOT IN (SELECT "+f+"ippDetectID FROM StackObject)"
+        self.scratchDb.execute(sql)
+        self.logger.infoPair("Detections not in StackObject", "%d deleted from %s" % (nMissing, table))
        
 
@@ -749,167 +952,142 @@
 
         self.logger.infoPair("Procesing table", "StackToImage")
-
-        imageIDs = self.gpc1Db.getImageIDsForThisStackID(self.id)
-
-        for imageID in imageIDs:
-            sql = "INSERT INTO StackToImage (stackMetaID, imageID) \
+        filters = ['g','r','i','z','y']
+        for f in filters:
+            
+            if f == 'g':
+                stackmetaid = self.gstackID
+            if f == 'r':
+                stackmetaid = self.rstackID
+            if f == 'i':
+                stackmetaid = self.istackID
+            if f == 'z':
+                stackmetaid = self.zstackID
+            if f == 'y':
+                stackmetaid = self.ystackID
+            if stackmetaid > 0:
+    
+                imageIDs = self.gpc1Db.getImageIDsForThisStackID(stackmetaid)
+
+                for imageID in imageIDs:
+                    sql = "INSERT INTO StackToImage (stackMetaID, imageID) \
                    VALUES (\
-                   " + str(self.id) + ", " + imageID + ")"
+                   " + str(stackmetaid) + ", " + imageID + ")"
+                    self.scratchDb.execute(sql)
+
+        # now update StackMeta with correct number of inputs
+                    sql = "UPDATE "+f+"StackMeta SET nP2Images = (SELECT COUNT(distinct(floor(imageID/100))) FROM StackToImage where stackMetaID = "+str(stackmetaid)+")"
+                    self.scratchDb.execute(sql)
+
+    ''' 
+    Generates the randomStackIds
+    '''
+    def populateRandomsAndSkyCellID(self):
+
+        self.logger.infoPair("Generating Randoms","for StackObject")
+        sql = "update StackObject set randomStackObjID = FLOOR(RAND()*9223372036854775807) \
+              ,skyCellID = " + str(self.skycell)+ " \
+              ,surveyID = " + str(self.surveyID) 
+        try:
             self.scratchDb.execute(sql)
-
-        # now update StackMeta with correct number of inputs
-        sql = "UPDATE StackMeta SET nP2Images = (SELECT COUNT(distinct(floor(imageID/100))) FROM StackToImage)"
-        self.scratchDb.execute(sql)
-
-    '''
-    Populates the SkinnyObject table
-    '''
-    def populateSkinnyObject(self):
-
-        self.logger.infoPair("Procesing table", "SkinnyObject")
-
-        sql = "INSERT INTO SkinnyObject (\
-               objID \
-               ,ippObjID \
-               ,projectionCellID \
-               ) \
-               SELECT \
-               DISTINCT objID \
-               ,ippObjID \
-               ,projectionCellID \
-               FROM StackDetection"
-        self.scratchDb.execute(sql)
-
-        self.scratchDb.updateAllRows("SkinnyObject", "surveyID", str(self.surveyID))
-        self.scratchDb.updateAllRows("SkinnyObject", "dataRelease", str(self.skychunk.dataRelease))
-
-    '''    
-    Populates the StackDetectionCalib table
-    XXX this can probably get a big speed increase by using 'SELECT () INTO OUTFILE '/tmp/name' and then
-    calling the load data infile '/tmp/name' into table;
-    '''
-    def populateStackDetectionCalibInsertUpdate(self):
-        self.logger.infoPair("Processing table", "StackDetectionCalib")
-        tableName = "StackDetectionCalib"
-        # insert all detections into table
-        sql = "INSERT INTO " + tableName + " ( \
-               objID \
-               ,stackDetectID \
-               ,ippObjID \
-               ,ippDetectID \
-               ,filterID \
-               ,surveyID \
-               ) \
-               SELECT \
-               objID \
-               ,stackDetectID \
-               ,ippObjID \
-               ,ippDetectID \
-               ,filterID \
-               ,surveyID \
-               FROM StackDetection"
-        self.scratchDb.execute(sql)
-
-        imageID = self.scratchDb.getImageIDFromExternID(self.header['IMAGEID'])
-        self.logger.infoPair("obtained","imageID")
-
-        # insert calibration information from dvoDetections into the Table
-        sql = "UPDATE " + tableName + " AS a, "  + self.scratchDb.dvoDetectionTable + " AS b \
-            SET a.ra = b.ra, \
-            a.dec = b.dec_, \
-            a.raErr = b.raErr, \
-            a.decErr = b.decErr, \
-            a.zp = b.zp, \
-            a.zpErr = b.zpErr, \
-            a.expTime = b.expTime, \
-            a.airMass = b.airMass   \
-            WHERE a.stackDetectID = b.detectID \
-            AND b.imageID = " + str(imageID)
-        self.scratchDb.execute(sql)
+        except:
+            self.logger.infoPair("failed sql", sql)
+
+    ''' 
+    copies randomStackIds from StackObject to tableName
+    '''
+    def copyRandomsAndSkyCellIDFromStackObject(self, tableName):
+
+        self.logger.infoPair("copying Randoms from StackObject to ", tableName)
+        sql = "update " + tableName + " join StackObject using (objID) \
+        set " + tableName + ".randomStackObjID = StackObject.randomStackObjID \
+        , " + tableName + ".skyCellID = StackObject.skyCellID \
+        , " + tableName + ".surveyID = StackObject.surveyID"
+        self.logger.infoPair("sql", sql)
+        try:
+            self.scratchDb.execute(sql)
+        except:
+            self.logger.infoPair("failed sql", sql)
+
+
+        
+    def populateStackIPPDetectIDFromDvo(self, tableName, all):
+
+        #tableName = "StackObject"
+        self.logger.infoPair("Processing table", tableName)
+
+        filters = ['g','r','i','z','y']
+        
+        for f in filters:
+            skip = 0
+            #first: do we skip this filter
+            if f == 'g':
+                if self.gstackID < 0:
+                    skip = 1
+                else:
+                    self.header=self.gheader
+                    stackmetaid = self.gstackID
+            elif f == 'r':
+                if self.rstackID < 0:
+                    skip = 1
+                else:
+                    self.header = self.rheader
+                    stackmetaid = self.rstackID
+            elif f == 'i':
+                if self.istackID < 0:
+                    skip = 1
+                else:
+                    self.header = self.iheader
+                    stackmetaid = self.istackID
+            elif f == 'z':
+                if self.zstackID < 0:
+                    skip = 1
+                else:
+                    self.header = self.zheader
+                    stackmetaid = self.zstackID
+            elif f == 'y':
+                if self.ystackID < 0:
+                    skip = 1
+                else:
+                    self.header = self.yheader
+                    stackmetaid = self.ystackID
+            if skip == 0:        
+                imageID = self.scratchDb.getImageIDFromExternID(self.header['IMAGEID'])
+                self.logger.infoPair("obtained","imageID")
+                addsql = ""
+                if (all == 1):
+                    addsql = "a." + f + "ra = b.ra, \
+                      a." + f + "dec = b.dec_, \
+                      a." + f + "raErr = b.raErr, \
+                      a." + f + "decErr = b.decErr, \
+                      a." + f + "zp = b.zp, \
+                      a." + f + "expTime = b.expTime,"
+
+                    
+                sql = "UPDATE " + tableName + " AS a, "  + self.scratchDb.dvoDetectionTable + " AS b \
+                      SET a." + f + "ippDetectID = b.ippDetectID, \
+                      " + addsql + " \
+                      a." + f + "stackDetectID = b.detectID,   \
+                      a." + f + "ippObjID = b.ippObjID, \
+                      a." + f + "stackMetaID = " + str(stackmetaid) +  " \
+                      WHERE a.objID = b.objID  AND b.imageID = " + str(imageID)
+                self.logger.infoPair('sql',sql)    
+                self.scratchDb.execute(sql)
+            else:
+                self.logger.infoPair("skipping ingest of dvo for filter",f)
+        #out of the loops - give dataRelase to all        
         self.scratchDb.updateAllRows(tableName, "dataRelease", str(self.skychunk.dataRelease))
-        
-    def populateStackDetectionCalib(self):
-
-        tableName = "StackDetectionCalib"
-        self.logger.infoPair("Processing table", tableName)
-
-        imageID = self.scratchDb.getImageIDFromExternID(self.header['IMAGEID'])
-        self.logger.infoPair("obtained","imageID")
-
-        # check for & create output directory first
-        datadumpDir = "/tmp/datadump"
-        try:
-            statinfo = os.stat(datadumpDir)
-            # check on the stat results?
-        except:
-            print "making the data dump directory ", datadumpDir
-            os.mkdir(datadumpDir)
-            os.chmod(datadumpDir, 0777)
-            statinfo = os.stat(datadumpDir)
-
-        dumpFile = datadumpDir + "/genetest.xx.dat"
-        files = glob.glob(dumpFile)
-        if len(files) > 0:
-            os.unlink(dumpFile)
-
-        # insert all detections into table
-        sql = "SELECT \
-          a.objID,    \
-          a.stackDetectID, \
-          a.ippObjID,      \
-          a.ippDetectID,   \
-          a.filterID,      \
-          a.surveyID,      \
-          b.ra,            \
-          b.dec_,          \
-          b.raErr,         \
-          b.decErr,        \
-          b.zp,            \
-          b.zpErr,         \
-          b.expTime,       \
-          b.airMass,       \
-          " + str(self.skychunk.dataRelease) + " \
-         FROM              \
-           StackDetection as a \
-         JOIN " + self.scratchDb.dvoDetectionTable + " as b \
-         ON (a.stackDetectID = b.detectID) where b.imageID = " + str(imageID) + \
-         " INTO OUTFILE '" + dumpFile + "'"
-
-        try: self.scratchDb.execute(sql)
-        except:
-            self.logger.info("failed to select data for stackDetectionCalib")
-            self.logger.infoPair("sql: ", sql)
-            raise
-
-        sql = "LOAD DATA INFILE '" + dumpFile + "' INTO TABLE " + tableName
-        try: self.scratchDb.execute(sql)
-        except:
-            self.logger.info("failed to load data from infile for stackDetectionCalib")
-            self.logger.infoPair("sql: ", sql)
-            raise
-
-        ## XXX write this with the select/insert
-        # self.scratchDb.updateAllRows(tableName, "dataRelease", str(self.skychunk.dataRelease))
-
-    '''
-    Populates the ObjectCalColor table
-    '''
-    def populateObjectCalColor(self):
-
-        self.logger.infoPair("Procesing table", "ObjectCalColor table")
-
-        sql = "INSERT INTO ObjectCalColor (\
-               objID \
-               ,ippObjID \
-               ) \
-               SELECT \
-               DISTINCT objID \
-               ,ippObjID \
-               FROM StackDetection"
-        self.scratchDb.execute(sql)
-
-        self.scratchDb.updateFilterID("ObjectCalColor", self.filter)
-        self.scratchDb.updateAllRows("ObjectCalColor", "dataRelease", str(self.skychunk.dataRelease))
-
+
+
+    def deleteNULLippDetectIDs(self, tableName):
+
+        self.logger.infoPair("Deleting NULL ippdetectIDs from table", tableName)
+        sql = "DELETE FROM " + tableName + " WHERE \
+              gippDetectID is NULL AND \
+              rippDetectID is NULL AND \
+              iippDetectID is NULL AND \
+              zippDetectID is NULL AND \
+              yippDetectID is NULL "
+        self.logger.infoPair('sql',sql)    
+        self.scratchDb.execute(sql)
 
     '''
@@ -920,13 +1098,9 @@
         self.logger.debug("Altering PSPS tables")
         # heather uncommented the unique line -- well that no worky
-        #self.scratchDb.makeColumnUnique("StackDetection", "objID")
-        self.scratchDb.createIndex("StackDetection", "ippDetectID")
-        self.scratchDb.createIndex("StackDetection", "stackDetectID")
+        #self.scratchDb.makeColumnUnique("StackObject", "objID")
+        self.scratchDb.createIndex("StackObject", "ippDetectID")
+        self.scratchDb.createIndex("StackObject", "stackDetectID")
         self.scratchDb.createIndex("StackApFlx", "ippDetectID")
         self.scratchDb.createIndex("StackModelFit", "ippDetectID")
-
-        # dec is reserved in MySQL, so STILTS replaces if with dec_, which is not the name of 
-        # the column in PSPS
-        self.scratchDb.execute("ALTER TABLE StackDetectionCalib CHANGE dec_ `dec` double")
 
         return True
@@ -944,10 +1118,37 @@
 
         return True
+    '''
+    Insert objid (from dvo) into table
+    '''
+    def insertDvoIDs(self, table, filterName):
+        self.logger.infoPair("getting imageID for ","filter")
+        if (filterName == 'g.00000'):
+            self.header=self.gheader
+        if (filterName == 'r.00000'):
+            self.header=self.rheader
+        if (filterName == 'i.00000'):
+            self.header=self.iheader
+        if (filterName == 'z.00000'):
+            self.header=self.zheader
+        if (filterName == 'y.00000'):
+            self.header=self.yheader
+
+        imageID = self.scratchDb.getImageIDFromExternID(self.header['IMAGEID'])
+        self.logger.infoPair("obtained","imageID")
+        self.logger.debug("Updating table '" + table + "' with DVO IDs...")
+        sql = "INSERT IGNORE INTO " + table + " ( \
+               objID ) \
+               SELECT (objID) FROM " + self.scratchDb.dvoDetectionTable + "  \
+               WHERE " + self.scratchDb.dvoDetectionTable + ".imageID = " + str(imageID)
+        self.logger.infoPair("sql",sql)
+        self.scratchDb.execute(sql)
+    
+
 
     '''
     Updates provided table with DVO IDs from DVO table
     '''
-    def updateDvoIDs(self, table):
-        self.logger.infoPair("getting","imageID")
+    def updateDvoIDs(self, table, filterName):
+        self.logger.infoPair("getting imageID for ","filter")
         imageID = self.scratchDb.getImageIDFromExternID(self.header['IMAGEID'])
         self.logger.infoPair("obtained","imageID")
@@ -979,5 +1180,4 @@
 
         print "update dvo sql: ", sql
-        # response = raw_input("update dvo...")
         self.scratchDb.execute(sql)
     
@@ -987,36 +1187,137 @@
     '''
     def populatePspsTables(self):
-
+        self.logger.infoPair("starting","populatePspsTables");
         self.skipBatch = False
-
         if not self.useFullTables:
-            if not self.getIDsFromDVO():
+             if not self.getIDsFromDVO():
                 return False
-        #self.logger.infoPair("populating","StackMeta")    
-        self.populateStackMeta()
-        #self.logger.infoPair("populating","StackDetection") 
-        self.populateStackDetection()
-        
-        if self.stackType != "NIGHTLY_STACK": 
-            #self.logger.infoPair("populating","StackModelFit") 
-            self.populateStackModelFit()
-            #self.logger.infoPair("populating","StackApFlx") 
+        #do some basics first
+        # populate stack meta per filter
+        # insert objid/stackdetectid per filter to each table           
+        self.tablesToExport=[]    
+
+        if self.gstackID > 0:        
+            self.logger.infoPair("populating","gStackMeta")    
+            self.populateStackMeta("g.00000")
+            self.insertDvoIDs("StackObject","g.00000")
+            self.insertDvoIDs("StackModelFit","g.00000")
+            self.insertDvoIDs("StackApFlx","g.00000")
+            self.tablesToExport.append("gStackMeta")
+        if self.rstackID > 0:    
+            self.logger.infoPair("populating","rStackMeta")    
+            self.populateStackMeta("r.00000")
+            self.insertDvoIDs("StackObject","r.00000")
+            self.insertDvoIDs("StackModelFit","r.00000")
+            self.insertDvoIDs("StackApFlx","r.00000")
+            self.tablesToExport.append("rStackMeta")
+        if self.istackID > 0:    
+            self.logger.infoPair("populating","iStackMeta")    
+            self.populateStackMeta("i.00000")
+            self.insertDvoIDs("StackObject","i.00000")
+            self.insertDvoIDs("StackModelFit","i.00000")
+            self.insertDvoIDs("StackApFlx","i.00000")
+            self.tablesToExport.append("iStackMeta")
+        if self.zstackID > 0:    
+            self.logger.infoPair("populating","zStackMeta")    
+            self.populateStackMeta("z.00000")
+            self.insertDvoIDs("StackObject","z.00000")
+            self.insertDvoIDs("StackModelFit","z.00000")
+            self.insertDvoIDs("StackApFlx","z.00000")
+            self.tablesToExport.append("zStackMeta")
+        if self.ystackID > 0:    
+            self.logger.infoPair("populating","yStackMeta")    
+            self.populateStackMeta("y.00000")
+            self.insertDvoIDs("StackObject","y.00000")
+            self.insertDvoIDs("StackModelFit","y.00000")
+            self.insertDvoIDs("StackApFlx","y.00000")
+            self.tablesToExport.append("yStackMeta")
+
+        self.logger.infoPair("populating ","StackObject")
+        # need to index on objid and ippdetectid  or it is stupidly slow
+        self.scratchDb.createIndex("StackObject", "objID")
+        #populate from dvo the (f)ippDetectID into StackObject  
+        self.populateStackIPPDetectIDFromDvo("StackObject",1)
+        #index the ippDetectids for the next step
+        self.scratchDb.createIndex("StackObject", "gippDetectID")
+        self.scratchDb.createIndex("StackObject", "rippDetectID")
+        self.scratchDb.createIndex("StackObject", "iippDetectID")
+        self.scratchDb.createIndex("StackObject", "zippDetectID")
+        self.scratchDb.createIndex("StackObject", "yippDetectID")
+        self.populateStackObject()
+        self.populateRandomsAndSkyCellID()
+        # stackObject should be done, pending a few NULL columns (need help)
+
+        if self.stackType != "NIGHTLY_STACK":
+
+            self.logger.infoPair("populating ","StackModelFit")
+
+            self.scratchDb.createIndex("StackModelFit", "objID")
+        #populate from dvo the (f)ippdetectid into stackModelFit
+            self.populateStackIPPDetectIDFromDvo("StackModelFit",0)
+        #index the ippDetectIds for the next step
+            self.scratchDb.createIndex("StackModelFit", "gippDetectID")
+            self.scratchDb.createIndex("StackModelFit", "rippDetectID")
+            self.scratchDb.createIndex("StackModelFit", "iippDetectID")
+            self.scratchDb.createIndex("StackModelFit", "zippDetectID")
+            self.scratchDb.createIndex("StackModelFit", "yippDetectID")
+        #cull the entries that should not be (how?)        
+            self.deleteNULLippDetectIDs("StackModelFit") 
+        #populate stackModelFit
+            if self.gstackID > 0:
+                self.logger.infoPair("populating g filter for stackModelFit, stackmetaid =", self.gstackID)
+                self.populateStackModelFit("g")
+            if self.rstackID > 0: 
+                self.logger.infoPair("populating r filter for stackModelFit, stackmetaid =", self.rstackID)
+                self.populateStackModelFit("r")
+            if self.istackID > 0: 
+                self.logger.infoPair("populating i filter for stackModelFit, stackmetaid =", self.istackID)
+                self.populateStackModelFit("i")
+            if self.zstackID > 0: 
+                self.logger.infoPair("populating z filter for stackModelFit, stackmetaid =", self.zstackID)
+                self.populateStackModelFit("z")
+            if self.ystackID > 0: 
+                self.logger.infoPair("populating y filter for stackModelFit, stackmetaid =", self.ystackID)
+                self.populateStackModelFit("y")
+           
+            self.copyRandomsAndSkyCellIDFromStackObject("StackModelFit")
+ 
+            self.logger.infoPair("populating ","StackApFlx")
+            
+            self.scratchDb.createIndex("StackApFlx", "objID")
+        #populate from dvo the (f)ippDetectID into StackApFlx
+            self.populateStackIPPDetectIDFromDvo("StackApFlx",0)
+        #index the ippDetectIDs for the next step 
+            self.scratchDb.createIndex("StackApFlx", "gippDetectID")
+            self.scratchDb.createIndex("StackApFlx", "rippDetectID")
+            self.scratchDb.createIndex("StackApFlx", "iippDetectID")
+            self.scratchDb.createIndex("StackApFlx", "zippDetectID")
+            self.scratchDb.createIndex("StackApFlx", "yippDetectID")
+        #populate StackApFlx
+            self.deleteNULLippDetectIDs("StackApFlx") 
             self.populateStackApFlx()
-        #self.logger.infoPair("populating","StackToImage") 
+            self.copyRandomsAndSkyCellIDFromStackObject("StackApFlx")
+        #cull the entries that should not be (how?) 
+        
+        
+        self.logger.infoPair("populating","StackToImage") 
         self.populateStackToImage()
-        #self.logger.infoPair("populating","SkinnyObject") 
-        self.populateSkinnyObject()
-        #self.logger.infoPair("populating","ObjectCalColor") 
-        #self.populateObjectCalColor()
-        #self.logger.infoPair("populating","StackDetectionCalib") 
-        self.populateStackDetectionCalib()
-
-        self.setMinMaxObjID(["StackDetection"])
-       
-        if self.totalDetections < 1: 
-
-            self.logger.error("No detections to publish")
-            return False
-
+        
+        self.setMinMaxObjID(["StackObject"])
+      #  self.updateStackTypeID("StackModelFit")
+
+        ##if self.totalDetections < 1: 
+
+            ##self.logger.error("No detections to publish")
+            ##return False
+        self.tablesToExport.append("StackToImage")
+        self.tablesToExport.append("StackObject")
+        self.tablesToExport.append("StackModelFit")
+        self.tablesToExport.append("StackApFlx")
+
+        self.logger.infoPair("finishing","populatePspsTables"); 
         return True
-
+    '''
+    overidding this method - use regex to trimoff letter before stack
+    '''
+    def exportPspsTablesToFits(self, regex="(.*)"):
+        return super(StackBatch, self).exportPspsTablesToFits("(Stack.*)")
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/perl/Makefile.am
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/perl/Makefile.am	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/perl/Makefile.am	(revision 37066)
@@ -1,3 +1,3 @@
-bin_SCRIPTS = checkOdmStatus.pl convertPhotCodesToXml.pl deleteFromDXLayer.pl pspsSchema2xml.pl
+bin_SCRIPTS = checkOdmStatus.pl convertPhotCodesToXml.pl deleteFromDXLayer.pl pspsSchema2xml.pl deleteFromDXLayer2.pl
 
 INSTALL = @INSTALL@ -C
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/perl/deleteFromDXLayer.pl
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/perl/deleteFromDXLayer.pl	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/perl/deleteFromDXLayer.pl	(revision 37066)
@@ -18,5 +18,12 @@
         );
 
-my $dxWebServiceUrl = "http://lsb01.psps.ifa.hawaii.edu/cgi-bin/dxlayer/dxwebservice.cgi";
+#my $dxWebServiceUrl = "http://lsb01.psps.ifa.hawaii.edu/cgi-bin/dxlayer/dxwebservice.cgi";
+
+#my $dxWebServiceUrl = "http://web02.psps.ifa.hawaii.edu/lsb01/cgi-bin/dxwebservice.cgi";
+my $dxWebServiceUrl = "http://web02.psps.ifa.hawaii.edu/lsb01/cgi-bin/dxlayer/dxwebservice.cgi";
+
+
+#my $dxWebServiceUrl2 = "http://lsb02.psps.ifa.hawaii.edu/cgi-bin/dxlayer/dxwebservice.cgi";
+
 #my $dxWebServiceUrl = "http://166.122.172.121/cgi-bin/dxlayer/dxwebservice.cgi";
 my $ua = LWP::UserAgent->new;
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/perl/deleteFromDXLayer2.pl
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/perl/deleteFromDXLayer2.pl	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/perl/deleteFromDXLayer2.pl	(revision 37066)
@@ -0,0 +1,66 @@
+#!/usr/bin/env perl
+
+use warnings;
+use strict;
+
+use LWP::UserAgent;
+use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
+use XML::LibXML;
+use File::Temp qw(tempfile);
+
+
+my $batchName = undef;
+my $file = undef;
+
+GetOptions(
+        'batch|b=s' => \$batchName,
+        'file|f=s' => \$file,
+        );
+
+#my $dxWebServiceUrl = "http://lsb02.psps.ifa.hawaii.edu/cgi-bin/dxlayer/dxwebservice.cgi";
+
+#my $dxWebServiceUrl = "http://web02.psps.ifa.hawaii.edu/lsb02/cgi-bin/dxwebservice.cgi";
+my $dxWebServiceUrl = "http://web02.psps.ifa.hawaii.edu/lsb02/cgi-bin/dxlayer/dxwebservice.cgi";
+#my $dxWebServiceUrl2 = "http://lsb02.psps.ifa.hawaii.edu/cgi-bin/dxlayer/dxwebservice.cgi";
+
+#my $dxWebServiceUrl = "http://166.122.172.121/cgi-bin/dxlayer/dxwebservice.cgi";
+my $ua = LWP::UserAgent->new;
+$ua->timeout(15);
+$ua->env_proxy;
+
+    my $doc = XML::LibXML::Document->new(); # Global document variable.
+    my $rootNode = $doc->createElement('AdminQueryParams');
+$doc->setDocumentElement($rootNode);
+
+my $paramNode = $doc->createElement('Param');
+$paramNode->setAttribute('Name', "BatchID"); # default FirstRow is 1
+my $text=XML::LibXML::Text->new($batchName);
+$paramNode->appendChild($text); #append
+$rootNode->appendChild($paramNode); # append a node to the xml tree
+
+my $xmlParams = $doc->toString; 
+
+print  $xmlParams;
+
+my $response = $ua->post($dxWebServiceUrl,
+        [op => "delete_dxbatch_files",
+        xmlParams => $xmlParams ]
+        );
+
+# '200' is the 'OK' response
+if ($response->code != 200) {
+
+    print "Problem connecting to DXLayerweb service, HTTP response status: ".$response->status_line."\n";
+    exit(1);
+}
+
+open (DAT, ">".$file);
+print DAT $response->content;
+
+
+print "$file\n";
+
+exit(0);
+
+
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/Notes_on_Schema10.txt
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/Notes_on_Schema10.txt	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/Notes_on_Schema10.txt	(revision 37066)
@@ -0,0 +1,132 @@
+Notes on Schema Version 9
+
+
+Proposed Image Products and PSPS Tables and Views
+
+IMAGE PRODUCTS 
+
+Survey  | Description               |  Image Products Saved
+
+3pi     | 3pi                       | 3pi warps, 3pi stacks
+CNP     | Celestial North Pole (3pi)| CNP warps, stacks
+SS      | ecliptic w band data      |   w warps, w stack
+MDD     | Medium Deep Deep          |  MD warps, deep stacks 
+MDT     | Medium Deep Template      |            template stacks
+MDN     | Medium Deep Nightly Stack |            nightly stacks 
+MDN     | Medium Deep Off Year      |            off year template stacks 
+M31     | M31                       | M31 warps, M31 stacks, template
+STS     | STS                       | STS warps, STS template - best iq stack 
+
+
+Survey  | Description               |  Image Products NOT Saved, but analyzed for difference detections and discarded 
+
+3pi     | difference                |3pi warps - stack 
+CNP     | difference                |CNP warps - stack 
+SS      | difference image          |  w warps - stack 
+MDD     | difference image          | MD warps - off year template stacks  
+MDO     | difference image          | MDN stacks - off year template stacks  
+M31     | difference image          | M31 warps - stack 
+STS     | difference image          | STS warps - template 
+
+
+
+PSPS TABLES                                                 
+
+
+Fundamental IPP Data Products  Origin 
+
+Detection                      detections found in detrended images   
+ObjectThin                     positonal and flag data, no fluxes   
+MeanObject                     extracted Mean properties as determined from individual Detections.   
+StackObject                    Stack Detections in all filters, with forced upperlimits, separate rows for primary, secondary, best stack detections (80% time only primary)  
+StackApFlx                     all filters in one table, unconvolved and convolved apertures (up to  6 , 8, 10(?) pixels  in all bands) 
+StackModelFit                  all filters in one table. Models of high signal to noise objects in low density regions.     
+DiffDet                        difference detections found in difference image = image - template 
+DiffObject                     associations of Difference Detections
+ForcedWarpMeasure              forced measurements on each warp in all filters at the position of an object found in a stack. Includes StackApFlx-like table   
+ForcedMeanObject               like MeanObject, but using the Forced Mean Measurements to form the Mean. 
+
+w band                         TBD 
+
+
+Derived Data Product Tables 
+
+pcsPhotoZ                       populated from PCS
+pcsPhotoZProbability            populated from PCS
+pcsStarGalQSOSep                populated from PCS
+pcsStellarParams                populated from PCS
+mopsMovingObject                populated from MOPS database
+ppmObj                          proper motion and parallax populated from IPP  
+tcsClassification               populated from transient server database
+galExtinction                   populated from Dust team
+stargal                         populated from various algorithms, combos of ipp parameters, fits to population as function of magnitude, or Support Vector Machine
+GoodObject                      selected and populated post-facto  
+StarGalaxySep                   selected and populated post-facto 
+
+
+Observational Metadata and System MetaData Tables
+
+CameraConfig
+DetectionFlags
+DiffMeta
+Filter
+FitModel
+ForcedWarpMeta
+FrameMeta
+ImageFlags
+ImageMeta                       add psf 3nd and 4th  moments
+Mask
+MovingObjectToDet
+MovingObjectToDiffDet
+MovingObjToObject
+ObjectFilterFlags               flag info not in current schema but in PSI interface...
+ObjectInfoFlags
+ObjectQualityFlags
+PhotoCal
+ProjectionCell
+ProcessingVersion
+SkyCell 
+StackDetectionFlags
+StackMeta                       
+StackToImage
+StackType
+Survey
+TelescopeConfig
+fitModel
+pcsGalaxyModel
+pcsPhotoZRecipe
+pcsSGSepRecipe
+pcsStarModel
+pcsStellarParamsRecipe
+
+
+
+PSPS VIEWS - examples  
+
+ObjectMean        = ObjectThin join MeanObject 
+ObjectStack       = ObjectThin join StackObject
+ObjectApFlx       = ObjectThin join StackApFlx  
+ObjectModel       = ObjectThin join StackModelFit   
+ObjectStackAll    = ObjectThin join StackObject and StackAp and StackModelFit 
+ObjectForcedMean  = ObjectThin join ForcedMeanObject
+ObjectPrimary     = ObjectThin join StackObject join StackApFlx where primaryDection is true
+ObjectBest        = ObjectThin join StackObject join StackApFlx where bestDetection is true
+
+
+PSPS Indicies 
+
+DetectionID
+ObjectID
+BatchID
+StackTypeID
+MovingObjID
+DiffObjID 
+RandomID           between 1 and 2^16 = 4,294,967,296 so you pick how many random objects you want ,
+                   i.e 10,000 pick randomid < 10,000 and if indexed, this will be very fast. 
+RandomStackID      between 1 and 2^16 = 4,294,967,296 so you pick how many random objects you want ,
+                   i.e 10,000 pick randomid < 10,000 and if indexed, this will be very fast. 
+
+
+
+
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/Notes_on_Schema11.txt
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/Notes_on_Schema11.txt	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/Notes_on_Schema11.txt	(revision 37066)
@@ -0,0 +1,132 @@
+Notes on Schema Version 9
+
+
+Proposed Image Products and PSPS Tables and Views
+
+IMAGE PRODUCTS 
+
+Survey  | Description               |  Image Products Saved
+
+3pi     | 3pi                       | 3pi warps, 3pi stacks
+CNP     | Celestial North Pole (3pi)| CNP warps, stacks
+SS      | ecliptic w band data      |   w warps, w stack
+MDD     | Medium Deep Deep          |  MD warps, deep stacks 
+MDT     | Medium Deep Template      |            template stacks
+MDN     | Medium Deep Nightly Stack |            nightly stacks 
+MDN     | Medium Deep Off Year      |            off year template stacks 
+M31     | M31                       | M31 warps, M31 stacks, template
+STS     | STS                       | STS warps, STS template - best iq stack 
+
+
+Survey  | Description               |  Image Products NOT Saved, but analyzed for difference detections and discarded 
+
+3pi     | difference                |3pi warps - stack 
+CNP     | difference                |CNP warps - stack 
+SS      | difference image          |  w warps - stack 
+MDD     | difference image          | MD warps - off year template stacks  
+MDO     | difference image          | MDN stacks - off year template stacks  
+M31     | difference image          | M31 warps - stack 
+STS     | difference image          | STS warps - template 
+
+
+
+PSPS TABLES                                                 
+
+
+Fundamental IPP Data Products  Origin 
+
+Detection                      detections found in detrended images   
+ObjectThin                     positonal and flag data, no fluxes   
+MeanObject                     extracted Mean properties as determined from individual Detections.   
+StackObject                    Stack Detections in all filters, with forced upperlimits, separate rows for primary, secondary, best stack detections (80% time only primary)  
+StackApFlx                     all filters in one table, unconvolved and convolved apertures (up to  6 , 8, 10(?) pixels  in all bands) 
+StackModelFit                  all filters in one table. Models of high signal to noise objects in low density regions.     
+DiffDet                        difference detections found in difference image = image - template 
+DiffObject                     associations of Difference Detections
+ForcedWarpMeasure              forced measurements on each warp in all filters at the position of an object found in a stack. Includes StackApFlx-like table   
+ForcedMeanObject               like MeanObject, but using the Forced Mean Measurements to form the Mean. 
+
+w band                         TBD 
+
+
+Derived Data Product Tables 
+
+pcsPhotoZ                       populated from PCS
+pcsPhotoZProbability            populated from PCS
+pcsStarGalQSOSep                populated from PCS
+pcsStellarParams                populated from PCS
+mopsMovingObject                populated from MOPS database
+ppmObj                          proper motion and parallax populated from IPP  
+tcsClassification               populated from transient server database
+galExtinction                   populated from Dust team
+stargal                         populated from various algorithms, combos of ipp parameters, fits to population as function of magnitude, or Support Vector Machine
+GoodObject                      selected and populated post-facto  
+StarGalaxySep                   selected and populated post-facto 
+
+
+Observational Metadata and System MetaData Tables
+
+CameraConfig
+DetectionFlags
+DiffMeta
+Filter
+FitModel
+ForcedWarpMeta
+FrameMeta
+ImageFlags
+ImageMeta                       add psf 3nd and 4th  moments
+Mask
+MovingObjectToDet
+MovingObjectToDiffDet
+MovingObjToObject
+ObjectFilterFlags               flag info not in current schema but in PSI interface...
+ObjectInfoFlags
+ObjectQualityFlags
+PhotoCal
+ProjectionCell
+ProcessingVersion
+SkyCell 
+StackDetectionFlags
+StackMeta                       
+StackToImage
+StackType
+Survey
+TelescopeConfig
+fitModel
+pcsGalaxyModel
+pcsPhotoZRecipe
+pcsSGSepRecipe
+pcsStarModel
+pcsStellarParamsRecipe
+
+
+
+PSPS VIEWS - examples  
+
+ObjectMean        = ObjectThin join MeanObject 
+ObjectStack       = ObjectThin join StackObject
+ObjectApFlx       = ObjectThin join StackApFlx  
+ObjectModel       = ObjectThin join StackModelFit   
+ObjectStackAll    = ObjectThin join StackObject and StackAp and StackModelFit 
+ObjectForcedMean  = ObjectThin join ForcedMeanObject
+ObjectPrimary     = ObjectThin join StackObject join StackApFlx where primaryDection is true
+ObjectBest        = ObjectThin join StackObject join StackApFlx where bestDetection is true
+
+
+PSPS Indicies 
+
+DetectionID
+ObjectID
+BatchID
+StackTypeID
+MovingObjID
+DiffObjID 
+RandomID           between 1 and 2^16 = 4,294,967,296 so you pick how many random objects you want ,
+                   i.e 10,000 pick randomid < 10,000 and if indexed, this will be very fast. 
+RandomStackID      between 1 and 2^16 = 4,294,967,296 so you pick how many random objects you want ,
+                   i.e 10,000 pick randomid < 10,000 and if indexed, this will be very fast. 
+
+
+
+
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/Notes_on_Schema12.txt
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/Notes_on_Schema12.txt	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/Notes_on_Schema12.txt	(revision 37066)
@@ -0,0 +1,2 @@
+Heather cleaned up the column names and types to make them consistent.
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/Notes_on_Schema13.txt
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/Notes_on_Schema13.txt	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/Notes_on_Schema13.txt	(revision 37066)
@@ -0,0 +1,8 @@
+changes by EAM:
+* added lensing terms to ForcedWarpMeasurement & ForcedMeanObject
+* removed fluxPeak and momentRH generally
+* changed psfWidMajor,Minor to psfMajorFWHM,psfMinorFWHM
+* added psfCore (k term in psf model : 1 / (1 + kz + k^1.667)
+* fixed stack flux & mag names
+* set units for moments to be in arcsec everywhere.
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Derived_Data_Product_Tables/GoodObject
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Derived_Data_Product_Tables/GoodObject	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Derived_Data_Product_Tables/GoodObject	(revision 37066)
@@ -0,0 +1,4 @@
+objName         string          VAR     8       NA      IAU Name constructed from objID postion PS1.x JHHMMSS.SS+/-DDMMSS.S where x is leading number of procesing version
+objID           dimensionless   BIGINT  8       NA      ODM object identifier index
+ippObjID        dimensionless   BIGINT  8       NA      IPP object number
+goodObjectID    dimensionless   BIGINT  8       NA      index for post-facto "good objects" subset from ObjID 
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Derived_Data_Product_Tables/StarGalaxySep
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Derived_Data_Product_Tables/StarGalaxySep	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Derived_Data_Product_Tables/StarGalaxySep	(revision 37066)
@@ -0,0 +1,9 @@
+objName         string          VAR     8       NA      IAU Name constructed from objID postion PS1.x JHHMMSS.SS+/-DDMMSS.S where x is leading number of procesing version
+objID           dimensionless   BIGINT  8       NA      ODM object identifier index
+ippObjID        dimensionless   BIGINT  8       NA      IPP object number
+sgbinarySep1    dimensionless   TINYINT 2       255     binary flag for star galaxy separator - technique 1
+sgbinarySep2    dimensionless   TINYINT 2       255     binary flag for star galaxy separator - technique 2
+sgbinarySep3    dimensionless   TINYINT 2       255     binary flag for star galaxy separator - technique 3
+sgSep1          dimensionless   REAL    4       -999    probility of star/galaxy technique 1  
+sgSep2          dimensionless   REAL    4       -999    probility of star/galaxy technique 2  
+sgSep3          dimensionless   REAL    4       -999    probility of star/galaxy technique 3  
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Derived_Data_Product_Tables/galExtinction
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Derived_Data_Product_Tables/galExtinction	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Derived_Data_Product_Tables/galExtinction	(revision 37066)
@@ -0,0 +1,28 @@
+galExtinction 
+Name	Unit	Data Type	Size	Default Value	Description
+
+objID				dimensionless	BIGINT	8	NA	ODM object identifier index
+ippObjID			dimensionless	BIGINT	8	NA	IPP object number
+
+From Doug and Eddie ?
+
+E(B-V)
+
+gGalext
+rGalext
+iGalext
+zGalext
+yGalext
+wGalext
+probability vector
+
+stellar parameters
+Teff
+g_surf
+[Fe/H]
+
+
+
+
+
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Derived_Data_Product_Tables/mopsMovingObject
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Derived_Data_Product_Tables/mopsMovingObject	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Derived_Data_Product_Tables/mopsMovingObject	(revision 37066)
@@ -0,0 +1,28 @@
+Name Unit Data Type Size Default Value Description
+
+MovingObjName   dimensionless	STRING 	x	-999	MPC Name 
+MovingObjType   dimensionless 	STRING 	x	-999 	Type of moving object (NEO, PHA, COMET, ...)
+MovingObjID     dimensionless	BIGINT 8 	-999  	Moving Object identifier     
+OrbEpoch        date		DATE     	-999  	The epoch of osculation of the orbital elements.
+Moid       	au		REAL   	4 	-999  	Minimum orbit intersection distance 
+OrbM       	dimensionles	REAL	4	-999	Mean anomaly at the epoch.
+OrbT       	date 		DATE 	  	-999    Date of perihelion passage.
+ORBn 		deg/day		REAL	4	-999	Mean daily motion (in degrees/day).
+ORBa       	AU		REAL	4	-999	Semimajor axis (in AU).
+ORBz       	1/AU		REAL	4	-999 	Reciprocal semimajor axis (in 1/AU).
+ORBq       	AU		REAL	4	-999	Perihelion distance (in AU).
+ORBe       	dimensionless	REAL	4	-999	Orbital eccentricity.
+OrbP       	years		REAL	4	-999	Orbital period (in years).
+OrbPeri    	degrees		REAL	4	-999	The J2000.0 argument of perihelion (in degrees).
+OrbNode    	degrees		REAL	4	-999	The J2000.0 longitude of the ascending node (in degrees).
+OrbIncl    	degrees		REAL	4	-999	The J2000.0 inclination (in degrees).
+P1         	dimensionless	REAL	4	-999	P1 first component of P vector
+P2	        dimensionless   REAL    4       -999    P2 second component of P vector 
+P3              dimensionless   REAL    4       -999    P3 third component of P vector
+Q1         	dimensionless   REAL    4       -999    Q1 first component of Q vector
+Q2         	dimensionless 	REAL    4	-999    Q2 second component of Q vector
+Q3         	dimensionless   REAL    4       -999    Q3 third component of Q vector
+U               dimensionless   REAL    4       -999    Uncertainty parameter.
+H               dimensionless   REAL    4       -999    Absolute visual magnitude. A table converting H to a diameter is available.
+G               dimensionless   REAL    4       -999    Slope parameter. 
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Derived_Data_Product_Tables/pcsPhotoZ
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Derived_Data_Product_Tables/pcsPhotoZ	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Derived_Data_Product_Tables/pcsPhotoZ	(revision 37066)
@@ -0,0 +1,21 @@
+pcsPhotoZ
+Name	Unit	Data Type	Size	Default Value	Description
+
+objID			BIGINT	8	NA	ODM object identifier index
+ippObjID		BIGINT	8	NA	IPP object number
+pcsPhotoZRecipeID	INT	4	-999	Recipe of the photoZ calculation
+galExt			REAL	4	-999	Galactic extinction E(B-V) used for photoz determination (derived from Schlegel Maps)
+photoz_1		REAL	4	-999	PhotoZ for best fitting template
+photozErr_1		REAL	4	-999	Estimated error for this tempalte
+chi2_1			REAL	4	-999	Chi^2 for this template
+modelID_1		INT	4	-999	Identifier for the template for this recipe
+photoz_2		REAL	4	-999	PhotoZ for second template
+photozErr_2		REAL	4	-999	Estimated error for this tempalte
+chi2_2			REAL	4	-999	Chi^2 for this template
+modelID_2		INT	4	-999	Identifier for the template for this recipe
+flags_gtfit		INT	4	-999	warning flags (e.g. missing band(s), unreliable galExt value etc.), TBD
+av			REAL	4	-999	determined extinction
+chi2			REAL	4	-999	chi2 for the best fitting stellar template
+modelID			INT	4	-999	modelID of the best fitting stellar template
+flags_stfit		INT	4	-999	warning flags from stellar template fitting
+starGalQSOSep		INT	4	-999	0: Object is a star (chi2
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Derived_Data_Product_Tables/pcsPhotoZProbabiity
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Derived_Data_Product_Tables/pcsPhotoZProbabiity	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Derived_Data_Product_Tables/pcsPhotoZProbabiity	(revision 37066)
@@ -0,0 +1,37 @@
+PhotoZProbability
+Name	Unit	Data Type	Size	Default Value	Description
+
+objID			dimensionless	BIGINT	8	NA	ODM object identifier index
+ippObjID		dimensionless	BIGINT	8	NA	IPP object number
+pcsPhotoZRecipeID	dimensionless	INT	4	-999	recipe for the photoz determination
+modelID			dimensionless	INT	4	-999	modelID of the template
+sp1	dimensionless	REAL	4	-999	spline params 1
+sp2	dimensionless	REAL	4	-999	spline params 2
+sp3	dimensionless	REAL	4	-999	spline params 3
+sp4	dimensionless	REAL	4	-999	spline params 4
+sp5	dimensionless	REAL	4	-999	spline params 5
+sp6	dimensionless	REAL	4	-999	spline params 6
+sp7	dimensionless	REAL	4	-999	spline params 7
+sp8	dimensionless	REAL	4	-999	spline params 8
+sp9	dimensionless	REAL	4	-999	spline params 9
+sp10	dimensionless	REAL	4	-999	spline params 10
+sp11	dimensionless	REAL	4	-999	spline params 11
+sp12	dimensionless	REAL	4	-999	spline params 12
+sp13	dimensionless	REAL	4	-999	spline params 13
+sp14	dimensionless	REAL	4	-999	spline params 14
+sp15	dimensionless	REAL	4	-999	spline params 15
+sp16	dimensionless	REAL	4	-999	spline params 16
+sp17	dimensionless	REAL	4	-999	spline params 17
+sp18	dimensionless	REAL	4	-999	spline params 18
+sp19	dimensionless	REAL	4	-999	spline params 19
+sp20	dimensionless	REAL	4	-999	spline params 20
+sp21	dimensionless	REAL	4	-999	spline params 21
+sp22	dimensionless	REAL	4	-999	spline params 22
+sp23	dimensionless	REAL	4	-999	spline params 23
+sp24	dimensionless	REAL	4	-999	spline params 24
+sp25	dimensionless	REAL	4	-999	spline params 25
+sp26	dimensionless	REAL	4	-999	spline params 26
+sp27	dimensionless	REAL	4	-999	spline params 27
+sp28	dimensionless	REAL	4	-999	spline params 28
+sp29	dimensionless	REAL	4	-999	spline params 29
+sp30	dimensionless	REAL	4	-999	spline params 30
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Derived_Data_Product_Tables/pcsStarGalQSOSep
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Derived_Data_Product_Tables/pcsStarGalQSOSep	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Derived_Data_Product_Tables/pcsStarGalQSOSep	(revision 37066)
@@ -0,0 +1,10 @@
+pcsStarGalQSOSep
+Name	Unit	Data Type	Size	Default Value	Description
+
+objID		dimensionless	BIGINT	8	NA	ODM object identifier index
+ippObjID	dimensionless	BIGINT	8	NA	IPP object number
+pcsSGSepRecipeIDdimensionless	INT	4	NA	recipe for the star/galaxy/quasar separation
+probStar	percentage	FLOAT	8	-999	probability object is a star
+probGalaxy	percentage	FLOAT	8	-999	probability object is a galaxy
+probQuasar	percentage	FLOAT	8	-999	probability object is a quasar
+flags		dimensionless	INT	4	-999	flags
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Derived_Data_Product_Tables/pcsStellarParams
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Derived_Data_Product_Tables/pcsStellarParams	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Derived_Data_Product_Tables/pcsStellarParams	(revision 37066)
@@ -0,0 +1,11 @@
+pcsStellarParams s
+Name	Unit	Data Type	Size	Default Value	Description
+
+objID				dimensionless	BIGINT	8	NA	ODM object identifier index
+ippObjID			dimensionless	BIGINT	8	NA	IPP object number
+pcsStellarParamsRecipeID	dimensionless	INT	4	-999	recipe for the star/galaxy/quasar separation
+Teff	dimensionless	REAL	4	-999	N/A
+A0	dimensionless	REAL	4	-999	N/A
+Fe_H	dimensionless	REAL	4	-999	N/A
+flags	dimensionless	INT	4	-999	flags
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Derived_Data_Product_Tables/ppmObj
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Derived_Data_Product_Tables/ppmObj	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Derived_Data_Product_Tables/ppmObj	(revision 37066)
@@ -0,0 +1,25 @@
+PPM
+Description: Proper motions and parallax associated with defined objects. 
+
+Name Unit Data Type Size Default Value Description
+objID		BIGINT 8 NA ODM object identifier
+ippObjID   	BIGINT 8 NA IPP object identifier index
+ppmID           BIGINT 8 NA ppm object identifier ( ppmToObject metatable?)
+meanEpoch	FLOAT 	8 	-999 	mean epoch of observations in Mean Julian Days
+elapseTime 	REAL 4 -999 Elapsed time of astrometric observations
+muRa 		REAL 4 -999 proper motion in RA
+muRaErr 	REAL 4 -999 error in proper motion in RA
+muDec 		REAL 4 -999 proper motion in DEC
+muDecErr 	REAL 4 -999 error in proper motion in Dec
+mu 		REAL 4 -999 total proper motion
+muErr 		REAL 4 -999 error in total proper motion
+theta 		REAL 4 -999 angle of parallax vector from N in degrees
+plx 		REAL 4 -999 total parallax
+plxErr 		REAL 4 -999 error in total parallax
+nAstro 		SMALLINT 2 -999 number of measures in astrometric fit
+rmsRA 		REAL 4 -999 rms of astrometric error in RA
+rmsDec 		REAL 4 -999 rms of astrometric error in Dec
+wiggle 		TINYINT 1 255 flag/pointer to astrometric orbit
+
+
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Derived_Data_Product_Tables/stargal
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Derived_Data_Product_Tables/stargal	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Derived_Data_Product_Tables/stargal	(revision 37066)
@@ -0,0 +1,17 @@
+
+
+Name	Unit	Data Type	Size	Default Value	Description
+
+objID		dimensionless	BIGINT	8	NA	ODM object identifier index
+ippObjID	dimensionless	BIGINT	8	NA	IPP object number
+StarProb1	fraction	FLOAT	8	-999	fractional probability object is a star, Recipe 1
+GalProb1	fraction	FLOAT	8	-999	fractional probability object is a galaxy, Recipe 1
+StarProb2	fraction	FLOAT	8	-999	fractional probability object is a star, Recipe 2
+GalProb2 	fraction	FLOAT	8	-999	fractional probability object is a galaxy, Recipe 2
+StarProb3	fraction	FLOAT	8	-999	fractional probability object is a star, Recipe 3
+GalProb3	fraction	FLOAT	8	-999	fractional probability object is a galaxy, Recipe 3
+
+
+comment - may come from different combinations of ipp parameters, model fit as function of magnitude, 
+or Support Vector Machine result. 
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Derived_Data_Product_Tables/tcsClassification
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Derived_Data_Product_Tables/tcsClassification	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Derived_Data_Product_Tables/tcsClassification	(revision 37066)
@@ -0,0 +1,16 @@
+galExtinction 
+Name	Unit	Data Type	Size	Default Value	Description
+
+objID				dimensionless	BIGINT	8	NA	ODM object identifier index
+ippObjID			dimensionless	BIGINT	8	NA	IPP object number
+diffobjID 			dimensionless	BIGINT	8	NA	IPP object number
+
+From Stephen and Ken?
+
+TransientName                                                           eg. PS1-10jh
+transientClass                                                          TDE
+ATEL                                                           -999     Astronomical Telegram number
+
+
+
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/Detection
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/Detection	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/Detection	(revision 37066)
@@ -0,0 +1,60 @@
+objID           dimensionless   BIGINT  8         NA    ODM object identifier
+gcObjID		dimensionless	BIGINT	8	  NA 	ODM galactic coordinates identifier
+detectID        dimensionless   BIGINT  8         NA    ODM detection identifier
+ippObjID        dimensionless   BIGINT  8         NA    detection id generated by IPP
+ippDetectID     dimensionless   BIGINT  8         NA    detection id generated by IPP
+filterID        dimensionless   TINYINT 1         NA    filter ID: g=1, r=2, i=3, z=4, y=5, w=6, ...
+surveyID        dimensionless   TINYINT 1         NA    survey flag identifier
+imageID         dimensionless   BIGINT  8         NA    image id hash of frame identifier & OTA/CCD number
+randomDetID     dimensionless   BIGINT  8         NA    random detection Id
+dvoRegionID     dimensionless   INT     4          0    identifier to dvo spatial region
+obsTime         MeanJulianDays  FLOAT   8       -999    Time of mid observation in Mean Julian Days
+xPos            raw pixels      REAL    4       -999    measured x on CCD from PSF fit
+yPos            raw pixels      REAL    4       -999    measured y on CCD from PSF fit
+xPosErr         raw pixels      REAL    4       -999    estimated error in x
+yPosErr         raw pixels      REAL    4       -999    estimated error in y
+pltScale        arcsec/pix      REAL    4       -999    plate scale at this location (from DVO)
+posAngle        degrees         REAL    4       -999    position angle (sky-to-chip) at this location (from DVO)
+------------------------------------------------------  Note - next 8 lines came from previous DetCalib table
+ra              degrees         FLOAT   8         NA    Right Ascension
+dec             degrees         FLOAT   8         NA    Declination
+raErr           arcsec          REAL    4         NA    Right Ascension error
+decErr          arcsec          REAL    4         NA    Declination error
+zp              magnitude       REAL    4          0    zeropoint (only thing needed to convert adu/sec to AB mag), note no zpErr
+telluricExt     magnitude       REAL    4         NA    estimated extinction due to non-photometric conditions  
+expTime         seconds         REAL    4       -999    exposure time (informational)
+airMass         dimensionless   REAL    4          0    airmass (informational)
+------------------------------------------------------  
+psfFlux         adu/seconds     REAL    4       -999    PSF instrumental flux (in analog-to-digital units/sec) or adu/sec
+psfFluxErr      adu/seconds     REAL    4       -999    estimated error in flux
+psfMajorFWHM    arcsec          REAL    4       -999    model PSF width in major axis
+psfMinorFWHM    arcsec          REAL    4       -999    model PSF width in minor axis
+psfTheta        degrees         REAL    4       -999    model PSF orientation angle degrees East of North
+psfCore         dimensionless   REAL    4       -999    model PSF core parameter [k in (1 + kz + z^1.66)]
+psfQf           dimensionless   REAL    4       -999    PSF coverage factor
+psfQfPerfect    dimensionless   REAL    4       -999    PSF-weighted fraction of pixels totally unmasked
+psfChiSq        dimensionless   REAL    4       -999    reduced-chisq of the psf model fit. (ndof?, npix?)
+psfLikelihood   dimensionless   REAL    4       -999    PSF likelihood
+momentXX        arcsec^2        REAL    4       -999    moment XX
+momentXY        arcsec^2        REAL    4       -999    moment XY
+momentYY        arcsec^2        REAL    4       -999    momeny YY
+momentR1        arcsec          REAL    4       -999    first radial moment 
+momentRH        arcsec          REAL    4       -999    half light radius (REMOVE THIS)
+momentM3C       arcsec^n        REAL    4       -999    3rd moment sin(theta) 
+momentM3S       arcsec^n        REAL    4       -999    3rd moment cos(theta) 
+momentM4C       arcsec^n        REAL    4       -999    4th moment sin(theta)
+momentM4S       arcsec^n        REAL    4       -999    4th moment cos(theta) 
+apFlux          adu/seconds     REAL    4       -999    Aperture flux
+apFluxErr       adu/seconds     REAL    4       -999    Aperture flux error
+apFillF         dimensionless   REAL    4       -999    Aperture fill factor 
+kronFlux        adu/seconds     REAL    4       -999    Kron flux
+kronFluxErr     adu/seconds     REAL    4       -999    Kron flux error
+kronRad         arcsec      	REAL    4       -999    Kron radius
+kronRadErr      arcsec      	REAL    4       -999    Kron radius error (DROP)
+sky             adu/sec/pixel   REAL    4       -999    PSF sky level at source
+skyErr          adu/sec/pixel   REAL    4       -999    estimated error in sky
+infoFlag        dimensionless   INT     4       -999    flag indicating provenance information
+infoFlag2       dimensionless   INT     4       -999    flag indicating provenance information
+dataRelease     dimensionless   TINYINT 1         NA    Data release when this detection was originally taken. Recalibrations do not affect this value.
+--
+-- [231 bytes/det]
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/Detection.txt
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/Detection.txt	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/Detection.txt	(revision 37066)
@@ -0,0 +1,58 @@
+objID           = dvo / addstar
+gcObjID		= dvo / addstar [EAM: add to addstar]
+detectID        = dvo / addstar
+ippObjID        = dvo / addstar
+ippDetectID     = dvo / addstar
+filterID        = smf / ipptopsps
+surveyID        = ipptopsps
+imageID         = smf header
+randomDetID     = ipptopsps
+dvoRegionID     = dvo / catID [EAM: add to dvopsps]
+obsTime         = smf
+xPos            = smf
+yPos            = smf
+xPosErr         = smf [EAM: modify errors to match relastro?]
+yPosErr         = smf
+pltScale        = smf
+posAngle        = smf
+----------------= 
+ra              = dvo / relastro
+dec             = dvo / relastro
+raErr           = dvo / relastro
+decErr          = dvo / relastro
+zp              = dvo / relphot
+telluricExt     = zp - zpNominal (dvopsps) [EAM: add to dvopsps]
+expTime         = smf
+airMass         = smf
+----------------= 
+psfFlux         = smf [OK: ipptopsps uses PSF_FLUX]
+psfFluxErr      = smf
+psfMajorFWHM    = smf [PSF_MAJOR is Sxx parameter, NOT FWHM] [EAM: add PSF_FWHM_MAJ to smf, keep PSF_MAJOR]
+psfMinorFWHM    = smf [PSF_MINOR is Sxx parameter, NOT FWHM] [EAM: add PSF_FWHM_MIN to smf, keep PSF_MINOR]
+psfTheta        = smf
+psfCore         = smf [EAM: add PSF_CORE to smf]
+psfQf           = smf
+psfQfPerfect    = smf
+psfChiSq        = smf
+psfLikelihood   = ipptopsps
+momentXX        = smf
+momentXY        = smf
+momentYY        = smf
+momentR1        = smf
+momentRH        = smf [XXX : MOMENTS_RH is NOT half-light radius : keep as MOMENTS_RH or calculate?]
+momentM3C       = smf
+momentM3S       = smf
+momentM4C       = smf
+momentM4S       = smf
+apFlux          = smf [requires PS1_V4]
+apFluxErr       = smf [requires PS1_V4]
+apFillF         = smf [EAM: add to pmSource and smf]
+kronFlux        = smf
+kronFluxErr     = smf
+kronRad         = (2.5*R1) : Ken : drop this or MOMENTS_R1?
+kronRadErr      = [not calculated] : drop this
+sky             = smf
+skyErr          = smf
+infoFlag        = smf
+infoFlag2       = smf
+dataRelease     = ippToPsps
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetObject
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetObject	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetObject	(revision 37066)
@@ -0,0 +1,34 @@
+
+diffObjName     string          VAR     8       NA      IAU Name constructed from objID postion PS1.x JHHMMSS.SS+/-DDMMSS.S x procesing version       
+diffObjID	dimensionless 	BIGINT 	8 	NA 	ODM object identifier index
+diffgcObjID	dimensionless	BIGINT	8       NA 	ODM galactic coordinates identifier
+ippObjID  	dimensionless 	BIGINT 	8 	NA 	IPP object number
+surveyID 	dimensionless 	TINYINT 1 	255 	Survey ID
+skyCellID       dimensionless   REAL    4       -999    single float giving PrimaryCell.SkyCell identifier
+htmID 		dimensionless 	BIGINT 	8 	NA 	HTM index
+zoneID 		dimensionless 	INT 	4 	NA 	Zone index
+randomID 	dimensionless 	BIGINT 	8 	0 	Random integer between 0 and 2^32 = 4,394,967,296 remaining ramdom integer 0  
+batchID 	dimensionless	BIGINT 	8 	-999 	
+dvoRegionID     dimensionless  	INT     4       -999    identifier to dvo spatial region
+objInfoFlag 	dimensionless 	BIGINT 	8 	-999 	flag indicating odd properties
+qualityFlag 	dimensionless 	TINYINT 1 	0 	subset of objInfoFlag - flags related to goodness of object
+consistencyFlag	dimensionless 	SMALLINT2 	0 	Value computed from associated detections, it is originally given by IPP and should agree with the ODM validation (DROP)
+ra 		degrees 	FLOAT 	8 	NA 	Right Ascension
+dec 		degrees 	FLOAT 	8 	NA 	Declination
+raErr 		arcsec 		REAL 	4 	0.0 	Right Ascension error
+decErr 		arcsec 		REAL 	4 	0.0 	Declination error
+cx              dimensionless	FLOAT 	8 	NA 	Cartesian x
+cy 	        dimensionless	FLOAT 	8 	NA 	Cartesian y
+cz              dimensionless	FLOAT 	8 	NA 	Cartesian z
+lambda 		degrees 	FLOAT 	8 	-999 	ecliptic longitude
+beta 		degrees 	FLOAT 	8 	-999 	ecliptic latitude
+l 		degrees 	FLOAT 	8 	-999 	galactic longitude
+b 		degrees 	FLOAT 	8 	-999 	galactic latitude
+qfPerfect 	dimensionless 	REAL 	4 	-999 	qfPerfect
+dataRelease 	dimensionless 	TINYINT 1 	NA 	Data release Version of this table
+nDetections 	dimensionless 	SMALLINT2 	-999 	total number of detection measurements in all filters
+ng 		dimensionless 	SMALLINT2 	-999 	number of detections in g filter
+nr 		dimensionless 	SMALLINT2 	-999 	number of detections in g filter
+ni 		dimensionless 	SMALLINT2 	-999 	number of detections in g filter
+nz 		dimensionless 	SMALLINT2 	-999 	number of detections in g filter
+ny 		dimensionless 	SMALLINT2 	-999 	number of detections in g filter
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetObject.txt
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetObject.txt	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetObject.txt	(revision 37066)
@@ -0,0 +1,34 @@
+		
+diffObjName      = ipptopsps
+diffObjID	 = dvo / addstar
+diffgcObjID	 = dvo / addstar
+ippObjID  	 = dvo / addstar
+surveyID 	 = ipptopsps
+skyCellID        = smf header
+htmID 		 = PSPS
+zoneID 		 = PSPS
+randomID 	 = ipptopsps
+batchID 	 = ipptopsps
+dvoRegionID      = dvo catID 
+objInfoFlag 	 = average.flags
+qualityFlag 	 = average.flags >> 24 & 0xff (needed??)
+consistencyFlag	 = ?
+ra 		 = dvo / relastro
+dec 		 = dvo / relastro
+raErr 		 = dvo / relastro
+decErr 		 = dvo / relastro
+cx               = PSPS
+cy 	         = PSPS
+cz               = PSPS
+lambda 		 = PSPS
+beta 		 = PSPS
+l 		 = PSPS
+b 		 = PSPS
+qfPerfect 	 = dvo / relphot / secfilt. [XXX Not calculated]
+dataRelease 	 = ipptopsps
+nDetections 	 = dvo / relphot
+ng 		 = dvo / relphot
+nr 		 = dvo / relphot
+ni 		 = dvo / relphot
+nz 		 = dvo / relphot
+ny 		 = dvo / relphot
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetection
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetection	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetection	(revision 37066)
@@ -0,0 +1,71 @@
+
+diffObjID	dimensionless 	BIGINT 	8 	NA 	diff object identifier
+diffgcObjID	dimensionless	BIGINT	8	NA 	ODM galactic coordinates identifier
+diffDetID 	dimensionless 	BIGINT 	8 	NA 	diff detection identifier
+diffDetMetaID 	dimensionless 	BIGINT 	8 	NA 	diff detection meta identifier
+ippDetectID 	dimensionless 	BIGINT 	8 	NA 	ipp detection id generated by IPP
+ippObjID 	dimensionless 	BIGINT 	8 	NA 	ipp object id generated by IPP
+filterID 	dimensionless 	TINYINT	1 	NA 	filter ID: g=1, r=2, i=3, z=4, y=5, w=6, ...
+surveyID 	dimensionless 	TINYINT	1 	NA 	survey flag identifierr
+randomDiffID 	dimensionless 	BIGINT 	8 	NA 	random diff id  
+skyCellID       dimensionless   REAL    4       -999    single float giving PrimaryCell.SkyCell identifier 
+dvoRegionID     dimensionless   INT     4          0    identifier to dvo spatial region
+obsTime 	MeanJulianDays 	FLOAT 	8 	-999 	Time of mid observation of positive detection in Mean Julian Days of positive detection
+xPos 		pixels 		REAL 	4 	-999 	measured x on diff image sky cell PSF fit
+yPos 		pixels 		REAL 	4 	-999 	measured y on diff image sky cell from PSF fit
+xPosErr 	pixels 		REAL 	4 	-999 	estimated error in x
+yPosErr 	pixels 		REAL 	4 	-999 	estimated error in y
+pltScale        arcsec/pix      REAL    4       -999    plate scale at this location (from DVO)
+posAngle        degrees         REAL    4       -999    position angle (sky-to-chip) at this location (from DVO)
+----------------------------------------------------    next 8 came from old DiffDetCalib, zp derived from cpt tables of BOTH images 
+ra              degrees         FLOAT   8       NA      Right Ascension
+dec             degrees         FLOAT   8       NA      Declination
+raErr           arcsec          REAL    4       NA      Right Ascension error -> posErr because RA,Dec same?
+decErr          arcsec          REAL    4       NA      Declination error
+zp              magnitude       REAL    4       0       zeropoint (all that is needed to convert adu/sec to AB mag), no zpErr
+telluricExt     magnitude       REAL    4       NA      estimated extinction due to non-photometric conditions  
+expTime         seconds         REAL    4       -999    exposure time (informational)
+airMass         dimensionless   REAL    4       0       airmass (informational)
+-----------------------------------------------------   attributes of positive detection
+psfFlux 	adu/seconds 	REAL 	4 	-999 	PSF instrumental flux (in analog-to-digital units/sec) or adu/sec
+psfFluxErr 	adu/seconds 	REAL 	4 	-999 	estimated error in flux
+psfMajorFWHM    arcsec          REAL    4       -999    model PSF width in major axis
+psfMinorFWHM    arcsec          REAL    4       -999    model PSF width in minor axis
+psfTheta        degrees         REAL    4       -999    model PSF orientation angle degrees East of North
+psfCore         dimensionless   REAL    4       -999    model PSF core parameter [k in (1 + kz + z^1.66)]
+psfQf 		dimensionless 	REAL 	4 	-999 	PSF coverage factor
+psfQfPerfect 	dimensionless 	REAL 	4 	-999 	PSF-weighted fraction of pixels totally unmasked
+psfChiSq 	dimensionless 	REAL 	4 	-999 	reduced-chisq of the psf model fit. (ndof?, npix?)
+psfLikelihood 	dimensionless 	REAL 	4 	-999 	PSF likelihood
+momentXX 	arcsec^2     	REAL 	4 	-999 	moment XX
+momentXY 	arcsec^2     	REAL 	4 	-999 	moment XY
+momentYY 	arcsec^2     	REAL 	4 	-999 	momeny YY
+momentR1 	arcsec       	REAL 	4 	-999 	first radial moment 
+momentRH 	arcsec       	REAL 	4 	-999 	half light radius   (DROP)
+momentM3C 	arcsec^3     	REAL 	4 	-999 	3rd moment sin(theta) 
+momentM3S 	arcsec^3     	REAL 	4 	-999 	3rd moment cos(theta) 
+momentM4C 	arcsec^4     	REAL 	4 	-999 	4th moment sin(theta)
+momentM4S  	arcsec^4     	REAL 	4 	-999 	4th moment cos(theta) 
+apFlux 		adu/seconds 	REAL 	4 	-999 	Aperture flux
+apFluxErr 	adu/seconds 	REAL 	4 	-999 	Aperture flux error
+apFillF         dimensionless   REAL    4       -999    Aperture fill factor 
+kronFlux 	adu/seconds 	REAL 	4 	-999 	Kron flux
+kronFluxErr 	adu/seconds 	REAL 	4 	-999 	Kron flux error
+kronRad 	raw pixels 	REAL 	4 	-999 	Kron radius
+kronRadErr 	raw pixels 	REAL 	4 	-999 	Kron radius error
+------------------------------------------------------- from diff image cmf/smf files 
+diffNPos        dimensionless   REAL    4       -999    npix > 3sigma
+diffFRatio      dimensionless   REAL    4       -999    fPos/(fPos +fNeg)
+diffNBad        dimensionless   REAL    4       -999    nPos/(nPos+nNeg)
+diffNMask       dimensionless   REAL    4       -999    nPos/(nPos + nMask)
+diffNAll        dimensionless   REAL    4       -999    nPos/(nPos + nMask + nNeg)
+diffPdist       arcsec          REAL    4       -999    distance to positive match source
+diffNdist       arcsec          REAL    4       -999    distance to negative match source
+diffPSN         dimensionless   REAL    4       -999    signal to noise of pos match source
+diffNSN         dimensionless   REAL    4       -999    signal to noise of neg match source
+-------------------------------------------------------
+sky 		adu/sec/pixel 	REAL 	4 	-999 	PSF sky level at source
+skyErr 		adu/sec/pixel 	REAL 	4 	-999 	estimated error in sky
+infoFlag 	dimensionless 	INT     4 	-999 	flag indicating provenance information
+infoFlag2	dimensionless 	INT     4 	-999 	flag indicating provenance information
+dataRelease 	dimensionless 	TINYINT	1 	NA 	Data release when this detection was originally taken. Recalibrations do not affect this value.
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetection.txt
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetection.txt	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetection.txt	(revision 37066)
@@ -0,0 +1,72 @@
+		
+diffObjID	 = dvo / addstar
+diffgcObjID	 = dvo / addstar
+diffDetID 	 = dvo / addstar
+diffDetMetaID 	 = dvo / addstar
+ippDetectID 	 = dvo / addstar
+ippObjID 	 = dvo / addstar
+filterID 	 = smf / ipptopsps
+surveyID 	 = ipptopsps
+randomDiffID 	 = ipptopsps
+skyCellID        = smf header
+dvoRegionID      = dvo / catID
+obsTime 	 = smf
+xPos 		 = smf
+yPos 		 = smf
+xPosErr 	 = smf
+yPosErr 	 = smf
+pltScale         = smf
+posAngle         = smf
+---------------- = 
+ra               = dvo / relastro? [allow / require relastro recalibration?]
+dec              = dvo / relastro?
+raErr            = dvo / relastro?
+decErr           = dvo / relastro?
+zp               = dvo / relphot
+telluricExt      = (zp - zpNominal) dvopsps
+expTime          = smf
+airMass          = smf
+---------------- = 
+psfFlux 	 = smf
+psfFluxErr 	 = smf
+psfMajorFWHM     = [PSF_MAJOR is Sxx parameter, NOT FWHM] [ADD PSF_MAJ_FWHM to smf, keep PSF_MAJOR]
+psfMinorFWHM     = [PSF_MAJOR is Sxx parameter, NOT FWHM] [ditto]
+psfTheta         = smf
+psfCore          = [XXX : not currently written out!!]
+psfQf 		 = smf
+psfQfPerfect 	 = smf
+psfChiSq 	 = smf
+psfLikelihood 	 = ipptopsps
+momentXX 	 = smf
+momentXY 	 = smf
+momentYY 	 = smf
+momentR1 	 = smf
+momentRH 	 = smf [XXX : MOMENTS_RH is NOT half-light radius]
+momentM3C 	 = smf
+momentM3S 	 = smf
+momentM4C 	 = smf
+momentM4S  	 = smf
+apFlux 		 = smf [PS1_DV2 or later]
+apFluxErr 	 = smf [PS1_DV2 or later]
+apFillF          = [XXX : not currently calculated]
+kronFlux 	 = smf
+kronFluxErr 	 = smf
+kronRad 	 = (2.5*R1)
+kronRadErr 	 = [drop this? ]
+---------------- = 
+diffNPos         = smf
+diffFRatio       = smf
+diffNBad         = smf
+diffNMask        = smf
+diffNAll         = smf
+diffPdist        = smf
+diffNdist        = smf
+diffPSN          = smf
+diffNSN          = smf
+---------------- = 
+sky 		 = smf
+skyErr 		 = smf
+infoFlag 	 = smf
+infoFlag2	 = smf
+dataRelease 	 = ipptopsps
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedMeanObject
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedMeanObject	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedMeanObject	(revision 37066)
@@ -0,0 +1,63 @@
+
+objID           dimensionless   BIGINT   8        NA    ODM object identifier index
+gcObjID		dimensionless	BIGINT	 8	  NA 	ODM galactic coordinates identifier
+ippObjID        dimensionless   BIGINT   8        NA    IPP object identifier
+nDetections     dimensionless   SMALLINT 2      -999    total number of detection measurements in all filters
+batchID         dimensionless   BIGINT   8        NA    batch id 
+-----------------------------------------------------   replicate to bottom for each filter
+gStackID        dimensionless   INT      4              stack image id (how to carry through IPP + DVO)
+gnTotal         dimensionless   SMALLINT 2      -999    number of detections in g filter
+gnIncPSFMag     dimensionless   SMALLINT 2      -999    number of detections included in robust psf mean in g filter 
+gnIncKronMag    dimensionless   SMALLINT 2      -999    number of detections included in robust mean of Kron mag in g filter
+gnIncApMag      dimensionless   SMALLINT 2      -999    number of detections included in robust mean of Ap mag in g filter
+gnIncR5         dimensionless   SMALLINT 2      -999    number of detections included in robust mean of ApFlx 5 in g filter
+gnIncR6         dimensionless   SMALLINT 2      -999    number of detections included in robust mean of ApFlx 6 in g filter
+------------------------------------------------------- one of the above also corresponds to the moments
+gPSFMag         AB_magnitude    REAL     4      -999    robust mean g psf AB magnitude (sigma clipping or MAP or go to 5 or 7 number sumary? 1/12 is ~9th percentile 
+gPSFMagErr      AB_magnitude    REAL     4      -999    estimated error of g psf AB magnitude mean (individual errors added in quadrature)
+gPSFMagStd      dimensionless   REAL     4      -999    standard deviation of measurements included in the robust mean  
+gKronMag        AB_magnitude    REAL     4      -999    mean g kron AB magnitude
+gKronMagErr     AB_magnitude    REAL     4      -999    estimated error of g kron AB magnitude mean
+gKronMagStd     dimensionless   REAL     4      -999    standard deviation of measurements included in the robust mean  
+gApMag          AB_magnitude    REAL     4      -999    mean g kron AB magnitude
+gApMagErr       AB_magnitude    REAL     4      -999    estimated error of g kron AB magnitude mean
+gApMagStd       dimensionless   REAL     4      -999    standard deviation of measurements included in the robust mean  
+------------------------------------------------------
+gFmeanflxR5     adu/seconds     REAL     4      -999    Flux inside r = 5 in g unconvolved stack  
+gFmeanflxR5Err  adu/seconds     REAL     4      -999    estimated error is flxR5
+gFmeanflxR5Std  adu/seconds     REAL     4      -999    estimated standard deviation in flxR5
+gFmeanflxR5Fill dimensionless   REAL     4      -999    estimated filling factor at R5
+gFmeanflxR6     adu/seconds     REAL     4      -999    Flux inside r = 6 in g unconvolved stack 
+gFmeanflxR6Err  adu/seconds     REAL     4      -999    estimated error is flxR6
+gFmeanflxR6Std  adu/seconds     REAL     4      -999    estimated standard deviation in flxR6
+gFmeanflxR6Fill dimensionless   REAL     4      -999    estimated filling factor at R6
+gFlags          dimensionless   BIGINT   8        NA    flags for g forced
+------------------------------------------------------
+gLensObjSmearX11 arcsec^-2      REAL     4      -999    per-object smear polarizability X11 term
+gLensObjSmearX12 arcsec^-2      REAL     4      -999    per-object smear polarizability X12 term
+gLensObjSmearX22 arcsec^-2      REAL     4      -999    per-object smear polarizability X22 term
+gLensObjSmearE1  arcsec^-2      REAL     4      -999    per-object smear polarizability E1 term
+gLensObjSmearE2  arcsec^-2      REAL     4      -999    per-object smear polarizability E2 term
+gLensObjShearX11 dimensionless  REAL     4      -999    per-object shear polarizability X11 term
+gLensObjShearX12 dimensionless  REAL     4      -999    per-object shear polarizability X12 term
+gLensObjShearX22 dimensionless  REAL     4      -999    per-object shear polarizability X22 term
+gLensObjShearE1  dimensionless  REAL     4      -999    per-object shear polarizability E1 term
+gLensObjShearE2  dimensionless  REAL     4      -999    per-object shear polarizability E2 term
+gLensPSFSmearX11 arcsec^-2      REAL     4      -999    psf model smear polarizability X11 term
+gLensPSFSmearX12 arcsec^-2      REAL     4      -999    psf model smear polarizability X12 term
+gLensPSFSmearX22 arcsec^-2      REAL     4      -999    psf model smear polarizability X22 term
+gLensPSFSmearE1  arcsec^-2      REAL     4      -999    psf model smear polarizability E1 term
+gLensPSFSmearE2  arcsec^-2      REAL     4      -999    psf model smear polarizability E2 term
+gLensPSFShearX11 dimensionless  REAL     4      -999    psf model shear polarizability X11 term
+gLensPSFShearX12 dimensionless  REAL     4      -999    psf model shear polarizability X12 term
+gLensPSFShearX22 dimensionless  REAL     4      -999    psf model shear polarizability X22 term
+gLensPSFShearE1  dimensionless  REAL     4      -999    psf model shear polarizability E1 term
+gLensPSFShearE2  dimensionless  REAL     4      -999    psf model shear polarizability E2 term
+------------------------------------------------------
+gGamma           arcsec^2       REAL     4      -999    second moment (Mxx + Myy)
+gE1              dimensionless  REAL     4      -999    polarization, KSB-corrected (Mxx - Myy) / (Mxx + Myy)
+gE2              dimensionless  REAL     4      -999    polarization, KSB-corrected 2Mxy / (Mxx + Myy)
+
+-- duplicated for other filters
+-- [184 byte/obj/filter + 22 byte/obj]
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedMeanObject.txt
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedMeanObject.txt	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedMeanObject.txt	(revision 37066)
@@ -0,0 +1,70 @@
+		 
+objID            = dvo / addstar
+gcobjID          = dvo / addstar
+ippObjID         = dvo / addstar
+nDetections      = dvo / addstar
+batchID          = dvo / addstar
+---------------- = 
+gStackID         = 
+gnTotal          = 
+gnIncPSFMag      = 
+gnIncKronMag     = 
+gnIncApMag       = 
+gnIncR5          = 
+gnIncR6          = 
+---------------- = 
+gPSFMag          = 
+gPSFMagErr       = 
+gPSFMagStd       = 
+gKronMag         = 
+gKronMagErr      = 
+gKronMagStd      = 
+gApMag           = 
+gApMagErr        = 
+gApMagStd        = 
+---------------- = 
+gFmeanflxR5      = 
+gFmeanflxR5Err   = 
+gFmeanflxR5Std   = 
+gFmeanflxR5Fill  = 
+gFmeanflxR6      = 
+gFmeanflxR6Err   = 
+gFmeanflxR6Std   = 
+gFmeanflxR6Fill  = 
+gFlags           = 
+---------------- = 
+gLensObjSmearX11 = 
+gLensObjSmearX12 = 
+gLensObjSmearX22 = 
+gLensObjSmearE1  = 
+gLensObjSmearE2  = 
+gLensObjShearX11 = 
+gLensObjShearX12 = 
+gLensObjShearX22 = 
+gLensObjShearE1  = 
+gLensObjShearE2  = 
+gLensPSFSmearX11 = 
+gLensPSFSmearX12 = 
+gLensPSFSmearX22 = 
+gLensPSFSmearE1  = 
+gLensPSFSmearE2  = 
+gLensPSFShearX11 = 
+gLensPSFShearX12 = 
+gLensPSFShearX22 = 
+gLensPSFShearE1  = 
+gLensPSFShearE2  = 
+---------------- = 
+gGamma           = 
+gE1              = 
+gE2              = 
+
+[NOTES:
+
+ * PSF Mag, Kron Mag, Ap Mag stats are all 
+   calculated from values in the existing Measure table
+
+   XXX : no! we need to record fluxes, not mags
+
+ * R5 & R6 ap flux values & lensing parameters need
+   a new table
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedWarpMeasurement
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedWarpMeasurement	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedWarpMeasurement	(revision 37066)
@@ -0,0 +1,82 @@
+objID           dimensionless   BIGINT  8       NA      ODM object identifier
+gcObjID		dimensionless	BIGINT	8	NA 	ODM galactic coordinates identifier
+detectID        dimensionless   BIGINT  8       NA      ODM detection identifier
+ippObjID        dimensionless   BIGINT  8       NA      ippobject id generated by IPP
+ippDetectID     dimensionless   BIGINT  8       NA      detection id generated by IPP
+filterID        dimensionless   TINYINT 1       NA      filter ID: g=1, r=2, i=3, z=4, y=5, w=6, ...
+surveyID        dimensionless   TINYINT 1       NA      survey flag identifier
+forcedWarpID    dimensionless   BIGINT  8       NA      IPP warp_id
+randomWarpID    dimensionless   BIGINT  8       NA      Random warp_id
+skyCellID       dimensionless   REAL    4       -999    single float giving PrimaryCell.SkyCell identifier 
+dvoRegionID     dimensionless   INT     4       -999    identifier to dvo spatial region
+obsTime         MeanJulianDays  FLOAT   8       -999    Time of mid observation in Mean Julian Days
+------------------------------------------------------ 
+zp              magnitude       REAL    4       0       zeropoint (only thing needed to convert adu/sec to AB mag), note no zpErr
+telluricExt     magnitude       REAL    4       NA      estimated extinction due to non-photometric conditions  
+expTime         seconds         REAL    4       -999    exposure time (informational)
+airMass         dimensionless   REAL    4       0       airmass (informational)
+------------------------------------------------------ 
+psfFlux         adu/seconds     REAL    4       -999    PSF instrumental flux (in analog-to-digital units/sec) or adu/sec
+psfFluxErr      adu/seconds     REAL    4       -999    estimated error in flux
+psfMajorFWHM    arcsec          REAL    4       -999    model PSF width in major axis
+psfMinorFWHM    arcsec          REAL    4       -999    model PSF width in minor axis
+psfTheta        degrees         REAL    4       -999    model PSF orientation angle degrees East of North
+psfCore         dimensionless   REAL    4       -999    model PSF core parameter [k in (1 + kz + z^1.66)]
+psfQf           dimensionless   REAL    4       -999    PSF coverage factor
+psfQfPerfect    dimensionless   REAL    4       -999    PSF-weighted fraction of pixels totally unmasked
+psfChiSq        dimensionless   REAL    4       -999    reduced-chisq of the psf model fit. (ndof?, npix?)
+psfLikelihood   dimensionless   REAL    4       -999    PSF likelihood
+momentXX        arcsec^2        REAL    4       -999    moment XX
+momentXY        arcsec^2        REAL    4       -999    moment XY
+momentYY        arcsec^2        REAL    4       -999    momeny YY
+momentR1        arcsec^1        REAL    4       -999    first radial moment 
+momentRH        arcsec          REAL    4       -999    to be half light radius   (DROP)
+momentM3C       arcsec^3        REAL    4       -999    3rd moment sin(theta) 
+momentM3S       arcsec^3        REAL    4       -999    3rd moment cos(theta) 
+momentM4C       arcsec^4        REAL    4       -999    4th moment sin(theta)
+momentM4S       arcsec^4        REAL    4       -999    4th moment cos(theta) 
+
+lensObjSmearX11 arcsec^-2       REAL    4       -999    per-object smear polarizability X11 term
+lensObjSmearX12 arcsec^-2       REAL    4       -999    per-object smear polarizability X12 term
+lensObjSmearX22 arcsec^-2       REAL    4       -999    per-object smear polarizability X22 term
+lensObjSmearE1  arcsec^-2       REAL    4       -999    per-object smear polarizability E1 term
+lensObjSmearE2  arcsec^-2       REAL    4       -999    per-object smear polarizability E2 term
+lensObjShearX11 dimensionless   REAL    4       -999    per-object shear polarizability X11 term
+lensObjShearX12 dimensionless   REAL    4       -999    per-object shear polarizability X12 term
+lensObjShearX22 dimensionless   REAL    4       -999    per-object shear polarizability X22 term
+lensObjShearE1  dimensionless   REAL    4       -999    per-object shear polarizability E1 term
+lensObjShearE2  dimensionless   REAL    4       -999    per-object shear polarizability E2 term
+lensPSFSmearX11 arcsec^-2       REAL    4       -999    psf model smear polarizability X11 term
+lensPSFSmearX12 arcsec^-2       REAL    4       -999    psf model smear polarizability X12 term
+lensPSFSmearX22 arcsec^-2       REAL    4       -999    psf model smear polarizability X22 term
+lensPSFSmearE1  arcsec^-2       REAL    4       -999    psf model smear polarizability E1 term
+lensPSFSmearE2  arcsec^-2       REAL    4       -999    psf model smear polarizability E2 term
+lensPSFShearX11 dimensionless   REAL    4       -999    psf model shear polarizability X11 term
+lensPSFShearX12 dimensionless   REAL    4       -999    psf model shear polarizability X12 term
+lensPSFShearX22 dimensionless   REAL    4       -999    psf model shear polarizability X22 term
+lensPSFShearE1  dimensionless   REAL    4       -999    psf model shear polarizability E1 term
+lensPSFShearE2  dimensionless   REAL    4       -999    psf model shear polarizability E2 term
+
+apFlux          adu/seconds     REAL    4       -999    Aperture flux
+apFluxErr       adu/seconds     REAL    4       -999    Aperture flux error
+apFillF         dimensionless   REAL    4       -999    Aperture fill factor 
+kronFlux        adu/seconds     REAL    4       -999    Kron flux
+kronFluxErr     adu/seconds     REAL    4       -999    Kron flux error
+kronRad         arcsec          REAL    4       -999    Kron radius
+kronRadErr      arcsed          REAL    4       -999    Kron radius error
+------------------------------------------------------ 
+flxR5           adu/seconds     REAL    4       -999    Flux inside r = 5
+flxR5Err        adu/seconds     REAL    4       -999    estimated error is flxR5
+flxR5Std        adu/seconds     REAL    4       -999    estimated standard deviation in flxR5
+flxR5Fill       dimensionless   REAL    4       -999    estimated filling factor at R5
+flxR6           adu/seconds     REAL    4       -999    Flux inside r = 6
+flxR6Err        adu/seconds     REAL    4       -999    estimated error is flxR6
+flxR6Std        adu/seconds     REAL    4       -999    estimated standard deviation in flxR6
+flxR6Fill       dimensionless   REAL    4       -999    estimated filling factor at R6
+------------------------------------------------------ 
+sky             adu/sec/pixel   REAL    4       -999    PSF sky level at source
+skyErr          adu/sec/pixel   REAL    4       -999    estimated error in sky
+infoFlag        dimensionless   BIGINT  8       -999    flag indicating provenance information
+dataRelease     dimensionless   TINYINT 1       NA      Data release when this detection was originally taken. Recalibrations do not affect this value.
+
+-- [295 byte/det]
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedWarpMeasurement.txt
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedWarpMeasurement.txt	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedWarpMeasurement.txt	(revision 37066)
@@ -0,0 +1,81 @@
+
+objID            = dvo/addstar
+gcObjID          = dvo/addstar
+detectID         = dvo/addstar
+ippObjID         = dvo/addstar
+ippDetectID      = dvo/addstar
+filterID         = 
+surveyID         = 
+forcedWarpID     = 
+randomWarpID     = 
+skyCellID        = 
+dvoRegionID      = 
+obsTime          = smf
+---------------- = 
+zp               = smf
+telluricExt      = (zp - zpNominal)
+expTime          = smf
+airMass          = smf
+---------------- = 
+psfFlux          = smf
+psfFluxErr       = smf
+psfMajorFWHM     = smf [PSF_MAJOR is Sxx parameter, NOT FWHM]
+psfMinorFWHM     = smf [PSF_MAJOR is Sxx parameter, NOT FWHM]
+psfTheta         = smf
+psfCore          = smf [XXX : not currently written out!!]
+psfQf            = smf
+psfQfPerfect     = smf
+psfChiSq         = smf
+psfLikelihood    = ipptopsps
+momentXX         = smf
+momentXY         = smf
+momentYY         = smf
+momentR1         = smf
+momentRH         = smf [XXX : MOMENTS_RH is NOT half-light radius]
+momentM3C        = smf
+momentM3S        = smf
+momentM4C        = smf
+momentM4S        = smf
+		 = 
+lensObjSmearX11  = smf [PS1_V5]
+lensObjSmearX12  = smf [PS1_V5]
+lensObjSmearX22  = smf [PS1_V5]
+lensObjSmearE1   = smf [PS1_V5]
+lensObjSmearE2   = smf [PS1_V5]
+lensObjShearX11  = smf [PS1_V5]
+lensObjShearX12  = smf [PS1_V5]
+lensObjShearX22  = smf [PS1_V5]
+lensObjShearE1   = smf [PS1_V5]
+lensObjShearE2   = smf [PS1_V5]
+lensPSFSmearX11  = smf [PS1_V5]
+lensPSFSmearX12  = smf [PS1_V5]
+lensPSFSmearX22  = smf [PS1_V5]
+lensPSFSmearE1   = smf [PS1_V5]
+lensPSFSmearE2   = smf [PS1_V5]
+lensPSFShearX11  = smf [PS1_V5]
+lensPSFShearX12  = smf [PS1_V5]
+lensPSFShearX22  = smf [PS1_V5]
+lensPSFShearE1   = smf [PS1_V5]
+lensPSFShearE2   = smf [PS1_V5]
+		 = 
+apFlux           = smf [PS1_V4]
+apFluxErr        = smf [PS1_V4]
+apFillF          = smf [EAM: add to smf output]
+kronFlux         = smf
+kronFluxErr      = smf
+kronRad          = (2.5*R1)
+kronRadErr       = [drop : not currently calculated]
+---------------- = 
+flxR5            = smf [?? calculated?]
+flxR5Err         = smf [?? calculated?]
+flxR5Std         = smf [?? calculated?]
+flxR5Fill        = smf [?? calculated?]
+flxR6            = smf [?? calculated?]
+flxR6Err         = smf [?? calculated?]
+flxR6Std         = smf [?? calculated?]
+flxR6Fill        = smf [?? calculated?]
+---------------- = 
+sky              = smf
+skyErr           = smf
+infoFlag         = 
+dataRelease      = 
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/MeanObject
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/MeanObject	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/MeanObject	(revision 37066)
@@ -0,0 +1,27 @@
+             
+--              The  "best available" measurements refer first to those objects with qfPerfect > 0.85 and good flags, 
+--              but descends down a "waterfall logic" in ipp so that there exists a mean mag for less than ideal objects. The logic is given in Magnier etal 2013.
+
+objID           dimensionless   BIGINT   8       NA      ODM object identifier index
+gcObjID		dimensionless	BIGINT	 8	 NA 	ODM galactic coordinates identifier
+gQfPerfect      dimensionless   REAL     4       -999    maximum psf qfPerfect from best available g band detections 
+gMeanPSFMag     AB_magnitude    REAL     4       -999    mean g psf AB magnitude from best available measurements (best available as current defined by ipp "waterfall logic"  
+gMeanPSFMagErr  AB_magnitude    REAL     4       -999    estimated error of best availalbe g-band psf AB magnitudes (individual errors added in quadrature)
+gnIncPSFMag     dimensionless   SMALLINT 2       -999    number of best available detections included in mean psfMag 
+gMeanPSFMagStd  dimensioless    REAL     4       -999    standard deviation of best available measurements - compared with MeanErr this is one measure of true variability  
+gMinPSFMag      AB_magnitude    REAL     4       -999    minimum best available PSFMag - min and max are given for PSFMag as they may indicate variability.  
+gMaxPSFMag      AB_magnitude    REAL     4       -999    maximum best available PSFMag   
+					 
+gMeanKronMag    AB_magnitude    REAL     4       -999    mean g kron AB magnitude from best available measurements     
+gMeanKronMagErr AB_magnitude    REAL     4       -999    estimated error of mean g kron AB magnitude 
+gnIncKronMag    dimensionless   SMALLINT 2       -999    number of best available detections included mean Kron mag 
+gMeanKronMagStd dimensioless    REAL     4       -999    standard deviation of best available measurements   
+					 
+gMeanApMag      AB_magnitude    REAL     4       -999    mean g kron AB magnitude from best available measurements
+gMeanApMagErr   AB_magnitude    REAL     4       -999    estimated error of g kron AB magnitude mean
+gnIncApMag      dimensionless   SMALLINT 2       -999    number of detections included in best available mean of Kron mag in g filter
+gMeanApMagStd   dimensioless    REAL     4       -999    standard deviation of best available measurements   
+gFlags          dimensionless   BIGINT   8       NA      flags for g mean
+-- duplicate for other filters
+
+[62 byte/obj/filter + 8 byte/filter]
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/MeanObject.txt
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/MeanObject.txt	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/MeanObject.txt	(revision 37066)
@@ -0,0 +1,25 @@
+
+
+
+
+objID           = dvo / addstar
+gcObjID         = dvo / addstar
+gQfPerfect      = dvo / relphot / secfilt. [XXX Not calculated]
+gMeanPSFMag     = dvo / relphot / secfilt.M 
+gMeanPSFMagErr  = dvo / relphot / secfilt.dM
+gnIncPSFMag     = dvo / relphot / secfilt.Nused [XXX : ensure .Nused matches .M]
+gMeanPSFMagStd  = dvo / relphot / secfilt.Mstdev 
+gMinPSFMag      = dvo / relphot / secfilt.Min [XXX: replace M_20, M_80 with Min, Max]
+gMaxPSFMag      = dvo / relphot / secfilt.Max [XXX: replace M_20, M_80 with Min, Max]
+		= 
+gMeanKronMag    = dvo / relphot / secfilt.Mkron 
+gMeanKronMagErr = dvo / relphot / secfilt.dMkron
+gnIncKronMag    = dvo / relphot / secfilt.nMkron [XXX : not calculated]
+gMeanKronMagStd = dvo / relphot / secfilt.MstdevKron [XXX : not calculated]
+		= 
+gMeanApMag      = dvo / relphot / secfilt.Map
+gMeanApMagErr   = dvo / relphot / secfilt.? [XXX : not calculated]
+gnIncApMag      = dvo / relphot / secfilt.? [XXX : not calculated]
+gMeanApMagStd   = dvo / relphot / secfilt.? [XXX : not calculated]
+
+gFlags          = dvo / relphot / secfilt.flags
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ObjectThin
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ObjectThin	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ObjectThin	(revision 37066)
@@ -0,0 +1,51 @@
+
+objName          string         VAR      8      NA      IAU Name constructed from objID postion PS1.x JHHMMSS.SS+/-DDMMSS.S where x is leading number of procesing version       
+objID            dimensionless  BIGINT   8      NA      ODM object identifier index
+gcObjID		 dimensionless	BIGINT	8	  NA 	ODM galactic coordinates identifier
+ippObjID         dimensionless  BIGINT   8      NA      IPP object number
+surveyID         dimensionless  TINYINT  1      255     Survey ID
+skyCellID        dimensionless  REAL     4      -999     single float giving PrimaryCell.SkyCell identifier
+htmID            dimensionless  BIGINT   8      NA      HTM index
+zoneID           dimensionless  INT      4      NA      Zone index
+randomID         dimensionless  BIGINT   8      0       Random integer between 0 and 2^32 = 4,394,967,296 remaining ramdom integer 0  
+batchID          dimensionless  BIGINT   8      -999    batch id        
+dvoRegionID      dimensionless  INT      4      -999    identifier of dvo spatial region - dvo cat id
+dataRelease      dimensionless  TINYINT  1      NA      Data release Version of this table
+objInfoFlag      dimensionless  BIGINT   8      -999    flag indicating odd properties
+qualityFlag      dimensionless  TINYINT  1      0       subset of objInfoFlag - flags related to goodness of object
+consistencyFlag  dimensionless  SMALLINT 2      0       Value computed from associated detections, it is originally given by IPP and should agree with the ODM validation (DROP)
+raStack          degrees        FLOAT    8      -999    Right Ascension - best weighted RA across filters from stack WHENEVER an object is detected in the stack  
+decStack         degrees        FLOAT    8      -999    Declination - best weighted Dec across filters from stack WHENEVER an object is detected in the stack 
+raStackErr       arcsec         REAL     4      -999    Error in stack Right Ascension, note will have a systematic floor, and is not necessary the best ra,dec for all objects 
+decStackErr      arcsec         REAL     4      -999    Error in stack Declination, note will have a systematic floor, and is not necessarily the best ra,dec for all objects
+raMean           degrees        FLOAT    8      -999    Right Ascension from the Mean of RA from individual detections if it exists. This is for information only  
+decMean          degrees        FLOAT    8      -999    Declination from the Mean of Dec from individual detections if it exists  This is for information only.  
+raMeanErr        arcsec         REAL     4      -999    Combination of the measurement Errors in the Right Ascension from the mean detections if they exist 
+decMeanErr       arcsec         REAL     4      -999    Combination of the measurement Errors in the  Declination measurements if they exist  
+raMeanStd        arcsec         Real     4      -999    standard deviation of Right Ascension measurements in detections if they exist 
+decMeanStd       arcsec         REAL     4      -999    standard deviation of the  Declination measurements if they exist  
+--------------------------------------------------------------------------------------------------------
+--                                                      Note: the following three sets of coordinate systems are based on stack if it exists, and mean if it does not.
+--                                                      This means cone or box searches work on the stack and consistent with Primary and Best stack detection.
+--                                                      For objects without a stack postion, (moving, transient, or false dectection) a cone search may be incomplete for
+--                                                      an object within less than 1 arc sec of the boundary edge. But science cases here will want to work from Detection
+--                                                      Table anyway, or can vary cone search by 1'' radius to check for incompleteness.  
+cx               dimensionless  FLOAT    8      NA      Cartesian x from Stack RA,Dec WHENEVER a stack detection exists, and Mean RA, Dec (mean of one?) when it doesn't 
+cy               dimensionless  FLOAT    8      NA      Cartesian y from Stack RA,Dec WHENEVER a stack detection exists, and mean RA, Dec (mean of one?) when it doesn't 
+cz               dimensionless  FLOAT    8      NA      Cartesian z from Stack RA,Dec WHENEVER a stack detection exists, ditto
+lambda           degrees        FLOAT    8      -999    ecliptic longitude from Stack RA,Dec WHENEVER A STACK MEASURMENT EXISTS and Mean RA,Dec (mean of one?) otherwise 
+beta             degrees        FLOAT    8      -999    ecliptic latitude ditto
+l                degrees        FLOAT    8      -999    galactic longitude ditto
+b                degrees        FLOAT    8      -999    galactic latitude ditto
+---------------------------------------------------------------------------------
+nStackObjectRows dimensionless  SMALLINT 2      -999    number of independent StackObjectRows this object has. 
+--                                                      zero if not detected in the Stack, 1 if there is a primary, 2 or more if it is in an overlap region
+nStackDetections dimensionless  TINYINT  2       255    which filter bands it is detected in (not forced) or if it was masked in a band.        
+nDetections      dimensionless  SMALLINT 2      -999    total number of detection measurements in all filters
+ng               dimensionless  SMALLINT 2      -999    number of detections in individual g filter exposures
+nr               dimensionless  SMALLINT 2      -999    number of detections in individual r filter exposures
+ni               dimensionless  SMALLINT 2      -999    number of detections in individual i filter exposures
+nz               dimensionless  SMALLINT 2      -999    number of detections in individual z filter exposures
+ny               dimensionless  SMALLINT 2      -999    number of detections in individual y filter exposures
+
+-- [197 byte/obj]
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ObjectThin.txt
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ObjectThin.txt	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ObjectThin.txt	(revision 37066)
@@ -0,0 +1,49 @@
+
+objName           = ipptopsps
+objID             = dvo / addstar
+gcobjID           = dvo / addstar
+ippObjID          = dvo / addstar
+surveyID          = ipptopsps
+skyCellID         = smf header
+htmID             = PSPS
+zoneID            = PSPS
+randomID          = ipptopsps
+batchID           = ipptopsps
+dvoRegionID       = dvo / catID
+dataRelease       = ipptopsps
+objInfoFlag       = dvo / relastro,relphot [define]
+qualityFlag       = dvo / relastro,relphot [define]
+consistencyFlag   = ipptopsps?
+raStack           = dvo / allow recalibration? [ADD to average.d]
+decStack          = dvo / allow recalibration?
+raStackErr        = dvo / allow recalibration?
+decStackErr       = dvo / allow recalibration?
+raMean            = dvo / relastro
+decMean           = dvo / relastro
+raMeanErr         = dvo / relastro
+decMeanErr        = dvo / relastro
+raMeanStd         = dvo / relastro
+decMeanStd        = dvo / relastro
+----------------- = 
+--                = 
+--                = 
+--                = 
+--                = 
+--                = 
+cx                = PSPS
+cy                = PSPS
+cz                = PSPS
+lambda            = PSPS
+beta              = PSPS
+l                 = PSPS
+b                 = PSPS
+----------------- = 
+nStackObjectRows  = dvo [ADD to average.d]
+--                = 
+nStackDetections  = dvo / relphot [Sum of not-forced stack detections]
+nDetections       = dvo / relphot [Sum of ng+nr, etc?]
+ng                = dvo / relphot [Sum of GPC1.g.XY?? measure.d]
+nr                = dvo / relphot [ditto]
+ni                = dvo / relphot
+nz                = dvo / relphot
+ny                = dvo / relphot
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackApFlx
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackApFlx	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackApFlx	(revision 37066)
@@ -0,0 +1,60 @@
+
+objID            dimensionless  BIGINT  8       NA      ODM object identifier
+gcObjID	  	 dimensionless	BIGINT	8	NA 	ODM galactic coordinates identifier
+ippObjID         dimensionless  BIGINT  8       NA      ipp object identifier
+surveyID         dimensionless  TINYINT 1       0       stack type identifier
+skyCellID        dimensionless  REAL    4       -999    single float giving PrimaryCell.SkyCell identifier 
+randomStackObjID dimensionless  BIGINT  8       NA      random stack id
+stackDetectRowID dimensionless  BIGINT  8       NA      identifies which of up to 5 possible stackdetctions this Row refers to: Primary, up to 3 Secondary, 1 best  
+primaryDetection dimensionless  TINYINT 1       255     identifies if this row is a primary stack detection. True about 80% of time. 
+bestDetection    dimensionless  TINYINT 1       255     identifies if this row is a best detection or not. Also set if only a primary detection exists.   
+--                                                      the Primary Dectection, 0 to 3 possible secondary dectections, and the "best" per filter.  
+dvoRegionID     dimensionless   INT    4       -999    identifier to dvo spatial region
+dataRelease     dimensionless   TINYINT 1       NA      Data release when this table was loaded.
+------------------------------------------------------- replicate to end for each filter g,r,i,z,y
+gippDetectID    dimensionless   BIGINT  8       NA      stack identifier
+gstackDetectID  dimensionless   BIGINT  8       NA      ODM detection identifier
+gstackMetaID    dimensionless   BIGINT  8       NA      stack identifier
+--------------------------------------------------------unconvolved
+gflxR3          adu/seconds     REAL    4       -999    Flux inside r = 3
+gflxR3Err       adu/seconds     REAL    4       -999    estimated error is flxR3
+gflxR3Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR3
+gflxR3Fill      dimensionless   REAL    4       -999    estimated filling factor at R3
+gflxR4          adu/seconds     REAL    4       -999    Flux inside r = 4
+gflxR4Err       adu/seconds     REAL    4       -999    estimated error is flxR4
+gflxR4Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR4
+gflxR4Fill      dimensionless   REAL    4       -999    estimated filling factor at R4
+gflxR5          adu/seconds     REAL    4       -999    Flux inside r = 5
+gflxR5Err       adu/seconds     REAL    4       -999    estimated error is flxR5
+gflxR5Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR5
+gflxR5Fill      dimensionless   REAL    4       -999    estimated filling factor at R5
+----------------------------------------------------    convolved across all bands to 6 or 8 pixels
+gc1flxR3        adu/seconds     REAL    4       -999    Flux inside r = 3
+gc1flxR3Err     adu/seconds     REAL    4       -999    estimated error is c1flxR3
+gc1flxR3Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR3
+gc1flxR3Fill    dimensionless   REAL    4       -999    estimated filling factor at R3
+gc1flxR4        adu/seconds     REAL    4       -999    Flux inside r = 4
+gc1flxR4Err     adu/seconds     REAL    4       -999    estimated error is c1flxR4
+gc1flxR4Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR4
+gc1flxR4Fill    dimensionless   REAL    4       -999    estimated filling factor at R4
+gc1flxR5        adu/seconds     REAL    4       -999    Flux inside r = 5
+gc1flxR5Err     adu/seconds     REAL    4       -999    estimated error is c1flxR5
+gc1flxR5Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR5
+gc1flxR5Fill    dimensionless   REAL    4       -999    estimated filling factor at R5
+----------------------------------------------------    convolved across all bands to 6 or 8 pixels
+gc2flxR3        adu/seconds     REAL    4       -999    Flux inside r = 3
+gc2flxR3Err     adu/seconds     REAL    4       -999    estimated error in c2flxR3
+gc2flxR3Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR3
+gc2flxR3Fill    dimensionless   REAL    4       -999    estimated filling factor at R3
+gc2flxR4        adu/seconds     REAL    4       -999    Flux inside r = 4
+gc2flxR4Err     adu/seconds     REAL    4       -999    estimated error in c2flxR4
+gc2flxR4Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR4
+gc2flxR4Fill    dimensionless   REAL    4       -999    estimated filling factor at R4
+gc2flxR5        adu/seconds     REAL    4       -999    Flux inside r = 5
+gc2flxR5Err     adu/seconds     REAL    4       -999    estimated error in c2flxR5
+gc2flxR5Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR5
+gc2flxR5Fill    dimensionless   REAL    4       -999    estimated filling factor at R5
+
+-- repeat for other filters with appropriate leading prefex.
+-- [168 byte/filter/obj + 44 byte/obj]
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackApFlx.txt
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackApFlx.txt	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackApFlx.txt	(revision 37066)
@@ -0,0 +1,56 @@
+
+objID            = dvo/addstar
+gcObjID          = dvo/addstar
+ippObjID         = dvo/addstar average.objID + (average.catID << 32)
+surveyID         = ipptopsps
+skyCellID        = smf header
+randomStackObjID = ipptopsps
+stackDetectRowID = PSPS ?
+primaryDetection = dvo
+bestDetection    = dvo
+--               = 
+dvoRegionID      = dvo / catID
+dataRelease      = ipptopsps
+---------------- = 
+gippDetectID     = dvo/addstar
+gstackDetectID   = dvopsps (see StackObject.txt)
+gstackMetaID     = dvopsps (see StackObject.txt)
+---------------- = 
+gflxR3           = smf
+gflxR3Err        = smf
+gflxR3Std        = smf
+gflxR3Fill       = smf
+gflxR4           = smf
+gflxR4Err        = smf
+gflxR4Std        = smf
+gflxR4Fill       = smf
+gflxR5           = smf
+gflxR5Err        = smf
+gflxR5Std        = smf
+gflxR5Fill       = smf
+---------------- = 
+gc1flxR3         = smf
+gc1flxR3Err      = smf
+gc1flxR3Std      = smf
+gc1flxR3Fill     = smf
+gc1flxR4         = smf
+gc1flxR4Err      = smf
+gc1flxR4Std      = smf
+gc1flxR4Fill     = smf
+gc1flxR5         = smf
+gc1flxR5Err      = smf
+gc1flxR5Std      = smf
+gc1flxR5Fill     = smf
+---------------- = 
+gc2flxR3         = smf
+gc2flxR3Err      = smf
+gc2flxR3Std      = smf
+gc2flxR3Fill     = smf
+gc2flxR4         = smf
+gc2flxR4Err      = smf
+gc2flxR4Std      = smf
+gc2flxR4Fill     = smf
+gc2flxR5         = smf
+gc2flxR5Err      = smf
+gc2flxR5Std      = smf
+gc2flxR5Fill     = smf
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFit
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFit	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFit	(revision 37066)
@@ -0,0 +1,209 @@
+
+objID            dimensionless  BIGINT  8       NA      ODM object identifier
+gcObjID		 dimensionless	BIGINT	8	NA 	ODM galactic coordinates identifier
+ippObjID         dimensionless  BIGINT  8       NA      ipp object identifier
+surveyID         dimensionless  TINYINT 1       NA      survey flag identifier
+skyCellID        dimensionless  REAL    4       -999    single float giving PrimaryCell.SkyCell identifier 
+randomStackObjID dimensionless  BIGINT  8       NA      random stack id
+stackDetectRowID dimensionless  BIGINT  8       NA      identifies which of up to 5 possible stackdetctions this Row refers to: Primary, up to 3 Secondary, 1 best  
+primaryDetection dimensionless  TINYINT 1       255     identifies if this row is a primary stack detection. True about 80% of time. 
+bestDetection    dimensionless  TINYINT 1       255     identifies if this row is a best detection or not. Also set if only a primary detection exists.   
+--                                                      the Primary Dectection, 0 to 3 possible secondary dectections, and the "best" per filter.  
+dvoRegionID      dimensionless  INT     4       -999    identifier to dvo spatial region
+dataRelease      dimensionless  TINYINT 1       NA      Data release when this table was loaded
+-------------------------------------------------------- replicate below for all filters (grizy)
+gS2             dimensionless   REAL    4       -999    (un)smoothness (Cheng 2012, Simard 2002)
+glogRT		dimensionless   REAL    4       -999    total residual (from ellipcally symmetric model)
+glogRA		dimensionless   REAL    4       -999    asymmetric residual (from ellipcally symmetric model)
+glogC           dimensionless   REAL    4       -999    concentration index  (Petrosian R_50 / R_90)
+glogA           dimensionless   REAL    4       -999    log of asymmetry index (Gyory & Bell 2010)
+gbumpy          dimensionless   REAL    4       -999    Blakeslee bumpiness
+ghalfLightRad   arcsec          REAL    4       -999    half-light radius
+-------------------------------------------------------- replicate below for all filters (grizy)
+gippDetectID    dimensionless   BIGINT  8       NA      ipp detect identifier
+gstackDetectID  dimensionless   BIGINT  8       NA      ODM detection identifier
+gstackMetaID    dimensionless   BIGINT  8       NA      stack identifier
+----------------------------------------------------------------------------------------
+gdeVRadius      arcsec          REAL    4       -999    deVaucouleurs radius
+gdeVRadiusErr   arcsec          REAL    4       -999    estimated error in deVaucouleurs radius
+gdeVFlux        adu/seconds     REAL    4       -999    deVaucouleurs flux
+gdeVFluxErr     adu/seconds     REAL    4       -999    estimated error in deVaucouleurs flux
+gdeVAb          dimensionless   REAL    4       -999    deVaucoulerus axis ratio
+gdeVAbErr       dimensionless   REAL    4       -999    estimated error in deVaucoulerus axis ratio
+gdeVPhi         degrees         REAL    4       -999    estmated phi of deVaucouleurs axis. Degrees East of North.
+gdeVPhiErr      degrees         REAL    4       -999    estmated error of phi of deVaucouleurs axis
+graDeVOff       arcsec          REAL    4       -999    Offset in RA of deVaucouleurs fit from PSF RA
+gdecDeVOff      arcsec          REAL    4       -999    Offset in DEC of deVaucouleurs fit from PSF DEC
+graDeVOffErr    arcsec          REAL    4       -999    estimated error in ra offset
+gdecDeVOffErr   arcsec          REAL    4       -999    estimated error in dec offset
+gdeVCf          dimensionless   REAL    4       -999    deVaucouleurs fit coverage factor
+gdeVLikelihood  dimensionless   REAL    4       -999    deVaucouleurs fit likelihood factor
+----------------------------------------------------------------------------------------
+gexpRadius      arcsec          REAL    4       -999    Exponential fit radius
+gexpRadiusErr   arcsec          REAL    4       -999    estimated error in Exponential fit radius
+gexpFlux        adu/seconds     REAL    4       -999    Exponential fit flux
+gexpFluxErr     adu/seconds     REAL    4       -999    estimated error in expFlux
+gexpAb          dimensionless   REAL    4       -999    Exponential fit axis ratio
+gexpAbErr       dimensionless   REAL    4       -999    estimated error in Exponential fit axis ratio
+gexpPhi         degrees         REAL    4       -999    estmated phi of Exponential axis
+gexpPhiErr      degrees         REAL    4       -999    estmated error of phi of Exponential axis
+graExpOff       dimensionless   REAL    4       -999    Offset in RA of Exponential fit from PSF RA
+gdecExpOff      dimensionless   REAL    4       -999    Offset in DEC of Exponential fit from PSF DEC
+graExpOffErr    dimensionless   REAL    4       -999    estimated error in raExpOff
+gdecExpOffErr   dimensionless   REAL    4       -999    estimated error in decExpOff
+gexpCf          dimensionless   REAL    4       -999    Exponential fit coverage factor
+gexpLikelihood  dimensionless   REAL    4       -999    Exponential fit likelihood factor
+---------------------------------------------------------------------------------------
+gserRadius      arcsec          REAL    4       -999    Sersic radius
+gserRadiusErr   arcsed          REAL    4       -999    estimated error in Sersic radius
+gserFlux        adu/seconds     REAL    4       -999    Sersic Flux
+gserFluxErr     adu/seconds     REAL    4       -999    estimated error in serFlux
+gserAb          dimensionless   REAL    4       -999    Sersic axis ratio
+gserAbErr       dimensionlessn  REAL    4       -999    estimated error in Sersic axis ratio
+gserNu          dimensionlessn  REAL    4       -999    Sersic index
+gserNuErr       diemensionless  REAL    4       -999    estimated error in Sersic index
+gserPhi         degrees         REAL    4       -999    estmated phi of Sersic axis
+gserPhiErr      degrees         REAL    4       -999    estmated error of phi of Sersic axis
+graSerOff       dimensionless   REAL    4       -999    Offset in RA of Sersic fit from PSF RA
+gdecSerOff      dimensionless   REAL    4       -999    Offset in DEC of Sersic fit from PSF DEC
+graSerOffErr    dimensionless   REAL    4       -999    estimated error in raSerOff
+gdecSerOffErr   dimensionless   REAL    4       -999    estimated error in decSerOff
+gserCf          dimensionless   REAL    4       -999    Sersic fit coverage factor
+gserLikelihood  dimensionless   REAL    4       -999    Sersic fit likelihood factor
+---------------------------------------------------------------------------------------
+gpetRadius      pixels          REAL    4       -999    Petrosian radius
+gpetRadiusErr   pixels          REAL    4       -999    estimated error inPetrosian radius
+gpetFlux        adu/sec         REAL    4       -999    Petrosian Flux
+gpetFluxErr     adu/sec         REAL    4       -999    estimated error in petFlux
+gpetR50         pixels          REAL    4       -999    Petrosian radius at 50% light
+gpetR50Err      pixels          REAL    4       -999    estimated error inPetrosian radius at 50% light
+gpetR90         pixels          REAL    4       -999    Petrosian radius at 90% light
+gpetR90Err      pixels          REAL    4       -999    estimated error in Petrosian radius at 90% light
+gpetCf          dimensionless   REAL    4       -999    Petrosian fit coverage factor
+--------------------------------------------------------unconvolved
+gflxR1          adu/seconds     REAL    4       -999    Flux inside r = 1
+gflxR1Err       adu/seconds     REAL    4       -999    estimated error is flxR1
+gflxR1Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR1
+gflxR1Fill      dimensionless   REAL    4       -999    estimated filling factor at R1
+gflxR2          adu/seconds     REAL    4       -999    Flux inside r = 2
+gflxR2Err       adu/seconds     REAL    4       -999    estimated error is flxR2
+gflxR2Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR2
+gflxR2Fill      dimensionless   REAL    4       -999    estimated filling factor at R1
+gflxR3          adu/seconds     REAL    4       -999    Flux inside r = 3
+gflxR3Err       adu/seconds     REAL    4       -999    estimated error is flxR3
+gflxR3Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR3
+gflxR3Fill      dimensionless   REAL    4       -999    estimated filling factor at R3
+gflxR4          adu/seconds     REAL    4       -999    Flux inside r = 4
+gflxR4Err       adu/seconds     REAL    4       -999    estimated error is flxR4
+gflxR4Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR4
+gflxR4Fill      dimensionless   REAL    4       -999    estimated filling factor at R4
+gflxR5          adu/seconds     REAL    4       -999    Flux inside r = 5
+gflxR5Err       adu/seconds     REAL    4       -999    estimated error is flxR5
+gflxR5Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR5
+gflxR5Fill      dimensionless   REAL    4       -999    estimated filling factor at R5
+gflxR6          adu/seconds     REAL    4       -999    Flux inside r = 6
+gflxR6Err       adu/seconds     REAL    4       -999    estimated error is flxR6
+gflxR6Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR6
+gflxR6Fill      dimensionless   REAL    4       -999    estimated filling factor at R6
+gflxR7          adu/seconds     REAL    4       -999    Flux inside r = 7
+gflxR7Err       adu/seconds     REAL    4       -999    estimated error is flxR7
+gflxR7Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR7
+gflxR7Fill      dimensionless   REAL    4       -999    estimated filling factor at R7
+gflxR8          adu/seconds     REAL    4       -999    Flux inside r = 8
+gflxR8Err       adu/seconds     REAL    4       -999    estimated error is flxR8
+gflxR8Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR8
+gflxR8Fill      dimensionless   REAL    4       -999    estimated filling factor at R8
+gflxR9          adu/seconds     REAL    4       -999    Flux inside r = 9
+gflxR9Err       adu/seconds     REAL    4       -999    estimated error is flxR9
+gflxR9Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR9
+gflxR9Fill      dimensionless   REAL    4       -999    estimated filling factor at R9
+gflxR10         adu/seconds     REAL    4       -999    Flux inside r = 10
+gflxR10Err      adu/seconds     REAL    4       -999    estimated error is flxR10
+gflxR10Std      adu/seconds     REAL    4       -999    estimated standard deviation in flxR10
+gflxR10Fill     dimensionless   REAL    4       -999    estimated filling factor at R10
+----------------------------------------------------    convolved across all bands to 6 or 8 pixels
+gc1flxR1        adu/seconds     REAL    4       -999    Flux inside r = 1
+gc1flxR1Err     adu/seconds     REAL    4       -999    estimated error is c1flxR1
+gc1flxR1Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR1
+gc1flxR1Fill    dimensionless   REAL    4       -999    estimated filling factor at R1
+gc1flxR2        adu/seconds     REAL    4       -999    Flux inside r = 2
+gc1flxR2Err     adu/seconds     REAL    4       -999    estimated error is c1flxR2
+gc1flxR2Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR2
+gc1flxR2Fill    dimensionless   REAL    4       -999    estimated filling factor at R1
+gc1flxR3        adu/seconds     REAL    4       -999    Flux inside r = 3
+gc1flxR3Err     adu/seconds     REAL    4       -999    estimated error is c1flxR3
+gc1flxR3Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR3
+gc1flxR3Fill    dimensionless   REAL    4       -999    estimated filling factor at R3
+gc1flxR4        adu/seconds     REAL    4       -999    Flux inside r = 4
+gc1flxR4Err     adu/seconds     REAL    4       -999    estimated error is c1flxR4
+gc1flxR4Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR4
+gc1flxR4Fill    dimensionless   REAL    4       -999    estimated filling factor at R4
+gc1flxR5        adu/seconds     REAL    4       -999    Flux inside r = 5
+gc1flxR5Err     adu/seconds     REAL    4       -999    estimated error is c1flxR5
+gc1flxR5Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR5
+gc1flxR5Fill    dimensionless   REAL    4       -999    estimated filling factor at R5
+gc1flxR6        adu/seconds     REAL    4       -999    Flux inside r = 6
+gc1flxR6Err     adu/seconds     REAL    4       -999    estimated error is c1flxR6
+gc1flxR6Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR6
+gc1flxR6Fill    dimensionless   REAL    4       -999    estimated filling factor at R6
+gc1flxR7        adu/seconds     REAL    4       -999    Flux inside r = 7
+gc1flxR7Err     adu/seconds     REAL    4       -999    estimated error is c1flxR7
+gc1flxR7Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR7
+gc1flxR7Fill    dimensionless   REAL    4       -999    estimated filling factor at R7
+gc1flxR8        adu/seconds     REAL    4       -999    Flux inside r = 8
+gc1flxR8Err     adu/seconds     REAL    4       -999    estimated error is c1flxR8
+gc1flxR8Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR8
+gc1flxR8Fill    dimensionless   REAL    4       -999    estimated filling factor at R8
+gc1flxR9        adu/seconds     REAL    4       -999    Flux inside r = 9
+gc1flxR9Err     adu/seconds     REAL    4       -999    estimated error is c1flxR9
+gc1flxR9Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR9
+gc1flxR9Fill    dimensionless   REAL    4       -999    estimated filling factor at R9
+gc1flxR10       adu/seconds     REAL    4       -999    Flux inside r = 10
+gc1flxR10Err    adu/seconds     REAL    4       -999    estimated error is c1flxR10
+gc1flxR10Std    adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR10
+gc1flxR10Fill   dimensionless   REAL    4       -999    estimated filling factor at R10
+gc2flxR1        adu/seconds     REAL    4       -999    Flux inside r = 1
+gc2flxR1Err     adu/seconds     REAL    4       -999    estimated error is c2flxR1
+gc2flxR1Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR1
+gc2flxR1Fill    dimensionless   REAL    4       -999    estimated filling factor at R1
+gc2flxR2        adu/seconds     REAL    4       -999    Flux inside r = 2
+gc2flxR2Err     adu/seconds     REAL    4       -999    estimated error is c2flxR2
+gc2flxR2Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR2
+gc2flxR2Fill    dimensionless   REAL    4       -999    estimated filling factor at R1
+gc2flxR3        adu/seconds     REAL    4       -999    Flux inside r = 3
+gc2flxR3Err     adu/seconds     REAL    4       -999    estimated error is c2flxR3
+gc2flxR3Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR3
+gc2flxR3Fill    dimensionless   REAL    4       -999    estimated filling factor at R3
+gc2flxR4        adu/seconds     REAL    4       -999    Flux inside r = 4
+gc2flxR4Err     adu/seconds     REAL    4       -999    estimated error is c2flxR4
+gc2flxR4Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR4
+gc2flxR4Fill    dimensionless   REAL    4       -999    estimated filling factor at R4
+gc2flxR5        adu/seconds     REAL    4       -999    Flux inside r = 5
+gc2flxR5Err     adu/seconds     REAL    4       -999    estimated error is c2flxR5
+gc2flxR5Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR5
+gc2flxR5Fill    dimensionless   REAL    4       -999    estimated filling factor at R5
+gc2flxR6        adu/seconds     REAL    4       -999    Flux inside r = 6
+gc2flxR6Err     adu/seconds     REAL    4       -999    estimated error is c2flxR6
+gc2flxR6Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR6
+gc2flxR6Fill    dimensionless   REAL    4       -999    estimated filling factor at R6
+gc2flxR7        adu/seconds     REAL    4       -999    Flux inside r = 7
+gc2flxR7Err     adu/seconds     REAL    4       -999    estimated error is c2flxR7
+gc2flxR7Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR7
+gc2flxR7Fill    dimensionless   REAL    4       -999    estimated filling factor at R7
+gc2flxR8        adu/seconds     REAL    4       -999    Flux inside r = 8
+gc2flxR8Err     adu/seconds     REAL    4       -999    estimated error is c2flxR8
+gc2flxR8Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR8
+gc2flxR8Fill    dimensionless   REAL    4       -999    estimated filling factor at R8
+gc2flxR9        adu/seconds     REAL    4       -999    Flux inside r = 9
+gc2flxR9Err     adu/seconds     REAL    4       -999    estimated error is c2flxR9
+gc2flxR9Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR9
+gc2flxR9Fill    dimensionless   REAL    4       -999    estimated filling factor at R9
+gc2flxR10       adu/seconds     REAL    4       -999    Flux inside r = 10
+gc2flxR10Err    adu/seconds     REAL    4       -999    estimated error is c2flxR10
+gc2flxR10Std    adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR10
+gc2flxR10Fill   dimensionless   REAL    4       -999    estimated filling factor at R10
+
+-- repeat for other filters with appropriate leading prefex.
+
+-- [728 byte/filter/obj + 44 byte/obj]
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFit.txt
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFit.txt	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFit.txt	(revision 37066)
@@ -0,0 +1,200 @@
+
+objID             = dvo / addstar
+gcObjID           = dvo / addstar [EAM: add to addstar]
+ippObjID          = dvo / addstar average.objID + (average.catID << 32)
+surveyID          = ipptopsps
+skyCellID         = smf header
+randomStackObjID  = ipptopsps
+stackDetectRowID  = PSPS ?
+primaryDetection  = dvo
+bestDetection     = dvo (define?)
+--                = 
+dvoRegionID       = dvo / catID [EAM: add to dvopsps]
+dataRelease       = ipptopsps
+----------------  = 
+glogC             = [NOT currently calculated] [EAM: add to psphotStack]
+glogA             = [NOT currently calculated]
+gclump            = [NOT currently calculated]
+----------------  = 
+gippDetectID      = dvopsps (see StackObject.txt)
+gstackDetectID    = dvopsps (see StackObject.txt)
+gstackMetaID      = dvopsps (see StackObject.txt)
+----------------  = 
+gdeVRadius        = smf [NOTE: the smf has Major, Minor, Theta, but errors on Sxx, Syy, Sxy
+gdeVRadiusErr     = smf
+gdeVFlux          = smf
+gdeVFluxErr       = smf
+gdeVAb            = smf
+gdeVAbErr         = smf
+gdeVPhi           = smf
+gdeVPhiErr        = smf [convert from Sxx,Sxy,Syy??]
+graDeVOff         = smf (calculate from reported position vs psf position)
+gdecDeVOff        = smf (calculate from reported position vs psf position)
+graDeVOffErr      = smf
+gdecDeVOffErr     = smf
+gdeVCf            = [NOT currently calculated] [count nPix in fit vs pi r^2]
+gdeVLikelihood    = ipptopsps
+----------------  = 
+gexpRadius        = smf [NOTE: the smf has Major, Minor, Theta, but errors on Sxx, Syy, Sxy
+gexpRadiusErr     = smf
+gexpFlux          = smf
+gexpFluxErr       = smf
+gexpAb            = smf
+gexpAbErr         = smf
+gexpPhi           = smf
+gexpPhiErr        = smf
+graExpOff         = smf (calculate from reported position vs psf position)
+gdecExpOff        = smf (calculate from reported position vs psf position)
+graExpOffErr      = smf
+gdecExpOffErr     = smf
+gexpCf            = [NOT currently calculated]
+gexpLikelihood    = ipptopsps
+----------------  = 
+gserRadius        = smf [NOTE: the smf has Major, Minor, Theta, but errors on Sxx, Syy, Sxy
+gserRadiusErr     = smf
+gserFlux          = smf
+gserFluxErr       = smf
+gserAb            = smf
+gserAbErr         = smf
+gserNu            = smf
+gserNuErr         = smf
+gserPhi           = smf
+gserPhiErr        = smf
+graSerOff         = smf (calculate from reported position vs psf position)
+gdecSerOff        = smf (calculate from reported position vs psf position)
+graSerOffErr      = smf
+gdecSerOffErr     = smf
+gserCf            = [NOT currently calculated]
+gserLikelihood    = ipptopsps
+----------------  = 
+gpetRadius        = smf
+gpetRadiusErr     = smf
+gpetFlux          = smf
+gpetFluxErr       = smf
+gpetR50           = smf
+gpetR50Err        = smf
+gpetR90           = smf
+gpetR90Err        = smf
+gpetCf            = smf
+----------------  = 
+gflxR1            = smf
+gflxR1Err         = smf
+gflxR1Std         = smf
+gflxR1Fill        = smf
+gflxR2            = smf
+gflxR2Err         = smf
+gflxR2Std         = smf
+gflxR2Fill        = smf
+gflxR3            = smf
+gflxR3Err         = smf
+gflxR3Std         = smf
+gflxR3Fill        = smf
+gflxR4            = smf
+gflxR4Err         = smf
+gflxR4Std         = smf
+gflxR4Fill        = smf
+gflxR5            = smf
+gflxR5Err         = smf
+gflxR5Std         = smf
+gflxR5Fill        = smf
+gflxR6            = smf
+gflxR6Err         = smf
+gflxR6Std         = smf
+gflxR6Fill        = smf
+gflxR7            = smf
+gflxR7Err         = smf
+gflxR7Std         = smf
+gflxR7Fill        = smf
+gflxR8            = smf
+gflxR8Err         = smf
+gflxR8Std         = smf
+gflxR8Fill        = smf
+gflxR9            = smf
+gflxR9Err         = smf
+gflxR9Std         = smf
+gflxR9Fill        = smf
+gflxR10           = smf
+gflxR10Err        = smf
+gflxR10Std        = smf
+gflxR10Fill       = smf
+----------------  = 
+gc1flxR1          = smf
+gc1flxR1Err       = smf
+gc1flxR1Std       = smf
+gc1flxR1Fill      = smf
+gc1flxR2          = smf
+gc1flxR2Err       = smf
+gc1flxR2Std       = smf
+gc1flxR2Fill      = smf
+gc1flxR3          = smf
+gc1flxR3Err       = smf
+gc1flxR3Std       = smf
+gc1flxR3Fill      = smf
+gc1flxR4          = smf
+gc1flxR4Err       = smf
+gc1flxR4Std       = smf
+gc1flxR4Fill      = smf
+gc1flxR5          = smf
+gc1flxR5Err       = smf
+gc1flxR5Std       = smf
+gc1flxR5Fill      = smf
+gc1flxR6          = smf
+gc1flxR6Err       = smf
+gc1flxR6Std       = smf
+gc1flxR6Fill      = smf
+gc1flxR7          = smf
+gc1flxR7Err       = smf
+gc1flxR7Std       = smf
+gc1flxR7Fill      = smf
+gc1flxR8          = smf
+gc1flxR8Err       = smf
+gc1flxR8Std       = smf
+gc1flxR8Fill      = smf
+gc1flxR9          = smf
+gc1flxR9Err       = smf
+gc1flxR9Std       = smf
+gc1flxR9Fill      = smf
+gc1flxR10         = smf
+gc1flxR10Err      = smf
+gc1flxR10Std      = smf
+gc1flxR10Fill     = smf
+gc2flxR1          = smf
+gc2flxR1Err       = smf
+gc2flxR1Std       = smf
+gc2flxR1Fill      = smf
+gc2flxR2          = smf
+gc2flxR2Err       = smf
+gc2flxR2Std       = smf
+gc2flxR2Fill      = smf
+gc2flxR3          = smf
+gc2flxR3Err       = smf
+gc2flxR3Std       = smf
+gc2flxR3Fill      = smf
+gc2flxR4          = smf
+gc2flxR4Err       = smf
+gc2flxR4Std       = smf
+gc2flxR4Fill      = smf
+gc2flxR5          = smf
+gc2flxR5Err       = smf
+gc2flxR5Std       = smf
+gc2flxR5Fill      = smf
+gc2flxR6          = smf
+gc2flxR6Err       = smf
+gc2flxR6Std       = smf
+gc2flxR6Fill      = smf
+gc2flxR7          = smf
+gc2flxR7Err       = smf
+gc2flxR7Std       = smf
+gc2flxR7Fill      = smf
+gc2flxR8          = smf
+gc2flxR8Err       = smf
+gc2flxR8Std       = smf
+gc2flxR8Fill      = smf
+gc2flxR9          = smf
+gc2flxR9Err       = smf
+gc2flxR9Std       = smf
+gc2flxR9Fill      = smf
+gc2flxR10         = smf
+gc2flxR10Err      = smf
+gc2flxR10Std      = smf
+gc2flxR10Fill     = smf
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackObject
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackObject	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackObject	(revision 37066)
@@ -0,0 +1,65 @@
+
+objID             dimensionless   BIGINT  8       NA      ODM object identifier
+gcObjID	  	  dimensionless	  BIGINT  8	  NA 	  ODM galactic coordinates identifier
+ippObjID          dimensionless   BIGINT  8       NA      object ID generated by IPP
+surveyID          dimensionless   TINYINT 1       NA      survey flag identifier
+skyCellID         dimensionless   REAL    4       -999    single float giving PrimaryCell.SkyCell identifier 
+randomStackObjID  dimensionless   BIGINT  8       NA      random stack id
+stackDetectRowID  dimensionless   BIGINT  8       NA      identifies which of up to 5 possible stackdetctions this Row refers to: Primary, up to 3 Secondary, 1 best  
+primaryDetection  dimensionless   TINYINT 1       255     identifies if this row is a primary stack detection. True about 80% of time. 
+bestDetection     dimensionless   TINYINT 1       255     identifies if this row is a best detection or not. Also set if only a primary detection exists.   
+                                                          the Primary Dectection, 0 to 3 possible secondary dectections, and the "best" per filter.  
+dvoRegionID       dimensionless   INT     4       -999    identifier to dvo spatial region
+dataRelease       dimensionless   TINYINT 1       NA      Data release when this detection was originally taken.
+------------------------------------------------------------------------------------------
+-- attributes for all stack detections in all filters (these are currently forced anyway) 
+-- Replicate the section below for each filter, changing the prefex ("g" in this example) 
+------------------------------------------------------------------------------------------
+gippDetectID      dimensionless   BIGINT  8       NA      detection ID generated by IPP
+gstackDetectID    dimensionless   BIGINT  8       NA      ODM detection identifier
+gstackMetaID      dimensionless   BIGINT  8       NA      stack identifier
+------------------------------------------------------------------------------------------
+gxPos             arcsec          REAL    4       -999    measured x in sky Cell from PSF fit
+gyPos             arcsec          REAL    4       -999    measured y in sky Cell from PSF fit
+gxPosErr          arcsec          REAL    4       -999    estimated error in x
+gyPosErr          arcsec          REAL    4       -999    estimated error in y
+gra               degrees         FLOAT   8       NA      Right Ascension   
+gdec              degrees         FLOAT   8       NA      Declination       
+graErr            arcsec          REAL    4       NA      Right Ascension error
+gdecErr           arcsec          REAL    4       NA      Declination error  (same as RA error - need?)
+gzp               magnitude       REAL    4       0       zeropoint , no error given 
+gexpTime          seconds         REAL    4       -999    total exposure time (informational)
+gpsfMajorFWHM     arcsec          REAL    4       -999    PSF width in major axis
+gpsfMinorFWHM     arcsec          REAL    4       -999    PSF width in minor axis
+gpsfTheta         degrees         REAL    4       -999    PSF orientation angle. Degrees East of North.
+gpsfCore          dimensionless   REAL    4       -999    PSF core parameter [k in (1 + kz + z^1.66)]
+gpsfLikelihood    dimensionless   REAL    4       -999    PSF likelihood
+gpsfQf            dimensionless   REAL    4       -999    PSF coverage factor
+gpsfQfPerfect     dimensionless   REAL    4       -999    PSF-weighted fraction of arcsec totally unmasked
+gpsfChiSq         dimensionless   REAL    4       -999    PSF-weighted fraction of arcsec to.
+gmomentXX         arcsec^2        REAL    4       -999    moment XX
+gmomentXY         arcsec^2        REAL    4       -999    moment XY
+gmomentYY         arcsec^2        REAL    4       -999    moment YY
+gmomentR1         arcsec          REAL    4       -999    moment R1
+gmomentRH         arcsec          REAL    4       -999    moment RH - or half light radius (REMOVE)
+gPSFFlux     	  adu/sec         REAL    4       -999    g psf flux from stack
+gPSFFluxErr  	  adu/sec         REAL    4       -999    estimated error of g psf flux from stack
+gApFlux           adu/seconds     REAL    4       -999    Aperture magnitude
+gApFluxErr        adu/seconds     REAL    4       -999    Aperture magnitude error
+gApFillFac        dimensionless   REAL    4       -999    Aperture fill factor - ~ redundant with psfQF, keep?
+gKronFlux         adu/seconds     REAL    4       -999    Kron flux
+gKronFluxErr      adu/seconds     REAL    4       -999    Kron flux error
+gKronRad          arcsec          REAL    4       -999    Kron radius
+gPSFMag      	  AB_magnitude    REAL    4       -999    g psf AB magnitude from stack
+gPSFMagErr   	  AB_magnitude    REAL    4       -999    estimated error of g psf AB magnitude from stack
+gApMag       	  AB_magnitude    REAL    4       -999    g Aperture AB magnitude from stack
+gApMagErr    	  AB_magnitude    REAL    4       -999    estimated error of g Ap Mag AB magnitude from stack
+gKronMag     	  AB_magnitude    REAL    4       -999    g kron AB magnitude from stack
+gKronMagErr  	  AB_magnitude    REAL    4       -999    estimated error of g kron AB magnitude from stack
+gsky              adu/secs/arcsec REAL    4       -999    PSF sky level at source (adu)
+gskyErr           adu/secs/arcsec REAL    4       -999    estimated error in sky
+ginfoFlag         dimensionless   INT     4       -999    indicator of strange propeties
+ginfoFlag2        dimensionless   INT     4       -999    indicator of strange propeties
+gnFrames          dimensionless   INT     4       -999    Number of frames contributing to source
+
+-- [220 byte/filter/obj + 44 byte/obj]
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackObject.txt
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackObject.txt	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackObject.txt	(revision 37066)
@@ -0,0 +1,66 @@
+		  
+objID              = dvo/addstar = average.extID
+gcObjID            = dvo/addstar [EAM: add to addstar, average.d]
+ippObjID           = dvo/addstar = average.objID + (average.catID << 32)
+surveyID           = ipptopsps
+skyCellID          = ipptopsps / smf header
+randomStackObjID   = ipptopsps
+stackDetectRowID   = PSPS ?
+primaryDetection   = dvo 
+bestDetection      = dvo ?
+                   = 
+dvoRegionID        = dvo / catID
+dataRelease        = ippToPsps
+------------------ = 
+-- attributes for  = 
+-- Replicate the s = 
+------------------ = 
+gippDetectID       = dvopsps.ippDetectID = dvo.measure.detID = smf / IPP_IDET
+gstackDetectID     = dvopsps.detectID = dvo:measure.extID (addstar psps stack detect ID)
+gstackMetaID       = smf header 
+------------------ = 
+gxPos              = smf
+gyPos              = smf
+gxPosErr           = smf
+gyPosErr           = smf
+gra                = smf or relastro? (Ken?)
+gdec               = smf or relastro?
+graErr             = smf or relastro?
+gdecErr            = smf or relastro?
+gzp                = dvo / relphot
+gexpTime           = smf [see Detection.txt]
+gpsfMajorFWHM      = smf [see Detection.txt]
+gpsfMinorFWHM      = smf [see Detection.txt]
+gpsfTheta          = smf [see Detection.txt]
+gpsfCore           = smf [see Detection.txt]
+gpsfLikelihood     = ipptopsps
+gpsfQf             = smf
+gpsfQfPerfect      = smf
+gpsfChiSq          = smf
+gmomentXX          = smf
+gmomentXY          = smf
+gmomentYY          = smf
+gmomentR1          = smf
+gmomentRH          = smf [XXX : MOMENTS_RH is NOT half-light radius]
+gPSFFlux     	   = smf
+gPSFFluxErr  	   = smf
+gApFlux            = smf
+gApFluxErr         = smf
+gApFillFac         = smf [EAM: add to smf output]
+gKronFlux          = smf
+gKronFluxErr       = smf
+gKronRad           = (2.5 * R1) [drop from schema]
+gPSFMag      	   = smf
+gPSFMagErr   	   = smf
+gApMag       	   = smf
+gApMagErr    	   = smf
+gKronMag     	   = smf (calculated)
+gKronMagErr  	   = smf (calculated)
+gsky               = smf
+gskyErr            = smf
+ginfoFlag          = smf
+ginfoFlag2         = smf
+gnFrames           = smf
+
+[NOTE: for stacks, dvo only needs to determine the 
+       primary measurement (and modified zero point?).
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/changes.r36847
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/changes.r36847	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/changes.r36847	(revision 37066)
@@ -0,0 +1,199 @@
+Index: Detection
+===================================================================
+--- Detection	(revision 36838)
++++ Detection	(working copy)
+@@ -7,7 +7,7 @@
+ surveyID        dimensionless   TINYINT 1         NA    survey flag identifier
+ imageID         dimensionless   BIGINT  8         NA    image id hash of frame identifier & OTA/CCD number
+ randomDetID     dimensionless   BIGINT  8         NA    random detection Id
+-dvoRegionID     dimensionless   REAL    4       -999    identifier to dvo spatial region
++dvoRegionID     dimensionless   INT     4          0    identifier to dvo spatial region
+ obsTime         MeanJulianDays  FLOAT   8       -999    Time of mid observation in Mean Julian Days
+ xPos            raw pixels      REAL    4       -999    measured x on CCD from PSF fit
+ yPos            raw pixels      REAL    4       -999    measured y on CCD from PSF fit
+@@ -53,7 +53,8 @@
+ kronRadErr      arcsec      	REAL    4       -999    Kron radius error
+ sky             adu/sec/pixel   REAL    4       -999    PSF sky level at source
+ skyErr          adu/sec/pixel   REAL    4       -999    estimated error in sky
+-infoFlag        dimensionless   BIGINT  8       -999    flag indicating provenance information
++infoFlag        dimensionless   INT     4       -999    flag indicating provenance information
++infoFlag2       dimensionless   INT     4       -999    flag indicating provenance information
+ dataRelease     dimensionless   TINYINT 1         NA    Data release when this detection was originally taken. Recalibrations do not affect this value.
+ --
+ -- [231 bytes/det]
+Index: StackApFlx
+===================================================================
+--- StackApFlx	(revision 36838)
++++ StackApFlx	(working copy)
+@@ -1,6 +1,7 @@
+ 
+ objID            dimensionless  BIGINT  8       NA      ODM object identifier
+ gcObjID		dimensionless	BIGINT	8	  NA 	ODM galactic coordinates identifier
++ippObjID         dimensionless  BIGINT  8       NA      ipp object identifier
+ surveyID         dimensionless  TINYINT 1       0       stack type identifier
+ skyCellID        dimensionless  REAL    4       -999    single float giving PrimaryCell.SkyCell identifier 
+ randomStackObjID dimensionless  BIGINT  8       NA      random stack id
+@@ -8,13 +9,12 @@
+ primaryDetection dimensionless  TINYINT 1       255     identifies if this row is a primary stack detection. True about 80% of time. 
+ bestDetection    dimensionless  TINYINT 1       255     identifies if this row is a best detection or not. Also set if only a primary detection exists.   
+ --                                                      the Primary Dectection, 0 to 3 possible secondary dectections, and the "best" per filter.  
+-dvoRegionID      dimensionless  REAL    4       -999    identifier to dvo spatial region
++dvoRegionID     dimensionless   INT    4       -999    identifier to dvo spatial region
+ dataRelease     dimensionless   TINYINT 1       NA      Data release when this table was loaded.
+ ------------------------------------------------------- replicate to end for each filter g,r,i,z,y
++gippDetectID    dimensionless   BIGINT  8       NA      stack identifier
+ gstackDetectID  dimensionless   BIGINT  8       NA      ODM detection identifier
+ gstackMetaID    dimensionless   BIGINT  8       NA      stack identifier
+-gippObjID        dimensionless  BIGINT  8       NA      ipp object identifier
+-gippDetectID    dimensionless   BIGINT  8       NA      stack identifier
+ --------------------------------------------------------unconvolved
+ gflxR3          adu/seconds     REAL    4       -999    Flux inside r = 3
+ gflxR3Err       adu/seconds     REAL    4       -999    estimated error is flxR3
+Index: ForcedWarpMeasurement
+===================================================================
+--- ForcedWarpMeasurement	(revision 36838)
++++ ForcedWarpMeasurement	(working copy)
+@@ -8,7 +8,7 @@
+ forcedWarpID    dimensionless   BIGINT  8       NA      IPP warp_id
+ randomWarpID    dimensionless   BIGINT  8       NA      Random warp_id
+ skyCellID       dimensionless   REAL    4       -999    single float giving PrimaryCell.SkyCell identifier 
+-dvoRegionID     dimensionless   REAL    4       -999    identifier to dvo spatial region
++dvoRegionID     dimensionless   INT     4       -999    identifier to dvo spatial region
+ obsTime         MeanJulianDays  FLOAT   8       -999    Time of mid observation in Mean Julian Days
+ ------------------------------------------------------ 
+ zp              magnitude       REAL    4       0       zeropoint (only thing needed to convert adu/sec to AB mag), note no zpErr
+Index: DiffDetection
+===================================================================
+--- DiffDetection	(revision 36838)
++++ DiffDetection	(working copy)
+@@ -1,3 +1,4 @@
++
+ diffObjID	dimensionless 	BIGINT 	8 	NA 	diff object identifier
+ diffgcObjID		dimensionless	BIGINT	8	  NA 	ODM galactic coordinates identifier
+ diffDetID 	dimensionless 	BIGINT 	8 	NA 	diff detection identifier
+@@ -8,7 +9,7 @@
+ surveyID 	dimensionless 	TINYINT	1 	NA 	survey flag identifierr
+ randomDiffID 	dimensionless 	BIGINT 	8 	NA 	random diff id  
+ skyCellID       dimensionless   REAL    4       -999    single float giving PrimaryCell.SkyCell identifier 
+-dvoRegionID     dimensionless   REAL    4       -999    identifier to dvo spatial region
++dvoRegionID     dimensionless   INT     4          0    identifier to dvo spatial region
+ obsTime 	MeanJulianDays 	FLOAT 	8 	-999 	Time of mid observation of positive detection in Mean Julian Days of positive detection
+ xPos 		pixels 		REAL 	4 	-999 	measured x on diff image sky cell PSF fit
+ yPos 		pixels 		REAL 	4 	-999 	measured y on diff image sky cell from PSF fit
+@@ -65,5 +66,6 @@
+ -------------------------------------------------------
+ sky 		adu/sec/pixel 	REAL 	4 	-999 	PSF sky level at source
+ skyErr 		adu/sec/pixel 	REAL 	4 	-999 	estimated error in sky
+-infoFlag 	dimensionless 	BIGINT 	8 	-999 	flag indicating provenance information
++infoFlag 	dimensionless 	INT     4 	-999 	flag indicating provenance information
++infoFlag2	dimensionless 	INT     4 	-999 	flag indicating provenance information
+ dataRelease 	dimensionless 	TINYINT	1 	NA 	Data release when this detection was originally taken. Recalibrations do not affect this value.
+Index: ObjectThin
+===================================================================
+--- ObjectThin	(revision 36838)
++++ ObjectThin	(working copy)
+@@ -9,7 +9,7 @@
+ zoneID           dimensionless  INT      4      NA      Zone index
+ randomID         dimensionless  BIGINT   8      0       Random integer between 0 and 2^32 = 4,394,967,296 remaining ramdom integer 0  
+ batchID          dimensionless  BIGINT   8      -999    batch id        
+-dvoRegionID      dimensionless  REAL     4      -999    identifier of dvo spatial region - dvo cat id
++dvoRegionID      dimensionless  INT      4      -999    identifier of dvo spatial region - dvo cat id
+ dataRelease      dimensionless  TINYINT  1      NA      Data release Version of this table
+ objInfoFlag      dimensionless  BIGINT   8      -999    flag indicating odd properties
+ qualityFlag      dimensionless  TINYINT  1      0       subset of objInfoFlag - flags related to goodness of object
+Index: StackModelFit
+===================================================================
+--- StackModelFit	(revision 36838)
++++ StackModelFit	(working copy)
+@@ -1,6 +1,7 @@
+ 
+ objID            dimensionless  BIGINT  8       NA      ODM object identifier
+ gcObjID		dimensionless	BIGINT	8	  NA 	ODM galactic coordinates identifier
++ippObjID         dimensionless  BIGINT  8       NA      ipp object identifier
+ surveyID         dimensionless  TINYINT 1       NA      survey flag identifier
+ skyCellID        dimensionless  REAL    4       -999    single float giving PrimaryCell.SkyCell identifier 
+ randomStackObjID dimensionless  BIGINT  8       NA      random stack id
+@@ -8,17 +9,17 @@
+ primaryDetection dimensionless  TINYINT 1       255     identifies if this row is a primary stack detection. True about 80% of time. 
+ bestDetection    dimensionless  TINYINT 1       255     identifies if this row is a best detection or not. Also set if only a primary detection exists.   
+ --                                                      the Primary Dectection, 0 to 3 possible secondary dectections, and the "best" per filter.  
+-dvoRegionID      dimensionless  REAL    4       -999    identifier to dvo spatial region
++dvoRegionID      dimensionless  INT     4       -999    identifier to dvo spatial region
+ dataRelease      dimensionless  TINYINT 1       NA      Data release when this table was loaded
+ -------------------------------------------------------- replicate below for all filters (grizy)
+ glogC           dimensionless   REAL    4       -999    concentration index 
+ glogA           dimensionless   REAL    4       -999    asymmetry index
+ gclump          dimensionless   REAL    4       -999    clumpiness factor   
+ -------------------------------------------------------- replicate below for all filters (grizy)
++gippDetectID    dimensionless   BIGINT  8       NA      ipp detect identifier
+ gstackDetectID  dimensionless   BIGINT  8       NA      ODM detection identifier
+ gstackMetaID    dimensionless   BIGINT  8       NA      stack identifier
+-gippObjID       dimensionless  BIGINT  8       NA      ipp object identifier
+-gippDetectID    dimensionless   BIGINT  8       NA      ipp detect identifier
++----------------------------------------------------------------------------------------
+ gdeVRadius      arcsec          REAL    4       -999    deVaucouleurs radius
+ gdeVRadiusErr   arcsec          REAL    4       -999    estimated error in deVaucouleurs radius
+ gdeVFlux        adu/seconds     REAL    4       -999    deVaucouleurs flux
+Index: ForcedMeanObject
+===================================================================
+--- ForcedMeanObject	(revision 36838)
++++ ForcedMeanObject	(working copy)
+@@ -1,3 +1,4 @@
++
+ objID           dimensionless   BIGINT   8        NA    ODM object identifier index
+ gcObjID		dimensionless	BIGINT	8	  NA 	ODM galactic coordinates identifier
+ ippObjID        dimensionless   BIGINT   8        NA    IPP object identifier
+Index: DiffDetObject
+===================================================================
+--- DiffDetObject	(revision 36838)
++++ DiffDetObject	(working copy)
+@@ -9,7 +9,7 @@
+ zoneID 		dimensionless 	INT 	4 	NA 	Zone index
+ randomID 	dimensionless 	BIGINT 	8 	0 	Random integer between 0 and 2^32 = 4,394,967,296 remaining ramdom integer 0  
+ batchID 	dimensionless	BIGINT 	8 	-999 	
+-dvoRegionID     dimensionless  	REAL    4       -999    identifier to dvo spatial region
++dvoRegionID     dimensionless  	INT     4       -999    identifier to dvo spatial region
+ objInfoFlag 	dimensionless 	BIGINT 	8 	-999 	flag indicating odd properties
+ qualityFlag 	dimensionless 	TINYINT 1 	0 	subset of objInfoFlag - flags related to goodness of object
+ consistencyFlag	dimensionless 	SMALLINT2 	0 	Value computed from associated detections, it is originally given by IPP and should agree with the ODM validation
+Index: StackObject
+===================================================================
+--- StackObject	(revision 36838)
++++ StackObject	(working copy)
+@@ -1,6 +1,7 @@
+ 
+ objID             dimensionless   BIGINT  8       NA      ODM object identifier
+ gcObjID		dimensionless	BIGINT	8	  NA 	ODM galactic coordinates identifier
++ippObjID          dimensionless   BIGINT  8       NA      object ID generated by IPP
+ surveyID          dimensionless   TINYINT 1       NA      survey flag identifier
+ skyCellID         dimensionless   REAL    4       -999    single float giving PrimaryCell.SkyCell identifier 
+ randomStackObjID  dimensionless   BIGINT  8       NA      random stack id
+@@ -8,16 +9,16 @@
+ primaryDetection  dimensionless   TINYINT 1       255     identifies if this row is a primary stack detection. True about 80% of time. 
+ bestDetection     dimensionless   TINYINT 1       255     identifies if this row is a best detection or not. Also set if only a primary detection exists.   
+                                                           the Primary Dectection, 0 to 3 possible secondary dectections, and the "best" per filter.  
+-dvoRegionID       dimensionless   REAL    4       -999    identifier to dvo spatial region
++dvoRegionID       dimensionless   INT     4       -999    identifier to dvo spatial region
+ dataRelease       dimensionless   TINYINT 1       NA      Data release when this detection was originally taken.
+ ------------------------------------------------------------------------------------------
+ -- attributes for all stack detections in all filters (these are currently forced anyway) 
+ -- Replicate the section below for each filter, changing the prefex ("g" in this example) 
+ ------------------------------------------------------------------------------------------
+-gippObjID         dimensionless   BIGINT  8       NA      object ID generated by IPP
+ gippDetectID      dimensionless   BIGINT  8       NA      detection ID generated by IPP
+ gstackDetectID    dimensionless   BIGINT  8       NA      ODM detection identifier
+ gstackMetaID      dimensionless   BIGINT  8       NA      stack identifier
++------------------------------------------------------------------------------------------
+ gxPos             arcsec          REAL    4       -999    measured x in sky Cell from PSF fit
+ gyPos             arcsec          REAL    4       -999    measured y in sky Cell from PSF fit
+ gxPosErr          arcsec          REAL    4       -999    estimated error in x
+@@ -57,7 +58,8 @@
+ gKronMagErr  	  AB magnitude    REAL    4       -999    estimated error of g kron AB magnitude from stack
+ gsky              adu/secs/arcsec REAL    4       -999    PSF sky level at source (adu)
+ gskyErr           adu/secs/arcsec REAL    4       -999    estimated error in sky
+-ginfoFlag         dimensionless   BIGINT  8       -999    indicator of strange propeties
++ginfoFlag         dimensionless   INT     4       -999    indicator of strange propeties
++ginfoFlag2        dimensionless   INT     4       -999    indicator of strange propeties
+ gnFrames          dimensionless   INT     4       -999    Number of frames contributing to source
+ 
+ -- [220 byte/filter/obj + 44 byte/obj]
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/CameraConfig
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/CameraConfig	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/CameraConfig	(revision 37066)
@@ -0,0 +1,12 @@
+CameraConfig
+Description: Camera configuration
+
+Name      	Unit		        DataType    Size	Default		ValueDescription 
+
+cameraID  	dimensionless   	SMALLINT 	2 	   -999         camera identifier (i.e. GPC1, ISP)
+cameraConfigID  dimensionless           SMALLINT        2          -999         camera configuration
+endDate         dimensionless               REAL        4          -999         ending date of this configuration in MJD
+configDetails   string           VARCHAR(MAX) 8000      0x00         NA         text/table giving the details of the camera configuration
+                                                                                NEED TO CHANGE and pass camera x from raw data file
+
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/DetectionFlags
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/DetectionFlags	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/DetectionFlags	(revision 37066)
@@ -0,0 +1,10 @@
+DetectionFlags
+
+Description: Flags used to interpret the information flag provided
+with each detection (infoFlag in 'Detection' table)
+
+Name Unit Data Type Size Default Value Description
+
+name 		VARCHAR(32) 	32	NA 	Name of flag 
+value 		BIGINT 		8 	NA 	Flag value
+description     VARCHAR(2000) 2000      NA      Description of the flag
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/DiffMeta
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/DiffMeta	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/DiffMeta	(revision 37066)
@@ -0,0 +1,26 @@
+diffMetaID   dimensionless   BIGINT 8 NA diff  identifier
+batchID      dimensionless   BIGINT 8 NA batch  identifier
+surveyID     dimensionless   TINYINT 1 NA survey flag identifier
+filterID     dimensionless   TINYINT 1 NA filter id 
+diffTypeID   dimensionless   TINYINT 1 0 diff type identifier
+posImageID   dimensionless   BIGINT 8 NA positive image identifier
+negImageID   dimensionless   BIGINT 8 NA negative image identifier
+skyCellID    dimensionless   REAL 4 NA skycell region identifier 
+photoCalID   dimensionless   INT 4 NA photometry code
+magSat       dimensionless   REAL 4 -999 saturation magnitude level
+analVer      dimensionless   SMALLINT 2 -999 analysis version index
+expTime      seconds         REAL 4 -999 exposure time of positive image
+ctype1       alphanumeric   VARCHAR(MAX) 8000 name of astrometric projection in RA
+ctype2       alphanumeric   VARCHAR(MAX) 8000 name of astrometric projection in DEC
+crval1       degrees        FLOAT 8 -999 RA corresponding to reference pixel
+crval2       degrees        FLOAT 8 -999 DEC corresponding to reference pixel
+crpix1       dimensionless  FLOAT 8 -999 reference pixel value for RA
+crpix2       dimensionless  FLOAT 8 -999 reference pixel value for DEC
+cdelt1       deg/pixel      FLOAT 8 -999 scale factor for RA
+cdelt2       deg/pixel      FLOAT 8 -999 scale factor for DEC
+pc001001     dimensionless  FLOAT 8 -999 elements of rotation/Dcale matrix 
+pc001002     dimensionless  FLOAT 8 -999 elements of rotation/Dcale matrix
+pc002001     dimensionless  FLOAT 8 -999 elements of rotation/Dcale matrix
+pc002002     dimensionless  FLOAT 8 -999 elements of rotation/Dcale matrix
+calibModNum  dimensionless  SMALLINT 2 NA calibration modification number
+dataRelease  dimensionless  TINYINT 1 NA Data release
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/DiffToImage
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/DiffToImage	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/DiffToImage	(revision 37066)
@@ -0,0 +1,2 @@
+diffMetaID 	BIGINT 	8 	NA 	diff identifier
+imageID 	BIGINT 	8 	NA 	hashed exposure-ccdID identifier
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/Filter
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/Filter	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/Filter	(revision 37066)
@@ -0,0 +1,3 @@
+FilterID dimensionless TINYNT 1 NA filter ID: g=1, r=2, i=3, z=4, y=5, w=6, ...
+filterType VARCHAR(2) 2 NA filter name: g,r,i,z,y, etc.
+filterSpec VARCHAR(MAX) 8000 0x00 No comment
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/FitModel
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/FitModel	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/FitModel	(revision 37066)
@@ -0,0 +1,42 @@
+fitModelID		SMALLINT	2	NA	indentifier of alternate model fit
+name		VARCHAR(30)	30		model name
+description		VARCHAR(MAX)	8000		string describing the model
+param1		VARCHAR(MAX)	8000		description of model parameter 1
+param2		VARCHAR(MAX)	8000		description of model parameter 2
+param3		VARCHAR(MAX)	8000		description of model parameter 3
+param4		VARCHAR(MAX)	8000		description of model parameter 4
+param5		VARCHAR(MAX)	8000		description of model parameter 5
+param6		VARCHAR(MAX)	8000		description of model parameter 6
+param7		VARCHAR(MAX)	8000		description of model parameter 7
+param8		VARCHAR(MAX)	8000		description of model parameter 8
+param9		VARCHAR(MAX)	8000		description of model parameter 9
+param10		VARCHAR(MAX)	8000		description of model parameter 10
+param11		VARCHAR(MAX)	8000		description of model parameter 11
+param12		VARCHAR(MAX)	8000		description of model parameter 12
+param13		VARCHAR(MAX)	8000		description of model parameter 13
+param14		VARCHAR(MAX)	8000		description of model parameter 14
+param15		VARCHAR(MAX)	8000		description of model parameter 15
+param16		VARCHAR(MAX)	8000		description of model parameter 16
+param17		VARCHAR(MAX)	8000		description of model parameter 17
+param18		VARCHAR(MAX)	8000		description of model parameter 18
+param19		VARCHAR(MAX)	8000		description of model parameter 19
+param20		VARCHAR(MAX)	8000		description of model parameter 20
+param21		VARCHAR(MAX)	8000		description of model parameter 21
+param22		VARCHAR(MAX)	8000		description of model parameter 22
+param23		VARCHAR(MAX)	8000		description of model parameter 23
+param24		VARCHAR(MAX)	8000		description of model parameter 24
+param25		VARCHAR(MAX)	8000		description of model parameter 25
+param26		VARCHAR(MAX)	8000		description of model parameter 26
+param27		VARCHAR(MAX)	8000		description of model parameter 27
+param28		VARCHAR(MAX)	8000		description of model parameter 28
+param29		VARCHAR(MAX)	8000		description of model parameter 29
+param30		VARCHAR(MAX)	8000		description of model parameter 30
+param31		VARCHAR(MAX)	8000		description of model parameter 31
+param32		VARCHAR(MAX)	8000		description of model parameter 32
+param33		VARCHAR(MAX)	8000		description of model parameter 33
+param34		VARCHAR(MAX)	8000		description of model parameter 34
+param35		VARCHAR(MAX)	8000		description of model parameter 35
+param36		VARCHAR(MAX)	8000		description of model parameter 36
+param37		VARCHAR(MAX)	8000		description of model parameter 37
+param38		VARCHAR(MAX)	8000		description of model parameter 38
+param39		VARCHAR(MAX)	8000		description of model parameter 39
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/ForcedWarpMeta
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/ForcedWarpMeta	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/ForcedWarpMeta	(revision 37066)
@@ -0,0 +1,33 @@
+forcedWarpID dimensionless   BIGINT 8 NA stack identifier
+batchID          dimensionless   BIGINT 8 NA batch identifier
+surveyID         dimensionless   TINYINT 1 NA survey flag identifier
+filterID         dimensionless   TINYINT 1 NA fnilutemr eidriecnatl ifidier
+skyCellID        dimensionless   REAL 4 NA skycell region identifier 
+photoCalID       dimensionless   INT 4 NA photometry code
+magSat           dimensionless   REAL 4 -999 saturation magnitude level
+analVer          dimensionless   SMALLINT 2 -999 analysis version index
+expTime          seconds         REAL 4 -999 exposure time
+completMag       magnitudes      REAL 4 -999 95% completion level in mag
+astroScat        dimensionless   REAL 4 -999 astrometric scatter for chip
+photoScat        dimensionless   REAL 4 -999 photometric scatter for chip
+nAstroRef        dimensionless   INT 4 -999 number of astrometric reference sources
+nPhoRef          dimensionless   INT 4 -999 number of photometric reference sources
+psfModelID       dimensionless   VARCHAR(MAX) 8000 PSF model identifier
+psfFwhm_mean     arcsec         FLOAT 8 -999 mean PSF FWHM in the stack
+psfFwhm_max      arcsec         FLOAT 8 -999 maximum PSF FWHM in the stack 
+photoZero        magnitudes     REAL 4 -999 local derived photometric zero point
+photoColor       magnitudes     REAL 4 -999 local derived photometric color term
+ctype1           alphanumeric   VARCHAR(MAX) 8000 name of astrometric projection in RA
+ctype2           alphanumeric   VARCHAR(MAX) 8000 name of astrometric projection in DEC
+crval1           degrees        FLOAT 8 -999 RA corresponding to reference pixel
+crval2           degrees        FLOAT 8 -999 DEC corresponding to reference pixel
+crpix1           dimensionless  FLOAT 8 -999 reference pixel value for RA
+crpix2           dimensionless  FLOAT 8 -999 reference pixel value for DEC
+cdelt1           deg/pixel      FLOAT 8 -999 scale factor for RA
+cdelt2           deg/pixel      FLOAT 8 -999 scale factor for DEC
+pc001001         dimensionless  FLOAT 8 -999 elements of rotation/Dcale matrix 
+pc001002         dimensionless  FLOAT 8 -999 elements of rotation/Dcale matrix
+pc002001         dimensionless  FLOAT 8 -999 elements of rotation/Dcale matrix
+pc002002         dimensionless  FLOAT 8 -999 elements of rotation/Dcale matrix
+calibModNum      dimensionless  SMALLINT 2 NA calibration modification number
+dataRelease      dimensionless  TINYINT 1 NA Data release
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/ForcedWarpToImage
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/ForcedWarpToImage	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/ForcedWarpToImage	(revision 37066)
@@ -0,0 +1,2 @@
+forcedWarpID 	BIGINT 	8 	NA 	forced warp identifier
+imageID 		BIGINT 	8 	NA 	hashed exposure-ccdID identifier
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/FrameMeta
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/FrameMeta	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/FrameMeta	(revision 37066)
@@ -0,0 +1,49 @@
+frameID	dimensionless	INT	4	NA	unique exposure/frame identifier.
+frameName	dimensionless	VARCHAR(32)	32	NA	frame name provided by camera software
+surveyID	dimensionless	TINYINT	1	NA	survey flag identifier
+filterID	dimensionless	TINYINT	1	NA	filter identifier
+cameraID	dimensionless	SMALLINT	2	NA	camera identifier
+cameraConfigID	dimensionless	SMALLINT	2	NA	camera configuration identifier
+telescopeID	dimensionless	SMALLINT	2	NA	telescope identifier
+analysisVer	alphanumeric	VARCHAR(MAX)	8000		IPP software analysis release
+p1Recip	alphanumeric	VARCHAR(MAX)	8000		IPP phase 1 MD5 Checksum
+p2Recip	alphanumeric	VARCHAR(MAX)	8000		IPP phase 2 MD5 Checksum
+p3Recip	alphanumeric	VARCHAR(MAX)	8000		IPP phase 3 MD5 Checksum
+nOTA	alphanumeric	SMALLINT	2	-999	number of valid OTA/CCD images in this exposure
+photoScat	magnitude	REAL	4	-999	global photometric scatter
+numPhotoRef	dimensionless	INT	4	-999	number of photometric reference sources
+expStart	days	FLOAT	8	-999	exposure start time in MJD
+expTime	seconds	REAL	4	-999	exposure time
+airmass	dimensionless	REAL	4	-999	airmass at mid-exposure
+raBore	degrees	FLOAT	8	-999	RA of telescope boresight
+decBore	degrees	FLOAT	8	-999	DEC of telescope boresight
+ctype1	alphanumeric	VARCHAR(MAX)	8000		name of astrometric projection in RA
+ctype2		VARCHAR(MAX)	8000		name of astrometric projection in DEC
+crval1	degrees	FLOAT	8	-999	RA corresponding to reference pixel
+crval2	degrees	FLOAT	8	-999	DEC corresponding to reference pixel
+crpix1	pc001001	FLOAT	8	-999	reference pixel value for RA
+crpix2	dimensionless	FLOAT	8	-999	reference pixel value for DEC
+cdelt1	degrees/pixel	FLOAT	8	-999	scale factor for RA
+cdelt2	degrees/pixel	FLOAT	8	-999	scale factor for DEC
+pc001001	dimensionless	FLOAT	8	-999	elements of rotation/Dcale matrix
+pc001002	dimensionless	FLOAT	8	-999	elements of rotation/Dcale matrix
+pc002001	dimensionless	FLOAT	8	-999	elements of rotation/Dcale matrix
+pc002002	dimensionless	FLOAT	8	-999	elements of rotation/Dcale matrix
+polyOrder	dimensionless	TINYINT	1	255	polynomial order of astrometry fit
+pca1x3y0	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca1x2y1	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca1x1y2	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca1x0y3	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca1x2y0	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca1x1y1	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca1x0y2	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca2x3y0	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca2x2y1	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca2x1y2	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca2x0y3	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca2x2y0	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca2x1y1	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca2x0y2	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+calibModNum	dimensionless	SMALLINT	2	NA	calibration modification number
+batchID 	dimensionless	BIGINT	8	NA	batch ID 
+dataRelease	dimensionless	TINYINT	1	NA	Data release Version of this table
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/ImageFlags
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/ImageFlags	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/ImageFlags	(revision 37066)
@@ -0,0 +1,3 @@
+name VARCHAR(32) 32 NA Name of flag
+value BIGINT 8 NA Flag value
+description VARCHAR(2000) 2000 Description of the flag
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/ImageMeta
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/ImageMeta	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/ImageMeta	(revision 37066)
@@ -0,0 +1,74 @@
+imageID		dimensionless	BIGINT	8	NA	unique ID for each image, hashed from frameID and ccdID 
+frameID		dimensionless	INT	4	NA	frame identifier, also known as exposure number
+ccdID		dimensionless	SMALLINT	2	NA	ccd cell identifier in the focal plane
+photoCalID      dimensionless	INT	4	NA	photometry reduction code identifier
+filterID	dimensionless	TINYINT	1	NA	filter ID
+bias		ADU		REAL	4	-999	detector bias level
+biasScat	ADU		REAL	4	-999	scatter in bias level
+sky		ADU/pixel	REAL	4	-999	mean sky level
+skyScat		ADU/pixel	REAL	4	-999	scatter in mean sky level
+nDetect		dimensionless	INT	4	-999	number of detections on CCD
+magSat		magnitude	REAL	4	-999	saturation magnitude level
+completMag	magnitude	REAL	4	-999	95% completion level in mag
+astroScat	arcsec		REAL	4	-999	astrometric scatter for chip
+photoScat	magitude	REAL	4	-999	photometric scatter for chip
+numAstroRef	dimensionless	INT	4	-999	number of astrometric reference sources
+numPhotoRef	dimensionless	INT	4	-999	number of photometric reference sources
+nx		pixels		SMALLINT	2	-999	chip dimension in x
+ny		pixels		SMALLINT	2	-999	chip dimension in y
+psfModelID	dimensionless	INT	4	-999	PSF model identifier
+psfFwhm		arcsec		REAL	4	-999	model psf full width at half maximum at chip center
+psfWidMajor	arcsec		REAL	4	-999	model PSF parameters at chip center
+psfWidMinor	arcsec		REAL	4	-999	model PSF parameters at chip center
+psfTheta	degrees		REAL	4	-999	model PSF parameters at chip center
+momentXX        pixels  	REAL    4       -999    moment XX
+momentXY        pixels  	REAL    4       -999    moment XY
+momentYY        pixels  	REAL    4       -999    moment YY
+momentM3C       pixels squared  REAL    4       -999    moment M3C
+momentM3S       pixels squared  REAL    4       -999    moment M3S
+momentM4C       pixels squared  REAL    4       -999    moment M4C
+momentM4S       pixels squared  REAL    4       -999    moment M4S
+momentR1        pixels  	REAL    4       -999    moment R1
+momentRH        sqrt pixels     REAL    4       -999    moment RH
+apResid		magnitide	REAL	4	-999	corrected aperture residual
+dapResid	magnitide	REAL	4	-999	scatter of aperture corrections
+detectorID	alphanumeric	VARCHAR(32)	32		identifier for actual CCD chip
+qaFlags		dimensionless	BIGINT	8	-999	Q/A flags for this OTA
+detrend1	alphanumeric	VARCHAR(MAX)	8000		identifier of detrend image 1
+detrend2	alphanumeric	VARCHAR(MAX)	8000		identifier of detrend image 2
+detrend3	alphanumeric	VARCHAR(MAX)	8000		identifier of detrend image 3
+detrend4	alphanumeric	VARCHAR(MAX)	8000		identifier of detrend image 4
+detrend5	alphanumeric	VARCHAR(MAX)	8000		identifier of detrend image 5
+detrend6	alphanumeric	VARCHAR(MAX)	8000		identifier of detrend image 6
+detrend7	alphanumeric	VARCHAR(MAX)	8000		identifier of detrend image 7
+detrend8	alphanumeric	VARCHAR(MAX)	8000		identifier of detrend image 8
+photoZero	magnitude	REAL	4	-999	local derived photometric zero point
+ctype1		alphanumeric	VARCHAR(MAX)	8000		name of astrometric projection in RA
+ctype2		alphanumeric	VARCHAR(MAX)	8000		name of astrometric projection in DEC
+crval1		degrees	FLOAT	8	-999	RA corresponding to reference pixel
+crval2		degrees	FLOAT	8	-999	DEC corresponding to reference pixel
+crpix1		pixels	FLOAT	8	-999	reference pixel value for RA
+crpix2		pixels	FLOAT	8	-999	reference pixel value for DEC
+cdelt1		degrees/pixel	FLOAT	8	-999	scale factor for RA
+cdelt2		degrees/pixel	FLOAT	8	-999	scale factor for DEC
+pc001001	unknown	FLOAT	8	-999	elements of rotation/Dcale matrix
+pc001002	unknown	FLOAT	8	-999	elements of rotation/Dcale matrix
+pc002001	unknown	FLOAT	8	-999	elements of rotation/Dcale matrix
+pc002002	unknown	FLOAT	8	-999	elements of rotation/Dcale matrix
+polyOrder	dimensionless	TINYINT	1	255	polynomial order of astrometry fit
+pca1x3y0	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca1x2y1	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca1x1y2	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca1x0y3	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca1x2y0	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca1x1y1	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca1x0y2	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca2x3y0	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca2x2y1	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca2x1y2	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca2x0y3	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca2x2y0	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca2x1y1	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca2x0y2	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+calibModNum	dimensionless	SMALLINT	2	NA	calibration modification number
+dataRelease	dimensionless	TINYINT	1	NA	Data release Version of this table
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/Mask
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/Mask	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/Mask	(revision 37066)
@@ -0,0 +1,9 @@
+maskID BIGINT 8 NA mask identifier
+partitionKey BIGINT 8 NA fget(mask_center_ra, mask_center_dec, zoneH)
+frameID INT 4 NA reference to the P2FrameMeta table where the mask is defined
+imageID BIGINT 8 NA reference to the P2FrameMeta table where the mask is
+ra FLOAT 8 NA rdae finin ethde center
+dec FLOAT 8 NA dec in the center
+radius FLOAT 8 NA No comment
+maskString VARCHAR(MAX) 8000 string representation fo the mask region
+maskBinary VARBINARY(MAX) 8000 0x Binary object managed by the spatial library
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/MovingObjToDet
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/MovingObjToDet	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/MovingObjToDet	(revision 37066)
@@ -0,0 +1,2 @@
+MovingObjID  	BIGINT 	8 	NA 	Moving Object identifier  
+DetectionID 	BIGINT 	8 	NA 	detection identifier  
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/MovingObjToDiffDet
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/MovingObjToDiffDet	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/MovingObjToDiffDet	(revision 37066)
@@ -0,0 +1,2 @@
+MovingObjID  	BIGINT 	8 	NA 	Moving Object identifier  
+DiffDetID 	BIGINT 	8 	NA 	difference image detection identifier  
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/MovingObjToObject
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/MovingObjToObject	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/MovingObjToObject	(revision 37066)
@@ -0,0 +1,2 @@
+MovingObjID  	BIGINT 	8 	NA 	Moving Object identifier
+ObjID 	 	BIGINT 	8 	NA 	Object identifier
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/ObjectFilterFlags
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/ObjectFilterFlags	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/ObjectFilterFlags	(revision 37066)
@@ -0,0 +1,3 @@
+name	dimensionless	VARCHAR(32)	32		Name of flag
+value	dimensionless	BIGINT	8	NA	Flag value
+description	dimensionless	VARCHAR(2000)	2000		Description of the flag
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/ObjectInfoFlags
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/ObjectInfoFlags	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/ObjectInfoFlags	(revision 37066)
@@ -0,0 +1,3 @@
+name	dimensionless	VARCHAR(32)	32		Name of flag
+value	dimensionless	BIGINT	8	NA	Flag value
+description	dimensionless	VARCHAR(2000)	2000		Description of the flag
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/ObjectQualityFlags
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/ObjectQualityFlags	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/ObjectQualityFlags	(revision 37066)
@@ -0,0 +1,3 @@
+name	dimensionless	VARCHAR(32)	32		Name of flag
+value	dimensionless	BIGINT	8	NA	Flag value
+description	dimensionless	VARCHAR(2000)	2000		Description of the flag
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/PhotoCal
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/PhotoCal	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/PhotoCal	(revision 37066)
@@ -0,0 +1,11 @@
+photoCalID		INT	4	NA	numerical code for this reduction
+filterID		TINYINT	1	NA	filter id
+photoCodeDesc		VARCHAR(MAX)	8000		Photometry reduction code name
+AB		REAL	4	1.0	AB magnitude
+zeropoint		REAL	4	-999	photometric zero point (excluding long term variation)
+extinction		REAL	4	-999	photometric extinction term (excluding long term variation)
+colorterm		REAL	4	-999	photometric color term (excluding long term variation)
+colorExtn		REAL	4	-999	photometric color dependent extinction (excluding long term variation)
+orphanCalColor		REAL	4	-999	color adopted for magnitude calculation
+orphanCalColorErr		REAL	4	-999	error in calibrating color
+startDate	day	REAL	4	NA	starting date of this configuration in MJD
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/ProjectionCell
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/ProjectionCell	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/ProjectionCell	(revision 37066)
@@ -0,0 +1,22 @@
+projectionCellID 		INT 4 NA projection cell unique identifier
+partitionKey 			BIGINT 8 NA fGetPanObjID(crval1,crval2)
+primaryCellRegionID 		BIGINT 8 NA reference to the primary cell region definition in the Region table
+projectionCellRegionID 		BIGINT 8 NA reference to the projectio cell region definition in the
+ctype1 				VARCHAR(MAX) 8000 NA nRaemgieo no ft aabsltero)metric projection in RA
+ctype2 				VARCHAR(MAX) 8000 NA name of astrometric projection in DEC
+crval1 deg 			FLOAT 8 NA RA corresponding to reference pixel
+crval2 deg 			FLOAT 8 NA DEC corresponding to reference pixel
+crpix1 				FLOAT 8 NA reference pixel value for RA
+crpix2 				FLOAT 8 NA reference pixel value for DEC
+pc001001 			FLOAT 8 NA elements of rotation/Dcale matrix
+pc001002 			FLOAT 8 NA elements of rotation/Dcale matrix
+pc002001 			FLOAT 8 NA elements of rotation/Dcale matrix
+pc002002 			FLOAT 8 NA elements of rotation/Dcale matrix
+raNEcornerPC   degrees          FLOAT  8 -999 ra of NE corner
+decNEcornerPC  degrees          FLOAT  8 -999 dec of NE corner
+raNWcornerPC   degrees          FLOAT  8 -999 ra of NE corner
+decNWcornerPC  degrees          FLOAT  8 -999 dec of NE corner
+raSEcornerPC   degrees          FLOAT  8 -999 ra of NE corner
+decSEcornerPC  degrees          FLOAT  8 -999 dec of NE corner
+raSWcornerPC   degrees          FLOAT  8 -999 ra of NE corner
+decSWcornerPC  degrees          FLOAT  8 -999 dec of NE corner
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/PsConstant
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/PsConstant	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/PsConstant	(revision 37066)
@@ -0,0 +1,4 @@
+name VARCHAR(32) 32 NA constant's name
+value FLOAT 8 NA constant's value
+unit VARCHAR(32) 32 unit of constant
+description VARCHAR(2000) 2000 description of the constant
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/Region
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/Region	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/Region	(revision 37066)
@@ -0,0 +1,7 @@
+regionID dimensionless	BIGINT 8 NA Unique Region identifier 
+id 	 dimensionless	BIGINT 8 NA Custom Identifier
+type 	 string         VARCHAR(16) 16 NA Region type
+comment  string         VARCHAR(MAX) 8000 Comment
+area     sqdeg?         FLOAT 8 0 Area covered by the region
+region   dimensionless	Binary VARBINARY(MAX) 8000 0x Binary object managed by the spatial library
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/RegionPatch
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/RegionPatch	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/RegionPatch	(revision 37066)
@@ -0,0 +1,15 @@
+Unit Data Type Size Default Value Description
+regionid BIGINT 8 NA No comment
+convexid BIGINT 8 NA No comment
+patchid INT 4 NA No comment
+type (16) NA No comment
+radius FLOAT 8 0 No comment
+ra degree FLOAT 8 0 Right Ascension
+dec FLOAT 8 0 No comment
+x FLOAT 8 0 No comment
+y FLOAT 8 0 No comment
+z FLOAT 8 0 No comment
+c FLOAT 8 0 No comment
+htmid BIGINT 8 0 No comment
+area FLOAT 8 0 No comment
+convexString (MAX) No comment
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/SkyCell
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/SkyCell	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/SkyCell	(revision 37066)
@@ -0,0 +1,12 @@
+skyCellID   dimensionless I	INT 4 NA indentifier of the sky cell
+projectionCellID 		INT 4 -999 indentifier of the projection cell
+partitionKey 	 		BIGINT 8 -999 fgetPANobjID(skyCell_center_ra, skyCell_center_dec, zHeight)
+regionID 	 		BIGINT 8 -999 region identifier in the Region table
+raNEcorner   degrees            FLOAT  8 -999 ra of NE corner
+decNEcorner  degrees            FLOAT  8 -999 dec of NE corner
+raNWcorner   degrees            FLOAT  8 -999 ra of NE corner
+decNWcorner  degrees            FLOAT  8 -999 dec of NE corner
+raSEcorner   degrees            FLOAT  8 -999 ra of NE corner
+decSEcorner  degrees            FLOAT  8 -999 dec of NE corner
+raSWcorner   degrees            FLOAT  8 -999 ra of NE corner
+decSWcorner  degrees            FLOAT  8 -999 dec of NE corner
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/StackDetectionFlags
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/StackDetectionFlags	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/StackDetectionFlags	(revision 37066)
@@ -0,0 +1,3 @@
+Name	dimensionless	VARCHAR(32)	32		Name of flag
+value	dimensionless	BIGINT	8	NA	Flag value
+description	dimensionless	VARCHAR(2000)	2000		Description of the flag
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/StackMeta
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/StackMeta	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/StackMeta	(revision 37066)
@@ -0,0 +1,35 @@
+stackMetaID dimensionless   BIGINT 8 NA stack identifier
+batchID     dimensionless   BIGINT 8 NA batch identifier
+surveyID    dimensionless   TINYINT 1 NA survey flag identifier
+filterID    dimensionless   TINYINT 1 NA fnilutemr eidriecnatl ifidier
+stackTypeID dimensionless   TINYINT 1 0 stack type identifier
+skyCellID   dimensionless   REAL 4 NA skycell region identifier 
+photoCalID  dimensionless   INT 4 NA photometry code
+magSat      dimensionless   REAL 4 -999 saturation magnitude level
+analVer     dimensionless   SMALLINT 2 -999 analysis version index
+expTime     seconds         REAL 4 -999 exposure time
+nP2Images   dimensionless   SMALLINT 2 -999 number of P2 images contributing to this cell
+completMag  magnitudes      REAL 4 -999 95% completion level in mag
+astroScat   dimensionless   REAL 4 -999 astrometric scatter for chip
+photoScat   dimensionless   REAL 4 -999 photometric scatter for chip
+nAstroRef   dimensionless   INT 4 -999 number of astrometric reference sources
+nPhoRef     dimensionless   INT 4 -999 number of photometric reference sources
+psfModelID  dimensionless   VARCHAR(MAX) 8000 PSF model identifier
+psfFwhm_mean arcsec         FLOAT 8 -999 mean PSF FWHM in the stack
+psfFwhm_max  arcsec         FLOAT 8 -999 maximum PSF FWHM in the stack 
+photoZero    magnitudes     REAL 4 -999 local derived photometric zero point
+photoColor   magnitudes     REAL 4 -999 local derived photometric color term
+ctype1       alphanumeric   VARCHAR(MAX) 8000 name of astrometric projection in RA
+ctype2       alphanumeric   VARCHAR(MAX) 8000 name of astrometric projection in DEC
+crval1       degrees        FLOAT 8 -999 RA corresponding to reference pixel
+crval2       degrees        FLOAT 8 -999 DEC corresponding to reference pixel
+crpix1       dimensionless  FLOAT 8 -999 reference pixel value for RA
+crpix2       dimensionless  FLOAT 8 -999 reference pixel value for DEC
+cdelt1       deg/pixel      FLOAT 8 -999 scale factor for RA
+cdelt2       deg/pixel      FLOAT 8 -999 scale factor for DEC
+pc001001     dimensionless  FLOAT 8 -999 elements of rotation/Dcale matrix 
+pc001002     dimensionless  FLOAT 8 -999 elements of rotation/Dcale matrix
+pc002001     dimensionless  FLOAT 8 -999 elements of rotation/Dcale matrix
+pc002002     dimensionless  FLOAT 8 -999 elements of rotation/Dcale matrix
+calibModNum  dimensionless  SMALLINT 2 NA calibration modification number
+dataRelease  dimensionless  TINYINT 1 NA Data release
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/StackToImage
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/StackToImage	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/StackToImage	(revision 37066)
@@ -0,0 +1,2 @@
+stackMetaID 	BIGINT 	8 	NA 	stack identifier
+imageID 	BIGINT 	8 	NA 	hashed exposure-ccdID identifier
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/StackType
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/StackType	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/StackType	(revision 37066)
@@ -0,0 +1,3 @@
+stackTypeID		TINYINT	1	-999	stack type identifier
+name		VARCHAR(20)	20		stack type name
+description		VARCHAR(MAX)	8000		stack type description
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/Survey
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/Survey	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/Survey	(revision 37066)
@@ -0,0 +1,4 @@
+SurveyID TINYINT 1 NA index of survey type
+name VARCHAR(6) 6 survey name
+description VARCHAR(MAX) 8000 
+survey description
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/TelescopeConfig
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/TelescopeConfig	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/TelescopeConfig	(revision 37066)
@@ -0,0 +1,16 @@
+TelescopeConfig
+Description: Telescope configuration
+
+Name      	Unit		        DataType    Size	Default		ValueDescription 
+
+TelescopeID  	dimensionless   	SMALLINT 	2 	   -999         Telescope identifier (i.e. PS1, ISP)
+TeleConfigID    dimensionless           SMALLINT        2          -999         Telescope Configuration ID
+MountModel      string                                  8            NA         Mount Model Name
+MirrorModel     string                                  8            NA         Mirror Model Name
+Observera       string                                  8            NA         Observers Name
+endDate         MeanJulianDays   	    FLOAT       8          -999         ending date of this configuration in MJD
+configDetails   string           VARCHAR(MAX) 8000      0x00         NA         text/table giving the details of the telescope configuration
+
+
+
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/pcsGalaxyModel
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/pcsGalaxyModel	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/pcsGalaxyModel	(revision 37066)
@@ -0,0 +1,3 @@
+galaxyModelID	dimensionless	INT	4	NA	modelID
+description	dimensionless	VARCHAR(128)	128		model description, spectral type etc.
+priors	dimensionless	VARCHAR(128)	128		priors applied to this model, may also split into 7 columns
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/pcsPhotoZRecipe
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/pcsPhotoZRecipe	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/pcsPhotoZRecipe	(revision 37066)
@@ -0,0 +1,2 @@
+photozRecipeID	dimensionless	TINYINT	1	-999	recipe index
+description	dimensionless	VARCHAR(MAX)	8000		string\ describing\ the\ recipe
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/pcsSGSepRecipe
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/pcsSGSepRecipe	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/pcsSGSepRecipe	(revision 37066)
@@ -0,0 +1,2 @@
+sgSepRecipeID	dimensionless	INT	4	NA	Star/Galaxy Seperator Recuipe ID
+description	dimensionless	VARCHAR(128)	128		Description
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/pcsStarModel
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/pcsStarModel	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/pcsStarModel	(revision 37066)
@@ -0,0 +1,2 @@
+starModelID	dimensionless	INT	4	-999	modelID
+description	dimensionless	VARCHAR(128)	128		model description, spectral type etc
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/pcsStellarParamsRecipe
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/pcsStellarParamsRecipe	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/MetaData_Tables/pcsStellarParamsRecipe	(revision 37066)
@@ -0,0 +1,3 @@
+stellarParamsRecipeID	dimensionless	INT	4	NA	Na
+description	dimensionless	VARCHAR(128)	128		Description:wq
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_VIEWS/README
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_VIEWS/README	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_VIEWS/README	(revision 37066)
@@ -0,0 +1,5 @@
+See Notes_on_Schema 03.txt
+for what tables are combined into what views.
+Once there is concensus on tables, then will combine tables to make views. Meanwhile can concatente yourself from Notes.
+
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_VIEWS/Views
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_VIEWS/Views	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew16.0/PSPS_VIEWS/Views	(revision 37066)
@@ -0,0 +1,17 @@
+
+PSPS VIEWS - examples  
+
+ObjectMean        = ObjectThin join MeanObject 
+ObjectStack       = ObjectThin join StackObject
+ObjectApFlx       = ObjectThin join StackApFlx  
+ObjectModel       = ObjectThin join StackModelFit   
+ObjectStackAll    = ObjectThin join StackObject and StackAp and StackModelFit 
+ObjectForcedMean  = ObjectThin join ForcedMeanObject
+ObjectPrimary     = ObjectThin join StackObject join StackApFlx where primaryDection is true
+ObjectBest        = ObjectThin join StackObject join StackApFlx where bestDetection is true
+
+
+
+
+
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/Notes_on_Schema10.txt
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/Notes_on_Schema10.txt	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/Notes_on_Schema10.txt	(revision 37066)
@@ -0,0 +1,132 @@
+Notes on Schema Version 9
+
+
+Proposed Image Products and PSPS Tables and Views
+
+IMAGE PRODUCTS 
+
+Survey  | Description               |  Image Products Saved
+
+3pi     | 3pi                       | 3pi warps, 3pi stacks
+CNP     | Celestial North Pole (3pi)| CNP warps, stacks
+SS      | ecliptic w band data      |   w warps, w stack
+MDD     | Medium Deep Deep          |  MD warps, deep stacks 
+MDT     | Medium Deep Template      |            template stacks
+MDN     | Medium Deep Nightly Stack |            nightly stacks 
+MDN     | Medium Deep Off Year      |            off year template stacks 
+M31     | M31                       | M31 warps, M31 stacks, template
+STS     | STS                       | STS warps, STS template - best iq stack 
+
+
+Survey  | Description               |  Image Products NOT Saved, but analyzed for difference detections and discarded 
+
+3pi     | difference                |3pi warps - stack 
+CNP     | difference                |CNP warps - stack 
+SS      | difference image          |  w warps - stack 
+MDD     | difference image          | MD warps - off year template stacks  
+MDO     | difference image          | MDN stacks - off year template stacks  
+M31     | difference image          | M31 warps - stack 
+STS     | difference image          | STS warps - template 
+
+
+
+PSPS TABLES                                                 
+
+
+Fundamental IPP Data Products  Origin 
+
+Detection                      detections found in detrended images   
+ObjectThin                     positonal and flag data, no fluxes   
+MeanObject                     extracted Mean properties as determined from individual Detections.   
+StackObject                    Stack Detections in all filters, with forced upperlimits, separate rows for primary, secondary, best stack detections (80% time only primary)  
+StackApFlx                     all filters in one table, unconvolved and convolved apertures (up to  6 , 8, 10(?) pixels  in all bands) 
+StackModelFit                  all filters in one table. Models of high signal to noise objects in low density regions.     
+DiffDet                        difference detections found in difference image = image - template 
+DiffObject                     associations of Difference Detections
+ForcedWarpMeasure              forced measurements on each warp in all filters at the position of an object found in a stack. Includes StackApFlx-like table   
+ForcedMeanObject               like MeanObject, but using the Forced Mean Measurements to form the Mean. 
+
+w band                         TBD 
+
+
+Derived Data Product Tables 
+
+pcsPhotoZ                       populated from PCS
+pcsPhotoZProbability            populated from PCS
+pcsStarGalQSOSep                populated from PCS
+pcsStellarParams                populated from PCS
+mopsMovingObject                populated from MOPS database
+ppmObj                          proper motion and parallax populated from IPP  
+tcsClassification               populated from transient server database
+galExtinction                   populated from Dust team
+stargal                         populated from various algorithms, combos of ipp parameters, fits to population as function of magnitude, or Support Vector Machine
+GoodObject                      selected and populated post-facto  
+StarGalaxySep                   selected and populated post-facto 
+
+
+Observational Metadata and System MetaData Tables
+
+CameraConfig
+DetectionFlags
+DiffMeta
+Filter
+FitModel
+ForcedWarpMeta
+FrameMeta
+ImageFlags
+ImageMeta                       add psf 3nd and 4th  moments
+Mask
+MovingObjectToDet
+MovingObjectToDiffDet
+MovingObjToObject
+ObjectFilterFlags               flag info not in current schema but in PSI interface...
+ObjectInfoFlags
+ObjectQualityFlags
+PhotoCal
+ProjectionCell
+ProcessingVersion
+SkyCell 
+StackDetectionFlags
+StackMeta                       
+StackToImage
+StackType
+Survey
+TelescopeConfig
+fitModel
+pcsGalaxyModel
+pcsPhotoZRecipe
+pcsSGSepRecipe
+pcsStarModel
+pcsStellarParamsRecipe
+
+
+
+PSPS VIEWS - examples  
+
+ObjectMean        = ObjectThin join MeanObject 
+ObjectStack       = ObjectThin join StackObject
+ObjectApFlx       = ObjectThin join StackApFlx  
+ObjectModel       = ObjectThin join StackModelFit   
+ObjectStackAll    = ObjectThin join StackObject and StackAp and StackModelFit 
+ObjectForcedMean  = ObjectThin join ForcedMeanObject
+ObjectPrimary     = ObjectThin join StackObject join StackApFlx where primaryDection is true
+ObjectBest        = ObjectThin join StackObject join StackApFlx where bestDetection is true
+
+
+PSPS Indicies 
+
+DetectionID
+ObjectID
+BatchID
+StackTypeID
+MovingObjID
+DiffObjID 
+RandomID           between 1 and 2^16 = 4,294,967,296 so you pick how many random objects you want ,
+                   i.e 10,000 pick randomid < 10,000 and if indexed, this will be very fast. 
+RandomStackID      between 1 and 2^16 = 4,294,967,296 so you pick how many random objects you want ,
+                   i.e 10,000 pick randomid < 10,000 and if indexed, this will be very fast. 
+
+
+
+
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/Notes_on_Schema11.txt
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/Notes_on_Schema11.txt	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/Notes_on_Schema11.txt	(revision 37066)
@@ -0,0 +1,132 @@
+Notes on Schema Version 9
+
+
+Proposed Image Products and PSPS Tables and Views
+
+IMAGE PRODUCTS 
+
+Survey  | Description               |  Image Products Saved
+
+3pi     | 3pi                       | 3pi warps, 3pi stacks
+CNP     | Celestial North Pole (3pi)| CNP warps, stacks
+SS      | ecliptic w band data      |   w warps, w stack
+MDD     | Medium Deep Deep          |  MD warps, deep stacks 
+MDT     | Medium Deep Template      |            template stacks
+MDN     | Medium Deep Nightly Stack |            nightly stacks 
+MDN     | Medium Deep Off Year      |            off year template stacks 
+M31     | M31                       | M31 warps, M31 stacks, template
+STS     | STS                       | STS warps, STS template - best iq stack 
+
+
+Survey  | Description               |  Image Products NOT Saved, but analyzed for difference detections and discarded 
+
+3pi     | difference                |3pi warps - stack 
+CNP     | difference                |CNP warps - stack 
+SS      | difference image          |  w warps - stack 
+MDD     | difference image          | MD warps - off year template stacks  
+MDO     | difference image          | MDN stacks - off year template stacks  
+M31     | difference image          | M31 warps - stack 
+STS     | difference image          | STS warps - template 
+
+
+
+PSPS TABLES                                                 
+
+
+Fundamental IPP Data Products  Origin 
+
+Detection                      detections found in detrended images   
+ObjectThin                     positonal and flag data, no fluxes   
+MeanObject                     extracted Mean properties as determined from individual Detections.   
+StackObject                    Stack Detections in all filters, with forced upperlimits, separate rows for primary, secondary, best stack detections (80% time only primary)  
+StackApFlx                     all filters in one table, unconvolved and convolved apertures (up to  6 , 8, 10(?) pixels  in all bands) 
+StackModelFit                  all filters in one table. Models of high signal to noise objects in low density regions.     
+DiffDet                        difference detections found in difference image = image - template 
+DiffObject                     associations of Difference Detections
+ForcedWarpMeasure              forced measurements on each warp in all filters at the position of an object found in a stack. Includes StackApFlx-like table   
+ForcedMeanObject               like MeanObject, but using the Forced Mean Measurements to form the Mean. 
+
+w band                         TBD 
+
+
+Derived Data Product Tables 
+
+pcsPhotoZ                       populated from PCS
+pcsPhotoZProbability            populated from PCS
+pcsStarGalQSOSep                populated from PCS
+pcsStellarParams                populated from PCS
+mopsMovingObject                populated from MOPS database
+ppmObj                          proper motion and parallax populated from IPP  
+tcsClassification               populated from transient server database
+galExtinction                   populated from Dust team
+stargal                         populated from various algorithms, combos of ipp parameters, fits to population as function of magnitude, or Support Vector Machine
+GoodObject                      selected and populated post-facto  
+StarGalaxySep                   selected and populated post-facto 
+
+
+Observational Metadata and System MetaData Tables
+
+CameraConfig
+DetectionFlags
+DiffMeta
+Filter
+FitModel
+ForcedWarpMeta
+FrameMeta
+ImageFlags
+ImageMeta                       add psf 3nd and 4th  moments
+Mask
+MovingObjectToDet
+MovingObjectToDiffDet
+MovingObjToObject
+ObjectFilterFlags               flag info not in current schema but in PSI interface...
+ObjectInfoFlags
+ObjectQualityFlags
+PhotoCal
+ProjectionCell
+ProcessingVersion
+SkyCell 
+StackDetectionFlags
+StackMeta                       
+StackToImage
+StackType
+Survey
+TelescopeConfig
+fitModel
+pcsGalaxyModel
+pcsPhotoZRecipe
+pcsSGSepRecipe
+pcsStarModel
+pcsStellarParamsRecipe
+
+
+
+PSPS VIEWS - examples  
+
+ObjectMean        = ObjectThin join MeanObject 
+ObjectStack       = ObjectThin join StackObject
+ObjectApFlx       = ObjectThin join StackApFlx  
+ObjectModel       = ObjectThin join StackModelFit   
+ObjectStackAll    = ObjectThin join StackObject and StackAp and StackModelFit 
+ObjectForcedMean  = ObjectThin join ForcedMeanObject
+ObjectPrimary     = ObjectThin join StackObject join StackApFlx where primaryDection is true
+ObjectBest        = ObjectThin join StackObject join StackApFlx where bestDetection is true
+
+
+PSPS Indicies 
+
+DetectionID
+ObjectID
+BatchID
+StackTypeID
+MovingObjID
+DiffObjID 
+RandomID           between 1 and 2^16 = 4,294,967,296 so you pick how many random objects you want ,
+                   i.e 10,000 pick randomid < 10,000 and if indexed, this will be very fast. 
+RandomStackID      between 1 and 2^16 = 4,294,967,296 so you pick how many random objects you want ,
+                   i.e 10,000 pick randomid < 10,000 and if indexed, this will be very fast. 
+
+
+
+
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/Notes_on_Schema12.txt
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/Notes_on_Schema12.txt	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/Notes_on_Schema12.txt	(revision 37066)
@@ -0,0 +1,2 @@
+Heather cleaned up the column names and types to make them consistent.
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/Notes_on_Schema13.txt
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/Notes_on_Schema13.txt	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/Notes_on_Schema13.txt	(revision 37066)
@@ -0,0 +1,8 @@
+changes by EAM:
+* added lensing terms to ForcedWarpMeasurement & ForcedMeanObject
+* removed fluxPeak and momentRH generally
+* changed psfWidMajor,Minor to psfMajorFWHM,psfMinorFWHM
+* added psfCore (k term in psf model : 1 / (1 + kz + k^1.667)
+* fixed stack flux & mag names
+* set units for moments to be in arcsec everywhere.
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Derived_Data_Product_Tables/GoodObject
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Derived_Data_Product_Tables/GoodObject	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Derived_Data_Product_Tables/GoodObject	(revision 37066)
@@ -0,0 +1,4 @@
+objName         string          VAR     8       NA      IAU Name constructed from objID postion PS1.x JHHMMSS.SS+/-DDMMSS.S where x is leading number of procesing version
+objID           dimensionless   BIGINT  8       NA      ODM object identifier index
+ippObjID        dimensionless   BIGINT  8       NA      IPP object number
+goodObjectID    dimensionless   BIGINT  8       NA      index for post-facto "good objects" subset from ObjID 
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Derived_Data_Product_Tables/StarGalaxySep
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Derived_Data_Product_Tables/StarGalaxySep	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Derived_Data_Product_Tables/StarGalaxySep	(revision 37066)
@@ -0,0 +1,9 @@
+objName         string          VAR     8       NA      IAU Name constructed from objID postion PS1.x JHHMMSS.SS+/-DDMMSS.S where x is leading number of procesing version
+objID           dimensionless   BIGINT  8       NA      ODM object identifier index
+ippObjID        dimensionless   BIGINT  8       NA      IPP object number
+sgbinarySep1    dimensionless   TINYINT 2       255     binary flag for star galaxy separator - technique 1
+sgbinarySep2    dimensionless   TINYINT 2       255     binary flag for star galaxy separator - technique 2
+sgbinarySep3    dimensionless   TINYINT 2       255     binary flag for star galaxy separator - technique 3
+sgSep1          dimensionless   REAL    4       -999    probility of star/galaxy technique 1  
+sgSep2          dimensionless   REAL    4       -999    probility of star/galaxy technique 2  
+sgSep3          dimensionless   REAL    4       -999    probility of star/galaxy technique 3  
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Derived_Data_Product_Tables/galExtinction
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Derived_Data_Product_Tables/galExtinction	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Derived_Data_Product_Tables/galExtinction	(revision 37066)
@@ -0,0 +1,28 @@
+galExtinction 
+Name	Unit	Data Type	Size	Default Value	Description
+
+objID				dimensionless	BIGINT	8	NA	ODM object identifier index
+ippObjID			dimensionless	BIGINT	8	NA	IPP object number
+
+From Doug and Eddie ?
+
+E(B-V)
+
+gGalext
+rGalext
+iGalext
+zGalext
+yGalext
+wGalext
+probability vector
+
+stellar parameters
+Teff
+g_surf
+[Fe/H]
+
+
+
+
+
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Derived_Data_Product_Tables/mopsMovingObject
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Derived_Data_Product_Tables/mopsMovingObject	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Derived_Data_Product_Tables/mopsMovingObject	(revision 37066)
@@ -0,0 +1,28 @@
+Name Unit Data Type Size Default Value Description
+
+MovingObjName   dimensionless	STRING 	x	-999	MPC Name 
+MovingObjType   dimensionless 	STRING 	x	-999 	Type of moving object (NEO, PHA, COMET, ...)
+MovingObjID     dimensionless	BIGINT 8 	-999  	Moving Object identifier     
+OrbEpoch        date		DATE     	-999  	The epoch of osculation of the orbital elements.
+Moid       	au		REAL   	4 	-999  	Minimum orbit intersection distance 
+OrbM       	dimensionles	REAL	4	-999	Mean anomaly at the epoch.
+OrbT       	date 		DATE 	  	-999    Date of perihelion passage.
+ORBn 		deg/day		REAL	4	-999	Mean daily motion (in degrees/day).
+ORBa       	AU		REAL	4	-999	Semimajor axis (in AU).
+ORBz       	1/AU		REAL	4	-999 	Reciprocal semimajor axis (in 1/AU).
+ORBq       	AU		REAL	4	-999	Perihelion distance (in AU).
+ORBe       	dimensionless	REAL	4	-999	Orbital eccentricity.
+OrbP       	years		REAL	4	-999	Orbital period (in years).
+OrbPeri    	degrees		REAL	4	-999	The J2000.0 argument of perihelion (in degrees).
+OrbNode    	degrees		REAL	4	-999	The J2000.0 longitude of the ascending node (in degrees).
+OrbIncl    	degrees		REAL	4	-999	The J2000.0 inclination (in degrees).
+P1         	dimensionless	REAL	4	-999	P1 first component of P vector
+P2	        dimensionless   REAL    4       -999    P2 second component of P vector 
+P3              dimensionless   REAL    4       -999    P3 third component of P vector
+Q1         	dimensionless   REAL    4       -999    Q1 first component of Q vector
+Q2         	dimensionless 	REAL    4	-999    Q2 second component of Q vector
+Q3         	dimensionless   REAL    4       -999    Q3 third component of Q vector
+U               dimensionless   REAL    4       -999    Uncertainty parameter.
+H               dimensionless   REAL    4       -999    Absolute visual magnitude. A table converting H to a diameter is available.
+G               dimensionless   REAL    4       -999    Slope parameter. 
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Derived_Data_Product_Tables/pcsPhotoZ
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Derived_Data_Product_Tables/pcsPhotoZ	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Derived_Data_Product_Tables/pcsPhotoZ	(revision 37066)
@@ -0,0 +1,21 @@
+pcsPhotoZ
+Name	Unit	Data Type	Size	Default Value	Description
+
+objID			BIGINT	8	NA	ODM object identifier index
+ippObjID		BIGINT	8	NA	IPP object number
+pcsPhotoZRecipeID	INT	4	-999	Recipe of the photoZ calculation
+galExt			REAL	4	-999	Galactic extinction E(B-V) used for photoz determination (derived from Schlegel Maps)
+photoz_1		REAL	4	-999	PhotoZ for best fitting template
+photozErr_1		REAL	4	-999	Estimated error for this tempalte
+chi2_1			REAL	4	-999	Chi^2 for this template
+modelID_1		INT	4	-999	Identifier for the template for this recipe
+photoz_2		REAL	4	-999	PhotoZ for second template
+photozErr_2		REAL	4	-999	Estimated error for this tempalte
+chi2_2			REAL	4	-999	Chi^2 for this template
+modelID_2		INT	4	-999	Identifier for the template for this recipe
+flags_gtfit		INT	4	-999	warning flags (e.g. missing band(s), unreliable galExt value etc.), TBD
+av			REAL	4	-999	determined extinction
+chi2			REAL	4	-999	chi2 for the best fitting stellar template
+modelID			INT	4	-999	modelID of the best fitting stellar template
+flags_stfit		INT	4	-999	warning flags from stellar template fitting
+starGalQSOSep		INT	4	-999	0: Object is a star (chi2
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Derived_Data_Product_Tables/pcsPhotoZProbabiity
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Derived_Data_Product_Tables/pcsPhotoZProbabiity	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Derived_Data_Product_Tables/pcsPhotoZProbabiity	(revision 37066)
@@ -0,0 +1,37 @@
+PhotoZProbability
+Name	Unit	Data Type	Size	Default Value	Description
+
+objID			dimensionless	BIGINT	8	NA	ODM object identifier index
+ippObjID		dimensionless	BIGINT	8	NA	IPP object number
+pcsPhotoZRecipeID	dimensionless	INT	4	-999	recipe for the photoz determination
+modelID			dimensionless	INT	4	-999	modelID of the template
+sp1	dimensionless	REAL	4	-999	spline params 1
+sp2	dimensionless	REAL	4	-999	spline params 2
+sp3	dimensionless	REAL	4	-999	spline params 3
+sp4	dimensionless	REAL	4	-999	spline params 4
+sp5	dimensionless	REAL	4	-999	spline params 5
+sp6	dimensionless	REAL	4	-999	spline params 6
+sp7	dimensionless	REAL	4	-999	spline params 7
+sp8	dimensionless	REAL	4	-999	spline params 8
+sp9	dimensionless	REAL	4	-999	spline params 9
+sp10	dimensionless	REAL	4	-999	spline params 10
+sp11	dimensionless	REAL	4	-999	spline params 11
+sp12	dimensionless	REAL	4	-999	spline params 12
+sp13	dimensionless	REAL	4	-999	spline params 13
+sp14	dimensionless	REAL	4	-999	spline params 14
+sp15	dimensionless	REAL	4	-999	spline params 15
+sp16	dimensionless	REAL	4	-999	spline params 16
+sp17	dimensionless	REAL	4	-999	spline params 17
+sp18	dimensionless	REAL	4	-999	spline params 18
+sp19	dimensionless	REAL	4	-999	spline params 19
+sp20	dimensionless	REAL	4	-999	spline params 20
+sp21	dimensionless	REAL	4	-999	spline params 21
+sp22	dimensionless	REAL	4	-999	spline params 22
+sp23	dimensionless	REAL	4	-999	spline params 23
+sp24	dimensionless	REAL	4	-999	spline params 24
+sp25	dimensionless	REAL	4	-999	spline params 25
+sp26	dimensionless	REAL	4	-999	spline params 26
+sp27	dimensionless	REAL	4	-999	spline params 27
+sp28	dimensionless	REAL	4	-999	spline params 28
+sp29	dimensionless	REAL	4	-999	spline params 29
+sp30	dimensionless	REAL	4	-999	spline params 30
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Derived_Data_Product_Tables/pcsStarGalQSOSep
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Derived_Data_Product_Tables/pcsStarGalQSOSep	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Derived_Data_Product_Tables/pcsStarGalQSOSep	(revision 37066)
@@ -0,0 +1,10 @@
+pcsStarGalQSOSep
+Name	Unit	Data Type	Size	Default Value	Description
+
+objID		dimensionless	BIGINT	8	NA	ODM object identifier index
+ippObjID	dimensionless	BIGINT	8	NA	IPP object number
+pcsSGSepRecipeIDdimensionless	INT	4	NA	recipe for the star/galaxy/quasar separation
+probStar	percentage	FLOAT	8	-999	probability object is a star
+probGalaxy	percentage	FLOAT	8	-999	probability object is a galaxy
+probQuasar	percentage	FLOAT	8	-999	probability object is a quasar
+flags		dimensionless	INT	4	-999	flags
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Derived_Data_Product_Tables/pcsStellarParams
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Derived_Data_Product_Tables/pcsStellarParams	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Derived_Data_Product_Tables/pcsStellarParams	(revision 37066)
@@ -0,0 +1,11 @@
+pcsStellarParams s
+Name	Unit	Data Type	Size	Default Value	Description
+
+objID				dimensionless	BIGINT	8	NA	ODM object identifier index
+ippObjID			dimensionless	BIGINT	8	NA	IPP object number
+pcsStellarParamsRecipeID	dimensionless	INT	4	-999	recipe for the star/galaxy/quasar separation
+Teff	dimensionless	REAL	4	-999	N/A
+A0	dimensionless	REAL	4	-999	N/A
+Fe_H	dimensionless	REAL	4	-999	N/A
+flags	dimensionless	INT	4	-999	flags
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Derived_Data_Product_Tables/ppmObj
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Derived_Data_Product_Tables/ppmObj	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Derived_Data_Product_Tables/ppmObj	(revision 37066)
@@ -0,0 +1,25 @@
+PPM
+Description: Proper motions and parallax associated with defined objects. 
+
+Name Unit Data Type Size Default Value Description
+objID		BIGINT 8 NA ODM object identifier
+ippObjID   	BIGINT 8 NA IPP object identifier index
+ppmID           BIGINT 8 NA ppm object identifier ( ppmToObject metatable?)
+meanEpoch	FLOAT 	8 	-999 	mean epoch of observations in Mean Julian Days
+elapseTime 	REAL 4 -999 Elapsed time of astrometric observations
+muRa 		REAL 4 -999 proper motion in RA
+muRaErr 	REAL 4 -999 error in proper motion in RA
+muDec 		REAL 4 -999 proper motion in DEC
+muDecErr 	REAL 4 -999 error in proper motion in Dec
+mu 		REAL 4 -999 total proper motion
+muErr 		REAL 4 -999 error in total proper motion
+theta 		REAL 4 -999 angle of parallax vector from N in degrees
+plx 		REAL 4 -999 total parallax
+plxErr 		REAL 4 -999 error in total parallax
+nAstro 		SMALLINT 2 -999 number of measures in astrometric fit
+rmsRA 		REAL 4 -999 rms of astrometric error in RA
+rmsDec 		REAL 4 -999 rms of astrometric error in Dec
+wiggle 		TINYINT 1 255 flag/pointer to astrometric orbit
+
+
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Derived_Data_Product_Tables/stargal
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Derived_Data_Product_Tables/stargal	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Derived_Data_Product_Tables/stargal	(revision 37066)
@@ -0,0 +1,17 @@
+
+
+Name	Unit	Data Type	Size	Default Value	Description
+
+objID		dimensionless	BIGINT	8	NA	ODM object identifier index
+ippObjID	dimensionless	BIGINT	8	NA	IPP object number
+StarProb1	fraction	FLOAT	8	-999	fractional probability object is a star, Recipe 1
+GalProb1	fraction	FLOAT	8	-999	fractional probability object is a galaxy, Recipe 1
+StarProb2	fraction	FLOAT	8	-999	fractional probability object is a star, Recipe 2
+GalProb2 	fraction	FLOAT	8	-999	fractional probability object is a galaxy, Recipe 2
+StarProb3	fraction	FLOAT	8	-999	fractional probability object is a star, Recipe 3
+GalProb3	fraction	FLOAT	8	-999	fractional probability object is a galaxy, Recipe 3
+
+
+comment - may come from different combinations of ipp parameters, model fit as function of magnitude, 
+or Support Vector Machine result. 
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Derived_Data_Product_Tables/tcsClassification
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Derived_Data_Product_Tables/tcsClassification	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Derived_Data_Product_Tables/tcsClassification	(revision 37066)
@@ -0,0 +1,16 @@
+galExtinction 
+Name	Unit	Data Type	Size	Default Value	Description
+
+objID				dimensionless	BIGINT	8	NA	ODM object identifier index
+ippObjID			dimensionless	BIGINT	8	NA	IPP object number
+diffobjID 			dimensionless	BIGINT	8	NA	IPP object number
+
+From Stephen and Ken?
+
+TransientName                                                           eg. PS1-10jh
+transientClass                                                          TDE
+ATEL                                                           -999     Astronomical Telegram number
+
+
+
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/Detection
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/Detection	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/Detection	(revision 37066)
@@ -0,0 +1,60 @@
+objID           dimensionless   BIGINT  8         NA    ODM object identifier
+gcObjID		dimensionless	BIGINT	8	  NA 	ODM galactic coordinates identifier
+detectID        dimensionless   BIGINT  8         NA    ODM detection identifier
+ippObjID        dimensionless   BIGINT  8         NA    detection id generated by IPP
+ippDetectID     dimensionless   BIGINT  8         NA    detection id generated by IPP
+filterID        dimensionless   TINYINT 1         NA    filter ID: g=1, r=2, i=3, z=4, y=5, w=6, ...
+surveyID        dimensionless   TINYINT 1         NA    survey flag identifier
+imageID         dimensionless   BIGINT  8         NA    image id hash of frame identifier & OTA/CCD number
+randomDetID     dimensionless   BIGINT  8         NA    random detection Id
+dvoRegionID     dimensionless   INT     4          0    identifier to dvo spatial region
+obsTime         MeanJulianDays  FLOAT   8       -999    Time of mid observation in Mean Julian Days
+xPos            raw pixels      REAL    4       -999    measured x on CCD from PSF fit
+yPos            raw pixels      REAL    4       -999    measured y on CCD from PSF fit
+xPosErr         raw pixels      REAL    4       -999    estimated error in x
+yPosErr         raw pixels      REAL    4       -999    estimated error in y
+pltScale        arcsec/pix      REAL    4       -999    plate scale at this location (from DVO)
+posAngle        degrees         REAL    4       -999    position angle (sky-to-chip) at this location (from DVO)
+------------------------------------------------------  Note - next 8 lines came from previous DetCalib table
+ra              degrees         FLOAT   8         NA    Right Ascension
+dec             degrees         FLOAT   8         NA    Declination
+raErr           arcsec          REAL    4         NA    Right Ascension error
+decErr          arcsec          REAL    4         NA    Declination error
+zp              magnitude       REAL    4          0    zeropoint (only thing needed to convert adu/sec to AB mag), note no zpErr
+telluricExt     magnitude       REAL    4         NA    estimated extinction due to non-photometric conditions  
+expTime         seconds         REAL    4       -999    exposure time (informational)
+airMass         dimensionless   REAL    4          0    airmass (informational)
+------------------------------------------------------  
+psfFlux         adu/seconds     REAL    4       -999    PSF instrumental flux (in analog-to-digital units/sec) or adu/sec
+psfFluxErr      adu/seconds     REAL    4       -999    estimated error in flux
+psfMajorFWHM    arcsec          REAL    4       -999    model PSF width in major axis
+psfMinorFWHM    arcsec          REAL    4       -999    model PSF width in minor axis
+psfTheta        degrees         REAL    4       -999    model PSF orientation angle degrees East of North
+psfCore         dimensionless   REAL    4       -999    model PSF core parameter [k in (1 + kz + z^1.66)]
+psfQf           dimensionless   REAL    4       -999    PSF coverage factor
+psfQfPerfect    dimensionless   REAL    4       -999    PSF-weighted fraction of pixels totally unmasked
+psfChiSq        dimensionless   REAL    4       -999    reduced-chisq of the psf model fit. (ndof?, npix?)
+psfLikelihood   dimensionless   REAL    4       -999    PSF likelihood
+momentXX        arcsec^2        REAL    4       -999    moment XX
+momentXY        arcsec^2        REAL    4       -999    moment XY
+momentYY        arcsec^2        REAL    4       -999    momeny YY
+momentR1        arcsec          REAL    4       -999    first radial moment 
+momentRH        arcsec          REAL    4       -999    half light radius (REMOVE THIS)
+momentM3C       arcsec^n        REAL    4       -999    3rd moment sin(theta) 
+momentM3S       arcsec^n        REAL    4       -999    3rd moment cos(theta) 
+momentM4C       arcsec^n        REAL    4       -999    4th moment sin(theta)
+momentM4S       arcsec^n        REAL    4       -999    4th moment cos(theta) 
+apFlux          adu/seconds     REAL    4       -999    Aperture flux
+apFluxErr       adu/seconds     REAL    4       -999    Aperture flux error
+apFillF         dimensionless   REAL    4       -999    Aperture fill factor 
+kronFlux        adu/seconds     REAL    4       -999    Kron flux
+kronFluxErr     adu/seconds     REAL    4       -999    Kron flux error
+kronRad         arcsec      	REAL    4       -999    Kron radius
+kronRadErr      arcsec      	REAL    4       -999    Kron radius error (DROP)
+sky             adu/sec/pixel   REAL    4       -999    PSF sky level at source
+skyErr          adu/sec/pixel   REAL    4       -999    estimated error in sky
+infoFlag        dimensionless   INT     4       -999    flag indicating provenance information
+infoFlag2       dimensionless   INT     4       -999    flag indicating provenance information
+dataRelease     dimensionless   TINYINT 1         NA    Data release when this detection was originally taken. Recalibrations do not affect this value.
+--
+-- [231 bytes/det]
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/Detection.txt
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/Detection.txt	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/Detection.txt	(revision 37066)
@@ -0,0 +1,58 @@
+objID           = dvo / addstar
+gcObjID		= dvo / addstar [EAM: add to addstar]
+detectID        = dvo / addstar
+ippObjID        = dvo / addstar
+ippDetectID     = dvo / addstar
+filterID        = smf / ipptopsps
+surveyID        = ipptopsps
+imageID         = smf header
+randomDetID     = ipptopsps
+dvoRegionID     = dvo / catID [EAM: add to dvopsps]
+obsTime         = smf
+xPos            = smf
+yPos            = smf
+xPosErr         = smf [EAM: modify errors to match relastro?]
+yPosErr         = smf
+pltScale        = smf
+posAngle        = smf
+----------------= 
+ra              = dvo / relastro
+dec             = dvo / relastro
+raErr           = dvo / relastro
+decErr          = dvo / relastro
+zp              = dvo / relphot
+telluricExt     = zp - zpNominal (dvopsps) [EAM: add to dvopsps]
+expTime         = smf
+airMass         = smf
+----------------= 
+psfFlux         = smf [OK: ipptopsps uses PSF_FLUX]
+psfFluxErr      = smf
+psfMajorFWHM    = smf [PSF_MAJOR is Sxx parameter, NOT FWHM] [EAM: add PSF_FWHM_MAJ to smf, keep PSF_MAJOR]
+psfMinorFWHM    = smf [PSF_MINOR is Sxx parameter, NOT FWHM] [EAM: add PSF_FWHM_MIN to smf, keep PSF_MINOR]
+psfTheta        = smf
+psfCore         = smf [EAM: add PSF_CORE to smf]
+psfQf           = smf
+psfQfPerfect    = smf
+psfChiSq        = smf
+psfLikelihood   = ipptopsps
+momentXX        = smf
+momentXY        = smf
+momentYY        = smf
+momentR1        = smf
+momentRH        = smf [XXX : MOMENTS_RH is NOT half-light radius : keep as MOMENTS_RH or calculate?]
+momentM3C       = smf
+momentM3S       = smf
+momentM4C       = smf
+momentM4S       = smf
+apFlux          = smf [requires PS1_V4]
+apFluxErr       = smf [requires PS1_V4]
+apFillF         = smf [EAM: add to pmSource and smf]
+kronFlux        = smf
+kronFluxErr     = smf
+kronRad         = (2.5*R1) : Ken : drop this or MOMENTS_R1?
+kronRadErr      = [not calculated] : drop this
+sky             = smf
+skyErr          = smf
+infoFlag        = smf
+infoFlag2       = smf
+dataRelease     = ippToPsps
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetObject
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetObject	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetObject	(revision 37066)
@@ -0,0 +1,34 @@
+
+diffObjName     string          VAR     8       NA      IAU Name constructed from objID postion PS1.x JHHMMSS.SS+/-DDMMSS.S x procesing version       
+diffObjID	dimensionless 	BIGINT 	8 	NA 	ODM object identifier index
+diffgcObjID	dimensionless	BIGINT	8       NA 	ODM galactic coordinates identifier
+ippObjID  	dimensionless 	BIGINT 	8 	NA 	IPP object number
+surveyID 	dimensionless 	TINYINT 1 	255 	Survey ID
+skyCellID       dimensionless   REAL    4       -999    single float giving PrimaryCell.SkyCell identifier
+htmID 		dimensionless 	BIGINT 	8 	NA 	HTM index
+zoneID 		dimensionless 	INT 	4 	NA 	Zone index
+randomID 	dimensionless 	BIGINT 	8 	0 	Random integer between 0 and 2^32 = 4,394,967,296 remaining ramdom integer 0  
+batchID 	dimensionless	BIGINT 	8 	-999 	
+dvoRegionID     dimensionless  	INT     4       -999    identifier to dvo spatial region
+objInfoFlag 	dimensionless 	BIGINT 	8 	-999 	flag indicating odd properties
+qualityFlag 	dimensionless 	TINYINT 1 	0 	subset of objInfoFlag - flags related to goodness of object
+consistencyFlag	dimensionless 	SMALLINT2 	0 	Value computed from associated detections, it is originally given by IPP and should agree with the ODM validation (DROP)
+ra 		degrees 	FLOAT 	8 	NA 	Right Ascension
+dec 		degrees 	FLOAT 	8 	NA 	Declination
+raErr 		arcsec 		REAL 	4 	0.0 	Right Ascension error
+decErr 		arcsec 		REAL 	4 	0.0 	Declination error
+cx              dimensionless	FLOAT 	8 	NA 	Cartesian x
+cy 	        dimensionless	FLOAT 	8 	NA 	Cartesian y
+cz              dimensionless	FLOAT 	8 	NA 	Cartesian z
+lambda 		degrees 	FLOAT 	8 	-999 	ecliptic longitude
+beta 		degrees 	FLOAT 	8 	-999 	ecliptic latitude
+l 		degrees 	FLOAT 	8 	-999 	galactic longitude
+b 		degrees 	FLOAT 	8 	-999 	galactic latitude
+qfPerfect 	dimensionless 	REAL 	4 	-999 	qfPerfect
+dataRelease 	dimensionless 	TINYINT 1 	NA 	Data release Version of this table
+nDetections 	dimensionless 	SMALLINT2 	-999 	total number of detection measurements in all filters
+ng 		dimensionless 	SMALLINT2 	-999 	number of detections in g filter
+nr 		dimensionless 	SMALLINT2 	-999 	number of detections in g filter
+ni 		dimensionless 	SMALLINT2 	-999 	number of detections in g filter
+nz 		dimensionless 	SMALLINT2 	-999 	number of detections in g filter
+ny 		dimensionless 	SMALLINT2 	-999 	number of detections in g filter
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetObject.txt
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetObject.txt	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetObject.txt	(revision 37066)
@@ -0,0 +1,34 @@
+		
+diffObjName      = ipptopsps
+diffObjID	 = dvo / addstar
+diffgcObjID	 = dvo / addstar
+ippObjID  	 = dvo / addstar
+surveyID 	 = ipptopsps
+skyCellID        = smf header
+htmID 		 = PSPS
+zoneID 		 = PSPS
+randomID 	 = ipptopsps
+batchID 	 = ipptopsps
+dvoRegionID      = dvo catID 
+objInfoFlag 	 = average.flags
+qualityFlag 	 = average.flags >> 24 & 0xff (needed??)
+consistencyFlag	 = ?
+ra 		 = dvo / relastro
+dec 		 = dvo / relastro
+raErr 		 = dvo / relastro
+decErr 		 = dvo / relastro
+cx               = PSPS
+cy 	         = PSPS
+cz               = PSPS
+lambda 		 = PSPS
+beta 		 = PSPS
+l 		 = PSPS
+b 		 = PSPS
+qfPerfect 	 = dvo / relphot / secfilt. [XXX Not calculated]
+dataRelease 	 = ipptopsps
+nDetections 	 = dvo / relphot
+ng 		 = dvo / relphot
+nr 		 = dvo / relphot
+ni 		 = dvo / relphot
+nz 		 = dvo / relphot
+ny 		 = dvo / relphot
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetection
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetection	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetection	(revision 37066)
@@ -0,0 +1,71 @@
+
+diffObjID	dimensionless 	BIGINT 	8 	NA 	diff object identifier
+diffgcObjID	dimensionless	BIGINT	8	NA 	ODM galactic coordinates identifier
+diffDetID 	dimensionless 	BIGINT 	8 	NA 	diff detection identifier
+diffDetMetaID 	dimensionless 	BIGINT 	8 	NA 	diff detection meta identifier
+ippDetectID 	dimensionless 	BIGINT 	8 	NA 	ipp detection id generated by IPP
+ippObjID 	dimensionless 	BIGINT 	8 	NA 	ipp object id generated by IPP
+filterID 	dimensionless 	TINYINT	1 	NA 	filter ID: g=1, r=2, i=3, z=4, y=5, w=6, ...
+surveyID 	dimensionless 	TINYINT	1 	NA 	survey flag identifierr
+randomDiffID 	dimensionless 	BIGINT 	8 	NA 	random diff id  
+skyCellID       dimensionless   REAL    4       -999    single float giving PrimaryCell.SkyCell identifier 
+dvoRegionID     dimensionless   INT     4          0    identifier to dvo spatial region
+obsTime 	MeanJulianDays 	FLOAT 	8 	-999 	Time of mid observation of positive detection in Mean Julian Days of positive detection
+xPos 		pixels 		REAL 	4 	-999 	measured x on diff image sky cell PSF fit
+yPos 		pixels 		REAL 	4 	-999 	measured y on diff image sky cell from PSF fit
+xPosErr 	pixels 		REAL 	4 	-999 	estimated error in x
+yPosErr 	pixels 		REAL 	4 	-999 	estimated error in y
+pltScale        arcsec/pix      REAL    4       -999    plate scale at this location (from DVO)
+posAngle        degrees         REAL    4       -999    position angle (sky-to-chip) at this location (from DVO)
+----------------------------------------------------    next 8 came from old DiffDetCalib, zp derived from cpt tables of BOTH images 
+ra              degrees         FLOAT   8       NA      Right Ascension
+dec             degrees         FLOAT   8       NA      Declination
+raErr           arcsec          REAL    4       NA      Right Ascension error -> posErr because RA,Dec same?
+decErr          arcsec          REAL    4       NA      Declination error
+zp              magnitude       REAL    4       0       zeropoint (all that is needed to convert adu/sec to AB mag), no zpErr
+telluricExt     magnitude       REAL    4       NA      estimated extinction due to non-photometric conditions  
+expTime         seconds         REAL    4       -999    exposure time (informational)
+airMass         dimensionless   REAL    4       0       airmass (informational)
+-----------------------------------------------------   attributes of positive detection
+psfFlux 	adu/seconds 	REAL 	4 	-999 	PSF instrumental flux (in analog-to-digital units/sec) or adu/sec
+psfFluxErr 	adu/seconds 	REAL 	4 	-999 	estimated error in flux
+psfMajorFWHM    arcsec          REAL    4       -999    model PSF width in major axis
+psfMinorFWHM    arcsec          REAL    4       -999    model PSF width in minor axis
+psfTheta        degrees         REAL    4       -999    model PSF orientation angle degrees East of North
+psfCore         dimensionless   REAL    4       -999    model PSF core parameter [k in (1 + kz + z^1.66)]
+psfQf 		dimensionless 	REAL 	4 	-999 	PSF coverage factor
+psfQfPerfect 	dimensionless 	REAL 	4 	-999 	PSF-weighted fraction of pixels totally unmasked
+psfChiSq 	dimensionless 	REAL 	4 	-999 	reduced-chisq of the psf model fit. (ndof?, npix?)
+psfLikelihood 	dimensionless 	REAL 	4 	-999 	PSF likelihood
+momentXX 	arcsec^2     	REAL 	4 	-999 	moment XX
+momentXY 	arcsec^2     	REAL 	4 	-999 	moment XY
+momentYY 	arcsec^2     	REAL 	4 	-999 	momeny YY
+momentR1 	arcsec       	REAL 	4 	-999 	first radial moment 
+momentRH 	arcsec       	REAL 	4 	-999 	half light radius   (DROP)
+momentM3C 	arcsec^3     	REAL 	4 	-999 	3rd moment sin(theta) 
+momentM3S 	arcsec^3     	REAL 	4 	-999 	3rd moment cos(theta) 
+momentM4C 	arcsec^4     	REAL 	4 	-999 	4th moment sin(theta)
+momentM4S  	arcsec^4     	REAL 	4 	-999 	4th moment cos(theta) 
+apFlux 		adu/seconds 	REAL 	4 	-999 	Aperture flux
+apFluxErr 	adu/seconds 	REAL 	4 	-999 	Aperture flux error
+apFillF         dimensionless   REAL    4       -999    Aperture fill factor 
+kronFlux 	adu/seconds 	REAL 	4 	-999 	Kron flux
+kronFluxErr 	adu/seconds 	REAL 	4 	-999 	Kron flux error
+kronRad 	raw pixels 	REAL 	4 	-999 	Kron radius
+kronRadErr 	raw pixels 	REAL 	4 	-999 	Kron radius error
+------------------------------------------------------- from diff image cmf/smf files 
+diffNPos        dimensionless   REAL    4       -999    npix > 3sigma
+diffFRatio      dimensionless   REAL    4       -999    fPos/(fPos +fNeg)
+diffNBad        dimensionless   REAL    4       -999    nPos/(nPos+nNeg)
+diffNMask       dimensionless   REAL    4       -999    nPos/(nPos + nMask)
+diffNAll        dimensionless   REAL    4       -999    nPos/(nPos + nMask + nNeg)
+diffPdist       arcsec          REAL    4       -999    distance to positive match source
+diffNdist       arcsec          REAL    4       -999    distance to negative match source
+diffPSN         dimensionless   REAL    4       -999    signal to noise of pos match source
+diffNSN         dimensionless   REAL    4       -999    signal to noise of neg match source
+-------------------------------------------------------
+sky 		adu/sec/pixel 	REAL 	4 	-999 	PSF sky level at source
+skyErr 		adu/sec/pixel 	REAL 	4 	-999 	estimated error in sky
+infoFlag 	dimensionless 	INT     4 	-999 	flag indicating provenance information
+infoFlag2	dimensionless 	INT     4 	-999 	flag indicating provenance information
+dataRelease 	dimensionless 	TINYINT	1 	NA 	Data release when this detection was originally taken. Recalibrations do not affect this value.
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetection.txt
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetection.txt	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetection.txt	(revision 37066)
@@ -0,0 +1,72 @@
+		
+diffObjID	 = dvo / addstar
+diffgcObjID	 = dvo / addstar
+diffDetID 	 = dvo / addstar
+diffDetMetaID 	 = dvo / addstar
+ippDetectID 	 = dvo / addstar
+ippObjID 	 = dvo / addstar
+filterID 	 = smf / ipptopsps
+surveyID 	 = ipptopsps
+randomDiffID 	 = ipptopsps
+skyCellID        = smf header
+dvoRegionID      = dvo / catID
+obsTime 	 = smf
+xPos 		 = smf
+yPos 		 = smf
+xPosErr 	 = smf
+yPosErr 	 = smf
+pltScale         = smf
+posAngle         = smf
+---------------- = 
+ra               = dvo / relastro? [allow / require relastro recalibration?]
+dec              = dvo / relastro?
+raErr            = dvo / relastro?
+decErr           = dvo / relastro?
+zp               = dvo / relphot
+telluricExt      = (zp - zpNominal) dvopsps
+expTime          = smf
+airMass          = smf
+---------------- = 
+psfFlux 	 = smf
+psfFluxErr 	 = smf
+psfMajorFWHM     = [PSF_MAJOR is Sxx parameter, NOT FWHM] [ADD PSF_MAJ_FWHM to smf, keep PSF_MAJOR]
+psfMinorFWHM     = [PSF_MAJOR is Sxx parameter, NOT FWHM] [ditto]
+psfTheta         = smf
+psfCore          = [XXX : not currently written out!!]
+psfQf 		 = smf
+psfQfPerfect 	 = smf
+psfChiSq 	 = smf
+psfLikelihood 	 = ipptopsps
+momentXX 	 = smf
+momentXY 	 = smf
+momentYY 	 = smf
+momentR1 	 = smf
+momentRH 	 = smf [XXX : MOMENTS_RH is NOT half-light radius]
+momentM3C 	 = smf
+momentM3S 	 = smf
+momentM4C 	 = smf
+momentM4S  	 = smf
+apFlux 		 = smf [PS1_DV2 or later]
+apFluxErr 	 = smf [PS1_DV2 or later]
+apFillF          = [XXX : not currently calculated]
+kronFlux 	 = smf
+kronFluxErr 	 = smf
+kronRad 	 = (2.5*R1)
+kronRadErr 	 = [drop this? ]
+---------------- = 
+diffNPos         = smf
+diffFRatio       = smf
+diffNBad         = smf
+diffNMask        = smf
+diffNAll         = smf
+diffPdist        = smf
+diffNdist        = smf
+diffPSN          = smf
+diffNSN          = smf
+---------------- = 
+sky 		 = smf
+skyErr 		 = smf
+infoFlag 	 = smf
+infoFlag2	 = smf
+dataRelease 	 = ipptopsps
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedMeanObject
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedMeanObject	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedMeanObject	(revision 37066)
@@ -0,0 +1,63 @@
+
+objID           dimensionless   BIGINT   8        NA    ODM object identifier index
+gcObjID		dimensionless	BIGINT	 8	  NA 	ODM galactic coordinates identifier
+ippObjID        dimensionless   BIGINT   8        NA    IPP object identifier
+nDetections     dimensionless   SMALLINT 2      -999    total number of detection measurements in all filters
+batchID         dimensionless   BIGINT   8        NA    batch id 
+-----------------------------------------------------   replicate to bottom for each filter
+gStackID        dimensionless   INT      4              stack image id (how to carry through IPP + DVO)
+gnTotal         dimensionless   SMALLINT 2      -999    number of detections in g filter
+gnIncPSFMag     dimensionless   SMALLINT 2      -999    number of detections included in robust psf mean in g filter 
+gnIncKronMag    dimensionless   SMALLINT 2      -999    number of detections included in robust mean of Kron mag in g filter
+gnIncApMag      dimensionless   SMALLINT 2      -999    number of detections included in robust mean of Ap mag in g filter
+gnIncR5         dimensionless   SMALLINT 2      -999    number of detections included in robust mean of ApFlx 5 in g filter
+gnIncR6         dimensionless   SMALLINT 2      -999    number of detections included in robust mean of ApFlx 6 in g filter
+------------------------------------------------------- one of the above also corresponds to the moments
+gPSFMag         AB_magnitude    REAL     4      -999    robust mean g psf AB magnitude (sigma clipping or MAP or go to 5 or 7 number sumary? 1/12 is ~9th percentile 
+gPSFMagErr      AB_magnitude    REAL     4      -999    estimated error of g psf AB magnitude mean (individual errors added in quadrature)
+gPSFMagStd      dimensionless   REAL     4      -999    standard deviation of measurements included in the robust mean  
+gKronMag        AB_magnitude    REAL     4      -999    mean g kron AB magnitude
+gKronMagErr     AB_magnitude    REAL     4      -999    estimated error of g kron AB magnitude mean
+gKronMagStd     dimensionless   REAL     4      -999    standard deviation of measurements included in the robust mean  
+gApMag          AB_magnitude    REAL     4      -999    mean g kron AB magnitude
+gApMagErr       AB_magnitude    REAL     4      -999    estimated error of g kron AB magnitude mean
+gApMagStd       dimensionless   REAL     4      -999    standard deviation of measurements included in the robust mean  
+------------------------------------------------------
+gFmeanflxR5     adu/seconds     REAL     4      -999    Flux inside r = 5 in g unconvolved stack  
+gFmeanflxR5Err  adu/seconds     REAL     4      -999    estimated error is flxR5
+gFmeanflxR5Std  adu/seconds     REAL     4      -999    estimated standard deviation in flxR5
+gFmeanflxR5Fill dimensionless   REAL     4      -999    estimated filling factor at R5
+gFmeanflxR6     adu/seconds     REAL     4      -999    Flux inside r = 6 in g unconvolved stack 
+gFmeanflxR6Err  adu/seconds     REAL     4      -999    estimated error is flxR6
+gFmeanflxR6Std  adu/seconds     REAL     4      -999    estimated standard deviation in flxR6
+gFmeanflxR6Fill dimensionless   REAL     4      -999    estimated filling factor at R6
+gFlags          dimensionless   BIGINT   8        NA    flags for g forced
+------------------------------------------------------
+gLensObjSmearX11 arcsec^-2      REAL     4      -999    per-object smear polarizability X11 term
+gLensObjSmearX12 arcsec^-2      REAL     4      -999    per-object smear polarizability X12 term
+gLensObjSmearX22 arcsec^-2      REAL     4      -999    per-object smear polarizability X22 term
+gLensObjSmearE1  arcsec^-2      REAL     4      -999    per-object smear polarizability E1 term
+gLensObjSmearE2  arcsec^-2      REAL     4      -999    per-object smear polarizability E2 term
+gLensObjShearX11 dimensionless  REAL     4      -999    per-object shear polarizability X11 term
+gLensObjShearX12 dimensionless  REAL     4      -999    per-object shear polarizability X12 term
+gLensObjShearX22 dimensionless  REAL     4      -999    per-object shear polarizability X22 term
+gLensObjShearE1  dimensionless  REAL     4      -999    per-object shear polarizability E1 term
+gLensObjShearE2  dimensionless  REAL     4      -999    per-object shear polarizability E2 term
+gLensPSFSmearX11 arcsec^-2      REAL     4      -999    psf model smear polarizability X11 term
+gLensPSFSmearX12 arcsec^-2      REAL     4      -999    psf model smear polarizability X12 term
+gLensPSFSmearX22 arcsec^-2      REAL     4      -999    psf model smear polarizability X22 term
+gLensPSFSmearE1  arcsec^-2      REAL     4      -999    psf model smear polarizability E1 term
+gLensPSFSmearE2  arcsec^-2      REAL     4      -999    psf model smear polarizability E2 term
+gLensPSFShearX11 dimensionless  REAL     4      -999    psf model shear polarizability X11 term
+gLensPSFShearX12 dimensionless  REAL     4      -999    psf model shear polarizability X12 term
+gLensPSFShearX22 dimensionless  REAL     4      -999    psf model shear polarizability X22 term
+gLensPSFShearE1  dimensionless  REAL     4      -999    psf model shear polarizability E1 term
+gLensPSFShearE2  dimensionless  REAL     4      -999    psf model shear polarizability E2 term
+------------------------------------------------------
+gGamma           arcsec^2       REAL     4      -999    second moment (Mxx + Myy)
+gE1              dimensionless  REAL     4      -999    polarization, KSB-corrected (Mxx - Myy) / (Mxx + Myy)
+gE2              dimensionless  REAL     4      -999    polarization, KSB-corrected 2Mxy / (Mxx + Myy)
+
+-- duplicated for other filters
+-- [184 byte/obj/filter + 22 byte/obj]
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedMeanObject.txt
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedMeanObject.txt	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedMeanObject.txt	(revision 37066)
@@ -0,0 +1,70 @@
+		 
+objID            = dvo / addstar
+gcobjID          = dvo / addstar
+ippObjID         = dvo / addstar
+nDetections      = dvo / addstar
+batchID          = dvo / addstar
+---------------- = 
+gStackID         = 
+gnTotal          = 
+gnIncPSFMag      = 
+gnIncKronMag     = 
+gnIncApMag       = 
+gnIncR5          = 
+gnIncR6          = 
+---------------- = 
+gPSFMag          = 
+gPSFMagErr       = 
+gPSFMagStd       = 
+gKronMag         = 
+gKronMagErr      = 
+gKronMagStd      = 
+gApMag           = 
+gApMagErr        = 
+gApMagStd        = 
+---------------- = 
+gFmeanflxR5      = 
+gFmeanflxR5Err   = 
+gFmeanflxR5Std   = 
+gFmeanflxR5Fill  = 
+gFmeanflxR6      = 
+gFmeanflxR6Err   = 
+gFmeanflxR6Std   = 
+gFmeanflxR6Fill  = 
+gFlags           = 
+---------------- = 
+gLensObjSmearX11 = 
+gLensObjSmearX12 = 
+gLensObjSmearX22 = 
+gLensObjSmearE1  = 
+gLensObjSmearE2  = 
+gLensObjShearX11 = 
+gLensObjShearX12 = 
+gLensObjShearX22 = 
+gLensObjShearE1  = 
+gLensObjShearE2  = 
+gLensPSFSmearX11 = 
+gLensPSFSmearX12 = 
+gLensPSFSmearX22 = 
+gLensPSFSmearE1  = 
+gLensPSFSmearE2  = 
+gLensPSFShearX11 = 
+gLensPSFShearX12 = 
+gLensPSFShearX22 = 
+gLensPSFShearE1  = 
+gLensPSFShearE2  = 
+---------------- = 
+gGamma           = 
+gE1              = 
+gE2              = 
+
+[NOTES:
+
+ * PSF Mag, Kron Mag, Ap Mag stats are all 
+   calculated from values in the existing Measure table
+
+   XXX : no! we need to record fluxes, not mags
+
+ * R5 & R6 ap flux values & lensing parameters need
+   a new table
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedWarpMeasurement
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedWarpMeasurement	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedWarpMeasurement	(revision 37066)
@@ -0,0 +1,82 @@
+objID           dimensionless   BIGINT  8       NA      ODM object identifier
+gcObjID		dimensionless	BIGINT	8	NA 	ODM galactic coordinates identifier
+detectID        dimensionless   BIGINT  8       NA      ODM detection identifier
+ippObjID        dimensionless   BIGINT  8       NA      ippobject id generated by IPP
+ippDetectID     dimensionless   BIGINT  8       NA      detection id generated by IPP
+filterID        dimensionless   TINYINT 1       NA      filter ID: g=1, r=2, i=3, z=4, y=5, w=6, ...
+surveyID        dimensionless   TINYINT 1       NA      survey flag identifier
+forcedWarpID    dimensionless   BIGINT  8       NA      IPP warp_id
+randomWarpID    dimensionless   BIGINT  8       NA      Random warp_id
+skyCellID       dimensionless   REAL    4       -999    single float giving PrimaryCell.SkyCell identifier 
+dvoRegionID     dimensionless   INT     4       -999    identifier to dvo spatial region
+obsTime         MeanJulianDays  FLOAT   8       -999    Time of mid observation in Mean Julian Days
+------------------------------------------------------ 
+zp              magnitude       REAL    4       0       zeropoint (only thing needed to convert adu/sec to AB mag), note no zpErr
+telluricExt     magnitude       REAL    4       NA      estimated extinction due to non-photometric conditions  
+expTime         seconds         REAL    4       -999    exposure time (informational)
+airMass         dimensionless   REAL    4       0       airmass (informational)
+------------------------------------------------------ 
+psfFlux         adu/seconds     REAL    4       -999    PSF instrumental flux (in analog-to-digital units/sec) or adu/sec
+psfFluxErr      adu/seconds     REAL    4       -999    estimated error in flux
+psfMajorFWHM    arcsec          REAL    4       -999    model PSF width in major axis
+psfMinorFWHM    arcsec          REAL    4       -999    model PSF width in minor axis
+psfTheta        degrees         REAL    4       -999    model PSF orientation angle degrees East of North
+psfCore         dimensionless   REAL    4       -999    model PSF core parameter [k in (1 + kz + z^1.66)]
+psfQf           dimensionless   REAL    4       -999    PSF coverage factor
+psfQfPerfect    dimensionless   REAL    4       -999    PSF-weighted fraction of pixels totally unmasked
+psfChiSq        dimensionless   REAL    4       -999    reduced-chisq of the psf model fit. (ndof?, npix?)
+psfLikelihood   dimensionless   REAL    4       -999    PSF likelihood
+momentXX        arcsec^2        REAL    4       -999    moment XX
+momentXY        arcsec^2        REAL    4       -999    moment XY
+momentYY        arcsec^2        REAL    4       -999    momeny YY
+momentR1        arcsec^1        REAL    4       -999    first radial moment 
+momentRH        arcsec          REAL    4       -999    to be half light radius   (DROP)
+momentM3C       arcsec^3        REAL    4       -999    3rd moment sin(theta) 
+momentM3S       arcsec^3        REAL    4       -999    3rd moment cos(theta) 
+momentM4C       arcsec^4        REAL    4       -999    4th moment sin(theta)
+momentM4S       arcsec^4        REAL    4       -999    4th moment cos(theta) 
+
+lensObjSmearX11 arcsec^-2       REAL    4       -999    per-object smear polarizability X11 term
+lensObjSmearX12 arcsec^-2       REAL    4       -999    per-object smear polarizability X12 term
+lensObjSmearX22 arcsec^-2       REAL    4       -999    per-object smear polarizability X22 term
+lensObjSmearE1  arcsec^-2       REAL    4       -999    per-object smear polarizability E1 term
+lensObjSmearE2  arcsec^-2       REAL    4       -999    per-object smear polarizability E2 term
+lensObjShearX11 dimensionless   REAL    4       -999    per-object shear polarizability X11 term
+lensObjShearX12 dimensionless   REAL    4       -999    per-object shear polarizability X12 term
+lensObjShearX22 dimensionless   REAL    4       -999    per-object shear polarizability X22 term
+lensObjShearE1  dimensionless   REAL    4       -999    per-object shear polarizability E1 term
+lensObjShearE2  dimensionless   REAL    4       -999    per-object shear polarizability E2 term
+lensPSFSmearX11 arcsec^-2       REAL    4       -999    psf model smear polarizability X11 term
+lensPSFSmearX12 arcsec^-2       REAL    4       -999    psf model smear polarizability X12 term
+lensPSFSmearX22 arcsec^-2       REAL    4       -999    psf model smear polarizability X22 term
+lensPSFSmearE1  arcsec^-2       REAL    4       -999    psf model smear polarizability E1 term
+lensPSFSmearE2  arcsec^-2       REAL    4       -999    psf model smear polarizability E2 term
+lensPSFShearX11 dimensionless   REAL    4       -999    psf model shear polarizability X11 term
+lensPSFShearX12 dimensionless   REAL    4       -999    psf model shear polarizability X12 term
+lensPSFShearX22 dimensionless   REAL    4       -999    psf model shear polarizability X22 term
+lensPSFShearE1  dimensionless   REAL    4       -999    psf model shear polarizability E1 term
+lensPSFShearE2  dimensionless   REAL    4       -999    psf model shear polarizability E2 term
+
+apFlux          adu/seconds     REAL    4       -999    Aperture flux
+apFluxErr       adu/seconds     REAL    4       -999    Aperture flux error
+apFillF         dimensionless   REAL    4       -999    Aperture fill factor 
+kronFlux        adu/seconds     REAL    4       -999    Kron flux
+kronFluxErr     adu/seconds     REAL    4       -999    Kron flux error
+kronRad         arcsec          REAL    4       -999    Kron radius
+kronRadErr      arcsed          REAL    4       -999    Kron radius error
+------------------------------------------------------ 
+flxR5           adu/seconds     REAL    4       -999    Flux inside r = 5
+flxR5Err        adu/seconds     REAL    4       -999    estimated error is flxR5
+flxR5Std        adu/seconds     REAL    4       -999    estimated standard deviation in flxR5
+flxR5Fill       dimensionless   REAL    4       -999    estimated filling factor at R5
+flxR6           adu/seconds     REAL    4       -999    Flux inside r = 6
+flxR6Err        adu/seconds     REAL    4       -999    estimated error is flxR6
+flxR6Std        adu/seconds     REAL    4       -999    estimated standard deviation in flxR6
+flxR6Fill       dimensionless   REAL    4       -999    estimated filling factor at R6
+------------------------------------------------------ 
+sky             adu/sec/pixel   REAL    4       -999    PSF sky level at source
+skyErr          adu/sec/pixel   REAL    4       -999    estimated error in sky
+infoFlag        dimensionless   BIGINT  8       -999    flag indicating provenance information
+dataRelease     dimensionless   TINYINT 1       NA      Data release when this detection was originally taken. Recalibrations do not affect this value.
+
+-- [295 byte/det]
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedWarpMeasurement.txt
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedWarpMeasurement.txt	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedWarpMeasurement.txt	(revision 37066)
@@ -0,0 +1,81 @@
+
+objID            = dvo/addstar
+gcObjID          = dvo/addstar
+detectID         = dvo/addstar
+ippObjID         = dvo/addstar
+ippDetectID      = dvo/addstar
+filterID         = 
+surveyID         = 
+forcedWarpID     = 
+randomWarpID     = 
+skyCellID        = 
+dvoRegionID      = 
+obsTime          = smf
+---------------- = 
+zp               = smf
+telluricExt      = (zp - zpNominal)
+expTime          = smf
+airMass          = smf
+---------------- = 
+psfFlux          = smf
+psfFluxErr       = smf
+psfMajorFWHM     = smf [PSF_MAJOR is Sxx parameter, NOT FWHM]
+psfMinorFWHM     = smf [PSF_MAJOR is Sxx parameter, NOT FWHM]
+psfTheta         = smf
+psfCore          = smf [XXX : not currently written out!!]
+psfQf            = smf
+psfQfPerfect     = smf
+psfChiSq         = smf
+psfLikelihood    = ipptopsps
+momentXX         = smf
+momentXY         = smf
+momentYY         = smf
+momentR1         = smf
+momentRH         = smf [XXX : MOMENTS_RH is NOT half-light radius]
+momentM3C        = smf
+momentM3S        = smf
+momentM4C        = smf
+momentM4S        = smf
+		 = 
+lensObjSmearX11  = smf [PS1_V5]
+lensObjSmearX12  = smf [PS1_V5]
+lensObjSmearX22  = smf [PS1_V5]
+lensObjSmearE1   = smf [PS1_V5]
+lensObjSmearE2   = smf [PS1_V5]
+lensObjShearX11  = smf [PS1_V5]
+lensObjShearX12  = smf [PS1_V5]
+lensObjShearX22  = smf [PS1_V5]
+lensObjShearE1   = smf [PS1_V5]
+lensObjShearE2   = smf [PS1_V5]
+lensPSFSmearX11  = smf [PS1_V5]
+lensPSFSmearX12  = smf [PS1_V5]
+lensPSFSmearX22  = smf [PS1_V5]
+lensPSFSmearE1   = smf [PS1_V5]
+lensPSFSmearE2   = smf [PS1_V5]
+lensPSFShearX11  = smf [PS1_V5]
+lensPSFShearX12  = smf [PS1_V5]
+lensPSFShearX22  = smf [PS1_V5]
+lensPSFShearE1   = smf [PS1_V5]
+lensPSFShearE2   = smf [PS1_V5]
+		 = 
+apFlux           = smf [PS1_V4]
+apFluxErr        = smf [PS1_V4]
+apFillF          = smf [EAM: add to smf output]
+kronFlux         = smf
+kronFluxErr      = smf
+kronRad          = (2.5*R1)
+kronRadErr       = [drop : not currently calculated]
+---------------- = 
+flxR5            = smf [?? calculated?]
+flxR5Err         = smf [?? calculated?]
+flxR5Std         = smf [?? calculated?]
+flxR5Fill        = smf [?? calculated?]
+flxR6            = smf [?? calculated?]
+flxR6Err         = smf [?? calculated?]
+flxR6Std         = smf [?? calculated?]
+flxR6Fill        = smf [?? calculated?]
+---------------- = 
+sky              = smf
+skyErr           = smf
+infoFlag         = 
+dataRelease      = 
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/MeanObject
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/MeanObject	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/MeanObject	(revision 37066)
@@ -0,0 +1,27 @@
+             
+--              The  "best available" measurements refer first to those objects with qfPerfect > 0.85 and good flags, 
+--              but descends down a "waterfall logic" in ipp so that there exists a mean mag for less than ideal objects. The logic is given in Magnier etal 2013.
+
+objID           dimensionless   BIGINT   8       NA      ODM object identifier index
+gcObjID		dimensionless	BIGINT	 8	 NA 	ODM galactic coordinates identifier
+gQfPerfect      dimensionless   REAL     4       -999    maximum psf qfPerfect from best available g band detections 
+gMeanPSFMag     AB_magnitude    REAL     4       -999    mean g psf AB magnitude from best available measurements (best available as current defined by ipp "waterfall logic"  
+gMeanPSFMagErr  AB_magnitude    REAL     4       -999    estimated error of best availalbe g-band psf AB magnitudes (individual errors added in quadrature)
+gnIncPSFMag     dimensionless   SMALLINT 2       -999    number of best available detections included in mean psfMag 
+gMeanPSFMagStd  dimensioless    REAL     4       -999    standard deviation of best available measurements - compared with MeanErr this is one measure of true variability  
+gMinPSFMag      AB_magnitude    REAL     4       -999    minimum best available PSFMag - min and max are given for PSFMag as they may indicate variability.  
+gMaxPSFMag      AB_magnitude    REAL     4       -999    maximum best available PSFMag   
+					 
+gMeanKronMag    AB_magnitude    REAL     4       -999    mean g kron AB magnitude from best available measurements     
+gMeanKronMagErr AB_magnitude    REAL     4       -999    estimated error of mean g kron AB magnitude 
+gnIncKronMag    dimensionless   SMALLINT 2       -999    number of best available detections included mean Kron mag 
+gMeanKronMagStd dimensioless    REAL     4       -999    standard deviation of best available measurements   
+					 
+gMeanApMag      AB_magnitude    REAL     4       -999    mean g kron AB magnitude from best available measurements
+gMeanApMagErr   AB_magnitude    REAL     4       -999    estimated error of g kron AB magnitude mean
+gnIncApMag      dimensionless   SMALLINT 2       -999    number of detections included in best available mean of Kron mag in g filter
+gMeanApMagStd   dimensioless    REAL     4       -999    standard deviation of best available measurements   
+gFlags          dimensionless   BIGINT   8       NA      flags for g mean
+-- duplicate for other filters
+
+[62 byte/obj/filter + 8 byte/filter]
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/MeanObject.txt
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/MeanObject.txt	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/MeanObject.txt	(revision 37066)
@@ -0,0 +1,25 @@
+
+
+
+
+objID           = dvo / addstar
+gcObjID         = dvo / addstar
+gQfPerfect      = dvo / relphot / secfilt. [XXX Not calculated]
+gMeanPSFMag     = dvo / relphot / secfilt.M 
+gMeanPSFMagErr  = dvo / relphot / secfilt.dM
+gnIncPSFMag     = dvo / relphot / secfilt.Nused [XXX : ensure .Nused matches .M]
+gMeanPSFMagStd  = dvo / relphot / secfilt.Mstdev 
+gMinPSFMag      = dvo / relphot / secfilt.Min [XXX: replace M_20, M_80 with Min, Max]
+gMaxPSFMag      = dvo / relphot / secfilt.Max [XXX: replace M_20, M_80 with Min, Max]
+		= 
+gMeanKronMag    = dvo / relphot / secfilt.Mkron 
+gMeanKronMagErr = dvo / relphot / secfilt.dMkron
+gnIncKronMag    = dvo / relphot / secfilt.nMkron [XXX : not calculated]
+gMeanKronMagStd = dvo / relphot / secfilt.MstdevKron [XXX : not calculated]
+		= 
+gMeanApMag      = dvo / relphot / secfilt.Map
+gMeanApMagErr   = dvo / relphot / secfilt.? [XXX : not calculated]
+gnIncApMag      = dvo / relphot / secfilt.? [XXX : not calculated]
+gMeanApMagStd   = dvo / relphot / secfilt.? [XXX : not calculated]
+
+gFlags          = dvo / relphot / secfilt.flags
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ObjectThin
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ObjectThin	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ObjectThin	(revision 37066)
@@ -0,0 +1,51 @@
+
+objName          string         VAR      8      NA      IAU Name constructed from objID postion PS1.x JHHMMSS.SS+/-DDMMSS.S where x is leading number of procesing version       
+objID            dimensionless  BIGINT   8      NA      ODM object identifier index
+gcObjID		 dimensionless	BIGINT	8	  NA 	ODM galactic coordinates identifier
+ippObjID         dimensionless  BIGINT   8      NA      IPP object number
+surveyID         dimensionless  TINYINT  1      255     Survey ID
+skyCellID        dimensionless  REAL     4      -999     single float giving PrimaryCell.SkyCell identifier
+htmID            dimensionless  BIGINT   8      NA      HTM index
+zoneID           dimensionless  INT      4      NA      Zone index
+randomID         dimensionless  BIGINT   8      0       Random integer between 0 and 2^32 = 4,394,967,296 remaining ramdom integer 0  
+batchID          dimensionless  BIGINT   8      -999    batch id        
+dvoRegionID      dimensionless  INT      4      -999    identifier of dvo spatial region - dvo cat id
+dataRelease      dimensionless  TINYINT  1      NA      Data release Version of this table
+objInfoFlag      dimensionless  BIGINT   8      -999    flag indicating odd properties
+qualityFlag      dimensionless  TINYINT  1      0       subset of objInfoFlag - flags related to goodness of object
+consistencyFlag  dimensionless  SMALLINT 2      0       Value computed from associated detections, it is originally given by IPP and should agree with the ODM validation (DROP)
+raStack          degrees        FLOAT    8      -999    Right Ascension - best weighted RA across filters from stack WHENEVER an object is detected in the stack  
+decStack         degrees        FLOAT    8      -999    Declination - best weighted Dec across filters from stack WHENEVER an object is detected in the stack 
+raStackErr       arcsec         REAL     4      -999    Error in stack Right Ascension, note will have a systematic floor, and is not necessary the best ra,dec for all objects 
+decStackErr      arcsec         REAL     4      -999    Error in stack Declination, note will have a systematic floor, and is not necessarily the best ra,dec for all objects
+raMean           degrees        FLOAT    8      -999    Right Ascension from the Mean of RA from individual detections if it exists. This is for information only  
+decMean          degrees        FLOAT    8      -999    Declination from the Mean of Dec from individual detections if it exists  This is for information only.  
+raMeanErr        arcsec         REAL     4      -999    Combination of the measurement Errors in the Right Ascension from the mean detections if they exist 
+decMeanErr       arcsec         REAL     4      -999    Combination of the measurement Errors in the  Declination measurements if they exist  
+raMeanStd        arcsec         Real     4      -999    standard deviation of Right Ascension measurements in detections if they exist 
+decMeanStd       arcsec         REAL     4      -999    standard deviation of the  Declination measurements if they exist  
+--------------------------------------------------------------------------------------------------------
+--                                                      Note: the following three sets of coordinate systems are based on stack if it exists, and mean if it does not.
+--                                                      This means cone or box searches work on the stack and consistent with Primary and Best stack detection.
+--                                                      For objects without a stack postion, (moving, transient, or false dectection) a cone search may be incomplete for
+--                                                      an object within less than 1 arc sec of the boundary edge. But science cases here will want to work from Detection
+--                                                      Table anyway, or can vary cone search by 1'' radius to check for incompleteness.  
+cx               dimensionless  FLOAT    8      NA      Cartesian x from Stack RA,Dec WHENEVER a stack detection exists, and Mean RA, Dec (mean of one?) when it doesn't 
+cy               dimensionless  FLOAT    8      NA      Cartesian y from Stack RA,Dec WHENEVER a stack detection exists, and mean RA, Dec (mean of one?) when it doesn't 
+cz               dimensionless  FLOAT    8      NA      Cartesian z from Stack RA,Dec WHENEVER a stack detection exists, ditto
+lambda           degrees        FLOAT    8      -999    ecliptic longitude from Stack RA,Dec WHENEVER A STACK MEASURMENT EXISTS and Mean RA,Dec (mean of one?) otherwise 
+beta             degrees        FLOAT    8      -999    ecliptic latitude ditto
+l                degrees        FLOAT    8      -999    galactic longitude ditto
+b                degrees        FLOAT    8      -999    galactic latitude ditto
+---------------------------------------------------------------------------------
+nStackObjectRows dimensionless  SMALLINT 2      -999    number of independent StackObjectRows this object has. 
+--                                                      zero if not detected in the Stack, 1 if there is a primary, 2 or more if it is in an overlap region
+nStackDetections dimensionless  TINYINT  2       255    which filter bands it is detected in (not forced) or if it was masked in a band.        
+nDetections      dimensionless  SMALLINT 2      -999    total number of detection measurements in all filters
+ng               dimensionless  SMALLINT 2      -999    number of detections in individual g filter exposures
+nr               dimensionless  SMALLINT 2      -999    number of detections in individual r filter exposures
+ni               dimensionless  SMALLINT 2      -999    number of detections in individual i filter exposures
+nz               dimensionless  SMALLINT 2      -999    number of detections in individual z filter exposures
+ny               dimensionless  SMALLINT 2      -999    number of detections in individual y filter exposures
+
+-- [197 byte/obj]
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ObjectThin.txt
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ObjectThin.txt	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ObjectThin.txt	(revision 37066)
@@ -0,0 +1,49 @@
+
+objName           = ipptopsps
+objID             = dvo / addstar
+gcobjID           = dvo / addstar
+ippObjID          = dvo / addstar
+surveyID          = ipptopsps
+skyCellID         = smf header
+htmID             = PSPS
+zoneID            = PSPS
+randomID          = ipptopsps
+batchID           = ipptopsps
+dvoRegionID       = dvo / catID
+dataRelease       = ipptopsps
+objInfoFlag       = dvo / relastro,relphot [define]
+qualityFlag       = dvo / relastro,relphot [define]
+consistencyFlag   = ipptopsps?
+raStack           = dvo / allow recalibration? [ADD to average.d]
+decStack          = dvo / allow recalibration?
+raStackErr        = dvo / allow recalibration?
+decStackErr       = dvo / allow recalibration?
+raMean            = dvo / relastro
+decMean           = dvo / relastro
+raMeanErr         = dvo / relastro
+decMeanErr        = dvo / relastro
+raMeanStd         = dvo / relastro
+decMeanStd        = dvo / relastro
+----------------- = 
+--                = 
+--                = 
+--                = 
+--                = 
+--                = 
+cx                = PSPS
+cy                = PSPS
+cz                = PSPS
+lambda            = PSPS
+beta              = PSPS
+l                 = PSPS
+b                 = PSPS
+----------------- = 
+nStackObjectRows  = dvo [ADD to average.d]
+--                = 
+nStackDetections  = dvo / relphot [Sum of not-forced stack detections]
+nDetections       = dvo / relphot [Sum of ng+nr, etc?]
+ng                = dvo / relphot [Sum of GPC1.g.XY?? measure.d]
+nr                = dvo / relphot [ditto]
+ni                = dvo / relphot
+nz                = dvo / relphot
+ny                = dvo / relphot
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackApFlx
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackApFlx	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackApFlx	(revision 37066)
@@ -0,0 +1,60 @@
+
+objID            dimensionless  BIGINT  8       NA      ODM object identifier
+gcObjID	  	 dimensionless	BIGINT	8	NA 	ODM galactic coordinates identifier
+ippObjID         dimensionless  BIGINT  8       NA      ipp object identifier
+surveyID         dimensionless  TINYINT 1       0       stack type identifier
+skyCellID        dimensionless  REAL    4       -999    single float giving PrimaryCell.SkyCell identifier 
+randomStackObjID dimensionless  BIGINT  8       NA      random stack id
+stackDetectRowID dimensionless  BIGINT  8       NA      identifies which of up to 5 possible stackdetctions this Row refers to: Primary, up to 3 Secondary, 1 best  
+primaryDetection dimensionless  TINYINT 1       255     identifies if this row is a primary stack detection. True about 80% of time. 
+bestDetection    dimensionless  TINYINT 1       255     identifies if this row is a best detection or not. Also set if only a primary detection exists.   
+--                                                      the Primary Dectection, 0 to 3 possible secondary dectections, and the "best" per filter.  
+dvoRegionID     dimensionless   INT    4       -999    identifier to dvo spatial region
+dataRelease     dimensionless   TINYINT 1       NA      Data release when this table was loaded.
+------------------------------------------------------- replicate to end for each filter g,r,i,z,y
+gippDetectID    dimensionless   BIGINT  8       NA      stack identifier
+gstackDetectID  dimensionless   BIGINT  8       NA      ODM detection identifier
+gstackMetaID    dimensionless   BIGINT  8       NA      stack identifier
+--------------------------------------------------------unconvolved
+gflxR3          adu/seconds     REAL    4       -999    Flux inside r = 3
+gflxR3Err       adu/seconds     REAL    4       -999    estimated error is flxR3
+gflxR3Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR3
+gflxR3Fill      dimensionless   REAL    4       -999    estimated filling factor at R3
+gflxR4          adu/seconds     REAL    4       -999    Flux inside r = 4
+gflxR4Err       adu/seconds     REAL    4       -999    estimated error is flxR4
+gflxR4Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR4
+gflxR4Fill      dimensionless   REAL    4       -999    estimated filling factor at R4
+gflxR5          adu/seconds     REAL    4       -999    Flux inside r = 5
+gflxR5Err       adu/seconds     REAL    4       -999    estimated error is flxR5
+gflxR5Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR5
+gflxR5Fill      dimensionless   REAL    4       -999    estimated filling factor at R5
+----------------------------------------------------    convolved across all bands to 6 or 8 pixels
+gc1flxR3        adu/seconds     REAL    4       -999    Flux inside r = 3
+gc1flxR3Err     adu/seconds     REAL    4       -999    estimated error is c1flxR3
+gc1flxR3Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR3
+gc1flxR3Fill    dimensionless   REAL    4       -999    estimated filling factor at R3
+gc1flxR4        adu/seconds     REAL    4       -999    Flux inside r = 4
+gc1flxR4Err     adu/seconds     REAL    4       -999    estimated error is c1flxR4
+gc1flxR4Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR4
+gc1flxR4Fill    dimensionless   REAL    4       -999    estimated filling factor at R4
+gc1flxR5        adu/seconds     REAL    4       -999    Flux inside r = 5
+gc1flxR5Err     adu/seconds     REAL    4       -999    estimated error is c1flxR5
+gc1flxR5Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR5
+gc1flxR5Fill    dimensionless   REAL    4       -999    estimated filling factor at R5
+----------------------------------------------------    convolved across all bands to 6 or 8 pixels
+gc2flxR3        adu/seconds     REAL    4       -999    Flux inside r = 3
+gc2flxR3Err     adu/seconds     REAL    4       -999    estimated error in c2flxR3
+gc2flxR3Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR3
+gc2flxR3Fill    dimensionless   REAL    4       -999    estimated filling factor at R3
+gc2flxR4        adu/seconds     REAL    4       -999    Flux inside r = 4
+gc2flxR4Err     adu/seconds     REAL    4       -999    estimated error in c2flxR4
+gc2flxR4Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR4
+gc2flxR4Fill    dimensionless   REAL    4       -999    estimated filling factor at R4
+gc2flxR5        adu/seconds     REAL    4       -999    Flux inside r = 5
+gc2flxR5Err     adu/seconds     REAL    4       -999    estimated error in c2flxR5
+gc2flxR5Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR5
+gc2flxR5Fill    dimensionless   REAL    4       -999    estimated filling factor at R5
+
+-- repeat for other filters with appropriate leading prefex.
+-- [168 byte/filter/obj + 44 byte/obj]
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackApFlx.txt
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackApFlx.txt	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackApFlx.txt	(revision 37066)
@@ -0,0 +1,56 @@
+
+objID            = dvo/addstar
+gcObjID          = dvo/addstar
+ippObjID         = dvo/addstar average.objID + (average.catID << 32)
+surveyID         = ipptopsps
+skyCellID        = smf header
+randomStackObjID = ipptopsps
+stackDetectRowID = PSPS ?
+primaryDetection = dvo
+bestDetection    = dvo
+--               = 
+dvoRegionID      = dvo / catID
+dataRelease      = ipptopsps
+---------------- = 
+gippDetectID     = dvo/addstar
+gstackDetectID   = dvopsps (see StackObject.txt)
+gstackMetaID     = dvopsps (see StackObject.txt)
+---------------- = 
+gflxR3           = smf
+gflxR3Err        = smf
+gflxR3Std        = smf
+gflxR3Fill       = smf
+gflxR4           = smf
+gflxR4Err        = smf
+gflxR4Std        = smf
+gflxR4Fill       = smf
+gflxR5           = smf
+gflxR5Err        = smf
+gflxR5Std        = smf
+gflxR5Fill       = smf
+---------------- = 
+gc1flxR3         = smf
+gc1flxR3Err      = smf
+gc1flxR3Std      = smf
+gc1flxR3Fill     = smf
+gc1flxR4         = smf
+gc1flxR4Err      = smf
+gc1flxR4Std      = smf
+gc1flxR4Fill     = smf
+gc1flxR5         = smf
+gc1flxR5Err      = smf
+gc1flxR5Std      = smf
+gc1flxR5Fill     = smf
+---------------- = 
+gc2flxR3         = smf
+gc2flxR3Err      = smf
+gc2flxR3Std      = smf
+gc2flxR3Fill     = smf
+gc2flxR4         = smf
+gc2flxR4Err      = smf
+gc2flxR4Std      = smf
+gc2flxR4Fill     = smf
+gc2flxR5         = smf
+gc2flxR5Err      = smf
+gc2flxR5Std      = smf
+gc2flxR5Fill     = smf
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFit
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFit	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFit	(revision 37066)
@@ -0,0 +1,209 @@
+
+objID            dimensionless  BIGINT  8       NA      ODM object identifier
+gcObjID		 dimensionless	BIGINT	8	NA 	ODM galactic coordinates identifier
+ippObjID         dimensionless  BIGINT  8       NA      ipp object identifier
+surveyID         dimensionless  TINYINT 1       NA      survey flag identifier
+skyCellID        dimensionless  REAL    4       -999    single float giving PrimaryCell.SkyCell identifier 
+randomStackObjID dimensionless  BIGINT  8       NA      random stack id
+stackDetectRowID dimensionless  BIGINT  8       NA      identifies which of up to 5 possible stackdetctions this Row refers to: Primary, up to 3 Secondary, 1 best  
+primaryDetection dimensionless  TINYINT 1       255     identifies if this row is a primary stack detection. True about 80% of time. 
+bestDetection    dimensionless  TINYINT 1       255     identifies if this row is a best detection or not. Also set if only a primary detection exists.   
+--                                                      the Primary Dectection, 0 to 3 possible secondary dectections, and the "best" per filter.  
+dvoRegionID      dimensionless  INT     4       -999    identifier to dvo spatial region
+dataRelease      dimensionless  TINYINT 1       NA      Data release when this table was loaded
+-------------------------------------------------------- replicate below for all filters (grizy)
+gS2             dimensionless   REAL    4       -999    (un)smoothness (Cheng 2012, Simard 2002)
+glogRT		dimensionless   REAL    4       -999    total residual (from ellipcally symmetric model)
+glogRA		dimensionless   REAL    4       -999    asymmetric residual (from ellipcally symmetric model)
+glogC           dimensionless   REAL    4       -999    concentration index  (Petrosian R_50 / R_90)
+glogA           dimensionless   REAL    4       -999    log of asymmetry index (Gyory & Bell 2010)
+gbumpy          dimensionless   REAL    4       -999    Blakeslee bumpiness
+ghalfLightRad   arcsec          REAL    4       -999    half-light radius
+-------------------------------------------------------- replicate below for all filters (grizy)
+gippDetectID    dimensionless   BIGINT  8       NA      ipp detect identifier
+gstackDetectID  dimensionless   BIGINT  8       NA      ODM detection identifier
+gstackMetaID    dimensionless   BIGINT  8       NA      stack identifier
+----------------------------------------------------------------------------------------
+gdeVRadius      arcsec          REAL    4       -999    deVaucouleurs radius
+gdeVRadiusErr   arcsec          REAL    4       -999    estimated error in deVaucouleurs radius
+gdeVFlux        adu/seconds     REAL    4       -999    deVaucouleurs flux
+gdeVFluxErr     adu/seconds     REAL    4       -999    estimated error in deVaucouleurs flux
+gdeVAb          dimensionless   REAL    4       -999    deVaucoulerus axis ratio
+gdeVAbErr       dimensionless   REAL    4       -999    estimated error in deVaucoulerus axis ratio
+gdeVPhi         degrees         REAL    4       -999    estmated phi of deVaucouleurs axis. Degrees East of North.
+gdeVPhiErr      degrees         REAL    4       -999    estmated error of phi of deVaucouleurs axis
+graDeVOff       arcsec          REAL    4       -999    Offset in RA of deVaucouleurs fit from PSF RA
+gdecDeVOff      arcsec          REAL    4       -999    Offset in DEC of deVaucouleurs fit from PSF DEC
+graDeVOffErr    arcsec          REAL    4       -999    estimated error in ra offset
+gdecDeVOffErr   arcsec          REAL    4       -999    estimated error in dec offset
+gdeVCf          dimensionless   REAL    4       -999    deVaucouleurs fit coverage factor
+gdeVLikelihood  dimensionless   REAL    4       -999    deVaucouleurs fit likelihood factor
+----------------------------------------------------------------------------------------
+gexpRadius      arcsec          REAL    4       -999    Exponential fit radius
+gexpRadiusErr   arcsec          REAL    4       -999    estimated error in Exponential fit radius
+gexpFlux        adu/seconds     REAL    4       -999    Exponential fit flux
+gexpFluxErr     adu/seconds     REAL    4       -999    estimated error in expFlux
+gexpAb          dimensionless   REAL    4       -999    Exponential fit axis ratio
+gexpAbErr       dimensionless   REAL    4       -999    estimated error in Exponential fit axis ratio
+gexpPhi         degrees         REAL    4       -999    estmated phi of Exponential axis
+gexpPhiErr      degrees         REAL    4       -999    estmated error of phi of Exponential axis
+graExpOff       dimensionless   REAL    4       -999    Offset in RA of Exponential fit from PSF RA
+gdecExpOff      dimensionless   REAL    4       -999    Offset in DEC of Exponential fit from PSF DEC
+graExpOffErr    dimensionless   REAL    4       -999    estimated error in raExpOff
+gdecExpOffErr   dimensionless   REAL    4       -999    estimated error in decExpOff
+gexpCf          dimensionless   REAL    4       -999    Exponential fit coverage factor
+gexpLikelihood  dimensionless   REAL    4       -999    Exponential fit likelihood factor
+---------------------------------------------------------------------------------------
+gserRadius      arcsec          REAL    4       -999    Sersic radius
+gserRadiusErr   arcsed          REAL    4       -999    estimated error in Sersic radius
+gserFlux        adu/seconds     REAL    4       -999    Sersic Flux
+gserFluxErr     adu/seconds     REAL    4       -999    estimated error in serFlux
+gserAb          dimensionless   REAL    4       -999    Sersic axis ratio
+gserAbErr       dimensionlessn  REAL    4       -999    estimated error in Sersic axis ratio
+gserNu          dimensionlessn  REAL    4       -999    Sersic index
+gserNuErr       diemensionless  REAL    4       -999    estimated error in Sersic index
+gserPhi         degrees         REAL    4       -999    estmated phi of Sersic axis
+gserPhiErr      degrees         REAL    4       -999    estmated error of phi of Sersic axis
+graSerOff       dimensionless   REAL    4       -999    Offset in RA of Sersic fit from PSF RA
+gdecSerOff      dimensionless   REAL    4       -999    Offset in DEC of Sersic fit from PSF DEC
+graSerOffErr    dimensionless   REAL    4       -999    estimated error in raSerOff
+gdecSerOffErr   dimensionless   REAL    4       -999    estimated error in decSerOff
+gserCf          dimensionless   REAL    4       -999    Sersic fit coverage factor
+gserLikelihood  dimensionless   REAL    4       -999    Sersic fit likelihood factor
+---------------------------------------------------------------------------------------
+gpetRadius      pixels          REAL    4       -999    Petrosian radius
+gpetRadiusErr   pixels          REAL    4       -999    estimated error inPetrosian radius
+gpetFlux        adu/sec         REAL    4       -999    Petrosian Flux
+gpetFluxErr     adu/sec         REAL    4       -999    estimated error in petFlux
+gpetR50         pixels          REAL    4       -999    Petrosian radius at 50% light
+gpetR50Err      pixels          REAL    4       -999    estimated error inPetrosian radius at 50% light
+gpetR90         pixels          REAL    4       -999    Petrosian radius at 90% light
+gpetR90Err      pixels          REAL    4       -999    estimated error in Petrosian radius at 90% light
+gpetCf          dimensionless   REAL    4       -999    Petrosian fit coverage factor
+--------------------------------------------------------unconvolved
+gflxR1          adu/seconds     REAL    4       -999    Flux inside r = 1
+gflxR1Err       adu/seconds     REAL    4       -999    estimated error is flxR1
+gflxR1Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR1
+gflxR1Fill      dimensionless   REAL    4       -999    estimated filling factor at R1
+gflxR2          adu/seconds     REAL    4       -999    Flux inside r = 2
+gflxR2Err       adu/seconds     REAL    4       -999    estimated error is flxR2
+gflxR2Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR2
+gflxR2Fill      dimensionless   REAL    4       -999    estimated filling factor at R1
+gflxR3          adu/seconds     REAL    4       -999    Flux inside r = 3
+gflxR3Err       adu/seconds     REAL    4       -999    estimated error is flxR3
+gflxR3Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR3
+gflxR3Fill      dimensionless   REAL    4       -999    estimated filling factor at R3
+gflxR4          adu/seconds     REAL    4       -999    Flux inside r = 4
+gflxR4Err       adu/seconds     REAL    4       -999    estimated error is flxR4
+gflxR4Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR4
+gflxR4Fill      dimensionless   REAL    4       -999    estimated filling factor at R4
+gflxR5          adu/seconds     REAL    4       -999    Flux inside r = 5
+gflxR5Err       adu/seconds     REAL    4       -999    estimated error is flxR5
+gflxR5Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR5
+gflxR5Fill      dimensionless   REAL    4       -999    estimated filling factor at R5
+gflxR6          adu/seconds     REAL    4       -999    Flux inside r = 6
+gflxR6Err       adu/seconds     REAL    4       -999    estimated error is flxR6
+gflxR6Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR6
+gflxR6Fill      dimensionless   REAL    4       -999    estimated filling factor at R6
+gflxR7          adu/seconds     REAL    4       -999    Flux inside r = 7
+gflxR7Err       adu/seconds     REAL    4       -999    estimated error is flxR7
+gflxR7Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR7
+gflxR7Fill      dimensionless   REAL    4       -999    estimated filling factor at R7
+gflxR8          adu/seconds     REAL    4       -999    Flux inside r = 8
+gflxR8Err       adu/seconds     REAL    4       -999    estimated error is flxR8
+gflxR8Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR8
+gflxR8Fill      dimensionless   REAL    4       -999    estimated filling factor at R8
+gflxR9          adu/seconds     REAL    4       -999    Flux inside r = 9
+gflxR9Err       adu/seconds     REAL    4       -999    estimated error is flxR9
+gflxR9Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR9
+gflxR9Fill      dimensionless   REAL    4       -999    estimated filling factor at R9
+gflxR10         adu/seconds     REAL    4       -999    Flux inside r = 10
+gflxR10Err      adu/seconds     REAL    4       -999    estimated error is flxR10
+gflxR10Std      adu/seconds     REAL    4       -999    estimated standard deviation in flxR10
+gflxR10Fill     dimensionless   REAL    4       -999    estimated filling factor at R10
+----------------------------------------------------    convolved across all bands to 6 or 8 pixels
+gc1flxR1        adu/seconds     REAL    4       -999    Flux inside r = 1
+gc1flxR1Err     adu/seconds     REAL    4       -999    estimated error is c1flxR1
+gc1flxR1Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR1
+gc1flxR1Fill    dimensionless   REAL    4       -999    estimated filling factor at R1
+gc1flxR2        adu/seconds     REAL    4       -999    Flux inside r = 2
+gc1flxR2Err     adu/seconds     REAL    4       -999    estimated error is c1flxR2
+gc1flxR2Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR2
+gc1flxR2Fill    dimensionless   REAL    4       -999    estimated filling factor at R1
+gc1flxR3        adu/seconds     REAL    4       -999    Flux inside r = 3
+gc1flxR3Err     adu/seconds     REAL    4       -999    estimated error is c1flxR3
+gc1flxR3Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR3
+gc1flxR3Fill    dimensionless   REAL    4       -999    estimated filling factor at R3
+gc1flxR4        adu/seconds     REAL    4       -999    Flux inside r = 4
+gc1flxR4Err     adu/seconds     REAL    4       -999    estimated error is c1flxR4
+gc1flxR4Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR4
+gc1flxR4Fill    dimensionless   REAL    4       -999    estimated filling factor at R4
+gc1flxR5        adu/seconds     REAL    4       -999    Flux inside r = 5
+gc1flxR5Err     adu/seconds     REAL    4       -999    estimated error is c1flxR5
+gc1flxR5Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR5
+gc1flxR5Fill    dimensionless   REAL    4       -999    estimated filling factor at R5
+gc1flxR6        adu/seconds     REAL    4       -999    Flux inside r = 6
+gc1flxR6Err     adu/seconds     REAL    4       -999    estimated error is c1flxR6
+gc1flxR6Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR6
+gc1flxR6Fill    dimensionless   REAL    4       -999    estimated filling factor at R6
+gc1flxR7        adu/seconds     REAL    4       -999    Flux inside r = 7
+gc1flxR7Err     adu/seconds     REAL    4       -999    estimated error is c1flxR7
+gc1flxR7Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR7
+gc1flxR7Fill    dimensionless   REAL    4       -999    estimated filling factor at R7
+gc1flxR8        adu/seconds     REAL    4       -999    Flux inside r = 8
+gc1flxR8Err     adu/seconds     REAL    4       -999    estimated error is c1flxR8
+gc1flxR8Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR8
+gc1flxR8Fill    dimensionless   REAL    4       -999    estimated filling factor at R8
+gc1flxR9        adu/seconds     REAL    4       -999    Flux inside r = 9
+gc1flxR9Err     adu/seconds     REAL    4       -999    estimated error is c1flxR9
+gc1flxR9Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR9
+gc1flxR9Fill    dimensionless   REAL    4       -999    estimated filling factor at R9
+gc1flxR10       adu/seconds     REAL    4       -999    Flux inside r = 10
+gc1flxR10Err    adu/seconds     REAL    4       -999    estimated error is c1flxR10
+gc1flxR10Std    adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR10
+gc1flxR10Fill   dimensionless   REAL    4       -999    estimated filling factor at R10
+gc2flxR1        adu/seconds     REAL    4       -999    Flux inside r = 1
+gc2flxR1Err     adu/seconds     REAL    4       -999    estimated error is c2flxR1
+gc2flxR1Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR1
+gc2flxR1Fill    dimensionless   REAL    4       -999    estimated filling factor at R1
+gc2flxR2        adu/seconds     REAL    4       -999    Flux inside r = 2
+gc2flxR2Err     adu/seconds     REAL    4       -999    estimated error is c2flxR2
+gc2flxR2Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR2
+gc2flxR2Fill    dimensionless   REAL    4       -999    estimated filling factor at R1
+gc2flxR3        adu/seconds     REAL    4       -999    Flux inside r = 3
+gc2flxR3Err     adu/seconds     REAL    4       -999    estimated error is c2flxR3
+gc2flxR3Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR3
+gc2flxR3Fill    dimensionless   REAL    4       -999    estimated filling factor at R3
+gc2flxR4        adu/seconds     REAL    4       -999    Flux inside r = 4
+gc2flxR4Err     adu/seconds     REAL    4       -999    estimated error is c2flxR4
+gc2flxR4Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR4
+gc2flxR4Fill    dimensionless   REAL    4       -999    estimated filling factor at R4
+gc2flxR5        adu/seconds     REAL    4       -999    Flux inside r = 5
+gc2flxR5Err     adu/seconds     REAL    4       -999    estimated error is c2flxR5
+gc2flxR5Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR5
+gc2flxR5Fill    dimensionless   REAL    4       -999    estimated filling factor at R5
+gc2flxR6        adu/seconds     REAL    4       -999    Flux inside r = 6
+gc2flxR6Err     adu/seconds     REAL    4       -999    estimated error is c2flxR6
+gc2flxR6Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR6
+gc2flxR6Fill    dimensionless   REAL    4       -999    estimated filling factor at R6
+gc2flxR7        adu/seconds     REAL    4       -999    Flux inside r = 7
+gc2flxR7Err     adu/seconds     REAL    4       -999    estimated error is c2flxR7
+gc2flxR7Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR7
+gc2flxR7Fill    dimensionless   REAL    4       -999    estimated filling factor at R7
+gc2flxR8        adu/seconds     REAL    4       -999    Flux inside r = 8
+gc2flxR8Err     adu/seconds     REAL    4       -999    estimated error is c2flxR8
+gc2flxR8Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR8
+gc2flxR8Fill    dimensionless   REAL    4       -999    estimated filling factor at R8
+gc2flxR9        adu/seconds     REAL    4       -999    Flux inside r = 9
+gc2flxR9Err     adu/seconds     REAL    4       -999    estimated error is c2flxR9
+gc2flxR9Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR9
+gc2flxR9Fill    dimensionless   REAL    4       -999    estimated filling factor at R9
+gc2flxR10       adu/seconds     REAL    4       -999    Flux inside r = 10
+gc2flxR10Err    adu/seconds     REAL    4       -999    estimated error is c2flxR10
+gc2flxR10Std    adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR10
+gc2flxR10Fill   dimensionless   REAL    4       -999    estimated filling factor at R10
+
+-- repeat for other filters with appropriate leading prefex.
+
+-- [728 byte/filter/obj + 44 byte/obj]
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFit.txt
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFit.txt	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFit.txt	(revision 37066)
@@ -0,0 +1,200 @@
+
+objID             = dvo / addstar
+gcObjID           = dvo / addstar [EAM: add to addstar]
+ippObjID          = dvo / addstar average.objID + (average.catID << 32)
+surveyID          = ipptopsps
+skyCellID         = smf header
+randomStackObjID  = ipptopsps
+stackDetectRowID  = PSPS ?
+primaryDetection  = dvo
+bestDetection     = dvo (define?)
+--                = 
+dvoRegionID       = dvo / catID [EAM: add to dvopsps]
+dataRelease       = ipptopsps
+----------------  = 
+glogC             = [NOT currently calculated] [EAM: add to psphotStack]
+glogA             = [NOT currently calculated]
+gclump            = [NOT currently calculated]
+----------------  = 
+gippDetectID      = dvopsps (see StackObject.txt)
+gstackDetectID    = dvopsps (see StackObject.txt)
+gstackMetaID      = dvopsps (see StackObject.txt)
+----------------  = 
+gdeVRadius        = smf [NOTE: the smf has Major, Minor, Theta, but errors on Sxx, Syy, Sxy
+gdeVRadiusErr     = smf
+gdeVFlux          = smf
+gdeVFluxErr       = smf
+gdeVAb            = smf
+gdeVAbErr         = smf
+gdeVPhi           = smf
+gdeVPhiErr        = smf [convert from Sxx,Sxy,Syy??]
+graDeVOff         = smf (calculate from reported position vs psf position)
+gdecDeVOff        = smf (calculate from reported position vs psf position)
+graDeVOffErr      = smf
+gdecDeVOffErr     = smf
+gdeVCf            = [NOT currently calculated] [count nPix in fit vs pi r^2]
+gdeVLikelihood    = ipptopsps
+----------------  = 
+gexpRadius        = smf [NOTE: the smf has Major, Minor, Theta, but errors on Sxx, Syy, Sxy
+gexpRadiusErr     = smf
+gexpFlux          = smf
+gexpFluxErr       = smf
+gexpAb            = smf
+gexpAbErr         = smf
+gexpPhi           = smf
+gexpPhiErr        = smf
+graExpOff         = smf (calculate from reported position vs psf position)
+gdecExpOff        = smf (calculate from reported position vs psf position)
+graExpOffErr      = smf
+gdecExpOffErr     = smf
+gexpCf            = [NOT currently calculated]
+gexpLikelihood    = ipptopsps
+----------------  = 
+gserRadius        = smf [NOTE: the smf has Major, Minor, Theta, but errors on Sxx, Syy, Sxy
+gserRadiusErr     = smf
+gserFlux          = smf
+gserFluxErr       = smf
+gserAb            = smf
+gserAbErr         = smf
+gserNu            = smf
+gserNuErr         = smf
+gserPhi           = smf
+gserPhiErr        = smf
+graSerOff         = smf (calculate from reported position vs psf position)
+gdecSerOff        = smf (calculate from reported position vs psf position)
+graSerOffErr      = smf
+gdecSerOffErr     = smf
+gserCf            = [NOT currently calculated]
+gserLikelihood    = ipptopsps
+----------------  = 
+gpetRadius        = smf
+gpetRadiusErr     = smf
+gpetFlux          = smf
+gpetFluxErr       = smf
+gpetR50           = smf
+gpetR50Err        = smf
+gpetR90           = smf
+gpetR90Err        = smf
+gpetCf            = smf
+----------------  = 
+gflxR1            = smf
+gflxR1Err         = smf
+gflxR1Std         = smf
+gflxR1Fill        = smf
+gflxR2            = smf
+gflxR2Err         = smf
+gflxR2Std         = smf
+gflxR2Fill        = smf
+gflxR3            = smf
+gflxR3Err         = smf
+gflxR3Std         = smf
+gflxR3Fill        = smf
+gflxR4            = smf
+gflxR4Err         = smf
+gflxR4Std         = smf
+gflxR4Fill        = smf
+gflxR5            = smf
+gflxR5Err         = smf
+gflxR5Std         = smf
+gflxR5Fill        = smf
+gflxR6            = smf
+gflxR6Err         = smf
+gflxR6Std         = smf
+gflxR6Fill        = smf
+gflxR7            = smf
+gflxR7Err         = smf
+gflxR7Std         = smf
+gflxR7Fill        = smf
+gflxR8            = smf
+gflxR8Err         = smf
+gflxR8Std         = smf
+gflxR8Fill        = smf
+gflxR9            = smf
+gflxR9Err         = smf
+gflxR9Std         = smf
+gflxR9Fill        = smf
+gflxR10           = smf
+gflxR10Err        = smf
+gflxR10Std        = smf
+gflxR10Fill       = smf
+----------------  = 
+gc1flxR1          = smf
+gc1flxR1Err       = smf
+gc1flxR1Std       = smf
+gc1flxR1Fill      = smf
+gc1flxR2          = smf
+gc1flxR2Err       = smf
+gc1flxR2Std       = smf
+gc1flxR2Fill      = smf
+gc1flxR3          = smf
+gc1flxR3Err       = smf
+gc1flxR3Std       = smf
+gc1flxR3Fill      = smf
+gc1flxR4          = smf
+gc1flxR4Err       = smf
+gc1flxR4Std       = smf
+gc1flxR4Fill      = smf
+gc1flxR5          = smf
+gc1flxR5Err       = smf
+gc1flxR5Std       = smf
+gc1flxR5Fill      = smf
+gc1flxR6          = smf
+gc1flxR6Err       = smf
+gc1flxR6Std       = smf
+gc1flxR6Fill      = smf
+gc1flxR7          = smf
+gc1flxR7Err       = smf
+gc1flxR7Std       = smf
+gc1flxR7Fill      = smf
+gc1flxR8          = smf
+gc1flxR8Err       = smf
+gc1flxR8Std       = smf
+gc1flxR8Fill      = smf
+gc1flxR9          = smf
+gc1flxR9Err       = smf
+gc1flxR9Std       = smf
+gc1flxR9Fill      = smf
+gc1flxR10         = smf
+gc1flxR10Err      = smf
+gc1flxR10Std      = smf
+gc1flxR10Fill     = smf
+gc2flxR1          = smf
+gc2flxR1Err       = smf
+gc2flxR1Std       = smf
+gc2flxR1Fill      = smf
+gc2flxR2          = smf
+gc2flxR2Err       = smf
+gc2flxR2Std       = smf
+gc2flxR2Fill      = smf
+gc2flxR3          = smf
+gc2flxR3Err       = smf
+gc2flxR3Std       = smf
+gc2flxR3Fill      = smf
+gc2flxR4          = smf
+gc2flxR4Err       = smf
+gc2flxR4Std       = smf
+gc2flxR4Fill      = smf
+gc2flxR5          = smf
+gc2flxR5Err       = smf
+gc2flxR5Std       = smf
+gc2flxR5Fill      = smf
+gc2flxR6          = smf
+gc2flxR6Err       = smf
+gc2flxR6Std       = smf
+gc2flxR6Fill      = smf
+gc2flxR7          = smf
+gc2flxR7Err       = smf
+gc2flxR7Std       = smf
+gc2flxR7Fill      = smf
+gc2flxR8          = smf
+gc2flxR8Err       = smf
+gc2flxR8Std       = smf
+gc2flxR8Fill      = smf
+gc2flxR9          = smf
+gc2flxR9Err       = smf
+gc2flxR9Std       = smf
+gc2flxR9Fill      = smf
+gc2flxR10         = smf
+gc2flxR10Err      = smf
+gc2flxR10Std      = smf
+gc2flxR10Fill     = smf
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackObject
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackObject	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackObject	(revision 37066)
@@ -0,0 +1,65 @@
+
+objID             dimensionless   BIGINT  8       NA      ODM object identifier
+gcObjID	  	  dimensionless	  BIGINT  8	  NA 	  ODM galactic coordinates identifier
+ippObjID          dimensionless   BIGINT  8       NA      object ID generated by IPP
+surveyID          dimensionless   TINYINT 1       NA      survey flag identifier
+skyCellID         dimensionless   REAL    4       -999    single float giving PrimaryCell.SkyCell identifier 
+randomStackObjID  dimensionless   BIGINT  8       NA      random stack id
+stackDetectRowID  dimensionless   BIGINT  8       NA      identifies which of up to 5 possible stackdetctions this Row refers to: Primary, up to 3 Secondary, 1 best  
+primaryDetection  dimensionless   TINYINT 1       255     identifies if this row is a primary stack detection. True about 80% of time. 
+bestDetection     dimensionless   TINYINT 1       255     identifies if this row is a best detection or not. Also set if only a primary detection exists.   
+                                                          the Primary Dectection, 0 to 3 possible secondary dectections, and the "best" per filter.  
+dvoRegionID       dimensionless   INT     4       -999    identifier to dvo spatial region
+dataRelease       dimensionless   TINYINT 1       NA      Data release when this detection was originally taken.
+------------------------------------------------------------------------------------------
+-- attributes for all stack detections in all filters (these are currently forced anyway) 
+-- Replicate the section below for each filter, changing the prefex ("g" in this example) 
+------------------------------------------------------------------------------------------
+gippDetectID      dimensionless   BIGINT  8       NA      detection ID generated by IPP
+gstackDetectID    dimensionless   BIGINT  8       NA      ODM detection identifier
+gstackMetaID      dimensionless   BIGINT  8       NA      stack identifier
+------------------------------------------------------------------------------------------
+gxPos             arcsec          REAL    4       -999    measured x in sky Cell from PSF fit
+gyPos             arcsec          REAL    4       -999    measured y in sky Cell from PSF fit
+gxPosErr          arcsec          REAL    4       -999    estimated error in x
+gyPosErr          arcsec          REAL    4       -999    estimated error in y
+gra               degrees         FLOAT   8       NA      Right Ascension   
+gdec              degrees         FLOAT   8       NA      Declination       
+graErr            arcsec          REAL    4       NA      Right Ascension error
+gdecErr           arcsec          REAL    4       NA      Declination error  (same as RA error - need?)
+gzp               magnitude       REAL    4       0       zeropoint , no error given 
+gexpTime          seconds         REAL    4       -999    total exposure time (informational)
+gpsfMajorFWHM     arcsec          REAL    4       -999    PSF width in major axis
+gpsfMinorFWHM     arcsec          REAL    4       -999    PSF width in minor axis
+gpsfTheta         degrees         REAL    4       -999    PSF orientation angle. Degrees East of North.
+gpsfCore          dimensionless   REAL    4       -999    PSF core parameter [k in (1 + kz + z^1.66)]
+gpsfLikelihood    dimensionless   REAL    4       -999    PSF likelihood
+gpsfQf            dimensionless   REAL    4       -999    PSF coverage factor
+gpsfQfPerfect     dimensionless   REAL    4       -999    PSF-weighted fraction of arcsec totally unmasked
+gpsfChiSq         dimensionless   REAL    4       -999    PSF-weighted fraction of arcsec to.
+gmomentXX         arcsec^2        REAL    4       -999    moment XX
+gmomentXY         arcsec^2        REAL    4       -999    moment XY
+gmomentYY         arcsec^2        REAL    4       -999    moment YY
+gmomentR1         arcsec          REAL    4       -999    moment R1
+gmomentRH         arcsec          REAL    4       -999    moment RH - or half light radius (REMOVE)
+gPSFFlux     	  adu/sec         REAL    4       -999    g psf flux from stack
+gPSFFluxErr  	  adu/sec         REAL    4       -999    estimated error of g psf flux from stack
+gApFlux           adu/seconds     REAL    4       -999    Aperture magnitude
+gApFluxErr        adu/seconds     REAL    4       -999    Aperture magnitude error
+gApFillFac        dimensionless   REAL    4       -999    Aperture fill factor - ~ redundant with psfQF, keep?
+gKronFlux         adu/seconds     REAL    4       -999    Kron flux
+gKronFluxErr      adu/seconds     REAL    4       -999    Kron flux error
+gKronRad          arcsec          REAL    4       -999    Kron radius
+gPSFMag      	  AB_magnitude    REAL    4       -999    g psf AB magnitude from stack
+gPSFMagErr   	  AB_magnitude    REAL    4       -999    estimated error of g psf AB magnitude from stack
+gApMag       	  AB_magnitude    REAL    4       -999    g Aperture AB magnitude from stack
+gApMagErr    	  AB_magnitude    REAL    4       -999    estimated error of g Ap Mag AB magnitude from stack
+gKronMag     	  AB_magnitude    REAL    4       -999    g kron AB magnitude from stack
+gKronMagErr  	  AB_magnitude    REAL    4       -999    estimated error of g kron AB magnitude from stack
+gsky              adu/secs/arcsec REAL    4       -999    PSF sky level at source (adu)
+gskyErr           adu/secs/arcsec REAL    4       -999    estimated error in sky
+ginfoFlag         dimensionless   INT     4       -999    indicator of strange propeties
+ginfoFlag2        dimensionless   INT     4       -999    indicator of strange propeties
+gnFrames          dimensionless   INT     4       -999    Number of frames contributing to source
+
+-- [220 byte/filter/obj + 44 byte/obj]
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackObject.txt
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackObject.txt	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackObject.txt	(revision 37066)
@@ -0,0 +1,66 @@
+		  
+objID              = dvo/addstar = average.extID
+gcObjID            = dvo/addstar [EAM: add to addstar, average.d]
+ippObjID           = dvo/addstar = average.objID + (average.catID << 32)
+surveyID           = ipptopsps
+skyCellID          = ipptopsps / smf header
+randomStackObjID   = ipptopsps
+stackDetectRowID   = PSPS ?
+primaryDetection   = dvo 
+bestDetection      = dvo ?
+                   = 
+dvoRegionID        = dvo / catID
+dataRelease        = ippToPsps
+------------------ = 
+-- attributes for  = 
+-- Replicate the s = 
+------------------ = 
+gippDetectID       = dvopsps.ippDetectID = dvo.measure.detID = smf / IPP_IDET
+gstackDetectID     = dvopsps.detectID = dvo:measure.extID (addstar psps stack detect ID)
+gstackMetaID       = smf header 
+------------------ = 
+gxPos              = smf
+gyPos              = smf
+gxPosErr           = smf
+gyPosErr           = smf
+gra                = smf or relastro? (Ken?)
+gdec               = smf or relastro?
+graErr             = smf or relastro?
+gdecErr            = smf or relastro?
+gzp                = dvo / relphot
+gexpTime           = smf [see Detection.txt]
+gpsfMajorFWHM      = smf [see Detection.txt]
+gpsfMinorFWHM      = smf [see Detection.txt]
+gpsfTheta          = smf [see Detection.txt]
+gpsfCore           = smf [see Detection.txt]
+gpsfLikelihood     = ipptopsps
+gpsfQf             = smf
+gpsfQfPerfect      = smf
+gpsfChiSq          = smf
+gmomentXX          = smf
+gmomentXY          = smf
+gmomentYY          = smf
+gmomentR1          = smf
+gmomentRH          = smf [XXX : MOMENTS_RH is NOT half-light radius]
+gPSFFlux     	   = smf
+gPSFFluxErr  	   = smf
+gApFlux            = smf
+gApFluxErr         = smf
+gApFillFac         = smf [EAM: add to smf output]
+gKronFlux          = smf
+gKronFluxErr       = smf
+gKronRad           = (2.5 * R1) [drop from schema]
+gPSFMag      	   = smf
+gPSFMagErr   	   = smf
+gApMag       	   = smf
+gApMagErr    	   = smf
+gKronMag     	   = smf (calculated)
+gKronMagErr  	   = smf (calculated)
+gsky               = smf
+gskyErr            = smf
+ginfoFlag          = smf
+ginfoFlag2         = smf
+gnFrames           = smf
+
+[NOTE: for stacks, dvo only needs to determine the 
+       primary measurement (and modified zero point?).
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/changes.r36847
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/changes.r36847	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/changes.r36847	(revision 37066)
@@ -0,0 +1,199 @@
+Index: Detection
+===================================================================
+--- Detection	(revision 36838)
++++ Detection	(working copy)
+@@ -7,7 +7,7 @@
+ surveyID        dimensionless   TINYINT 1         NA    survey flag identifier
+ imageID         dimensionless   BIGINT  8         NA    image id hash of frame identifier & OTA/CCD number
+ randomDetID     dimensionless   BIGINT  8         NA    random detection Id
+-dvoRegionID     dimensionless   REAL    4       -999    identifier to dvo spatial region
++dvoRegionID     dimensionless   INT     4          0    identifier to dvo spatial region
+ obsTime         MeanJulianDays  FLOAT   8       -999    Time of mid observation in Mean Julian Days
+ xPos            raw pixels      REAL    4       -999    measured x on CCD from PSF fit
+ yPos            raw pixels      REAL    4       -999    measured y on CCD from PSF fit
+@@ -53,7 +53,8 @@
+ kronRadErr      arcsec      	REAL    4       -999    Kron radius error
+ sky             adu/sec/pixel   REAL    4       -999    PSF sky level at source
+ skyErr          adu/sec/pixel   REAL    4       -999    estimated error in sky
+-infoFlag        dimensionless   BIGINT  8       -999    flag indicating provenance information
++infoFlag        dimensionless   INT     4       -999    flag indicating provenance information
++infoFlag2       dimensionless   INT     4       -999    flag indicating provenance information
+ dataRelease     dimensionless   TINYINT 1         NA    Data release when this detection was originally taken. Recalibrations do not affect this value.
+ --
+ -- [231 bytes/det]
+Index: StackApFlx
+===================================================================
+--- StackApFlx	(revision 36838)
++++ StackApFlx	(working copy)
+@@ -1,6 +1,7 @@
+ 
+ objID            dimensionless  BIGINT  8       NA      ODM object identifier
+ gcObjID		dimensionless	BIGINT	8	  NA 	ODM galactic coordinates identifier
++ippObjID         dimensionless  BIGINT  8       NA      ipp object identifier
+ surveyID         dimensionless  TINYINT 1       0       stack type identifier
+ skyCellID        dimensionless  REAL    4       -999    single float giving PrimaryCell.SkyCell identifier 
+ randomStackObjID dimensionless  BIGINT  8       NA      random stack id
+@@ -8,13 +9,12 @@
+ primaryDetection dimensionless  TINYINT 1       255     identifies if this row is a primary stack detection. True about 80% of time. 
+ bestDetection    dimensionless  TINYINT 1       255     identifies if this row is a best detection or not. Also set if only a primary detection exists.   
+ --                                                      the Primary Dectection, 0 to 3 possible secondary dectections, and the "best" per filter.  
+-dvoRegionID      dimensionless  REAL    4       -999    identifier to dvo spatial region
++dvoRegionID     dimensionless   INT    4       -999    identifier to dvo spatial region
+ dataRelease     dimensionless   TINYINT 1       NA      Data release when this table was loaded.
+ ------------------------------------------------------- replicate to end for each filter g,r,i,z,y
++gippDetectID    dimensionless   BIGINT  8       NA      stack identifier
+ gstackDetectID  dimensionless   BIGINT  8       NA      ODM detection identifier
+ gstackMetaID    dimensionless   BIGINT  8       NA      stack identifier
+-gippObjID        dimensionless  BIGINT  8       NA      ipp object identifier
+-gippDetectID    dimensionless   BIGINT  8       NA      stack identifier
+ --------------------------------------------------------unconvolved
+ gflxR3          adu/seconds     REAL    4       -999    Flux inside r = 3
+ gflxR3Err       adu/seconds     REAL    4       -999    estimated error is flxR3
+Index: ForcedWarpMeasurement
+===================================================================
+--- ForcedWarpMeasurement	(revision 36838)
++++ ForcedWarpMeasurement	(working copy)
+@@ -8,7 +8,7 @@
+ forcedWarpID    dimensionless   BIGINT  8       NA      IPP warp_id
+ randomWarpID    dimensionless   BIGINT  8       NA      Random warp_id
+ skyCellID       dimensionless   REAL    4       -999    single float giving PrimaryCell.SkyCell identifier 
+-dvoRegionID     dimensionless   REAL    4       -999    identifier to dvo spatial region
++dvoRegionID     dimensionless   INT     4       -999    identifier to dvo spatial region
+ obsTime         MeanJulianDays  FLOAT   8       -999    Time of mid observation in Mean Julian Days
+ ------------------------------------------------------ 
+ zp              magnitude       REAL    4       0       zeropoint (only thing needed to convert adu/sec to AB mag), note no zpErr
+Index: DiffDetection
+===================================================================
+--- DiffDetection	(revision 36838)
++++ DiffDetection	(working copy)
+@@ -1,3 +1,4 @@
++
+ diffObjID	dimensionless 	BIGINT 	8 	NA 	diff object identifier
+ diffgcObjID		dimensionless	BIGINT	8	  NA 	ODM galactic coordinates identifier
+ diffDetID 	dimensionless 	BIGINT 	8 	NA 	diff detection identifier
+@@ -8,7 +9,7 @@
+ surveyID 	dimensionless 	TINYINT	1 	NA 	survey flag identifierr
+ randomDiffID 	dimensionless 	BIGINT 	8 	NA 	random diff id  
+ skyCellID       dimensionless   REAL    4       -999    single float giving PrimaryCell.SkyCell identifier 
+-dvoRegionID     dimensionless   REAL    4       -999    identifier to dvo spatial region
++dvoRegionID     dimensionless   INT     4          0    identifier to dvo spatial region
+ obsTime 	MeanJulianDays 	FLOAT 	8 	-999 	Time of mid observation of positive detection in Mean Julian Days of positive detection
+ xPos 		pixels 		REAL 	4 	-999 	measured x on diff image sky cell PSF fit
+ yPos 		pixels 		REAL 	4 	-999 	measured y on diff image sky cell from PSF fit
+@@ -65,5 +66,6 @@
+ -------------------------------------------------------
+ sky 		adu/sec/pixel 	REAL 	4 	-999 	PSF sky level at source
+ skyErr 		adu/sec/pixel 	REAL 	4 	-999 	estimated error in sky
+-infoFlag 	dimensionless 	BIGINT 	8 	-999 	flag indicating provenance information
++infoFlag 	dimensionless 	INT     4 	-999 	flag indicating provenance information
++infoFlag2	dimensionless 	INT     4 	-999 	flag indicating provenance information
+ dataRelease 	dimensionless 	TINYINT	1 	NA 	Data release when this detection was originally taken. Recalibrations do not affect this value.
+Index: ObjectThin
+===================================================================
+--- ObjectThin	(revision 36838)
++++ ObjectThin	(working copy)
+@@ -9,7 +9,7 @@
+ zoneID           dimensionless  INT      4      NA      Zone index
+ randomID         dimensionless  BIGINT   8      0       Random integer between 0 and 2^32 = 4,394,967,296 remaining ramdom integer 0  
+ batchID          dimensionless  BIGINT   8      -999    batch id        
+-dvoRegionID      dimensionless  REAL     4      -999    identifier of dvo spatial region - dvo cat id
++dvoRegionID      dimensionless  INT      4      -999    identifier of dvo spatial region - dvo cat id
+ dataRelease      dimensionless  TINYINT  1      NA      Data release Version of this table
+ objInfoFlag      dimensionless  BIGINT   8      -999    flag indicating odd properties
+ qualityFlag      dimensionless  TINYINT  1      0       subset of objInfoFlag - flags related to goodness of object
+Index: StackModelFit
+===================================================================
+--- StackModelFit	(revision 36838)
++++ StackModelFit	(working copy)
+@@ -1,6 +1,7 @@
+ 
+ objID            dimensionless  BIGINT  8       NA      ODM object identifier
+ gcObjID		dimensionless	BIGINT	8	  NA 	ODM galactic coordinates identifier
++ippObjID         dimensionless  BIGINT  8       NA      ipp object identifier
+ surveyID         dimensionless  TINYINT 1       NA      survey flag identifier
+ skyCellID        dimensionless  REAL    4       -999    single float giving PrimaryCell.SkyCell identifier 
+ randomStackObjID dimensionless  BIGINT  8       NA      random stack id
+@@ -8,17 +9,17 @@
+ primaryDetection dimensionless  TINYINT 1       255     identifies if this row is a primary stack detection. True about 80% of time. 
+ bestDetection    dimensionless  TINYINT 1       255     identifies if this row is a best detection or not. Also set if only a primary detection exists.   
+ --                                                      the Primary Dectection, 0 to 3 possible secondary dectections, and the "best" per filter.  
+-dvoRegionID      dimensionless  REAL    4       -999    identifier to dvo spatial region
++dvoRegionID      dimensionless  INT     4       -999    identifier to dvo spatial region
+ dataRelease      dimensionless  TINYINT 1       NA      Data release when this table was loaded
+ -------------------------------------------------------- replicate below for all filters (grizy)
+ glogC           dimensionless   REAL    4       -999    concentration index 
+ glogA           dimensionless   REAL    4       -999    asymmetry index
+ gclump          dimensionless   REAL    4       -999    clumpiness factor   
+ -------------------------------------------------------- replicate below for all filters (grizy)
++gippDetectID    dimensionless   BIGINT  8       NA      ipp detect identifier
+ gstackDetectID  dimensionless   BIGINT  8       NA      ODM detection identifier
+ gstackMetaID    dimensionless   BIGINT  8       NA      stack identifier
+-gippObjID       dimensionless  BIGINT  8       NA      ipp object identifier
+-gippDetectID    dimensionless   BIGINT  8       NA      ipp detect identifier
++----------------------------------------------------------------------------------------
+ gdeVRadius      arcsec          REAL    4       -999    deVaucouleurs radius
+ gdeVRadiusErr   arcsec          REAL    4       -999    estimated error in deVaucouleurs radius
+ gdeVFlux        adu/seconds     REAL    4       -999    deVaucouleurs flux
+Index: ForcedMeanObject
+===================================================================
+--- ForcedMeanObject	(revision 36838)
++++ ForcedMeanObject	(working copy)
+@@ -1,3 +1,4 @@
++
+ objID           dimensionless   BIGINT   8        NA    ODM object identifier index
+ gcObjID		dimensionless	BIGINT	8	  NA 	ODM galactic coordinates identifier
+ ippObjID        dimensionless   BIGINT   8        NA    IPP object identifier
+Index: DiffDetObject
+===================================================================
+--- DiffDetObject	(revision 36838)
++++ DiffDetObject	(working copy)
+@@ -9,7 +9,7 @@
+ zoneID 		dimensionless 	INT 	4 	NA 	Zone index
+ randomID 	dimensionless 	BIGINT 	8 	0 	Random integer between 0 and 2^32 = 4,394,967,296 remaining ramdom integer 0  
+ batchID 	dimensionless	BIGINT 	8 	-999 	
+-dvoRegionID     dimensionless  	REAL    4       -999    identifier to dvo spatial region
++dvoRegionID     dimensionless  	INT     4       -999    identifier to dvo spatial region
+ objInfoFlag 	dimensionless 	BIGINT 	8 	-999 	flag indicating odd properties
+ qualityFlag 	dimensionless 	TINYINT 1 	0 	subset of objInfoFlag - flags related to goodness of object
+ consistencyFlag	dimensionless 	SMALLINT2 	0 	Value computed from associated detections, it is originally given by IPP and should agree with the ODM validation
+Index: StackObject
+===================================================================
+--- StackObject	(revision 36838)
++++ StackObject	(working copy)
+@@ -1,6 +1,7 @@
+ 
+ objID             dimensionless   BIGINT  8       NA      ODM object identifier
+ gcObjID		dimensionless	BIGINT	8	  NA 	ODM galactic coordinates identifier
++ippObjID          dimensionless   BIGINT  8       NA      object ID generated by IPP
+ surveyID          dimensionless   TINYINT 1       NA      survey flag identifier
+ skyCellID         dimensionless   REAL    4       -999    single float giving PrimaryCell.SkyCell identifier 
+ randomStackObjID  dimensionless   BIGINT  8       NA      random stack id
+@@ -8,16 +9,16 @@
+ primaryDetection  dimensionless   TINYINT 1       255     identifies if this row is a primary stack detection. True about 80% of time. 
+ bestDetection     dimensionless   TINYINT 1       255     identifies if this row is a best detection or not. Also set if only a primary detection exists.   
+                                                           the Primary Dectection, 0 to 3 possible secondary dectections, and the "best" per filter.  
+-dvoRegionID       dimensionless   REAL    4       -999    identifier to dvo spatial region
++dvoRegionID       dimensionless   INT     4       -999    identifier to dvo spatial region
+ dataRelease       dimensionless   TINYINT 1       NA      Data release when this detection was originally taken.
+ ------------------------------------------------------------------------------------------
+ -- attributes for all stack detections in all filters (these are currently forced anyway) 
+ -- Replicate the section below for each filter, changing the prefex ("g" in this example) 
+ ------------------------------------------------------------------------------------------
+-gippObjID         dimensionless   BIGINT  8       NA      object ID generated by IPP
+ gippDetectID      dimensionless   BIGINT  8       NA      detection ID generated by IPP
+ gstackDetectID    dimensionless   BIGINT  8       NA      ODM detection identifier
+ gstackMetaID      dimensionless   BIGINT  8       NA      stack identifier
++------------------------------------------------------------------------------------------
+ gxPos             arcsec          REAL    4       -999    measured x in sky Cell from PSF fit
+ gyPos             arcsec          REAL    4       -999    measured y in sky Cell from PSF fit
+ gxPosErr          arcsec          REAL    4       -999    estimated error in x
+@@ -57,7 +58,8 @@
+ gKronMagErr  	  AB magnitude    REAL    4       -999    estimated error of g kron AB magnitude from stack
+ gsky              adu/secs/arcsec REAL    4       -999    PSF sky level at source (adu)
+ gskyErr           adu/secs/arcsec REAL    4       -999    estimated error in sky
+-ginfoFlag         dimensionless   BIGINT  8       -999    indicator of strange propeties
++ginfoFlag         dimensionless   INT     4       -999    indicator of strange propeties
++ginfoFlag2        dimensionless   INT     4       -999    indicator of strange propeties
+ gnFrames          dimensionless   INT     4       -999    Number of frames contributing to source
+ 
+ -- [220 byte/filter/obj + 44 byte/obj]
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/CameraConfig
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/CameraConfig	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/CameraConfig	(revision 37066)
@@ -0,0 +1,12 @@
+CameraConfig
+Description: Camera configuration
+
+Name      	Unit		        DataType    Size	Default		ValueDescription 
+
+cameraID  	dimensionless   	SMALLINT 	2 	   -999         camera identifier (i.e. GPC1, ISP)
+cameraConfigID  dimensionless           SMALLINT        2          -999         camera configuration
+endDate         dimensionless               REAL        4          -999         ending date of this configuration in MJD
+configDetails   string           VARCHAR(MAX) 8000      0x00         NA         text/table giving the details of the camera configuration
+                                                                                NEED TO CHANGE and pass camera x from raw data file
+
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/DetectionFlags
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/DetectionFlags	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/DetectionFlags	(revision 37066)
@@ -0,0 +1,10 @@
+DetectionFlags
+
+Description: Flags used to interpret the information flag provided
+with each detection (infoFlag in 'Detection' table)
+
+Name Unit Data Type Size Default Value Description
+
+name 		VARCHAR(32) 	32	NA 	Name of flag 
+value 		BIGINT 		8 	NA 	Flag value
+description     VARCHAR(2000) 2000      NA      Description of the flag
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/DiffMeta
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/DiffMeta	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/DiffMeta	(revision 37066)
@@ -0,0 +1,26 @@
+diffMetaID   dimensionless   BIGINT 8 NA diff  identifier
+batchID      dimensionless   BIGINT 8 NA batch  identifier
+surveyID     dimensionless   TINYINT 1 NA survey flag identifier
+filterID     dimensionless   TINYINT 1 NA filter id 
+diffTypeID   dimensionless   TINYINT 1 0 diff type identifier
+posImageID   dimensionless   BIGINT 8 NA positive image identifier
+negImageID   dimensionless   BIGINT 8 NA negative image identifier
+skyCellID    dimensionless   REAL 4 NA skycell region identifier 
+photoCalID   dimensionless   INT 4 NA photometry code
+magSat       dimensionless   REAL 4 -999 saturation magnitude level
+analVer      dimensionless   SMALLINT 2 -999 analysis version index
+expTime      seconds         REAL 4 -999 exposure time of positive image
+ctype1       alphanumeric   VARCHAR(MAX) 8000 name of astrometric projection in RA
+ctype2       alphanumeric   VARCHAR(MAX) 8000 name of astrometric projection in DEC
+crval1       degrees        FLOAT 8 -999 RA corresponding to reference pixel
+crval2       degrees        FLOAT 8 -999 DEC corresponding to reference pixel
+crpix1       dimensionless  FLOAT 8 -999 reference pixel value for RA
+crpix2       dimensionless  FLOAT 8 -999 reference pixel value for DEC
+cdelt1       deg/pixel      FLOAT 8 -999 scale factor for RA
+cdelt2       deg/pixel      FLOAT 8 -999 scale factor for DEC
+pc001001     dimensionless  FLOAT 8 -999 elements of rotation/Dcale matrix 
+pc001002     dimensionless  FLOAT 8 -999 elements of rotation/Dcale matrix
+pc002001     dimensionless  FLOAT 8 -999 elements of rotation/Dcale matrix
+pc002002     dimensionless  FLOAT 8 -999 elements of rotation/Dcale matrix
+calibModNum  dimensionless  SMALLINT 2 NA calibration modification number
+dataRelease  dimensionless  TINYINT 1 NA Data release
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/DiffToImage
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/DiffToImage	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/DiffToImage	(revision 37066)
@@ -0,0 +1,2 @@
+diffMetaID 	BIGINT 	8 	NA 	diff identifier
+imageID 	BIGINT 	8 	NA 	hashed exposure-ccdID identifier
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/Filter
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/Filter	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/Filter	(revision 37066)
@@ -0,0 +1,3 @@
+FilterID dimensionless TINYNT 1 NA filter ID: g=1, r=2, i=3, z=4, y=5, w=6, ...
+filterType VARCHAR(2) 2 NA filter name: g,r,i,z,y, etc.
+filterSpec VARCHAR(MAX) 8000 0x00 No comment
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/FitModel
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/FitModel	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/FitModel	(revision 37066)
@@ -0,0 +1,42 @@
+fitModelID		SMALLINT	2	NA	indentifier of alternate model fit
+name		VARCHAR(30)	30		model name
+description		VARCHAR(MAX)	8000		string describing the model
+param1		VARCHAR(MAX)	8000		description of model parameter 1
+param2		VARCHAR(MAX)	8000		description of model parameter 2
+param3		VARCHAR(MAX)	8000		description of model parameter 3
+param4		VARCHAR(MAX)	8000		description of model parameter 4
+param5		VARCHAR(MAX)	8000		description of model parameter 5
+param6		VARCHAR(MAX)	8000		description of model parameter 6
+param7		VARCHAR(MAX)	8000		description of model parameter 7
+param8		VARCHAR(MAX)	8000		description of model parameter 8
+param9		VARCHAR(MAX)	8000		description of model parameter 9
+param10		VARCHAR(MAX)	8000		description of model parameter 10
+param11		VARCHAR(MAX)	8000		description of model parameter 11
+param12		VARCHAR(MAX)	8000		description of model parameter 12
+param13		VARCHAR(MAX)	8000		description of model parameter 13
+param14		VARCHAR(MAX)	8000		description of model parameter 14
+param15		VARCHAR(MAX)	8000		description of model parameter 15
+param16		VARCHAR(MAX)	8000		description of model parameter 16
+param17		VARCHAR(MAX)	8000		description of model parameter 17
+param18		VARCHAR(MAX)	8000		description of model parameter 18
+param19		VARCHAR(MAX)	8000		description of model parameter 19
+param20		VARCHAR(MAX)	8000		description of model parameter 20
+param21		VARCHAR(MAX)	8000		description of model parameter 21
+param22		VARCHAR(MAX)	8000		description of model parameter 22
+param23		VARCHAR(MAX)	8000		description of model parameter 23
+param24		VARCHAR(MAX)	8000		description of model parameter 24
+param25		VARCHAR(MAX)	8000		description of model parameter 25
+param26		VARCHAR(MAX)	8000		description of model parameter 26
+param27		VARCHAR(MAX)	8000		description of model parameter 27
+param28		VARCHAR(MAX)	8000		description of model parameter 28
+param29		VARCHAR(MAX)	8000		description of model parameter 29
+param30		VARCHAR(MAX)	8000		description of model parameter 30
+param31		VARCHAR(MAX)	8000		description of model parameter 31
+param32		VARCHAR(MAX)	8000		description of model parameter 32
+param33		VARCHAR(MAX)	8000		description of model parameter 33
+param34		VARCHAR(MAX)	8000		description of model parameter 34
+param35		VARCHAR(MAX)	8000		description of model parameter 35
+param36		VARCHAR(MAX)	8000		description of model parameter 36
+param37		VARCHAR(MAX)	8000		description of model parameter 37
+param38		VARCHAR(MAX)	8000		description of model parameter 38
+param39		VARCHAR(MAX)	8000		description of model parameter 39
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/ForcedWarpMeta
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/ForcedWarpMeta	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/ForcedWarpMeta	(revision 37066)
@@ -0,0 +1,33 @@
+forcedWarpID dimensionless   BIGINT 8 NA stack identifier
+batchID          dimensionless   BIGINT 8 NA batch identifier
+surveyID         dimensionless   TINYINT 1 NA survey flag identifier
+filterID         dimensionless   TINYINT 1 NA fnilutemr eidriecnatl ifidier
+skyCellID        dimensionless   REAL 4 NA skycell region identifier 
+photoCalID       dimensionless   INT 4 NA photometry code
+magSat           dimensionless   REAL 4 -999 saturation magnitude level
+analVer          dimensionless   SMALLINT 2 -999 analysis version index
+expTime          seconds         REAL 4 -999 exposure time
+completMag       magnitudes      REAL 4 -999 95% completion level in mag
+astroScat        dimensionless   REAL 4 -999 astrometric scatter for chip
+photoScat        dimensionless   REAL 4 -999 photometric scatter for chip
+nAstroRef        dimensionless   INT 4 -999 number of astrometric reference sources
+nPhoRef          dimensionless   INT 4 -999 number of photometric reference sources
+psfModelID       dimensionless   VARCHAR(MAX) 8000 PSF model identifier
+psfFwhm_mean     arcsec         FLOAT 8 -999 mean PSF FWHM in the stack
+psfFwhm_max      arcsec         FLOAT 8 -999 maximum PSF FWHM in the stack 
+photoZero        magnitudes     REAL 4 -999 local derived photometric zero point
+photoColor       magnitudes     REAL 4 -999 local derived photometric color term
+ctype1           alphanumeric   VARCHAR(MAX) 8000 name of astrometric projection in RA
+ctype2           alphanumeric   VARCHAR(MAX) 8000 name of astrometric projection in DEC
+crval1           degrees        FLOAT 8 -999 RA corresponding to reference pixel
+crval2           degrees        FLOAT 8 -999 DEC corresponding to reference pixel
+crpix1           dimensionless  FLOAT 8 -999 reference pixel value for RA
+crpix2           dimensionless  FLOAT 8 -999 reference pixel value for DEC
+cdelt1           deg/pixel      FLOAT 8 -999 scale factor for RA
+cdelt2           deg/pixel      FLOAT 8 -999 scale factor for DEC
+pc001001         dimensionless  FLOAT 8 -999 elements of rotation/Dcale matrix 
+pc001002         dimensionless  FLOAT 8 -999 elements of rotation/Dcale matrix
+pc002001         dimensionless  FLOAT 8 -999 elements of rotation/Dcale matrix
+pc002002         dimensionless  FLOAT 8 -999 elements of rotation/Dcale matrix
+calibModNum      dimensionless  SMALLINT 2 NA calibration modification number
+dataRelease      dimensionless  TINYINT 1 NA Data release
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/ForcedWarpToImage
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/ForcedWarpToImage	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/ForcedWarpToImage	(revision 37066)
@@ -0,0 +1,2 @@
+forcedWarpID 	BIGINT 	8 	NA 	forced warp identifier
+imageID 		BIGINT 	8 	NA 	hashed exposure-ccdID identifier
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/FrameMeta
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/FrameMeta	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/FrameMeta	(revision 37066)
@@ -0,0 +1,49 @@
+frameID	dimensionless	INT	4	NA	unique exposure/frame identifier.
+frameName	dimensionless	VARCHAR(32)	32	NA	frame name provided by camera software
+surveyID	dimensionless	TINYINT	1	NA	survey flag identifier
+filterID	dimensionless	TINYINT	1	NA	filter identifier
+cameraID	dimensionless	SMALLINT	2	NA	camera identifier
+cameraConfigID	dimensionless	SMALLINT	2	NA	camera configuration identifier
+telescopeID	dimensionless	SMALLINT	2	NA	telescope identifier
+analysisVer	alphanumeric	VARCHAR(MAX)	8000		IPP software analysis release
+p1Recip	alphanumeric	VARCHAR(MAX)	8000		IPP phase 1 MD5 Checksum
+p2Recip	alphanumeric	VARCHAR(MAX)	8000		IPP phase 2 MD5 Checksum
+p3Recip	alphanumeric	VARCHAR(MAX)	8000		IPP phase 3 MD5 Checksum
+nOTA	alphanumeric	SMALLINT	2	-999	number of valid OTA/CCD images in this exposure
+photoScat	magnitude	REAL	4	-999	global photometric scatter
+numPhotoRef	dimensionless	INT	4	-999	number of photometric reference sources
+expStart	days	FLOAT	8	-999	exposure start time in MJD
+expTime	seconds	REAL	4	-999	exposure time
+airmass	dimensionless	REAL	4	-999	airmass at mid-exposure
+raBore	degrees	FLOAT	8	-999	RA of telescope boresight
+decBore	degrees	FLOAT	8	-999	DEC of telescope boresight
+ctype1	alphanumeric	VARCHAR(MAX)	8000		name of astrometric projection in RA
+ctype2		VARCHAR(MAX)	8000		name of astrometric projection in DEC
+crval1	degrees	FLOAT	8	-999	RA corresponding to reference pixel
+crval2	degrees	FLOAT	8	-999	DEC corresponding to reference pixel
+crpix1	pc001001	FLOAT	8	-999	reference pixel value for RA
+crpix2	dimensionless	FLOAT	8	-999	reference pixel value for DEC
+cdelt1	degrees/pixel	FLOAT	8	-999	scale factor for RA
+cdelt2	degrees/pixel	FLOAT	8	-999	scale factor for DEC
+pc001001	dimensionless	FLOAT	8	-999	elements of rotation/Dcale matrix
+pc001002	dimensionless	FLOAT	8	-999	elements of rotation/Dcale matrix
+pc002001	dimensionless	FLOAT	8	-999	elements of rotation/Dcale matrix
+pc002002	dimensionless	FLOAT	8	-999	elements of rotation/Dcale matrix
+polyOrder	dimensionless	TINYINT	1	255	polynomial order of astrometry fit
+pca1x3y0	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca1x2y1	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca1x1y2	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca1x0y3	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca1x2y0	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca1x1y1	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca1x0y2	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca2x3y0	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca2x2y1	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca2x1y2	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca2x0y3	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca2x2y0	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca2x1y1	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca2x0y2	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+calibModNum	dimensionless	SMALLINT	2	NA	calibration modification number
+batchID 	dimensionless	BIGINT	8	NA	batch ID 
+dataRelease	dimensionless	TINYINT	1	NA	Data release Version of this table
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/ImageFlags
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/ImageFlags	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/ImageFlags	(revision 37066)
@@ -0,0 +1,3 @@
+name VARCHAR(32) 32 NA Name of flag
+value BIGINT 8 NA Flag value
+description VARCHAR(2000) 2000 Description of the flag
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/ImageMeta
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/ImageMeta	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/ImageMeta	(revision 37066)
@@ -0,0 +1,74 @@
+imageID		dimensionless	BIGINT	8	NA	unique ID for each image, hashed from frameID and ccdID 
+frameID		dimensionless	INT	4	NA	frame identifier, also known as exposure number
+ccdID		dimensionless	SMALLINT	2	NA	ccd cell identifier in the focal plane
+photoCalID      dimensionless	INT	4	NA	photometry reduction code identifier
+filterID	dimensionless	TINYINT	1	NA	filter ID
+bias		ADU		REAL	4	-999	detector bias level
+biasScat	ADU		REAL	4	-999	scatter in bias level
+sky		ADU/pixel	REAL	4	-999	mean sky level
+skyScat		ADU/pixel	REAL	4	-999	scatter in mean sky level
+nDetect		dimensionless	INT	4	-999	number of detections on CCD
+magSat		magnitude	REAL	4	-999	saturation magnitude level
+completMag	magnitude	REAL	4	-999	95% completion level in mag
+astroScat	arcsec		REAL	4	-999	astrometric scatter for chip
+photoScat	magitude	REAL	4	-999	photometric scatter for chip
+numAstroRef	dimensionless	INT	4	-999	number of astrometric reference sources
+numPhotoRef	dimensionless	INT	4	-999	number of photometric reference sources
+nx		pixels		SMALLINT	2	-999	chip dimension in x
+ny		pixels		SMALLINT	2	-999	chip dimension in y
+psfModelID	dimensionless	INT	4	-999	PSF model identifier
+psfFwhm		arcsec		REAL	4	-999	model psf full width at half maximum at chip center
+psfWidMajor	arcsec		REAL	4	-999	model PSF parameters at chip center
+psfWidMinor	arcsec		REAL	4	-999	model PSF parameters at chip center
+psfTheta	degrees		REAL	4	-999	model PSF parameters at chip center
+momentXX        pixels  	REAL    4       -999    moment XX
+momentXY        pixels  	REAL    4       -999    moment XY
+momentYY        pixels  	REAL    4       -999    moment YY
+momentM3C       pixels squared  REAL    4       -999    moment M3C
+momentM3S       pixels squared  REAL    4       -999    moment M3S
+momentM4C       pixels squared  REAL    4       -999    moment M4C
+momentM4S       pixels squared  REAL    4       -999    moment M4S
+momentR1        pixels  	REAL    4       -999    moment R1
+momentRH        sqrt pixels     REAL    4       -999    moment RH
+apResid		magnitide	REAL	4	-999	corrected aperture residual
+dapResid	magnitide	REAL	4	-999	scatter of aperture corrections
+detectorID	alphanumeric	VARCHAR(32)	32		identifier for actual CCD chip
+qaFlags		dimensionless	BIGINT	8	-999	Q/A flags for this OTA
+detrend1	alphanumeric	VARCHAR(MAX)	8000		identifier of detrend image 1
+detrend2	alphanumeric	VARCHAR(MAX)	8000		identifier of detrend image 2
+detrend3	alphanumeric	VARCHAR(MAX)	8000		identifier of detrend image 3
+detrend4	alphanumeric	VARCHAR(MAX)	8000		identifier of detrend image 4
+detrend5	alphanumeric	VARCHAR(MAX)	8000		identifier of detrend image 5
+detrend6	alphanumeric	VARCHAR(MAX)	8000		identifier of detrend image 6
+detrend7	alphanumeric	VARCHAR(MAX)	8000		identifier of detrend image 7
+detrend8	alphanumeric	VARCHAR(MAX)	8000		identifier of detrend image 8
+photoZero	magnitude	REAL	4	-999	local derived photometric zero point
+ctype1		alphanumeric	VARCHAR(MAX)	8000		name of astrometric projection in RA
+ctype2		alphanumeric	VARCHAR(MAX)	8000		name of astrometric projection in DEC
+crval1		degrees	FLOAT	8	-999	RA corresponding to reference pixel
+crval2		degrees	FLOAT	8	-999	DEC corresponding to reference pixel
+crpix1		pixels	FLOAT	8	-999	reference pixel value for RA
+crpix2		pixels	FLOAT	8	-999	reference pixel value for DEC
+cdelt1		degrees/pixel	FLOAT	8	-999	scale factor for RA
+cdelt2		degrees/pixel	FLOAT	8	-999	scale factor for DEC
+pc001001	unknown	FLOAT	8	-999	elements of rotation/Dcale matrix
+pc001002	unknown	FLOAT	8	-999	elements of rotation/Dcale matrix
+pc002001	unknown	FLOAT	8	-999	elements of rotation/Dcale matrix
+pc002002	unknown	FLOAT	8	-999	elements of rotation/Dcale matrix
+polyOrder	dimensionless	TINYINT	1	255	polynomial order of astrometry fit
+pca1x3y0	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca1x2y1	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca1x1y2	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca1x0y3	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca1x2y0	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca1x1y1	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca1x0y2	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca2x3y0	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca2x2y1	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca2x1y2	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca2x0y3	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca2x2y0	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca2x1y1	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca2x0y2	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+calibModNum	dimensionless	SMALLINT	2	NA	calibration modification number
+dataRelease	dimensionless	TINYINT	1	NA	Data release Version of this table
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/Mask
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/Mask	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/Mask	(revision 37066)
@@ -0,0 +1,9 @@
+maskID BIGINT 8 NA mask identifier
+partitionKey BIGINT 8 NA fget(mask_center_ra, mask_center_dec, zoneH)
+frameID INT 4 NA reference to the P2FrameMeta table where the mask is defined
+imageID BIGINT 8 NA reference to the P2FrameMeta table where the mask is
+ra FLOAT 8 NA rdae finin ethde center
+dec FLOAT 8 NA dec in the center
+radius FLOAT 8 NA No comment
+maskString VARCHAR(MAX) 8000 string representation fo the mask region
+maskBinary VARBINARY(MAX) 8000 0x Binary object managed by the spatial library
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/MovingObjToDet
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/MovingObjToDet	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/MovingObjToDet	(revision 37066)
@@ -0,0 +1,2 @@
+MovingObjID  	BIGINT 	8 	NA 	Moving Object identifier  
+DetectionID 	BIGINT 	8 	NA 	detection identifier  
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/MovingObjToDiffDet
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/MovingObjToDiffDet	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/MovingObjToDiffDet	(revision 37066)
@@ -0,0 +1,2 @@
+MovingObjID  	BIGINT 	8 	NA 	Moving Object identifier  
+DiffDetID 	BIGINT 	8 	NA 	difference image detection identifier  
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/MovingObjToObject
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/MovingObjToObject	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/MovingObjToObject	(revision 37066)
@@ -0,0 +1,2 @@
+MovingObjID  	BIGINT 	8 	NA 	Moving Object identifier
+ObjID 	 	BIGINT 	8 	NA 	Object identifier
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/ObjectFilterFlags
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/ObjectFilterFlags	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/ObjectFilterFlags	(revision 37066)
@@ -0,0 +1,3 @@
+name	dimensionless	VARCHAR(32)	32		Name of flag
+value	dimensionless	BIGINT	8	NA	Flag value
+description	dimensionless	VARCHAR(2000)	2000		Description of the flag
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/ObjectInfoFlags
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/ObjectInfoFlags	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/ObjectInfoFlags	(revision 37066)
@@ -0,0 +1,3 @@
+name	dimensionless	VARCHAR(32)	32		Name of flag
+value	dimensionless	BIGINT	8	NA	Flag value
+description	dimensionless	VARCHAR(2000)	2000		Description of the flag
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/ObjectQualityFlags
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/ObjectQualityFlags	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/ObjectQualityFlags	(revision 37066)
@@ -0,0 +1,3 @@
+name	dimensionless	VARCHAR(32)	32		Name of flag
+value	dimensionless	BIGINT	8	NA	Flag value
+description	dimensionless	VARCHAR(2000)	2000		Description of the flag
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/PhotoCal
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/PhotoCal	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/PhotoCal	(revision 37066)
@@ -0,0 +1,11 @@
+photoCalID		INT	4	NA	numerical code for this reduction
+filterID		TINYINT	1	NA	filter id
+photoCodeDesc		VARCHAR(MAX)	8000		Photometry reduction code name
+AB		REAL	4	1.0	AB magnitude
+zeropoint		REAL	4	-999	photometric zero point (excluding long term variation)
+extinction		REAL	4	-999	photometric extinction term (excluding long term variation)
+colorterm		REAL	4	-999	photometric color term (excluding long term variation)
+colorExtn		REAL	4	-999	photometric color dependent extinction (excluding long term variation)
+orphanCalColor		REAL	4	-999	color adopted for magnitude calculation
+orphanCalColorErr		REAL	4	-999	error in calibrating color
+startDate	day	REAL	4	NA	starting date of this configuration in MJD
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/ProjectionCell
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/ProjectionCell	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/ProjectionCell	(revision 37066)
@@ -0,0 +1,22 @@
+projectionCellID 		INT 4 NA projection cell unique identifier
+partitionKey 			BIGINT 8 NA fGetPanObjID(crval1,crval2)
+primaryCellRegionID 		BIGINT 8 NA reference to the primary cell region definition in the Region table
+projectionCellRegionID 		BIGINT 8 NA reference to the projectio cell region definition in the
+ctype1 				VARCHAR(MAX) 8000 NA nRaemgieo no ft aabsltero)metric projection in RA
+ctype2 				VARCHAR(MAX) 8000 NA name of astrometric projection in DEC
+crval1 deg 			FLOAT 8 NA RA corresponding to reference pixel
+crval2 deg 			FLOAT 8 NA DEC corresponding to reference pixel
+crpix1 				FLOAT 8 NA reference pixel value for RA
+crpix2 				FLOAT 8 NA reference pixel value for DEC
+pc001001 			FLOAT 8 NA elements of rotation/Dcale matrix
+pc001002 			FLOAT 8 NA elements of rotation/Dcale matrix
+pc002001 			FLOAT 8 NA elements of rotation/Dcale matrix
+pc002002 			FLOAT 8 NA elements of rotation/Dcale matrix
+raNEcornerPC   degrees          FLOAT  8 -999 ra of NE corner
+decNEcornerPC  degrees          FLOAT  8 -999 dec of NE corner
+raNWcornerPC   degrees          FLOAT  8 -999 ra of NE corner
+decNWcornerPC  degrees          FLOAT  8 -999 dec of NE corner
+raSEcornerPC   degrees          FLOAT  8 -999 ra of NE corner
+decSEcornerPC  degrees          FLOAT  8 -999 dec of NE corner
+raSWcornerPC   degrees          FLOAT  8 -999 ra of NE corner
+decSWcornerPC  degrees          FLOAT  8 -999 dec of NE corner
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/PsConstant
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/PsConstant	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/PsConstant	(revision 37066)
@@ -0,0 +1,4 @@
+name VARCHAR(32) 32 NA constant's name
+value FLOAT 8 NA constant's value
+unit VARCHAR(32) 32 unit of constant
+description VARCHAR(2000) 2000 description of the constant
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/Region
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/Region	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/Region	(revision 37066)
@@ -0,0 +1,7 @@
+regionID dimensionless	BIGINT 8 NA Unique Region identifier 
+id 	 dimensionless	BIGINT 8 NA Custom Identifier
+type 	 string         VARCHAR(16) 16 NA Region type
+comment  string         VARCHAR(MAX) 8000 Comment
+area     sqdeg?         FLOAT 8 0 Area covered by the region
+region   dimensionless	Binary VARBINARY(MAX) 8000 0x Binary object managed by the spatial library
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/RegionPatch
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/RegionPatch	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/RegionPatch	(revision 37066)
@@ -0,0 +1,15 @@
+Unit Data Type Size Default Value Description
+regionid BIGINT 8 NA No comment
+convexid BIGINT 8 NA No comment
+patchid INT 4 NA No comment
+type (16) NA No comment
+radius FLOAT 8 0 No comment
+ra degree FLOAT 8 0 Right Ascension
+dec FLOAT 8 0 No comment
+x FLOAT 8 0 No comment
+y FLOAT 8 0 No comment
+z FLOAT 8 0 No comment
+c FLOAT 8 0 No comment
+htmid BIGINT 8 0 No comment
+area FLOAT 8 0 No comment
+convexString (MAX) No comment
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/SkyCell
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/SkyCell	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/SkyCell	(revision 37066)
@@ -0,0 +1,12 @@
+skyCellID   dimensionless I	INT 4 NA indentifier of the sky cell
+projectionCellID 		INT 4 -999 indentifier of the projection cell
+partitionKey 	 		BIGINT 8 -999 fgetPANobjID(skyCell_center_ra, skyCell_center_dec, zHeight)
+regionID 	 		BIGINT 8 -999 region identifier in the Region table
+raNEcorner   degrees            FLOAT  8 -999 ra of NE corner
+decNEcorner  degrees            FLOAT  8 -999 dec of NE corner
+raNWcorner   degrees            FLOAT  8 -999 ra of NE corner
+decNWcorner  degrees            FLOAT  8 -999 dec of NE corner
+raSEcorner   degrees            FLOAT  8 -999 ra of NE corner
+decSEcorner  degrees            FLOAT  8 -999 dec of NE corner
+raSWcorner   degrees            FLOAT  8 -999 ra of NE corner
+decSWcorner  degrees            FLOAT  8 -999 dec of NE corner
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/StackDetectionFlags
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/StackDetectionFlags	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/StackDetectionFlags	(revision 37066)
@@ -0,0 +1,3 @@
+Name	dimensionless	VARCHAR(32)	32		Name of flag
+value	dimensionless	BIGINT	8	NA	Flag value
+description	dimensionless	VARCHAR(2000)	2000		Description of the flag
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/StackMeta
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/StackMeta	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/StackMeta	(revision 37066)
@@ -0,0 +1,35 @@
+stackMetaID dimensionless   BIGINT 8 NA stack identifier
+batchID     dimensionless   BIGINT 8 NA batch identifier
+surveyID    dimensionless   TINYINT 1 NA survey flag identifier
+filterID    dimensionless   TINYINT 1 NA fnilutemr eidriecnatl ifidier
+stackTypeID dimensionless   TINYINT 1 0 stack type identifier
+skyCellID   dimensionless   REAL 4 NA skycell region identifier 
+photoCalID  dimensionless   INT 4 NA photometry code
+magSat      dimensionless   REAL 4 -999 saturation magnitude level
+analVer     dimensionless   SMALLINT 2 -999 analysis version index
+expTime     seconds         REAL 4 -999 exposure time
+nP2Images   dimensionless   SMALLINT 2 -999 number of P2 images contributing to this cell
+completMag  magnitudes      REAL 4 -999 95% completion level in mag
+astroScat   dimensionless   REAL 4 -999 astrometric scatter for chip
+photoScat   dimensionless   REAL 4 -999 photometric scatter for chip
+nAstroRef   dimensionless   INT 4 -999 number of astrometric reference sources
+nPhoRef     dimensionless   INT 4 -999 number of photometric reference sources
+psfModelID  dimensionless   VARCHAR(MAX) 8000 PSF model identifier
+psfFwhm_mean arcsec         FLOAT 8 -999 mean PSF FWHM in the stack
+psfFwhm_max  arcsec         FLOAT 8 -999 maximum PSF FWHM in the stack 
+photoZero    magnitudes     REAL 4 -999 local derived photometric zero point
+photoColor   magnitudes     REAL 4 -999 local derived photometric color term
+ctype1       alphanumeric   VARCHAR(MAX) 8000 name of astrometric projection in RA
+ctype2       alphanumeric   VARCHAR(MAX) 8000 name of astrometric projection in DEC
+crval1       degrees        FLOAT 8 -999 RA corresponding to reference pixel
+crval2       degrees        FLOAT 8 -999 DEC corresponding to reference pixel
+crpix1       dimensionless  FLOAT 8 -999 reference pixel value for RA
+crpix2       dimensionless  FLOAT 8 -999 reference pixel value for DEC
+cdelt1       deg/pixel      FLOAT 8 -999 scale factor for RA
+cdelt2       deg/pixel      FLOAT 8 -999 scale factor for DEC
+pc001001     dimensionless  FLOAT 8 -999 elements of rotation/Dcale matrix 
+pc001002     dimensionless  FLOAT 8 -999 elements of rotation/Dcale matrix
+pc002001     dimensionless  FLOAT 8 -999 elements of rotation/Dcale matrix
+pc002002     dimensionless  FLOAT 8 -999 elements of rotation/Dcale matrix
+calibModNum  dimensionless  SMALLINT 2 NA calibration modification number
+dataRelease  dimensionless  TINYINT 1 NA Data release
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/StackToImage
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/StackToImage	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/StackToImage	(revision 37066)
@@ -0,0 +1,2 @@
+stackMetaID 	BIGINT 	8 	NA 	stack identifier
+imageID 	BIGINT 	8 	NA 	hashed exposure-ccdID identifier
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/StackType
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/StackType	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/StackType	(revision 37066)
@@ -0,0 +1,3 @@
+stackTypeID		TINYINT	1	-999	stack type identifier
+name		VARCHAR(20)	20		stack type name
+description		VARCHAR(MAX)	8000		stack type description
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/Survey
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/Survey	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/Survey	(revision 37066)
@@ -0,0 +1,4 @@
+SurveyID TINYINT 1 NA index of survey type
+name VARCHAR(6) 6 survey name
+description VARCHAR(MAX) 8000 
+survey description
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/TelescopeConfig
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/TelescopeConfig	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/TelescopeConfig	(revision 37066)
@@ -0,0 +1,16 @@
+TelescopeConfig
+Description: Telescope configuration
+
+Name      	Unit		        DataType    Size	Default		ValueDescription 
+
+TelescopeID  	dimensionless   	SMALLINT 	2 	   -999         Telescope identifier (i.e. PS1, ISP)
+TeleConfigID    dimensionless           SMALLINT        2          -999         Telescope Configuration ID
+MountModel      string                                  8            NA         Mount Model Name
+MirrorModel     string                                  8            NA         Mirror Model Name
+Observera       string                                  8            NA         Observers Name
+endDate         MeanJulianDays   	    FLOAT       8          -999         ending date of this configuration in MJD
+configDetails   string           VARCHAR(MAX) 8000      0x00         NA         text/table giving the details of the telescope configuration
+
+
+
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/pcsGalaxyModel
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/pcsGalaxyModel	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/pcsGalaxyModel	(revision 37066)
@@ -0,0 +1,3 @@
+galaxyModelID	dimensionless	INT	4	NA	modelID
+description	dimensionless	VARCHAR(128)	128		model description, spectral type etc.
+priors	dimensionless	VARCHAR(128)	128		priors applied to this model, may also split into 7 columns
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/pcsPhotoZRecipe
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/pcsPhotoZRecipe	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/pcsPhotoZRecipe	(revision 37066)
@@ -0,0 +1,2 @@
+photozRecipeID	dimensionless	TINYINT	1	-999	recipe index
+description	dimensionless	VARCHAR(MAX)	8000		string\ describing\ the\ recipe
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/pcsSGSepRecipe
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/pcsSGSepRecipe	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/pcsSGSepRecipe	(revision 37066)
@@ -0,0 +1,2 @@
+sgSepRecipeID	dimensionless	INT	4	NA	Star/Galaxy Seperator Recuipe ID
+description	dimensionless	VARCHAR(128)	128		Description
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/pcsStarModel
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/pcsStarModel	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/pcsStarModel	(revision 37066)
@@ -0,0 +1,2 @@
+starModelID	dimensionless	INT	4	-999	modelID
+description	dimensionless	VARCHAR(128)	128		model description, spectral type etc
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/pcsStellarParamsRecipe
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/pcsStellarParamsRecipe	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_TABLES/MetaData_Tables/pcsStellarParamsRecipe	(revision 37066)
@@ -0,0 +1,3 @@
+stellarParamsRecipeID	dimensionless	INT	4	NA	Na
+description	dimensionless	VARCHAR(128)	128		Description:wq
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_VIEWS/README
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_VIEWS/README	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_VIEWS/README	(revision 37066)
@@ -0,0 +1,5 @@
+See Notes_on_Schema 03.txt
+for what tables are combined into what views.
+Once there is concensus on tables, then will combine tables to make views. Meanwhile can concatente yourself from Notes.
+
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_VIEWS/Views
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_VIEWS/Views	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew17.0/PSPS_VIEWS/Views	(revision 37066)
@@ -0,0 +1,17 @@
+
+PSPS VIEWS - examples  
+
+ObjectMean        = ObjectThin join MeanObject 
+ObjectStack       = ObjectThin join StackObject
+ObjectApFlx       = ObjectThin join StackApFlx  
+ObjectModel       = ObjectThin join StackModelFit   
+ObjectStackAll    = ObjectThin join StackObject and StackAp and StackModelFit 
+ObjectForcedMean  = ObjectThin join ForcedMeanObject
+ObjectPrimary     = ObjectThin join StackObject join StackApFlx where primaryDection is true
+ObjectBest        = ObjectThin join StackObject join StackApFlx where bestDetection is true
+
+
+
+
+
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/Notes_on_Schema10.txt
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/Notes_on_Schema10.txt	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/Notes_on_Schema10.txt	(revision 37066)
@@ -0,0 +1,132 @@
+Notes on Schema Version 9
+
+
+Proposed Image Products and PSPS Tables and Views
+
+IMAGE PRODUCTS 
+
+Survey  | Description               |  Image Products Saved
+
+3pi     | 3pi                       | 3pi warps, 3pi stacks
+CNP     | Celestial North Pole (3pi)| CNP warps, stacks
+SS      | ecliptic w band data      |   w warps, w stack
+MDD     | Medium Deep Deep          |  MD warps, deep stacks 
+MDT     | Medium Deep Template      |            template stacks
+MDN     | Medium Deep Nightly Stack |            nightly stacks 
+MDN     | Medium Deep Off Year      |            off year template stacks 
+M31     | M31                       | M31 warps, M31 stacks, template
+STS     | STS                       | STS warps, STS template - best iq stack 
+
+
+Survey  | Description               |  Image Products NOT Saved, but analyzed for difference detections and discarded 
+
+3pi     | difference                |3pi warps - stack 
+CNP     | difference                |CNP warps - stack 
+SS      | difference image          |  w warps - stack 
+MDD     | difference image          | MD warps - off year template stacks  
+MDO     | difference image          | MDN stacks - off year template stacks  
+M31     | difference image          | M31 warps - stack 
+STS     | difference image          | STS warps - template 
+
+
+
+PSPS TABLES                                                 
+
+
+Fundamental IPP Data Products  Origin 
+
+Detection                      detections found in detrended images   
+ObjectThin                     positonal and flag data, no fluxes   
+MeanObject                     extracted Mean properties as determined from individual Detections.   
+StackObject                    Stack Detections in all filters, with forced upperlimits, separate rows for primary, secondary, best stack detections (80% time only primary)  
+StackApFlx                     all filters in one table, unconvolved and convolved apertures (up to  6 , 8, 10(?) pixels  in all bands) 
+StackModelFit                  all filters in one table. Models of high signal to noise objects in low density regions.     
+DiffDet                        difference detections found in difference image = image - template 
+DiffObject                     associations of Difference Detections
+ForcedWarpMeasure              forced measurements on each warp in all filters at the position of an object found in a stack. Includes StackApFlx-like table   
+ForcedMeanObject               like MeanObject, but using the Forced Mean Measurements to form the Mean. 
+
+w band                         TBD 
+
+
+Derived Data Product Tables 
+
+pcsPhotoZ                       populated from PCS
+pcsPhotoZProbability            populated from PCS
+pcsStarGalQSOSep                populated from PCS
+pcsStellarParams                populated from PCS
+mopsMovingObject                populated from MOPS database
+ppmObj                          proper motion and parallax populated from IPP  
+tcsClassification               populated from transient server database
+galExtinction                   populated from Dust team
+stargal                         populated from various algorithms, combos of ipp parameters, fits to population as function of magnitude, or Support Vector Machine
+GoodObject                      selected and populated post-facto  
+StarGalaxySep                   selected and populated post-facto 
+
+
+Observational Metadata and System MetaData Tables
+
+CameraConfig
+DetectionFlags
+DiffMeta
+Filter
+FitModel
+ForcedWarpMeta
+FrameMeta
+ImageFlags
+ImageMeta                       add psf 3nd and 4th  moments
+Mask
+MovingObjectToDet
+MovingObjectToDiffDet
+MovingObjToObject
+ObjectFilterFlags               flag info not in current schema but in PSI interface...
+ObjectInfoFlags
+ObjectQualityFlags
+PhotoCal
+ProjectionCell
+ProcessingVersion
+SkyCell 
+StackDetectionFlags
+StackMeta                       
+StackToImage
+StackType
+Survey
+TelescopeConfig
+fitModel
+pcsGalaxyModel
+pcsPhotoZRecipe
+pcsSGSepRecipe
+pcsStarModel
+pcsStellarParamsRecipe
+
+
+
+PSPS VIEWS - examples  
+
+ObjectMean        = ObjectThin join MeanObject 
+ObjectStack       = ObjectThin join StackObject
+ObjectApFlx       = ObjectThin join StackApFlx  
+ObjectModel       = ObjectThin join StackModelFit   
+ObjectStackAll    = ObjectThin join StackObject and StackAp and StackModelFit 
+ObjectForcedMean  = ObjectThin join ForcedMeanObject
+ObjectPrimary     = ObjectThin join StackObject join StackApFlx where primaryDection is true
+ObjectBest        = ObjectThin join StackObject join StackApFlx where bestDetection is true
+
+
+PSPS Indicies 
+
+DetectionID
+ObjectID
+BatchID
+StackTypeID
+MovingObjID
+DiffObjID 
+RandomID           between 1 and 2^16 = 4,294,967,296 so you pick how many random objects you want ,
+                   i.e 10,000 pick randomid < 10,000 and if indexed, this will be very fast. 
+RandomStackID      between 1 and 2^16 = 4,294,967,296 so you pick how many random objects you want ,
+                   i.e 10,000 pick randomid < 10,000 and if indexed, this will be very fast. 
+
+
+
+
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/Notes_on_Schema11.txt
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/Notes_on_Schema11.txt	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/Notes_on_Schema11.txt	(revision 37066)
@@ -0,0 +1,132 @@
+Notes on Schema Version 9
+
+
+Proposed Image Products and PSPS Tables and Views
+
+IMAGE PRODUCTS 
+
+Survey  | Description               |  Image Products Saved
+
+3pi     | 3pi                       | 3pi warps, 3pi stacks
+CNP     | Celestial North Pole (3pi)| CNP warps, stacks
+SS      | ecliptic w band data      |   w warps, w stack
+MDD     | Medium Deep Deep          |  MD warps, deep stacks 
+MDT     | Medium Deep Template      |            template stacks
+MDN     | Medium Deep Nightly Stack |            nightly stacks 
+MDN     | Medium Deep Off Year      |            off year template stacks 
+M31     | M31                       | M31 warps, M31 stacks, template
+STS     | STS                       | STS warps, STS template - best iq stack 
+
+
+Survey  | Description               |  Image Products NOT Saved, but analyzed for difference detections and discarded 
+
+3pi     | difference                |3pi warps - stack 
+CNP     | difference                |CNP warps - stack 
+SS      | difference image          |  w warps - stack 
+MDD     | difference image          | MD warps - off year template stacks  
+MDO     | difference image          | MDN stacks - off year template stacks  
+M31     | difference image          | M31 warps - stack 
+STS     | difference image          | STS warps - template 
+
+
+
+PSPS TABLES                                                 
+
+
+Fundamental IPP Data Products  Origin 
+
+Detection                      detections found in detrended images   
+ObjectThin                     positonal and flag data, no fluxes   
+MeanObject                     extracted Mean properties as determined from individual Detections.   
+StackObject                    Stack Detections in all filters, with forced upperlimits, separate rows for primary, secondary, best stack detections (80% time only primary)  
+StackApFlx                     all filters in one table, unconvolved and convolved apertures (up to  6 , 8, 10(?) pixels  in all bands) 
+StackModelFit                  all filters in one table. Models of high signal to noise objects in low density regions.     
+DiffDet                        difference detections found in difference image = image - template 
+DiffObject                     associations of Difference Detections
+ForcedWarpMeasure              forced measurements on each warp in all filters at the position of an object found in a stack. Includes StackApFlx-like table   
+ForcedMeanObject               like MeanObject, but using the Forced Mean Measurements to form the Mean. 
+
+w band                         TBD 
+
+
+Derived Data Product Tables 
+
+pcsPhotoZ                       populated from PCS
+pcsPhotoZProbability            populated from PCS
+pcsStarGalQSOSep                populated from PCS
+pcsStellarParams                populated from PCS
+mopsMovingObject                populated from MOPS database
+ppmObj                          proper motion and parallax populated from IPP  
+tcsClassification               populated from transient server database
+galExtinction                   populated from Dust team
+stargal                         populated from various algorithms, combos of ipp parameters, fits to population as function of magnitude, or Support Vector Machine
+GoodObject                      selected and populated post-facto  
+StarGalaxySep                   selected and populated post-facto 
+
+
+Observational Metadata and System MetaData Tables
+
+CameraConfig
+DetectionFlags
+DiffMeta
+Filter
+FitModel
+ForcedWarpMeta
+FrameMeta
+ImageFlags
+ImageMeta                       add psf 3nd and 4th  moments
+Mask
+MovingObjectToDet
+MovingObjectToDiffDet
+MovingObjToObject
+ObjectFilterFlags               flag info not in current schema but in PSI interface...
+ObjectInfoFlags
+ObjectQualityFlags
+PhotoCal
+ProjectionCell
+ProcessingVersion
+SkyCell 
+StackDetectionFlags
+StackMeta                       
+StackToImage
+StackType
+Survey
+TelescopeConfig
+fitModel
+pcsGalaxyModel
+pcsPhotoZRecipe
+pcsSGSepRecipe
+pcsStarModel
+pcsStellarParamsRecipe
+
+
+
+PSPS VIEWS - examples  
+
+ObjectMean        = ObjectThin join MeanObject 
+ObjectStack       = ObjectThin join StackObject
+ObjectApFlx       = ObjectThin join StackApFlx  
+ObjectModel       = ObjectThin join StackModelFit   
+ObjectStackAll    = ObjectThin join StackObject and StackAp and StackModelFit 
+ObjectForcedMean  = ObjectThin join ForcedMeanObject
+ObjectPrimary     = ObjectThin join StackObject join StackApFlx where primaryDection is true
+ObjectBest        = ObjectThin join StackObject join StackApFlx where bestDetection is true
+
+
+PSPS Indicies 
+
+DetectionID
+ObjectID
+BatchID
+StackTypeID
+MovingObjID
+DiffObjID 
+RandomID           between 1 and 2^16 = 4,294,967,296 so you pick how many random objects you want ,
+                   i.e 10,000 pick randomid < 10,000 and if indexed, this will be very fast. 
+RandomStackID      between 1 and 2^16 = 4,294,967,296 so you pick how many random objects you want ,
+                   i.e 10,000 pick randomid < 10,000 and if indexed, this will be very fast. 
+
+
+
+
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/Notes_on_Schema12.txt
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/Notes_on_Schema12.txt	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/Notes_on_Schema12.txt	(revision 37066)
@@ -0,0 +1,2 @@
+Heather cleaned up the column names and types to make them consistent.
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/Notes_on_Schema13.txt
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/Notes_on_Schema13.txt	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/Notes_on_Schema13.txt	(revision 37066)
@@ -0,0 +1,8 @@
+changes by EAM:
+* added lensing terms to ForcedWarpMeasurement & ForcedMeanObject
+* removed fluxPeak and momentRH generally
+* changed psfWidMajor,Minor to psfMajorFWHM,psfMinorFWHM
+* added psfCore (k term in psf model : 1 / (1 + kz + k^1.667)
+* fixed stack flux & mag names
+* set units for moments to be in arcsec everywhere.
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Derived_Data_Product_Tables/GoodObject
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Derived_Data_Product_Tables/GoodObject	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Derived_Data_Product_Tables/GoodObject	(revision 37066)
@@ -0,0 +1,4 @@
+objName         string          VAR     8       NA      IAU Name constructed from objID postion PS1.x JHHMMSS.SS+/-DDMMSS.S where x is leading number of procesing version
+objID           dimensionless   BIGINT  8       NA      ODM object identifier index
+ippObjID        dimensionless   BIGINT  8       NA      IPP object number
+goodObjectID    dimensionless   BIGINT  8       NA      index for post-facto "good objects" subset from ObjID 
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Derived_Data_Product_Tables/StarGalaxySep
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Derived_Data_Product_Tables/StarGalaxySep	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Derived_Data_Product_Tables/StarGalaxySep	(revision 37066)
@@ -0,0 +1,9 @@
+objName         string          VAR     8       NA      IAU Name constructed from objID postion PS1.x JHHMMSS.SS+/-DDMMSS.S where x is leading number of procesing version
+objID           dimensionless   BIGINT  8       NA      ODM object identifier index
+ippObjID        dimensionless   BIGINT  8       NA      IPP object number
+sgbinarySep1    dimensionless   TINYINT 2       255     binary flag for star galaxy separator - technique 1
+sgbinarySep2    dimensionless   TINYINT 2       255     binary flag for star galaxy separator - technique 2
+sgbinarySep3    dimensionless   TINYINT 2       255     binary flag for star galaxy separator - technique 3
+sgSep1          dimensionless   REAL    4       -999    probility of star/galaxy technique 1  
+sgSep2          dimensionless   REAL    4       -999    probility of star/galaxy technique 2  
+sgSep3          dimensionless   REAL    4       -999    probility of star/galaxy technique 3  
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Derived_Data_Product_Tables/galExtinction
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Derived_Data_Product_Tables/galExtinction	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Derived_Data_Product_Tables/galExtinction	(revision 37066)
@@ -0,0 +1,28 @@
+galExtinction 
+Name	Unit	Data Type	Size	Default Value	Description
+
+objID				dimensionless	BIGINT	8	NA	ODM object identifier index
+ippObjID			dimensionless	BIGINT	8	NA	IPP object number
+
+From Doug and Eddie ?
+
+E(B-V)
+
+gGalext
+rGalext
+iGalext
+zGalext
+yGalext
+wGalext
+probability vector
+
+stellar parameters
+Teff
+g_surf
+[Fe/H]
+
+
+
+
+
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Derived_Data_Product_Tables/mopsMovingObject
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Derived_Data_Product_Tables/mopsMovingObject	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Derived_Data_Product_Tables/mopsMovingObject	(revision 37066)
@@ -0,0 +1,28 @@
+Name Unit Data Type Size Default Value Description
+
+MovingObjName   dimensionless	STRING 	x	-999	MPC Name 
+MovingObjType   dimensionless 	STRING 	x	-999 	Type of moving object (NEO, PHA, COMET, ...)
+MovingObjID     dimensionless	BIGINT 8 	-999  	Moving Object identifier     
+OrbEpoch        date		DATE     	-999  	The epoch of osculation of the orbital elements.
+Moid       	au		REAL   	4 	-999  	Minimum orbit intersection distance 
+OrbM       	dimensionles	REAL	4	-999	Mean anomaly at the epoch.
+OrbT       	date 		DATE 	  	-999    Date of perihelion passage.
+ORBn 		deg/day		REAL	4	-999	Mean daily motion (in degrees/day).
+ORBa       	AU		REAL	4	-999	Semimajor axis (in AU).
+ORBz       	1/AU		REAL	4	-999 	Reciprocal semimajor axis (in 1/AU).
+ORBq       	AU		REAL	4	-999	Perihelion distance (in AU).
+ORBe       	dimensionless	REAL	4	-999	Orbital eccentricity.
+OrbP       	years		REAL	4	-999	Orbital period (in years).
+OrbPeri    	degrees		REAL	4	-999	The J2000.0 argument of perihelion (in degrees).
+OrbNode    	degrees		REAL	4	-999	The J2000.0 longitude of the ascending node (in degrees).
+OrbIncl    	degrees		REAL	4	-999	The J2000.0 inclination (in degrees).
+P1         	dimensionless	REAL	4	-999	P1 first component of P vector
+P2	        dimensionless   REAL    4       -999    P2 second component of P vector 
+P3              dimensionless   REAL    4       -999    P3 third component of P vector
+Q1         	dimensionless   REAL    4       -999    Q1 first component of Q vector
+Q2         	dimensionless 	REAL    4	-999    Q2 second component of Q vector
+Q3         	dimensionless   REAL    4       -999    Q3 third component of Q vector
+U               dimensionless   REAL    4       -999    Uncertainty parameter.
+H               dimensionless   REAL    4       -999    Absolute visual magnitude. A table converting H to a diameter is available.
+G               dimensionless   REAL    4       -999    Slope parameter. 
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Derived_Data_Product_Tables/pcsPhotoZ
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Derived_Data_Product_Tables/pcsPhotoZ	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Derived_Data_Product_Tables/pcsPhotoZ	(revision 37066)
@@ -0,0 +1,21 @@
+pcsPhotoZ
+Name	Unit	Data Type	Size	Default Value	Description
+
+objID			BIGINT	8	NA	ODM object identifier index
+ippObjID		BIGINT	8	NA	IPP object number
+pcsPhotoZRecipeID	INT	4	-999	Recipe of the photoZ calculation
+galExt			REAL	4	-999	Galactic extinction E(B-V) used for photoz determination (derived from Schlegel Maps)
+photoz_1		REAL	4	-999	PhotoZ for best fitting template
+photozErr_1		REAL	4	-999	Estimated error for this tempalte
+chi2_1			REAL	4	-999	Chi^2 for this template
+modelID_1		INT	4	-999	Identifier for the template for this recipe
+photoz_2		REAL	4	-999	PhotoZ for second template
+photozErr_2		REAL	4	-999	Estimated error for this tempalte
+chi2_2			REAL	4	-999	Chi^2 for this template
+modelID_2		INT	4	-999	Identifier for the template for this recipe
+flags_gtfit		INT	4	-999	warning flags (e.g. missing band(s), unreliable galExt value etc.), TBD
+av			REAL	4	-999	determined extinction
+chi2			REAL	4	-999	chi2 for the best fitting stellar template
+modelID			INT	4	-999	modelID of the best fitting stellar template
+flags_stfit		INT	4	-999	warning flags from stellar template fitting
+starGalQSOSep		INT	4	-999	0: Object is a star (chi2
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Derived_Data_Product_Tables/pcsPhotoZProbabiity
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Derived_Data_Product_Tables/pcsPhotoZProbabiity	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Derived_Data_Product_Tables/pcsPhotoZProbabiity	(revision 37066)
@@ -0,0 +1,37 @@
+PhotoZProbability
+Name	Unit	Data Type	Size	Default Value	Description
+
+objID			dimensionless	BIGINT	8	NA	ODM object identifier index
+ippObjID		dimensionless	BIGINT	8	NA	IPP object number
+pcsPhotoZRecipeID	dimensionless	INT	4	-999	recipe for the photoz determination
+modelID			dimensionless	INT	4	-999	modelID of the template
+sp1	dimensionless	REAL	4	-999	spline params 1
+sp2	dimensionless	REAL	4	-999	spline params 2
+sp3	dimensionless	REAL	4	-999	spline params 3
+sp4	dimensionless	REAL	4	-999	spline params 4
+sp5	dimensionless	REAL	4	-999	spline params 5
+sp6	dimensionless	REAL	4	-999	spline params 6
+sp7	dimensionless	REAL	4	-999	spline params 7
+sp8	dimensionless	REAL	4	-999	spline params 8
+sp9	dimensionless	REAL	4	-999	spline params 9
+sp10	dimensionless	REAL	4	-999	spline params 10
+sp11	dimensionless	REAL	4	-999	spline params 11
+sp12	dimensionless	REAL	4	-999	spline params 12
+sp13	dimensionless	REAL	4	-999	spline params 13
+sp14	dimensionless	REAL	4	-999	spline params 14
+sp15	dimensionless	REAL	4	-999	spline params 15
+sp16	dimensionless	REAL	4	-999	spline params 16
+sp17	dimensionless	REAL	4	-999	spline params 17
+sp18	dimensionless	REAL	4	-999	spline params 18
+sp19	dimensionless	REAL	4	-999	spline params 19
+sp20	dimensionless	REAL	4	-999	spline params 20
+sp21	dimensionless	REAL	4	-999	spline params 21
+sp22	dimensionless	REAL	4	-999	spline params 22
+sp23	dimensionless	REAL	4	-999	spline params 23
+sp24	dimensionless	REAL	4	-999	spline params 24
+sp25	dimensionless	REAL	4	-999	spline params 25
+sp26	dimensionless	REAL	4	-999	spline params 26
+sp27	dimensionless	REAL	4	-999	spline params 27
+sp28	dimensionless	REAL	4	-999	spline params 28
+sp29	dimensionless	REAL	4	-999	spline params 29
+sp30	dimensionless	REAL	4	-999	spline params 30
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Derived_Data_Product_Tables/pcsStarGalQSOSep
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Derived_Data_Product_Tables/pcsStarGalQSOSep	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Derived_Data_Product_Tables/pcsStarGalQSOSep	(revision 37066)
@@ -0,0 +1,10 @@
+pcsStarGalQSOSep
+Name	Unit	Data Type	Size	Default Value	Description
+
+objID		dimensionless	BIGINT	8	NA	ODM object identifier index
+ippObjID	dimensionless	BIGINT	8	NA	IPP object number
+pcsSGSepRecipeIDdimensionless	INT	4	NA	recipe for the star/galaxy/quasar separation
+probStar	percentage	FLOAT	8	-999	probability object is a star
+probGalaxy	percentage	FLOAT	8	-999	probability object is a galaxy
+probQuasar	percentage	FLOAT	8	-999	probability object is a quasar
+flags		dimensionless	INT	4	-999	flags
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Derived_Data_Product_Tables/pcsStellarParams
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Derived_Data_Product_Tables/pcsStellarParams	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Derived_Data_Product_Tables/pcsStellarParams	(revision 37066)
@@ -0,0 +1,11 @@
+pcsStellarParams s
+Name	Unit	Data Type	Size	Default Value	Description
+
+objID				dimensionless	BIGINT	8	NA	ODM object identifier index
+ippObjID			dimensionless	BIGINT	8	NA	IPP object number
+pcsStellarParamsRecipeID	dimensionless	INT	4	-999	recipe for the star/galaxy/quasar separation
+Teff	dimensionless	REAL	4	-999	N/A
+A0	dimensionless	REAL	4	-999	N/A
+Fe_H	dimensionless	REAL	4	-999	N/A
+flags	dimensionless	INT	4	-999	flags
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Derived_Data_Product_Tables/ppmObj
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Derived_Data_Product_Tables/ppmObj	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Derived_Data_Product_Tables/ppmObj	(revision 37066)
@@ -0,0 +1,25 @@
+PPM
+Description: Proper motions and parallax associated with defined objects. 
+
+Name Unit Data Type Size Default Value Description
+objID		BIGINT 8 NA ODM object identifier
+ippObjID   	BIGINT 8 NA IPP object identifier index
+ppmID           BIGINT 8 NA ppm object identifier ( ppmToObject metatable?)
+meanEpoch	FLOAT 	8 	-999 	mean epoch of observations in Mean Julian Days
+elapseTime 	REAL 4 -999 Elapsed time of astrometric observations
+muRa 		REAL 4 -999 proper motion in RA
+muRaErr 	REAL 4 -999 error in proper motion in RA
+muDec 		REAL 4 -999 proper motion in DEC
+muDecErr 	REAL 4 -999 error in proper motion in Dec
+mu 		REAL 4 -999 total proper motion
+muErr 		REAL 4 -999 error in total proper motion
+theta 		REAL 4 -999 angle of parallax vector from N in degrees
+plx 		REAL 4 -999 total parallax
+plxErr 		REAL 4 -999 error in total parallax
+nAstro 		SMALLINT 2 -999 number of measures in astrometric fit
+rmsRA 		REAL 4 -999 rms of astrometric error in RA
+rmsDec 		REAL 4 -999 rms of astrometric error in Dec
+wiggle 		TINYINT 1 255 flag/pointer to astrometric orbit
+
+
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Derived_Data_Product_Tables/stargal
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Derived_Data_Product_Tables/stargal	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Derived_Data_Product_Tables/stargal	(revision 37066)
@@ -0,0 +1,17 @@
+
+
+Name	Unit	Data Type	Size	Default Value	Description
+
+objID		dimensionless	BIGINT	8	NA	ODM object identifier index
+ippObjID	dimensionless	BIGINT	8	NA	IPP object number
+StarProb1	fraction	FLOAT	8	-999	fractional probability object is a star, Recipe 1
+GalProb1	fraction	FLOAT	8	-999	fractional probability object is a galaxy, Recipe 1
+StarProb2	fraction	FLOAT	8	-999	fractional probability object is a star, Recipe 2
+GalProb2 	fraction	FLOAT	8	-999	fractional probability object is a galaxy, Recipe 2
+StarProb3	fraction	FLOAT	8	-999	fractional probability object is a star, Recipe 3
+GalProb3	fraction	FLOAT	8	-999	fractional probability object is a galaxy, Recipe 3
+
+
+comment - may come from different combinations of ipp parameters, model fit as function of magnitude, 
+or Support Vector Machine result. 
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Derived_Data_Product_Tables/tcsClassification
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Derived_Data_Product_Tables/tcsClassification	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Derived_Data_Product_Tables/tcsClassification	(revision 37066)
@@ -0,0 +1,16 @@
+galExtinction 
+Name	Unit	Data Type	Size	Default Value	Description
+
+objID				dimensionless	BIGINT	8	NA	ODM object identifier index
+ippObjID			dimensionless	BIGINT	8	NA	IPP object number
+diffobjID 			dimensionless	BIGINT	8	NA	IPP object number
+
+From Stephen and Ken?
+
+TransientName                                                           eg. PS1-10jh
+transientClass                                                          TDE
+ATEL                                                           -999     Astronomical Telegram number
+
+
+
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/Detection
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/Detection	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/Detection	(revision 37066)
@@ -0,0 +1,60 @@
+objID           dimensionless   BIGINT  8         NA    ODM object identifier
+gcObjID		dimensionless	BIGINT	8	  NA 	ODM galactic coordinates identifier
+detectID        dimensionless   BIGINT  8         NA    ODM detection identifier
+ippObjID        dimensionless   BIGINT  8         NA    detection id generated by IPP
+ippDetectID     dimensionless   BIGINT  8         NA    detection id generated by IPP
+filterID        dimensionless   TINYINT 1         NA    filter ID: g=1, r=2, i=3, z=4, y=5, w=6, ...
+surveyID        dimensionless   TINYINT 1         NA    survey flag identifier
+imageID         dimensionless   BIGINT  8         NA    image id hash of frame identifier & OTA/CCD number
+randomDetID     dimensionless   BIGINT  8         NA    random detection Id
+dvoRegionID     dimensionless   INT     4          0    identifier to dvo spatial region
+obsTime         MeanJulianDays  FLOAT   8       -999    Time of mid observation in Mean Julian Days
+xPos            raw pixels      REAL    4       -999    measured x on CCD from PSF fit
+yPos            raw pixels      REAL    4       -999    measured y on CCD from PSF fit
+xPosErr         raw pixels      REAL    4       -999    estimated error in x
+yPosErr         raw pixels      REAL    4       -999    estimated error in y
+pltScale        arcsec/pix      REAL    4       -999    plate scale at this location (from DVO)
+posAngle        degrees         REAL    4       -999    position angle (sky-to-chip) at this location (from DVO)
+------------------------------------------------------  Note - next 8 lines came from previous DetCalib table
+ra              degrees         FLOAT   8         NA    Right Ascension
+dec             degrees         FLOAT   8         NA    Declination
+raErr           arcsec          REAL    4         NA    Right Ascension error
+decErr          arcsec          REAL    4         NA    Declination error
+zp              magnitude       REAL    4          0    zeropoint (only thing needed to convert adu/sec to AB mag), note no zpErr
+telluricExt     magnitude       REAL    4         NA    estimated extinction due to non-photometric conditions  
+expTime         seconds         REAL    4       -999    exposure time (informational)
+airMass         dimensionless   REAL    4          0    airmass (informational)
+------------------------------------------------------  
+psfFlux         adu/seconds     REAL    4       -999    PSF instrumental flux (in analog-to-digital units/sec) or adu/sec
+psfFluxErr      adu/seconds     REAL    4       -999    estimated error in flux
+psfMajorFWHM    arcsec          REAL    4       -999    model PSF width in major axis
+psfMinorFWHM    arcsec          REAL    4       -999    model PSF width in minor axis
+psfTheta        degrees         REAL    4       -999    model PSF orientation angle degrees East of North
+psfCore         dimensionless   REAL    4       -999    model PSF core parameter [k in (1 + kz + z^1.66)]
+psfQf           dimensionless   REAL    4       -999    PSF coverage factor
+psfQfPerfect    dimensionless   REAL    4       -999    PSF-weighted fraction of pixels totally unmasked
+psfChiSq        dimensionless   REAL    4       -999    reduced-chisq of the psf model fit. (ndof?, npix?)
+psfLikelihood   dimensionless   REAL    4       -999    PSF likelihood
+momentXX        arcsec^2        REAL    4       -999    moment XX
+momentXY        arcsec^2        REAL    4       -999    moment XY
+momentYY        arcsec^2        REAL    4       -999    momeny YY
+momentR1        arcsec          REAL    4       -999    first radial moment 
+momentRH        arcsec          REAL    4       -999    half light radius (REMOVE THIS)
+momentM3C       arcsec^n        REAL    4       -999    3rd moment sin(theta) 
+momentM3S       arcsec^n        REAL    4       -999    3rd moment cos(theta) 
+momentM4C       arcsec^n        REAL    4       -999    4th moment sin(theta)
+momentM4S       arcsec^n        REAL    4       -999    4th moment cos(theta) 
+apFlux          adu/seconds     REAL    4       -999    Aperture flux
+apFluxErr       adu/seconds     REAL    4       -999    Aperture flux error
+apFillF         dimensionless   REAL    4       -999    Aperture fill factor 
+kronFlux        adu/seconds     REAL    4       -999    Kron flux
+kronFluxErr     adu/seconds     REAL    4       -999    Kron flux error
+kronRad         arcsec      	REAL    4       -999    Kron radius
+kronRadErr      arcsec      	REAL    4       -999    Kron radius error (DROP)
+sky             adu/sec/pixel   REAL    4       -999    PSF sky level at source
+skyErr          adu/sec/pixel   REAL    4       -999    estimated error in sky
+infoFlag        dimensionless   INT     4       -999    flag indicating provenance information
+infoFlag2       dimensionless   INT     4       -999    flag indicating provenance information
+dataRelease     dimensionless   TINYINT 1         NA    Data release when this detection was originally taken. Recalibrations do not affect this value.
+--
+-- [231 bytes/det]
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/Detection.txt
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/Detection.txt	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/Detection.txt	(revision 37066)
@@ -0,0 +1,58 @@
+objID           = dvo / addstar
+gcObjID		= dvo / addstar [EAM: add to addstar]
+detectID        = dvo / addstar
+ippObjID        = dvo / addstar
+ippDetectID     = dvo / addstar
+filterID        = smf / ipptopsps
+surveyID        = ipptopsps
+imageID         = smf header
+randomDetID     = ipptopsps
+dvoRegionID     = dvo / catID [EAM: add to dvopsps]
+obsTime         = smf
+xPos            = smf
+yPos            = smf
+xPosErr         = smf [EAM: modify errors to match relastro?]
+yPosErr         = smf
+pltScale        = smf
+posAngle        = smf
+----------------= 
+ra              = dvo / relastro
+dec             = dvo / relastro
+raErr           = dvo / relastro
+decErr          = dvo / relastro
+zp              = dvo / relphot
+telluricExt     = zp - zpNominal (dvopsps) [EAM: add to dvopsps]
+expTime         = smf
+airMass         = smf
+----------------= 
+psfFlux         = smf [OK: ipptopsps uses PSF_FLUX]
+psfFluxErr      = smf
+psfMajorFWHM    = smf [PSF_MAJOR is Sxx parameter, NOT FWHM] [EAM: add PSF_FWHM_MAJ to smf, keep PSF_MAJOR]
+psfMinorFWHM    = smf [PSF_MINOR is Sxx parameter, NOT FWHM] [EAM: add PSF_FWHM_MIN to smf, keep PSF_MINOR]
+psfTheta        = smf
+psfCore         = smf [EAM: add PSF_CORE to smf]
+psfQf           = smf
+psfQfPerfect    = smf
+psfChiSq        = smf
+psfLikelihood   = ipptopsps
+momentXX        = smf
+momentXY        = smf
+momentYY        = smf
+momentR1        = smf
+momentRH        = smf [XXX : MOMENTS_RH is NOT half-light radius : keep as MOMENTS_RH or calculate?]
+momentM3C       = smf
+momentM3S       = smf
+momentM4C       = smf
+momentM4S       = smf
+apFlux          = smf [requires PS1_V4]
+apFluxErr       = smf [requires PS1_V4]
+apFillF         = smf [EAM: add to pmSource and smf]
+kronFlux        = smf
+kronFluxErr     = smf
+kronRad         = (2.5*R1) : Ken : drop this or MOMENTS_R1?
+kronRadErr      = [not calculated] : drop this
+sky             = smf
+skyErr          = smf
+infoFlag        = smf
+infoFlag2       = smf
+dataRelease     = ippToPsps
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetObject
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetObject	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetObject	(revision 37066)
@@ -0,0 +1,34 @@
+
+diffObjName     string          VAR     8       NA      IAU Name constructed from objID postion PS1.x JHHMMSS.SS+/-DDMMSS.S x procesing version       
+diffObjID	dimensionless 	BIGINT 	8 	NA 	ODM object identifier index
+diffgcObjID	dimensionless	BIGINT	8       NA 	ODM galactic coordinates identifier
+ippObjID  	dimensionless 	BIGINT 	8 	NA 	IPP object number
+surveyID 	dimensionless 	TINYINT 1 	255 	Survey ID
+skyCellID       dimensionless   REAL    4       -999    single float giving PrimaryCell.SkyCell identifier
+htmID 		dimensionless 	BIGINT 	8 	NA 	HTM index
+zoneID 		dimensionless 	INT 	4 	NA 	Zone index
+randomID 	dimensionless 	BIGINT 	8 	0 	Random integer between 0 and 2^32 = 4,394,967,296 remaining ramdom integer 0  
+batchID 	dimensionless	BIGINT 	8 	-999 	
+dvoRegionID     dimensionless  	INT     4       -999    identifier to dvo spatial region
+objInfoFlag 	dimensionless 	BIGINT 	8 	-999 	flag indicating odd properties
+qualityFlag 	dimensionless 	TINYINT 1 	0 	subset of objInfoFlag - flags related to goodness of object
+consistencyFlag	dimensionless 	SMALLINT2 	0 	Value computed from associated detections, it is originally given by IPP and should agree with the ODM validation (DROP)
+ra 		degrees 	FLOAT 	8 	NA 	Right Ascension
+dec 		degrees 	FLOAT 	8 	NA 	Declination
+raErr 		arcsec 		REAL 	4 	0.0 	Right Ascension error
+decErr 		arcsec 		REAL 	4 	0.0 	Declination error
+cx              dimensionless	FLOAT 	8 	NA 	Cartesian x
+cy 	        dimensionless	FLOAT 	8 	NA 	Cartesian y
+cz              dimensionless	FLOAT 	8 	NA 	Cartesian z
+lambda 		degrees 	FLOAT 	8 	-999 	ecliptic longitude
+beta 		degrees 	FLOAT 	8 	-999 	ecliptic latitude
+l 		degrees 	FLOAT 	8 	-999 	galactic longitude
+b 		degrees 	FLOAT 	8 	-999 	galactic latitude
+qfPerfect 	dimensionless 	REAL 	4 	-999 	qfPerfect
+dataRelease 	dimensionless 	TINYINT 1 	NA 	Data release Version of this table
+nDetections 	dimensionless 	SMALLINT2 	-999 	total number of detection measurements in all filters
+ng 		dimensionless 	SMALLINT2 	-999 	number of detections in g filter
+nr 		dimensionless 	SMALLINT2 	-999 	number of detections in g filter
+ni 		dimensionless 	SMALLINT2 	-999 	number of detections in g filter
+nz 		dimensionless 	SMALLINT2 	-999 	number of detections in g filter
+ny 		dimensionless 	SMALLINT2 	-999 	number of detections in g filter
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetObject.txt
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetObject.txt	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetObject.txt	(revision 37066)
@@ -0,0 +1,34 @@
+		
+diffObjName      = ipptopsps
+diffObjID	 = dvo / addstar
+diffgcObjID	 = dvo / addstar
+ippObjID  	 = dvo / addstar
+surveyID 	 = ipptopsps
+skyCellID        = smf header
+htmID 		 = PSPS
+zoneID 		 = PSPS
+randomID 	 = ipptopsps
+batchID 	 = ipptopsps
+dvoRegionID      = dvo catID 
+objInfoFlag 	 = average.flags
+qualityFlag 	 = average.flags >> 24 & 0xff (needed??)
+consistencyFlag	 = ?
+ra 		 = dvo / relastro
+dec 		 = dvo / relastro
+raErr 		 = dvo / relastro
+decErr 		 = dvo / relastro
+cx               = PSPS
+cy 	         = PSPS
+cz               = PSPS
+lambda 		 = PSPS
+beta 		 = PSPS
+l 		 = PSPS
+b 		 = PSPS
+qfPerfect 	 = dvo / relphot / secfilt. [XXX Not calculated]
+dataRelease 	 = ipptopsps
+nDetections 	 = dvo / relphot
+ng 		 = dvo / relphot
+nr 		 = dvo / relphot
+ni 		 = dvo / relphot
+nz 		 = dvo / relphot
+ny 		 = dvo / relphot
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetection
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetection	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetection	(revision 37066)
@@ -0,0 +1,71 @@
+
+diffObjID	dimensionless 	BIGINT 	8 	NA 	diff object identifier
+diffgcObjID	dimensionless	BIGINT	8	NA 	ODM galactic coordinates identifier
+diffDetID 	dimensionless 	BIGINT 	8 	NA 	diff detection identifier
+diffDetMetaID 	dimensionless 	BIGINT 	8 	NA 	diff detection meta identifier
+ippDetectID 	dimensionless 	BIGINT 	8 	NA 	ipp detection id generated by IPP
+ippObjID 	dimensionless 	BIGINT 	8 	NA 	ipp object id generated by IPP
+filterID 	dimensionless 	TINYINT	1 	NA 	filter ID: g=1, r=2, i=3, z=4, y=5, w=6, ...
+surveyID 	dimensionless 	TINYINT	1 	NA 	survey flag identifierr
+randomDiffID 	dimensionless 	BIGINT 	8 	NA 	random diff id  
+skyCellID       dimensionless   REAL    4       -999    single float giving PrimaryCell.SkyCell identifier 
+dvoRegionID     dimensionless   INT     4          0    identifier to dvo spatial region
+obsTime 	MeanJulianDays 	FLOAT 	8 	-999 	Time of mid observation of positive detection in Mean Julian Days of positive detection
+xPos 		pixels 		REAL 	4 	-999 	measured x on diff image sky cell PSF fit
+yPos 		pixels 		REAL 	4 	-999 	measured y on diff image sky cell from PSF fit
+xPosErr 	pixels 		REAL 	4 	-999 	estimated error in x
+yPosErr 	pixels 		REAL 	4 	-999 	estimated error in y
+pltScale        arcsec/pix      REAL    4       -999    plate scale at this location (from DVO)
+posAngle        degrees         REAL    4       -999    position angle (sky-to-chip) at this location (from DVO)
+----------------------------------------------------    next 8 came from old DiffDetCalib, zp derived from cpt tables of BOTH images 
+ra              degrees         FLOAT   8       NA      Right Ascension
+dec             degrees         FLOAT   8       NA      Declination
+raErr           arcsec          REAL    4       NA      Right Ascension error -> posErr because RA,Dec same?
+decErr          arcsec          REAL    4       NA      Declination error
+zp              magnitude       REAL    4       0       zeropoint (all that is needed to convert adu/sec to AB mag), no zpErr
+telluricExt     magnitude       REAL    4       NA      estimated extinction due to non-photometric conditions  
+expTime         seconds         REAL    4       -999    exposure time (informational)
+airMass         dimensionless   REAL    4       0       airmass (informational)
+-----------------------------------------------------   attributes of positive detection
+psfFlux 	adu/seconds 	REAL 	4 	-999 	PSF instrumental flux (in analog-to-digital units/sec) or adu/sec
+psfFluxErr 	adu/seconds 	REAL 	4 	-999 	estimated error in flux
+psfMajorFWHM    arcsec          REAL    4       -999    model PSF width in major axis
+psfMinorFWHM    arcsec          REAL    4       -999    model PSF width in minor axis
+psfTheta        degrees         REAL    4       -999    model PSF orientation angle degrees East of North
+psfCore         dimensionless   REAL    4       -999    model PSF core parameter [k in (1 + kz + z^1.66)]
+psfQf 		dimensionless 	REAL 	4 	-999 	PSF coverage factor
+psfQfPerfect 	dimensionless 	REAL 	4 	-999 	PSF-weighted fraction of pixels totally unmasked
+psfChiSq 	dimensionless 	REAL 	4 	-999 	reduced-chisq of the psf model fit. (ndof?, npix?)
+psfLikelihood 	dimensionless 	REAL 	4 	-999 	PSF likelihood
+momentXX 	arcsec^2     	REAL 	4 	-999 	moment XX
+momentXY 	arcsec^2     	REAL 	4 	-999 	moment XY
+momentYY 	arcsec^2     	REAL 	4 	-999 	momeny YY
+momentR1 	arcsec       	REAL 	4 	-999 	first radial moment 
+momentRH 	arcsec       	REAL 	4 	-999 	half light radius   (DROP)
+momentM3C 	arcsec^3     	REAL 	4 	-999 	3rd moment sin(theta) 
+momentM3S 	arcsec^3     	REAL 	4 	-999 	3rd moment cos(theta) 
+momentM4C 	arcsec^4     	REAL 	4 	-999 	4th moment sin(theta)
+momentM4S  	arcsec^4     	REAL 	4 	-999 	4th moment cos(theta) 
+apFlux 		adu/seconds 	REAL 	4 	-999 	Aperture flux
+apFluxErr 	adu/seconds 	REAL 	4 	-999 	Aperture flux error
+apFillF         dimensionless   REAL    4       -999    Aperture fill factor 
+kronFlux 	adu/seconds 	REAL 	4 	-999 	Kron flux
+kronFluxErr 	adu/seconds 	REAL 	4 	-999 	Kron flux error
+kronRad 	raw pixels 	REAL 	4 	-999 	Kron radius
+kronRadErr 	raw pixels 	REAL 	4 	-999 	Kron radius error
+------------------------------------------------------- from diff image cmf/smf files 
+diffNPos        dimensionless   REAL    4       -999    npix > 3sigma
+diffFRatio      dimensionless   REAL    4       -999    fPos/(fPos +fNeg)
+diffNBad        dimensionless   REAL    4       -999    nPos/(nPos+nNeg)
+diffNMask       dimensionless   REAL    4       -999    nPos/(nPos + nMask)
+diffNAll        dimensionless   REAL    4       -999    nPos/(nPos + nMask + nNeg)
+diffPdist       arcsec          REAL    4       -999    distance to positive match source
+diffNdist       arcsec          REAL    4       -999    distance to negative match source
+diffPSN         dimensionless   REAL    4       -999    signal to noise of pos match source
+diffNSN         dimensionless   REAL    4       -999    signal to noise of neg match source
+-------------------------------------------------------
+sky 		adu/sec/pixel 	REAL 	4 	-999 	PSF sky level at source
+skyErr 		adu/sec/pixel 	REAL 	4 	-999 	estimated error in sky
+infoFlag 	dimensionless 	INT     4 	-999 	flag indicating provenance information
+infoFlag2	dimensionless 	INT     4 	-999 	flag indicating provenance information
+dataRelease 	dimensionless 	TINYINT	1 	NA 	Data release when this detection was originally taken. Recalibrations do not affect this value.
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetection.txt
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetection.txt	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetection.txt	(revision 37066)
@@ -0,0 +1,72 @@
+		
+diffObjID	 = dvo / addstar
+diffgcObjID	 = dvo / addstar
+diffDetID 	 = dvo / addstar
+diffDetMetaID 	 = dvo / addstar
+ippDetectID 	 = dvo / addstar
+ippObjID 	 = dvo / addstar
+filterID 	 = smf / ipptopsps
+surveyID 	 = ipptopsps
+randomDiffID 	 = ipptopsps
+skyCellID        = smf header
+dvoRegionID      = dvo / catID
+obsTime 	 = smf
+xPos 		 = smf
+yPos 		 = smf
+xPosErr 	 = smf
+yPosErr 	 = smf
+pltScale         = smf
+posAngle         = smf
+---------------- = 
+ra               = dvo / relastro? [allow / require relastro recalibration?]
+dec              = dvo / relastro?
+raErr            = dvo / relastro?
+decErr           = dvo / relastro?
+zp               = dvo / relphot
+telluricExt      = (zp - zpNominal) dvopsps
+expTime          = smf
+airMass          = smf
+---------------- = 
+psfFlux 	 = smf
+psfFluxErr 	 = smf
+psfMajorFWHM     = [PSF_MAJOR is Sxx parameter, NOT FWHM] [ADD PSF_MAJ_FWHM to smf, keep PSF_MAJOR]
+psfMinorFWHM     = [PSF_MAJOR is Sxx parameter, NOT FWHM] [ditto]
+psfTheta         = smf
+psfCore          = [XXX : not currently written out!!]
+psfQf 		 = smf
+psfQfPerfect 	 = smf
+psfChiSq 	 = smf
+psfLikelihood 	 = ipptopsps
+momentXX 	 = smf
+momentXY 	 = smf
+momentYY 	 = smf
+momentR1 	 = smf
+momentRH 	 = smf [XXX : MOMENTS_RH is NOT half-light radius]
+momentM3C 	 = smf
+momentM3S 	 = smf
+momentM4C 	 = smf
+momentM4S  	 = smf
+apFlux 		 = smf [PS1_DV2 or later]
+apFluxErr 	 = smf [PS1_DV2 or later]
+apFillF          = [XXX : not currently calculated]
+kronFlux 	 = smf
+kronFluxErr 	 = smf
+kronRad 	 = (2.5*R1)
+kronRadErr 	 = [drop this? ]
+---------------- = 
+diffNPos         = smf
+diffFRatio       = smf
+diffNBad         = smf
+diffNMask        = smf
+diffNAll         = smf
+diffPdist        = smf
+diffNdist        = smf
+diffPSN          = smf
+diffNSN          = smf
+---------------- = 
+sky 		 = smf
+skyErr 		 = smf
+infoFlag 	 = smf
+infoFlag2	 = smf
+dataRelease 	 = ipptopsps
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedMeanObject
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedMeanObject	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedMeanObject	(revision 37066)
@@ -0,0 +1,63 @@
+
+objID           dimensionless   BIGINT   8        NA    ODM object identifier index
+gcObjID		dimensionless	BIGINT	 8	  NA 	ODM galactic coordinates identifier
+ippObjID        dimensionless   BIGINT   8        NA    IPP object identifier
+nDetections     dimensionless   SMALLINT 2      -999    total number of detection measurements in all filters
+batchID         dimensionless   BIGINT   8        NA    batch id 
+-----------------------------------------------------   replicate to bottom for each filter
+gStackID        dimensionless   INT      4              stack image id (how to carry through IPP + DVO)
+gnTotal         dimensionless   SMALLINT 2      -999    number of detections in g filter
+gnIncPSFMag     dimensionless   SMALLINT 2      -999    number of detections included in robust psf mean in g filter 
+gnIncKronMag    dimensionless   SMALLINT 2      -999    number of detections included in robust mean of Kron mag in g filter
+gnIncApMag      dimensionless   SMALLINT 2      -999    number of detections included in robust mean of Ap mag in g filter
+gnIncR5         dimensionless   SMALLINT 2      -999    number of detections included in robust mean of ApFlx 5 in g filter
+gnIncR6         dimensionless   SMALLINT 2      -999    number of detections included in robust mean of ApFlx 6 in g filter
+------------------------------------------------------- one of the above also corresponds to the moments
+gPSFMag         AB_magnitude    REAL     4      -999    robust mean g psf AB magnitude (sigma clipping or MAP or go to 5 or 7 number sumary? 1/12 is ~9th percentile 
+gPSFMagErr      AB_magnitude    REAL     4      -999    estimated error of g psf AB magnitude mean (individual errors added in quadrature)
+gPSFMagStd      dimensionless   REAL     4      -999    standard deviation of measurements included in the robust mean  
+gKronMag        AB_magnitude    REAL     4      -999    mean g kron AB magnitude
+gKronMagErr     AB_magnitude    REAL     4      -999    estimated error of g kron AB magnitude mean
+gKronMagStd     dimensionless   REAL     4      -999    standard deviation of measurements included in the robust mean  
+gApMag          AB_magnitude    REAL     4      -999    mean g kron AB magnitude
+gApMagErr       AB_magnitude    REAL     4      -999    estimated error of g kron AB magnitude mean
+gApMagStd       dimensionless   REAL     4      -999    standard deviation of measurements included in the robust mean  
+------------------------------------------------------
+gFmeanflxR5     adu/seconds     REAL     4      -999    Flux inside r = 5 in g unconvolved stack  
+gFmeanflxR5Err  adu/seconds     REAL     4      -999    estimated error is flxR5
+gFmeanflxR5Std  adu/seconds     REAL     4      -999    estimated standard deviation in flxR5
+gFmeanflxR5Fill dimensionless   REAL     4      -999    estimated filling factor at R5
+gFmeanflxR6     adu/seconds     REAL     4      -999    Flux inside r = 6 in g unconvolved stack 
+gFmeanflxR6Err  adu/seconds     REAL     4      -999    estimated error is flxR6
+gFmeanflxR6Std  adu/seconds     REAL     4      -999    estimated standard deviation in flxR6
+gFmeanflxR6Fill dimensionless   REAL     4      -999    estimated filling factor at R6
+gFlags          dimensionless   BIGINT   8        NA    flags for g forced
+------------------------------------------------------
+gLensObjSmearX11 arcsec^-2      REAL     4      -999    per-object smear polarizability X11 term
+gLensObjSmearX12 arcsec^-2      REAL     4      -999    per-object smear polarizability X12 term
+gLensObjSmearX22 arcsec^-2      REAL     4      -999    per-object smear polarizability X22 term
+gLensObjSmearE1  arcsec^-2      REAL     4      -999    per-object smear polarizability E1 term
+gLensObjSmearE2  arcsec^-2      REAL     4      -999    per-object smear polarizability E2 term
+gLensObjShearX11 dimensionless  REAL     4      -999    per-object shear polarizability X11 term
+gLensObjShearX12 dimensionless  REAL     4      -999    per-object shear polarizability X12 term
+gLensObjShearX22 dimensionless  REAL     4      -999    per-object shear polarizability X22 term
+gLensObjShearE1  dimensionless  REAL     4      -999    per-object shear polarizability E1 term
+gLensObjShearE2  dimensionless  REAL     4      -999    per-object shear polarizability E2 term
+gLensPSFSmearX11 arcsec^-2      REAL     4      -999    psf model smear polarizability X11 term
+gLensPSFSmearX12 arcsec^-2      REAL     4      -999    psf model smear polarizability X12 term
+gLensPSFSmearX22 arcsec^-2      REAL     4      -999    psf model smear polarizability X22 term
+gLensPSFSmearE1  arcsec^-2      REAL     4      -999    psf model smear polarizability E1 term
+gLensPSFSmearE2  arcsec^-2      REAL     4      -999    psf model smear polarizability E2 term
+gLensPSFShearX11 dimensionless  REAL     4      -999    psf model shear polarizability X11 term
+gLensPSFShearX12 dimensionless  REAL     4      -999    psf model shear polarizability X12 term
+gLensPSFShearX22 dimensionless  REAL     4      -999    psf model shear polarizability X22 term
+gLensPSFShearE1  dimensionless  REAL     4      -999    psf model shear polarizability E1 term
+gLensPSFShearE2  dimensionless  REAL     4      -999    psf model shear polarizability E2 term
+------------------------------------------------------
+gGamma           arcsec^2       REAL     4      -999    second moment (Mxx + Myy)
+gE1              dimensionless  REAL     4      -999    polarization, KSB-corrected (Mxx - Myy) / (Mxx + Myy)
+gE2              dimensionless  REAL     4      -999    polarization, KSB-corrected 2Mxy / (Mxx + Myy)
+
+-- duplicated for other filters
+-- [184 byte/obj/filter + 22 byte/obj]
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedMeanObject.txt
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedMeanObject.txt	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedMeanObject.txt	(revision 37066)
@@ -0,0 +1,70 @@
+		 
+objID            = dvo / addstar
+gcobjID          = dvo / addstar
+ippObjID         = dvo / addstar
+nDetections      = dvo / addstar
+batchID          = dvo / addstar
+---------------- = 
+gStackID         = 
+gnTotal          = 
+gnIncPSFMag      = 
+gnIncKronMag     = 
+gnIncApMag       = 
+gnIncR5          = 
+gnIncR6          = 
+---------------- = 
+gPSFMag          = 
+gPSFMagErr       = 
+gPSFMagStd       = 
+gKronMag         = 
+gKronMagErr      = 
+gKronMagStd      = 
+gApMag           = 
+gApMagErr        = 
+gApMagStd        = 
+---------------- = 
+gFmeanflxR5      = 
+gFmeanflxR5Err   = 
+gFmeanflxR5Std   = 
+gFmeanflxR5Fill  = 
+gFmeanflxR6      = 
+gFmeanflxR6Err   = 
+gFmeanflxR6Std   = 
+gFmeanflxR6Fill  = 
+gFlags           = 
+---------------- = 
+gLensObjSmearX11 = 
+gLensObjSmearX12 = 
+gLensObjSmearX22 = 
+gLensObjSmearE1  = 
+gLensObjSmearE2  = 
+gLensObjShearX11 = 
+gLensObjShearX12 = 
+gLensObjShearX22 = 
+gLensObjShearE1  = 
+gLensObjShearE2  = 
+gLensPSFSmearX11 = 
+gLensPSFSmearX12 = 
+gLensPSFSmearX22 = 
+gLensPSFSmearE1  = 
+gLensPSFSmearE2  = 
+gLensPSFShearX11 = 
+gLensPSFShearX12 = 
+gLensPSFShearX22 = 
+gLensPSFShearE1  = 
+gLensPSFShearE2  = 
+---------------- = 
+gGamma           = 
+gE1              = 
+gE2              = 
+
+[NOTES:
+
+ * PSF Mag, Kron Mag, Ap Mag stats are all 
+   calculated from values in the existing Measure table
+
+   XXX : no! we need to record fluxes, not mags
+
+ * R5 & R6 ap flux values & lensing parameters need
+   a new table
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedWarpMeasurement
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedWarpMeasurement	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedWarpMeasurement	(revision 37066)
@@ -0,0 +1,82 @@
+objID           dimensionless   BIGINT  8       NA      ODM object identifier
+gcObjID		dimensionless	BIGINT	8	NA 	ODM galactic coordinates identifier
+detectID        dimensionless   BIGINT  8       NA      ODM detection identifier
+ippObjID        dimensionless   BIGINT  8       NA      ippobject id generated by IPP
+ippDetectID     dimensionless   BIGINT  8       NA      detection id generated by IPP
+filterID        dimensionless   TINYINT 1       NA      filter ID: g=1, r=2, i=3, z=4, y=5, w=6, ...
+surveyID        dimensionless   TINYINT 1       NA      survey flag identifier
+forcedWarpID    dimensionless   BIGINT  8       NA      IPP warp_id
+randomWarpID    dimensionless   BIGINT  8       NA      Random warp_id
+skyCellID       dimensionless   REAL    4       -999    single float giving PrimaryCell.SkyCell identifier 
+dvoRegionID     dimensionless   INT     4       -999    identifier to dvo spatial region
+obsTime         MeanJulianDays  FLOAT   8       -999    Time of mid observation in Mean Julian Days
+------------------------------------------------------ 
+zp              magnitude       REAL    4       0       zeropoint (only thing needed to convert adu/sec to AB mag), note no zpErr
+telluricExt     magnitude       REAL    4       NA      estimated extinction due to non-photometric conditions  
+expTime         seconds         REAL    4       -999    exposure time (informational)
+airMass         dimensionless   REAL    4       0       airmass (informational)
+------------------------------------------------------ 
+psfFlux         adu/seconds     REAL    4       -999    PSF instrumental flux (in analog-to-digital units/sec) or adu/sec
+psfFluxErr      adu/seconds     REAL    4       -999    estimated error in flux
+psfMajorFWHM    arcsec          REAL    4       -999    model PSF width in major axis
+psfMinorFWHM    arcsec          REAL    4       -999    model PSF width in minor axis
+psfTheta        degrees         REAL    4       -999    model PSF orientation angle degrees East of North
+psfCore         dimensionless   REAL    4       -999    model PSF core parameter [k in (1 + kz + z^1.66)]
+psfQf           dimensionless   REAL    4       -999    PSF coverage factor
+psfQfPerfect    dimensionless   REAL    4       -999    PSF-weighted fraction of pixels totally unmasked
+psfChiSq        dimensionless   REAL    4       -999    reduced-chisq of the psf model fit. (ndof?, npix?)
+psfLikelihood   dimensionless   REAL    4       -999    PSF likelihood
+momentXX        arcsec^2        REAL    4       -999    moment XX
+momentXY        arcsec^2        REAL    4       -999    moment XY
+momentYY        arcsec^2        REAL    4       -999    momeny YY
+momentR1        arcsec^1        REAL    4       -999    first radial moment 
+momentRH        arcsec          REAL    4       -999    to be half light radius   (DROP)
+momentM3C       arcsec^3        REAL    4       -999    3rd moment sin(theta) 
+momentM3S       arcsec^3        REAL    4       -999    3rd moment cos(theta) 
+momentM4C       arcsec^4        REAL    4       -999    4th moment sin(theta)
+momentM4S       arcsec^4        REAL    4       -999    4th moment cos(theta) 
+
+lensObjSmearX11 arcsec^-2       REAL    4       -999    per-object smear polarizability X11 term
+lensObjSmearX12 arcsec^-2       REAL    4       -999    per-object smear polarizability X12 term
+lensObjSmearX22 arcsec^-2       REAL    4       -999    per-object smear polarizability X22 term
+lensObjSmearE1  arcsec^-2       REAL    4       -999    per-object smear polarizability E1 term
+lensObjSmearE2  arcsec^-2       REAL    4       -999    per-object smear polarizability E2 term
+lensObjShearX11 dimensionless   REAL    4       -999    per-object shear polarizability X11 term
+lensObjShearX12 dimensionless   REAL    4       -999    per-object shear polarizability X12 term
+lensObjShearX22 dimensionless   REAL    4       -999    per-object shear polarizability X22 term
+lensObjShearE1  dimensionless   REAL    4       -999    per-object shear polarizability E1 term
+lensObjShearE2  dimensionless   REAL    4       -999    per-object shear polarizability E2 term
+lensPSFSmearX11 arcsec^-2       REAL    4       -999    psf model smear polarizability X11 term
+lensPSFSmearX12 arcsec^-2       REAL    4       -999    psf model smear polarizability X12 term
+lensPSFSmearX22 arcsec^-2       REAL    4       -999    psf model smear polarizability X22 term
+lensPSFSmearE1  arcsec^-2       REAL    4       -999    psf model smear polarizability E1 term
+lensPSFSmearE2  arcsec^-2       REAL    4       -999    psf model smear polarizability E2 term
+lensPSFShearX11 dimensionless   REAL    4       -999    psf model shear polarizability X11 term
+lensPSFShearX12 dimensionless   REAL    4       -999    psf model shear polarizability X12 term
+lensPSFShearX22 dimensionless   REAL    4       -999    psf model shear polarizability X22 term
+lensPSFShearE1  dimensionless   REAL    4       -999    psf model shear polarizability E1 term
+lensPSFShearE2  dimensionless   REAL    4       -999    psf model shear polarizability E2 term
+
+apFlux          adu/seconds     REAL    4       -999    Aperture flux
+apFluxErr       adu/seconds     REAL    4       -999    Aperture flux error
+apFillF         dimensionless   REAL    4       -999    Aperture fill factor 
+kronFlux        adu/seconds     REAL    4       -999    Kron flux
+kronFluxErr     adu/seconds     REAL    4       -999    Kron flux error
+kronRad         arcsec          REAL    4       -999    Kron radius
+kronRadErr      arcsed          REAL    4       -999    Kron radius error
+------------------------------------------------------ 
+flxR5           adu/seconds     REAL    4       -999    Flux inside r = 5
+flxR5Err        adu/seconds     REAL    4       -999    estimated error is flxR5
+flxR5Std        adu/seconds     REAL    4       -999    estimated standard deviation in flxR5
+flxR5Fill       dimensionless   REAL    4       -999    estimated filling factor at R5
+flxR6           adu/seconds     REAL    4       -999    Flux inside r = 6
+flxR6Err        adu/seconds     REAL    4       -999    estimated error is flxR6
+flxR6Std        adu/seconds     REAL    4       -999    estimated standard deviation in flxR6
+flxR6Fill       dimensionless   REAL    4       -999    estimated filling factor at R6
+------------------------------------------------------ 
+sky             adu/sec/pixel   REAL    4       -999    PSF sky level at source
+skyErr          adu/sec/pixel   REAL    4       -999    estimated error in sky
+infoFlag        dimensionless   BIGINT  8       -999    flag indicating provenance information
+dataRelease     dimensionless   TINYINT 1       NA      Data release when this detection was originally taken. Recalibrations do not affect this value.
+
+-- [295 byte/det]
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedWarpMeasurement.txt
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedWarpMeasurement.txt	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedWarpMeasurement.txt	(revision 37066)
@@ -0,0 +1,81 @@
+
+objID            = dvo/addstar
+gcObjID          = dvo/addstar
+detectID         = dvo/addstar
+ippObjID         = dvo/addstar
+ippDetectID      = dvo/addstar
+filterID         = 
+surveyID         = 
+forcedWarpID     = 
+randomWarpID     = 
+skyCellID        = 
+dvoRegionID      = 
+obsTime          = smf
+---------------- = 
+zp               = smf
+telluricExt      = (zp - zpNominal)
+expTime          = smf
+airMass          = smf
+---------------- = 
+psfFlux          = smf
+psfFluxErr       = smf
+psfMajorFWHM     = smf [PSF_MAJOR is Sxx parameter, NOT FWHM]
+psfMinorFWHM     = smf [PSF_MAJOR is Sxx parameter, NOT FWHM]
+psfTheta         = smf
+psfCore          = smf [XXX : not currently written out!!]
+psfQf            = smf
+psfQfPerfect     = smf
+psfChiSq         = smf
+psfLikelihood    = ipptopsps
+momentXX         = smf
+momentXY         = smf
+momentYY         = smf
+momentR1         = smf
+momentRH         = smf [XXX : MOMENTS_RH is NOT half-light radius]
+momentM3C        = smf
+momentM3S        = smf
+momentM4C        = smf
+momentM4S        = smf
+		 = 
+lensObjSmearX11  = smf [PS1_V5]
+lensObjSmearX12  = smf [PS1_V5]
+lensObjSmearX22  = smf [PS1_V5]
+lensObjSmearE1   = smf [PS1_V5]
+lensObjSmearE2   = smf [PS1_V5]
+lensObjShearX11  = smf [PS1_V5]
+lensObjShearX12  = smf [PS1_V5]
+lensObjShearX22  = smf [PS1_V5]
+lensObjShearE1   = smf [PS1_V5]
+lensObjShearE2   = smf [PS1_V5]
+lensPSFSmearX11  = smf [PS1_V5]
+lensPSFSmearX12  = smf [PS1_V5]
+lensPSFSmearX22  = smf [PS1_V5]
+lensPSFSmearE1   = smf [PS1_V5]
+lensPSFSmearE2   = smf [PS1_V5]
+lensPSFShearX11  = smf [PS1_V5]
+lensPSFShearX12  = smf [PS1_V5]
+lensPSFShearX22  = smf [PS1_V5]
+lensPSFShearE1   = smf [PS1_V5]
+lensPSFShearE2   = smf [PS1_V5]
+		 = 
+apFlux           = smf [PS1_V4]
+apFluxErr        = smf [PS1_V4]
+apFillF          = smf [EAM: add to smf output]
+kronFlux         = smf
+kronFluxErr      = smf
+kronRad          = (2.5*R1)
+kronRadErr       = [drop : not currently calculated]
+---------------- = 
+flxR5            = smf [?? calculated?]
+flxR5Err         = smf [?? calculated?]
+flxR5Std         = smf [?? calculated?]
+flxR5Fill        = smf [?? calculated?]
+flxR6            = smf [?? calculated?]
+flxR6Err         = smf [?? calculated?]
+flxR6Std         = smf [?? calculated?]
+flxR6Fill        = smf [?? calculated?]
+---------------- = 
+sky              = smf
+skyErr           = smf
+infoFlag         = 
+dataRelease      = 
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/MeanObject
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/MeanObject	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/MeanObject	(revision 37066)
@@ -0,0 +1,27 @@
+             
+--              The  "best available" measurements refer first to those objects with qfPerfect > 0.85 and good flags, 
+--              but descends down a "waterfall logic" in ipp so that there exists a mean mag for less than ideal objects. The logic is given in Magnier etal 2013.
+
+objID           dimensionless   BIGINT   8       NA      ODM object identifier index
+gcObjID		dimensionless	BIGINT	 8	 NA 	ODM galactic coordinates identifier
+gQfPerfect      dimensionless   REAL     4       -999    maximum psf qfPerfect from best available g band detections 
+gMeanPSFMag     AB_magnitude    REAL     4       -999    mean g psf AB magnitude from best available measurements (best available as current defined by ipp "waterfall logic"  
+gMeanPSFMagErr  AB_magnitude    REAL     4       -999    estimated error of best availalbe g-band psf AB magnitudes (individual errors added in quadrature)
+gnIncPSFMag     dimensionless   SMALLINT 2       -999    number of best available detections included in mean psfMag 
+gMeanPSFMagStd  dimensioless    REAL     4       -999    standard deviation of best available measurements - compared with MeanErr this is one measure of true variability  
+gMinPSFMag      AB_magnitude    REAL     4       -999    minimum best available PSFMag - min and max are given for PSFMag as they may indicate variability.  
+gMaxPSFMag      AB_magnitude    REAL     4       -999    maximum best available PSFMag   
+					 
+gMeanKronMag    AB_magnitude    REAL     4       -999    mean g kron AB magnitude from best available measurements     
+gMeanKronMagErr AB_magnitude    REAL     4       -999    estimated error of mean g kron AB magnitude 
+gnIncKronMag    dimensionless   SMALLINT 2       -999    number of best available detections included mean Kron mag 
+gMeanKronMagStd dimensioless    REAL     4       -999    standard deviation of best available measurements   
+					 
+gMeanApMag      AB_magnitude    REAL     4       -999    mean g kron AB magnitude from best available measurements
+gMeanApMagErr   AB_magnitude    REAL     4       -999    estimated error of g kron AB magnitude mean
+gnIncApMag      dimensionless   SMALLINT 2       -999    number of detections included in best available mean of Kron mag in g filter
+gMeanApMagStd   dimensioless    REAL     4       -999    standard deviation of best available measurements   
+gFlags          dimensionless   BIGINT   8       NA      flags for g mean
+-- duplicate for other filters
+
+[62 byte/obj/filter + 8 byte/filter]
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/MeanObject.txt
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/MeanObject.txt	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/MeanObject.txt	(revision 37066)
@@ -0,0 +1,25 @@
+
+
+
+
+objID           = dvo / addstar
+gcObjID         = dvo / addstar
+gQfPerfect      = dvo / relphot / secfilt. [XXX Not calculated]
+gMeanPSFMag     = dvo / relphot / secfilt.M 
+gMeanPSFMagErr  = dvo / relphot / secfilt.dM
+gnIncPSFMag     = dvo / relphot / secfilt.Nused [XXX : ensure .Nused matches .M]
+gMeanPSFMagStd  = dvo / relphot / secfilt.Mstdev 
+gMinPSFMag      = dvo / relphot / secfilt.Min [XXX: replace M_20, M_80 with Min, Max]
+gMaxPSFMag      = dvo / relphot / secfilt.Max [XXX: replace M_20, M_80 with Min, Max]
+		= 
+gMeanKronMag    = dvo / relphot / secfilt.Mkron 
+gMeanKronMagErr = dvo / relphot / secfilt.dMkron
+gnIncKronMag    = dvo / relphot / secfilt.nMkron [XXX : not calculated]
+gMeanKronMagStd = dvo / relphot / secfilt.MstdevKron [XXX : not calculated]
+		= 
+gMeanApMag      = dvo / relphot / secfilt.Map
+gMeanApMagErr   = dvo / relphot / secfilt.? [XXX : not calculated]
+gnIncApMag      = dvo / relphot / secfilt.? [XXX : not calculated]
+gMeanApMagStd   = dvo / relphot / secfilt.? [XXX : not calculated]
+
+gFlags          = dvo / relphot / secfilt.flags
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ObjectThin
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ObjectThin	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ObjectThin	(revision 37066)
@@ -0,0 +1,51 @@
+
+objName          string         VAR      8      NA      IAU Name constructed from objID postion PS1.x JHHMMSS.SS+/-DDMMSS.S where x is leading number of procesing version       
+objID            dimensionless  BIGINT   8      NA      ODM object identifier index
+gcObjID		 dimensionless	BIGINT	8	  NA 	ODM galactic coordinates identifier
+ippObjID         dimensionless  BIGINT   8      NA      IPP object number
+surveyID         dimensionless  TINYINT  1      255     Survey ID
+skyCellID        dimensionless  REAL     4      -999     single float giving PrimaryCell.SkyCell identifier
+htmID            dimensionless  BIGINT   8      NA      HTM index
+zoneID           dimensionless  INT      4      NA      Zone index
+randomID         dimensionless  BIGINT   8      0       Random integer between 0 and 2^32 = 4,394,967,296 remaining ramdom integer 0  
+batchID          dimensionless  BIGINT   8      -999    batch id        
+dvoRegionID      dimensionless  INT      4      -999    identifier of dvo spatial region - dvo cat id
+dataRelease      dimensionless  TINYINT  1      NA      Data release Version of this table
+objInfoFlag      dimensionless  BIGINT   8      -999    flag indicating odd properties
+qualityFlag      dimensionless  TINYINT  1      0       subset of objInfoFlag - flags related to goodness of object
+consistencyFlag  dimensionless  SMALLINT 2      0       Value computed from associated detections, it is originally given by IPP and should agree with the ODM validation (DROP)
+raStack          degrees        FLOAT    8      -999    Right Ascension - best weighted RA across filters from stack WHENEVER an object is detected in the stack  
+decStack         degrees        FLOAT    8      -999    Declination - best weighted Dec across filters from stack WHENEVER an object is detected in the stack 
+raStackErr       arcsec         REAL     4      -999    Error in stack Right Ascension, note will have a systematic floor, and is not necessary the best ra,dec for all objects 
+decStackErr      arcsec         REAL     4      -999    Error in stack Declination, note will have a systematic floor, and is not necessarily the best ra,dec for all objects
+raMean           degrees        FLOAT    8      -999    Right Ascension from the Mean of RA from individual detections if it exists. This is for information only  
+decMean          degrees        FLOAT    8      -999    Declination from the Mean of Dec from individual detections if it exists  This is for information only.  
+raMeanErr        arcsec         REAL     4      -999    Combination of the measurement Errors in the Right Ascension from the mean detections if they exist 
+decMeanErr       arcsec         REAL     4      -999    Combination of the measurement Errors in the  Declination measurements if they exist  
+raMeanStd        arcsec         Real     4      -999    standard deviation of Right Ascension measurements in detections if they exist 
+decMeanStd       arcsec         REAL     4      -999    standard deviation of the  Declination measurements if they exist  
+--------------------------------------------------------------------------------------------------------
+--                                                      Note: the following three sets of coordinate systems are based on stack if it exists, and mean if it does not.
+--                                                      This means cone or box searches work on the stack and consistent with Primary and Best stack detection.
+--                                                      For objects without a stack postion, (moving, transient, or false dectection) a cone search may be incomplete for
+--                                                      an object within less than 1 arc sec of the boundary edge. But science cases here will want to work from Detection
+--                                                      Table anyway, or can vary cone search by 1'' radius to check for incompleteness.  
+cx               dimensionless  FLOAT    8      NA      Cartesian x from Stack RA,Dec WHENEVER a stack detection exists, and Mean RA, Dec (mean of one?) when it doesn't 
+cy               dimensionless  FLOAT    8      NA      Cartesian y from Stack RA,Dec WHENEVER a stack detection exists, and mean RA, Dec (mean of one?) when it doesn't 
+cz               dimensionless  FLOAT    8      NA      Cartesian z from Stack RA,Dec WHENEVER a stack detection exists, ditto
+lambda           degrees        FLOAT    8      -999    ecliptic longitude from Stack RA,Dec WHENEVER A STACK MEASURMENT EXISTS and Mean RA,Dec (mean of one?) otherwise 
+beta             degrees        FLOAT    8      -999    ecliptic latitude ditto
+l                degrees        FLOAT    8      -999    galactic longitude ditto
+b                degrees        FLOAT    8      -999    galactic latitude ditto
+---------------------------------------------------------------------------------
+nStackObjectRows dimensionless  SMALLINT 2      -999    number of independent StackObjectRows this object has. 
+--                                                      zero if not detected in the Stack, 1 if there is a primary, 2 or more if it is in an overlap region
+nStackDetections dimensionless  TINYINT  2       255    which filter bands it is detected in (not forced) or if it was masked in a band.        
+nDetections      dimensionless  SMALLINT 2      -999    total number of detection measurements in all filters
+ng               dimensionless  SMALLINT 2      -999    number of detections in individual g filter exposures
+nr               dimensionless  SMALLINT 2      -999    number of detections in individual r filter exposures
+ni               dimensionless  SMALLINT 2      -999    number of detections in individual i filter exposures
+nz               dimensionless  SMALLINT 2      -999    number of detections in individual z filter exposures
+ny               dimensionless  SMALLINT 2      -999    number of detections in individual y filter exposures
+
+-- [197 byte/obj]
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ObjectThin.txt
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ObjectThin.txt	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ObjectThin.txt	(revision 37066)
@@ -0,0 +1,49 @@
+
+objName           = ipptopsps
+objID             = dvo / addstar
+gcobjID           = dvo / addstar
+ippObjID          = dvo / addstar
+surveyID          = ipptopsps
+skyCellID         = smf header
+htmID             = PSPS
+zoneID            = PSPS
+randomID          = ipptopsps
+batchID           = ipptopsps
+dvoRegionID       = dvo / catID
+dataRelease       = ipptopsps
+objInfoFlag       = dvo / relastro,relphot [define]
+qualityFlag       = dvo / relastro,relphot [define]
+consistencyFlag   = ipptopsps?
+raStack           = dvo / allow recalibration? [ADD to average.d]
+decStack          = dvo / allow recalibration?
+raStackErr        = dvo / allow recalibration?
+decStackErr       = dvo / allow recalibration?
+raMean            = dvo / relastro
+decMean           = dvo / relastro
+raMeanErr         = dvo / relastro
+decMeanErr        = dvo / relastro
+raMeanStd         = dvo / relastro
+decMeanStd        = dvo / relastro
+----------------- = 
+--                = 
+--                = 
+--                = 
+--                = 
+--                = 
+cx                = PSPS
+cy                = PSPS
+cz                = PSPS
+lambda            = PSPS
+beta              = PSPS
+l                 = PSPS
+b                 = PSPS
+----------------- = 
+nStackObjectRows  = dvo [ADD to average.d]
+--                = 
+nStackDetections  = dvo / relphot [Sum of not-forced stack detections]
+nDetections       = dvo / relphot [Sum of ng+nr, etc?]
+ng                = dvo / relphot [Sum of GPC1.g.XY?? measure.d]
+nr                = dvo / relphot [ditto]
+ni                = dvo / relphot
+nz                = dvo / relphot
+ny                = dvo / relphot
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackApFlx
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackApFlx	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackApFlx	(revision 37066)
@@ -0,0 +1,60 @@
+
+objID            dimensionless  BIGINT  8       NA      ODM object identifier
+gcObjID	  	 dimensionless	BIGINT	8	NA 	ODM galactic coordinates identifier
+ippObjID         dimensionless  BIGINT  8       NA      ipp object identifier
+surveyID         dimensionless  TINYINT 1       0       stack type identifier
+skyCellID        dimensionless  REAL    4       -999    single float giving PrimaryCell.SkyCell identifier 
+randomStackObjID dimensionless  BIGINT  8       NA      random stack id
+stackDetectRowID dimensionless  BIGINT  8       NA      identifies which of up to 5 possible stackdetctions this Row refers to: Primary, up to 3 Secondary, 1 best  
+primaryDetection dimensionless  TINYINT 1       255     identifies if this row is a primary stack detection. True about 80% of time. 
+bestDetection    dimensionless  TINYINT 1       255     identifies if this row is a best detection or not. Also set if only a primary detection exists.   
+--                                                      the Primary Dectection, 0 to 3 possible secondary dectections, and the "best" per filter.  
+dvoRegionID     dimensionless   INT    4       -999    identifier to dvo spatial region
+dataRelease     dimensionless   TINYINT 1       NA      Data release when this table was loaded.
+------------------------------------------------------- replicate to end for each filter g,r,i,z,y
+gippDetectID    dimensionless   BIGINT  8       NA      stack identifier
+gstackDetectID  dimensionless   BIGINT  8       NA      ODM detection identifier
+gstackMetaID    dimensionless   BIGINT  8       NA      stack identifier
+--------------------------------------------------------unconvolved
+gflxR3          adu/seconds     REAL    4       -999    Flux inside r = 3
+gflxR3Err       adu/seconds     REAL    4       -999    estimated error is flxR3
+gflxR3Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR3
+gflxR3Fill      dimensionless   REAL    4       -999    estimated filling factor at R3
+gflxR4          adu/seconds     REAL    4       -999    Flux inside r = 4
+gflxR4Err       adu/seconds     REAL    4       -999    estimated error is flxR4
+gflxR4Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR4
+gflxR4Fill      dimensionless   REAL    4       -999    estimated filling factor at R4
+gflxR5          adu/seconds     REAL    4       -999    Flux inside r = 5
+gflxR5Err       adu/seconds     REAL    4       -999    estimated error is flxR5
+gflxR5Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR5
+gflxR5Fill      dimensionless   REAL    4       -999    estimated filling factor at R5
+----------------------------------------------------    convolved across all bands to 6 or 8 pixels
+gc1flxR3        adu/seconds     REAL    4       -999    Flux inside r = 3
+gc1flxR3Err     adu/seconds     REAL    4       -999    estimated error is c1flxR3
+gc1flxR3Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR3
+gc1flxR3Fill    dimensionless   REAL    4       -999    estimated filling factor at R3
+gc1flxR4        adu/seconds     REAL    4       -999    Flux inside r = 4
+gc1flxR4Err     adu/seconds     REAL    4       -999    estimated error is c1flxR4
+gc1flxR4Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR4
+gc1flxR4Fill    dimensionless   REAL    4       -999    estimated filling factor at R4
+gc1flxR5        adu/seconds     REAL    4       -999    Flux inside r = 5
+gc1flxR5Err     adu/seconds     REAL    4       -999    estimated error is c1flxR5
+gc1flxR5Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR5
+gc1flxR5Fill    dimensionless   REAL    4       -999    estimated filling factor at R5
+----------------------------------------------------    convolved across all bands to 6 or 8 pixels
+gc2flxR3        adu/seconds     REAL    4       -999    Flux inside r = 3
+gc2flxR3Err     adu/seconds     REAL    4       -999    estimated error in c2flxR3
+gc2flxR3Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR3
+gc2flxR3Fill    dimensionless   REAL    4       -999    estimated filling factor at R3
+gc2flxR4        adu/seconds     REAL    4       -999    Flux inside r = 4
+gc2flxR4Err     adu/seconds     REAL    4       -999    estimated error in c2flxR4
+gc2flxR4Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR4
+gc2flxR4Fill    dimensionless   REAL    4       -999    estimated filling factor at R4
+gc2flxR5        adu/seconds     REAL    4       -999    Flux inside r = 5
+gc2flxR5Err     adu/seconds     REAL    4       -999    estimated error in c2flxR5
+gc2flxR5Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR5
+gc2flxR5Fill    dimensionless   REAL    4       -999    estimated filling factor at R5
+
+-- repeat for other filters with appropriate leading prefex.
+-- [168 byte/filter/obj + 44 byte/obj]
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackApFlx.txt
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackApFlx.txt	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackApFlx.txt	(revision 37066)
@@ -0,0 +1,56 @@
+
+objID            = dvo/addstar
+gcObjID          = dvo/addstar
+ippObjID         = dvo/addstar average.objID + (average.catID << 32)
+surveyID         = ipptopsps
+skyCellID        = smf header
+randomStackObjID = ipptopsps
+stackDetectRowID = PSPS ?
+primaryDetection = dvo
+bestDetection    = dvo
+--               = 
+dvoRegionID      = dvo / catID
+dataRelease      = ipptopsps
+---------------- = 
+gippDetectID     = dvo/addstar
+gstackDetectID   = dvopsps (see StackObject.txt)
+gstackMetaID     = dvopsps (see StackObject.txt)
+---------------- = 
+gflxR3           = smf
+gflxR3Err        = smf
+gflxR3Std        = smf
+gflxR3Fill       = smf
+gflxR4           = smf
+gflxR4Err        = smf
+gflxR4Std        = smf
+gflxR4Fill       = smf
+gflxR5           = smf
+gflxR5Err        = smf
+gflxR5Std        = smf
+gflxR5Fill       = smf
+---------------- = 
+gc1flxR3         = smf
+gc1flxR3Err      = smf
+gc1flxR3Std      = smf
+gc1flxR3Fill     = smf
+gc1flxR4         = smf
+gc1flxR4Err      = smf
+gc1flxR4Std      = smf
+gc1flxR4Fill     = smf
+gc1flxR5         = smf
+gc1flxR5Err      = smf
+gc1flxR5Std      = smf
+gc1flxR5Fill     = smf
+---------------- = 
+gc2flxR3         = smf
+gc2flxR3Err      = smf
+gc2flxR3Std      = smf
+gc2flxR3Fill     = smf
+gc2flxR4         = smf
+gc2flxR4Err      = smf
+gc2flxR4Std      = smf
+gc2flxR4Fill     = smf
+gc2flxR5         = smf
+gc2flxR5Err      = smf
+gc2flxR5Std      = smf
+gc2flxR5Fill     = smf
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFit
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFit	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFit	(revision 37066)
@@ -0,0 +1,209 @@
+
+objID            dimensionless  BIGINT  8       NA      ODM object identifier
+gcObjID		 dimensionless	BIGINT	8	NA 	ODM galactic coordinates identifier
+ippObjID         dimensionless  BIGINT  8       NA      ipp object identifier
+surveyID         dimensionless  TINYINT 1       NA      survey flag identifier
+skyCellID        dimensionless  REAL    4       -999    single float giving PrimaryCell.SkyCell identifier 
+randomStackObjID dimensionless  BIGINT  8       NA      random stack id
+stackDetectRowID dimensionless  BIGINT  8       NA      identifies which of up to 5 possible stackdetctions this Row refers to: Primary, up to 3 Secondary, 1 best  
+primaryDetection dimensionless  TINYINT 1       255     identifies if this row is a primary stack detection. True about 80% of time. 
+bestDetection    dimensionless  TINYINT 1       255     identifies if this row is a best detection or not. Also set if only a primary detection exists.   
+--                                                      the Primary Dectection, 0 to 3 possible secondary dectections, and the "best" per filter.  
+dvoRegionID      dimensionless  INT     4       -999    identifier to dvo spatial region
+dataRelease      dimensionless  TINYINT 1       NA      Data release when this table was loaded
+-------------------------------------------------------- replicate below for all filters (grizy)
+gS2             dimensionless   REAL    4       -999    (un)smoothness (Cheng 2012, Simard 2002)
+glogRT		dimensionless   REAL    4       -999    total residual (from ellipcally symmetric model)
+glogRA		dimensionless   REAL    4       -999    asymmetric residual (from ellipcally symmetric model)
+glogC           dimensionless   REAL    4       -999    concentration index  (Petrosian R_50 / R_90)
+glogA           dimensionless   REAL    4       -999    log of asymmetry index (Gyory & Bell 2010)
+gbumpy          dimensionless   REAL    4       -999    Blakeslee bumpiness
+ghalfLightRad   arcsec          REAL    4       -999    half-light radius
+-------------------------------------------------------- replicate below for all filters (grizy)
+gippDetectID    dimensionless   BIGINT  8       NA      ipp detect identifier
+gstackDetectID  dimensionless   BIGINT  8       NA      ODM detection identifier
+gstackMetaID    dimensionless   BIGINT  8       NA      stack identifier
+----------------------------------------------------------------------------------------
+gdeVRadius      arcsec          REAL    4       -999    deVaucouleurs radius
+gdeVRadiusErr   arcsec          REAL    4       -999    estimated error in deVaucouleurs radius
+gdeVFlux        adu/seconds     REAL    4       -999    deVaucouleurs flux
+gdeVFluxErr     adu/seconds     REAL    4       -999    estimated error in deVaucouleurs flux
+gdeVAb          dimensionless   REAL    4       -999    deVaucoulerus axis ratio
+gdeVAbErr       dimensionless   REAL    4       -999    estimated error in deVaucoulerus axis ratio
+gdeVPhi         degrees         REAL    4       -999    estmated phi of deVaucouleurs axis. Degrees East of North.
+gdeVPhiErr      degrees         REAL    4       -999    estmated error of phi of deVaucouleurs axis
+graDeVOff       arcsec          REAL    4       -999    Offset in RA of deVaucouleurs fit from PSF RA
+gdecDeVOff      arcsec          REAL    4       -999    Offset in DEC of deVaucouleurs fit from PSF DEC
+graDeVOffErr    arcsec          REAL    4       -999    estimated error in ra offset
+gdecDeVOffErr   arcsec          REAL    4       -999    estimated error in dec offset
+gdeVCf          dimensionless   REAL    4       -999    deVaucouleurs fit coverage factor
+gdeVLikelihood  dimensionless   REAL    4       -999    deVaucouleurs fit likelihood factor
+----------------------------------------------------------------------------------------
+gexpRadius      arcsec          REAL    4       -999    Exponential fit radius
+gexpRadiusErr   arcsec          REAL    4       -999    estimated error in Exponential fit radius
+gexpFlux        adu/seconds     REAL    4       -999    Exponential fit flux
+gexpFluxErr     adu/seconds     REAL    4       -999    estimated error in expFlux
+gexpAb          dimensionless   REAL    4       -999    Exponential fit axis ratio
+gexpAbErr       dimensionless   REAL    4       -999    estimated error in Exponential fit axis ratio
+gexpPhi         degrees         REAL    4       -999    estmated phi of Exponential axis
+gexpPhiErr      degrees         REAL    4       -999    estmated error of phi of Exponential axis
+graExpOff       dimensionless   REAL    4       -999    Offset in RA of Exponential fit from PSF RA
+gdecExpOff      dimensionless   REAL    4       -999    Offset in DEC of Exponential fit from PSF DEC
+graExpOffErr    dimensionless   REAL    4       -999    estimated error in raExpOff
+gdecExpOffErr   dimensionless   REAL    4       -999    estimated error in decExpOff
+gexpCf          dimensionless   REAL    4       -999    Exponential fit coverage factor
+gexpLikelihood  dimensionless   REAL    4       -999    Exponential fit likelihood factor
+---------------------------------------------------------------------------------------
+gserRadius      arcsec          REAL    4       -999    Sersic radius
+gserRadiusErr   arcsed          REAL    4       -999    estimated error in Sersic radius
+gserFlux        adu/seconds     REAL    4       -999    Sersic Flux
+gserFluxErr     adu/seconds     REAL    4       -999    estimated error in serFlux
+gserAb          dimensionless   REAL    4       -999    Sersic axis ratio
+gserAbErr       dimensionlessn  REAL    4       -999    estimated error in Sersic axis ratio
+gserNu          dimensionlessn  REAL    4       -999    Sersic index
+gserNuErr       diemensionless  REAL    4       -999    estimated error in Sersic index
+gserPhi         degrees         REAL    4       -999    estmated phi of Sersic axis
+gserPhiErr      degrees         REAL    4       -999    estmated error of phi of Sersic axis
+graSerOff       dimensionless   REAL    4       -999    Offset in RA of Sersic fit from PSF RA
+gdecSerOff      dimensionless   REAL    4       -999    Offset in DEC of Sersic fit from PSF DEC
+graSerOffErr    dimensionless   REAL    4       -999    estimated error in raSerOff
+gdecSerOffErr   dimensionless   REAL    4       -999    estimated error in decSerOff
+gserCf          dimensionless   REAL    4       -999    Sersic fit coverage factor
+gserLikelihood  dimensionless   REAL    4       -999    Sersic fit likelihood factor
+---------------------------------------------------------------------------------------
+gpetRadius      pixels          REAL    4       -999    Petrosian radius
+gpetRadiusErr   pixels          REAL    4       -999    estimated error inPetrosian radius
+gpetFlux        adu/sec         REAL    4       -999    Petrosian Flux
+gpetFluxErr     adu/sec         REAL    4       -999    estimated error in petFlux
+gpetR50         pixels          REAL    4       -999    Petrosian radius at 50% light
+gpetR50Err      pixels          REAL    4       -999    estimated error inPetrosian radius at 50% light
+gpetR90         pixels          REAL    4       -999    Petrosian radius at 90% light
+gpetR90Err      pixels          REAL    4       -999    estimated error in Petrosian radius at 90% light
+gpetCf          dimensionless   REAL    4       -999    Petrosian fit coverage factor
+--------------------------------------------------------unconvolved
+gflxR1          adu/seconds     REAL    4       -999    Flux inside r = 1
+gflxR1Err       adu/seconds     REAL    4       -999    estimated error is flxR1
+gflxR1Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR1
+gflxR1Fill      dimensionless   REAL    4       -999    estimated filling factor at R1
+gflxR2          adu/seconds     REAL    4       -999    Flux inside r = 2
+gflxR2Err       adu/seconds     REAL    4       -999    estimated error is flxR2
+gflxR2Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR2
+gflxR2Fill      dimensionless   REAL    4       -999    estimated filling factor at R1
+gflxR3          adu/seconds     REAL    4       -999    Flux inside r = 3
+gflxR3Err       adu/seconds     REAL    4       -999    estimated error is flxR3
+gflxR3Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR3
+gflxR3Fill      dimensionless   REAL    4       -999    estimated filling factor at R3
+gflxR4          adu/seconds     REAL    4       -999    Flux inside r = 4
+gflxR4Err       adu/seconds     REAL    4       -999    estimated error is flxR4
+gflxR4Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR4
+gflxR4Fill      dimensionless   REAL    4       -999    estimated filling factor at R4
+gflxR5          adu/seconds     REAL    4       -999    Flux inside r = 5
+gflxR5Err       adu/seconds     REAL    4       -999    estimated error is flxR5
+gflxR5Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR5
+gflxR5Fill      dimensionless   REAL    4       -999    estimated filling factor at R5
+gflxR6          adu/seconds     REAL    4       -999    Flux inside r = 6
+gflxR6Err       adu/seconds     REAL    4       -999    estimated error is flxR6
+gflxR6Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR6
+gflxR6Fill      dimensionless   REAL    4       -999    estimated filling factor at R6
+gflxR7          adu/seconds     REAL    4       -999    Flux inside r = 7
+gflxR7Err       adu/seconds     REAL    4       -999    estimated error is flxR7
+gflxR7Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR7
+gflxR7Fill      dimensionless   REAL    4       -999    estimated filling factor at R7
+gflxR8          adu/seconds     REAL    4       -999    Flux inside r = 8
+gflxR8Err       adu/seconds     REAL    4       -999    estimated error is flxR8
+gflxR8Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR8
+gflxR8Fill      dimensionless   REAL    4       -999    estimated filling factor at R8
+gflxR9          adu/seconds     REAL    4       -999    Flux inside r = 9
+gflxR9Err       adu/seconds     REAL    4       -999    estimated error is flxR9
+gflxR9Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR9
+gflxR9Fill      dimensionless   REAL    4       -999    estimated filling factor at R9
+gflxR10         adu/seconds     REAL    4       -999    Flux inside r = 10
+gflxR10Err      adu/seconds     REAL    4       -999    estimated error is flxR10
+gflxR10Std      adu/seconds     REAL    4       -999    estimated standard deviation in flxR10
+gflxR10Fill     dimensionless   REAL    4       -999    estimated filling factor at R10
+----------------------------------------------------    convolved across all bands to 6 or 8 pixels
+gc1flxR1        adu/seconds     REAL    4       -999    Flux inside r = 1
+gc1flxR1Err     adu/seconds     REAL    4       -999    estimated error is c1flxR1
+gc1flxR1Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR1
+gc1flxR1Fill    dimensionless   REAL    4       -999    estimated filling factor at R1
+gc1flxR2        adu/seconds     REAL    4       -999    Flux inside r = 2
+gc1flxR2Err     adu/seconds     REAL    4       -999    estimated error is c1flxR2
+gc1flxR2Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR2
+gc1flxR2Fill    dimensionless   REAL    4       -999    estimated filling factor at R1
+gc1flxR3        adu/seconds     REAL    4       -999    Flux inside r = 3
+gc1flxR3Err     adu/seconds     REAL    4       -999    estimated error is c1flxR3
+gc1flxR3Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR3
+gc1flxR3Fill    dimensionless   REAL    4       -999    estimated filling factor at R3
+gc1flxR4        adu/seconds     REAL    4       -999    Flux inside r = 4
+gc1flxR4Err     adu/seconds     REAL    4       -999    estimated error is c1flxR4
+gc1flxR4Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR4
+gc1flxR4Fill    dimensionless   REAL    4       -999    estimated filling factor at R4
+gc1flxR5        adu/seconds     REAL    4       -999    Flux inside r = 5
+gc1flxR5Err     adu/seconds     REAL    4       -999    estimated error is c1flxR5
+gc1flxR5Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR5
+gc1flxR5Fill    dimensionless   REAL    4       -999    estimated filling factor at R5
+gc1flxR6        adu/seconds     REAL    4       -999    Flux inside r = 6
+gc1flxR6Err     adu/seconds     REAL    4       -999    estimated error is c1flxR6
+gc1flxR6Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR6
+gc1flxR6Fill    dimensionless   REAL    4       -999    estimated filling factor at R6
+gc1flxR7        adu/seconds     REAL    4       -999    Flux inside r = 7
+gc1flxR7Err     adu/seconds     REAL    4       -999    estimated error is c1flxR7
+gc1flxR7Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR7
+gc1flxR7Fill    dimensionless   REAL    4       -999    estimated filling factor at R7
+gc1flxR8        adu/seconds     REAL    4       -999    Flux inside r = 8
+gc1flxR8Err     adu/seconds     REAL    4       -999    estimated error is c1flxR8
+gc1flxR8Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR8
+gc1flxR8Fill    dimensionless   REAL    4       -999    estimated filling factor at R8
+gc1flxR9        adu/seconds     REAL    4       -999    Flux inside r = 9
+gc1flxR9Err     adu/seconds     REAL    4       -999    estimated error is c1flxR9
+gc1flxR9Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR9
+gc1flxR9Fill    dimensionless   REAL    4       -999    estimated filling factor at R9
+gc1flxR10       adu/seconds     REAL    4       -999    Flux inside r = 10
+gc1flxR10Err    adu/seconds     REAL    4       -999    estimated error is c1flxR10
+gc1flxR10Std    adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR10
+gc1flxR10Fill   dimensionless   REAL    4       -999    estimated filling factor at R10
+gc2flxR1        adu/seconds     REAL    4       -999    Flux inside r = 1
+gc2flxR1Err     adu/seconds     REAL    4       -999    estimated error is c2flxR1
+gc2flxR1Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR1
+gc2flxR1Fill    dimensionless   REAL    4       -999    estimated filling factor at R1
+gc2flxR2        adu/seconds     REAL    4       -999    Flux inside r = 2
+gc2flxR2Err     adu/seconds     REAL    4       -999    estimated error is c2flxR2
+gc2flxR2Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR2
+gc2flxR2Fill    dimensionless   REAL    4       -999    estimated filling factor at R1
+gc2flxR3        adu/seconds     REAL    4       -999    Flux inside r = 3
+gc2flxR3Err     adu/seconds     REAL    4       -999    estimated error is c2flxR3
+gc2flxR3Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR3
+gc2flxR3Fill    dimensionless   REAL    4       -999    estimated filling factor at R3
+gc2flxR4        adu/seconds     REAL    4       -999    Flux inside r = 4
+gc2flxR4Err     adu/seconds     REAL    4       -999    estimated error is c2flxR4
+gc2flxR4Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR4
+gc2flxR4Fill    dimensionless   REAL    4       -999    estimated filling factor at R4
+gc2flxR5        adu/seconds     REAL    4       -999    Flux inside r = 5
+gc2flxR5Err     adu/seconds     REAL    4       -999    estimated error is c2flxR5
+gc2flxR5Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR5
+gc2flxR5Fill    dimensionless   REAL    4       -999    estimated filling factor at R5
+gc2flxR6        adu/seconds     REAL    4       -999    Flux inside r = 6
+gc2flxR6Err     adu/seconds     REAL    4       -999    estimated error is c2flxR6
+gc2flxR6Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR6
+gc2flxR6Fill    dimensionless   REAL    4       -999    estimated filling factor at R6
+gc2flxR7        adu/seconds     REAL    4       -999    Flux inside r = 7
+gc2flxR7Err     adu/seconds     REAL    4       -999    estimated error is c2flxR7
+gc2flxR7Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR7
+gc2flxR7Fill    dimensionless   REAL    4       -999    estimated filling factor at R7
+gc2flxR8        adu/seconds     REAL    4       -999    Flux inside r = 8
+gc2flxR8Err     adu/seconds     REAL    4       -999    estimated error is c2flxR8
+gc2flxR8Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR8
+gc2flxR8Fill    dimensionless   REAL    4       -999    estimated filling factor at R8
+gc2flxR9        adu/seconds     REAL    4       -999    Flux inside r = 9
+gc2flxR9Err     adu/seconds     REAL    4       -999    estimated error is c2flxR9
+gc2flxR9Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR9
+gc2flxR9Fill    dimensionless   REAL    4       -999    estimated filling factor at R9
+gc2flxR10       adu/seconds     REAL    4       -999    Flux inside r = 10
+gc2flxR10Err    adu/seconds     REAL    4       -999    estimated error is c2flxR10
+gc2flxR10Std    adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR10
+gc2flxR10Fill   dimensionless   REAL    4       -999    estimated filling factor at R10
+
+-- repeat for other filters with appropriate leading prefex.
+
+-- [728 byte/filter/obj + 44 byte/obj]
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFit.txt
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFit.txt	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFit.txt	(revision 37066)
@@ -0,0 +1,200 @@
+
+objID             = dvo / addstar
+gcObjID           = dvo / addstar [EAM: add to addstar]
+ippObjID          = dvo / addstar average.objID + (average.catID << 32)
+surveyID          = ipptopsps
+skyCellID         = smf header
+randomStackObjID  = ipptopsps
+stackDetectRowID  = PSPS ?
+primaryDetection  = dvo
+bestDetection     = dvo (define?)
+--                = 
+dvoRegionID       = dvo / catID [EAM: add to dvopsps]
+dataRelease       = ipptopsps
+----------------  = 
+glogC             = [NOT currently calculated] [EAM: add to psphotStack]
+glogA             = [NOT currently calculated]
+gclump            = [NOT currently calculated]
+----------------  = 
+gippDetectID      = dvopsps (see StackObject.txt)
+gstackDetectID    = dvopsps (see StackObject.txt)
+gstackMetaID      = dvopsps (see StackObject.txt)
+----------------  = 
+gdeVRadius        = smf [NOTE: the smf has Major, Minor, Theta, but errors on Sxx, Syy, Sxy
+gdeVRadiusErr     = smf
+gdeVFlux          = smf
+gdeVFluxErr       = smf
+gdeVAb            = smf
+gdeVAbErr         = smf
+gdeVPhi           = smf
+gdeVPhiErr        = smf [convert from Sxx,Sxy,Syy??]
+graDeVOff         = smf (calculate from reported position vs psf position)
+gdecDeVOff        = smf (calculate from reported position vs psf position)
+graDeVOffErr      = smf
+gdecDeVOffErr     = smf
+gdeVCf            = [NOT currently calculated] [count nPix in fit vs pi r^2]
+gdeVLikelihood    = ipptopsps
+----------------  = 
+gexpRadius        = smf [NOTE: the smf has Major, Minor, Theta, but errors on Sxx, Syy, Sxy
+gexpRadiusErr     = smf
+gexpFlux          = smf
+gexpFluxErr       = smf
+gexpAb            = smf
+gexpAbErr         = smf
+gexpPhi           = smf
+gexpPhiErr        = smf
+graExpOff         = smf (calculate from reported position vs psf position)
+gdecExpOff        = smf (calculate from reported position vs psf position)
+graExpOffErr      = smf
+gdecExpOffErr     = smf
+gexpCf            = [NOT currently calculated]
+gexpLikelihood    = ipptopsps
+----------------  = 
+gserRadius        = smf [NOTE: the smf has Major, Minor, Theta, but errors on Sxx, Syy, Sxy
+gserRadiusErr     = smf
+gserFlux          = smf
+gserFluxErr       = smf
+gserAb            = smf
+gserAbErr         = smf
+gserNu            = smf
+gserNuErr         = smf
+gserPhi           = smf
+gserPhiErr        = smf
+graSerOff         = smf (calculate from reported position vs psf position)
+gdecSerOff        = smf (calculate from reported position vs psf position)
+graSerOffErr      = smf
+gdecSerOffErr     = smf
+gserCf            = [NOT currently calculated]
+gserLikelihood    = ipptopsps
+----------------  = 
+gpetRadius        = smf
+gpetRadiusErr     = smf
+gpetFlux          = smf
+gpetFluxErr       = smf
+gpetR50           = smf
+gpetR50Err        = smf
+gpetR90           = smf
+gpetR90Err        = smf
+gpetCf            = smf
+----------------  = 
+gflxR1            = smf
+gflxR1Err         = smf
+gflxR1Std         = smf
+gflxR1Fill        = smf
+gflxR2            = smf
+gflxR2Err         = smf
+gflxR2Std         = smf
+gflxR2Fill        = smf
+gflxR3            = smf
+gflxR3Err         = smf
+gflxR3Std         = smf
+gflxR3Fill        = smf
+gflxR4            = smf
+gflxR4Err         = smf
+gflxR4Std         = smf
+gflxR4Fill        = smf
+gflxR5            = smf
+gflxR5Err         = smf
+gflxR5Std         = smf
+gflxR5Fill        = smf
+gflxR6            = smf
+gflxR6Err         = smf
+gflxR6Std         = smf
+gflxR6Fill        = smf
+gflxR7            = smf
+gflxR7Err         = smf
+gflxR7Std         = smf
+gflxR7Fill        = smf
+gflxR8            = smf
+gflxR8Err         = smf
+gflxR8Std         = smf
+gflxR8Fill        = smf
+gflxR9            = smf
+gflxR9Err         = smf
+gflxR9Std         = smf
+gflxR9Fill        = smf
+gflxR10           = smf
+gflxR10Err        = smf
+gflxR10Std        = smf
+gflxR10Fill       = smf
+----------------  = 
+gc1flxR1          = smf
+gc1flxR1Err       = smf
+gc1flxR1Std       = smf
+gc1flxR1Fill      = smf
+gc1flxR2          = smf
+gc1flxR2Err       = smf
+gc1flxR2Std       = smf
+gc1flxR2Fill      = smf
+gc1flxR3          = smf
+gc1flxR3Err       = smf
+gc1flxR3Std       = smf
+gc1flxR3Fill      = smf
+gc1flxR4          = smf
+gc1flxR4Err       = smf
+gc1flxR4Std       = smf
+gc1flxR4Fill      = smf
+gc1flxR5          = smf
+gc1flxR5Err       = smf
+gc1flxR5Std       = smf
+gc1flxR5Fill      = smf
+gc1flxR6          = smf
+gc1flxR6Err       = smf
+gc1flxR6Std       = smf
+gc1flxR6Fill      = smf
+gc1flxR7          = smf
+gc1flxR7Err       = smf
+gc1flxR7Std       = smf
+gc1flxR7Fill      = smf
+gc1flxR8          = smf
+gc1flxR8Err       = smf
+gc1flxR8Std       = smf
+gc1flxR8Fill      = smf
+gc1flxR9          = smf
+gc1flxR9Err       = smf
+gc1flxR9Std       = smf
+gc1flxR9Fill      = smf
+gc1flxR10         = smf
+gc1flxR10Err      = smf
+gc1flxR10Std      = smf
+gc1flxR10Fill     = smf
+gc2flxR1          = smf
+gc2flxR1Err       = smf
+gc2flxR1Std       = smf
+gc2flxR1Fill      = smf
+gc2flxR2          = smf
+gc2flxR2Err       = smf
+gc2flxR2Std       = smf
+gc2flxR2Fill      = smf
+gc2flxR3          = smf
+gc2flxR3Err       = smf
+gc2flxR3Std       = smf
+gc2flxR3Fill      = smf
+gc2flxR4          = smf
+gc2flxR4Err       = smf
+gc2flxR4Std       = smf
+gc2flxR4Fill      = smf
+gc2flxR5          = smf
+gc2flxR5Err       = smf
+gc2flxR5Std       = smf
+gc2flxR5Fill      = smf
+gc2flxR6          = smf
+gc2flxR6Err       = smf
+gc2flxR6Std       = smf
+gc2flxR6Fill      = smf
+gc2flxR7          = smf
+gc2flxR7Err       = smf
+gc2flxR7Std       = smf
+gc2flxR7Fill      = smf
+gc2flxR8          = smf
+gc2flxR8Err       = smf
+gc2flxR8Std       = smf
+gc2flxR8Fill      = smf
+gc2flxR9          = smf
+gc2flxR9Err       = smf
+gc2flxR9Std       = smf
+gc2flxR9Fill      = smf
+gc2flxR10         = smf
+gc2flxR10Err      = smf
+gc2flxR10Std      = smf
+gc2flxR10Fill     = smf
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFitDeV
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFitDeV	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFitDeV	(revision 37066)
@@ -0,0 +1,32 @@
+
+objID            dimensionless  BIGINT  8       NA      ODM object identifier
+gcObjID		 dimensionless	BIGINT	8	NA 	ODM galactic coordinates identifier
+surveyID         dimensionless  TINYINT 1       NA      survey flag identifier
+skyCellID        dimensionless  REAL    4       -999    single float giving PrimaryCell.SkyCell identifier 
+randomStackObjID dimensionless  BIGINT  8       NA      random stack id
+stackDetectRowID dimensionless  BIGINT  8       NA      identifies which of up to 5 possible stackdetctions this Row refers to: Primary, up to 3 Secondary, 1 best  
+primaryDetection dimensionless  TINYINT 1       255     identifies if this row is a primary stack detection. True about 80% of time. 
+bestDetection    dimensionless  TINYINT 1       255     identifies if this row is a best detection or not. Also set if only a primary detection exists.   
+--                                                      the Primary Dectection, 0 to 3 possible secondary dectections, and the "best" per filter.  
+dvoRegionID      dimensionless  INT     4       -999    identifier to dvo spatial region
+dataRelease      dimensionless  TINYINT 1       NA      Data release when this table was loaded
+-------------------------------------------------------- replicate below for all filters (grizy)
+ippObjID         dimensionless  BIGINT  8       NA      ipp object identifier
+gippDetectID    dimensionless   BIGINT  8       NA      ipp detect identifier
+gstackDetectID  dimensionless   BIGINT  8       NA      ODM detection identifier
+gstackMetaID    dimensionless   BIGINT  8       NA      stack identifier
+----------------------------------------------------------------------------------------
+gdeVRadius      arcsec          REAL    4       -999    deVaucouleurs radius
+gdeVRadiusErr   arcsec          REAL    4       -999    estimated error in deVaucouleurs radius
+gdeVFlux        adu/seconds     REAL    4       -999    deVaucouleurs flux
+gdeVFluxErr     adu/seconds     REAL    4       -999    estimated error in deVaucouleurs flux
+gdeVAb          dimensionless   REAL    4       -999    deVaucoulerus axis ratio
+gdeVAbErr       dimensionless   REAL    4       -999    estimated error in deVaucoulerus axis ratio
+gdeVPhi         degrees         REAL    4       -999    estmated phi of deVaucouleurs axis. Degrees East of North.
+gdeVPhiErr      degrees         REAL    4       -999    estmated error of phi of deVaucouleurs axis
+graDeVOff       arcsec          REAL    4       -999    Offset in RA of deVaucouleurs fit from PSF RA
+gdecDeVOff      arcsec          REAL    4       -999    Offset in DEC of deVaucouleurs fit from PSF DEC
+graDeVOffErr    arcsec          REAL    4       -999    estimated error in ra offset
+gdecDeVOffErr   arcsec          REAL    4       -999    estimated error in dec offset
+gdeVCf          dimensionless   REAL    4       -999    deVaucouleurs fit coverage factor
+gdeVLikelihood  dimensionless   REAL    4       -999    deVaucouleurs fit likelihood factor
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFitExp
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFitExp	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFitExp	(revision 37066)
@@ -0,0 +1,33 @@
+
+objID            dimensionless  BIGINT  8       NA      ODM object identifier
+gcObjID		 dimensionless	BIGINT	8	NA 	ODM galactic coordinates identifier
+surveyID         dimensionless  TINYINT 1       NA      survey flag identifier
+skyCellID        dimensionless  REAL    4       -999    single float giving PrimaryCell.SkyCell identifier 
+randomStackObjID dimensionless  BIGINT  8       NA      random stack id
+stackDetectRowID dimensionless  BIGINT  8       NA      identifies which of up to 5 possible stackdetctions this Row refers to: Primary, up to 3 Secondary, 1 best  
+primaryDetection dimensionless  TINYINT 1       255     identifies if this row is a primary stack detection. True about 80% of time. 
+bestDetection    dimensionless  TINYINT 1       255     identifies if this row is a best detection or not. Also set if only a primary detection exists.   
+--                                                      the Primary Dectection, 0 to 3 possible secondary dectections, and the "best" per filter.  
+dvoRegionID      dimensionless  INT     4       -999    identifier to dvo spatial region
+dataRelease      dimensionless  TINYINT 1       NA      Data release when this table was loaded
+-------------------------------------------------------- replicate below for all filters (grizy)
+gippObjID         dimensionless  BIGINT  8       NA      ipp object identifier
+gippDetectID    dimensionless   BIGINT  8       NA      ipp detect identifier
+gstackDetectID  dimensionless   BIGINT  8       NA      ODM detection identifier
+gstackMetaID    dimensionless   BIGINT  8       NA      stack identifier
+----------------------------------------------------------------------------------------
+gexpRadius      arcsec          REAL    4       -999    Exponential fit radius
+gexpRadiusErr   arcsec          REAL    4       -999    estimated error in Exponential fit radius
+gexpFlux        adu/seconds     REAL    4       -999    Exponential fit flux
+gexpFluxErr     adu/seconds     REAL    4       -999    estimated error in expFlux
+gexpAb          dimensionless   REAL    4       -999    Exponential fit axis ratio
+gexpAbErr       dimensionless   REAL    4       -999    estimated error in Exponential fit axis ratio
+gexpPhi         degrees         REAL    4       -999    estmated phi of Exponential axis
+gexpPhiErr      degrees         REAL    4       -999    estmated error of phi of Exponential axis
+graExpOff       dimensionless   REAL    4       -999    Offset in RA of Exponential fit from PSF RA
+gdecExpOff      dimensionless   REAL    4       -999    Offset in DEC of Exponential fit from PSF DEC
+graExpOffErr    dimensionless   REAL    4       -999    estimated error in raExpOff
+gdecExpOffErr   dimensionless   REAL    4       -999    estimated error in decExpOff
+gexpCf          dimensionless   REAL    4       -999    Exponential fit coverage factor
+gexpLikelihood  dimensionless   REAL    4       -999    Exponential fit likelihood factor
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFitFlx
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFitFlx	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFitFlx	(revision 37066)
@@ -0,0 +1,58 @@
+
+objID            dimensionless  BIGINT  8       NA      ODM object identifier
+gcObjID		 dimensionless	BIGINT	8	NA 	ODM galactic coordinates identifier
+surveyID         dimensionless  TINYINT 1       NA      survey flag identifier
+skyCellID        dimensionless  REAL    4       -999    single float giving PrimaryCell.SkyCell identifier 
+randomStackObjID dimensionless  BIGINT  8       NA      random stack id
+stackDetectRowID dimensionless  BIGINT  8       NA      identifies which of up to 5 possible stackdetctions this Row refers to: Primary, up to 3 Secondary, 1 best  
+primaryDetection dimensionless  TINYINT 1       255     identifies if this row is a primary stack detection. True about 80% of time. 
+bestDetection    dimensionless  TINYINT 1       255     identifies if this row is a best detection or not. Also set if only a primary detection exists.   
+--                                                      the Primary Dectection, 0 to 3 possible secondary dectections, and the "best" per filter.  
+dvoRegionID      dimensionless  INT     4       -999    identifier to dvo spatial region
+dataRelease      dimensionless  TINYINT 1       NA      Data release when this table was loaded
+-------------------------------------------------------- replicate below for all filters (grizy)
+gippObjID         dimensionless  BIGINT  8       NA      ipp object identifier
+gippDetectID    dimensionless   BIGINT  8       NA      ipp detect identifier
+gstackDetectID  dimensionless   BIGINT  8       NA      ODM detection identifier
+gstackMetaID    dimensionless   BIGINT  8       NA      stack identifier
+----------------------------------------------------------------------------------------
+gflxR1          adu/seconds     REAL    4       -999    Flux inside r = 1
+gflxR1Err       adu/seconds     REAL    4       -999    estimated error is flxR1
+gflxR1Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR1
+gflxR1Fill      dimensionless   REAL    4       -999    estimated filling factor at R1
+gflxR2          adu/seconds     REAL    4       -999    Flux inside r = 2
+gflxR2Err       adu/seconds     REAL    4       -999    estimated error is flxR2
+gflxR2Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR2
+gflxR2Fill      dimensionless   REAL    4       -999    estimated filling factor at R1
+gflxR3          adu/seconds     REAL    4       -999    Flux inside r = 3
+gflxR3Err       adu/seconds     REAL    4       -999    estimated error is flxR3
+gflxR3Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR3
+gflxR3Fill      dimensionless   REAL    4       -999    estimated filling factor at R3
+gflxR4          adu/seconds     REAL    4       -999    Flux inside r = 4
+gflxR4Err       adu/seconds     REAL    4       -999    estimated error is flxR4
+gflxR4Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR4
+gflxR4Fill      dimensionless   REAL    4       -999    estimated filling factor at R4
+gflxR5          adu/seconds     REAL    4       -999    Flux inside r = 5
+gflxR5Err       adu/seconds     REAL    4       -999    estimated error is flxR5
+gflxR5Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR5
+gflxR5Fill      dimensionless   REAL    4       -999    estimated filling factor at R5
+gflxR6          adu/seconds     REAL    4       -999    Flux inside r = 6
+gflxR6Err       adu/seconds     REAL    4       -999    estimated error is flxR6
+gflxR6Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR6
+gflxR6Fill      dimensionless   REAL    4       -999    estimated filling factor at R6
+gflxR7          adu/seconds     REAL    4       -999    Flux inside r = 7
+gflxR7Err       adu/seconds     REAL    4       -999    estimated error is flxR7
+gflxR7Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR7
+gflxR7Fill      dimensionless   REAL    4       -999    estimated filling factor at R7
+gflxR8          adu/seconds     REAL    4       -999    Flux inside r = 8
+gflxR8Err       adu/seconds     REAL    4       -999    estimated error is flxR8
+gflxR8Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR8
+gflxR8Fill      dimensionless   REAL    4       -999    estimated filling factor at R8
+gflxR9          adu/seconds     REAL    4       -999    Flux inside r = 9
+gflxR9Err       adu/seconds     REAL    4       -999    estimated error is flxR9
+gflxR9Std       adu/seconds     REAL    4       -999    estimated standard deviation in flxR9
+gflxR9Fill      dimensionless   REAL    4       -999    estimated filling factor at R9
+gflxR10         adu/seconds     REAL    4       -999    Flux inside r = 10
+gflxR10Err      adu/seconds     REAL    4       -999    estimated error is flxR10
+gflxR10Std      adu/seconds     REAL    4       -999    estimated standard deviation in flxR10
+gflxR10Fill     dimensionless   REAL    4       -999    estimated filling factor at R10
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFitFlxC1
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFitFlxC1	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFitFlxC1	(revision 37066)
@@ -0,0 +1,60 @@
+
+objID            dimensionless  BIGINT  8       NA      ODM object identifier
+gcObjID		 dimensionless	BIGINT	8	NA 	ODM galactic coordinates identifier
+surveyID         dimensionless  TINYINT 1       NA      survey flag identifier
+skyCellID        dimensionless  REAL    4       -999    single float giving PrimaryCell.SkyCell identifier 
+randomStackObjID dimensionless  BIGINT  8       NA      random stack id
+stackDetectRowID dimensionless  BIGINT  8       NA      identifies which of up to 5 possible stackdetctions this Row refers to: Primary, up to 3 Secondary, 1 best  
+primaryDetection dimensionless  TINYINT 1       255     identifies if this row is a primary stack detection. True about 80% of time. 
+bestDetection    dimensionless  TINYINT 1       255     identifies if this row is a best detection or not. Also set if only a primary detection exists.   
+--                                                      the Primary Dectection, 0 to 3 possible secondary dectections, and the "best" per filter.  
+dvoRegionID      dimensionless  INT     4       -999    identifier to dvo spatial region
+dataRelease      dimensionless  TINYINT 1       NA      Data release when this table was loaded
+-------------------------------------------------------- replicate below for all filters (grizy)
+gippObjID         dimensionless  BIGINT  8       NA      ipp object identifier
+gippDetectID    dimensionless   BIGINT  8       NA      ipp detect identifier
+gstackDetectID  dimensionless   BIGINT  8       NA      ODM detection identifier
+gstackMetaID    dimensionless   BIGINT  8       NA      stack identifier
+----------------------------------------------------------------------------------------
+gc1flxR1        adu/seconds     REAL    4       -999    Flux inside r = 1
+gc1flxR1Err     adu/seconds     REAL    4       -999    estimated error is c1flxR1
+gc1flxR1Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR1
+gc1flxR1Fill    dimensionless   REAL    4       -999    estimated filling factor at R1
+gc1flxR2        adu/seconds     REAL    4       -999    Flux inside r = 2
+gc1flxR2Err     adu/seconds     REAL    4       -999    estimated error is c1flxR2
+gc1flxR2Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR2
+gc1flxR2Fill    dimensionless   REAL    4       -999    estimated filling factor at R1
+gc1flxR3        adu/seconds     REAL    4       -999    Flux inside r = 3
+gc1flxR3Err     adu/seconds     REAL    4       -999    estimated error is c1flxR3
+gc1flxR3Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR3
+gc1flxR3Fill    dimensionless   REAL    4       -999    estimated filling factor at R3
+gc1flxR4        adu/seconds     REAL    4       -999    Flux inside r = 4
+gc1flxR4Err     adu/seconds     REAL    4       -999    estimated error is c1flxR4
+gc1flxR4Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR4
+gc1flxR4Fill    dimensionless   REAL    4       -999    estimated filling factor at R4
+gc1flxR5        adu/seconds     REAL    4       -999    Flux inside r = 5
+gc1flxR5Err     adu/seconds     REAL    4       -999    estimated error is c1flxR5
+gc1flxR5Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR5
+gc1flxR5Fill    dimensionless   REAL    4       -999    estimated filling factor at R5
+gc1flxR6        adu/seconds     REAL    4       -999    Flux inside r = 6
+gc1flxR6Err     adu/seconds     REAL    4       -999    estimated error is c1flxR6
+gc1flxR6Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR6
+gc1flxR6Fill    dimensionless   REAL    4       -999    estimated filling factor at R6
+gc1flxR7        adu/seconds     REAL    4       -999    Flux inside r = 7
+gc1flxR7Err     adu/seconds     REAL    4       -999    estimated error is c1flxR7
+gc1flxR7Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR7
+gc1flxR7Fill    dimensionless   REAL    4       -999    estimated filling factor at R7
+gc1flxR8        adu/seconds     REAL    4       -999    Flux inside r = 8
+gc1flxR8Err     adu/seconds     REAL    4       -999    estimated error is c1flxR8
+gc1flxR8Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR8
+gc1flxR8Fill    dimensionless   REAL    4       -999    estimated filling factor at R8
+gc1flxR9        adu/seconds     REAL    4       -999    Flux inside r = 9
+gc1flxR9Err     adu/seconds     REAL    4       -999    estimated error is c1flxR9
+gc1flxR9Std     adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR9
+gc1flxR9Fill    dimensionless   REAL    4       -999    estimated filling factor at R9
+gc1flxR10       adu/seconds     REAL    4       -999    Flux inside r = 10
+gc1flxR10Err    adu/seconds     REAL    4       -999    estimated error is c1flxR10
+gc1flxR10Std    adu/seconds     REAL    4       -999    estimated standard deviation in c1flxR10
+gc1flxR10Fill   dimensionless   REAL    4       -999    estimated filling factor at R10
+
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFitFlxC2
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFitFlxC2	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFitFlxC2	(revision 37066)
@@ -0,0 +1,60 @@
+
+objID            dimensionless  BIGINT  8       NA      ODM object identifier
+gcObjID		 dimensionless	BIGINT	8	NA 	ODM galactic coordinates identifier
+surveyID         dimensionless  TINYINT 1       NA      survey flag identifier
+skyCellID        dimensionless  REAL    4       -999    single float giving PrimaryCell.SkyCell identifier 
+randomStackObjID dimensionless  BIGINT  8       NA      random stack id
+stackDetectRowID dimensionless  BIGINT  8       NA      identifies which of up to 5 possible stackdetctions this Row refers to: Primary, up to 3 Secondary, 1 best  
+primaryDetection dimensionless  TINYINT 1       255     identifies if this row is a primary stack detection. True about 80% of time. 
+bestDetection    dimensionless  TINYINT 1       255     identifies if this row is a best detection or not. Also set if only a primary detection exists.   
+--                                                      the Primary Dectection, 0 to 3 possible secondary dectections, and the "best" per filter.  
+dvoRegionID      dimensionless  INT     4       -999    identifier to dvo spatial region
+dataRelease      dimensionless  TINYINT 1       NA      Data release when this table was loaded
+-------------------------------------------------------- replicate below for all filters (grizy)
+gippObjID         dimensionless  BIGINT  8       NA      ipp object identifier
+gippDetectID    dimensionless   BIGINT  8       NA      ipp detect identifier
+gstackDetectID  dimensionless   BIGINT  8       NA      ODM detection identifier
+gstackMetaID    dimensionless   BIGINT  8       NA      stack identifier
+----------------------------------------------------------------------------------------
+gc2flxR1        adu/seconds     REAL    4       -999    Flux inside r = 1
+gc2flxR1Err     adu/seconds     REAL    4       -999    estimated error is c2flxR1
+gc2flxR1Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR1
+gc2flxR1Fill    dimensionless   REAL    4       -999    estimated filling factor at R1
+gc2flxR2        adu/seconds     REAL    4       -999    Flux inside r = 2
+gc2flxR2Err     adu/seconds     REAL    4       -999    estimated error is c2flxR2
+gc2flxR2Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR2
+gc2flxR2Fill    dimensionless   REAL    4       -999    estimated filling factor at R1
+gc2flxR3        adu/seconds     REAL    4       -999    Flux inside r = 3
+gc2flxR3Err     adu/seconds     REAL    4       -999    estimated error is c2flxR3
+gc2flxR3Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR3
+gc2flxR3Fill    dimensionless   REAL    4       -999    estimated filling factor at R3
+gc2flxR4        adu/seconds     REAL    4       -999    Flux inside r = 4
+gc2flxR4Err     adu/seconds     REAL    4       -999    estimated error is c2flxR4
+gc2flxR4Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR4
+gc2flxR4Fill    dimensionless   REAL    4       -999    estimated filling factor at R4
+gc2flxR5        adu/seconds     REAL    4       -999    Flux inside r = 5
+gc2flxR5Err     adu/seconds     REAL    4       -999    estimated error is c2flxR5
+gc2flxR5Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR5
+gc2flxR5Fill    dimensionless   REAL    4       -999    estimated filling factor at R5
+gc2flxR6        adu/seconds     REAL    4       -999    Flux inside r = 6
+gc2flxR6Err     adu/seconds     REAL    4       -999    estimated error is c2flxR6
+gc2flxR6Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR6
+gc2flxR6Fill    dimensionless   REAL    4       -999    estimated filling factor at R6
+gc2flxR7        adu/seconds     REAL    4       -999    Flux inside r = 7
+gc2flxR7Err     adu/seconds     REAL    4       -999    estimated error is c2flxR7
+gc2flxR7Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR7
+gc2flxR7Fill    dimensionless   REAL    4       -999    estimated filling factor at R7
+gc2flxR8        adu/seconds     REAL    4       -999    Flux inside r = 8
+gc2flxR8Err     adu/seconds     REAL    4       -999    estimated error is c2flxR8
+gc2flxR8Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR8
+gc2flxR8Fill    dimensionless   REAL    4       -999    estimated filling factor at R8
+gc2flxR9        adu/seconds     REAL    4       -999    Flux inside r = 9
+gc2flxR9Err     adu/seconds     REAL    4       -999    estimated error is c2flxR9
+gc2flxR9Std     adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR9
+gc2flxR9Fill    dimensionless   REAL    4       -999    estimated filling factor at R9
+gc2flxR10       adu/seconds     REAL    4       -999    Flux inside r = 10
+gc2flxR10Err    adu/seconds     REAL    4       -999    estimated error is c2flxR10
+gc2flxR10Std    adu/seconds     REAL    4       -999    estimated standard deviation in c2flxR10
+gc2flxR10Fill   dimensionless   REAL    4       -999    estimated filling factor at R10
+
+-- repeat for other filters with appropriate leading prefex.
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFitPet
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFitPet	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFitPet	(revision 37066)
@@ -0,0 +1,28 @@
+
+objID            dimensionless  BIGINT  8       NA      ODM object identifier
+gcObjID		 dimensionless	BIGINT	8	NA 	ODM galactic coordinates identifier
+surveyID         dimensionless  TINYINT 1       NA      survey flag identifier
+skyCellID        dimensionless  REAL    4       -999    single float giving PrimaryCell.SkyCell identifier 
+randomStackObjID dimensionless  BIGINT  8       NA      random stack id
+stackDetectRowID dimensionless  BIGINT  8       NA      identifies which of up to 5 possible stackdetctions this Row refers to: Primary, up to 3 Secondary, 1 best  
+primaryDetection dimensionless  TINYINT 1       255     identifies if this row is a primary stack detection. True about 80% of time. 
+bestDetection    dimensionless  TINYINT 1       255     identifies if this row is a best detection or not. Also set if only a primary detection exists.   
+--                                                      the Primary Dectection, 0 to 3 possible secondary dectections, and the "best" per filter.  
+dvoRegionID      dimensionless  INT     4       -999    identifier to dvo spatial region
+dataRelease      dimensionless  TINYINT 1       NA      Data release when this table was loaded
+-------------------------------------------------------- replicate below for all filters (grizy)
+gippObjID         dimensionless  BIGINT  8       NA      ipp object identifier
+gippDetectID    dimensionless   BIGINT  8       NA      ipp detect identifier
+gstackDetectID  dimensionless   BIGINT  8       NA      ODM detection identifier
+gstackMetaID    dimensionless   BIGINT  8       NA      stack identifier
+----------------------------------------------------------------------------------------
+gpetRadius      pixels          REAL    4       -999    Petrosian radius
+gpetRadiusErr   pixels          REAL    4       -999    estimated error inPetrosian radius
+gpetFlux        adu/sec         REAL    4       -999    Petrosian Flux
+gpetFluxErr     adu/sec         REAL    4       -999    estimated error in petFlux
+gpetR50         pixels          REAL    4       -999    Petrosian radius at 50% light
+gpetR50Err      pixels          REAL    4       -999    estimated error inPetrosian radius at 50% light
+gpetR90         pixels          REAL    4       -999    Petrosian radius at 90% light
+gpetR90Err      pixels          REAL    4       -999    estimated error in Petrosian radius at 90% light
+gpetCf          dimensionless   REAL    4       -999    Petrosian fit coverage factor
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFitSer
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFitSer	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFitSer	(revision 37066)
@@ -0,0 +1,35 @@
+
+objID            dimensionless  BIGINT  8       NA      ODM object identifier
+gcObjID		 dimensionless	BIGINT	8	NA 	ODM galactic coordinates identifier
+surveyID         dimensionless  TINYINT 1       NA      survey flag identifier
+skyCellID        dimensionless  REAL    4       -999    single float giving PrimaryCell.SkyCell identifier 
+randomStackObjID dimensionless  BIGINT  8       NA      random stack id
+stackDetectRowID dimensionless  BIGINT  8       NA      identifies which of up to 5 possible stackdetctions this Row refers to: Primary, up to 3 Secondary, 1 best  
+primaryDetection dimensionless  TINYINT 1       255     identifies if this row is a primary stack detection. True about 80% of time. 
+bestDetection    dimensionless  TINYINT 1       255     identifies if this row is a best detection or not. Also set if only a primary detection exists.   
+--                                                      the Primary Dectection, 0 to 3 possible secondary dectections, and the "best" per filter.  
+dvoRegionID      dimensionless  INT     4       -999    identifier to dvo spatial region
+dataRelease      dimensionless  TINYINT 1       NA      Data release when this table was loaded
+-------------------------------------------------------- replicate below for all filters (grizy)
+gippObjID         dimensionless  BIGINT  8       NA      ipp object identifier
+gippDetectID    dimensionless   BIGINT  8       NA      ipp detect identifier
+gstackDetectID  dimensionless   BIGINT  8       NA      ODM detection identifier
+gstackMetaID    dimensionless   BIGINT  8       NA      stack identifier
+----------------------------------------------------------------------------------------
+gserRadius      arcsec          REAL    4       -999    Sersic radius
+gserRadiusErr   arcsed          REAL    4       -999    estimated error in Sersic radius
+gserFlux        adu/seconds     REAL    4       -999    Sersic Flux
+gserFluxErr     adu/seconds     REAL    4       -999    estimated error in serFlux
+gserAb          dimensionless   REAL    4       -999    Sersic axis ratio
+gserAbErr       dimensionlessn  REAL    4       -999    estimated error in Sersic axis ratio
+gserNu          dimensionlessn  REAL    4       -999    Sersic index
+gserNuErr       diemensionless  REAL    4       -999    estimated error in Sersic index
+gserPhi         degrees         REAL    4       -999    estmated phi of Sersic axis
+gserPhiErr      degrees         REAL    4       -999    estmated error of phi of Sersic axis
+graSerOff       dimensionless   REAL    4       -999    Offset in RA of Sersic fit from PSF RA
+gdecSerOff      dimensionless   REAL    4       -999    Offset in DEC of Sersic fit from PSF DEC
+graSerOffErr    dimensionless   REAL    4       -999    estimated error in raSerOff
+gdecSerOffErr   dimensionless   REAL    4       -999    estimated error in decSerOff
+gserCf          dimensionless   REAL    4       -999    Sersic fit coverage factor
+gserLikelihood  dimensionless   REAL    4       -999    Sersic fit likelihood factor
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFitThin
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFitThin	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFitThin	(revision 37066)
@@ -0,0 +1,25 @@
+
+objID            dimensionless  BIGINT  8       NA      ODM object identifier
+gcObjID		 dimensionless	BIGINT	8	NA 	ODM galactic coordinates identifier
+surveyID         dimensionless  TINYINT 1       NA      survey flag identifier
+skyCellID        dimensionless  REAL    4       -999    single float giving PrimaryCell.SkyCell identifier 
+randomStackObjID dimensionless  BIGINT  8       NA      random stack id
+stackDetectRowID dimensionless  BIGINT  8       NA      identifies which of up to 5 possible stackdetctions this Row refers to: Primary, up to 3 Secondary, 1 best  
+primaryDetection dimensionless  TINYINT 1       255     identifies if this row is a primary stack detection. True about 80% of time. 
+bestDetection    dimensionless  TINYINT 1       255     identifies if this row is a best detection or not. Also set if only a primary detection exists.   
+--                                                      the Primary Dectection, 0 to 3 possible secondary dectections, and the "best" per filter.  
+dvoRegionID      dimensionless  INT     4       -999    identifier to dvo spatial region
+dataRelease      dimensionless  TINYINT 1       NA      Data release when this table was loaded
+-------------------------------------------------------- replicate below for all filters (grizy)
+gS2             dimensionless   REAL    4       -999    (un)smoothness (Cheng 2012, Simard 2002)
+glogRT		dimensionless   REAL    4       -999    total residual (from ellipcally symmetric model)
+glogRA		dimensionless   REAL    4       -999    asymmetric residual (from ellipcally symmetric model)
+glogC           dimensionless   REAL    4       -999    concentration index  (Petrosian R_50 / R_90)
+glogA           dimensionless   REAL    4       -999    log of asymmetry index (Gyory & Bell 2010)
+gbumpy          dimensionless   REAL    4       -999    Blakeslee bumpiness
+ghalfLightRad   arcsec          REAL    4       -999    half-light radius
+-------------------------------------------------------- replicate below for all filters (grizy)
+gippObjID         dimensionless  BIGINT  8       NA      ipp object identifier
+gippDetectID    dimensionless   BIGINT  8       NA      ipp detect identifier
+gstackDetectID  dimensionless   BIGINT  8       NA      ODM detection identifier
+gstackMetaID    dimensionless   BIGINT  8       NA      stack identifier
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackObject.txt
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackObject.txt	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackObject.txt	(revision 37066)
@@ -0,0 +1,66 @@
+		  
+objID              = dvo/addstar = average.extID
+gcObjID            = dvo/addstar [EAM: add to addstar, average.d]
+ippObjID           = dvo/addstar = average.objID + (average.catID << 32)
+surveyID           = ipptopsps
+skyCellID          = ipptopsps / smf header
+randomStackObjID   = ipptopsps
+stackDetectRowID   = PSPS ?
+primaryDetection   = dvo 
+bestDetection      = dvo ?
+                   = 
+dvoRegionID        = dvo / catID
+dataRelease        = ippToPsps
+------------------ = 
+-- attributes for  = 
+-- Replicate the s = 
+------------------ = 
+gippDetectID       = dvopsps.ippDetectID = dvo.measure.detID = smf / IPP_IDET
+gstackDetectID     = dvopsps.detectID = dvo:measure.extID (addstar psps stack detect ID)
+gstackMetaID       = smf header 
+------------------ = 
+gxPos              = smf
+gyPos              = smf
+gxPosErr           = smf
+gyPosErr           = smf
+gra                = smf or relastro? (Ken?)
+gdec               = smf or relastro?
+graErr             = smf or relastro?
+gdecErr            = smf or relastro?
+gzp                = dvo / relphot
+gexpTime           = smf [see Detection.txt]
+gpsfMajorFWHM      = smf [see Detection.txt]
+gpsfMinorFWHM      = smf [see Detection.txt]
+gpsfTheta          = smf [see Detection.txt]
+gpsfCore           = smf [see Detection.txt]
+gpsfLikelihood     = ipptopsps
+gpsfQf             = smf
+gpsfQfPerfect      = smf
+gpsfChiSq          = smf
+gmomentXX          = smf
+gmomentXY          = smf
+gmomentYY          = smf
+gmomentR1          = smf
+gmomentRH          = smf [XXX : MOMENTS_RH is NOT half-light radius]
+gPSFFlux     	   = smf
+gPSFFluxErr  	   = smf
+gApFlux            = smf
+gApFluxErr         = smf
+gApFillFac         = smf [EAM: add to smf output]
+gKronFlux          = smf
+gKronFluxErr       = smf
+gKronRad           = (2.5 * R1) [drop from schema]
+gPSFMag      	   = smf
+gPSFMagErr   	   = smf
+gApMag       	   = smf
+gApMagErr    	   = smf
+gKronMag     	   = smf (calculated)
+gKronMagErr  	   = smf (calculated)
+gsky               = smf
+gskyErr            = smf
+ginfoFlag          = smf
+ginfoFlag2         = smf
+gnFrames           = smf
+
+[NOTE: for stacks, dvo only needs to determine the 
+       primary measurement (and modified zero point?).
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackObjectExtra
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackObjectExtra	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackObjectExtra	(revision 37066)
@@ -0,0 +1,47 @@
+
+objID             dimensionless   BIGINT  8       NA      ODM object identifier
+gcObjID	  	  dimensionless	  BIGINT  8	  NA 	  ODM galactic coordinates identifier
+surveyID          dimensionless   TINYINT 1       NA      survey flag identifier
+skyCellID         dimensionless   REAL    4       -999    single float giving PrimaryCell.SkyCell identifier 
+randomStackObjID  dimensionless   BIGINT  8       NA      random stack id
+stackDetectRowID  dimensionless   BIGINT  8       NA      identifies which of up to 5 possible stackdetctions this Row refers to: Primary, up to 3 Secondary, 1 best  
+primaryDetection  dimensionless   TINYINT 1       255     identifies if this row is a primary stack detection. True about 80% of time. 
+bestDetection     dimensionless   TINYINT 1       255     identifies if this row is a best detection or not. Also set if only a primary detection exists.   
+                                                          the Primary Dectection, 0 to 3 possible secondary dectections, and the "best" per filter.  
+dvoRegionID       dimensionless   INT     4       -999    identifier to dvo spatial region
+dataRelease       dimensionless   TINYINT 1       NA      Data release when this detection was originally taken.
+------------------------------------------------------------------------------------------
+-- attributes for all stack detections in all filters (these are currently forced anyway) 
+-- Replicate the section below for each filter, changing the prefex ("g" in this example) 
+------------------------------------------------------------------------------------------
+gippObjID          dimensionless   BIGINT  8       NA      object ID generated by IPP
+gippDetectID      dimensionless   BIGINT  8       NA      detection ID generated by IPP
+gstackDetectID    dimensionless   BIGINT  8       NA      ODM detection identifier
+gstackMetaID      dimensionless   BIGINT  8       NA      stack identifier
+------------------------------------------------------------------------------------------
+gxPos             arcsec          REAL    4       -999    measured x in sky Cell from PSF fit
+gyPos             arcsec          REAL    4       -999    measured y in sky Cell from PSF fit
+gxPosErr          arcsec          REAL    4       -999    estimated error in x
+gyPosErr          arcsec          REAL    4       -999    estimated error in y
+gexpTime          seconds         REAL    4       -999    total exposure time (informational)
+gpsfMajorFWHM     arcsec          REAL    4       -999    PSF width in major axis
+gpsfMinorFWHM     arcsec          REAL    4       -999    PSF width in minor axis
+gpsfTheta         degrees         REAL    4       -999    PSF orientation angle. Degrees East of North.
+gpsfCore          dimensionless   REAL    4       -999    PSF core parameter [k in (1 + kz + z^1.66)]
+gpsfLikelihood    dimensionless   REAL    4       -999    PSF likelihood
+gpsfQf            dimensionless   REAL    4       -999    PSF coverage factor
+gpsfQfPerfect     dimensionless   REAL    4       -999    PSF-weighted fraction of arcsec totally unmasked
+gpsfChiSq         dimensionless   REAL    4       -999    PSF-weighted fraction of arcsec to.
+gmomentXX         arcsec^2        REAL    4       -999    moment XX
+gmomentXY         arcsec^2        REAL    4       -999    moment XY
+gmomentYY         arcsec^2        REAL    4       -999    moment YY
+gmomentR1         arcsec          REAL    4       -999    moment R1
+gmomentRH         arcsec          REAL    4       -999    moment RH - or half light radius (REMOVE)
+gPSFFlux     	  adu/sec         REAL    4       -999    g psf flux from stack
+gPSFFluxErr  	  adu/sec         REAL    4       -999    estimated error of g psf flux from stack
+gApFlux           adu/seconds     REAL    4       -999    Aperture magnitude
+gApFluxErr        adu/seconds     REAL    4       -999    Aperture magnitude error
+gApFillFac        dimensionless   REAL    4       -999    Aperture fill factor - ~ redundant with psfQF, keep?
+gKronFlux         adu/seconds     REAL    4       -999    Kron flux
+gKronFluxErr      adu/seconds     REAL    4       -999    Kron flux error
+gKronRad          arcsec          REAL    4       -999    Kron radius
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackObjectThin
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackObjectThin	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackObjectThin	(revision 37066)
@@ -0,0 +1,39 @@
+
+objID             dimensionless   BIGINT  8       NA      ODM object identifier
+gcObjID	  	  dimensionless	  BIGINT  8	  NA 	  ODM galactic coordinates identifier
+surveyID          dimensionless   TINYINT 1       NA      survey flag identifier
+skyCellID         dimensionless   REAL    4       -999    single float giving PrimaryCell.SkyCell identifier 
+randomStackObjID  dimensionless   BIGINT  8       NA      random stack id
+stackDetectRowID  dimensionless   BIGINT  8       NA      identifies which of up to 5 possible stackdetctions this Row refers to: Primary, up to 3 Secondary, 1 best  
+primaryDetection  dimensionless   TINYINT 1       255     identifies if this row is a primary stack detection. True about 80% of time. 
+bestDetection     dimensionless   TINYINT 1       255     identifies if this row is a best detection or not. Also set if only a primary detection exists.   
+                                                          the Primary Dectection, 0 to 3 possible secondary dectections, and the "best" per filter.  
+dvoRegionID       dimensionless   INT     4       -999    identifier to dvo spatial region
+dataRelease       dimensionless   TINYINT 1       NA      Data release when this detection was originally taken.
+------------------------------------------------------------------------------------------
+-- attributes for all stack detections in all filters (these are currently forced anyway) 
+-- Replicate the section below for each filter, changing the prefex ("g" in this example) 
+------------------------------------------------------------------------------------------
+gippObjID      dimensionless   BIGINT  8       NA      object ID generated by IPP
+gippDetectID      dimensionless   BIGINT  8       NA      detection ID generated by IPP
+gstackDetectID    dimensionless   BIGINT  8       NA      ODM detection identifier
+gstackMetaID      dimensionless   BIGINT  8       NA      stack identifier
+------------------------------------------------------------------------------------------
+gra               degrees         FLOAT   8       NA      Right Ascension   
+gdec              degrees         FLOAT   8       NA      Declination       
+graErr            arcsec          REAL    4       NA      Right Ascension error
+gdecErr           arcsec          REAL    4       NA      Declination error  (same as RA error - need?)
+gzp               magnitude       REAL    4       0       zeropoint , no error given 
+gPSFMag      	  AB_magnitude    REAL    4       -999    g psf AB magnitude from stack
+gPSFMagErr   	  AB_magnitude    REAL    4       -999    estimated error of g psf AB magnitude from stack
+gApMag       	  AB_magnitude    REAL    4       -999    g Aperture AB magnitude from stack
+gApMagErr    	  AB_magnitude    REAL    4       -999    estimated error of g Ap Mag AB magnitude from stack
+gKronMag     	  AB_magnitude    REAL    4       -999    g kron AB magnitude from stack
+gKronMagErr  	  AB_magnitude    REAL    4       -999    estimated error of g kron AB magnitude from stack
+gsky              adu/secs/arcsec REAL    4       -999    PSF sky level at source (adu)
+gskyErr           adu/secs/arcsec REAL    4       -999    estimated error in sky
+ginfoFlag         dimensionless   INT     4       -999    indicator of strange propeties
+ginfoFlag2        dimensionless   INT     4       -999    indicator of strange propeties
+gnFrames          dimensionless   INT     4       -999    Number of frames contributing to source
+
+-- [220 byte/filter/obj + 44 byte/obj]
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/changes.r36847
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/changes.r36847	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/changes.r36847	(revision 37066)
@@ -0,0 +1,199 @@
+Index: Detection
+===================================================================
+--- Detection	(revision 36838)
++++ Detection	(working copy)
+@@ -7,7 +7,7 @@
+ surveyID        dimensionless   TINYINT 1         NA    survey flag identifier
+ imageID         dimensionless   BIGINT  8         NA    image id hash of frame identifier & OTA/CCD number
+ randomDetID     dimensionless   BIGINT  8         NA    random detection Id
+-dvoRegionID     dimensionless   REAL    4       -999    identifier to dvo spatial region
++dvoRegionID     dimensionless   INT     4          0    identifier to dvo spatial region
+ obsTime         MeanJulianDays  FLOAT   8       -999    Time of mid observation in Mean Julian Days
+ xPos            raw pixels      REAL    4       -999    measured x on CCD from PSF fit
+ yPos            raw pixels      REAL    4       -999    measured y on CCD from PSF fit
+@@ -53,7 +53,8 @@
+ kronRadErr      arcsec      	REAL    4       -999    Kron radius error
+ sky             adu/sec/pixel   REAL    4       -999    PSF sky level at source
+ skyErr          adu/sec/pixel   REAL    4       -999    estimated error in sky
+-infoFlag        dimensionless   BIGINT  8       -999    flag indicating provenance information
++infoFlag        dimensionless   INT     4       -999    flag indicating provenance information
++infoFlag2       dimensionless   INT     4       -999    flag indicating provenance information
+ dataRelease     dimensionless   TINYINT 1         NA    Data release when this detection was originally taken. Recalibrations do not affect this value.
+ --
+ -- [231 bytes/det]
+Index: StackApFlx
+===================================================================
+--- StackApFlx	(revision 36838)
++++ StackApFlx	(working copy)
+@@ -1,6 +1,7 @@
+ 
+ objID            dimensionless  BIGINT  8       NA      ODM object identifier
+ gcObjID		dimensionless	BIGINT	8	  NA 	ODM galactic coordinates identifier
++ippObjID         dimensionless  BIGINT  8       NA      ipp object identifier
+ surveyID         dimensionless  TINYINT 1       0       stack type identifier
+ skyCellID        dimensionless  REAL    4       -999    single float giving PrimaryCell.SkyCell identifier 
+ randomStackObjID dimensionless  BIGINT  8       NA      random stack id
+@@ -8,13 +9,12 @@
+ primaryDetection dimensionless  TINYINT 1       255     identifies if this row is a primary stack detection. True about 80% of time. 
+ bestDetection    dimensionless  TINYINT 1       255     identifies if this row is a best detection or not. Also set if only a primary detection exists.   
+ --                                                      the Primary Dectection, 0 to 3 possible secondary dectections, and the "best" per filter.  
+-dvoRegionID      dimensionless  REAL    4       -999    identifier to dvo spatial region
++dvoRegionID     dimensionless   INT    4       -999    identifier to dvo spatial region
+ dataRelease     dimensionless   TINYINT 1       NA      Data release when this table was loaded.
+ ------------------------------------------------------- replicate to end for each filter g,r,i,z,y
++gippDetectID    dimensionless   BIGINT  8       NA      stack identifier
+ gstackDetectID  dimensionless   BIGINT  8       NA      ODM detection identifier
+ gstackMetaID    dimensionless   BIGINT  8       NA      stack identifier
+-gippObjID        dimensionless  BIGINT  8       NA      ipp object identifier
+-gippDetectID    dimensionless   BIGINT  8       NA      stack identifier
+ --------------------------------------------------------unconvolved
+ gflxR3          adu/seconds     REAL    4       -999    Flux inside r = 3
+ gflxR3Err       adu/seconds     REAL    4       -999    estimated error is flxR3
+Index: ForcedWarpMeasurement
+===================================================================
+--- ForcedWarpMeasurement	(revision 36838)
++++ ForcedWarpMeasurement	(working copy)
+@@ -8,7 +8,7 @@
+ forcedWarpID    dimensionless   BIGINT  8       NA      IPP warp_id
+ randomWarpID    dimensionless   BIGINT  8       NA      Random warp_id
+ skyCellID       dimensionless   REAL    4       -999    single float giving PrimaryCell.SkyCell identifier 
+-dvoRegionID     dimensionless   REAL    4       -999    identifier to dvo spatial region
++dvoRegionID     dimensionless   INT     4       -999    identifier to dvo spatial region
+ obsTime         MeanJulianDays  FLOAT   8       -999    Time of mid observation in Mean Julian Days
+ ------------------------------------------------------ 
+ zp              magnitude       REAL    4       0       zeropoint (only thing needed to convert adu/sec to AB mag), note no zpErr
+Index: DiffDetection
+===================================================================
+--- DiffDetection	(revision 36838)
++++ DiffDetection	(working copy)
+@@ -1,3 +1,4 @@
++
+ diffObjID	dimensionless 	BIGINT 	8 	NA 	diff object identifier
+ diffgcObjID		dimensionless	BIGINT	8	  NA 	ODM galactic coordinates identifier
+ diffDetID 	dimensionless 	BIGINT 	8 	NA 	diff detection identifier
+@@ -8,7 +9,7 @@
+ surveyID 	dimensionless 	TINYINT	1 	NA 	survey flag identifierr
+ randomDiffID 	dimensionless 	BIGINT 	8 	NA 	random diff id  
+ skyCellID       dimensionless   REAL    4       -999    single float giving PrimaryCell.SkyCell identifier 
+-dvoRegionID     dimensionless   REAL    4       -999    identifier to dvo spatial region
++dvoRegionID     dimensionless   INT     4          0    identifier to dvo spatial region
+ obsTime 	MeanJulianDays 	FLOAT 	8 	-999 	Time of mid observation of positive detection in Mean Julian Days of positive detection
+ xPos 		pixels 		REAL 	4 	-999 	measured x on diff image sky cell PSF fit
+ yPos 		pixels 		REAL 	4 	-999 	measured y on diff image sky cell from PSF fit
+@@ -65,5 +66,6 @@
+ -------------------------------------------------------
+ sky 		adu/sec/pixel 	REAL 	4 	-999 	PSF sky level at source
+ skyErr 		adu/sec/pixel 	REAL 	4 	-999 	estimated error in sky
+-infoFlag 	dimensionless 	BIGINT 	8 	-999 	flag indicating provenance information
++infoFlag 	dimensionless 	INT     4 	-999 	flag indicating provenance information
++infoFlag2	dimensionless 	INT     4 	-999 	flag indicating provenance information
+ dataRelease 	dimensionless 	TINYINT	1 	NA 	Data release when this detection was originally taken. Recalibrations do not affect this value.
+Index: ObjectThin
+===================================================================
+--- ObjectThin	(revision 36838)
++++ ObjectThin	(working copy)
+@@ -9,7 +9,7 @@
+ zoneID           dimensionless  INT      4      NA      Zone index
+ randomID         dimensionless  BIGINT   8      0       Random integer between 0 and 2^32 = 4,394,967,296 remaining ramdom integer 0  
+ batchID          dimensionless  BIGINT   8      -999    batch id        
+-dvoRegionID      dimensionless  REAL     4      -999    identifier of dvo spatial region - dvo cat id
++dvoRegionID      dimensionless  INT      4      -999    identifier of dvo spatial region - dvo cat id
+ dataRelease      dimensionless  TINYINT  1      NA      Data release Version of this table
+ objInfoFlag      dimensionless  BIGINT   8      -999    flag indicating odd properties
+ qualityFlag      dimensionless  TINYINT  1      0       subset of objInfoFlag - flags related to goodness of object
+Index: StackModelFit
+===================================================================
+--- StackModelFit	(revision 36838)
++++ StackModelFit	(working copy)
+@@ -1,6 +1,7 @@
+ 
+ objID            dimensionless  BIGINT  8       NA      ODM object identifier
+ gcObjID		dimensionless	BIGINT	8	  NA 	ODM galactic coordinates identifier
++ippObjID         dimensionless  BIGINT  8       NA      ipp object identifier
+ surveyID         dimensionless  TINYINT 1       NA      survey flag identifier
+ skyCellID        dimensionless  REAL    4       -999    single float giving PrimaryCell.SkyCell identifier 
+ randomStackObjID dimensionless  BIGINT  8       NA      random stack id
+@@ -8,17 +9,17 @@
+ primaryDetection dimensionless  TINYINT 1       255     identifies if this row is a primary stack detection. True about 80% of time. 
+ bestDetection    dimensionless  TINYINT 1       255     identifies if this row is a best detection or not. Also set if only a primary detection exists.   
+ --                                                      the Primary Dectection, 0 to 3 possible secondary dectections, and the "best" per filter.  
+-dvoRegionID      dimensionless  REAL    4       -999    identifier to dvo spatial region
++dvoRegionID      dimensionless  INT     4       -999    identifier to dvo spatial region
+ dataRelease      dimensionless  TINYINT 1       NA      Data release when this table was loaded
+ -------------------------------------------------------- replicate below for all filters (grizy)
+ glogC           dimensionless   REAL    4       -999    concentration index 
+ glogA           dimensionless   REAL    4       -999    asymmetry index
+ gclump          dimensionless   REAL    4       -999    clumpiness factor   
+ -------------------------------------------------------- replicate below for all filters (grizy)
++gippDetectID    dimensionless   BIGINT  8       NA      ipp detect identifier
+ gstackDetectID  dimensionless   BIGINT  8       NA      ODM detection identifier
+ gstackMetaID    dimensionless   BIGINT  8       NA      stack identifier
+-gippObjID       dimensionless  BIGINT  8       NA      ipp object identifier
+-gippDetectID    dimensionless   BIGINT  8       NA      ipp detect identifier
++----------------------------------------------------------------------------------------
+ gdeVRadius      arcsec          REAL    4       -999    deVaucouleurs radius
+ gdeVRadiusErr   arcsec          REAL    4       -999    estimated error in deVaucouleurs radius
+ gdeVFlux        adu/seconds     REAL    4       -999    deVaucouleurs flux
+Index: ForcedMeanObject
+===================================================================
+--- ForcedMeanObject	(revision 36838)
++++ ForcedMeanObject	(working copy)
+@@ -1,3 +1,4 @@
++
+ objID           dimensionless   BIGINT   8        NA    ODM object identifier index
+ gcObjID		dimensionless	BIGINT	8	  NA 	ODM galactic coordinates identifier
+ ippObjID        dimensionless   BIGINT   8        NA    IPP object identifier
+Index: DiffDetObject
+===================================================================
+--- DiffDetObject	(revision 36838)
++++ DiffDetObject	(working copy)
+@@ -9,7 +9,7 @@
+ zoneID 		dimensionless 	INT 	4 	NA 	Zone index
+ randomID 	dimensionless 	BIGINT 	8 	0 	Random integer between 0 and 2^32 = 4,394,967,296 remaining ramdom integer 0  
+ batchID 	dimensionless	BIGINT 	8 	-999 	
+-dvoRegionID     dimensionless  	REAL    4       -999    identifier to dvo spatial region
++dvoRegionID     dimensionless  	INT     4       -999    identifier to dvo spatial region
+ objInfoFlag 	dimensionless 	BIGINT 	8 	-999 	flag indicating odd properties
+ qualityFlag 	dimensionless 	TINYINT 1 	0 	subset of objInfoFlag - flags related to goodness of object
+ consistencyFlag	dimensionless 	SMALLINT2 	0 	Value computed from associated detections, it is originally given by IPP and should agree with the ODM validation
+Index: StackObject
+===================================================================
+--- StackObject	(revision 36838)
++++ StackObject	(working copy)
+@@ -1,6 +1,7 @@
+ 
+ objID             dimensionless   BIGINT  8       NA      ODM object identifier
+ gcObjID		dimensionless	BIGINT	8	  NA 	ODM galactic coordinates identifier
++ippObjID          dimensionless   BIGINT  8       NA      object ID generated by IPP
+ surveyID          dimensionless   TINYINT 1       NA      survey flag identifier
+ skyCellID         dimensionless   REAL    4       -999    single float giving PrimaryCell.SkyCell identifier 
+ randomStackObjID  dimensionless   BIGINT  8       NA      random stack id
+@@ -8,16 +9,16 @@
+ primaryDetection  dimensionless   TINYINT 1       255     identifies if this row is a primary stack detection. True about 80% of time. 
+ bestDetection     dimensionless   TINYINT 1       255     identifies if this row is a best detection or not. Also set if only a primary detection exists.   
+                                                           the Primary Dectection, 0 to 3 possible secondary dectections, and the "best" per filter.  
+-dvoRegionID       dimensionless   REAL    4       -999    identifier to dvo spatial region
++dvoRegionID       dimensionless   INT     4       -999    identifier to dvo spatial region
+ dataRelease       dimensionless   TINYINT 1       NA      Data release when this detection was originally taken.
+ ------------------------------------------------------------------------------------------
+ -- attributes for all stack detections in all filters (these are currently forced anyway) 
+ -- Replicate the section below for each filter, changing the prefex ("g" in this example) 
+ ------------------------------------------------------------------------------------------
+-gippObjID         dimensionless   BIGINT  8       NA      object ID generated by IPP
+ gippDetectID      dimensionless   BIGINT  8       NA      detection ID generated by IPP
+ gstackDetectID    dimensionless   BIGINT  8       NA      ODM detection identifier
+ gstackMetaID      dimensionless   BIGINT  8       NA      stack identifier
++------------------------------------------------------------------------------------------
+ gxPos             arcsec          REAL    4       -999    measured x in sky Cell from PSF fit
+ gyPos             arcsec          REAL    4       -999    measured y in sky Cell from PSF fit
+ gxPosErr          arcsec          REAL    4       -999    estimated error in x
+@@ -57,7 +58,8 @@
+ gKronMagErr  	  AB magnitude    REAL    4       -999    estimated error of g kron AB magnitude from stack
+ gsky              adu/secs/arcsec REAL    4       -999    PSF sky level at source (adu)
+ gskyErr           adu/secs/arcsec REAL    4       -999    estimated error in sky
+-ginfoFlag         dimensionless   BIGINT  8       -999    indicator of strange propeties
++ginfoFlag         dimensionless   INT     4       -999    indicator of strange propeties
++ginfoFlag2        dimensionless   INT     4       -999    indicator of strange propeties
+ gnFrames          dimensionless   INT     4       -999    Number of frames contributing to source
+ 
+ -- [220 byte/filter/obj + 44 byte/obj]
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/CameraConfig
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/CameraConfig	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/CameraConfig	(revision 37066)
@@ -0,0 +1,12 @@
+CameraConfig
+Description: Camera configuration
+
+Name      	Unit		        DataType    Size	Default		ValueDescription 
+
+cameraID  	dimensionless   	SMALLINT 	2 	   -999         camera identifier (i.e. GPC1, ISP)
+cameraConfigID  dimensionless           SMALLINT        2          -999         camera configuration
+endDate         dimensionless               REAL        4          -999         ending date of this configuration in MJD
+configDetails   string           VARCHAR(MAX) 8000      0x00         NA         text/table giving the details of the camera configuration
+                                                                                NEED TO CHANGE and pass camera x from raw data file
+
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/DetectionFlags
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/DetectionFlags	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/DetectionFlags	(revision 37066)
@@ -0,0 +1,10 @@
+DetectionFlags
+
+Description: Flags used to interpret the information flag provided
+with each detection (infoFlag in 'Detection' table)
+
+Name Unit Data Type Size Default Value Description
+
+name 		VARCHAR(32) 	32	NA 	Name of flag 
+value 		BIGINT 		8 	NA 	Flag value
+description     VARCHAR(2000) 2000      NA      Description of the flag
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/DiffMeta
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/DiffMeta	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/DiffMeta	(revision 37066)
@@ -0,0 +1,26 @@
+diffMetaID   dimensionless   BIGINT 8 NA diff  identifier
+batchID      dimensionless   BIGINT 8 NA batch  identifier
+surveyID     dimensionless   TINYINT 1 NA survey flag identifier
+filterID     dimensionless   TINYINT 1 NA filter id 
+diffTypeID   dimensionless   TINYINT 1 0 diff type identifier
+posImageID   dimensionless   BIGINT 8 NA positive image identifier
+negImageID   dimensionless   BIGINT 8 NA negative image identifier
+skyCellID    dimensionless   REAL 4 NA skycell region identifier 
+photoCalID   dimensionless   INT 4 NA photometry code
+magSat       dimensionless   REAL 4 -999 saturation magnitude level
+analVer      dimensionless   SMALLINT 2 -999 analysis version index
+expTime      seconds         REAL 4 -999 exposure time of positive image
+ctype1       alphanumeric   VARCHAR(MAX) 8000 name of astrometric projection in RA
+ctype2       alphanumeric   VARCHAR(MAX) 8000 name of astrometric projection in DEC
+crval1       degrees        FLOAT 8 -999 RA corresponding to reference pixel
+crval2       degrees        FLOAT 8 -999 DEC corresponding to reference pixel
+crpix1       dimensionless  FLOAT 8 -999 reference pixel value for RA
+crpix2       dimensionless  FLOAT 8 -999 reference pixel value for DEC
+cdelt1       deg/pixel      FLOAT 8 -999 scale factor for RA
+cdelt2       deg/pixel      FLOAT 8 -999 scale factor for DEC
+pc001001     dimensionless  FLOAT 8 -999 elements of rotation/Dcale matrix 
+pc001002     dimensionless  FLOAT 8 -999 elements of rotation/Dcale matrix
+pc002001     dimensionless  FLOAT 8 -999 elements of rotation/Dcale matrix
+pc002002     dimensionless  FLOAT 8 -999 elements of rotation/Dcale matrix
+calibModNum  dimensionless  SMALLINT 2 NA calibration modification number
+dataRelease  dimensionless  TINYINT 1 NA Data release
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/DiffToImage
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/DiffToImage	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/DiffToImage	(revision 37066)
@@ -0,0 +1,2 @@
+diffMetaID 	BIGINT 	8 	NA 	diff identifier
+imageID 	BIGINT 	8 	NA 	hashed exposure-ccdID identifier
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/Filter
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/Filter	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/Filter	(revision 37066)
@@ -0,0 +1,3 @@
+FilterID dimensionless TINYNT 1 NA filter ID: g=1, r=2, i=3, z=4, y=5, w=6, ...
+filterType VARCHAR(2) 2 NA filter name: g,r,i,z,y, etc.
+filterSpec VARCHAR(MAX) 8000 0x00 No comment
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/FitModel
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/FitModel	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/FitModel	(revision 37066)
@@ -0,0 +1,42 @@
+fitModelID		SMALLINT	2	NA	indentifier of alternate model fit
+name		VARCHAR(30)	30		model name
+description		VARCHAR(MAX)	8000		string describing the model
+param1		VARCHAR(MAX)	8000		description of model parameter 1
+param2		VARCHAR(MAX)	8000		description of model parameter 2
+param3		VARCHAR(MAX)	8000		description of model parameter 3
+param4		VARCHAR(MAX)	8000		description of model parameter 4
+param5		VARCHAR(MAX)	8000		description of model parameter 5
+param6		VARCHAR(MAX)	8000		description of model parameter 6
+param7		VARCHAR(MAX)	8000		description of model parameter 7
+param8		VARCHAR(MAX)	8000		description of model parameter 8
+param9		VARCHAR(MAX)	8000		description of model parameter 9
+param10		VARCHAR(MAX)	8000		description of model parameter 10
+param11		VARCHAR(MAX)	8000		description of model parameter 11
+param12		VARCHAR(MAX)	8000		description of model parameter 12
+param13		VARCHAR(MAX)	8000		description of model parameter 13
+param14		VARCHAR(MAX)	8000		description of model parameter 14
+param15		VARCHAR(MAX)	8000		description of model parameter 15
+param16		VARCHAR(MAX)	8000		description of model parameter 16
+param17		VARCHAR(MAX)	8000		description of model parameter 17
+param18		VARCHAR(MAX)	8000		description of model parameter 18
+param19		VARCHAR(MAX)	8000		description of model parameter 19
+param20		VARCHAR(MAX)	8000		description of model parameter 20
+param21		VARCHAR(MAX)	8000		description of model parameter 21
+param22		VARCHAR(MAX)	8000		description of model parameter 22
+param23		VARCHAR(MAX)	8000		description of model parameter 23
+param24		VARCHAR(MAX)	8000		description of model parameter 24
+param25		VARCHAR(MAX)	8000		description of model parameter 25
+param26		VARCHAR(MAX)	8000		description of model parameter 26
+param27		VARCHAR(MAX)	8000		description of model parameter 27
+param28		VARCHAR(MAX)	8000		description of model parameter 28
+param29		VARCHAR(MAX)	8000		description of model parameter 29
+param30		VARCHAR(MAX)	8000		description of model parameter 30
+param31		VARCHAR(MAX)	8000		description of model parameter 31
+param32		VARCHAR(MAX)	8000		description of model parameter 32
+param33		VARCHAR(MAX)	8000		description of model parameter 33
+param34		VARCHAR(MAX)	8000		description of model parameter 34
+param35		VARCHAR(MAX)	8000		description of model parameter 35
+param36		VARCHAR(MAX)	8000		description of model parameter 36
+param37		VARCHAR(MAX)	8000		description of model parameter 37
+param38		VARCHAR(MAX)	8000		description of model parameter 38
+param39		VARCHAR(MAX)	8000		description of model parameter 39
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/ForcedWarpMeta
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/ForcedWarpMeta	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/ForcedWarpMeta	(revision 37066)
@@ -0,0 +1,33 @@
+forcedWarpID dimensionless   BIGINT 8 NA stack identifier
+batchID          dimensionless   BIGINT 8 NA batch identifier
+surveyID         dimensionless   TINYINT 1 NA survey flag identifier
+filterID         dimensionless   TINYINT 1 NA fnilutemr eidriecnatl ifidier
+skyCellID        dimensionless   REAL 4 NA skycell region identifier 
+photoCalID       dimensionless   INT 4 NA photometry code
+magSat           dimensionless   REAL 4 -999 saturation magnitude level
+analVer          dimensionless   SMALLINT 2 -999 analysis version index
+expTime          seconds         REAL 4 -999 exposure time
+completMag       magnitudes      REAL 4 -999 95% completion level in mag
+astroScat        dimensionless   REAL 4 -999 astrometric scatter for chip
+photoScat        dimensionless   REAL 4 -999 photometric scatter for chip
+nAstroRef        dimensionless   INT 4 -999 number of astrometric reference sources
+nPhoRef          dimensionless   INT 4 -999 number of photometric reference sources
+psfModelID       dimensionless   VARCHAR(MAX) 8000 PSF model identifier
+psfFwhm_mean     arcsec         FLOAT 8 -999 mean PSF FWHM in the stack
+psfFwhm_max      arcsec         FLOAT 8 -999 maximum PSF FWHM in the stack 
+photoZero        magnitudes     REAL 4 -999 local derived photometric zero point
+photoColor       magnitudes     REAL 4 -999 local derived photometric color term
+ctype1           alphanumeric   VARCHAR(MAX) 8000 name of astrometric projection in RA
+ctype2           alphanumeric   VARCHAR(MAX) 8000 name of astrometric projection in DEC
+crval1           degrees        FLOAT 8 -999 RA corresponding to reference pixel
+crval2           degrees        FLOAT 8 -999 DEC corresponding to reference pixel
+crpix1           dimensionless  FLOAT 8 -999 reference pixel value for RA
+crpix2           dimensionless  FLOAT 8 -999 reference pixel value for DEC
+cdelt1           deg/pixel      FLOAT 8 -999 scale factor for RA
+cdelt2           deg/pixel      FLOAT 8 -999 scale factor for DEC
+pc001001         dimensionless  FLOAT 8 -999 elements of rotation/Dcale matrix 
+pc001002         dimensionless  FLOAT 8 -999 elements of rotation/Dcale matrix
+pc002001         dimensionless  FLOAT 8 -999 elements of rotation/Dcale matrix
+pc002002         dimensionless  FLOAT 8 -999 elements of rotation/Dcale matrix
+calibModNum      dimensionless  SMALLINT 2 NA calibration modification number
+dataRelease      dimensionless  TINYINT 1 NA Data release
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/ForcedWarpToImage
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/ForcedWarpToImage	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/ForcedWarpToImage	(revision 37066)
@@ -0,0 +1,2 @@
+forcedWarpID 	BIGINT 	8 	NA 	forced warp identifier
+imageID 		BIGINT 	8 	NA 	hashed exposure-ccdID identifier
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/FrameMeta
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/FrameMeta	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/FrameMeta	(revision 37066)
@@ -0,0 +1,49 @@
+frameID	dimensionless	INT	4	NA	unique exposure/frame identifier.
+frameName	dimensionless	VARCHAR(32)	32	NA	frame name provided by camera software
+surveyID	dimensionless	TINYINT	1	NA	survey flag identifier
+filterID	dimensionless	TINYINT	1	NA	filter identifier
+cameraID	dimensionless	SMALLINT	2	NA	camera identifier
+cameraConfigID	dimensionless	SMALLINT	2	NA	camera configuration identifier
+telescopeID	dimensionless	SMALLINT	2	NA	telescope identifier
+analysisVer	alphanumeric	VARCHAR(MAX)	8000		IPP software analysis release
+p1Recip	alphanumeric	VARCHAR(MAX)	8000		IPP phase 1 MD5 Checksum
+p2Recip	alphanumeric	VARCHAR(MAX)	8000		IPP phase 2 MD5 Checksum
+p3Recip	alphanumeric	VARCHAR(MAX)	8000		IPP phase 3 MD5 Checksum
+nOTA	alphanumeric	SMALLINT	2	-999	number of valid OTA/CCD images in this exposure
+photoScat	magnitude	REAL	4	-999	global photometric scatter
+numPhotoRef	dimensionless	INT	4	-999	number of photometric reference sources
+expStart	days	FLOAT	8	-999	exposure start time in MJD
+expTime	seconds	REAL	4	-999	exposure time
+airmass	dimensionless	REAL	4	-999	airmass at mid-exposure
+raBore	degrees	FLOAT	8	-999	RA of telescope boresight
+decBore	degrees	FLOAT	8	-999	DEC of telescope boresight
+ctype1	alphanumeric	VARCHAR(MAX)	8000		name of astrometric projection in RA
+ctype2		VARCHAR(MAX)	8000		name of astrometric projection in DEC
+crval1	degrees	FLOAT	8	-999	RA corresponding to reference pixel
+crval2	degrees	FLOAT	8	-999	DEC corresponding to reference pixel
+crpix1	pc001001	FLOAT	8	-999	reference pixel value for RA
+crpix2	dimensionless	FLOAT	8	-999	reference pixel value for DEC
+cdelt1	degrees/pixel	FLOAT	8	-999	scale factor for RA
+cdelt2	degrees/pixel	FLOAT	8	-999	scale factor for DEC
+pc001001	dimensionless	FLOAT	8	-999	elements of rotation/Dcale matrix
+pc001002	dimensionless	FLOAT	8	-999	elements of rotation/Dcale matrix
+pc002001	dimensionless	FLOAT	8	-999	elements of rotation/Dcale matrix
+pc002002	dimensionless	FLOAT	8	-999	elements of rotation/Dcale matrix
+polyOrder	dimensionless	TINYINT	1	255	polynomial order of astrometry fit
+pca1x3y0	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca1x2y1	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca1x1y2	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca1x0y3	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca1x2y0	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca1x1y1	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca1x0y2	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca2x3y0	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca2x2y1	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca2x1y2	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca2x0y3	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca2x2y0	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca2x1y1	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca2x0y2	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+calibModNum	dimensionless	SMALLINT	2	NA	calibration modification number
+batchID 	dimensionless	BIGINT	8	NA	batch ID 
+dataRelease	dimensionless	TINYINT	1	NA	Data release Version of this table
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/ImageFlags
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/ImageFlags	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/ImageFlags	(revision 37066)
@@ -0,0 +1,3 @@
+name VARCHAR(32) 32 NA Name of flag
+value BIGINT 8 NA Flag value
+description VARCHAR(2000) 2000 Description of the flag
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/ImageMeta
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/ImageMeta	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/ImageMeta	(revision 37066)
@@ -0,0 +1,74 @@
+imageID		dimensionless	BIGINT	8	NA	unique ID for each image, hashed from frameID and ccdID 
+frameID		dimensionless	INT	4	NA	frame identifier, also known as exposure number
+ccdID		dimensionless	SMALLINT	2	NA	ccd cell identifier in the focal plane
+photoCalID      dimensionless	INT	4	NA	photometry reduction code identifier
+filterID	dimensionless	TINYINT	1	NA	filter ID
+bias		ADU		REAL	4	-999	detector bias level
+biasScat	ADU		REAL	4	-999	scatter in bias level
+sky		ADU/pixel	REAL	4	-999	mean sky level
+skyScat		ADU/pixel	REAL	4	-999	scatter in mean sky level
+nDetect		dimensionless	INT	4	-999	number of detections on CCD
+magSat		magnitude	REAL	4	-999	saturation magnitude level
+completMag	magnitude	REAL	4	-999	95% completion level in mag
+astroScat	arcsec		REAL	4	-999	astrometric scatter for chip
+photoScat	magitude	REAL	4	-999	photometric scatter for chip
+numAstroRef	dimensionless	INT	4	-999	number of astrometric reference sources
+numPhotoRef	dimensionless	INT	4	-999	number of photometric reference sources
+nx		pixels		SMALLINT	2	-999	chip dimension in x
+ny		pixels		SMALLINT	2	-999	chip dimension in y
+psfModelID	dimensionless	INT	4	-999	PSF model identifier
+psfFwhm		arcsec		REAL	4	-999	model psf full width at half maximum at chip center
+psfWidMajor	arcsec		REAL	4	-999	model PSF parameters at chip center
+psfWidMinor	arcsec		REAL	4	-999	model PSF parameters at chip center
+psfTheta	degrees		REAL	4	-999	model PSF parameters at chip center
+momentXX        pixels  	REAL    4       -999    moment XX
+momentXY        pixels  	REAL    4       -999    moment XY
+momentYY        pixels  	REAL    4       -999    moment YY
+momentM3C       pixels squared  REAL    4       -999    moment M3C
+momentM3S       pixels squared  REAL    4       -999    moment M3S
+momentM4C       pixels squared  REAL    4       -999    moment M4C
+momentM4S       pixels squared  REAL    4       -999    moment M4S
+momentR1        pixels  	REAL    4       -999    moment R1
+momentRH        sqrt pixels     REAL    4       -999    moment RH
+apResid		magnitide	REAL	4	-999	corrected aperture residual
+dapResid	magnitide	REAL	4	-999	scatter of aperture corrections
+detectorID	alphanumeric	VARCHAR(32)	32		identifier for actual CCD chip
+qaFlags		dimensionless	BIGINT	8	-999	Q/A flags for this OTA
+detrend1	alphanumeric	VARCHAR(MAX)	8000		identifier of detrend image 1
+detrend2	alphanumeric	VARCHAR(MAX)	8000		identifier of detrend image 2
+detrend3	alphanumeric	VARCHAR(MAX)	8000		identifier of detrend image 3
+detrend4	alphanumeric	VARCHAR(MAX)	8000		identifier of detrend image 4
+detrend5	alphanumeric	VARCHAR(MAX)	8000		identifier of detrend image 5
+detrend6	alphanumeric	VARCHAR(MAX)	8000		identifier of detrend image 6
+detrend7	alphanumeric	VARCHAR(MAX)	8000		identifier of detrend image 7
+detrend8	alphanumeric	VARCHAR(MAX)	8000		identifier of detrend image 8
+photoZero	magnitude	REAL	4	-999	local derived photometric zero point
+ctype1		alphanumeric	VARCHAR(MAX)	8000		name of astrometric projection in RA
+ctype2		alphanumeric	VARCHAR(MAX)	8000		name of astrometric projection in DEC
+crval1		degrees	FLOAT	8	-999	RA corresponding to reference pixel
+crval2		degrees	FLOAT	8	-999	DEC corresponding to reference pixel
+crpix1		pixels	FLOAT	8	-999	reference pixel value for RA
+crpix2		pixels	FLOAT	8	-999	reference pixel value for DEC
+cdelt1		degrees/pixel	FLOAT	8	-999	scale factor for RA
+cdelt2		degrees/pixel	FLOAT	8	-999	scale factor for DEC
+pc001001	unknown	FLOAT	8	-999	elements of rotation/Dcale matrix
+pc001002	unknown	FLOAT	8	-999	elements of rotation/Dcale matrix
+pc002001	unknown	FLOAT	8	-999	elements of rotation/Dcale matrix
+pc002002	unknown	FLOAT	8	-999	elements of rotation/Dcale matrix
+polyOrder	dimensionless	TINYINT	1	255	polynomial order of astrometry fit
+pca1x3y0	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca1x2y1	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca1x1y2	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca1x0y3	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca1x2y0	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca1x1y1	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca1x0y2	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca2x3y0	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca2x2y1	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca2x1y2	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca2x0y3	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca2x2y0	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca2x1y1	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+pca2x0y2	dimensionless	FLOAT	8	-999	polynomial coefficients for the astrometric fit
+calibModNum	dimensionless	SMALLINT	2	NA	calibration modification number
+dataRelease	dimensionless	TINYINT	1	NA	Data release Version of this table
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/Mask
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/Mask	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/Mask	(revision 37066)
@@ -0,0 +1,9 @@
+maskID BIGINT 8 NA mask identifier
+partitionKey BIGINT 8 NA fget(mask_center_ra, mask_center_dec, zoneH)
+frameID INT 4 NA reference to the P2FrameMeta table where the mask is defined
+imageID BIGINT 8 NA reference to the P2FrameMeta table where the mask is
+ra FLOAT 8 NA rdae finin ethde center
+dec FLOAT 8 NA dec in the center
+radius FLOAT 8 NA No comment
+maskString VARCHAR(MAX) 8000 string representation fo the mask region
+maskBinary VARBINARY(MAX) 8000 0x Binary object managed by the spatial library
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/MovingObjToDet
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/MovingObjToDet	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/MovingObjToDet	(revision 37066)
@@ -0,0 +1,2 @@
+MovingObjID  	BIGINT 	8 	NA 	Moving Object identifier  
+DetectionID 	BIGINT 	8 	NA 	detection identifier  
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/MovingObjToDiffDet
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/MovingObjToDiffDet	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/MovingObjToDiffDet	(revision 37066)
@@ -0,0 +1,2 @@
+MovingObjID  	BIGINT 	8 	NA 	Moving Object identifier  
+DiffDetID 	BIGINT 	8 	NA 	difference image detection identifier  
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/MovingObjToObject
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/MovingObjToObject	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/MovingObjToObject	(revision 37066)
@@ -0,0 +1,2 @@
+MovingObjID  	BIGINT 	8 	NA 	Moving Object identifier
+ObjID 	 	BIGINT 	8 	NA 	Object identifier
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/ObjectFilterFlags
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/ObjectFilterFlags	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/ObjectFilterFlags	(revision 37066)
@@ -0,0 +1,3 @@
+name	dimensionless	VARCHAR(32)	32		Name of flag
+value	dimensionless	BIGINT	8	NA	Flag value
+description	dimensionless	VARCHAR(2000)	2000		Description of the flag
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/ObjectInfoFlags
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/ObjectInfoFlags	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/ObjectInfoFlags	(revision 37066)
@@ -0,0 +1,3 @@
+name	dimensionless	VARCHAR(32)	32		Name of flag
+value	dimensionless	BIGINT	8	NA	Flag value
+description	dimensionless	VARCHAR(2000)	2000		Description of the flag
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/ObjectQualityFlags
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/ObjectQualityFlags	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/ObjectQualityFlags	(revision 37066)
@@ -0,0 +1,3 @@
+name	dimensionless	VARCHAR(32)	32		Name of flag
+value	dimensionless	BIGINT	8	NA	Flag value
+description	dimensionless	VARCHAR(2000)	2000		Description of the flag
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/PhotoCal
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/PhotoCal	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/PhotoCal	(revision 37066)
@@ -0,0 +1,11 @@
+photoCalID		INT	4	NA	numerical code for this reduction
+filterID		TINYINT	1	NA	filter id
+photoCodeDesc		VARCHAR(MAX)	8000		Photometry reduction code name
+AB		REAL	4	1.0	AB magnitude
+zeropoint		REAL	4	-999	photometric zero point (excluding long term variation)
+extinction		REAL	4	-999	photometric extinction term (excluding long term variation)
+colorterm		REAL	4	-999	photometric color term (excluding long term variation)
+colorExtn		REAL	4	-999	photometric color dependent extinction (excluding long term variation)
+orphanCalColor		REAL	4	-999	color adopted for magnitude calculation
+orphanCalColorErr		REAL	4	-999	error in calibrating color
+startDate	day	REAL	4	NA	starting date of this configuration in MJD
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/ProjectionCell
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/ProjectionCell	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/ProjectionCell	(revision 37066)
@@ -0,0 +1,22 @@
+projectionCellID 		INT 4 NA projection cell unique identifier
+partitionKey 			BIGINT 8 NA fGetPanObjID(crval1,crval2)
+primaryCellRegionID 		BIGINT 8 NA reference to the primary cell region definition in the Region table
+projectionCellRegionID 		BIGINT 8 NA reference to the projectio cell region definition in the
+ctype1 				VARCHAR(MAX) 8000 NA nRaemgieo no ft aabsltero)metric projection in RA
+ctype2 				VARCHAR(MAX) 8000 NA name of astrometric projection in DEC
+crval1 deg 			FLOAT 8 NA RA corresponding to reference pixel
+crval2 deg 			FLOAT 8 NA DEC corresponding to reference pixel
+crpix1 				FLOAT 8 NA reference pixel value for RA
+crpix2 				FLOAT 8 NA reference pixel value for DEC
+pc001001 			FLOAT 8 NA elements of rotation/Dcale matrix
+pc001002 			FLOAT 8 NA elements of rotation/Dcale matrix
+pc002001 			FLOAT 8 NA elements of rotation/Dcale matrix
+pc002002 			FLOAT 8 NA elements of rotation/Dcale matrix
+raNEcornerPC   degrees          FLOAT  8 -999 ra of NE corner
+decNEcornerPC  degrees          FLOAT  8 -999 dec of NE corner
+raNWcornerPC   degrees          FLOAT  8 -999 ra of NE corner
+decNWcornerPC  degrees          FLOAT  8 -999 dec of NE corner
+raSEcornerPC   degrees          FLOAT  8 -999 ra of NE corner
+decSEcornerPC  degrees          FLOAT  8 -999 dec of NE corner
+raSWcornerPC   degrees          FLOAT  8 -999 ra of NE corner
+decSWcornerPC  degrees          FLOAT  8 -999 dec of NE corner
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/PsConstant
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/PsConstant	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/PsConstant	(revision 37066)
@@ -0,0 +1,4 @@
+name VARCHAR(32) 32 NA constant's name
+value FLOAT 8 NA constant's value
+unit VARCHAR(32) 32 unit of constant
+description VARCHAR(2000) 2000 description of the constant
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/Region
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/Region	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/Region	(revision 37066)
@@ -0,0 +1,7 @@
+regionID dimensionless	BIGINT 8 NA Unique Region identifier 
+id 	 dimensionless	BIGINT 8 NA Custom Identifier
+type 	 string         VARCHAR(16) 16 NA Region type
+comment  string         VARCHAR(MAX) 8000 Comment
+area     sqdeg?         FLOAT 8 0 Area covered by the region
+region   dimensionless	Binary VARBINARY(MAX) 8000 0x Binary object managed by the spatial library
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/RegionPatch
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/RegionPatch	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/RegionPatch	(revision 37066)
@@ -0,0 +1,15 @@
+Unit Data Type Size Default Value Description
+regionid BIGINT 8 NA No comment
+convexid BIGINT 8 NA No comment
+patchid INT 4 NA No comment
+type (16) NA No comment
+radius FLOAT 8 0 No comment
+ra degree FLOAT 8 0 Right Ascension
+dec FLOAT 8 0 No comment
+x FLOAT 8 0 No comment
+y FLOAT 8 0 No comment
+z FLOAT 8 0 No comment
+c FLOAT 8 0 No comment
+htmid BIGINT 8 0 No comment
+area FLOAT 8 0 No comment
+convexString (MAX) No comment
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/SkyCell
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/SkyCell	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/SkyCell	(revision 37066)
@@ -0,0 +1,12 @@
+skyCellID   dimensionless I	INT 4 NA indentifier of the sky cell
+projectionCellID 		INT 4 -999 indentifier of the projection cell
+partitionKey 	 		BIGINT 8 -999 fgetPANobjID(skyCell_center_ra, skyCell_center_dec, zHeight)
+regionID 	 		BIGINT 8 -999 region identifier in the Region table
+raNEcorner   degrees            FLOAT  8 -999 ra of NE corner
+decNEcorner  degrees            FLOAT  8 -999 dec of NE corner
+raNWcorner   degrees            FLOAT  8 -999 ra of NE corner
+decNWcorner  degrees            FLOAT  8 -999 dec of NE corner
+raSEcorner   degrees            FLOAT  8 -999 ra of NE corner
+decSEcorner  degrees            FLOAT  8 -999 dec of NE corner
+raSWcorner   degrees            FLOAT  8 -999 ra of NE corner
+decSWcorner  degrees            FLOAT  8 -999 dec of NE corner
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/StackDetectionFlags
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/StackDetectionFlags	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/StackDetectionFlags	(revision 37066)
@@ -0,0 +1,3 @@
+Name	dimensionless	VARCHAR(32)	32		Name of flag
+value	dimensionless	BIGINT	8	NA	Flag value
+description	dimensionless	VARCHAR(2000)	2000		Description of the flag
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/StackMeta
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/StackMeta	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/StackMeta	(revision 37066)
@@ -0,0 +1,35 @@
+stackMetaID dimensionless   BIGINT 8 NA stack identifier
+batchID     dimensionless   BIGINT 8 NA batch identifier
+surveyID    dimensionless   TINYINT 1 NA survey flag identifier
+filterID    dimensionless   TINYINT 1 NA fnilutemr eidriecnatl ifidier
+stackTypeID dimensionless   TINYINT 1 0 stack type identifier
+skyCellID   dimensionless   REAL 4 NA skycell region identifier 
+photoCalID  dimensionless   INT 4 NA photometry code
+magSat      dimensionless   REAL 4 -999 saturation magnitude level
+analVer     dimensionless   SMALLINT 2 -999 analysis version index
+expTime     seconds         REAL 4 -999 exposure time
+nP2Images   dimensionless   SMALLINT 2 -999 number of P2 images contributing to this cell
+completMag  magnitudes      REAL 4 -999 95% completion level in mag
+astroScat   dimensionless   REAL 4 -999 astrometric scatter for chip
+photoScat   dimensionless   REAL 4 -999 photometric scatter for chip
+nAstroRef   dimensionless   INT 4 -999 number of astrometric reference sources
+nPhoRef     dimensionless   INT 4 -999 number of photometric reference sources
+psfModelID  dimensionless   VARCHAR(MAX) 8000 PSF model identifier
+psfFwhm_mean arcsec         FLOAT 8 -999 mean PSF FWHM in the stack
+psfFwhm_max  arcsec         FLOAT 8 -999 maximum PSF FWHM in the stack 
+photoZero    magnitudes     REAL 4 -999 local derived photometric zero point
+photoColor   magnitudes     REAL 4 -999 local derived photometric color term
+ctype1       alphanumeric   VARCHAR(MAX) 8000 name of astrometric projection in RA
+ctype2       alphanumeric   VARCHAR(MAX) 8000 name of astrometric projection in DEC
+crval1       degrees        FLOAT 8 -999 RA corresponding to reference pixel
+crval2       degrees        FLOAT 8 -999 DEC corresponding to reference pixel
+crpix1       dimensionless  FLOAT 8 -999 reference pixel value for RA
+crpix2       dimensionless  FLOAT 8 -999 reference pixel value for DEC
+cdelt1       deg/pixel      FLOAT 8 -999 scale factor for RA
+cdelt2       deg/pixel      FLOAT 8 -999 scale factor for DEC
+pc001001     dimensionless  FLOAT 8 -999 elements of rotation/Dcale matrix 
+pc001002     dimensionless  FLOAT 8 -999 elements of rotation/Dcale matrix
+pc002001     dimensionless  FLOAT 8 -999 elements of rotation/Dcale matrix
+pc002002     dimensionless  FLOAT 8 -999 elements of rotation/Dcale matrix
+calibModNum  dimensionless  SMALLINT 2 NA calibration modification number
+dataRelease  dimensionless  TINYINT 1 NA Data release
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/StackToImage
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/StackToImage	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/StackToImage	(revision 37066)
@@ -0,0 +1,2 @@
+stackMetaID 	BIGINT 	8 	NA 	stack identifier
+imageID 	BIGINT 	8 	NA 	hashed exposure-ccdID identifier
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/StackType
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/StackType	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/StackType	(revision 37066)
@@ -0,0 +1,3 @@
+stackTypeID		TINYINT	1	-999	stack type identifier
+name		VARCHAR(20)	20		stack type name
+description		VARCHAR(MAX)	8000		stack type description
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/Survey
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/Survey	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/Survey	(revision 37066)
@@ -0,0 +1,4 @@
+SurveyID TINYINT 1 NA index of survey type
+name VARCHAR(6) 6 survey name
+description VARCHAR(MAX) 8000 
+survey description
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/TelescopeConfig
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/TelescopeConfig	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/TelescopeConfig	(revision 37066)
@@ -0,0 +1,16 @@
+TelescopeConfig
+Description: Telescope configuration
+
+Name      	Unit		        DataType    Size	Default		ValueDescription 
+
+TelescopeID  	dimensionless   	SMALLINT 	2 	   -999         Telescope identifier (i.e. PS1, ISP)
+TeleConfigID    dimensionless           SMALLINT        2          -999         Telescope Configuration ID
+MountModel      string                                  8            NA         Mount Model Name
+MirrorModel     string                                  8            NA         Mirror Model Name
+Observera       string                                  8            NA         Observers Name
+endDate         MeanJulianDays   	    FLOAT       8          -999         ending date of this configuration in MJD
+configDetails   string           VARCHAR(MAX) 8000      0x00         NA         text/table giving the details of the telescope configuration
+
+
+
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/pcsGalaxyModel
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/pcsGalaxyModel	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/pcsGalaxyModel	(revision 37066)
@@ -0,0 +1,3 @@
+galaxyModelID	dimensionless	INT	4	NA	modelID
+description	dimensionless	VARCHAR(128)	128		model description, spectral type etc.
+priors	dimensionless	VARCHAR(128)	128		priors applied to this model, may also split into 7 columns
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/pcsPhotoZRecipe
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/pcsPhotoZRecipe	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/pcsPhotoZRecipe	(revision 37066)
@@ -0,0 +1,2 @@
+photozRecipeID	dimensionless	TINYINT	1	-999	recipe index
+description	dimensionless	VARCHAR(MAX)	8000		string\ describing\ the\ recipe
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/pcsSGSepRecipe
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/pcsSGSepRecipe	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/pcsSGSepRecipe	(revision 37066)
@@ -0,0 +1,2 @@
+sgSepRecipeID	dimensionless	INT	4	NA	Star/Galaxy Seperator Recuipe ID
+description	dimensionless	VARCHAR(128)	128		Description
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/pcsStarModel
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/pcsStarModel	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/pcsStarModel	(revision 37066)
@@ -0,0 +1,2 @@
+starModelID	dimensionless	INT	4	-999	modelID
+description	dimensionless	VARCHAR(128)	128		model description, spectral type etc
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/pcsStellarParamsRecipe
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/pcsStellarParamsRecipe	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_TABLES/MetaData_Tables/pcsStellarParamsRecipe	(revision 37066)
@@ -0,0 +1,3 @@
+stellarParamsRecipeID	dimensionless	INT	4	NA	Na
+description	dimensionless	VARCHAR(128)	128		Description:wq
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_VIEWS/README
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_VIEWS/README	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_VIEWS/README	(revision 37066)
@@ -0,0 +1,5 @@
+See Notes_on_Schema 03.txt
+for what tables are combined into what views.
+Once there is concensus on tables, then will combine tables to make views. Meanwhile can concatente yourself from Notes.
+
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_VIEWS/Views
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_VIEWS/Views	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/SchemaNew18.0/PSPS_VIEWS/Views	(revision 37066)
@@ -0,0 +1,17 @@
+
+PSPS VIEWS - examples  
+
+ObjectMean        = ObjectThin join MeanObject 
+ObjectStack       = ObjectThin join StackObject
+ObjectApFlx       = ObjectThin join StackApFlx  
+ObjectModel       = ObjectThin join StackModelFit   
+ObjectStackAll    = ObjectThin join StackObject and StackAp and StackModelFit 
+ObjectForcedMean  = ObjectThin join ForcedMeanObject
+ObjectPrimary     = ObjectThin join StackObject join StackApFlx where primaryDection is true
+ObjectBest        = ObjectThin join StackObject join StackApFlx where bestDetection is true
+
+
+
+
+
+
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/pspsSchema2xml.pl
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/pspsSchema2xml.pl	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/pspsschema/pspsSchema2xml.pl	(revision 37066)
@@ -0,0 +1,375 @@
+#!/usr/bin/perl -w
+
+#######################################################################################
+#
+# Script that searches a dir containing PSPS schema files, finds those that comtain the 
+# tables on interest then parses them into the VOTable format. Also generates trac-wiki 
+# formatted tables.
+#
+#######################################################################################
+
+use warnings;
+use strict;
+use IPC::Cmd 0.36 qw( can_run run );
+use XML::Writer;
+use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
+use Pod::Usage qw( pod2usage );
+
+my $schemaPath = undef;
+my $type = undef;
+
+# get user args
+GetOptions(
+        'schema|s=s' => \$schemaPath,
+        'type|t=s' => \$type,
+        ) or pod2usage( 2 );
+
+pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
+
+# tell off user for not providing proper args
+pod2usage(
+        -msg => "\n   Required options:\n\n".
+        "-s   <path to PSPS schema>\n".
+        "-t   <init|detection|diff|stack|object>\n".
+        -exitval => 3
+        ) unless
+defined $schemaPath and
+defined $type;
+
+if (
+        $type ne "init" && 
+        $type ne "detection" && 
+        $type ne "diff" && 
+        $type ne "stack" && 
+        $type ne "object" ) {
+
+    print "Don't understand type '$type'\n"; 
+    die;
+}
+
+open(WIKI, ">tables.wiki") or die("Error");
+
+my $enumsHeader = ucfirst($type)."BatchEnums";
+
+# VOTable file
+my $votOutput = new IO::File(">tables.vot");
+my $votWriter = new XML::Writer(OUTPUT => $votOutput, DATA_MODE => 1, DATA_INDENT=>2);
+$votWriter->xmlDecl('UTF-8');
+$votWriter->startTag('VOTABLE', "version" => "1.1");
+$votWriter->startTag('RESOURCE');
+
+if ($type eq "init") {createInit();}
+elsif ($type eq "detection") {createDetections();}
+elsif ($type eq "diff") {createDiffs();}
+elsif ($type eq "stack") {createStacks();}
+elsif ($type eq "object") {createObjects();}
+
+# finish up XML
+$votWriter->endTag(); # end RESOURCE tag
+$votWriter->endTag(); # end of TABLE tag
+$votWriter->end();
+
+close WIKI;
+
+
+#######################################################################################
+#
+# Finds the schema file containing the table name passed in
+#
+#######################################################################################
+sub findSchemaFile {
+    my ($tableName) = @_;
+
+    opendir(DIR, $schemaPath) or print "Cannot open '$schemaPath'\n" and return "";
+    my @files= readdir(DIR);
+    closedir(DIR);
+
+    foreach my $f (@files) {
+
+        if ($f =~ m/.*\.sql$/) {
+            #print "....$f\n";
+
+            open FILE, "<$schemaPath/$f" or next;
+
+            while (<FILE>) {
+                if ($_ =~ m/.*CREATE TABLE\s+dbo\.$tableName\s*\(/i) {
+
+                    close (FILE);
+                    return "$schemaPath/$f";
+                }
+            }
+
+            close (FILE);
+
+        }
+    }
+
+    print "Could not find table '$tableName'\n";
+    return "";
+}
+
+#######################################################################################
+#
+# Creates detection batch tables
+#
+#######################################################################################
+sub createInit {
+
+    parseTable("Filter");
+    parseTable("FitModel");
+ #   parseTable("PhotozRecipe");
+    parseTable("Survey");
+    parseTable("CameraConfig");
+    parseTable("PhotoCal");
+    parseTable("SkyCell");
+    parseTable("ProjectionCell");
+    parseTable("Region");
+    parseTable("StackType");
+    parseTable("ImageFlags");
+    parseTable("DetectionFlags");
+}
+
+#######################################################################################
+#
+# Creates initialisation batch tables
+#
+#######################################################################################
+sub createDetections {
+
+    parseTable("FrameMeta");
+    parseTable("ImageMeta");
+    parseTable("Detection");
+    parseTable("SkinnyObject");
+  #  parseTable("ObjectCalColor");
+}
+
+#######################################################################################
+#
+# Creates difference batch tables
+#
+#######################################################################################
+sub createDiffs {
+
+    parseTable("StackMeta");
+    parseTable("StackToImage");
+   # parseTable("StackLowSigDelta");
+   # parseTable("StackHighSigDelta");
+   # parseTable("ObjectCalColor");
+}
+
+#######################################################################################
+#
+# Creates stack batch tables
+#
+#######################################################################################
+sub createStacks {
+
+    parseTable("StackMeta");
+    parseTable("StackDetection");
+    parseTable("StackApFlx");
+    parseTable("StackModelFit");
+    parseTable("StackToImage");
+    parseTable("SkinnyObject");
+   # parseTable("ObjectCalColor");
+}
+
+#######################################################################################
+#
+# Creates object batch tables
+#
+#######################################################################################
+sub createObjects {
+
+    parseTable("Object");
+    #parseTable("ObjectCalColor");
+}
+
+#######################################################################################
+#
+# Parses a particular table from the SQL file and converts it to an XML description 
+#
+#######################################################################################
+sub parseTable {
+    my ($tableName, $newName) = @_;
+
+    my $path =  findSchemaFile($tableName);
+
+    if ($path eq "") {return;}
+
+    # sort out table name, either same as in schema or as defined
+    my $tableNameOut; 
+    if ($newName) { $tableNameOut = $newName;}
+    else {$tableNameOut = $tableName}
+
+
+    print WIKI "|| '''!".$tableNameOut."''' ||||||||||||||\n";
+    print WIKI "|| '''ODM attribute''' || '''units''' || '''Data type''' || '''Default''' || '''Description''' || '''IPP source''' || '''IPP variable/notes''' ||\n";
+    $votWriter->startTag('TABLE', 
+            "name" => "$tableNameOut");
+    $votWriter->dataElement('DESCRIPTION', "VOTable description of PSPS table $tableNameOut");
+    $votWriter->startTag('PARAM',
+            "arraysize" => "1",
+            "datatype" => "char",
+            "ucd" => "meta.bib.author",
+            "name" => "Author",
+            "value" => "PSPS");
+    $votWriter->endTag();
+
+    open (SCHEMA, $path);
+
+    my $reading = 0;
+    my $found = 0;
+    my $colNum = 0;
+    my $table;
+
+    while (<SCHEMA>) {
+        chomp;
+
+        if ($_ =~ m/.*CREATE TABLE\s+dbo\.([a-zA-Z0-9.]+)\s*\(/i) {
+
+            $table = $1;
+
+            if ($table eq $tableName) {
+
+                $reading = 1;
+                $found = 1;
+                $colNum = 0;
+                next;
+            }
+        }
+
+        if($reading && $_ =~ m/^\s*\)\s*/) {$reading = 0;}
+
+        if(!$reading) {next;}
+
+        my $line = $_;
+        $line =~ s/[\s]*$//;
+
+        if (!$line) {next;}
+        if (length($line) < 5) {next;}
+        if ($line =~ m/^\s*--/) {next;}
+        if ($line =~ m/\/\*/) {next;}
+        if ($line =~ m/\*\//) {next;}
+
+        $colNum = processLine($line, $tableName, $colNum);
+
+    }
+
+    if (!$found) {print "Could not find table '$tableName'\n";}
+
+    $votWriter->startTag('DATA');
+    $votWriter->startTag('TABLEDATA');
+    $votWriter->endTag(); # end TABLEDDATA tag
+        $votWriter->endTag(); # end DATA tag
+        $votWriter->endTag(); # end TABLE tag
+
+    close SCHEMA;
+}
+
+#######################################################################################
+#
+# Processes a line from the PSPS schema table description and converts to XML
+#
+#######################################################################################
+sub processLine {
+    my ($line, $tableName, $colNum) = @_;
+
+    my $name;
+    my $typeStr;
+    my $type;
+    my $comment;
+    my $fullComment;
+    my $default;
+    my $unit = "unknown";
+    my $mstype = "unknown";
+
+    # parse line
+    if ($line =~ m/\s*([a-zA-Z0-9()-_\[\]]+)\s+(.*)\s*--\/(.*)/) {
+
+        $name = $1;
+        $typeStr = $2;
+        $comment = $3;
+
+        # neaten up the comment
+        $comment =~ s/<[\/]{0,1}column>//g;
+        $comment =~ s/^[\s]*//;
+        $comment =~ s/[\s]*$//;
+        if ($comment =~ m/<column unit="(.*)">(.*)/ ) {$comment = $2; $unit = $1;}
+        $fullComment = "$comment (unit = $unit)";
+    }
+    # no comment case
+    elsif ($line =~ m/\s*([a-zA-Z0-9()-_\[\]]+)\s+(.*)/) {
+
+        $name = $1;
+        $typeStr = $2;
+        $comment = "No comment";
+        $fullComment = $comment;
+    }
+    else {
+
+        print "In '$tableName', can't process: '$line'\n";
+        return $colNum
+    }
+
+    my $ISBINARY = 0;
+
+    # remove [] from name
+    $name =~ s/[\[\]]//g;
+
+    # sort out type
+    if ($typeStr =~ m/([a-zA-Z0-9()-]*)[ \t]+.*/) {
+
+        $type = $1;
+        $mstype = $1;
+        $type =~ s/BIGINT/TLONGLONG/;
+        $type =~ s/SMALLINT/TSHORT/;
+        $type =~ s/TINYINT/TBYTE/;
+        $type =~ s/INT/TLONG/;
+        $type =~ s/FLOAT/TDOUBLE/;
+        $type =~ s/REAL/TFLOAT/;
+        $type =~ s/DATE/TSTRING/;
+        if ($type =~ m/^VARCHAR.*/) {$type = "TSTRING";}
+        if ($type =~ m/^VARBINARY.*/) {$type = "TSTRING"; $ISBINARY = 1;}
+    }
+
+    # get default value
+    if ($typeStr =~ m/.*DEFAULT[ \t]*(.*)/i) {
+
+        $default = $1;
+        $default =~ s/,//;
+            $default =~ s/[\(\)]//g;
+        $default =~ s/[\s]*$//;
+        $default =~ s/'//g;
+        if ($type ne "TSTRING" && !$default) {$default = "0";}
+        if ($ISBINARY && $default eq "0x") {$default = "";}
+    }
+    elsif ($type eq "TSTRING") {$default = " ";}
+    else {$default = 0;}
+
+    if ($type eq "TSTRING" && $default eq "") {$default = " ";}
+
+    $colNum++;
+
+    print WIKI "|| ".$name."||".$unit."||".$mstype."||".$default."||".$comment."|| || ||\n";
+
+    # get VOTable type
+    my $votType = "undef";
+    my $arraySize = 1;
+    if ($type eq "TBYTE") {$votType = "unsignedByte";}
+    elsif ($type eq "TSHORT") {$votType = "short";}
+    elsif ($type eq "TLONG") {$votType = "int";}
+    elsif ($type eq "TLONGLONG") {$votType = "long";}
+    elsif ($type eq "TFLOAT") {$votType = "float";}
+    elsif ($type eq "TDOUBLE") {$votType = "double";}
+    elsif ($type eq "TSTRING") {$votType = "char"; $arraySize = 100;}
+
+    $votWriter->startTag('FIELD',
+            "name" => $name,
+            "arraysize" => $arraySize,
+            "datatype" => $votType,
+            "unit" => $unit);
+    $votWriter->dataElement('DESCRIPTION', $comment);
+    $votWriter->endTag();
+
+    return $colNum;
+}
Index: /branches/eam_branches/ipp-ops-20130712/ippToPsps/xmlschema/BatchManifest.xsd
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/ippToPsps/xmlschema/BatchManifest.xsd	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/ippToPsps/xmlschema/BatchManifest.xsd	(revision 37066)
@@ -42,4 +42,8 @@
     <xs:enumeration value="ST" />
     <xs:enumeration value="OB" />
+    <xs:enumeration value="DF" />
+    <xs:enumeration value="DO" />
+    <xs:enumeration value="FW" />
+    <xs:enumeration value="FO" />
    </xs:restriction>
   </xs:simpleType>
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/astrom/Makefile.am
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/astrom/Makefile.am	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/astrom/Makefile.am	(revision 37066)
@@ -11,5 +11,6 @@
 	pmAstrometryRefstars.c \
 	pmAstrometryWCS.c \
-	pmAstrometryVisual.c 
+	pmAstrometryVisual.c \
+	pmKHcorrect.c
 
 pkginclude_HEADERS = \
@@ -21,5 +22,6 @@
 	pmAstrometryRefstars.h \
 	pmAstrometryWCS.h \
-	pmAstrometryVisual.h
+	pmAstrometryVisual.h \
+	pmKHcorrect.h
 
 CLEANFILES = *~
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/astrom/pmAstrometryModel.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/astrom/pmAstrometryModel.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/astrom/pmAstrometryModel.c	(revision 37066)
@@ -39,4 +39,5 @@
 #include "pmFPAExtent.h"
 #include "pmFPAfileFitsIO.h"
+#include "pmConcepts.h"
 #include "pmAstrometryWCS.h"
 #include "pmAstrometryUtils.h"
@@ -452,28 +453,4 @@
 }
 
-int pmConceptsChipNumberFromName (pmFPA *fpa, char *name) {
-
-    for (int i = 0; i < fpa->chips->n; i++) {
-        pmChip *chip = fpa->chips->data[i];
-        if (!chip) continue;
-        char *thisone = psMetadataLookupStr (NULL, chip->concepts, "CHIP.NAME");
-        if (!thisone) continue;
-        if (!strcmp (name, thisone)) return (i);
-    }
-    return -1;
-}
-
-pmChip *pmConceptsChipFromName (pmFPA *fpa, char *name) {
-
-    for (int i = 0; i < fpa->chips->n; i++) {
-        pmChip *chip = fpa->chips->data[i];
-        if (!chip) continue;
-        char *thisone = psMetadataLookupStr (NULL, chip->concepts, "CHIP.NAME");
-        if (!thisone) continue;
-        if (!strcmp (name, thisone)) return (chip);
-    }
-    return NULL;
-}
-
 // first layer converts Chip to Focal Plane
 bool pmAstromModelReadChips (pmFPAfile *file) {
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/astrom/pmAstrometryModel.h
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/astrom/pmAstrometryModel.h	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/astrom/pmAstrometryModel.h	(revision 37066)
@@ -27,7 +27,4 @@
 bool pmAstromModelWriteChips (pmFPAfile *file);
 
-int pmConceptsChipNumberFromName (pmFPA *fpa, char *name);
-pmChip *pmConceptsChipFromName (pmFPA *fpa, char *name);
-
 bool pmAstromModelReadForView (const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
 bool pmAstromModelReadFPA (pmFPAfile *file);
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/astrom/pmAstrometryObjects.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/astrom/pmAstrometryObjects.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/astrom/pmAstrometryObjects.c	(revision 37066)
@@ -571,13 +571,21 @@
     psMemSetDeallocator (stats, (psFreeFunc)pmAstromStatsFree);
 
-    //    stats->center = {0, 0, 0, 0};
-    //    stats->offset = {0, 0, 0, 0};
-    stats->angle     = 0.0;
-    stats->scale     = 1.0;
-    stats->minMetric = 0.0;
-    stats->minVar    = 0.0;
-    stats->nMatch    = 0;
-    stats->nTest     = 0;
-    stats->nSigma    = 0;
+    stats->center.x    = 0;
+    stats->center.y    = 0;
+    stats->center.xErr = 0;
+    stats->center.yErr = 0;
+
+    stats->offset.x    = 0;
+    stats->offset.y    = 0;
+    stats->offset.xErr = 0;
+    stats->offset.yErr = 0;
+
+    stats->angle       = 0.0;
+    stats->scale       = 1.0;
+    stats->minMetric   = 0.0;
+    stats->minVar      = 0.0;
+    stats->nMatch      = 0;
+    stats->nTest       = 0;
+    stats->nSigma      = 0;
 
     return (stats);
@@ -914,6 +922,5 @@
     // fprintf (stderr, "sigma: nMatch: %d, nTest: %d, nTen: %d\n", stats->nMatch, stats->nTest, sort->data.U32[sort->n - 10]);
 
-
-  psFree (sort);
+    psFree (sort);
     psFree (listNP);
     psFree (gridNP);
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/astrom/pmAstrometryObjects.h
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/astrom/pmAstrometryObjects.h	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/astrom/pmAstrometryObjects.h	(revision 37066)
@@ -42,4 +42,5 @@
     float Color;			///< object color 
     float dMag;				///< error on object magnitude
+    float SBinst;			///< surface brightness, used for Koppenhoefer correction
 }
 pmAstromObj;
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/astrom/pmAstrometryVisual.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/astrom/pmAstrometryVisual.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/astrom/pmAstrometryVisual.c	(revision 37066)
@@ -946,5 +946,5 @@
     KapaSendLabel (kapa2, "X (FP)", KAPA_LABEL_XM);
     KapaSendLabel (kapa2, "Y (FP)", KAPA_LABEL_YM);
-    KapaSendLabel (kapa2, "pmAstromGridAngle residuals. Box: Correlation Peak.", KAPA_LABEL_XP);
+    KapaSendLabel (kapa2, "pmAstromGridAngle red: raw, black: ref.", KAPA_LABEL_XP);
 
     // plot the REF data.  (also calculate the plot ranges, accumulate the plot vectors)
@@ -966,13 +966,18 @@
     KapaSetLimits(kapa2, &graphdata);
 
-    psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEDIAN);
+    psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEDIAN | PS_STAT_MIN  | PS_STAT_MAX );
     psVectorStats (stats, zPlot, NULL, NULL, 0);
-    float zero = stats->sampleMedian + 3.0;
-    float range = 6.0;
-
+    float range = stats->max - stats->min;
+    range = PS_MAX (0.5, PS_MIN (6.0, range));
+    float zero = stats->sampleMedian + 0.25*range;
+
+    float maxZ = zPlot->data.F32[0], minZ = zPlot->data.F32[0];
     for (int i = 0; i < zPlot->n; i++) {
+	maxZ = PS_MAX (maxZ, zPlot->data.F32[i]);
+	minZ = PS_MIN (minZ, zPlot->data.F32[i]);
 	float value = (zero - zPlot->data.F32[i]) / range;
 	zPlot->data.F32[i] = PS_MAX(0.0, PS_MIN(1.0, value));
     }
+    fprintf (stderr, "ref mags: %f to %f (%f median)\n", minZ, maxZ, stats->sampleMedian);
 
     // the point size will be scaled from the z vector
@@ -998,11 +1003,18 @@
     psStatsInit(stats);
     psVectorStats (stats, zPlot, NULL, NULL, 0);
-    zero = stats->sampleMedian + 3.0;
-    range = 6.0;
-
+    range = stats->max - stats->min;
+    range = PS_MAX (0.5, PS_MIN (6.0, range));
+    zero = stats->sampleMedian + 0.25*range;
+    // zero = stats->sampleMedian + 1.0;
+    // range = 6.0;
+
+    maxZ = zPlot->data.F32[0], minZ = zPlot->data.F32[0];
     for (int i = 0; i < zPlot->n; i++) {
+	maxZ = PS_MAX (maxZ, zPlot->data.F32[i]);
+	minZ = PS_MIN (minZ, zPlot->data.F32[i]);
 	float value = (zero - zPlot->data.F32[i]) / range;
 	zPlot->data.F32[i] = PS_MAX(0.0, PS_MIN(1.0, value));
     }
+    fprintf (stderr, "raw mags: %f to %f (%f median)\n", minZ, maxZ, stats->sampleMedian);
 
     // the point size will be scaled from the z vector
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/astrom/pmAstrometryWCS.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/astrom/pmAstrometryWCS.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/astrom/pmAstrometryWCS.c	(revision 37066)
@@ -576,4 +576,11 @@
     psFree (region);
 
+    // XXX if the inversion fails, we probably do not have a valid transform anyway
+    if (!chip->fromFPA) {
+      psWarning ("failed to find a valid transformation");
+      psFree (chip->toFPA);
+      return false;
+    }
+
     // this can take a very long time...
     while (fpa->toSky->R < 0)
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/astrom/pmKHcorrect.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/astrom/pmKHcorrect.c	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/astrom/pmKHcorrect.c	(revision 37066)
@@ -0,0 +1,252 @@
+/** @file  pmKHcorrect.c
+ *  @brief Functions to read (and write?) Koppenhoefer correction file
+ *
+ *  The Koppenhoefer correction is needed for some chips of gpc1 before the camera voltages were adjusted 2011/05/11.
+ *  The correction is a modification of the X (and possibly Y) coordinate of a star which depends on the instrumental 
+ *  surface brightness, defined as -2.5 log_10 (DN) + 5.0 log_10 fwhm_maj [XXX be careful about the definition of fwhm_maj]
+ *
+ *  @ingroup AstroImage
+ *  @author EAM, IfA
+ *
+ *  Copyright 2014 Institute for Astronomy, University of Hawaii
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/******************************************************************************/
+/*  INCLUDE FILES                                                             */
+/******************************************************************************/
+#include <stdio.h>
+#include <strings.h>
+#include <string.h>
+#include <math.h>
+#include <assert.h>
+#include <unistd.h>   // for unlink
+#include <pslib.h>
+
+#include "pmConfig.h"
+#include "pmDetrendDB.h"
+#include "pmHDU.h"
+#include "pmFPA.h"
+#include "pmFPALevel.h"
+#include "pmFPAview.h"
+#include "pmFPAfile.h"
+#include "pmFPAExtent.h"
+#include "pmFPAfileFitsIO.h"
+#include "pmConcepts.h"
+#include "pmKHcorrect.h"
+
+static void KHcorrectDataFree (KHcorrectData *spline) {
+
+    if (!spline) return;
+
+    psFree (spline->xk);
+    psFree (spline->yk);
+    psFree (spline->y2);
+    return;
+}
+
+KHcorrectData *KHcorrectDataAlloc (int Nrow) {
+
+    // allocate xk[Nrow], etc
+
+    KHcorrectData *spline = (KHcorrectData *) psAlloc(sizeof(KHcorrectData));
+    psMemSetDeallocator(spline, (psFreeFunc) KHcorrectDataFree);
+
+    spline->N  = Nrow;
+    spline->xk = (float *) psAlloc(Nrow*sizeof(float));
+    spline->yk = (float *) psAlloc(Nrow*sizeof(float));
+    spline->y2 = (float *) psAlloc(Nrow*sizeof(float));
+
+    return spline;
+}
+
+// the KH correction is a function of the instrumental surface brightness, SBinst
+float KHcorrectApply (KHcorrectData *spline, float X) {
+
+    int N = spline->N;
+
+    // saturate correction at high and low ends
+    if (X < spline->xk[  0]) return spline->yk[  0];
+    if (X > spline->xk[N-1]) return spline->yk[N-1];
+
+    float *xk = spline->xk;
+    float *yk = spline->yk;
+    float *y2 = spline->y2;
+
+    /* find correct element in array (x must be sorted) */
+    int lo = 0;
+    int hi = N-1;
+    while (hi - lo > 1) {
+	int i = 0.5*(hi+lo);
+	if (xk[i] > X) {
+	    hi = i;
+	} else {
+	    lo = i;
+	}
+    }
+
+    /* error condition: duplicate abssisca */
+    float dx = xk[hi] - xk[lo];
+    if (dx == 0.0) {
+	return (0.0);
+    }
+
+    /* evaluate spline */
+    float a = (xk[hi] - X) / dx;
+    float b = (X - xk[lo]) / dx;
+
+    float value = a*yk[lo] + b*yk[hi] + ((a*a - 1.0)*a*y2[lo] + (b*b - 1.0)*b*y2[hi])*(dx*dx) / 6.0;
+    return (value);
+}
+
+/********************* CheckDataStatus functions *****************************/
+
+bool pmKHcorrectCheckDataStatusForView (const pmFPAview *view, pmFPAfile *file) {
+    psError(PS_ERR_IO, false, "Check Data Status not defined");
+    return false;
+}
+
+bool pmKHcorrectCheckDataStatusForFPA (const pmFPA *fpa) {
+    psError(PS_ERR_IO, false, "Check Data Status not defined");
+    return false;
+}
+
+bool pmKHcorrectCheckDataStatusForChip (const pmChip *chip) {
+    psError(PS_ERR_IO, false, "Check Data Status not defined");
+    return false;
+}
+
+/********************* Write Data functions *****************************/
+
+// NOTE : these are not exposed because I don't think we need them (we do not create KHcorrect
+// in psModules based tool, but in DVO.
+
+bool pmKHcorrectWriteFPA (pmFPAfile *file, const pmFPA *fpa);
+bool pmKHcorrectWriteForView (const pmFPAview *view, pmFPAfile *file, pmConfig *config)
+{
+    // write the full model in one pass: require the level to be FPA
+    if (view->chip != -1) {
+        psError(PS_ERR_IO, false, "Koppenhoefer Correction must be written at the FPA level");
+        return false;
+    }
+
+    pmFPA *fpa = pmFPAfileSuitableFPA(file, view, config, false); // Suitable FPA for writing
+
+    if (!pmKHcorrectWriteFPA(file, fpa)) {
+        psError(PS_ERR_IO, false, "Failed to write KH Correction for fpa");
+        psFree(fpa);
+        return false;
+    }
+
+    psFree(fpa);
+
+    return true;
+}
+
+// write out all chip-level KH Correction data for this FPA
+bool pmKHcorrectWriteFPA (pmFPAfile *file, const pmFPA *fpa)
+{
+    psError(PS_ERR_IO, false, "output for KH Correction is not defined");
+    return false;
+}
+
+/********************* Read Data functions *****************************/
+
+bool pmKHcorrectReadForView (const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
+    {
+        // read the full model in one pass: require the level to be FPA
+        if (view->chip != -1) {
+            psError(PS_ERR_IO, false, "KH Correction must be read at the FPA level");
+            return false;
+        }
+
+        if (!pmKHcorrectReadFPA (file)) {
+            psError(PS_ERR_IO, false, "Failed to read KH Correction for fpa");
+            return false;
+        }
+        return true;
+    }
+
+// read in all chip-level KH Correction data for this FPA
+bool pmKHcorrectReadFPA (pmFPAfile *file) {
+
+    if (!pmKHcorrectReadChips (file)) {
+        psError(PS_ERR_IO, false, "Failed to read KH Correction for chips");
+        return false;
+    }
+
+    return true;
+}
+
+// read the set of tables, one for each chip
+bool pmKHcorrectReadChips (pmFPAfile *file) {
+
+    bool haveData, status;
+
+    // loop over the extensions
+    // for each extension, use the extname (eg, XY01.DX.T0) to assign to a chip
+
+    // move to the start of the file
+    haveData = psFitsMoveExtNum (file->fits, 1, false);
+    if (!haveData) {
+        psError(PS_ERR_IO, false, "Failed to read even the first extension?");
+        return false;
+    }
+
+    while (haveData) {
+
+	// load the header
+	psMetadata *header = psFitsReadHeader(NULL, file->fits); // The FITS header
+	if (!header) psAbort("cannot read model header");
+
+	// load the full model in one shot
+	psArray *model = psFitsReadTable (file->fits);
+	if (!model) psAbort("cannot read model");
+	
+	// determine the chip:
+	char *extname = psMetadataLookupStr (&status, header, "EXTNAME");
+	psLogMsg ("psModules.astrom", 4, "read %ld rows from Koppenhoefer correction file, extname %s\n", model->n, extname);
+
+	// I expect to find a name of the form: chipName.dir.tset (eg, XY01.DX.T0)
+	// where chipName like 'XY01'
+	// dir = 'DX' 
+	// tset = 'T0'
+	psAssert (strlen(extname) == 10, "invalid extension %s", extname);
+	psAssert (extname[5] == 'D', "invalid extension %s", extname);
+	psAssert (extname[6] == 'X', "invalid extension %s", extname);
+	psAssert (extname[8] == 'T', "invalid extension %s", extname);
+	psAssert (extname[9] == '0', "invalid extension %s", extname);
+
+	char chipName[5];
+	strncpy (chipName, extname, 4);
+	chipName[4] = 0;
+
+	pmChip *chip = pmConceptsChipFromName (file->fpa, chipName);
+	if (!chip) psAbort ("invalid chip?");
+
+	KHcorrectData *spline = KHcorrectDataAlloc (model->n);
+
+	// parse the model entries
+	for (int i = 0; i < model->n; i++) {
+	    psMetadata *row = model->data[i];
+
+	    spline->xk[i] = psMetadataLookupF32(&status, row, "X_KNOT");
+	    spline->yk[i] = psMetadataLookupF32(&status, row, "Y_KNOT");
+	    spline->y2[i] = psMetadataLookupF32(&status, row, "DY2_DX");
+	}
+	psMetadataAddUnknown (chip->analysis, PS_LIST_TAIL, "KH.CORRECT", PS_META_REPLACE, "", spline);
+	psFree (spline);
+
+	psFree (model);
+	psFree (header);
+
+	// move to the next extension
+	haveData = psFitsMoveExtNum (file->fits, 1, true);
+    }
+
+    return true;
+}
+
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/astrom/pmKHcorrect.h
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/astrom/pmKHcorrect.h	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/astrom/pmKHcorrect.h	(revision 37066)
@@ -0,0 +1,35 @@
+/** @file  pmKHcorrect.h
+ *  @brief Functions to read (and write?) Koppenhoefer correction file
+ *
+ *  The Koppenhoefer correction is needed for some chips of gpc1 before the camera voltages were adjusted 2011/05/11.
+ *  The correction is a modification of the X (and possibly Y) coordinate of a star which depends on the instrumental 
+ *  surface brightness, defined as -2.5 log_10 (DN) + 5.0 log_10 fwhm_maj [XXX be careful about the definition of fwhm_maj]
+ *
+ *  @ingroup AstroImage
+ *  @author EAM, IfA
+ *
+ *  Copyright 2014 Institute for Astronomy, University of Hawaii
+ */
+
+#ifndef PM_KH_CORRECT_H
+#define PM_KH_CORRECT_H
+
+/// @addtogroup Astrometry
+/// @{
+
+typedef struct {
+    int N;
+    float *xk;
+    float *yk;
+    float *y2;
+} KHcorrectData;
+
+KHcorrectData *KHcorrectDataAlloc (int Nrow);
+float KHcorrectApply (KHcorrectData *spline, float X);
+
+bool pmKHcorrectReadForView (const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
+bool pmKHcorrectReadFPA (pmFPAfile *file);
+bool pmKHcorrectReadChips (pmFPAfile *file);
+
+/// @}
+#endif
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/camera/pmFPAfile.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/camera/pmFPAfile.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/camera/pmFPAfile.c	(revision 37066)
@@ -492,4 +492,7 @@
         return PM_FPA_FILE_CMF;
     }
+    if (!strcasecmp(type, "CFF"))     {
+        return PM_FPA_FILE_CFF;
+    }
     if (!strcasecmp(type, "WCS"))     {
         return PM_FPA_FILE_WCS;
@@ -528,7 +531,6 @@
       return PM_FPA_FILE_LINEARITY;
     }
-    // deprecate this?
     if (!strcasecmp(type, "ASTROM"))     {
-        return PM_FPA_FILE_ASTROM_MODEL;
+      return PM_FPA_FILE_ASTROM_MODEL;
     }
     if (!strcasecmp(type, "ASTROM.MODEL"))     {
@@ -537,4 +539,7 @@
     if (!strcasecmp(type, "ASTROM.REFSTARS"))     {
         return PM_FPA_FILE_ASTROM_REFSTARS;
+    }
+    if (!strcasecmp(type, "KH.CORRECT"))     {
+        return PM_FPA_FILE_KH_CORRECT;
     }
     if (!strcasecmp(type, "SUBKERNEL"))     {
@@ -562,4 +567,6 @@
       case PM_FPA_FILE_CMF:
         return ("CMF");
+      case PM_FPA_FILE_CFF:
+        return ("CFF");
       case PM_FPA_FILE_WCS:
         return ("WCS");
@@ -588,4 +595,6 @@
       case PM_FPA_FILE_ASTROM_REFSTARS:
         return ("ASTROM.REFSTARS");
+      case PM_FPA_FILE_KH_CORRECT:
+        return ("KH.CORRECT");
       case PM_FPA_FILE_SUBKERNEL:
         return ("SUBKERNEL");
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/camera/pmFPAfile.h
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/camera/pmFPAfile.h	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/camera/pmFPAfile.h	(revision 37066)
@@ -34,4 +34,5 @@
     PM_FPA_FILE_CMP,
     PM_FPA_FILE_CMF,
+    PM_FPA_FILE_CFF,
     PM_FPA_FILE_WCS,
     PM_FPA_FILE_RAW,
@@ -47,4 +48,5 @@
     PM_FPA_FILE_ASTROM_MODEL,
     PM_FPA_FILE_ASTROM_REFSTARS,
+    PM_FPA_FILE_KH_CORRECT,
     PM_FPA_FILE_SUBKERNEL,
     PM_FPA_FILE_SRCTEXT,
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/camera/pmFPAfileDefine.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/camera/pmFPAfileDefine.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/camera/pmFPAfileDefine.c	(revision 37066)
@@ -103,7 +103,13 @@
 
     type = psMetadataLookupStr(&status, data, "FILE.TYPE");
+    if (!type) {
+        psError(PM_ERR_CONFIG, true, "FILE.TYPE is not defined for %s\n", name);
+        psFree(file);
+        return NULL;
+    }
+
     file->type = pmFPAfileTypeFromString(type);
     if (file->type == PM_FPA_FILE_NONE) {
-        psError(PM_ERR_CONFIG, true, "FILE.TYPE is not defined for %s\n", name);
+        psError(PM_ERR_CONFIG, true, "FILE.TYPE %s is not registered in pmFPAfile.c:pmFPAfileTypeFromString\n", type);
         psFree(file);
         return NULL;
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/camera/pmFPAfileFitsIO.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/camera/pmFPAfileFitsIO.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/camera/pmFPAfileFitsIO.c	(revision 37066)
@@ -150,5 +150,7 @@
       case PM_FPA_FILE_PSF:
       case PM_FPA_FILE_ASTROM_MODEL:
-      case PM_FPA_FILE_ASTROM_REFSTARS: {
+      case PM_FPA_FILE_ASTROM_REFSTARS: 
+      case PM_FPA_FILE_KH_CORRECT:
+	{
           pmHDU *hdu = pmFPAviewThisHDU(view, fpa);
           if (hdu) {
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/camera/pmFPAfileIO.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/camera/pmFPAfileIO.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/camera/pmFPAfileIO.c	(revision 37066)
@@ -34,4 +34,5 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmSourceMasks.h"
@@ -39,4 +40,5 @@
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceFitModel.h"
@@ -47,4 +49,5 @@
 #include "pmPSF_IO.h"
 
+#include "pmKHcorrect.h"
 #include "pmAstrometryModel.h"
 #include "pmAstrometryRefstars.h"
@@ -222,4 +225,5 @@
       case PM_FPA_FILE_CMP:
       case PM_FPA_FILE_CMF:
+      case PM_FPA_FILE_CFF:
       case PM_FPA_FILE_WCS:
       case PM_FPA_FILE_SRCTEXT:
@@ -231,4 +235,7 @@
       case PM_FPA_FILE_ASTROM_MODEL:
         status = pmAstromModelReadForView (view, file, config);
+        break;
+      case PM_FPA_FILE_KH_CORRECT:
+        status = pmKHcorrectReadForView (view, file, config);
         break;
       case PM_FPA_FILE_EXPNUM:
@@ -317,8 +324,10 @@
       case PM_FPA_FILE_CMP:
       case PM_FPA_FILE_CMF:
+      case PM_FPA_FILE_CFF:
       case PM_FPA_FILE_WCS:
       case PM_FPA_FILE_PSF:
       case PM_FPA_FILE_ASTROM_MODEL:
       case PM_FPA_FILE_ASTROM_REFSTARS:
+      case PM_FPA_FILE_KH_CORRECT:
       case PM_FPA_FILE_JPEG:
       case PM_FPA_FILE_KAPA:
@@ -405,4 +414,8 @@
       }
     }
+    if (file->type == PM_FPA_FILE_KH_CORRECT) {
+      psTrace("psModules.camera", 6, "skip write for %s, no write function defined", file->name);
+      return true;
+    }
 
     // open the file if not yet opened
@@ -483,4 +496,5 @@
       case PM_FPA_FILE_CMP:
       case PM_FPA_FILE_CMF:
+      case PM_FPA_FILE_CFF:
         status = pmFPAviewWriteObjects (view, file, config);
         break;
@@ -496,4 +510,8 @@
       case PM_FPA_FILE_ASTROM_REFSTARS:
         status = pmAstromRefstarsWriteForView (view, file, config);
+        break;
+
+      case PM_FPA_FILE_KH_CORRECT:
+        psError(PS_ERR_IO, true, "cannot write type KH.CORRECT (%s)", file->name);
         break;
 
@@ -567,8 +585,10 @@
       case PM_FPA_FILE_PATTERN:
       case PM_FPA_FILE_CMF:
+      case PM_FPA_FILE_CFF:
       case PM_FPA_FILE_WCS:
       case PM_FPA_FILE_PSF:
       case PM_FPA_FILE_ASTROM_MODEL:
       case PM_FPA_FILE_ASTROM_REFSTARS:
+      case PM_FPA_FILE_KH_CORRECT:
       case PM_FPA_FILE_LINEARITY:
       case PM_FPA_FILE_EXPNUM:
@@ -643,8 +663,10 @@
       case PM_FPA_FILE_CMP:
       case PM_FPA_FILE_CMF:
+      case PM_FPA_FILE_CFF:
       case PM_FPA_FILE_WCS:
       case PM_FPA_FILE_PSF:
       case PM_FPA_FILE_ASTROM_MODEL:
       case PM_FPA_FILE_ASTROM_REFSTARS:
+      case PM_FPA_FILE_KH_CORRECT:
       case PM_FPA_FILE_EXPNUM:
         psTrace ("psModules.camera", 6, "NOT freeing %s (%s) : save for further analysis\n", file->filename, file->name);
@@ -804,8 +826,10 @@
       case PM_FPA_FILE_PATTERN:
       case PM_FPA_FILE_CMF:
+      case PM_FPA_FILE_CFF:
       case PM_FPA_FILE_WCS:
       case PM_FPA_FILE_PSF:
       case PM_FPA_FILE_ASTROM_MODEL:
       case PM_FPA_FILE_ASTROM_REFSTARS:
+      case PM_FPA_FILE_KH_CORRECT:
       case PM_FPA_FILE_LINEARITY:
       case PM_FPA_FILE_EXPNUM:
@@ -1011,4 +1035,5 @@
       case PM_FPA_FILE_EXPNUM:
       case PM_FPA_FILE_ASTROM_MODEL:
+      case PM_FPA_FILE_KH_CORRECT:
       case PM_FPA_FILE_SX:
       case PM_FPA_FILE_RAW:
@@ -1016,4 +1041,5 @@
       case PM_FPA_FILE_CMP:
       case PM_FPA_FILE_WCS:
+      case PM_FPA_FILE_CFF:
       case PM_FPA_FILE_JPEG:
       case PM_FPA_FILE_KAPA:
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/camera/pmReadoutFake.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/camera/pmReadoutFake.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/camera/pmReadoutFake.c	(revision 37066)
@@ -20,11 +20,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceFitModel.h"
@@ -54,5 +55,5 @@
 
     psF32 *params = model->params->data.F32; // Model parameters
-    psEllipseAxes axes = pmPSF_ModelToAxes(params, model->type); // Ellipse axes
+    psEllipseAxes axes = pmPSF_ModelToAxes(params, model->class->useReff); // Ellipse axes
     // Curiously, the minor axis can be larger than the major axis, so need to check.
     if (axes.major >= axes.minor) {
@@ -61,5 +62,5 @@
         axes.major = axes.minor;
     }
-    return pmPSF_AxesToModel(params, axes, model->type);
+    return pmPSF_AxesToModel(params, axes, model->class->useReff);
 }
 
@@ -121,5 +122,5 @@
             }
 
-            flux /= normModel->modelFlux(normModel->params);
+            flux /= normModel->class->modelFlux(normModel->params);
             psFree(normModel);
         }
@@ -163,5 +164,5 @@
         float fakeRadius = 1.0;         // Radius of fake source
         if (isfinite(minFlux)) {
-            fakeRadius = PS_MAX(fakeRadius, fakeModel->modelRadius(fakeModel->params, minFlux));
+            fakeRadius = PS_MAX(fakeRadius, fakeModel->class->modelRadius(fakeModel->params, minFlux));
         }
         if (radius > 0) {
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/concepts/pmConcepts.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/concepts/pmConcepts.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/concepts/pmConcepts.c	(revision 37066)
@@ -578,2 +578,26 @@
 }
 
+int pmConceptsChipNumberFromName (pmFPA *fpa, char *name) {
+
+    for (int i = 0; i < fpa->chips->n; i++) {
+        pmChip *chip = fpa->chips->data[i];
+        if (!chip) continue;
+        char *thisone = psMetadataLookupStr (NULL, chip->concepts, "CHIP.NAME");
+        if (!thisone) continue;
+        if (!strcmp (name, thisone)) return (i);
+    }
+    return -1;
+}
+
+pmChip *pmConceptsChipFromName (pmFPA *fpa, char *name) {
+
+    for (int i = 0; i < fpa->chips->n; i++) {
+        pmChip *chip = fpa->chips->data[i];
+        if (!chip) continue;
+        char *thisone = psMetadataLookupStr (NULL, chip->concepts, "CHIP.NAME");
+        if (!thisone) continue;
+        if (!strcmp (name, thisone)) return (chip);
+    }
+    return NULL;
+}
+
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/concepts/pmConcepts.h
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/concepts/pmConcepts.h	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/concepts/pmConcepts.h	(revision 37066)
@@ -161,4 +161,8 @@
     );
 
+// some utility functions:
+int pmConceptsChipNumberFromName (pmFPA *fpa, char *name);
+pmChip *pmConceptsChipFromName (pmFPA *fpa, char *name);
+
 /// @}
 #endif
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/config/pmConfig.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/config/pmConfig.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/config/pmConfig.c	(revision 37066)
@@ -965,4 +965,42 @@
                                   "Original replaced by -R option", newRule);
         }
+        psFree(camerasIter);
+    }
+
+    // Look for command-line options for files to replace
+    while ((argNum = psArgumentGet(*argc, argv, "-photcode-rule")) > 0) {
+        psArgumentRemove(argNum, argc, argv);
+        if (argNum >= *argc) {
+            psError(PM_ERR_CONFIG, true,
+                    "-photcode-rule provided without new rule.");
+            psFree(config);
+            return NULL;
+        }
+
+        psString newrule = psStringCopy(argv[argNum]); // The filerule, to be modified
+        psArgumentRemove(argNum, argc, argv);
+
+        psMetadata *cameras = psMetadataLookupMetadata(NULL, config->system, "CAMERAS"); // List of cameras
+        if (!cameras) {
+            psError(PM_ERR_CONFIG, false, "Unable to find CAMERAS in the site configuration.\n");
+            return false;
+        }
+
+        psMetadataIterator *camerasIter = psMetadataIteratorAlloc(cameras, PS_LIST_HEAD, NULL); // Iterator
+        psMetadataItem *cameraItem;     // Item from iteration
+        while ((cameraItem = psMetadataGetAndIncrement(camerasIter))) {
+            // Silently ignore problems --- they will be caught later, because if the user wants the nominated
+            // file and it's not available for that camera, then they will know.
+
+            if (cameraItem->type != PS_DATA_METADATA) {
+                psTrace("psModules.config", 2,
+                        "Entry %s in CAMERAS is not of type METADATA --- ignored.", cameraItem->name);
+                continue;
+            }
+            psMetadata *camera = cameraItem->data.md; // Camera configuration
+
+	    psMetadataAddStr (camera, PS_LIST_TAIL, "PHOTCODE.RULE", PS_META_REPLACE, "original replaced by -photcode-rule option", newrule);
+        }
+	psFree(newrule);
         psFree(camerasIter);
     }
@@ -1860,5 +1898,5 @@
     }
 
-    return psMetadataLookupMetadata(NULL, filerules, realname);
+    return psMetadataLookupMetadata(&mdok, filerules, realname);
 }
 
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/detrend/pmDetrendDB.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/detrend/pmDetrendDB.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/detrend/pmDetrendDB.c	(revision 37066)
@@ -111,4 +111,5 @@
 	DETREND_STRING_CASE(LINEARITY);
 	DETREND_STRING_CASE(AUXMASK);
+	DETREND_STRING_CASE(KH_CORRECT);
     default:
         return NULL;
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/detrend/pmDetrendDB.h
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/detrend/pmDetrendDB.h	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/detrend/pmDetrendDB.h	(revision 37066)
@@ -40,4 +40,5 @@
     PM_DETREND_TYPE_LINEARITY,
     PM_DETREND_TYPE_AUXMASK,
+    PM_DETREND_TYPE_KH_CORRECT,
 } pmDetrendType;
 
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/detrend/pmPattern.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/detrend/pmPattern.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/detrend/pmPattern.c	(revision 37066)
@@ -1222,6 +1222,8 @@
     }
     double max_XX = 0;
+#if (PS_TRACE_ON)
     double solution_V = 0;
     int i_peak = -1;
+#endif
     for (int i = 0; i < numChips + 4; i++) { // If any cells have no value of themself, set the matrix to 1.0.
       if (XX->data.F64[i][i] == 0.0) {
@@ -1230,6 +1232,8 @@
       if (XX->data.F64[i][i] > max_XX) {
 	max_XX = XX->data.F64[i][i];
+#if (PS_TRACE_ON)
 	solution_V = solution->data.F64[i];
 	i_peak = i;
+#endif
       }
     }
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/extras/pmThreadTools.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/extras/pmThreadTools.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/extras/pmThreadTools.c	(revision 37066)
@@ -29,7 +29,7 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
@@ -37,4 +37,5 @@
 #include "pmSourcePhotometry.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/extras/pmVisual.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/extras/pmVisual.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/extras/pmVisual.c	(revision 37066)
@@ -22,32 +22,5 @@
 bool pmSourceVisualClose(void);
 
-// #include "pmHDU.h"
-// #include "pmFPA.h"
-// #include "pmFPAfile.h"
-// #include "pmAstrometryObjects.h"
-// #include "pmSubtractionStamps.h"
-// #include "pmTrend2D.h"
-// #include "pmResiduals.h"
-// #include "pmGrowthCurve.h"
-// #include "pmSpan.h"
-// #include "pmFootprintSpans.h"
-// #include "pmFootprint.h"
-// #include "pmPeaks.h"
-// #include "pmMoments.h"
-// #include "pmModelFuncs.h"
-// #include "pmModel.h"
-// #include "pmSourceMasks.h"
-// #include "pmSourceExtendedPars.h"
-// #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
-// #include "pmSource.h"
-// #include "pmSourceFitModel.h"
-// #include "pmPSF.h"
-// #include "pmPSFtry.h"
-// #include "pmFPAExtent.h"
-// #include "pmAstrometryVisual.h"
-// #include "pmSubtractionVisual.h"
-// #include "pmStackVisual.h"
-// #include "pmSourceVisual.h"
 
 # if (HAVE_KAPA)
@@ -160,4 +133,77 @@
 }
 
+
+// ask the user to continue or not.  give up after 2 seconds.
+bool pmVisualAskUserOrDump(bool *plotFlag, bool *dumpData)
+{
+    struct timeval timeout;
+    fd_set fdSet;
+    int status;
+
+    if (dumpData) *dumpData = false;
+
+    char key[10];
+    if (plotFlag && dumpData) {
+	fprintf (stderr, "[p]ause? [c]ontinue? [s]kip the rest of these plots? [d]ump the data? [a]bort all visual plots? (c) ");
+    } 
+    if (plotFlag && !dumpData) {
+	fprintf (stderr, "[p]ause? [c]ontinue? [s]kip the rest of these plots? [a]bort all visual plots? (c) ");
+    } 
+    if (!plotFlag && dumpData) {
+	fprintf (stderr, "[p]ause? [c]ontinue? [d]ump the data? [a]bort all visual plots? (c) ");
+    } 
+    if (!plotFlag && !dumpData) {
+	fprintf (stderr, "[p]ause? [c]ontinue? [a]bort all visual plots? (c) ");
+    }
+
+    /* Wait up to 1.0 second for a response, then continue */
+    timeout.tv_sec = 10;
+    timeout.tv_usec = 0;
+
+    FD_ZERO (&fdSet);
+    FD_SET (STDIN_FILENO, &fdSet);
+
+    status = select (1, &fdSet, NULL, NULL, &timeout);
+    if (status <= 0) {
+	fprintf (stderr, "\n");
+	return true; // if no data, give up
+    }
+
+    while (true) {
+	if (!fgets(key, 8, stdin)) {
+	    psWarning("Unable to read option");
+	}
+	switch (key[0]) {
+	  case 's':
+	    if (plotFlag) *plotFlag = false;
+	    return true;
+	  case 'd':
+	    if (dumpData) *dumpData = true;
+	    return true;
+	  case 'a':
+	    isVisual = false;
+	    return true;
+	  case 'c':
+	  case '\n':
+	    return true;
+	  default:
+	    break;
+	}
+	
+	if (plotFlag && dumpData) {
+	  fprintf (stderr, "[p]ause? [c]ontinue? [s]kip the rest of these plots? [d]ump the data? [a]bort all visual plots? (c) ");
+	} 
+	if (plotFlag && !dumpData) {
+	  fprintf (stderr, "[p]ause? [c]ontinue? [s]kip the rest of these plots? [a]bort all visual plots? (c) ");
+	} 
+	if (!plotFlag && dumpData) {
+	  fprintf (stderr, "[p]ause? [c]ontinue? [d]ump the data? [a]bort all visual plots? (c) ");
+	} 
+	if (!plotFlag && !dumpData) {
+	  fprintf (stderr, "[p]ause? [c]ontinue? [a]bort all visual plots? (c) ");
+	}
+    }
+    return true;
+}
 
 bool pmVisualImStats(psImage *image, double *mean, double *stdev, double *min, double *max) {
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/extras/pmVisual.h
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/extras/pmVisual.h	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/extras/pmVisual.h	(revision 37066)
@@ -52,4 +52,12 @@
  */
 bool pmVisualAskUser(bool *plotFlag);
+
+
+/** Ask the user how to proceed.
+ * At the user's request, this will disable diagnostic plotting.
+ * @param plotFlag, set to false if this plot should be disabled in the future
+ * @param dumpData, set to true if user requests a data dump
+ */
+bool pmVisualAskUserOrDump(bool *plotFlag, bool *dumpData);
 
 
@@ -138,4 +146,5 @@
 bool pmVisualInitGraph (int kapa, void *section, void *graphdata);
 bool pmVisualAskUser(bool *plotFlag);
+bool pmVisualAskUserOrDump(bool *plotFlag, bool *dumpData);
 bool pmVisualScaleImage(int kapaFD, psImage *inImage,
                         const char *name, int channel, bool clip);
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/imcombine/pmPSFEnvelope.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/imcombine/pmPSFEnvelope.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/imcombine/pmPSFEnvelope.c	(revision 37066)
@@ -20,11 +20,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceFitModel.h"
@@ -167,9 +168,9 @@
                         continue;
                     }
-                    model->modelSetLimits(PM_MODEL_LIMITS_MODERATE);
+                    model->class->modelSetLimits(PM_MODEL_LIMITS_MODERATE);
                     bool limits = true; // Model within limits?
                     for (int j = 0; j < model->params->n && limits; j++) {
-                        if (!model->modelLimits(PS_MINIMIZE_PARAM_MIN, j, model->params->data.F32, NULL) ||
-                            !model->modelLimits(PS_MINIMIZE_PARAM_MAX, j, model->params->data.F32, NULL)) {
+                        if (!model->class->modelLimits(PS_MINIMIZE_PARAM_MIN, j, model->params->data.F32, NULL) ||
+                            !model->class->modelLimits(PS_MINIMIZE_PARAM_MAX, j, model->params->data.F32, NULL)) {
                             limits = false;
                         }
@@ -245,5 +246,5 @@
                 continue;
             }
-            float srcRadius = model->modelRadius(model->params, PS_SQR(VARIANCE_VAL)); // Radius for source
+            float srcRadius = model->class->modelRadius(model->params, PS_SQR(VARIANCE_VAL)); // Radius for source
             psFree(model);
             if (srcRadius == 0) {
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/imcombine/pmStack.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/imcombine/pmStack.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/imcombine/pmStack.c	(revision 37066)
@@ -43,7 +43,11 @@
 // #define TEST_X 972
 // #define TEST_Y 3213
-#define TEST_X 3289
-#define TEST_Y 4810
-#define TEST_RADIUS 0.5                 // Radius to examine
+//#define TEST_X 3289
+//#define TEST_Y 4810
+//#define TEST_RADIUS 0.5                 // Radius to examine
+//MEH -- streak-like junk md04s065i
+#define TEST_X 1129 
+#define TEST_Y 4256
+#define TEST_RADIUS 2.0                 // Radius to examine
 # endif
 
@@ -108,5 +112,5 @@
 
 // KMM functions to do bimodality rejection of pixels
-float gaussian(float x, float m, float s) {
+double gaussian(float x, float m, float s) {
   return(pow(s * sqrt(2 * M_PI),-1) * exp(-0.5 * pow( (x - m) / s, 2)));
 }
@@ -116,5 +120,6 @@
 			 float *mU, float *sU,
 			 float *pi1, float *m1, float *s1,
-			 float *pi2, float *m2, float *s2) {
+			 float *pi2, float *m2, float *s2,
+                         int xyrdebug) {
   assert(values);
   assert(values->type.type == PS_TYPE_F32);
@@ -151,4 +156,10 @@
   }
 
+  if (xyrdebug == 1) { 
+      fprintf(stderr,"KMM uni: %d %f %d (%f %f)\n", 
+              xyrdebug,logL_unimodal,discrepant_index, 
+              *mU,*sU); 
+  } 
+
   // Do EM loop
   float dL = 0;
@@ -186,5 +197,6 @@
   *pi2 = 0.5;
 
-  float g1,g2,norm;
+  //MEH -- need to be double to help avoid 0 in norm
+  double g1,g2,norm;
   float w1,w2;
 
@@ -203,4 +215,12 @@
 /* 	      *m2,*s2,*pi2); */
 /*     } */
+
+    if (xyrdebug == 1) { 
+        fprintf(stderr,"KMM EM iter: %d %f %f %f %f (%f %f %e) (%f %f %e)\n", 
+                *iter,logL_unimodal,logL_bimodal,oldL,dL, 
+                *m1,*s1,*pi1, 
+                *m2,*s2,*pi2); 
+    } 
+
     // Expectation/P-stage
     for (i = 0; i < values->n; i++) { // Calculate probabilities for each mode
@@ -208,6 +228,18 @@
       g2 = gaussian(values->data.F32[i],*m2,*s2);
       norm = (*pi1 * g1 + *pi2 * g2);
-      P1->data.F32[i] = (*pi1 * g1) / norm;
-      P2->data.F32[i] = (*pi2 * g2) / norm;
+      //MEH -- must protect denom from norm=0
+      if (norm > 0) {
+	  P1->data.F32[i] = (*pi1 * g1) / norm;
+	  P2->data.F32[i] = (*pi2 * g2) / norm;
+      } else {
+	  P1->data.F32[i] = 0.0;
+	  P2->data.F32[i] = 0.0;
+      }	 
+ 
+      if (xyrdebug == 1) {
+          fprintf(stderr,"KMM EM-P loop: %d %d %le %le %le\n",
+                         *iter,i,norm,g1,g2);
+      }
+
     }
     // Maximization/M-stage
@@ -231,4 +263,10 @@
       w1 += P1->data.F32[i];
       w2 += P2->data.F32[i];
+
+      if (xyrdebug == 1) {
+          fprintf(stderr,"KMM EM-M loop: %d %d (%f %f %f %e) (%f %f %f %e)\n",
+                         *iter,i,*m1,values->data.F32[i],w1,P1->data.F32[i],*m2,values->data.F32[i],w2,P2->data.F32[i]);
+      }
+
     }
     *m1 /= w1;
@@ -250,10 +288,18 @@
       *pi2 = 0.0;
     }
-    if (*s1 == 0) { // sigma may not be zero
-      *s1 = KMM_SMALL_NUMBER * *m1;
-    }
-    if (*s2 == 0) { // sigma may not be zero
-      *s2 = KMM_SMALL_NUMBER * *m2;
-    }
+    if (*s1 == 0) { // sigma may not be zero -- MEH -- nor <0 and need additive offset if m~0
+      *s1 = fabsf(KMM_SMALL_NUMBER * *m1) + KMM_SMALL_NUMBER;
+    }
+    if (*s2 == 0) { // sigma may not be zero 
+      *s2 = fabsf(KMM_SMALL_NUMBER * *m2) + KMM_SMALL_NUMBER;
+    }
+
+    if (xyrdebug == 1) { 
+        fprintf(stderr,"KMM EM end: %d %f %f %f %f (%f %e %e %f) (%f %e %e %f)\n", 
+                *iter,logL_unimodal,logL_bimodal,oldL,dL, 
+                *m1,*s1,*pi1,w1, 
+                *m2,*s2,*pi2,w2); 
+    } 
+
   } // End EM phase
 
@@ -267,9 +313,15 @@
     *Punimodal = 1.0;
   }
+
+  if (xyrdebug == 1) { 
+      fprintf(stderr,"KMM calc Puni: %d %f %d %f\n", 
+              xyrdebug,lambda,df,*Punimodal); 
+  } 
+
   psFree(P1);
   psFree(P2);
 }
 
-static void KMMFindPopular(const psVector *values, float *Punimodal, float *mean, float *sigma, float *pi) {
+static void KMMFindPopular(const psVector *values, float *Punimodal, float *mean, float *sigma, float *pi, int xyrdebug) {
   float KMM_MINIMUM_PVALUE = 0.05; // Should be an option.
   float mU,sU;
@@ -283,5 +335,5 @@
 	       &mU,&sU,
 	       &pi1,&m1,&s1,
-	       &pi2,&m2,&s2);
+	       &pi2,&m2,&s2,xyrdebug);
 /*   fprintf(stdout,"%g %g : %g %g %g : %g %g %g : %g %d\t", */
 /* 	  mU,sU, */
@@ -783,4 +835,5 @@
                           psImageMaskType goodMask, // Value for good pixels
                           bool safe,           // Safe combination?
+			  int nminpix,         // Minimum number of input per pixel
                           float invTotalWeight    // Inverse of total weight for all inputs
                           )
@@ -802,5 +855,11 @@
     CHECKPIX(x, y, "bad vs good : %x %x %x\n", maskValue, badMask, blankMask);
 
-    switch (num) {
+    //MEH -- hackish adding of lower limit for input per pixel 
+    int numN = num;
+    if (num < nminpix) {
+        CHECKPIX(x, y, "Nmin (%d) inputs (%d) to combine, pixel %d,%d is manually set bad\n", nminpix, numN, x, y);
+        numN = 0;
+    }
+    switch (numN) {
       case 0: {
           // Nothing to combine: it's bad
@@ -898,4 +957,6 @@
     psVector *pixelSuspects = buffer->suspects; // Is the pixel suspect?
     psVector *pixelLimits = buffer->limits; // Is the pixel suspect?
+    //MEH -- adding a debug option for TESTING xyr position but could be better..
+    int xyrdebug = 0;
 
     // KMM values;
@@ -917,5 +978,10 @@
 	// This should probably be an option
 	if (useKMM) {
-	  KMMFindPopular(pixelData,&Punimodal,&KMMmean,&KMMsigma,&KMMpi);
+#ifdef TESTING
+            if (PS_SQR(x - TEST_X) + PS_SQR(y - TEST_Y) <= PS_SQR(TEST_RADIUS)) {
+                xyrdebug = 1;
+            }
+# endif
+	  KMMFindPopular(pixelData,&Punimodal,&KMMmean,&KMMsigma,&KMMpi,xyrdebug);
 	  CHECKPIX(x,y,"KMM Popularity Contest: (%d,%d) Puni: %g Mean: %f Sigma %f Pi: %f\n",
 		   x,y,Punimodal,KMMmean,KMMsigma,KMMpi);
@@ -1459,4 +1525,5 @@
     bool useVariance, 
     bool safe, 
+    int nminpix,
     bool rejection)
 {
@@ -1633,5 +1700,5 @@
 	    psImageMaskType goodMask = 0; // OR of mask bits in all good input pixels
             combineExtract(&num, &suspect, &badMask, &goodMask, buffer, combinedImage, combinedMask, combinedVariance, input, weights, exps, addVariance, reject, x, y, badMaskBits, suspectMaskBits);
-            combinePixels(combinedImage, combinedMask, combinedVariance, exp, expnum, expweight, num, buffer, x, y, blankMaskBits, badMask, goodMask, safe, totalExpWeight);
+            combinePixels(combinedImage, combinedMask, combinedVariance, exp, expnum, expweight, num, buffer, x, y, blankMaskBits, badMask, goodMask, safe, nminpix, totalExpWeight);
 
             if (iter > 0) {
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/imcombine/pmStack.h
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/imcombine/pmStack.h	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/imcombine/pmStack.h	(revision 37066)
@@ -61,4 +61,5 @@
                     bool useVariance,   ///< Use variance values for rejection?
                     bool safe,          ///< Play safe with small numbers of input pixels (mask if N <= 2)?
+		    int nminpix,        ///< Minimum number input per pixel to combine
                     bool rejectInspect  ///< Reject pixels instead of marking them for inspection?
     );
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/imcombine/pmSubtraction.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/imcombine/pmSubtraction.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/imcombine/pmSubtraction.c	(revision 37066)
@@ -37,4 +37,5 @@
 #define USE_KERNEL_ERR                  // Use kernel error image?
 #define NUM_COVAR_POS 5                 // Number of positions for covariance calculation
+//MEH -- this is causing diffim fault 5 -- seems not as robust
 #define USE_LOGFIT_REJECT
 
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/imcombine/pmSubtractionSimple.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/imcombine/pmSubtractionSimple.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/imcombine/pmSubtractionSimple.c	(revision 37066)
@@ -34,4 +34,5 @@
 #include "pmSourceSatstar.h"
 
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/imcombine/pmSubtractionStamps.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/imcombine/pmSubtractionStamps.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/imcombine/pmSubtractionStamps.c	(revision 37066)
@@ -21,4 +21,5 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmSourceMasks.h"
@@ -26,4 +27,5 @@
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/Makefile.am
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/Makefile.am	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/Makefile.am	(revision 37066)
@@ -20,4 +20,5 @@
 	pmModelClass.c \
 	pmModelUtils.c \
+	pmModel_CentralPixel.c \
 	pmSource.c \
 	pmPhotObj.c \
@@ -39,4 +40,5 @@
 	pmSourceIO_SX.c \
 	pmSourceIO_CMP.c \
+	pmSourceIO_CFF.c \
 	pmSourceIO_SMPDATA.c \
 	pmSourceIO_PS1_DEV_0.c \
@@ -47,9 +49,12 @@
 	pmSourceIO_CMF_PS1_V3.c \
 	pmSourceIO_CMF_PS1_V4.c \
+	pmSourceIO_CMF_PS1_V5.c \
 	pmSourceIO_CMF_PS1_SV1.c \
 	pmSourceIO_CMF_PS1_SV2.c \
+	pmSourceIO_CMF_PS1_SV3.c \
 	pmSourceIO_CMF_PS1_DV1.c \
 	pmSourceIO_CMF_PS1_DV2.c \
 	pmSourceIO_CMF_PS1_DV3.c \
+	pmSourceIO_CMF_PS1_DV4.c \
 	pmSourceIO_MatchedRefs.c \
 	pmSourcePlots.c \
@@ -74,4 +79,5 @@
 	pmGrowthCurve.c \
 	pmSourceMatch.c \
+	pmSourceLensing.c \
 	pmDetEff.c \
 	pmSourceGroups.c \
@@ -97,4 +103,5 @@
 	pmModelClass.h \
 	pmModelUtils.h \
+	pmModel_CentralPixel.h \
 	pmSource.h \
 	pmPhotObj.h \
@@ -110,5 +117,5 @@
 	pmSourceOutputs.h \
 	pmSourceIO.h \
-	pmSourceSatstar.h \ 
+	pmSourceSatstar.h \
 	pmSourcePlots.h \
 	pmSourceVisual.h \
@@ -122,4 +129,5 @@
 	pmGrowthCurveGenerate.h \
 	pmSourceMatch.h \
+	pmSourceLensing.h \
 	pmDetEff.h \
 	pmSourceGroups.h \
@@ -142,9 +150,12 @@
 pmSourceIO_CMF_PS1_V3.c \
 pmSourceIO_CMF_PS1_V4.c \
+pmSourceIO_CMF_PS1_V5.c \
 pmSourceIO_CMF_PS1_DV1.c \
 pmSourceIO_CMF_PS1_DV2.c \
 pmSourceIO_CMF_PS1_DV3.c \
+pmSourceIO_CMF_PS1_DV4.c \
 pmSourceIO_CMF_PS1_SV1.c \
-pmSourceIO_CMF_PS1_SV2.c
+pmSourceIO_CMF_PS1_SV2.c \
+pmSourceIO_CMF_PS1_SV3.c
 
 pmSourceIO_CMF_PS1_V1.c : pmSourceIO_CMF.c.in mksource.pl
@@ -160,4 +171,7 @@
 	mksource.pl pmSourceIO_CMF.c.in PS1_V4 pmSourceIO_CMF_PS1_V4.c
 
+pmSourceIO_CMF_PS1_V5.c : pmSourceIO_CMF.c.in mksource.pl
+	mksource.pl pmSourceIO_CMF.c.in PS1_V5 pmSourceIO_CMF_PS1_V5.c
+
 pmSourceIO_CMF_PS1_DV1.c : pmSourceIO_CMF.c.in mksource.pl
 	mksource.pl pmSourceIO_CMF.c.in PS1_DV1 pmSourceIO_CMF_PS1_DV1.c
@@ -169,4 +183,7 @@
 	mksource.pl pmSourceIO_CMF.c.in PS1_DV3 pmSourceIO_CMF_PS1_DV3.c
 
+pmSourceIO_CMF_PS1_DV4.c : pmSourceIO_CMF.c.in mksource.pl
+	mksource.pl pmSourceIO_CMF.c.in PS1_DV4 pmSourceIO_CMF_PS1_DV4.c
+
 pmSourceIO_CMF_PS1_SV1.c : pmSourceIO_CMF.c.in mksource.pl
 	mksource.pl pmSourceIO_CMF.c.in PS1_SV1 pmSourceIO_CMF_PS1_SV1.c
@@ -175,3 +192,6 @@
 	mksource.pl pmSourceIO_CMF.c.in PS1_SV2 pmSourceIO_CMF_PS1_SV2.c
 
+pmSourceIO_CMF_PS1_SV3.c : pmSourceIO_CMF.c.in mksource.pl
+	mksource.pl pmSourceIO_CMF.c.in PS1_SV3 pmSourceIO_CMF_PS1_SV3.c
+
 # EXTRA_DIST = pmErrorCodes.h.in pmErrorCodes.dat pmErrorCodes.c.in
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/mksource.pl
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/mksource.pl	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/mksource.pl	(revision 37066)
@@ -19,11 +19,14 @@
 	       "PS1_V3", 3,
 	       "PS1_V4", 4,
+	       "PS1_V5", 5,
     );
 %cmfmodes_dv = ("PS1_DV1", 1,
 		"PS1_DV2", 2,
 		"PS1_DV3", 3,
+		"PS1_DV4", 4,
     );
 %cmfmodes_sv = ("PS1_SV1", 1,
 		"PS1_SV2", 2,
+		"PS1_SV3", 3,
     );
 
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/fwhm.sh
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/fwhm.sh	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/fwhm.sh	(revision 37066)
@@ -0,0 +1,218 @@
+
+macro find.fwhm.pgauss
+  if ($0 != 1)
+    echo "USAGE: find.fwhm"
+    break
+  end
+  
+  $dz = 0.01
+  create z 0 50 $dz
+
+  # Gaussian taylor expansion
+  # f = 1 / (1 + z + z^2/2 + z^3/6)
+  # 1 + z + z^2/2 + z^3/6 = 2
+  # f = z + z^2/2 + z^3/6 - 2, find where f == 0.0
+  
+  set f = z + 0.5*z^2 + (1/6.0)*z^3 - 2.0
+  set dfdz = 1 + z + 0.5*z^2
+
+  lim -n 0 z f; clear; box; plot z f
+  lim -n 1 z dfdz; clear; box; plot z dfdz  
+
+  $nZ0 = 0
+  $nZ1 = 5 / $dz
+
+  $Zg = 0.5*(z[$nZ0] + z[$nZ1])  
+  $nZg = int($Zg / $dz)
+  $dZ = 1.0
+
+  for i 0 10
+    $Fg = f[$nZg]
+    $dFdz_g = dfdz[$nZg]
+
+    $dZ = $Fg / $dFdz_g
+
+    echo $Zg $Fg $dZ $dFdz_g
+
+    $Zg -= $dZ
+    $Zg = max ($Zg , 0)
+    $nZg = int($Zg / $dz)
+  end 
+  echo $Zg $Fg $dZ $dFdz_g
+  $Zhm = $Zg
+  $FWHM = 2*sqrt(2*$Zg)
+
+  echo $Zhm : $FWHM
+end
+
+macro find.fwhm.rgauss
+  if ($0 != 2)
+    echo "USAGE: find.fwhm (K)"
+    break
+  end
+  
+  $K = $1
+
+  if ($K == 0.0)
+    $Zhm = (sqrt(5) - 1.0) / 2.0
+    $FWHM = 2*sqrt(2*$Zhm)
+    echo $K : $Zhm : $FWHM
+    return
+  end
+
+  $dz = 0.01
+  create z 0 50 $dz
+
+  # set f = 1.0 / (1.0 + $K*z + z^1.667)
+  # f = $K*z + z^1.667 - 1.0, find where f == 0.0
+  
+  set f = z + z^$K - 1.0
+  set dfdz = ln(z) * z^$K + 1.0
+
+  lim -n 0 z f; clear; box; plot z f
+  lim -n 1 z dfdz; clear; box; plot z dfdz  
+
+  $nZ0 = 0
+  $nZ1 = 5 / $dz
+
+  $Zg = 0.5*(z[$nZ0] + z[$nZ1])  
+  $nZg = int($Zg / $dz)
+  $dZ = 1.0
+
+  for i 0 10
+    $Fg = f[$nZg]
+    $dFdz_g = dfdz[$nZg]
+
+    $dZ = $Fg / $dFdz_g
+
+    echo $nZg $Zg $Fg $dZ $dFdz_g
+
+    $Zg -= $dZ
+    $Zg = max ($Zg , 0)
+    $nZg = int($Zg / $dz)
+  end 
+  # echo $Zg $Fg $dZ $dFdz_g
+  $Zhm = $Zg
+  $FWHM = 2*sqrt(2*$Zg)
+
+  echo $K : $Zhm : $FWHM
+end
+
+macro find.fwhm.ps1v1
+  if ($0 != 2)
+    echo "USAGE: find.fwhm (K)"
+    break
+  end
+  
+  $K = $1
+
+  if ($K == 0.0)
+    $Zhm = 1.0
+    $FWHM = 2*sqrt(2)
+    echo $K : $Zhm : $FWHM
+    return
+  end
+
+  $dz = 0.01
+  create z 0 50 $dz
+
+  # set f = 1.0 / (1.0 + $K*z + z^1.667)
+  # f = $K*z + z^1.667 - 1.0, find where f == 0.0
+  
+  set f = $K*z + z^1.667 - 1.0
+  set dfdz = $K + z^0.667
+
+  #lim -n 0 z f; clear; box; plot z f
+  #lim -n 1 z dfdz; clear; box; plot z dfdz  
+
+  $nZ0 = 0
+  $nZ1 = 5 / $dz
+
+  $Zg = 0.5*(z[$nZ0] + z[$nZ1])  
+  $nZg = int($Zg / $dz)
+  $dZ = 1.0
+
+  for i 0 10
+    $Fg = f[$nZg]
+    $dFdz_g = dfdz[$nZg]
+
+    $dZ = $Fg / $dFdz_g
+
+    # echo $Zg $Fg $dZ $dFdz_g
+
+    $Zg -= $dZ
+    $Zg = max ($Zg , 0)
+    $nZg = int($Zg / $dz)
+  end 
+  # echo $Zg $Fg $dZ $dFdz_g
+  $Zhm = $Zg
+  $FWHM = 2*sqrt(2*$Zg)
+
+  echo $K : $Zhm : $FWHM
+end
+
+# qgauss is like ps1_v1 with z^2.25
+macro find.fwhm.qgauss
+  if ($0 != 2)
+    echo "USAGE: find.qgauss (K)"
+    break
+  end
+  
+  $K = $1
+
+  if ($K == 0.0)
+    $Zhm = 1.0
+    $FWHM = 2*sqrt(2)
+    echo $K : $Zhm : $FWHM
+    return
+  end
+
+  $dz = 0.01
+  create z 0 50 $dz
+
+  # set f = 1.0 / (1.0 + $K*z + z^2.25)
+  # f = $K*z + z^2.25 - 1.0, find where f == 0.0
+  
+  set f = $K*z + z^2.25 - 1.0
+  set dfdz = $K + z^1.25
+
+  #lim -n 0 z f; clear; box; plot z f
+  #lim -n 1 z dfdz; clear; box; plot z dfdz  
+
+  $nZ0 = 0
+  $nZ1 = 5 / $dz
+
+  $Zg = 0.5*(z[$nZ0] + z[$nZ1])  
+  $nZg = int($Zg / $dz)
+  $dZ = 1.0
+
+  for i 0 10
+    $Fg = f[$nZg]
+    $dFdz_g = dfdz[$nZg]
+
+    $dZ = $Fg / $dFdz_g
+
+    # echo $Zg $Fg $dZ $dFdz_g
+
+    $Zg -= $dZ
+    $Zg = max ($Zg , 0)
+    $nZg = int($Zg / $dz)
+  end 
+  # echo $Zg $Fg $dZ $dFdz_g
+  $Zhm = $Zg
+  $FWHM = 2*sqrt(2*$Zg)
+
+  echo $K : $Zhm : $FWHM
+end
+
+macro fwhm.trend
+
+  delete fwhm_v k_v
+
+  for k 0 20 1.0
+    find.fwhm.qgauss $k
+    concat $k k_v
+    concat $FWHM fwhm_v
+  end
+end
+
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_DEV.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_DEV.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_DEV.c	(revision 37066)
@@ -16,5 +16,4 @@
    * PM_PAR_SYY 5   - Y^2 term of elliptical contour (sqrt(2) / SigmaY)
    * PM_PAR_SXY 6   - X*Y term of elliptical contour
-   * PM_PAR_7   7   - normalized dev parameter
 
    note that a standard dev model uses exp(-K*(z^(1/2n) - 1).  the additional elements (K,
@@ -37,11 +36,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceFitModel.h"
@@ -49,4 +49,5 @@
 #include "pmPSFtry.h"
 #include "pmDetections.h"
+#include "pmModel_CentralPixel.h"
 
 #include "pmModel_DEV.h"
@@ -58,4 +59,5 @@
 # define PM_MODEL_LIMITS          pmModelLimits_DEV
 # define PM_MODEL_RADIUS          pmModelRadius_DEV
+# define PM_MODEL_SET_FWHM        pmModelSetFWHM_DEV
 # define PM_MODEL_FROM_PSF        pmModelFromPSF_DEV
 # define PM_MODEL_PARAMS_FROM_PSF pmModelParamsFromPSF_DEV
@@ -63,7 +65,8 @@
 # define PM_MODEL_SET_LIMITS      pmModelSetLimits_DEV
 
-// f = exp(-z^0.125) 
+// f = exp(-kappa*r^(1/index)) 
+// f = exp(-kappa*z^(0.5/index)) 
+// index = 4, 0.5/index = 0.125
 # define ALPHA 0.125 
-// # define ALPHA 0.25 
 
 // the model is a function of the pixel coordinate (pixcoord[0,1] = x,y)
@@ -73,5 +76,5 @@
 // Lax parameter limits
 static float paramsMinLax[] = { -1.0e3, 1.0e-2, -100, -100, 0.001, 0.001, -1.0 };
-static float paramsMaxLax[] = { 1.0e5, 1.0e8, 1.0e4, 1.0e4, 100, 100, 1.0 };
+static float paramsMaxLax[] = { 1.0e5, 1.0e9, 1.0e5, 1.0e5, 100, 100, 1.0 };
 
 // Moderate parameter limits
@@ -86,9 +89,7 @@
 static float *paramsMinUse = paramsMinLax;
 static float *paramsMaxUse = paramsMaxLax;
-static float betaUse[] = { 1000, 3e6, 5, 5, 1.0, 1.0, 0.5 };
+static float betaUse[] = { 2, 3e6, 5, 5, 10.0, 10.0, 0.5 };
 
 static bool limitsApply = true;         // Apply limits?
-
-# include "pmModel_SERSIC.CP.h"
 
 psF32 PM_MODEL_FUNC (psVector *deriv,
@@ -109,85 +110,31 @@
     psAssert (z >= 0, "do not allow negative z values in model");
 
-    float index = 0.5 / ALPHA;
-    float par7 = ALPHA;
-    float bn = 1.9992*index - 0.3271;
-    float Io = exp(bn);
-
-    psF32 f2 = bn*pow(z,ALPHA);
-    psF32 f1 = Io*exp(-f2);
-
-    psF32 radius = hypot(X, Y);
-    if (radius < 1.0) {
-
-	// ** use bilinear interpolation to the given location from the 4 surrounding pixels centered on the object center
-
-	// first, use Rmajor and index to find the central pixel flux (fraction of total flux)
-	psEllipseAxes axes;
-	pmModelParamsToAxes (&axes, PAR[PM_PAR_SXX], PAR[PM_PAR_SXY], PAR[PM_PAR_SYY], true);
-
-	// get the central pixel flux from the lookup table
-	float xPix = (axes.major - centralPixelXo) / centralPixeldX;
-	xPix = PS_MIN (PS_MAX(xPix, 0), centralPixelNX - 1);
-	float yPix = (index - centralPixelYo) / centralPixeldY;
-	yPix = PS_MIN (PS_MAX(yPix, 0), centralPixelNY - 1);
-
-	// the integral of a Sersic has an analytical form as follows:
-	float logGamma = lgamma(2.0*index);
-	float bnFactor = pow(bn, 2.0*index);
-	float norm = 2.0 * M_PI * PS_SQR(axes.major) * index * exp(bn) * exp(logGamma) / bnFactor;
-
-	// XXX interpolate to get the value
-	// XXX for the moment, just integerize
-	// XXX I need to multiply by the integrated flux to get the flux in the central pixel
-	float Vcenter = centralPixel[(int)yPix][(int)xPix] * norm;
-	
-	float px1 = 1.0 / PAR[PM_PAR_SXX];
-	float py1 = 1.0 / PAR[PM_PAR_SYY];
-	float z10 = PS_SQR(px1);
-	float z01 = PS_SQR(py1);
-
-	// which pixels do we need for this interpolation?
-	// (I do not keep state information, so I don't know anything about other evaluations of nearby pixels...)
-	if ((X >= 0) && (Y >= 0)) {
-	    float z11 = z10 + z01 + PAR[PM_PAR_SXY]; // X * Y positive
-	    float V00 = Vcenter;
-	    float V10 = Io*exp(-bn*pow(z10,par7));
-	    float V01 = Io*exp(-bn*pow(z01,par7));
-	    float V11 = Io*exp(-bn*pow(z11,par7));
-	    f1 = interpolatePixels(V00, V10, V01, V11, X, Y);
-	}
-	if ((X < 0) && (Y >= 0)) {
-	    float z11 = z10 + z01 - PAR[PM_PAR_SXY]; // X * Y negative
-	    float V00 = Io*exp(-bn*pow(z10,par7));
-	    float V10 = Vcenter;
-	    float V01 = Io*exp(-bn*pow(z11,par7));
-	    float V11 = Io*exp(-bn*pow(z01,par7));
-	    f1 = interpolatePixels(V00, V10, V01, V11, (1.0 + X), Y);
-	}
-	if ((X >= 0) && (Y < 0)) {
-	    float z11 = z10 + z01 - PAR[PM_PAR_SXY]; // X * Y negative
-	    float V00 = Io*exp(-bn*pow(z01,par7));
-	    float V10 = Io*exp(-bn*pow(z11,par7));
-	    float V01 = Vcenter;
-	    float V11 = Io*exp(-bn*pow(z10,par7));
-	    f1 = interpolatePixels(V00, V10, V01, V11, X, (1.0 + Y));
-	}
-	if ((X < 0) && (Y < 0)) {
-	    float z11 = z10 + z01 + PAR[PM_PAR_SXY]; // X * Y positive
-	    float V00 = Io*exp(-bn*pow(z11,par7));
-	    float V10 = Io*exp(-bn*pow(z10,par7));
-	    float V01 = Io*exp(-bn*pow(z01,par7));
-	    float V11 = Vcenter;
-	    f1 = interpolatePixels(V00, V10, V01, V11, (1.0 + X), (1.0 + Y));
-	}
+    // for DEV, we can hard-wire kappa(4):
+    // float index = 4.0;
+    float kappa = 7.670628;
+
+    // r = sqrt(z)
+    float q = kappa*pow(z,ALPHA);
+    float f0 = exp(-q);
+
+    assert (isfinite(q));
+
+    // only worry about the central pixels at most
+    float radius = hypot(X, Y);
+    if (radius <= 1.5) {
+	// Nsub ~ 10*index^2 + 1
+	psEllipseAxes axes = pmPSF_ModelToAxes(PAR, true); // DEV uses Reff
+	int Nsub = 2 * ((int)(25 / axes.minor)) + 1;
+	Nsub = PS_MIN (Nsub, 121);
+	Nsub = PS_MAX (Nsub, 11);
+	f0 = pmModelCP_SersicSubpix (X, Y, PAR[PM_PAR_SXX], PAR[PM_PAR_SXY], PAR[PM_PAR_SYY], 4.0, Nsub);
     }   
-
-    psF32 z0 = PAR[PM_PAR_I0]*f1;
-    psF32 f0 = PAR[PM_PAR_SKY] + z0;
-
-    assert (isfinite(f2));
+    assert (isfinite(f0));
+
+    float f1 = PAR[PM_PAR_I0]*f0;
+    float f = PAR[PM_PAR_SKY] + f1;
+
     assert (isfinite(f1));
-    assert (isfinite(z0));
-    assert (isfinite(f0));
+    assert (isfinite(f));
 
     if (deriv != NULL) {
@@ -195,18 +142,24 @@
 
         dPAR[PM_PAR_SKY]  = +1.0;
-        dPAR[PM_PAR_I0]   = +2.0*f1; // XXX extra damping..
-
-        // gradient is infinite for z = 0; saturate at z = 0.01
-        psF32 z1 = (z < 0.01) ? z0*bn*ALPHA*pow(0.01,ALPHA - 1.0) : z0*bn*ALPHA*pow(z,ALPHA - 1.0);
-
-        assert (isfinite(z1));
-
-        dPAR[PM_PAR_XPOS] = +1.0*z1*(2.0*px/PAR[PM_PAR_SXX] + Y*PAR[PM_PAR_SXY]);
-        dPAR[PM_PAR_YPOS] = +1.0*z1*(2.0*py/PAR[PM_PAR_SYY] + X*PAR[PM_PAR_SXY]);
-        dPAR[PM_PAR_SXX]  = +2.0*z1*px*px/PAR[PM_PAR_SXX];
-        dPAR[PM_PAR_SYY]  = +2.0*z1*py*py/PAR[PM_PAR_SYY];
-        dPAR[PM_PAR_SXY]  = -1.0*z1*X*Y;
-    }
-    return (f0);
+        dPAR[PM_PAR_I0]   = +f0;
+
+	if (z > 0.01) {
+	  float z1 = f1*kappa*ALPHA*pow(z,ALPHA-1.0);
+	  dPAR[PM_PAR_XPOS] = +1.0*z1*(2.0*px + Y*PAR[PM_PAR_SXY]);
+	  dPAR[PM_PAR_YPOS] = +1.0*z1*(2.0*py + X*PAR[PM_PAR_SXY]);
+	  dPAR[PM_PAR_SXX]  = +2.0*z1*px*px/PAR[PM_PAR_SXX];
+	  dPAR[PM_PAR_SYY]  = +2.0*z1*py*py/PAR[PM_PAR_SYY];
+	  dPAR[PM_PAR_SXY]  = -1.0*z1*X*Y;
+	} else {
+	  // gradient -> 0 for z -> 0, but has undef form
+	  float z1 = f1*kappa*ALPHA*pow(z,ALPHA);
+	  dPAR[PM_PAR_XPOS] = +1.0*z1*(2.0/PAR[PM_PAR_SXX] + PAR[PM_PAR_SXY]);
+	  dPAR[PM_PAR_YPOS] = +1.0*z1*(2.0/PAR[PM_PAR_SYY] + PAR[PM_PAR_SXY]);
+	  dPAR[PM_PAR_SXX]  = +2.0*z1*px/PAR[PM_PAR_SXX]/PAR[PM_PAR_SXX];
+	  dPAR[PM_PAR_SYY]  = +2.0*z1*py/PAR[PM_PAR_SYY]/PAR[PM_PAR_SYY];
+	  dPAR[PM_PAR_SXY]  = -1.0*z1;
+	}
+    }
+    return (f);
 }
 
@@ -292,4 +245,12 @@
 bool PM_MODEL_GUESS (pmModel *model, pmSource *source, psImageMaskType maskVal, psImageMaskType markVal)
 {
+    // for the moment, we are going to require moments and KronFlux
+    if (!source->moments) return false;
+    pmMoments *moments = source->moments;
+
+    if (!isfinite(moments->KronFlux)) return false;
+    if (!isfinite(moments->Mrf)) return false;
+    if (moments->Mrf < 0.0) return false;
+
     psF32 *PAR  = model->params->data.F32;
 
@@ -297,19 +258,32 @@
     PAR[PM_PAR_SKY]  = 0.0;
 
-    // set the shape parameters
-    if (!pmModelSetShape(&PAR[PM_PAR_SXX], &PAR[PM_PAR_SXY], &PAR[PM_PAR_SYY], source->moments, true)) {
-      return false;
-    }
-
-    // the normalization is modified by the slope
-    float index = 0.5 / ALPHA;
-    float bn = 1.9992*index - 0.3271;
-    float Io = exp(0.5*bn);
-
-    // set the model normalization
-    if (!pmModelSetNorm(&PAR[PM_PAR_I0], source)) {
-      return false;
-    }
-    PAR[PM_PAR_I0] /= Io;
+    psEllipseMoments emoments;
+    emoments.x2 = moments->Mxx;
+    emoments.xy = moments->Mxy;
+    emoments.y2 = moments->Myy;
+
+    // force the axis ratio to be < 20.0
+    psEllipseAxes axes = psEllipseMomentsToAxes (emoments, 20.0);
+
+    if (!isfinite(axes.major)) return false;
+    if (!isfinite(axes.minor)) return false;
+    if (!isfinite(axes.theta)) return false;
+
+    // Mxx, Mxy, Myy define the elliptical shape, but Mrf defines the width 
+    // the factor of 2.3 comes from Table 1 of Graham and Driver (2005)
+    float scale = moments->Mrf / axes.major / 2.3;
+    axes.major *= scale;
+    axes.minor *= scale;
+
+    pmModelAxesToParams (&PAR[PM_PAR_SXX], &PAR[PM_PAR_SXY], &PAR[PM_PAR_SYY], axes, true);
+
+    // psEllipseAxes axes;
+    // use the code in SetShape here to avoid doing this 2x
+    // pmModelParamsToAxes (&axes, PAR[PM_PAR_SXX], PAR[PM_PAR_SXY], PAR[PM_PAR_SYY], true);
+
+    // float norm = pmSersicNorm (4);  // hardwire
+    float norm = 0.00168012;
+    float normFlux = 2.0 * M_PI * axes.major * axes.minor * norm;
+    PAR[PM_PAR_I0] = moments->KronFlux / normFlux;
 
     // set the model position
@@ -328,17 +302,9 @@
     psEllipseAxes axes;
     pmModelParamsToAxes (&axes, PAR[PM_PAR_SXX], PAR[PM_PAR_SXY], PAR[PM_PAR_SYY], true);
-    float AspectRatio = axes.minor / axes.major;
-
-    float index = 4.0;
-    float bn = 1.9992*index - 0.3271;
-
-    // the integral of a Sersic has an analytical form as follows:
-    float logGamma = lgamma(2.0*index);
-    float bnFactor = pow(bn, 2.0*index);
-    float norm = 2.0 * M_PI * PS_SQR(axes.major) * index * exp(bn) * exp(logGamma) / bnFactor;
-    
-    psF64 Flux = PAR[PM_PAR_I0] * norm * AspectRatio;
-
-    return(Flux);
+
+    float norm = 0.00168012;
+    float flux = PAR[PM_PAR_I0] * 2.0 * M_PI * axes.major * axes.minor * norm;
+
+    return(flux);
 }
 
@@ -359,11 +325,18 @@
     pmModelParamsToAxes (&axes, PAR[PM_PAR_SXX], PAR[PM_PAR_SXY], PAR[PM_PAR_SYY], true);
 
-    // f = Io exp(-z^n) -> z^n = ln(Io/f)
-    psF64 zn = log(PAR[PM_PAR_I0] / flux);
-    psF64 radius = axes.major * sqrt (2.0) * pow(zn, 0.5 / ALPHA);
+    // static value for DEV:
+    float kappa = 7.670628;
+
+    // f = Io exp(-kappa*z^n) -> z^n = ln(Io/f) / kappa
+    psF64 zn = log(PAR[PM_PAR_I0] / flux) / kappa;
+    psF64 radius = axes.major * pow(zn, 0.5 / ALPHA);
 
     psAssert (isfinite(radius), "fix this code: radius should not be nan for Io = %f, flux = %f, major = %f (%f, %f, %f)", 
 	      PAR[PM_PAR_I0], flux, axes.major, PAR[PM_PAR_SXX], PAR[PM_PAR_SXY], PAR[PM_PAR_SYY]);
     return (radius);
+}
+
+psF64 PM_MODEL_SET_FWHM (const psVector *params, psF64 sigma) {
+  return (NAN);
 }
 
@@ -389,5 +362,5 @@
     // the 2D PSF model fits polarization terms (E0,E1,E2)
     // convert to shape terms (SXX,SYY,SXY)
-    bool useReff = pmModelUseReff (modelPSF->type);
+    bool useReff = modelPSF->class->useReff;
     if (!pmPSF_FitToModel (out, 0.1, useReff)) {
         psTrace("psModules.objects", 5, "Failed to fit object at (r,c) = (%.1f,%.1f)", in[PM_PAR_YPOS], in[PM_PAR_XPOS]);
@@ -443,5 +416,5 @@
     // convert to shape terms (SXX,SYY,SXY)
     // XXX user-defined value for limit?
-    bool useReff = pmModelUseReff (model->type);
+    bool useReff = model->class->useReff;
     if (!pmPSF_FitToModel (PAR, 0.1, useReff)) {
         psTrace ("psModules.objects", 3, "Failed to fit object at (r,c) = (%.1f,%.1f)", Xo, Yo);
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_DEV.h
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_DEV.h	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_DEV.h	(revision 37066)
@@ -8,4 +8,5 @@
 psF64 pmModelFlux_DEV(const psVector *params);
 psF64 pmModelRadius_DEV(const psVector *params, psF64 flux);
+psF64 pmModelSetFWHM_DEV(const psVector *params, psF64 flux);
 bool pmModelFromPSF_DEV(pmModel *modelPSF, pmModel *modelFLT, const pmPSF *psf);
 bool  pmModelParamsFromPSF_DEV(pmModel *model, const pmPSF *psf, float Xo, float Yo, float Io);
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_EXP.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_EXP.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_EXP.c	(revision 37066)
@@ -33,11 +33,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceFitModel.h"
@@ -45,4 +46,5 @@
 #include "pmPSFtry.h"
 #include "pmDetections.h"
+#include "pmModel_CentralPixel.h"
 
 #include "pmModel_EXP.h"
@@ -54,4 +56,5 @@
 # define PM_MODEL_LIMITS          pmModelLimits_EXP
 # define PM_MODEL_RADIUS          pmModelRadius_EXP
+# define PM_MODEL_SET_FWHM        pmModelSetFWHM_EXP
 # define PM_MODEL_FROM_PSF        pmModelFromPSF_EXP
 # define PM_MODEL_PARAMS_FROM_PSF pmModelParamsFromPSF_EXP
@@ -62,8 +65,21 @@
 // 0.5 PIX: the parameters are defined in terms of pixel coords, so the incoming pixcoords
 // values need to be pixel coords
+//
+
+// Notes on changing kappa value from 1.70056 to 1.678
+// I'm using a functional form f(x,y) = Io exp(-kappa (r / r_e)).  
+// The article by Graham & Driver (2005) uses a form Ie exp(-bn [(r / r_e) -1]) 
+// which is equal to Ie exp(-bn (r / r_e)) exp(bn).  
+// Thus, my Io = Ie exp(bn) and my kappa is their bn.
+// My value of kappa is 1.700, their value for bn is 1.678., so I am off by a small amount there (1.5%).  
+
+
+#define KAPPA_EXP 1.678
+#define OLD_KAPP_EXP 1.70056
+
 
 // Lax parameter limits
 static float paramsMinLax[] = { -1.0e3, 1.0e-2, -100, -100, 0.05, 0.05, -1.0 };
-static float paramsMaxLax[] = { 1.0e5, 1.0e8, 1.0e4, 1.0e4, 100, 100, 1.0 };
+static float paramsMaxLax[] = { 1.0e5, 1.0e9, 1.0e5, 1.0e5, 100, 100, 1.0 };
 
 // Moderate parameter limits
@@ -78,9 +94,14 @@
 static float *paramsMinUse = paramsMinLax;
 static float *paramsMaxUse = paramsMaxLax;
-static float betaUse[] = { 1000, 3e6, 5, 5, 1.0, 1.0, 0.5};
+static float betaUse[] = { 2, 3e6, 5, 5, 10.0, 10.0, 0.5};
 
 static bool limitsApply = true;         // Apply limits?
 
-# include "pmModel_SERSIC.CP.h"
+// # include "pmModel_SERSIC.CP.h"
+
+// the problems I'm having with the SERSIC-like functions are:
+// 1) making sure I have the right functional form so that PAR[SXX,etc] represent R_eff (half-light radius)
+// 2) getting the central pixel right
+// 3) getting the derivaties right.
 
 psF32 PM_MODEL_FUNC (psVector *deriv,
@@ -101,85 +122,26 @@
     psAssert (z >= 0, "do not allow negative z values in model");
 
-    float index = 1.0;
-    float par7 = 0.5;
-    float bn = 1.9992*index - 0.3271;
-    float Io = exp(bn);
-
-    psF32 f2 = bn*sqrt(z);
-    psF32 f1 = Io*exp(-f2);
-
+    // for EXP, we can hard-wire kappa(1):
+    // float index = 1.0;
+    float kappa = KAPPA_EXP;
+
+    // sqrt(z) is r
+    float q = kappa*sqrt(z);
+    psF32 f0 = exp(-q);
+
+    assert (isfinite(q));
+
+    // only worry about the central 4 pixels at most
     psF32 radius = hypot(X, Y);
-    if (radius < 1.0) {
-
-	// ** use bilinear interpolation to the given location from the 4 surrounding pixels centered on the object center
-
-	// first, use Rmajor and index to find the central pixel flux (fraction of total flux)
-	psEllipseAxes axes;
-	pmModelParamsToAxes (&axes, PAR[PM_PAR_SXX], PAR[PM_PAR_SXY], PAR[PM_PAR_SYY], true);
-
-	// get the central pixel flux from the lookup table
-	float xPix = (axes.major - centralPixelXo) / centralPixeldX;
-	xPix = PS_MIN (PS_MAX(xPix, 0), centralPixelNX - 1);
-	float yPix = (index - centralPixelYo) / centralPixeldY;
-	yPix = PS_MIN (PS_MAX(yPix, 0), centralPixelNY - 1);
-
-	// the integral of a Sersic has an analytical form as follows:
-	float logGamma = lgamma(2.0*index);
-	float bnFactor = pow(bn, 2.0*index);
-	float norm = 2.0 * M_PI * PS_SQR(axes.major) * index * exp(bn) * exp(logGamma) / bnFactor;
-
-	// XXX interpolate to get the value
-	// XXX for the moment, just integerize
-	// XXX I need to multiply by the integrated flux to get the flux in the central pixel
-	float Vcenter = centralPixel[(int)yPix][(int)xPix] * norm;
-	
-	float px1 = 1.0 / PAR[PM_PAR_SXX];
-	float py1 = 1.0 / PAR[PM_PAR_SYY];
-	float z10 = PS_SQR(px1);
-	float z01 = PS_SQR(py1);
-
-	// which pixels do we need for this interpolation?
-	// (I do not keep state information, so I don't know anything about other evaluations of nearby pixels...)
-	if ((X >= 0) && (Y >= 0)) {
-	    float z11 = z10 + z01 + PAR[PM_PAR_SXY]; // X * Y positive
-	    float V00 = Vcenter;
-	    float V10 = Io*exp(-bn*pow(z10,par7));
-	    float V01 = Io*exp(-bn*pow(z01,par7));
-	    float V11 = Io*exp(-bn*pow(z11,par7));
-	    f1 = interpolatePixels(V00, V10, V01, V11, X, Y);
-	}
-	if ((X < 0) && (Y >= 0)) {
-	    float z11 = z10 + z01 - PAR[PM_PAR_SXY]; // X * Y negative
-	    float V00 = Io*exp(-bn*pow(z10,par7));
-	    float V10 = Vcenter;
-	    float V01 = Io*exp(-bn*pow(z11,par7));
-	    float V11 = Io*exp(-bn*pow(z01,par7));
-	    f1 = interpolatePixels(V00, V10, V01, V11, (1.0 + X), Y);
-	}
-	if ((X >= 0) && (Y < 0)) {
-	    float z11 = z10 + z01 - PAR[PM_PAR_SXY]; // X * Y negative
-	    float V00 = Io*exp(-bn*pow(z01,par7));
-	    float V10 = Io*exp(-bn*pow(z11,par7));
-	    float V01 = Vcenter;
-	    float V11 = Io*exp(-bn*pow(z10,par7));
-	    f1 = interpolatePixels(V00, V10, V01, V11, X, (1.0 + Y));
-	}
-	if ((X < 0) && (Y < 0)) {
-	    float z11 = z10 + z01 + PAR[PM_PAR_SXY]; // X * Y positive
-	    float V00 = Io*exp(-bn*pow(z11,par7));
-	    float V10 = Io*exp(-bn*pow(z10,par7));
-	    float V01 = Io*exp(-bn*pow(z01,par7));
-	    float V11 = Vcenter;
-	    f1 = interpolatePixels(V00, V10, V01, V11, (1.0 + X), (1.0 + Y));
-	}
-    }   
-
-    psF32 z0 = PAR[PM_PAR_I0]*f1;
-    psF32 f0 = PAR[PM_PAR_SKY] + z0;
-
-    assert (isfinite(f2));
+    if (radius <= 1.5) {
+	f0 = pmModelCP_SersicSubpix (X, Y, PAR[PM_PAR_SXX], PAR[PM_PAR_SXY], PAR[PM_PAR_SYY], 1.0, 51);
+    }
+    assert (isfinite(f0));
+
+    psF32 f1 = PAR[PM_PAR_I0]*f0;
+    psF32 f = PAR[PM_PAR_SKY] + f1;
+
     assert (isfinite(f1));
-    assert (isfinite(z0));
-    assert (isfinite(f0));
+    assert (isfinite(f));
 
     if (deriv != NULL) {
@@ -187,18 +149,24 @@
 
         dPAR[PM_PAR_SKY]  = +1.0;
-        dPAR[PM_PAR_I0]   = +f1;
-
-        // gradient is infinite for z = 0; saturate at z = 0.01
-	// z1 is -df/dz (the negative sign is canceled by most of dz/dPAR[i]
-        psF32 z1 = (z < 0.01) ? 0.5*bn*z0/sqrt(0.01) : 0.5*bn*z0/sqrt(z);
-
-	// XXX dampen SXX and SYY as in GAUSS?
-        dPAR[PM_PAR_XPOS] = +1.0*z1*(2.0*px/PAR[PM_PAR_SXX] + Y*PAR[PM_PAR_SXY]);
-        dPAR[PM_PAR_YPOS] = +1.0*z1*(2.0*py/PAR[PM_PAR_SYY] + X*PAR[PM_PAR_SXY]);
-        dPAR[PM_PAR_SXX]  = +2.0*z1*px*px/PAR[PM_PAR_SXX];
-        dPAR[PM_PAR_SYY]  = +2.0*z1*py*py/PAR[PM_PAR_SYY];
-        dPAR[PM_PAR_SXY]  = -1.0*z1*X*Y;
-    }
-    return (f0);
+        dPAR[PM_PAR_I0]   = +f0;
+
+	if (z > 0.01) {
+	  float z1 = 0.5*f1*kappa/sqrt(z);
+	  dPAR[PM_PAR_XPOS] = +1.0*z1*(2.0*px + Y*PAR[PM_PAR_SXY]);
+	  dPAR[PM_PAR_YPOS] = +1.0*z1*(2.0*py + X*PAR[PM_PAR_SXY]);
+	  dPAR[PM_PAR_SXX]  = +2.0*z1*px*px/PAR[PM_PAR_SXX];
+	  dPAR[PM_PAR_SYY]  = +2.0*z1*py*py/PAR[PM_PAR_SYY];
+	  dPAR[PM_PAR_SXY]  = -1.0*z1*X*Y;
+	} else {
+	  // gradient -> 0 for z -> 0, but has undef form
+	  float z1 = 0.5*f1*kappa;
+	  dPAR[PM_PAR_XPOS] = +1.0*z1*(2.0/PAR[PM_PAR_SXX] + PAR[PM_PAR_SXY]);
+	  dPAR[PM_PAR_YPOS] = +1.0*z1*(2.0/PAR[PM_PAR_SYY] + PAR[PM_PAR_SXY]);
+	  dPAR[PM_PAR_SXX]  = +2.0*z1*px/PAR[PM_PAR_SXX]/PAR[PM_PAR_SXX];
+	  dPAR[PM_PAR_SYY]  = +2.0*z1*py/PAR[PM_PAR_SYY]/PAR[PM_PAR_SYY];
+	  dPAR[PM_PAR_SXY]  = -1.0*z1;
+	}
+    }
+    return (f);
 }
 
@@ -284,4 +252,12 @@
 bool PM_MODEL_GUESS (pmModel *model, pmSource *source, psImageMaskType maskVal, psImageMaskType markVal)
 {
+    // for the moment, we are going to require moments and KronFlux
+    if (!source->moments) return false;
+    pmMoments *moments = source->moments;
+
+    if (!isfinite(moments->KronFlux)) return false;
+    if (!isfinite(moments->Mrf)) return false;
+    if (moments->Mrf < 0.0) return false;
+
     psF32 *PAR  = model->params->data.F32;
 
@@ -289,13 +265,31 @@
     PAR[PM_PAR_SKY]  = 0.0;
 
-    // set the shape parameters
-    if (!pmModelSetShape(&PAR[PM_PAR_SXX], &PAR[PM_PAR_SXY], &PAR[PM_PAR_SYY], source->moments, true)) {
-      return false;
-    }
-
-    // set the model normalization
-    if (!pmModelSetNorm(&PAR[PM_PAR_I0], source)) {
-      return false;
-    }
+    psEllipseMoments emoments;
+    emoments.x2 = moments->Mxx;
+    emoments.xy = moments->Mxy;
+    emoments.y2 = moments->Myy;
+
+    // force the axis ratio to be < 20.0
+    psEllipseAxes axes = psEllipseMomentsToAxes (emoments, 20.0);
+
+    if (!isfinite(axes.major)) return false;
+    if (!isfinite(axes.minor)) return false;
+    if (!isfinite(axes.theta)) return false;
+
+    // Mxx, Mxy, Myy define the elliptical shape, but Mrf defines the width 
+    float scale = moments->Mrf / axes.major;
+    axes.major *= scale;
+    axes.minor *= scale;
+
+    pmModelAxesToParams (&PAR[PM_PAR_SXX], &PAR[PM_PAR_SXY], &PAR[PM_PAR_SYY], axes, true);
+
+    // psEllipseAxes axes;
+    // use the code in SetShape here to avoid doing this 2x
+    // pmModelParamsToAxes (&axes, PAR[PM_PAR_SXX], PAR[PM_PAR_SXY], PAR[PM_PAR_SYY], true);
+
+    // float norm = pmSersicNorm (4);  // hardwire
+    float norm = 0.34578;
+    float normFlux = 2.0 * M_PI * axes.major * axes.minor * norm;
+    PAR[PM_PAR_I0] = moments->KronFlux / normFlux;
 
     // set the model position
@@ -306,5 +300,4 @@
     return(true);
 }
-
 // An exponential model is equivalent to a Sersic with index = 1.0
 psF64 PM_MODEL_FLUX (const psVector *params)
@@ -314,17 +307,11 @@
     psEllipseAxes axes;
     pmModelParamsToAxes (&axes, PAR[PM_PAR_SXX], PAR[PM_PAR_SXY], PAR[PM_PAR_SYY], true);
-    float AspectRatio = axes.minor / axes.major;
-
-    float index = 1.0;
-    float bn = 1.9992*index - 0.3271;
-
-    // the integral of a Sersic has an analytical form as follows:
-    float logGamma = lgamma(2.0*index);
-    float bnFactor = pow(bn, 2.0*index);
-    float norm = 2.0 * M_PI * PS_SQR(axes.major) * index * exp(bn) * exp(logGamma) / bnFactor;
-    
-    psF64 Flux = PAR[PM_PAR_I0] * norm * AspectRatio;
-
-    return(Flux);
+
+    // static value for EXP:
+    float norm = 0.34578; // \int exp(-kappa*sqrt(z)) r dr
+
+    float flux = PAR[PM_PAR_I0] * 2.0 * M_PI * axes.major * axes.minor * norm;
+
+    return(flux);
 }
 
@@ -345,11 +332,18 @@
     pmModelParamsToAxes (&axes, PAR[PM_PAR_SXX], PAR[PM_PAR_SXY], PAR[PM_PAR_SYY], true);
 
-    // f = Io exp(-sqrt(z)) -> sqrt(z) = ln(Io/f)
-    psF64 zn = log(PAR[PM_PAR_I0] / flux);
-    psF64 radius = axes.major * sqrt (2.0) * zn;
+    // static value for EXP:
+    float kappa = KAPPA_EXP;
+
+    // f = Io exp(-kappa*sqrt(z)) -> sqrt(z) = ln(Io/f) / kappa
+    psF64 zn = log(PAR[PM_PAR_I0] / flux) / kappa;
+    psF64 radius = axes.major * zn;
 
     psAssert (isfinite(radius), "fix this code: radius should not be nan for Io = %f, flux = %f, major = %f (%f, %f, %f)", 
 	      PAR[PM_PAR_I0], flux, axes.major, PAR[PM_PAR_SXX], PAR[PM_PAR_SXY], PAR[PM_PAR_SYY]);
     return (radius);
+}
+
+psF64 PM_MODEL_SET_FWHM (const psVector *params, psF64 sigma) {
+  return (NAN);
 }
 
@@ -375,5 +369,5 @@
     // the 2D PSF model fits polarization terms (E0,E1,E2)
     // convert to shape terms (SXX,SYY,SXY)
-    bool useReff = pmModelUseReff (modelPSF->type);
+    bool useReff = modelPSF->class->useReff;
     if (!pmPSF_FitToModel (out, 0.1, useReff)) {
         psTrace("psModules.objects", 5, "Failed to fit object at (r,c) = (%.1f,%.1f)", in[PM_PAR_YPOS], in[PM_PAR_XPOS]);
@@ -429,5 +423,5 @@
     // convert to shape terms (SXX,SYY,SXY)
     // XXX user-defined value for limit?
-    bool useReff = pmModelUseReff (model->type);
+    bool useReff = model->class->useReff;
     if (!pmPSF_FitToModel (PAR, 0.1, useReff)) {
         psTrace ("psModules.objects", 3, "Failed to fit object at (r,c) = (%.1f,%.1f)", Xo, Yo);
@@ -501,2 +495,66 @@
     return;
 }
+
+# if (0)
+void bilin_inter_function () {
+	// first, use Rmajor and index to find the central pixel flux (fraction of total flux)
+	psEllipseAxes axes;
+	pmModelParamsToAxes (&axes, PAR[PM_PAR_SXX], PAR[PM_PAR_SXY], PAR[PM_PAR_SYY], true);
+
+	// get the central pixel flux from the lookup table
+	float xPix = (axes.major - centralPixelXo) / centralPixeldX;
+	xPix = PS_MIN (PS_MAX(xPix, 0), centralPixelNX - 1);
+	float yPix = (index - centralPixelYo) / centralPixeldY;
+	yPix = PS_MIN (PS_MAX(yPix, 0), centralPixelNY - 1);
+
+	// the integral of a Sersic has an analytical form as follows:
+	float logGamma = lgamma(2.0*index);
+	float bnFactor = pow(bn, 2.0*index);
+	float norm = 2.0 * M_PI * PS_SQR(axes.major) * index * exp(bn) * exp(logGamma) / bnFactor;
+
+	// XXX interpolate to get the value
+	// XXX for the moment, just integerize
+	// XXX I need to multiply by the integrated flux to get the flux in the central pixel
+	float Vcenter = centralPixel[(int)yPix][(int)xPix] * norm;
+	
+	float px1 = 1.0 / PAR[PM_PAR_SXX];
+	float py1 = 1.0 / PAR[PM_PAR_SYY];
+	float z10 = PS_SQR(px1);
+	float z01 = PS_SQR(py1);
+
+	// which pixels do we need for this interpolation?
+	// (I do not keep state information, so I don't know anything about other evaluations of nearby pixels...)
+	if ((X >= 0) && (Y >= 0)) {
+	    float z11 = z10 + z01 + PAR[PM_PAR_SXY]; // X * Y positive
+	    float V00 = Vcenter;
+	    float V10 = Io*exp(-bn*pow(z10,par7));
+	    float V01 = Io*exp(-bn*pow(z01,par7));
+	    float V11 = Io*exp(-bn*pow(z11,par7));
+	    f1 = interpolatePixels(V00, V10, V01, V11, X, Y);
+	}
+	if ((X < 0) && (Y >= 0)) {
+	    float z11 = z10 + z01 - PAR[PM_PAR_SXY]; // X * Y negative
+	    float V00 = Io*exp(-bn*pow(z10,par7));
+	    float V10 = Vcenter;
+	    float V01 = Io*exp(-bn*pow(z11,par7));
+	    float V11 = Io*exp(-bn*pow(z01,par7));
+	    f1 = interpolatePixels(V00, V10, V01, V11, (1.0 + X), Y);
+	}
+	if ((X >= 0) && (Y < 0)) {
+	    float z11 = z10 + z01 - PAR[PM_PAR_SXY]; // X * Y negative
+	    float V00 = Io*exp(-bn*pow(z01,par7));
+	    float V10 = Io*exp(-bn*pow(z11,par7));
+	    float V01 = Vcenter;
+	    float V11 = Io*exp(-bn*pow(z10,par7));
+	    f1 = interpolatePixels(V00, V10, V01, V11, X, (1.0 + Y));
+	}
+	if ((X < 0) && (Y < 0)) {
+	    float z11 = z10 + z01 + PAR[PM_PAR_SXY]; // X * Y positive
+	    float V00 = Io*exp(-bn*pow(z11,par7));
+	    float V10 = Io*exp(-bn*pow(z10,par7));
+	    float V01 = Io*exp(-bn*pow(z01,par7));
+	    float V11 = Vcenter;
+	    f1 = interpolatePixels(V00, V10, V01, V11, (1.0 + X), (1.0 + Y));
+	}
+}
+# endif
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_EXP.h
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_EXP.h	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_EXP.h	(revision 37066)
@@ -8,4 +8,5 @@
 psF64 pmModelFlux_EXP(const psVector *params);
 psF64 pmModelRadius_EXP(const psVector *params, psF64 flux);
+psF64 pmModelSetFWHM_EXP(const psVector *params, psF64 flux);
 bool pmModelFromPSF_EXP(pmModel *modelPSF, pmModel *modelFLT, const pmPSF *psf);
 bool  pmModelParamsFromPSF_EXP(pmModel *model, const pmPSF *psf, float Xo, float Yo, float Io);
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_GAUSS.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_GAUSS.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_GAUSS.c	(revision 37066)
@@ -33,11 +33,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceFitModel.h"
@@ -53,4 +54,5 @@
 # define PM_MODEL_GUESS           pmModelGuess_GAUSS
 # define PM_MODEL_LIMITS          pmModelLimits_GAUSS
+# define PM_MODEL_SET_FWHM        pmModelSetFWHM_GAUSS
 # define PM_MODEL_RADIUS          pmModelRadius_GAUSS
 # define PM_MODEL_FROM_PSF        pmModelFromPSF_GAUSS
@@ -61,5 +63,5 @@
 // Lax parameter limits
 static float paramsMinLax[] = { -1.0e3, 1.0e-2, -100, -100, 0.5, 0.5, -1.0 };
-static float paramsMaxLax[] = { 1.0e5, 1.0e8, 1.0e4, 1.0e4, 100, 100, 1.0 };
+static float paramsMaxLax[] = { 1.0e5, 1.0e9, 1.0e5, 1.0e5, 100, 100, 1.0 };
 
 // Moderate parameter limits
@@ -256,4 +258,8 @@
 }
 
+psF64 PM_MODEL_SET_FWHM (const psVector *params, psF64 sigma) {
+    return (2.35482004503*sigma);
+}
+
 // construct the PSF model from the FLT model and the psf
 bool PM_MODEL_FROM_PSF (pmModel *modelPSF, pmModel *modelFLT, const pmPSF *psf)
@@ -278,5 +284,5 @@
     // the 2D PSF model fits polarization terms (E0,E1,E2)
     // convert to shape terms (SXX,SYY,SXY)
-    bool useReff = pmModelUseReff (modelPSF->type);
+    bool useReff = modelPSF->class->useReff;
     if (!pmPSF_FitToModel (out, 0.1, useReff)) {
         psTrace ("psModules.objects", 3, "Failed to fit object at (r,c) = (%.1f,%.1f)", in[PM_PAR_YPOS], in[PM_PAR_XPOS]);
@@ -330,5 +336,5 @@
     // the 2D PSF model fits polarization terms (E0,E1,E2)
     // convert to shape terms (SXX,SYY,SXY)
-    bool useReff = pmModelUseReff (model->type);
+    bool useReff = model->class->useReff;
     if (!pmPSF_FitToModel (PAR, 0.1, useReff)) {
         psTrace ("psModules.objects", 3, "Failed to fit object at (r,c) = (%.1f,%.1f)", Xo, Yo);
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_GAUSS.h
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_GAUSS.h	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_GAUSS.h	(revision 37066)
@@ -8,4 +8,5 @@
 psF64 pmModelFlux_GAUSS(const psVector *params);
 psF64 pmModelRadius_GAUSS(const psVector *params, psF64 flux);
+psF64 pmModelSetFWHM_GAUSS(const psVector *params, psF64 flux);
 bool pmModelFromPSF_GAUSS(pmModel *modelPSF, pmModel *modelFLT, const pmPSF *psf);
 bool  pmModelParamsFromPSF_GAUSS(pmModel *model, const pmPSF *psf, float Xo, float Yo, float Io);
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_PGAUSS.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_PGAUSS.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_PGAUSS.c	(revision 37066)
@@ -33,11 +33,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceFitModel.h"
@@ -54,4 +55,5 @@
 # define PM_MODEL_LIMITS          pmModelLimits_PGAUSS
 # define PM_MODEL_RADIUS          pmModelRadius_PGAUSS
+# define PM_MODEL_SET_FWHM        pmModelSetFWHM_PGAUSS
 # define PM_MODEL_FROM_PSF        pmModelFromPSF_PGAUSS
 # define PM_MODEL_PARAMS_FROM_PSF pmModelParamsFromPSF_PGAUSS
@@ -61,5 +63,5 @@
 // Lax parameter limits
 static float paramsMinLax[] = { -1.0e3, 1.0e-2, -100, -100, 0.5, 0.5, -1.0 };
-static float paramsMaxLax[] = { 1.0e5, 1.0e8, 1.0e4, 1.0e4, 100, 100, 1.0 };
+static float paramsMaxLax[] = { 1.0e5, 1.0e9, 1.0e5, 1.0e5, 100, 100, 1.0 };
 
 // Moderate parameter limits
@@ -323,4 +325,9 @@
 }
 
+// scale factor is constant for PGAUSS, I found it with the fwhm.sh script
+psF64 PM_MODEL_SET_FWHM (const psVector *params, psF64 sigma) {
+    return (3.0063103*sigma);
+}
+
 bool PM_MODEL_FROM_PSF (pmModel *modelPSF, pmModel *modelFLT, const pmPSF *psf)
 {
@@ -343,5 +350,5 @@
     // the 2D PSF model fits polarization terms (E0,E1,E2)
     // convert to shape terms (SXX,SYY,SXY)
-    bool useReff = pmModelUseReff (modelPSF->type);
+    bool useReff = modelPSF->class->useReff;
     if (!pmPSF_FitToModel (out, 0.1, useReff)) {
         psTrace("psModules.objects", 5, "Failed to fit object at (r,c) = (%.1f,%.1f)", in[PM_PAR_YPOS], in[PM_PAR_XPOS]);
@@ -395,5 +402,5 @@
     // the 2D PSF model fits polarization terms (E0,E1,E2)
     // convert to shape terms (SXX,SYY,SXY)
-    bool useReff = pmModelUseReff (model->type);
+    bool useReff = model->class->useReff;
     if (!pmPSF_FitToModel (PAR, 0.1, useReff)) {
         psTrace ("psModules.objects", 3, "Failed to fit object at (r,c) = (%.1f,%.1f)", Xo, Yo);
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_PGAUSS.h
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_PGAUSS.h	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_PGAUSS.h	(revision 37066)
@@ -8,4 +8,5 @@
 psF64 pmModelFlux_PGAUSS(const psVector *params);
 psF64 pmModelRadius_PGAUSS(const psVector *params, psF64 flux);
+psF64 pmModelSetFWHM_PGAUSS(const psVector *params, psF64 flux);
 bool pmModelFromPSF_PGAUSS(pmModel *modelPSF, pmModel *modelFLT, const pmPSF *psf);
 bool  pmModelParamsFromPSF_PGAUSS(pmModel *model, const pmPSF *psf, float Xo, float Yo, float Io);
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_PS1_V1.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_PS1_V1.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_PS1_V1.c	(revision 37066)
@@ -35,11 +35,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceFitModel.h"
@@ -56,4 +57,5 @@
 # define PM_MODEL_LIMITS          pmModelLimits_PS1_V1
 # define PM_MODEL_RADIUS          pmModelRadius_PS1_V1
+# define PM_MODEL_SET_FWHM        pmModelSetFWHM_PS1_V1
 # define PM_MODEL_FROM_PSF        pmModelFromPSF_PS1_V1
 # define PM_MODEL_PARAMS_FROM_PSF pmModelParamsFromPSF_PS1_V1
@@ -70,15 +72,15 @@
 // Lax parameter limits
 static float paramsMinLax[] = { -1.0e3, 1.0e-2, -100, -100, 0.5, 0.5, -1.0, -1.0 };
-static float paramsMaxLax[] = { 1.0e5, 1.0e8, 1.0e4, 1.0e4, 100, 100, 1.0, 20.0 };
+static float paramsMaxLax[] = { 1.0e5, 1.0e9, 1.0e5, 1.0e5, 100, 100, 1.0, 20.0 };
 
 // Moderate parameter limits
 // Tolerate a small divot (k < 0)
 static float paramsMinModerate[] = { -1.0e3, 1.0e-2, -100, -100, 0.5, 0.5, -1.0, -0.05 };
-static float paramsMaxModerate[] = { 1.0e5, 1.0e8, 1.0e4, 1.0e4, 100, 100, 1.0, 20.0 };
+static float paramsMaxModerate[] = { 1.0e5, 1.0e9, 1.0e5, 1.0e5, 100, 100, 1.0, 20.0 };
 
 // Strict parameter limits
 // k = PAR_7 < 0 is very undesirable (big divot in the middle)
 static float paramsMinStrict[] = { -1.0e3, 1.0e-2, -100, -100, 0.5, 0.5, -1.0, 0.0 };
-static float paramsMaxStrict[] = { 1.0e5, 1.0e8, 1.0e4, 1.0e4, 100, 100, 1.0, 20.0 };
+static float paramsMaxStrict[] = { 1.0e5, 1.0e9, 1.0e5, 1.0e5, 100, 100, 1.0, 20.0 };
 
 // Parameter limits to use
@@ -335,7 +337,54 @@
 }
 
+// I used the script in models/fwhm.sh to generate the trend of FWHM scaling vs the K value
+// FWHM = Scale * Sigma (not that PAR[PM_PAR_SXX] = sigma * sqrt(2)
+//  K : z_hm  : FWHM
+//  0 : 1.000 : 2.83
+//  1 : 0.597 : 2.19
+//  2 : 0.396 : 1.78
+//  3 : 0.291 : 1.53
+//  4 : 0.232 : 1.36
+//  5 : 0.198 : 1.26
+//  6 : 0.169 : 1.16
+//  7 : 0.142 : 1.07
+//  8 : 0.124 : 0.99
+//  9 : 0.118 : 0.97
+// 10 : 0.106 : 0.92
+// 11 : 0.092 : 0.86
+// 12 : 0.091 : 0.85
+// 13 : 0.080 : 0.80
+// 14 : 0.078 : 0.79
+// 15 : 0.073 : 0.76
+// 16 : 0.063 : 0.71
+// 17 : 0.068 : 0.74
+// 18 : 0.056 : 0.67
+// 19 : 0.058 : 0.68
+
+// static float PS1_V1_Core[] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0};
+static float PS1_V1_Scale[] = {2.83, 2.19, 1.78, 1.53, 1.36, 1.26, 1.16, 1.07, 0.99, 0.97, 0.92, 0.86, 0.85, 0.80, 0.79, 0.76, 0.71, 0.74, 0.67, 0.68};
+
+psF64 PM_MODEL_SET_FWHM (const psVector *params, psF64 sigma) {
+
+    psF32 *PAR = params->data.F32;
+
+    float core = PAR[PM_PAR_7];
+
+    if (!isfinite(core)) return (2.0*M_SQRT2*sigma);
+
+    // if PS1_V1_Core is defined as a set of integer steps, so we can simplify:
+    int binCore = MAX(0, MIN (19, (int)core));
+
+    float scale = NAN;
+    if (binCore == 0) {
+	scale = (core - binCore + 0) * (PS1_V1_Scale[binCore + 1] - PS1_V1_Scale[binCore + 0]) + PS1_V1_Scale[binCore + 0];
+    } else {
+	scale = (core - binCore - 1) * (PS1_V1_Scale[binCore + 0] - PS1_V1_Scale[binCore - 1]) + PS1_V1_Scale[binCore - 1];
+    }
+
+    return (scale * sigma);
+}
+
 bool PM_MODEL_FROM_PSF (pmModel *modelPSF, pmModel *modelFLT, const pmPSF *psf)
 {
-
     psF32 *out = modelPSF->params->data.F32;
     psF32 *in  = modelFLT->params->data.F32;
@@ -356,5 +405,5 @@
     // the 2D PSF model fits polarization terms (E0,E1,E2)
     // convert to shape terms (SXX,SYY,SXY)
-    bool useReff = pmModelUseReff (modelPSF->type);
+    bool useReff = modelPSF->class->useReff;
     if (!pmPSF_FitToModel (out, 0.1, useReff)) {
         psTrace("psModules.objects", 5, "Failed to fit object at (r,c) = (%.1f,%.1f)", in[PM_PAR_YPOS], in[PM_PAR_XPOS]);
@@ -410,5 +459,5 @@
     // convert to shape terms (SXX,SYY,SXY)
     // XXX user-defined value for limit?
-    bool useReff = pmModelUseReff (model->type);
+    bool useReff = model->class->useReff;
     if (!pmPSF_FitToModel (PAR, 0.1, useReff)) {
         psTrace ("psModules.objects", 3, "Failed to fit object at (r,c) = (%.1f,%.1f)", Xo, Yo);
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_PS1_V1.h
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_PS1_V1.h	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_PS1_V1.h	(revision 37066)
@@ -8,4 +8,5 @@
 psF64 pmModelFlux_PS1_V1(const psVector *params);
 psF64 pmModelRadius_PS1_V1(const psVector *params, psF64 flux);
+psF64 pmModelSetFWHM_PS1_V1(const psVector *params, psF64 flux);
 bool pmModelFromPSF_PS1_V1(pmModel *modelPSF, pmModel *modelFLT, const pmPSF *psf);
 bool  pmModelParamsFromPSF_PS1_V1(pmModel *model, const pmPSF *psf, float Xo, float Yo, float Io);
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_QGAUSS.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_QGAUSS.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_QGAUSS.c	(revision 37066)
@@ -35,11 +35,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceFitModel.h"
@@ -56,4 +57,5 @@
 # define PM_MODEL_LIMITS          pmModelLimits_QGAUSS
 # define PM_MODEL_RADIUS          pmModelRadius_QGAUSS
+# define PM_MODEL_SET_FWHM        pmModelSetFWHM_QGAUSS
 # define PM_MODEL_FROM_PSF        pmModelFromPSF_QGAUSS
 # define PM_MODEL_PARAMS_FROM_PSF pmModelParamsFromPSF_QGAUSS
@@ -70,15 +72,15 @@
 // Lax parameter limits
 static float paramsMinLax[] = { -1.0e3, 1.0e-2, -100, -100, 0.5, 0.5, -1.0, -1.0 };
-static float paramsMaxLax[] = { 1.0e5, 1.0e8, 1.0e4, 1.0e4, 100, 100, 1.0, 20.0 };
+static float paramsMaxLax[] = { 1.0e5, 1.0e9, 1.0e5, 1.0e5, 100, 100, 1.0, 20.0 };
 
 // Moderate parameter limits
 // Tolerate a small divot (k < 0)
 static float paramsMinModerate[] = { -1.0e3, 1.0e-2, -100, -100, 0.5, 0.5, -1.0, -0.05 };
-static float paramsMaxModerate[] = { 1.0e5, 1.0e8, 1.0e4, 1.0e4, 100, 100, 1.0, 20.0 };
+static float paramsMaxModerate[] = { 1.0e5, 1.0e9, 1.0e5, 1.0e5, 100, 100, 1.0, 20.0 };
 
 // Strict parameter limits
 // k = PAR_7 < 0 is very undesirable (big divot in the middle)
 static float paramsMinStrict[] = { -1.0e3, 1.0e-2, -100, -100, 0.5, 0.5, -1.0, 0.0 };
-static float paramsMaxStrict[] = { 1.0e5, 1.0e8, 1.0e4, 1.0e4, 100, 100, 1.0, 20.0 };
+static float paramsMaxStrict[] = { 1.0e5, 1.0e9, 1.0e5, 1.0e5, 100, 100, 1.0, 20.0 };
 
 // Parameter limits to use
@@ -336,4 +338,52 @@
 }
 
+// I used the script in models/fwhm.sh to generate the trend of FWHM scaling vs the K value
+// FWHM = Scale * Sigma (not that PAR[PM_PAR_SXX] = sigma * sqrt(2)
+//  K : z_hm  : FWHM
+//  0 : 1.000 : 2.83
+//  1 : 0.648 : 2.28
+//  2 : 0.430 : 1.85
+//  3 : 0.310 : 1.58
+//  4 : 0.244 : 1.40
+//  5 : 0.200 : 1.26
+//  6 : 0.165 : 1.15
+//  7 : 0.149 : 1.09
+//  8 : 0.125 : 1.00
+//  9 : 0.116 : 0.96
+// 10 : 0.101 : 0.90
+// 11 : 0.095 : 0.87
+// 12 : 0.083 : 0.82
+// 13 : 0.082 : 0.81
+// 14 : 0.080 : 0.80
+// 15 : 0.074 : 0.77
+// 16 : 0.064 : 0.71
+// 17 : 0.068 : 0.74
+// 18 : 0.057 : 0.67
+// 19 : 0.058 : 0.68
+
+// static float QGAUSS_Core[] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0};
+static float QGAUSS_Scale[] = {2.83, 2.28, 1.85, 1.58, 1.40, 1.26, 1.15, 1.09, 1.00, 0.96, 0.90, 0.87, 0.82, 0.81, 0.80, 0.77, 0.71, 0.74, 0.67, 0.68};
+
+psF64 PM_MODEL_SET_FWHM (const psVector *params, psF64 sigma) {
+
+    psF32 *PAR = params->data.F32;
+
+    float core = PAR[PM_PAR_7];
+
+    if (!isfinite(core)) return (2.0*M_SQRT2*sigma);
+
+    // QGAUSS_Core is defined as a set of integer steps, so we can simplify:
+    int binCore = MAX(0, MIN (19, (int)core));
+
+    float scale = NAN;
+    if (binCore == 0) {
+	scale = (core - binCore + 0) * (QGAUSS_Scale[binCore + 1] - QGAUSS_Scale[binCore + 0]) + QGAUSS_Scale[binCore + 0];
+    } else {
+	scale = (core - binCore - 1) * (QGAUSS_Scale[binCore + 0] - QGAUSS_Scale[binCore - 1]) + QGAUSS_Scale[binCore - 1];
+    }
+
+    return (scale * sigma);
+}
+
 bool PM_MODEL_FROM_PSF (pmModel *modelPSF, pmModel *modelFLT, const pmPSF *psf)
 {
@@ -357,5 +407,5 @@
     // the 2D PSF model fits polarization terms (E0,E1,E2)
     // convert to shape terms (SXX,SYY,SXY)
-    bool useReff = pmModelUseReff (modelPSF->type);
+    bool useReff = modelPSF->class->useReff;
     if (!pmPSF_FitToModel (out, 0.1, useReff)) {
         psTrace("psModules.objects", 5, "Failed to fit object at (r,c) = (%.1f,%.1f)", in[PM_PAR_YPOS], in[PM_PAR_XPOS]);
@@ -415,5 +465,5 @@
     // the 2D PSF model fits polarization terms (E0,E1,E2)
     // convert to shape terms (SXX,SYY,SXY)
-    bool useReff = pmModelUseReff (model->type);
+    bool useReff = model->class->useReff;
     if (!pmPSF_FitToModel (PAR, 0.1, useReff)) {
         psTrace ("psModules.objects", 3, "Failed to fit object at (r,c) = (%.1f,%.1f)", Xo, Yo);
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_QGAUSS.h
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_QGAUSS.h	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_QGAUSS.h	(revision 37066)
@@ -8,4 +8,5 @@
 psF64 pmModelFlux_QGAUSS(const psVector *params);
 psF64 pmModelRadius_QGAUSS(const psVector *params, psF64 flux);
+psF64 pmModelSetFWHM_QGAUSS(const psVector *params, psF64 flux);
 bool pmModelFromPSF_QGAUSS(pmModel *modelPSF, pmModel *modelFLT, const pmPSF *psf);
 bool  pmModelParamsFromPSF_QGAUSS(pmModel *model, const pmPSF *psf, float Xo, float Yo, float Io);
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_RGAUSS.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_RGAUSS.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_RGAUSS.c	(revision 37066)
@@ -34,11 +34,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceFitModel.h"
@@ -55,4 +56,5 @@
 # define PM_MODEL_LIMITS          pmModelLimits_RGAUSS
 # define PM_MODEL_RADIUS          pmModelRadius_RGAUSS
+# define PM_MODEL_SET_FWHM        pmModelSetFWHM_RGAUSS
 # define PM_MODEL_FROM_PSF        pmModelFromPSF_RGAUSS
 # define PM_MODEL_PARAMS_FROM_PSF pmModelParamsFromPSF_RGAUSS
@@ -66,5 +68,5 @@
 // Lax parameter limits
 static float paramsMinLax[] = { -1.0e3, 1.0e-2, -100, -100, 0.5, 0.5, -1.0, 1.25 };
-static float paramsMaxLax[] = { 1.0e5, 1.0e8, 1.0e4, 1.0e4, 100, 100, 1.0, 4.0 };
+static float paramsMaxLax[] = { 1.0e5, 1.0e9, 1.0e5, 1.0e5, 100, 100, 1.0, 4.0 };
 
 // Moderate parameter limits
@@ -329,4 +331,8 @@
 }
 
+psF64 PM_MODEL_SET_FWHM (const psVector *params, psF64 sigma) {
+  return (NAN);
+}
+
 bool PM_MODEL_FROM_PSF (pmModel *modelPSF, pmModel *modelFLT, const pmPSF *psf)
 {
@@ -350,5 +356,5 @@
     // the 2D PSF model fits polarization terms (E0,E1,E2)
     // convert to shape terms (SXX,SYY,SXY)
-    bool useReff = pmModelUseReff (modelPSF->type);
+    bool useReff = modelPSF->class->useReff;
     if (!pmPSF_FitToModel (out, 0.1, useReff)) {
         psTrace("psModules.objects", 5, "Failed to fit object at (r,c) = (%.1f,%.1f)", in[PM_PAR_YPOS], in[PM_PAR_XPOS]);
@@ -403,5 +409,5 @@
     // the 2D PSF model fits polarization terms (E0,E1,E2)
     // convert to shape terms (SXX,SYY,SXY)
-    bool useReff = pmModelUseReff (model->type);
+    bool useReff = model->class->useReff;
     if (!pmPSF_FitToModel (PAR, 0.1, useReff)) {
         psTrace ("psModules.objects", 3, "Failed to fit object at (r,c) = (%.1f,%.1f)", Xo, Yo);
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_RGAUSS.h
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_RGAUSS.h	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_RGAUSS.h	(revision 37066)
@@ -8,4 +8,5 @@
 psF64 pmModelFlux_RGAUSS(const psVector *params);
 psF64 pmModelRadius_RGAUSS(const psVector *params, psF64 flux);
+psF64 pmModelSetFWHM_RGAUSS(const psVector *params, psF64 flux);
 bool pmModelFromPSF_RGAUSS(pmModel *modelPSF, pmModel *modelFLT, const pmPSF *psf);
 bool  pmModelParamsFromPSF_RGAUSS(pmModel *model, const pmPSF *psf, float Xo, float Yo, float Io);
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_SERSIC.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_SERSIC.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_SERSIC.c	(revision 37066)
@@ -20,5 +20,5 @@
    * note that a Sersic model is usually defined in terms of R_e, the half-light radius.  This
      construction does not include a factor of 2 in the X^2 term, etc, like for a Gaussian.
-     Conversion from SXX, SYY, SXY to R_major, R_minor, theta can be done by using setting:
+     Conversion from SXX, SYY, SXY to R_major, R_minor, theta can be done by using:
      shape.sx = SXX / sqrt(2), shape.sy = SYY / sqrt(2), shape.sxy = SXY, then calling
      psEllipseShapeToAxes, and multiplying the values of axes.major, axes.minor by sqrt(2)
@@ -43,11 +43,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceFitModel.h"
@@ -55,4 +56,5 @@
 #include "pmPSFtry.h"
 #include "pmDetections.h"
+#include "pmModel_CentralPixel.h"
 
 #include "pmModel_SERSIC.h"
@@ -64,4 +66,5 @@
 # define PM_MODEL_LIMITS          pmModelLimits_SERSIC
 # define PM_MODEL_RADIUS          pmModelRadius_SERSIC
+# define PM_MODEL_SET_FWHM        pmModelSetFWHM_SERSIC
 # define PM_MODEL_FROM_PSF        pmModelFromPSF_SERSIC
 # define PM_MODEL_PARAMS_FROM_PSF pmModelParamsFromPSF_SERSIC
@@ -74,6 +77,6 @@
 
 // Lax parameter limits
-static float paramsMinLax[] = { -1.0e3, 1.0e-2, -100, -100, 0.001, 0.001, -1.0, 0.05 };
-static float paramsMaxLax[] = { 1.0e5, 1.0e8, 1.0e4, 1.0e4, 100, 100, 1.0, 4.0 };
+static float paramsMinLax[] = { -1.0e3, 1.0e-2, -100, -100, 0.001, 0.001, -1.0, 0.0625 };
+static float paramsMaxLax[] = { 1.0e5, 1.0e9, 1.0e5, 1.0e5, 100, 100, 1.0, 1.0 };
 
 // Moderate parameter limits
@@ -88,9 +91,9 @@
 static float *paramsMinUse = paramsMinLax;
 static float *paramsMaxUse = paramsMaxLax;
-static float betaUse[] = { 1000, 3e6, 5, 5, 1.0, 1.0, 0.5, 2.0 };
+static float betaUse[] = { 2, 3e6, 5, 5, 10.0, 10.0, 0.5, 1.0};
 
 static bool limitsApply = true;         // Apply limits?
 
-# include "pmModel_SERSIC.CP.h"
+// # include "pmModel_SERSIC.CP.h"
 
 psF32 PM_MODEL_FUNC (psVector *deriv,
@@ -111,91 +114,33 @@
     psAssert (z >= 0, "do not allow negative z values in model");
 
-    float index = 0.5 / PAR[PM_PAR_7];
-    float par7 = PAR[PM_PAR_7];
-    float bn = 1.9992*index - 0.3271;
-    float Io = exp(bn);
-
-    psF32 f2 = bn*pow(z,par7);
-    psF32 f1 = Io*exp(-f2);
+    float Sindex = 0.5 / PAR[PM_PAR_7];
+    float kappa = pmSersicKappa (Sindex);
+
+    float q = kappa*pow(z,PAR[PM_PAR_7]);
+    psF32 f0 = exp(-q);
+
+    assert (isfinite(q));
 
     psF32 radius = hypot(X, Y);
-    if (radius < 1.0) {
-
-	// ** use bilinear interpolation to the given location from the 4 surrounding pixels centered on the object center
-
-	// first, use Rmajor and index to find the central pixel flux (fraction of total flux)
-	psEllipseAxes axes;
-	pmModelParamsToAxes (&axes, PAR[PM_PAR_SXX], PAR[PM_PAR_SXY], PAR[PM_PAR_SYY], true);
-
-	// get the central pixel flux from the lookup table
-	float xPix = (axes.major - centralPixelXo) / centralPixeldX;
-	xPix = PS_MIN (PS_MAX(xPix, 0), centralPixelNX - 1);
-	float yPix = (index - centralPixelYo) / centralPixeldY;
-	yPix = PS_MIN (PS_MAX(yPix, 0), centralPixelNY - 1);
-
-	// the integral of a Sersic has an analytical form as follows:
-	float logGamma = lgamma(2.0*index);
-	float bnFactor = pow(bn, 2.0*index);
-	float norm = 2.0 * M_PI * PS_SQR(axes.major) * index * exp(bn) * exp(logGamma) / bnFactor;
-
-	// XXX interpolate to get the value
-	// XXX for the moment, just integerize
-	// XXX I need to multiply by the integrated flux to get the flux in the central pixel
-	float Vcenter = centralPixel[(int)yPix][(int)xPix] * norm;
-	
-	float px1 = 1.0 / PAR[PM_PAR_SXX];
-	float py1 = 1.0 / PAR[PM_PAR_SYY];
-	float z10 = PS_SQR(px1);
-	float z01 = PS_SQR(py1);
-
-	// which pixels do we need for this interpolation?
-	// (I do not keep state information, so I don't know anything about other evaluations of nearby pixels...)
-	if ((X >= 0) && (Y >= 0)) {
-	    float z11 = z10 + z01 + PAR[PM_PAR_SXY]; // X * Y positive
-	    float V00 = Vcenter;
-	    float V10 = Io*exp(-bn*pow(z10,par7));
-	    float V01 = Io*exp(-bn*pow(z01,par7));
-	    float V11 = Io*exp(-bn*pow(z11,par7));
-	    f1 = interpolatePixels(V00, V10, V01, V11, X, Y);
-	}
-	if ((X < 0) && (Y >= 0)) {
-	    float z11 = z10 + z01 - PAR[PM_PAR_SXY]; // X * Y negative
-	    float V00 = Io*exp(-bn*pow(z10,par7));
-	    float V10 = Vcenter;
-	    float V01 = Io*exp(-bn*pow(z11,par7));
-	    float V11 = Io*exp(-bn*pow(z01,par7));
-	    f1 = interpolatePixels(V00, V10, V01, V11, (1.0 + X), Y);
-	}
-	if ((X >= 0) && (Y < 0)) {
-	    float z11 = z10 + z01 - PAR[PM_PAR_SXY]; // X * Y negative
-	    float V00 = Io*exp(-bn*pow(z01,par7));
-	    float V10 = Io*exp(-bn*pow(z11,par7));
-	    float V01 = Vcenter;
-	    float V11 = Io*exp(-bn*pow(z10,par7));
-	    f1 = interpolatePixels(V00, V10, V01, V11, X, (1.0 + Y));
-	}
-	if ((X < 0) && (Y < 0)) {
-	    float z11 = z10 + z01 + PAR[PM_PAR_SXY]; // X * Y positive
-	    float V00 = Io*exp(-bn*pow(z11,par7));
-	    float V10 = Io*exp(-bn*pow(z10,par7));
-	    float V01 = Io*exp(-bn*pow(z01,par7));
-	    float V11 = Vcenter;
-	    f1 = interpolatePixels(V00, V10, V01, V11, (1.0 + X), (1.0 + Y));
-	}
-    }   
-
-    psF32 z0 = PAR[PM_PAR_I0]*f1;
-    psF32 f0 = PAR[PM_PAR_SKY] + z0;
-
-    if (!isfinite(z0)) {
-        fprintf(stderr, "z0 is not finite for %f %f %f %f %f.  Parameters: \n", X, Y, radius, z, f1);
+    if (radius <= 1.5) {
+	// Nsub ~ 10*index^2 + 1
+	psEllipseAxes axes = pmPSF_ModelToAxes(PAR, true); // SERSIC model uses Reff
+	int Nsub = 2 * ((int)(6.0*Sindex / axes.minor)) + 1;
+	Nsub = PS_MIN (Nsub, 121);
+	Nsub = PS_MAX (Nsub, 11);
+	f0 = pmModelCP_SersicSubpix (X, Y, PAR[PM_PAR_SXX], PAR[PM_PAR_SXY], PAR[PM_PAR_SYY], Sindex, Nsub);
+    }
+    if (!isfinite(f0)) {
+        fprintf(stderr, "f0 is not finite for %f %f %f %f %f.  Parameters: \n", X, Y, radius, z, q);
         fprintf(stderr, "%f %f %f %f %f %f %f %f\n", PAR[0], PAR[1], PAR[2], PAR[3], PAR[4],
             PAR[5], PAR[6], PAR[7]);
     }
-
-    assert (isfinite(f2));
+    assert (isfinite(f0));
+
+    psF32 f1 = PAR[PM_PAR_I0]*f0;
+    psF32 f = PAR[PM_PAR_SKY] + f1;
+
     assert (isfinite(f1));
-    assert (isfinite(z0));
-    assert (isfinite(f0));
+    assert (isfinite(f));
 
     if (deriv != NULL) {
@@ -203,22 +148,28 @@
 
         dPAR[PM_PAR_SKY]  = +1.0;
-        dPAR[PM_PAR_I0]   = +f1;
-
-        // gradient is infinite for z = 0; saturate at z = 0.01
-        psF32 z1 = (z < 0.01) ? z0*bn*par7*pow(0.01,par7 - 1.0) : z0*bn*par7*pow(z,par7 - 1.0);
-
-        dPAR[PM_PAR_7]    = (z < 0.01) ? -z0*pow(0.01,par7)*log(0.01) : -z0*f2*log(z);
-	dPAR[PM_PAR_7]   *= 3.0;
-
-        assert (isfinite(z1));
+        dPAR[PM_PAR_I0]   = +f0;
+
+	if (z > 0.01) {
+	  float z1 = f1*kappa*PAR[PM_PAR_7]*pow(z,PAR[PM_PAR_7]-1.0);
+	  dPAR[PM_PAR_XPOS] = +1.0*z1*(2.0*px + Y*PAR[PM_PAR_SXY]);
+	  dPAR[PM_PAR_YPOS] = +1.0*z1*(2.0*py + X*PAR[PM_PAR_SXY]);
+	  dPAR[PM_PAR_SXX]  = +2.0*z1*px*px/PAR[PM_PAR_SXX];
+	  dPAR[PM_PAR_SYY]  = +2.0*z1*py*py/PAR[PM_PAR_SYY];
+	  dPAR[PM_PAR_SXY]  = -1.0*z1*X*Y;
+	  dPAR[PM_PAR_7]    = -1.0*f1*q*log(z);
+	} else {
+	  // gradient -> 0 for z -> 0, but has undef form
+	  float z1 = f1*kappa*PAR[PM_PAR_7]*pow(z,PAR[PM_PAR_7]);
+	  dPAR[PM_PAR_XPOS] = +1.0*z1*(2.0/PAR[PM_PAR_SXX] + PAR[PM_PAR_SXY]);
+	  dPAR[PM_PAR_YPOS] = +1.0*z1*(2.0/PAR[PM_PAR_SYY] + PAR[PM_PAR_SXY]);
+	  dPAR[PM_PAR_SXX]  = +2.0*z1*px/PAR[PM_PAR_SXX]/PAR[PM_PAR_SXX];
+	  dPAR[PM_PAR_SYY]  = +2.0*z1*py/PAR[PM_PAR_SYY]/PAR[PM_PAR_SYY];
+	  dPAR[PM_PAR_SXY]  = -1.0*z1;
+	  // dPAR[PM_PAR_7]    = -1.0*f1*q*log(z + 0.0001);
+	  dPAR[PM_PAR_7]    = -1.0*f1*q*log(z + 0.0001); // factor of 16 to reduce the gain
+	}
         assert (isfinite(dPAR[PM_PAR_7]));
-
-        dPAR[PM_PAR_XPOS] = +1.0*z1*(2.0*px/PAR[PM_PAR_SXX] + Y*PAR[PM_PAR_SXY]);
-        dPAR[PM_PAR_YPOS] = +1.0*z1*(2.0*py/PAR[PM_PAR_SYY] + X*PAR[PM_PAR_SXY]);
-        dPAR[PM_PAR_SXX]  = +2.0*z1*px*px/PAR[PM_PAR_SXX]; // XXX : increase drag?
-        dPAR[PM_PAR_SYY]  = +2.0*z1*py*py/PAR[PM_PAR_SYY];
-        dPAR[PM_PAR_SXY]  = -1.0*z1*X*Y;
-    }
-    return (f0);
+    }
+    return (f);
 }
 
@@ -370,17 +321,11 @@
     psEllipseAxes axes;
     pmModelParamsToAxes (&axes, PAR[PM_PAR_SXX], PAR[PM_PAR_SXY], PAR[PM_PAR_SYY], true);
-    float AspectRatio = axes.minor / axes.major;
-
-    float index = 0.5 / PAR[PM_PAR_7];
-    float bn = 1.9992*index - 0.3271;
-
-    // the integral of a Sersic has an analytical form as follows:
-    float logGamma = lgamma(2.0*index);
-    float bnFactor = pow(bn, 2.0*index);
-    float norm = 2.0 * M_PI * PS_SQR(axes.major) * index * exp(bn) * exp(logGamma) / bnFactor;
-    
-    psF64 Flux = PAR[PM_PAR_I0] * norm * AspectRatio;
-
-    return(Flux);
+
+    float Sindex = 0.5 / PAR[PM_PAR_7];
+    float norm = pmSersicNorm (Sindex);
+
+    float flux = PAR[PM_PAR_I0] * 2.0 * M_PI * axes.major * axes.minor * norm;
+
+    return(flux);
 }
 
@@ -401,11 +346,18 @@
     pmModelParamsToAxes (&axes, PAR[PM_PAR_SXX], PAR[PM_PAR_SXY], PAR[PM_PAR_SYY], true);
 
+    float Sindex = 0.5 / PAR[PM_PAR_7];
+    float kappa = pmSersicKappa (Sindex);
+
     // f = Io exp(-z^n) -> z^n = ln(Io/f)
-    psF64 zn = log(PAR[PM_PAR_I0] / flux);
-    psF64 radius = axes.major * sqrt (2.0) * pow(zn, 0.5 / PAR[PM_PAR_7]);
+    psF64 zn = log(PAR[PM_PAR_I0] / flux) / kappa;
+    psF64 radius = axes.major * pow(zn, Sindex);
 
     psAssert (isfinite(radius), "fix this code: radius should not be nan for Io = %f, flux = %f, major = %f (%f, %f, %f), par 7 = %f", 
 	      PAR[PM_PAR_I0], flux, axes.major, PAR[PM_PAR_SXX], PAR[PM_PAR_SXY], PAR[PM_PAR_SYY], PAR[PM_PAR_7]);
     return (radius);
+}
+
+psF64 PM_MODEL_SET_FWHM (const psVector *params, psF64 sigma) {
+  return (NAN);
 }
 
@@ -431,5 +383,5 @@
     // the 2D PSF model fits polarization terms (E0,E1,E2)
     // convert to shape terms (SXX,SYY,SXY)
-    bool useReff = pmModelUseReff (modelPSF->type);
+    bool useReff = modelPSF->class->useReff;
     if (!pmPSF_FitToModel (out, 0.1, useReff)) {
         psTrace("psModules.objects", 5, "Failed to fit object at (r,c) = (%.1f,%.1f)", in[PM_PAR_YPOS], in[PM_PAR_XPOS]);
@@ -485,5 +437,5 @@
     // convert to shape terms (SXX,SYY,SXY)
     // XXX user-defined value for limit?
-    bool useReff = pmModelUseReff (model->type);
+    bool useReff = model->class->useReff;
     if (!pmPSF_FitToModel (PAR, 0.1, useReff)) {
         psTrace ("psModules.objects", 3, "Failed to fit object at (r,c) = (%.1f,%.1f)", Xo, Yo);
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_SERSIC.h
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_SERSIC.h	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_SERSIC.h	(revision 37066)
@@ -8,4 +8,5 @@
 psF64 pmModelFlux_SERSIC(const psVector *params);
 psF64 pmModelRadius_SERSIC(const psVector *params, psF64 flux);
+psF64 pmModelSetFWHM_SERSIC(const psVector *params, psF64 flux);
 bool pmModelFromPSF_SERSIC(pmModel *modelPSF, pmModel *modelFLT, const pmPSF *psf);
 bool  pmModelParamsFromPSF_SERSIC(pmModel *model, const pmPSF *psf, float Xo, float Yo, float Io);
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_TRAIL.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_TRAIL.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_TRAIL.c	(revision 37066)
@@ -5,4 +5,5 @@
  * The meaning of the parameters may thus vary depending on the specifics of the model.
  * All models which are used as a PSF representations share a few parameters, for which #
+#include "pmModelClass.h"
  * define names are listed in pmModel.h:
 
@@ -33,11 +34,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceFitModel.h"
@@ -54,4 +56,5 @@
 # define PM_MODEL_LIMITS          pmModelLimits_TRAIL
 # define PM_MODEL_RADIUS          pmModelRadius_TRAIL
+# define PM_MODEL_SET_FWHM        pmModelSetFWHM_TRAIL
 # define PM_MODEL_FROM_PSF        pmModelFromPSF_TRAIL
 # define PM_MODEL_PARAMS_FROM_PSF pmModelParamsFromPSF_TRAIL
@@ -61,5 +64,5 @@
 // Lax parameter limits 
 static float paramsMinLax[] = { -1.0e3, 1.0e-2, -1.0e2, -1.0e2,   0.5, -3.3, -0.5 };
-static float paramsMaxLax[] = {  1.0e5, 1.0e+8, +1.0e4, +1.0e4, 150.0, +3.3 , 5.0 };
+static float paramsMaxLax[] = {  1.0e5, 1.00+9, +1.0e5, +1.0e5, 150.0, +3.3 , 5.0 };
 
 // Moderate parameter limits
@@ -351,5 +354,5 @@
 
     psF32 *psfPAR  = source->modelPSF->params->data.F32;
-    bool useReff = pmModelUseReff (source->modelPSF->type);
+    bool useReff = source->modelPSF->class->useReff;
 
     psEllipseAxes psfAxes;
@@ -412,4 +415,8 @@
     // PAR_LENGTH is the unconvolved length.  add a bit for safety
     return (0.5*PAR[PM_PAR_LENGTH] + 2);
+}
+
+psF64 PM_MODEL_SET_FWHM (const psVector *params, psF64 sigma) {
+  return (NAN);
 }
 
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_TRAIL.h
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_TRAIL.h	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/models/pmModel_TRAIL.h	(revision 37066)
@@ -8,4 +8,5 @@
 psF64 pmModelFlux_TRAIL(const psVector *params);
 psF64 pmModelRadius_TRAIL(const psVector *params, psF64 flux);
+psF64 pmModelSetFWHM_TRAIL(const psVector *params, psF64 flux);
 bool pmModelFromPSF_TRAIL(pmModel *modelPSF, pmModel *modelFLT, const pmPSF *psf);
 bool  pmModelParamsFromPSF_TRAIL(pmModel *model, const pmPSF *psf, float Xo, float Yo, float Io);
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmDetEff.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmDetEff.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmDetEff.c	(revision 37066)
@@ -17,11 +17,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceFitModel.h"
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmFootprintCullPeaks.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmFootprintCullPeaks.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmFootprintCullPeaks.c	(revision 37066)
@@ -25,10 +25,10 @@
 bool dumpfootprints (pmFootprint *fp, pmFootprintSpans *fpSp);
 
- /*
-  * Examine the peaks in a pmFootprint, and throw away the ones that are not sufficiently
-  * isolated.  More precisely, for each peak find the highest coll that you'd have to traverse
-  * to reach a still higher peak --- and if that coll's more (less?) than nsigma DN below your
-  * starting point, discard the peak.
-  */
+/*
+ * Examine the peaks in a pmFootprint, and throw away the ones that are not sufficiently
+ * isolated.  More precisely, for each peak find the highest coll that you'd have to traverse
+ * to reach a still higher peak --- and if that coll's more (less?) than nsigma DN below your
+ * starting point, discard the peak.
+ */
 
 # define IN_PEAK 1
@@ -48,5 +48,5 @@
 
     if (fp->peaks == NULL || fp->peaks->n < 2) { // nothing to do
-        return PS_ERR_NONE;
+	return PS_ERR_NONE;
     }
 
@@ -91,16 +91,16 @@
 
 	// max flux is above threshold for brightest peak
-      pmPeak *maxPeak = NULL;
-      for (int i = 0; i < fp->peaks->n; i++) {
-	pmPeak *testPeak = fp->peaks->data[i];
-	float this_peak = useSmoothedImage ? testPeak->smoothFlux : testPeak->rawFlux;
+	pmPeak *maxPeak = NULL;
+	for (int i = 0; i < fp->peaks->n; i++) {
+	    pmPeak *testPeak = fp->peaks->data[i];
+	    float this_peak = useSmoothedImage ? testPeak->smoothFlux : testPeak->rawFlux;
 	
-	if (isfinite(this_peak)) {
-	  maxPeak = fp->peaks->data[i];
-	  break;
-	}
-      }
-      psAssert(maxPeak,"maxPeak was not set in these peaks");
-      //      = fp->peaks->data[0];
+	    if (isfinite(this_peak)) {
+		maxPeak = fp->peaks->data[i];
+		break;
+	    }
+	}
+	psAssert(maxPeak,"maxPeak was not set in these peaks");
+	//      = fp->peaks->data[0];
 	float maxFlux = useSmoothedImage ? maxPeak->smoothFlux : maxPeak->rawFlux;
 
@@ -130,8 +130,8 @@
 	}
 #if (0)
-        if (threshbounds->data.F32[threshbounds->n-1] > maxFlux) {
-            psWarning ("upper limit: %f does not include max flux: %f",
-                    threshbounds->data.F32[threshbounds->n-1], maxFlux);
-        }
+	if (threshbounds->data.F32[threshbounds->n-1] > maxFlux) {
+	    psWarning ("upper limit: %f does not include max flux: %f",
+		       threshbounds->data.F32[threshbounds->n-1], maxFlux);
+	}
 #endif
 	psHistogram *threshist = psHistogramAllocGeneric(threshbounds);
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmGrowthCurve.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmGrowthCurve.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmGrowthCurve.c	(revision 37066)
@@ -30,11 +30,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceFitModel.h"
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmGrowthCurveGenerate.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmGrowthCurveGenerate.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmGrowthCurveGenerate.c	(revision 37066)
@@ -37,11 +37,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceFitModel.h"
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmModel.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmModel.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmModel.c	(revision 37066)
@@ -33,10 +33,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
-#include "pmModelClass.h"
 
 static void modelFree(pmModel *tmp)
 {
     psTrace("psModules.objects", 10, "---- %s() begin ----\n", __func__);
+    if (!tmp) return;
+
     psFree(tmp->params);
     psFree(tmp->dparams);
@@ -90,13 +92,15 @@
     }
 
-    tmp->modelFunc          = class->modelFunc;
-    tmp->modelFlux          = class->modelFlux;
-    tmp->modelRadius        = class->modelRadius;
-    tmp->modelLimits        = class->modelLimits;
-    tmp->modelGuess         = class->modelGuess;
-    tmp->modelFromPSF       = class->modelFromPSF;
-    tmp->modelParamsFromPSF = class->modelParamsFromPSF;
-    tmp->modelFitStatus     = class->modelFitStatus;
-    tmp->modelSetLimits     = class->modelSetLimits;
+    tmp->class = class;
+
+    // tmp->modelFunc          = class->modelFunc;
+    // tmp->modelFlux          = class->modelFlux;
+    // tmp->modelRadius        = class->modelRadius;
+    // tmp->modelLimits        = class->modelLimits;
+    // tmp->modelGuess         = class->modelGuess;
+    // tmp->modelFromPSF       = class->modelFromPSF;
+    // tmp->modelParamsFromPSF = class->modelParamsFromPSF;
+    // tmp->modelFitStatus     = class->modelFitStatus;
+    // tmp->modelSetLimits     = class->modelSetLimits;
 
     psTrace("psModules.objects", 10, "---- %s() end ----\n", __func__);
@@ -156,5 +160,5 @@
     psF32 tmpF;
 
-    tmpF = model->modelFunc (NULL, model->params, x);
+    tmpF = model->class->modelFunc (NULL, model->params, x);
     psFree(x);
     psTrace("psModules.objects", 10, "---- %s() end ----\n", __func__);
@@ -176,5 +180,5 @@
     psF32 tmpF;
 
-    tmpF = model->modelFunc (NULL, model->params, x);
+    tmpF = model->class->modelFunc (NULL, model->params, x);
     psFree(x);
     psTrace("psModules.objects", 10, "---- %s() end ----\n", __func__);
@@ -217,9 +221,11 @@
     // the options allow us to modify various aspects of the model
     if (mode & PM_MODEL_OP_NORM) {
+	// if we are including the sky, renormalizing should force use to normalized down the sky flux
+	params->data.F32[PM_PAR_SKY] /= params->data.F32[PM_PAR_I0];
         params->data.F32[PM_PAR_I0] = 1.0;
     }
     if (!(mode & PM_MODEL_OP_SKY)) {
         params->data.F32[PM_PAR_SKY] = 0.0;
-    }
+    } 
     if (mode & PM_MODEL_OP_CENTER) {
         params->data.F32[PM_PAR_XPOS] = image->col0 + 0.5*image->numCols;
@@ -281,5 +287,5 @@
             // add in the desired components for this coordinate
             if (mode & PM_MODEL_OP_FUNC) {
-                pixelValue += model->modelFunc (NULL, params, x);
+                pixelValue += model->class->modelFunc (NULL, params, x);
             }
 
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmModel.h
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmModel.h	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmModel.h	(revision 37066)
@@ -47,14 +47,17 @@
     bool isPCM;				///< is this model fitted with PSF-convolution?
 
+    pmModelClass *class;
+
     // functions for this model which depend on the model class
-    pmModelFunc          modelFunc;
-    pmModelFlux          modelFlux;
-    pmModelRadius        modelRadius;
-    pmModelLimits        modelLimits;
-    pmModelGuessFunc     modelGuess;
-    pmModelFromPSFFunc   modelFromPSF;
-    pmModelParamsFromPSF modelParamsFromPSF;
-    pmModelFitStatusFunc modelFitStatus;
-    pmModelSetLimitsFunc modelSetLimits;
+    
+    // pmModelFunc          modelFunc;
+    // pmModelFlux          modelFlux;
+    // pmModelRadius        modelRadius;
+    // pmModelLimits        modelLimits;
+    // pmModelGuessFunc     modelGuess;
+    // pmModelFromPSFFunc   modelFromPSF;
+    // pmModelParamsFromPSF modelParamsFromPSF;
+    // pmModelFitStatusFunc modelFitStatus;
+    // pmModelSetLimitsFunc modelSetLimits;
 };
 
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmModelClass.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmModelClass.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmModelClass.c	(revision 37066)
@@ -33,7 +33,7 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 
 #include "pmErrorCodes.h"
@@ -54,16 +54,17 @@
 
 static pmModelClass defaultModels[] = {
-    {"PS_MODEL_GAUSS",        7, (pmModelFunc)pmModelFunc_GAUSS,   (pmModelFlux)pmModelFlux_GAUSS,   (pmModelRadius)pmModelRadius_GAUSS,   (pmModelLimits)pmModelLimits_GAUSS,   (pmModelGuessFunc)pmModelGuess_GAUSS,  (pmModelFromPSFFunc)pmModelFromPSF_GAUSS,  (pmModelParamsFromPSF)pmModelParamsFromPSF_GAUSS,  (pmModelFitStatusFunc)pmModelFitStatus_GAUSS,  (pmModelSetLimitsFunc)pmModelSetLimits_GAUSS  },
-    {"PS_MODEL_PGAUSS",       7, (pmModelFunc)pmModelFunc_PGAUSS,  (pmModelFlux)pmModelFlux_PGAUSS,  (pmModelRadius)pmModelRadius_PGAUSS,  (pmModelLimits)pmModelLimits_PGAUSS,  (pmModelGuessFunc)pmModelGuess_PGAUSS, (pmModelFromPSFFunc)pmModelFromPSF_PGAUSS, (pmModelParamsFromPSF)pmModelParamsFromPSF_PGAUSS, (pmModelFitStatusFunc)pmModelFitStatus_PGAUSS, (pmModelSetLimitsFunc)pmModelSetLimits_PGAUSS },
-    {"PS_MODEL_QGAUSS",       8, (pmModelFunc)pmModelFunc_QGAUSS,  (pmModelFlux)pmModelFlux_QGAUSS,  (pmModelRadius)pmModelRadius_QGAUSS,  (pmModelLimits)pmModelLimits_QGAUSS,  (pmModelGuessFunc)pmModelGuess_QGAUSS, (pmModelFromPSFFunc)pmModelFromPSF_QGAUSS, (pmModelParamsFromPSF)pmModelParamsFromPSF_QGAUSS, (pmModelFitStatusFunc)pmModelFitStatus_QGAUSS, (pmModelSetLimitsFunc)pmModelSetLimits_QGAUSS },
-    {"PS_MODEL_PS1_V1",       8, (pmModelFunc)pmModelFunc_PS1_V1,  (pmModelFlux)pmModelFlux_PS1_V1,  (pmModelRadius)pmModelRadius_PS1_V1,  (pmModelLimits)pmModelLimits_PS1_V1,  (pmModelGuessFunc)pmModelGuess_PS1_V1, (pmModelFromPSFFunc)pmModelFromPSF_PS1_V1, (pmModelParamsFromPSF)pmModelParamsFromPSF_PS1_V1, (pmModelFitStatusFunc)pmModelFitStatus_PS1_V1, (pmModelSetLimitsFunc)pmModelSetLimits_PS1_V1 },
-    {"PS_MODEL_RGAUSS",       8, (pmModelFunc)pmModelFunc_RGAUSS,  (pmModelFlux)pmModelFlux_RGAUSS,  (pmModelRadius)pmModelRadius_RGAUSS,  (pmModelLimits)pmModelLimits_RGAUSS,  (pmModelGuessFunc)pmModelGuess_RGAUSS, (pmModelFromPSFFunc)pmModelFromPSF_RGAUSS, (pmModelParamsFromPSF)pmModelParamsFromPSF_RGAUSS, (pmModelFitStatusFunc)pmModelFitStatus_RGAUSS, (pmModelSetLimitsFunc)pmModelSetLimits_RGAUSS },
-    {"PS_MODEL_SERSIC",       8, (pmModelFunc)pmModelFunc_SERSIC,  (pmModelFlux)pmModelFlux_SERSIC,  (pmModelRadius)pmModelRadius_SERSIC,  (pmModelLimits)pmModelLimits_SERSIC,  (pmModelGuessFunc)pmModelGuess_SERSIC, (pmModelFromPSFFunc)pmModelFromPSF_SERSIC, (pmModelParamsFromPSF)pmModelParamsFromPSF_SERSIC, (pmModelFitStatusFunc)pmModelFitStatus_SERSIC, (pmModelSetLimitsFunc)pmModelSetLimits_SERSIC },
-    {"PS_MODEL_EXP",          7, (pmModelFunc)pmModelFunc_EXP,     (pmModelFlux)pmModelFlux_EXP,     (pmModelRadius)pmModelRadius_EXP,     (pmModelLimits)pmModelLimits_EXP,     (pmModelGuessFunc)pmModelGuess_EXP,    (pmModelFromPSFFunc)pmModelFromPSF_EXP,    (pmModelParamsFromPSF)pmModelParamsFromPSF_EXP,    (pmModelFitStatusFunc)pmModelFitStatus_EXP,    (pmModelSetLimitsFunc)pmModelSetLimits_EXP    },
-    {"PS_MODEL_DEV",          7, (pmModelFunc)pmModelFunc_DEV,     (pmModelFlux)pmModelFlux_DEV,     (pmModelRadius)pmModelRadius_DEV,     (pmModelLimits)pmModelLimits_DEV,     (pmModelGuessFunc)pmModelGuess_DEV,    (pmModelFromPSFFunc)pmModelFromPSF_DEV,    (pmModelParamsFromPSF)pmModelParamsFromPSF_DEV,    (pmModelFitStatusFunc)pmModelFitStatus_DEV,    (pmModelSetLimitsFunc)pmModelSetLimits_DEV    },
-    {"PS_MODEL_TRAIL",        7, (pmModelFunc)pmModelFunc_TRAIL,   (pmModelFlux)pmModelFlux_TRAIL,   (pmModelRadius)pmModelRadius_TRAIL,   (pmModelLimits)pmModelLimits_TRAIL,   (pmModelGuessFunc)pmModelGuess_TRAIL,  (pmModelFromPSFFunc)pmModelFromPSF_TRAIL,  (pmModelParamsFromPSF)pmModelParamsFromPSF_TRAIL,  (pmModelFitStatusFunc)pmModelFitStatus_TRAIL,  (pmModelSetLimitsFunc)pmModelSetLimits_TRAIL  },
+    {"PS_MODEL_GAUSS",        7, 0, (pmModelFunc)pmModelFunc_GAUSS,   (pmModelFlux)pmModelFlux_GAUSS,   (pmModelRadius)pmModelRadius_GAUSS,   (pmModelSetFWHM)pmModelSetFWHM_GAUSS,   (pmModelLimits)pmModelLimits_GAUSS,   (pmModelGuessFunc)pmModelGuess_GAUSS,  (pmModelFromPSFFunc)pmModelFromPSF_GAUSS,  (pmModelParamsFromPSF)pmModelParamsFromPSF_GAUSS,  (pmModelFitStatusFunc)pmModelFitStatus_GAUSS,  (pmModelSetLimitsFunc)pmModelSetLimits_GAUSS  },
+    {"PS_MODEL_PGAUSS",       7, 0, (pmModelFunc)pmModelFunc_PGAUSS,  (pmModelFlux)pmModelFlux_PGAUSS,  (pmModelRadius)pmModelRadius_PGAUSS,  (pmModelSetFWHM)pmModelSetFWHM_PGAUSS,  (pmModelLimits)pmModelLimits_PGAUSS,  (pmModelGuessFunc)pmModelGuess_PGAUSS, (pmModelFromPSFFunc)pmModelFromPSF_PGAUSS, (pmModelParamsFromPSF)pmModelParamsFromPSF_PGAUSS, (pmModelFitStatusFunc)pmModelFitStatus_PGAUSS, (pmModelSetLimitsFunc)pmModelSetLimits_PGAUSS },
+    {"PS_MODEL_QGAUSS",       8, 0, (pmModelFunc)pmModelFunc_QGAUSS,  (pmModelFlux)pmModelFlux_QGAUSS,  (pmModelRadius)pmModelRadius_QGAUSS,  (pmModelSetFWHM)pmModelSetFWHM_QGAUSS,  (pmModelLimits)pmModelLimits_QGAUSS,  (pmModelGuessFunc)pmModelGuess_QGAUSS, (pmModelFromPSFFunc)pmModelFromPSF_QGAUSS, (pmModelParamsFromPSF)pmModelParamsFromPSF_QGAUSS, (pmModelFitStatusFunc)pmModelFitStatus_QGAUSS, (pmModelSetLimitsFunc)pmModelSetLimits_QGAUSS },
+    {"PS_MODEL_PS1_V1",       8, 0, (pmModelFunc)pmModelFunc_PS1_V1,  (pmModelFlux)pmModelFlux_PS1_V1,  (pmModelRadius)pmModelRadius_PS1_V1,  (pmModelSetFWHM)pmModelSetFWHM_PS1_V1,  (pmModelLimits)pmModelLimits_PS1_V1,  (pmModelGuessFunc)pmModelGuess_PS1_V1, (pmModelFromPSFFunc)pmModelFromPSF_PS1_V1, (pmModelParamsFromPSF)pmModelParamsFromPSF_PS1_V1, (pmModelFitStatusFunc)pmModelFitStatus_PS1_V1, (pmModelSetLimitsFunc)pmModelSetLimits_PS1_V1 },
+    {"PS_MODEL_RGAUSS",       8, 0, (pmModelFunc)pmModelFunc_RGAUSS,  (pmModelFlux)pmModelFlux_RGAUSS,  (pmModelRadius)pmModelRadius_RGAUSS,  (pmModelSetFWHM)pmModelSetFWHM_RGAUSS,  (pmModelLimits)pmModelLimits_RGAUSS,  (pmModelGuessFunc)pmModelGuess_RGAUSS, (pmModelFromPSFFunc)pmModelFromPSF_RGAUSS, (pmModelParamsFromPSF)pmModelParamsFromPSF_RGAUSS, (pmModelFitStatusFunc)pmModelFitStatus_RGAUSS, (pmModelSetLimitsFunc)pmModelSetLimits_RGAUSS },
+    {"PS_MODEL_SERSIC",       8, 1, (pmModelFunc)pmModelFunc_SERSIC,  (pmModelFlux)pmModelFlux_SERSIC,  (pmModelRadius)pmModelRadius_SERSIC,  (pmModelSetFWHM)pmModelSetFWHM_SERSIC,  (pmModelLimits)pmModelLimits_SERSIC,  (pmModelGuessFunc)pmModelGuess_SERSIC, (pmModelFromPSFFunc)pmModelFromPSF_SERSIC, (pmModelParamsFromPSF)pmModelParamsFromPSF_SERSIC, (pmModelFitStatusFunc)pmModelFitStatus_SERSIC, (pmModelSetLimitsFunc)pmModelSetLimits_SERSIC },
+    {"PS_MODEL_EXP",          7, 1, (pmModelFunc)pmModelFunc_EXP,     (pmModelFlux)pmModelFlux_EXP,     (pmModelRadius)pmModelRadius_EXP,     (pmModelSetFWHM)pmModelSetFWHM_EXP,     (pmModelLimits)pmModelLimits_EXP,     (pmModelGuessFunc)pmModelGuess_EXP,    (pmModelFromPSFFunc)pmModelFromPSF_EXP,    (pmModelParamsFromPSF)pmModelParamsFromPSF_EXP,    (pmModelFitStatusFunc)pmModelFitStatus_EXP,    (pmModelSetLimitsFunc)pmModelSetLimits_EXP    },
+    {"PS_MODEL_DEV",          7, 1, (pmModelFunc)pmModelFunc_DEV,     (pmModelFlux)pmModelFlux_DEV,     (pmModelRadius)pmModelRadius_DEV,     (pmModelSetFWHM)pmModelSetFWHM_DEV,     (pmModelLimits)pmModelLimits_DEV,     (pmModelGuessFunc)pmModelGuess_DEV,    (pmModelFromPSFFunc)pmModelFromPSF_DEV,    (pmModelParamsFromPSF)pmModelParamsFromPSF_DEV,    (pmModelFitStatusFunc)pmModelFitStatus_DEV,    (pmModelSetLimitsFunc)pmModelSetLimits_DEV    },
+    {"PS_MODEL_TRAIL",        7, 0, (pmModelFunc)pmModelFunc_TRAIL,   (pmModelFlux)pmModelFlux_TRAIL,   (pmModelRadius)pmModelRadius_TRAIL,   (pmModelSetFWHM)pmModelSetFWHM_TRAIL,   (pmModelLimits)pmModelLimits_TRAIL,   (pmModelGuessFunc)pmModelGuess_TRAIL,  (pmModelFromPSFFunc)pmModelFromPSF_TRAIL,  (pmModelParamsFromPSF)pmModelParamsFromPSF_TRAIL,  (pmModelFitStatusFunc)pmModelFitStatus_TRAIL,  (pmModelSetLimitsFunc)pmModelSetLimits_TRAIL  },
 };
 
 static pmModelClass *models = NULL;
+static psVector *modelClassLookupTable = NULL;  // translation between model types in header and here
 static int Nmodels = 0;
 
@@ -135,4 +136,6 @@
     models = NULL;
     Nmodels = 0;
+    psFree(modelClassLookupTable);
+    modelClassLookupTable = NULL;
     return;
 }
@@ -193,2 +196,80 @@
 }
 
+
+bool pmModelClassWriteHeader(psMetadata *header)
+{
+    psMetadataAddS32(header, PS_LIST_TAIL, "MTNUM", PS_META_REPLACE, "number of model types", Nmodels);
+    for (int i = 0; i < Nmodels; i++) {
+        char modelNameKey[16];
+        char modelValKey[16];
+        sprintf(modelNameKey, "MTNAM%02d", i);
+        sprintf(modelValKey,  "MTVAL%02d", i);
+        psMetadataAddStr(header, PS_LIST_TAIL, modelNameKey, PS_META_REPLACE, "", models[i].name);
+        psMetadataAddS32(header, PS_LIST_TAIL, modelValKey, PS_META_REPLACE, "", i);
+    }
+
+    return true;
+}
+
+bool pmModelClassReadHeader(psMetadata *header) {
+    psFree(modelClassLookupTable);
+
+    bool status;
+    int numHeaderModels = psMetadataLookupS32(&status, header, "MTNUM");
+    if (!status) {
+        return false;
+    }
+
+    psVector *inputTypes = psVectorAlloc(numHeaderModels, PS_TYPE_S32);
+    psVector *localTypes = psVectorAlloc(numHeaderModels, PS_TYPE_S32);
+    int max_val = -1;
+    for (int i = 0; i < numHeaderModels; i++) {
+        char modelNameKey[16];
+        char modelValKey[16];
+        sprintf(modelNameKey, "MTNAM%02d", i);
+        sprintf(modelValKey,  "MTVAL%02d", i);
+        psString thisName = psMetadataLookupStr(&status, header, modelNameKey);
+        int thisVal = psMetadataLookupS32(&status, header, modelValKey);
+        if (thisVal > max_val) {
+            max_val = thisVal;
+        }
+        inputTypes->data.S32[i] = thisVal;
+        localTypes->data.S32[i] = pmModelClassGetType(thisName);
+    }
+    if (max_val < 0) {
+        psFree(inputTypes);
+        psFree(localTypes);
+        return false;
+    }
+
+    modelClassLookupTable = psVectorAlloc(max_val + 1, PS_TYPE_S32);
+    psVectorInit(modelClassLookupTable, -1);
+
+    for (int i = 0; i < numHeaderModels; i++) {
+        int thisVal = inputTypes->data.S32[i];
+        int localVal = localTypes->data.S32[i];
+        modelClassLookupTable->data.S32[thisVal] = localVal;
+    }
+    psFree(inputTypes);
+    psFree(localTypes);
+
+    return true;
+}
+
+pmModelType pmModelClassGetLocalType(pmModelType inputType) {
+    pmModelType localType = -1;
+
+    if (modelClassLookupTable) {
+        if (inputType >= 0 && inputType < modelClassLookupTable->n) {
+            localType = modelClassLookupTable->data.S32[inputType];
+        }
+    } else {
+        // no lookup table defined
+        // for backwards compatability if inputType refers to a defined model, return it
+        if (inputType >= 0 && pmModelClassGetName(inputType)) {
+            localType = inputType;
+        }
+    }
+
+    return localType;
+}
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmModelClass.h
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmModelClass.h	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmModelClass.h	(revision 37066)
@@ -35,7 +35,9 @@
     char *name;
     int nParams;
+    bool useReff;
     pmModelFunc          modelFunc;
     pmModelFlux          modelFlux;
     pmModelRadius        modelRadius;
+    pmModelSetFWHM       modelSetFWHM;
     pmModelLimits        modelLimits;
     pmModelGuessFunc     modelGuess;
@@ -76,4 +78,10 @@
 void pmModelClassSetLimits(pmModelLimitsType type);
 
+// write keywords to header definining the model type values used by this program
+bool pmModelClassWriteHeader(psMetadata *header);
+// create a lookup table for translating input model type values to local model type values
+bool pmModelClassReadHeader(psMetadata *header);
+// translate input model type value to local value
+pmModelType pmModelClassGetLocalType(pmModelType inputType);
 
 /// @}
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmModelFuncs.h
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmModelFuncs.h	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmModelFuncs.h	(revision 37066)
@@ -36,11 +36,16 @@
 
 typedef enum {
-    PM_MODEL_STATUS_NONE         = 0x00, ///< model fit not yet attempted, no other info
-    PM_MODEL_STATUS_FITTED       = 0x01, ///< model fit completed
-    PM_MODEL_STATUS_NONCONVERGE  = 0x02, ///< model fit did not converge
-    PM_MODEL_STATUS_OFFIMAGE     = 0x04, ///< model fit drove out of range
-    PM_MODEL_STATUS_BADARGS      = 0x08, ///< model fit called with invalid args
-    PM_MODEL_STATUS_LIMITS       = 0x10, ///< model parameters hit limits
-    PM_MODEL_STATUS_WEAK_FIT     = 0x20, ///< model fit met loose tolerance, but not tight tolerance
+    PM_MODEL_STATUS_NONE           = 0x000, ///< model fit not yet attempted, no other info
+    PM_MODEL_STATUS_FITTED         = 0x001, ///< model fit completed
+    PM_MODEL_STATUS_NONCONVERGE    = 0x002, ///< model fit did not converge
+    PM_MODEL_STATUS_OFFIMAGE       = 0x004, ///< model fit drove out of range
+    PM_MODEL_STATUS_BADARGS        = 0x008, ///< model fit called with invalid args
+    PM_MODEL_STATUS_LIMITS         = 0x010, ///< model parameters hit limits
+    PM_MODEL_STATUS_WEAK_FIT       = 0x020, ///< model fit met loose tolerance, but not tight tolerance
+    PM_MODEL_STATUS_NAN_CHISQ      = 0x040, ///< model fit failed with a NAN chisq 
+    PM_MODEL_SERSIC_PCM_FAIL_GUESS = 0x080, ///< sersic model fit failed on the initial moments-based guess
+    PM_MODEL_SERSIC_PCM_FAIL_GRID  = 0x100, ///< sersic model fit failed on the grid search
+    PM_MODEL_PCM_FAIL_GUESS        = 0x200, ///< non-sersic model fit failed on the initial moments-based guess
+    PM_MODEL_BEST_FIT              = 0x400, ///< this model was the best fit and was subtracted
 } pmModelStatus;
 
@@ -105,4 +110,7 @@
 typedef psF64 (*pmModelRadius)(const psVector *params, double flux);
 
+// This function returns the FWHM given the supplied sigma (major or minor)
+typedef psF64 (*pmModelSetFWHM)(const psVector *params, double sigma);
+
 //  This function provides the model guess parameters based on the details of
 //  the given source.
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmModelUtils.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmModelUtils.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmModelUtils.c	(revision 37066)
@@ -32,11 +32,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceFitModel.h"
@@ -44,13 +45,4 @@
 
 #include "pmErrorCodes.h"
-
-// XX static bool useModelVar = false;
-// XX 
-// XX void pmModelSetModelVarOption (bool option) {
-// XX   useModelVar = option;
-// XX }
-// XX bool pmModelGetModelVarOption (void) {
-// XX   return useModelVar;
-// XX }
 
 /*****************************************************************************
@@ -67,5 +59,5 @@
 
     // set model parameters for this source based on PSF information
-    if (!modelEXT->modelFromPSF (modelPSF, modelEXT, psf)) {
+    if (!modelEXT->class->modelFromPSF (modelPSF, modelEXT, psf)) {
         psTrace ("psModules.objects", 3, "Failed to set model params from PSF");
         psFree(modelPSF);
@@ -88,5 +80,5 @@
 
     // set model parameters for this source based on PSF information
-    if (!modelPSF->modelParamsFromPSF (modelPSF, psf, Xo, Yo, Io)) {
+    if (!modelPSF->class->modelParamsFromPSF (modelPSF, psf, Xo, Yo, Io)) {
         psFree(modelPSF);
         return NULL;
@@ -108,5 +100,5 @@
 
     // determine the normalized flux
-    float normFlux = model->modelFlux (model->params);
+    float normFlux = model->class->modelFlux (model->params);
     assert (isfinite(normFlux));
     assert (normFlux > 0);
@@ -119,8 +111,8 @@
 
 bool pmModelUseReff (pmModelType type) {
-    bool useReff = false;
-    useReff |= (type == pmModelClassGetType ("PS_MODEL_SERSIC"));
-    useReff |= (type == pmModelClassGetType ("PS_MODEL_DEV"));
-    useReff |= (type == pmModelClassGetType ("PS_MODEL_EXP"));
+
+    pmModelClass *class = pmModelClassSelect (type);
+    psAssert (class, "undefined model class?");
+    bool useReff = class->useReff;
     return useReff;
 }
@@ -128,4 +120,8 @@
 // this function and the one below handle the two cases, where the model shape is uses R_eff or Sigma
 bool pmModelAxesToParams (float *Sxx, float *Sxy, float *Syy, psEllipseAxes axes, bool useReff)  {
+
+    // restrict axex to 0.5 here not below 
+    if (axes.minor < 0.2) axes.minor = 0.2;
+    if (axes.major < 0.2) axes.major = 0.2;
 
     psEllipseShape shape = psEllipseAxesToShape (axes);
@@ -137,10 +133,14 @@
     // set the shape parameters
     if (useReff) {
-	*Sxx  = PS_MAX(0.5, shape.sx);
-	*Syy  = PS_MAX(0.5, shape.sy);
+	// *Sxx  = PS_MAX(0.5, shape.sx);
+	// *Syy  = PS_MAX(0.5, shape.sy);
+	*Sxx  = shape.sx;
+	*Syy  = shape.sy;
 	*Sxy  = shape.sxy * 2.0;
     } else {
-	*Sxx  = PS_MAX(0.5, M_SQRT2*shape.sx);
-	*Syy  = PS_MAX(0.5, M_SQRT2*shape.sy);
+	// *Sxx  = PS_MAX(0.5, M_SQRT2*shape.sx);
+	// *Syy  = PS_MAX(0.5, M_SQRT2*shape.sy);
+	*Sxx  = M_SQRT2*shape.sx;
+	*Syy  = M_SQRT2*shape.sy;
 	*Sxy  = shape.sxy;
     }
@@ -193,4 +193,5 @@
     if (!isfinite(axes.minor)) return false;
     if (!isfinite(axes.theta)) return false;
+    if (axes.major == 0) return false;
 
     // Mxx, Mxy, Myy define the elliptical shape, but Mrf defines the width 
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmModel_CentralPixel.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmModel_CentralPixel.c	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmModel_CentralPixel.c	(revision 37066)
@@ -0,0 +1,821 @@
+/* @file  pmModel_CentralPixel.c
+ * @brief Functions to manage the central pixel for sersic-like models
+ * @author EAM, IfA
+ *
+ * @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-02-16 22:30:50 $
+ *
+ * Copyright 2013 Institute for Astronomy, University of Hawaii
+ */
+
+/******************************************************************************
+ * this file contains functions to determine the flux of the central pixel(s) for an
+ * exponential / devaucouleur / sersic style galaxy model.  The problem is that (a) these
+ * models are so centrally-peaked that it is necessary to determine the true mean flux in the
+ * central pixel by integration of fractional pixels (at least 0.02 pixels in the case of a
+ * DEV model) and (b) the process of integrating the central pixel is too slow to be used for
+ * real processing.
+
+ * we bypass this problem by defining a set of pre-calculated central pixel images, with
+ * subpixel resolution > 1 pixel (maybe 11 subpixels per real pixel).  These pre-calculated
+ * images are generated for a series of values for the following parameters: sersic index,
+ * effective radius, axial ratio.  We then select the closest image to our specific case, and
+ * integrate over the true sub-pixels relevant for our position and model.  We have thus turned
+ * problem from 2500 evaluations of the full sersic model to ~100 straight additions (possibly
+ * x 6 if we need to interpolate in each of the dimensions).  
+
+ * we need a number of support functions:
+
+ * pmModelCP_Load : load CP model data from the specified file. 
+ * pmModelCP_GetImage : choose an appropriate CP model image for a given set of parameters
+ * pmModelCP_GetValue : calculate the true CP value for the given image and parameters
+
+   *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <math.h>
+#include <string.h>
+#include <pslib.h>
+#include <pslib.h>
+
+#include "pmModel_CentralPixel.h"
+
+static void pmModelCP_Free(pmModelCP *cp) {
+    psFree (cp->flux);
+}
+
+pmModelCP *pmModelCP_Alloc(void)
+{
+    pmModelCP *tmp = (pmModelCP *) psAlloc(sizeof(pmModelCP));
+    psMemSetDeallocator(tmp, (psFreeFunc) pmModelCP_Free);
+
+    tmp->flux = NULL;
+    tmp->Rmajor = NAN;
+    tmp->Aratio = NAN;
+    tmp->Sindex = NAN;
+
+    return tmp;
+}
+
+static void pmModelCPset_Free(pmModelCPset *tmp) {
+
+    for (int i = 0; i < tmp->RmajorNitem; i++) {
+	for (int j = 0; j < tmp->AratioNitem; j++) {
+	    psFree (tmp->lookupCube[i][j]);
+	}
+	psFree (tmp->lookupCube[i]);
+    }
+    psFree (tmp->lookupCube);
+    psFree (tmp->images);
+}
+
+pmModelCPset *pmModelCPset_Alloc(void)
+{
+    pmModelCPset *tmp = (pmModelCPset *) psAlloc(sizeof(pmModelCPset));
+    psMemSetDeallocator(tmp, (psFreeFunc) pmModelCPset_Free);
+
+    tmp->RmajorMin = NAN;
+    tmp->RmajorMax = NAN;
+    tmp->RmajorDel = NAN;
+
+    tmp->AratioMin = NAN;
+    tmp->AratioMax = NAN;
+    tmp->AratioDel = NAN;
+
+    tmp->SindexMin = NAN;
+    tmp->SindexMax = NAN;
+    tmp->SindexDel = NAN;
+
+    tmp->RmajorNitem = 0;
+    tmp->AratioNitem = 0;
+    tmp->SindexNitem = 0;
+
+    tmp->lookupCube = NULL;
+    tmp->images = NULL;
+
+    return tmp;
+}
+
+// load the central-pixel maps as an array of pmModelCP 
+pmModelCPset *pmModelCP_Load (char *filename) {
+
+    bool status;
+
+    psFits *fits = psFitsOpen (filename, "r");
+    if (!fits) {
+	return false;
+    }
+    
+    // read the PHU -- it defines descriptive metadata
+    psMetadata *PHU = psFitsReadHeader (NULL, fits);
+    if (!PHU) {
+	psFitsClose (fits);
+	return false;
+    }
+
+    pmModelCPset *CPset = pmModelCPset_Alloc();
+
+    // NOTE : RMAJOR refers to the LOG_10 of the major axis
+    CPset->RmajorMin = psMetadataLookupF32 (&status, PHU, "RMAJ_MIN"); psAssert (status, "missing keyword RMAJ_MIN");
+    CPset->RmajorMax = psMetadataLookupF32 (&status, PHU, "RMAJ_MAX"); psAssert (status, "missing keyword RMAJ_MAX");
+    CPset->RmajorDel = psMetadataLookupF32 (&status, PHU, "RMAJ_DEL"); psAssert (status, "missing keyword RMAJ_DEL");
+    CPset->AratioMin = psMetadataLookupF32 (&status, PHU, "ARAT_MIN"); psAssert (status, "missing keyword ARAT_MIN");
+    CPset->AratioMax = psMetadataLookupF32 (&status, PHU, "ARAT_MAX"); psAssert (status, "missing keyword ARAT_MAX");
+    CPset->AratioDel = psMetadataLookupF32 (&status, PHU, "ARAT_DEL"); psAssert (status, "missing keyword ARAT_DEL");
+    CPset->SindexMin = psMetadataLookupF32 (&status, PHU, "SIDX_MIN"); psAssert (status, "missing keyword SIDX_MIN");
+    CPset->SindexMax = psMetadataLookupF32 (&status, PHU, "SIDX_MAX"); psAssert (status, "missing keyword SIDX_MAX");
+    CPset->SindexDel = psMetadataLookupF32 (&status, PHU, "SIDX_DEL"); psAssert (status, "missing keyword SIDX_DEL");
+
+    CPset->RmajorNitem = 1 + (int)(0.5 + (CPset->RmajorMax - CPset->RmajorMin) / CPset->RmajorDel);
+    CPset->AratioNitem = 1 + (int)(0.5 + (CPset->AratioMax - CPset->AratioMin) / CPset->AratioDel);
+    CPset->SindexNitem = 1 + (int)(0.5 + (CPset->SindexMax - CPset->SindexMin) / CPset->SindexDel);
+
+    // array entry = lookupCube[RmajorBin][AratioBin][SindexBin]
+
+    CPset->lookupCube = (int ***) psAlloc (sizeof(int **)*CPset->RmajorNitem);
+    for (int i = 0; i < CPset->RmajorNitem; i++) {
+	CPset->lookupCube[i] = (int **) psAlloc (sizeof(int *)*CPset->AratioNitem);
+	for (int j = 0; j < CPset->AratioNitem; j++) {
+	    CPset->lookupCube[i][j] = (int *) psAlloc (sizeof(int)*CPset->SindexNitem);
+	    for (int k = 0; k < CPset->SindexNitem; k++) {
+		CPset->lookupCube[i][j][k] = -1;
+	    }
+	}
+    }
+    
+    CPset->images = psArrayAllocEmpty (CPset->RmajorNitem*CPset->AratioNitem*CPset->SindexNitem);
+
+    // the CP file contains a set of 2D images; load them all 
+
+    psRegion fullImage = psRegionSet (0, 0, 0, 0);
+    while (true) {
+	bool status = psFitsMoveExtNum (fits, 1, true);
+	if (!status) break;
+
+	psMetadata *header = psFitsReadHeader (NULL, fits);
+	if (!header) {
+	    fprintf (stderr, "error reading header\n");
+	    return false;
+	}
+
+	pmModelCP *cp = pmModelCP_Alloc ();
+
+	cp->flux = psFitsReadImageBuffer (NULL, fits, fullImage, 0);
+	if (!cp->flux) {
+	    fprintf (stderr, "error reading image\n");
+	    return false;
+	}
+
+	cp->Rmajor = psMetadataLookupF32 (&status, header, "R_MAJOR");
+	cp->Aratio = psMetadataLookupF32 (&status, header, "A_RATIO");
+	cp->Sindex = psMetadataLookupF32 (&status, header, "S_INDEX");
+	
+	int RmajorBin = (int)((cp->Rmajor - CPset->RmajorMin) / CPset->RmajorDel); psAssert ((RmajorBin < CPset->RmajorNitem) && (RmajorBin >= 0), "bad bin");
+	int AratioBin = (int)((cp->Aratio - CPset->AratioMin) / CPset->AratioDel); psAssert ((AratioBin < CPset->AratioNitem) && (AratioBin >= 0), "bad bin");
+	int SindexBin = (int)((cp->Sindex - CPset->SindexMin) / CPset->SindexDel); psAssert ((SindexBin < CPset->SindexNitem) && (SindexBin >= 0), "bad bin");
+
+	CPset->lookupCube[RmajorBin][AratioBin][SindexBin] = CPset->images->n;
+
+	psArrayAdd (CPset->images, 121, cp);
+	psFree (cp);
+	psFree (header);
+    }
+
+    psFree (PHU);
+    psFitsClose (fits);
+
+    return CPset;
+}
+
+// choose the closest image to the given coords
+pmModelCP *pmModelCP_GetImage (pmModelCPset *CPset, float Rmajor, float Aratio, float Sindex) {
+
+    // the pmModelCP set is defined for a grid of Rmajor, Aratio, Sindex values
+
+    int RmajorBin = (int)((Rmajor - CPset->RmajorMin) / CPset->RmajorDel); psAssert ((RmajorBin < CPset->RmajorNitem) && (RmajorBin >= 0), "bad bin");
+    int AratioBin = (int)((Aratio - CPset->AratioMin) / CPset->AratioDel); psAssert ((AratioBin < CPset->AratioNitem) && (AratioBin >= 0), "bad bin");
+    int SindexBin = (int)((Sindex - CPset->SindexMin) / CPset->SindexDel); psAssert ((SindexBin < CPset->SindexNitem) && (SindexBin >= 0), "bad bin");
+    
+    int entry = CPset->lookupCube[RmajorBin][AratioBin][SindexBin];
+    
+    pmModelCP *cp = CPset->images->data[entry];
+
+    return (cp);
+}
+
+// XXX for test purposes only:
+# define TEST_IMAGE 0
+# if (TEST_IMAGE)
+static psImage *map = NULL;
+# endif
+
+float pmModelCP_GetFlux_RotSquare (pmModelCP *cp, float dx, float dy, float theta);
+
+float pmModelCP_GetFlux (pmModelCP *cp, float dx, float dy, float theta) {
+
+# if (TEST_IMAGE) 
+    map = psImageCopy (map, cp->flux, PS_TYPE_S32);
+    psImageInit (map, 0.0);
+# endif
+
+    // float flux = pmModelCP_GetFlux_Bresen (cp, dx, dy, theta);
+    // float flux = pmModelCP_GetFlux_Old (cp, dx, dy, theta);
+    float flux = pmModelCP_GetFlux_RotSquare (cp, dx, dy, theta);
+    
+    // RotSquare for theta = 0.0 & Bresen give the same answer 
+    // if I count from x[0] <= ix < x[1]
+
+# if (TEST_IMAGE) 
+    psFits *fits = psFitsOpen ("map.fits", "w");
+    psFitsWriteImage (fits, NULL, map, 0, NULL);
+    psFitsClose (fits);
+    psFree (map);
+# endif
+
+    return flux;
+}
+
+float pmModelCP_GetFlux_Old (pmModelCP *cp, float dx, float dy, float theta) {
+
+    // the cp data is defined for the central 3x3 pixels.  we allow dx,dy to have values of
+    // -1.0 <= dx,dy <= +1.0
+
+    // Xsub = (Xim * cos(theta) - Yim * sin(theta) + 1.5) * Nsub 
+    // Ysub = (Yim * cos(theta) + Xim * sin(theta) + 1.5) * Nsub 
+    
+    // integrate from (dx - 0.5 to dx + 0.5), (dy - 0.5 to dy + 0.5), 
+
+    // get the Xsub,Ysub values for the 4 corners, find the Xmin,Xmax, Ymin,Ymax in the
+    // subrastered image
+
+    float cs = cos(theta*PS_RAD_DEG);
+    float sn = sin(theta*PS_RAD_DEG);
+
+    float Nsub = 11.0;
+    int Xsub00 = ((dx - 0.5)*cs - (dy - 0.5)*sn + 1.5)*Nsub;
+    int Ysub00 = ((dx - 0.5)*sn + (dy - 0.5)*cs + 1.5)*Nsub;
+    int Xsub01 = ((dx - 0.5)*cs - (dy + 0.5)*sn + 1.5)*Nsub;
+    int Ysub01 = ((dx - 0.5)*sn + (dy + 0.5)*cs + 1.5)*Nsub;
+    int Xsub10 = ((dx + 0.5)*cs - (dy - 0.5)*sn + 1.5)*Nsub;
+    int Ysub10 = ((dx + 0.5)*sn + (dy - 0.5)*cs + 1.5)*Nsub;
+    int Xsub11 = ((dx + 0.5)*cs - (dy + 0.5)*sn + 1.5)*Nsub;
+    int Ysub11 = ((dx + 0.5)*sn + (dy + 0.5)*cs + 1.5)*Nsub;
+
+    int Xmin, Xmax, Ymin, Ymax;
+
+    Xmin = PS_MIN(Xsub00,Xsub01);
+    Xmin = PS_MIN(Xsub10,Xmin);
+    Xmin = PS_MIN(Xsub11,Xmin);
+    Xmin = PS_MIN(Xmin, cp->flux->numCols - 1);
+    Xmin = PS_MAX(Xmin, 0);
+    Xmax = PS_MAX(Xsub00,Xsub01);
+    Xmax = PS_MAX(Xsub10,Xmax);
+    Xmax = PS_MAX(Xsub11,Xmax);
+    Xmax = PS_MIN(Xmax, cp->flux->numCols - 1);
+    Xmax = PS_MAX(Xmax, 0);
+    Ymin = PS_MIN(Ysub00,Ysub01);
+    Ymin = PS_MIN(Ysub10,Ymin);
+    Ymin = PS_MIN(Ysub11,Ymin);
+    Ymin = PS_MIN(Ymin, cp->flux->numRows - 1);
+    Ymin = PS_MAX(Ymin, 0);
+    Ymax = PS_MAX(Ysub00,Ysub01);
+    Ymax = PS_MAX(Ysub10,Ymax);
+    Ymax = PS_MAX(Ysub11,Ymax);
+    Ymax = PS_MIN(Ymax, cp->flux->numRows - 1);
+    Ymax = PS_MAX(Ymax, 0);
+
+    // integrate pixels from Xmin,Ymin to Xmax,Ymax, only include pixels contained in the
+    // target pixel
+
+    float flux = 0.0;
+    int   npix = 0;
+    for (int i = Xmin; i < Xmax; i++) {
+	float dX = i / Nsub - 1.5;
+	for (int j = Ymin; j < Ymax; j++) {
+	    float dY = j / Nsub - 1.5;
+
+	    float Xim =  dX*cs + dY*sn;
+	    if (Xim < (dx - 0.5)) continue;
+	    if (Xim > (dx + 0.5)) continue;
+
+	    float Yim = -dX*sn + dY*cs;
+	    if (Yim < (dy - 0.5)) continue;
+	    if (Yim > (dy + 0.5)) continue;
+
+	    flux += cp->flux->data.F32[j][i];
+	    npix ++;
+	}
+    }
+	   
+    float normFlux = flux / npix;
+    return normFlux;
+}
+
+// *** pmSourceRadialProfileSortPair is a utility function for sorting a pair of vectors
+# define COMPARE_INDEX(A,B) (y[A] < y[B])
+# define SWAP_INDEX(TYPE,A,B) {				\
+	int tmp;					\
+	if (A != B) {					\
+	    tmp = x[A];					\
+	    x[A] = x[B];				\
+	    x[B] = tmp;					\
+	    tmp = y[A];					\
+	    y[A] = y[B];				\
+	    y[B] = tmp;					\
+	}						\
+    }
+
+bool pmModelCP_SortCorners (int *x, int *y, int Npar) {
+
+    if (Npar < 2) return true;
+
+    // sort the vector set by the radius
+    PSSORT (Npar, COMPARE_INDEX, SWAP_INDEX, NONE);
+    return true;
+}
+
+float pmModelCP_GetFlux_RotSquare (pmModelCP *cp, float dx, float dy, float theta) {
+
+    // the cp data is defined for the central 3x3 pixels.  we allow dx,dy to have values of
+    // -1.0 <= dx,dy <= +1.0
+
+    // Xsub = (Xim * cos(theta) - Yim * sin(theta) + 1.5) * Nsub 
+    // Ysub = (Yim * cos(theta) + Xim * sin(theta) + 1.5) * Nsub 
+    
+    // integrate from (dx - 0.5 to dx + 0.5), (dy - 0.5 to dy + 0.5), 
+
+    // get the Xsub,Ysub values for the 4 corners, find the Xmin,Xmax, Ymin,Ymax in the
+    // subrastered image
+
+    float cs = cos(theta*PS_RAD_DEG);
+    float sn = sin(theta*PS_RAD_DEG);
+    float Nsub = 11.0;
+
+    int Xsub[4], Ysub[4];
+
+    Xsub[0] = ((dx - 0.5)*cs - (dy - 0.5)*sn + 1.5)*Nsub;
+    Ysub[0] = ((dx - 0.5)*sn + (dy - 0.5)*cs + 1.5)*Nsub;
+    Xsub[1] = ((dx - 0.5)*cs - (dy + 0.5)*sn + 1.5)*Nsub;
+    Ysub[1] = ((dx - 0.5)*sn + (dy + 0.5)*cs + 1.5)*Nsub;
+    Xsub[2] = ((dx + 0.5)*cs - (dy - 0.5)*sn + 1.5)*Nsub;
+    Ysub[2] = ((dx + 0.5)*sn + (dy - 0.5)*cs + 1.5)*Nsub;
+    Xsub[3] = ((dx + 0.5)*cs - (dy + 0.5)*sn + 1.5)*Nsub;
+    Ysub[3] = ((dx + 0.5)*sn + (dy + 0.5)*cs + 1.5)*Nsub;
+
+    // first, sort the corners in order of the Y coordinate:
+    pmModelCP_SortCorners (Xsub, Ysub, 4);
+
+    float flux = 0.0;
+    float npix = 0.0;
+
+    // if (Ysub[0] == Ysub[1]), we have a simple square
+    if (Ysub[0] == Ysub[1]) {
+	psAssert (Ysub[2] == Ysub[3], "not square?");
+	int Xmin = PS_MIN(Xsub[0], Xsub[1]);
+	int Xmax = PS_MAX(Xsub[0], Xsub[1]);
+	for (int iy = Ysub[0]; iy < Ysub[3]; iy++) {
+	    for (int ix = Xmin; ix < Xmax; ix++) {
+		flux += cp->flux->data.F32[iy][ix];
+		npix += 1.0;
+# if (TEST_IMAGE) 
+		fprintf (stderr, "%d %d | %f %f | %f\n", ix, iy, flux, npix, cp->flux->data.F32[iy][ix]);
+		map->data.S32[iy][ix] ++;
+# endif
+	    }
+	}
+	float normFlux = flux / npix;
+	return normFlux;
+    }
+    
+    // second case: Xsub[1] > Xsub[2]:
+    if (Xsub[1] > Xsub[2]) {
+	float dYdXp, dYdXm;
+	// first segment, Ysub[0] to Ysub[1]:
+	dYdXp = (Ysub[1] - Ysub[0]) / (float) (Xsub[1] - Xsub[0]);
+	dYdXm = (Ysub[2] - Ysub[0]) / (float) (Xsub[2] - Xsub[0]);
+	for (int iy = Ysub[0]; iy < Ysub[1]; iy++) {
+	    int Xs = (iy - Ysub[0]) / dYdXm + Xsub[0];
+	    int Xe = (iy - Ysub[0]) / dYdXp + Xsub[0];
+	    for (int ix = Xs; ix < Xe; ix ++) {
+		flux += cp->flux->data.F32[iy][ix];
+		npix += 1.0;
+# if (TEST_IMAGE) 
+		fprintf (stderr, "%d %d | %f %f | %f\n", ix, iy, flux, npix, cp->flux->data.F32[iy][ix]);
+		map->data.S32[iy][ix] ++;
+# endif
+	    }
+	}
+	// 2nd segment, Ysub[1] to Ysub[2]:
+	dYdXp = (Ysub[3] - Ysub[1]) / (float) (Xsub[3] - Xsub[1]);
+	dYdXm = (Ysub[2] - Ysub[0]) / (float) (Xsub[2] - Xsub[0]);
+	for (int iy = Ysub[1]; iy < Ysub[2]; iy++) {
+	    int Xs = (iy - Ysub[0]) / dYdXm + Xsub[0];
+	    int Xe = (iy - Ysub[1]) / dYdXp + Xsub[1];
+	    for (int ix = Xs; ix < Xe; ix ++) {
+		flux += cp->flux->data.F32[iy][ix];
+		npix += 1.0;
+# if (TEST_IMAGE) 
+		fprintf (stderr, "%d %d | %f %f | %f\n", ix, iy, flux, npix, cp->flux->data.F32[iy][ix]);
+		map->data.S32[iy][ix] ++;
+# endif
+	    }
+	}
+	// first segment, Ysub[0] to Ysub[1]:
+	dYdXp = (Ysub[3] - Ysub[1]) / (float) (Xsub[3] - Xsub[1]);
+	dYdXm = (Ysub[3] - Ysub[2]) / (float) (Xsub[3] - Xsub[2]);
+	for (int iy = Ysub[2]; iy < Ysub[3]; iy++) {
+	    int Xs = (iy - Ysub[2]) / dYdXm + Xsub[2];
+	    int Xe = (iy - Ysub[1]) / dYdXp + Xsub[1];
+	    for (int ix = Xs; ix < Xe; ix ++) {
+		flux += cp->flux->data.F32[iy][ix];
+		npix += 1.0;
+# if (TEST_IMAGE) 
+		fprintf (stderr, "%d %d | %f %f | %f\n", ix, iy, flux, npix, cp->flux->data.F32[iy][ix]);
+		map->data.S32[iy][ix] ++;
+# endif
+	    }
+	}
+	float normFlux = flux / npix;
+	return normFlux;
+    }
+
+    // third case: Xsub[1] < Xsub[2]:
+    if (Xsub[2] > Xsub[1]) {
+	// first segment, Ysub[0] to Ysub[1]:
+	float dYdXp, dYdXm;
+	dYdXp = (Ysub[2] - Ysub[0]) / (float) (Xsub[2] - Xsub[0]);
+	dYdXm = (Ysub[1] - Ysub[0]) / (float) (Xsub[1] - Xsub[0]);
+	for (int iy = Ysub[0]; iy < Ysub[1]; iy++) {
+	    int Xs = (iy - Ysub[0]) / dYdXm + Xsub[0];
+	    int Xe = (iy - Ysub[0]) / dYdXp + Xsub[0];
+	    for (int ix = Xs; ix < Xe; ix ++) {
+		flux += cp->flux->data.F32[iy][ix];
+		npix += 1.0;
+# if (TEST_IMAGE) 
+		fprintf (stderr, "%d %d | %f %f | %f\n", ix, iy, flux, npix, cp->flux->data.F32[iy][ix]);
+		map->data.S32[iy][ix] ++;
+# endif
+	    }
+	}
+	// 2nd segment, Ysub[1] to Ysub[2]:
+	dYdXp = (Ysub[2] - Ysub[0]) / (float) (Xsub[2] - Xsub[0]);
+	dYdXm = (Ysub[3] - Ysub[1]) / (float) (Xsub[3] - Xsub[1]);
+	for (int iy = Ysub[1]; iy < Ysub[2]; iy++) {
+	    int Xs = (iy - Ysub[1]) / dYdXm + Xsub[1];
+	    int Xe = (iy - Ysub[0]) / dYdXp + Xsub[0];
+	    for (int ix = Xs; ix < Xe; ix ++) {
+		flux += cp->flux->data.F32[iy][ix];
+		npix += 1.0;
+# if (TEST_IMAGE) 
+		fprintf (stderr, "%d %d | %f %f | %f\n", ix, iy, flux, npix, cp->flux->data.F32[iy][ix]);
+		map->data.S32[iy][ix] ++;
+# endif
+	    }
+	}
+	// first segment, Ysub[0] to Ysub[1]:
+	dYdXp = (Ysub[3] - Ysub[2]) / (float) (Xsub[3] - Xsub[2]);
+	dYdXm = (Ysub[3] - Ysub[1]) / (float) (Xsub[3] - Xsub[1]);
+	for (int iy = Ysub[2]; iy < Ysub[3]; iy++) {
+	    int Xs = (iy - Ysub[1]) / dYdXm + Xsub[1];
+	    int Xe = (iy - Ysub[2]) / dYdXp + Xsub[2];
+	    for (int ix = Xs; ix < Xe; ix ++) {
+		flux += cp->flux->data.F32[iy][ix];
+		npix += 1.0;
+# if (TEST_IMAGE) 
+		fprintf (stderr, "%d %d | %f %f | %f\n", ix, iy, flux, npix, cp->flux->data.F32[iy][ix]);
+		map->data.S32[iy][ix] ++;
+# endif
+	    }
+	}
+	float normFlux = flux / npix;
+	return normFlux;
+    }
+    myAbort ("impossible case?");
+}
+
+float pmModelCP_GetFlux_Bresen (pmModelCP *cp, float dx, float dy, float theta) {
+
+    // the cp data is defined for the central 3x3 pixels.  we allow dx,dy to have values of
+    // -1.0 <= dx,dy <= +1.0
+
+    // Xsub = ( Xim * cos(theta) + Yim * sin(theta) + 1.5) * Nsub 
+    // Ysub = (-Yim * cos(theta) + Xim * sin(theta) + 1.5) * Nsub 
+    
+    // integrate from (dx - 0.5 to dx + 0.5), (dy - 0.5 to dy + 0.5), 
+
+    // get the Xsub,Ysub values for the 4 corners, find the Xmin,Xmax, Ymin,Ymax in the
+    // subrastered image
+
+    float cs = cos(theta*PS_RAD_DEG);
+    float sn = sin(theta*PS_RAD_DEG);
+
+    float Nsub = 11.0;
+    int Xsub00 = 0.5 + ((dx - 0.5)*cs + (dy - 0.5)*sn + 1.5)*Nsub;
+    int Ysub00 = 0.5 + ((dy - 0.5)*cs - (dx - 0.5)*sn + 1.5)*Nsub;
+    int Xsub01 = 0.5 + ((dx - 0.5)*cs + (dy + 0.5)*sn + 1.5)*Nsub;
+    int Ysub01 = 0.5 + ((dy + 0.5)*cs - (dx - 0.5)*sn + 1.5)*Nsub;
+    int Xsub10 = 0.5 + ((dx + 0.5)*cs + (dy - 0.5)*sn + 1.5)*Nsub;
+    int Ysub10 = 0.5 + ((dy - 0.5)*cs - (dx + 0.5)*sn + 1.5)*Nsub;
+    int Xsub11 = 0.5 + ((dx + 0.5)*cs + (dy + 0.5)*sn + 1.5)*Nsub;
+    int Ysub11 = 0.5 + ((dy + 0.5)*cs - (dx + 0.5)*sn + 1.5)*Nsub;
+
+    float flux = pmModelCP_GetFlux_BresenSquare (cp, Xsub00, Ysub00, Xsub10, Ysub10, Xsub01, Ysub01, Xsub11, Ysub11);
+    return flux;
+}
+
+// first line is (X00,Y00) - (X10,Y1) : last line is (X01,Y01) - (X11,Y11)
+float pmModelCP_GetFlux_BresenSquare (pmModelCP *cp, int X00, int Y00, int X10, int Y10, int X01, int Y01, int X11, int Y11) {
+
+    int dX0 = X01 - X00;
+    int dY0 = Y01 - Y00;
+
+    // int dX1 = X11 - X10;
+    // int dY1 = Y11 - Y10;
+
+    // myAssert ((dX0 == dX1) && (dY0 == dY1), "pixel is not square?");
+
+    bool FlipCoords = (abs(dX0) < abs(dY0));
+    bool FlipDirect = FlipCoords ? (Y00 > Y10) : (X00 > X10);
+
+    float flux = 0.0;
+    if (!FlipDirect && !FlipCoords) flux = pmModelCP_GetFlux_BresenSquareBase (cp, X00, Y00, X10, Y10, X01, Y01, X11, Y11, false);
+    if ( FlipDirect && !FlipCoords) flux = pmModelCP_GetFlux_BresenSquareBase (cp, X10, Y10, X00, Y00, X11, Y11, X01, Y01, false);
+    if (!FlipDirect &&  FlipCoords) flux = pmModelCP_GetFlux_BresenSquareBase (cp, Y00, X00, Y10, X10, Y01, X01, Y11, X11, true);
+    if ( FlipDirect &&  FlipCoords) flux = pmModelCP_GetFlux_BresenSquareBase (cp, Y10, X10, Y00, X00, Y11, X11, Y01, X01, true);
+    return flux;
+}
+
+// draw a line between (X00,Y00) & (X01,Y01) and increment to the next line segment until endpoints (X10,Y10) & (X11,Y11)
+float pmModelCP_GetFlux_BresenSquareBase (pmModelCP *cp, int X00, int Y00, int X10, int Y10, int X01, int Y01, int X11, int Y11, bool swapcoords) {
+
+    int dX0 = X01 - X00;
+    int dY0 = Y01 - Y00;
+
+    // int dX1 = X11 - X10;
+    // int dY1 = Y11 - Y10;
+
+    // myAssert ((dX0 == dX1) && (dY0 == dY1), "pixel is not square?");
+
+    float flux = 0.0;
+    float npix = 0.0;
+
+    int Ys = Y00;
+    int Ye = Y10;
+    int e = 0;
+    for (int Xs = X00, Xe = X10; Xs < X01; Xs++, Xe++) {
+	if (swapcoords) {
+	    pmModelCP_GetFlux_BresenLine (&flux, &npix, cp, Ys, Xs, Ye, Xe);
+	} else {
+	    pmModelCP_GetFlux_BresenLine (&flux, &npix, cp, Xs, Ys, Xe, Ye);
+	}
+	e += dY0;
+	float e2 = 2 * e;
+	if (e2 > dX0) {
+	    Ys++;
+	    Ye++;
+	    e -= dX0;
+	} 
+	if (e2 < -dX0) {
+	    Ys--;
+	    Ye--;
+	    e += dX0;
+	}
+    }
+    float normFlux = flux / npix;
+    // fprintf (stderr, "bres: %f %f %f\n", flux, (float) npix, normFlux);
+    return normFlux;
+}
+
+// get the sequence right: 
+// if abs(dY) > abs(dX) : we will run in the Y direction not the X direction (we swap X and Y going in)
+// if the direction (dX or dY) is negative, go the opposite direction
+bool pmModelCP_GetFlux_BresenLine (float *flux, float *npix, pmModelCP *cp, int X0, int Y0, int X1, int Y1) {
+
+  int dX = X1 - X0;
+  int dY = Y1 - Y0;
+
+  bool FlipCoords = (abs(dX) < abs(dY));
+  bool FlipDirect = FlipCoords ? (Y0 > Y1) : (X0 > X1);
+
+  if (!FlipDirect && !FlipCoords) pmModelCP_GetFlux_BresenLineBase (flux, npix, cp, X0, Y0, X1, Y1, false);
+  if ( FlipDirect && !FlipCoords) pmModelCP_GetFlux_BresenLineBase (flux, npix, cp, X1, Y1, X0, Y0, false);
+  if (!FlipDirect &&  FlipCoords) pmModelCP_GetFlux_BresenLineBase (flux, npix, cp, Y0, X0, Y1, X1, true);
+  if ( FlipDirect &&  FlipCoords) pmModelCP_GetFlux_BresenLineBase (flux, npix, cp, Y1, X1, Y0, X0, true);
+  return true;
+}
+
+bool pmModelCP_GetFlux_BresenLineBase (float *flux, float *npix, pmModelCP *cp, int X0, int Y0, int X1, int Y1, bool swapcoords) {
+
+    int dX = X1 - X0;
+    int dY = Y1 - Y0;
+
+    int Y = Y0;
+    int e = 0;
+    for (int X = X0; X < X1; X++) {
+	if (swapcoords) {
+	    *flux += cp->flux->data.F32[X][Y];
+	    *npix += 1.0;
+# if (TEST_IMAGE) 
+	    fprintf (stderr, "%d %d | %f %f | %f\n", X, Y, *flux, *npix, cp->flux->data.F32[X][Y]);
+	    map->data.S32[X][Y] ++;
+# endif
+	} else {
+	    *flux += cp->flux->data.F32[Y][X];
+	    *npix += 1.0;
+# if (TEST_IMAGE) 
+	    fprintf (stderr, "%d %d | %f %f | %f\n", X, Y, *flux, *npix, cp->flux->data.F32[Y][X]);
+	    map->data.S32[Y][X] ++;
+# endif
+	}
+	e += dY;
+	float e2 = 2 * e;
+	if (e2 > dX) {
+	    Y++;
+	    e -= dX;
+	} 
+	if (e2 < -dX) {
+	    Y--;
+	    e += dX;
+	}
+    }
+    return true;
+}
+
+// this is a test function which generates a full sersic model evaluation with sub-pixel sampling
+float pmModelCP_FullSersic (float dx, float dy, float theta, float Rmajor, float Aratio, float Sindex) {
+
+    float flux = 0.0;
+    int   npix = 0;
+
+    float Rminor = Aratio * Rmajor;
+    float f1 = 1.0 / PS_SQR(Rminor) + 1.0 / PS_SQR(Rmajor);
+    float f2 = 1.0 / PS_SQR(Rminor) - 1.0 / PS_SQR(Rmajor);
+    
+    float sxr = 0.5*f1 - 0.5*f2*cos(2.0*theta*PS_RAD_DEG);
+    float syr = 0.5*f1 + 0.5*f2*cos(2.0*theta*PS_RAD_DEG);
+    
+    float Rxx  = +1.0 / sqrt(sxr);
+    float Ryy  = +1.0 / sqrt(syr);
+    float Rxy = -f2*sin(2.0*theta*PS_RAD_DEG);
+    
+    float kappa = -0.275552 + 1.972625*Sindex + 0.003487 * PS_SQR(Sindex);
+    float rindex = 0.5 / Sindex;
+
+    float off = -60.0/(11*11);
+    float delta = 1.0 / (11*11);
+    for (float ix = off; ix < 0.5; ix += delta) {
+	for (float iy = off; iy < 0.5; iy += delta) {
+
+	    float dX = dx + ix;
+	    float dY = dy + iy;
+	    float z = PS_SQR(dX / Rxx) + PS_SQR(dY / Ryy) + dX * dY * Rxy;
+
+	    float q = pow (z, rindex);
+	    float f = exp(-kappa*q);
+
+	    flux += f;
+	    npix ++;
+	}
+    }
+    float normFlux = flux / npix;
+    // fprintf (stderr, "full : %f %f %f\n", flux, (float) npix, normFlux);
+    return normFlux;
+}
+
+// this is a test function which generates a full sersic model evaluation with sub-pixel sampling
+// Nsub is the number of sub-pixel samplings and must be odd
+// dx,dy are the centroid offset
+float pmModelCP_SersicSubpix (float dx, float dy, float Rxx, float Rxy, float Ryy, float Sindex, int Nsub) {
+
+    float flux = 0.0;
+    int   npix = 0;
+
+    // -0.275552 + 1.972625*Sindex + 0.003487 * PS_SQR(Sindex);
+    float kappa = pmSersicKappa (Sindex);
+    float rindex = 0.5 / Sindex;
+
+    // have the resolution be a user-parameter?
+    psAssert (Nsub % 2 == 1, "Nsub is not odd");
+    int Nsub2 = (Nsub - 1) / 2;
+
+    float delta = 1.0 / (float) Nsub;
+    // float off = -Nsub2 * delta;
+
+    int Sx = (int) floor(dx / delta);
+    int Sy = (int) floor(dy / delta);
+
+    for (int ix = -Nsub2; ix <= Nsub2; ix++) {
+      float dX = delta * (Sx + ix);
+      for (int iy = -Nsub2; iy <= Nsub2; iy++) {
+	float dY = delta * (Sy + iy);
+	    float z = PS_SQR(dX / Rxx) + PS_SQR(dY / Ryy) + dX * dY * Rxy;
+
+	    float q = pow (z, rindex);
+	    float f = exp(-kappa*q);
+
+	    // if ((ix == 0) && (iy == 0)) {
+	    //   // fprintf (stderr, "this: %f  %f  %f  --  full : %f %f\n", z, q, f, flux, (float) npix);
+	    // }
+
+	    flux += f;
+	    npix ++;
+	}
+    }
+    float normFlux = flux / npix;
+    // fprintf (stderr, "full : %f %f %f\n", flux, (float) npix, normFlux);
+    return normFlux;
+}
+
+float pmSersicKappa (float Sindex) {
+    // this function is empirically derived from a fit to data for Sindex = 0.5 - 5.5
+    // constrain Sindex or kappa?
+    float kappa = -0.275552 + 1.972625*Sindex + 0.003487 * PS_SQR(Sindex);
+    return kappa;
+}
+
+float pmSersicNorm (float Sindex) {
+
+    float C0 = NAN;
+    float C1 = NAN;
+    float C2 = NAN;
+
+    // y = 0.201545 x^0 -0.950965 x^1 -0.315248 x^2 
+    // y = 0.402084 x^0 -1.357775 x^1 -0.105102 x^2 
+    // y = 0.619093 x^0 -1.591674 x^1 -0.041576 x^2 
+    // y = 0.770263 x^0 -1.696421 x^1 -0.023363 x^2 
+    // y = 0.885891 x^0 -1.755684 x^1 -0.015753 x^2 
+
+    if ((Sindex >= 0.0) && (Sindex < 1.0)) { 
+	C0 = 0.201545; C1 = -0.950965; C2 = -0.315248;
+	// y = 0.201545 x^0 -0.950965 x^1 -0.315248 x^2 
+    }
+    if ((Sindex >= 1.0) && (Sindex < 2.0)) { 
+	C0 = 0.402084; C1 = -1.357775; C2 = -0.105102;
+	// y = 0.402084 x^0 -1.357775 x^1 -0.105102 x^2 
+    }
+    if ((Sindex >= 2.0) && (Sindex < 3.0)) { 
+	C0 = 0.619093; C1 = -1.591674; C2 = -0.041576;
+	// y = 0.619093 x^0 -1.591674 x^1 -0.041576 x^2 
+    }
+    if ((Sindex >= 3.0) && (Sindex < 4.0)) { 
+	C0 = 0.770263; C1 = -1.696421; C2 = -0.023363;
+	// y = 0.770263 x^0 -1.696421 x^1 -0.023363 x^2 
+    }
+    if ((Sindex >= 4.0) && (Sindex < 5.5)) { 
+	C0 = 0.885891; C1 = -1.755684; C2 = -0.015753; 
+	// y = 0.885891 x^0 -1.755684 x^1 -0.015753 x^2 
+    }
+
+    if (isnan(C0)) return NAN;
+
+    float lnorm = C0 + C1*Sindex + C2*Sindex*Sindex;
+    float norm = exp(lnorm);
+    return norm;
+}
+
+# if (0)
+// create a vector containing only the unique entries in the input vector
+psVector *psVectorUniqueSubset (psVector *input) {
+
+    // sort the input vector (to new temp vector)
+    // run through the sorted vector, copying to a new output vector if the current value is
+    // new
+
+    psVector *temp = psVectorSort (input);
+    
+    psVector *output = psVectorAllocEmpty (0.5*input->n, PS_TYPE_F32);
+    
+    psVectorAppend (output, temp->data.F32[0]);
+    float lastValue = temp->data.F32[0];
+    for (int i = 0; i < temp->n; i++) {
+	if (temp->data.F32[i] == lastValue) continue;
+	psVectorAppend (output, temp->data.F32[i]);
+	float lastValue = temp->data.F32[i];
+    }
+    psFree (temp);
+    return output;
+}
+
+getUnique() {
+    // we need to convert the collection of Rmajor, Aratio, Sindex values to a cube
+    // such that entry[RmajorBin][AratioBin][SindexBin] is the CPset array element
+
+    // create full vectors will all Rmajor, Aratio, Sindex values:
+    psVector *RmajorAll = psVectorAllocEmpty (CPset->n, PS_TYPE_F32);
+    psVector *AratioAll = psVectorAllocEmpty (CPset->n, PS_TYPE_F32);
+    psVector *SindexAll  = psVectorAllocEmpty (CPset->n, PS_TYPE_F32);
+    for (int i = 0; i < CPset->n; i++) {
+	pmModelCP *cp = CPset->data[i];
+	psVectorAppend (RmajorAll, cp->Rmajor);
+	psVectorAppend (AratioAll, cp->Aratio);
+	psVectorAppend (SindexAll,  cp->Sindex);
+    }
+    psVector *RmajorUniq = psVectorUniqueSubset (RmajorAll);
+    psVector *AratioUniq = psVectorUniqueSubset (AratioAll);
+    psVector *SindexUniq  = psVectorUniqueSubset (SindexAll);
+}
+# endif
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmModel_CentralPixel.h
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmModel_CentralPixel.h	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmModel_CentralPixel.h	(revision 37066)
@@ -0,0 +1,69 @@
+/* @file  pmModel_CentralPixel.h
+ * @brief Functions to manage the central pixel for sersic-like models
+ * @author EAM, IfA
+ *
+ * @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-02-16 22:30:50 $
+ *
+ * Copyright 2013 Institute for Astronomy, University of Hawaii
+ */
+
+# ifndef PM_MODEL_CENTRAL_PIXEL_H
+# define PM_MODEL_CENTRAL_PIXEL_H
+
+/// @addtogroup Objects Object Detection / Analysis Functions
+/// @{
+
+typedef struct {
+    psImage *flux;
+    float Rmajor;
+    float Aratio;
+    float Sindex;
+} pmModelCP;
+
+typedef struct {
+    psArray *images;
+
+    float RmajorMin;
+    float RmajorMax;
+    float RmajorDel;
+
+    float AratioMin;
+    float AratioMax;
+    float AratioDel;
+
+    float SindexMin;
+    float SindexMax;
+    float SindexDel;
+
+    int RmajorNitem;
+    int AratioNitem;
+    int SindexNitem;
+
+    int ***lookupCube;
+
+} pmModelCPset;
+
+pmModelCP    *pmModelCP_Alloc(void);
+pmModelCPset *pmModelCPset_Alloc(void);
+
+pmModelCPset *pmModelCP_Load (char *filename);
+
+pmModelCP    *pmModelCP_GetImage (pmModelCPset *CPset, float Rmajor, float Aratio, float Sindex);
+
+float         pmModelCP_GetFlux (pmModelCP *cp, float dx, float dy, float theta);
+float         pmModelCP_FullSersic (float dx, float dy, float theta, float Rmajor, float Aratio, float Sindex);
+
+bool pmModelCP_GetFlux_BresenLineBase (float *flux, float *npix, pmModelCP *cp, int X0, int Y0, int X1, int Y1, bool swapcoords);
+bool pmModelCP_GetFlux_BresenLine (float *flux, float *npix, pmModelCP *cp, int X0, int Y0, int X1, int Y1);
+float pmModelCP_GetFlux_BresenSquareBase (pmModelCP *cp, int X00, int Y00, int X01, int Y01, int X10, int Y10, int X11, int Y11, bool swapcoords);
+float pmModelCP_GetFlux_BresenSquare (pmModelCP *cp, int X00, int Y00, int X01, int Y01, int X10, int Y10, int X11, int Y11);
+float pmModelCP_GetFlux_Bresen (pmModelCP *cp, float dx, float dy, float theta);
+float pmModelCP_GetFlux_Old (pmModelCP *cp, float dx, float dy, float theta);
+
+float pmModelCP_SersicSubpix (float dx, float dy, float Rxx, float Rxy, float Ryy, float Sindex, int Nsub);
+
+float pmSersicKappa (float Sindex);
+float pmSersicNorm (float Sindex);
+
+# endif
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmMoments.h
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmMoments.h	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmMoments.h	(revision 37066)
@@ -44,4 +44,6 @@
     float Myyyy;   ///< fourth moment
 
+  // float wSum;    ///< window-weighted sum (NOT needed by lensing)
+
     float Sum;    ///< Pixel sum above sky (background).
     float Peak;   ///< Peak counts above sky.
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmPCM_MinimizeChisq.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmPCM_MinimizeChisq.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmPCM_MinimizeChisq.c	(revision 37066)
@@ -31,14 +31,20 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceFitModel.h"
 #include "pmPCMdata.h"
+
+# define SAVE_IMAGES 0
+# if (SAVE_IMAGES) 
+int psphotSaveImage (psMetadata *header, psImage *image, char *filename);
+# endif
 
 # define FACILITY "psModules.objects"
@@ -91,5 +97,5 @@
     psF32 lambda = 0.001;
     psF32 dLinear = 0.0;
-    psF32 nu = 2.0;
+    psF32 nu = 3.0;
 
 # if (USE_FFT && PRE_CONVOLVE)
@@ -130,6 +136,38 @@
 	}
 
+	if (min->isInteractive) {
+	    fprintf (stderr, "%d : ", min->iter);
+	    for (int ti = 0; ti < params->n; ti++) {
+		fprintf (stderr, "%f  ", params->data.F32[ti]);
+	    }
+	    fprintf (stderr, " : %f\n", min->value);
+	}
+
+	char key[10]; // used for interactive responses
+	bool testValue = false;
+
         // set a new guess for Alpha, Beta, Params
         if (!psMinLM_GuessABP(Alpha, Beta, Params, alpha, beta, params, paramMask, checkLimits, lambda, &dLinear)) {
+	    if (false && min->isInteractive) {
+		fprintf (stdout, "guess failed (singular matrix or NaN values), continue? [Y,n] ");
+		if (!fgets(key, 8, stdin)) {
+		    psWarning("Unable to read option");
+		}
+		switch (key[0]) {
+		  case 'n':
+		  case 'N':
+		    done = true;
+		    break;
+		  case 'y':
+		  case 'Y':
+		  case '\n':
+		    lambda *= 10.0;
+		    continue;
+		  default:
+		    lambda *= 10.0;
+		    continue;
+		}
+		if (done) break;
+	    }
             min->iter ++;
 	    if (min->iter >=  min->maxIter) break;
@@ -138,4 +176,40 @@
         }
 
+	if (false && min->isInteractive) {
+            p_psVectorPrint(psTraceGetDestination(), Params, "current parameters: ");
+	    fprintf (stdout, "last chisq : %f\n", min->value);
+	    bool getOptions = true;
+	    while (getOptions) {
+		fprintf (stdout, "options: (m)odify, (g)o, (q)uit: ");
+		if (!fgets(key, 8, stdin)) {
+		    psWarning("Unable to read option");
+		}
+		switch (key[0]) {
+		  case 'm':
+		  case 'M':
+		    testValue = TRUE;
+		    fprintf (stdout, "enter (Npar) (value): ");
+		    int Npar = 0;
+		    float value= 0;
+		    int Nscan = fscanf (stdin, "%d %f", &Npar, &value);
+		    if (Nscan != 2) {
+		      fprintf (stderr, "scan failure\n");
+		    }
+		    Params->data.F32[Npar] = value;
+		    break;
+		  case 'g':
+		  case 'G':
+		  case '\n':
+		    getOptions = false;
+		    break;
+		  default:
+		    done = true;
+		    break;
+		}
+		fprintf (stderr, "foo\n");
+	    }
+	    if (done) break;
+	}
+	    
         // dump some useful info if trace is defined
         if (psTraceGetLevel(FACILITY) >= 6) {
@@ -202,5 +276,5 @@
 	// XXX : Madsen gives suggestion for better use of rho
         // rho is positive if the new chisq is smaller
-        if (rho >= -1e-6) {
+        if (testValue || (rho >= -1e-6)) {
             min->value = Chisq;
             alpha  = psImageCopy(alpha, Alpha, PS_TYPE_F32);
@@ -215,5 +289,5 @@
 	  case 0:
 	    if (rho >= -1e-6) {
-		lambda *= 0.25;
+		lambda *= 0.1;
 	    } else {
 		lambda *= 10.0;
@@ -234,8 +308,8 @@
 	    if (rho > 0.0) {
 		lambda *= PS_MAX(0.33, (1.0 - pow(2.0*rho - 1.0, 3.0)));
-		nu = 2.0;
+		nu = 3.0;
 	    } else {
 		lambda *= nu;
-		nu *= 2.0;
+		nu *= 3.0;
 	    }
 	    break;
@@ -381,5 +455,5 @@
             coord->data.F32[1] = (psF32) (i + 0.5 + source->pixels->row0);
 
-            pcm->modelFlux->data.F32[i][j] = pcm->modelConv->modelFunc (deriv, params, coord);
+            pcm->modelFlux->data.F32[i][j] = pcm->modelConv->class->modelFunc (deriv, params, coord);
 
             for (int n = 0; n < params->n; n++) {
@@ -408,10 +482,15 @@
 # else
     if (pcm->use1Dgauss) {
-	// do not use the threaded, mask-aware version of this code (psImageSmoothMaskPixelsThread):
-	// * the model flux is not masked
-	// * threading takes place above this level
-	pcm->modelConvFlux = psImageCopy (pcm->modelConvFlux, pcm->modelFlux, pcm->modelFlux->type.type);
-	psImageSmooth_PreAlloc_F32 (pcm->modelConvFlux, pcm->smdata);
-	// psImageSmooth (pcm->modelConvFlux, pcm->sigma, pcm->nsigma);
+
+	if (USE_1D_CACHE) {
+	    // do not use the threaded, mask-aware version of this code (psImageSmoothMaskPixelsThread):
+	    // * the model flux is not masked
+	    // * threading takes place above this level
+	    pcm->modelConvFlux = psImageCopy (pcm->modelConvFlux, pcm->modelFlux, pcm->modelFlux->type.type);
+	    psImageSmoothCache_F32 (pcm->modelConvFlux, pcm->smdata);
+	} else {
+	    pcm->modelConvFlux = psImageCopy (pcm->modelConvFlux, pcm->modelFlux, pcm->modelFlux->type.type);
+	    psImageSmooth2dCache_F32 (pcm->modelConvFlux, pcm->smdata2d);
+	}
     } else {
 	psImageConvolveKernel (pcm->modelConvFlux, pcm->modelFlux, NULL, 0, pcm->psfFFT);
@@ -428,10 +507,14 @@
 # else
 	if (pcm->use1Dgauss) {
-	    // do not use the threaded, mask-aware version of this code (psImageSmoothMaskPixelsThread):
-	    // * the model flux is not masked
-	    // * threading takes place above this level
-	    dmodelConv = psImageCopy (dmodelConv, dmodel, dmodel->type.type);
-	    psImageSmooth_PreAlloc_F32 (dmodelConv, pcm->smdata);
-	    // psImageSmooth (dmodelConv, pcm->sigma, pcm->nsigma);
+	    if (USE_1D_CACHE) {
+		// do not use the threaded, mask-aware version of this code (psImageSmoothMaskPixelsThread):
+		// * the model flux is not masked
+		// * threading takes place above this level
+		dmodelConv = psImageCopy (dmodelConv, dmodel, dmodel->type.type);
+		psImageSmoothCache_F32 (dmodelConv, pcm->smdata);
+	    } else {
+		dmodelConv = psImageCopy (dmodelConv, dmodel, dmodel->type.type);
+		psImageSmooth2dCache_F32 (dmodelConv, pcm->smdata2d);
+	    }
 	} else {
 	    psImageConvolveKernel (dmodelConv, dmodel, NULL, 0, pcm->psfFFT);
@@ -449,10 +532,14 @@
 
 	if (pcm->use1Dgauss) {
-	    // do not use the threaded, mask-aware version of this code (psImageSmoothMaskPixelsThread):
-	    // * the model flux is not masked
-	    // * threading takes place above this level
-	    dmodelConv = psImageCopy (dmodelConv, dmodel, dmodel->type.type);
-	    psImageSmooth_PreAlloc_F32 (dmodelConv, pcm->smdata);
-	    // psImageSmooth (dmodelConv, pcm->sigma, pcm->nsigma);
+	    if (USE_1D_CACHE) {
+		// do not use the threaded, mask-aware version of this code (psImageSmoothMaskPixelsThread):
+		// * the model flux is not masked
+		// * threading takes place above this level
+		dmodelConv = psImageCopy (dmodelConv, dmodel, dmodel->type.type);
+		psImageSmoothCache_F32 (dmodelConv, pcm->smdata);
+	    } else {
+		dmodelConv = psImageCopy (dmodelConv, dmodel, dmodel->type.type);
+		psImageSmooth2dCache_F32 (dmodelConv, pcm->smdata2d);
+	    }
 	} else {
 	    psImageConvolveFFT (dmodelConv, dmodel, NULL, 0, pcm->psf);
@@ -474,10 +561,20 @@
     // XXX TEST : SAVE IMAGES
 # if (SAVE_IMAGES)
-    psphotSaveImage (NULL, pcm->psf->image, "psf.fits");
-    psphotSaveImage (NULL, pcm->modelFlux, "model.fits");
-    psphotSaveImage (NULL, pcm->modelConvFlux, "modelConv.fits");
-    psphotSaveImage (NULL, source->pixels, "obj.fits");
-    psphotSaveImage (NULL, source->maskObj, "mask.fits");
-    psphotSaveImage (NULL, source->variance, "variance.fits");
+    static int Npass = 0;
+    char name[128]; 
+    if (!pcm->use1Dgauss) {
+      snprintf (name, 128, "psf.%03d.fits", Npass); psphotSaveImage (NULL, pcm->psf->image, name);
+    }
+    snprintf (name, 128, "mod.%03d.fits", Npass); psphotSaveImage (NULL, pcm->modelFlux, name);
+    snprintf (name, 128, "cnv.%03d.fits", Npass); psphotSaveImage (NULL, pcm->modelConvFlux, name);
+    snprintf (name, 128, "obj.%03d.fits", Npass); psphotSaveImage (NULL, source->pixels, name);
+    snprintf (name, 128, "msk.%03d.fits", Npass); psphotSaveImage (NULL, source->maskObj, name);
+    snprintf (name, 128, "var.%03d.fits", Npass); psphotSaveImage (NULL, source->variance, name);
+    for (int n = 0; n < pcm->dmodelsFlux->n; n++) {
+        psImage *dmodelConv = pcm->dmodelsConvFlux->data[n];
+	if (!dmodelConv) continue;
+	snprintf (name, 128, "dpar.%01d.%03d.fits", n, Npass); psphotSaveImage (NULL, dmodelConv, name);
+    }
+    Npass ++;
 # endif
 
@@ -506,5 +603,7 @@
 
             float ymodel  = pcm->modelConvFlux->data.F32[i][j];
-            float yweight = 1.0 / source->variance->data.F32[i][j];
+
+	    // XXXX note this point here:::
+            float yweight = pcm->poissonErrors ? 1.0 / source->variance->data.F32[i][j] : 1.0;
             float delta = ymodel - source->pixels->data.F32[i][j];
 
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmPCMdata.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmPCMdata.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmPCMdata.c	(revision 37066)
@@ -31,11 +31,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceFitModel.h"
@@ -43,5 +44,4 @@
 
 # define USE_DELTA_PSF 0
-# define USE_1D_GAUSS 1
 
 static void pmPCMdataFree (pmPCMdata *pcm) {
@@ -58,5 +58,7 @@
     psFree (pcm->psfFFT);
     psFree (pcm->constraint);
+
     psFree (pcm->smdata); // pre-allocated data for psImageSmooth_PreAlloc
+    psFree (pcm->smdata2d); // pre-allocated data for psImageSmooth_PreAlloc
     return;
 }
@@ -88,4 +90,7 @@
     }
 
+    pcm->smdata = NULL;
+    pcm->smdata2d = NULL;
+
     pcm->modelConv = NULL;
     pcm->psf = NULL;
@@ -94,8 +99,10 @@
     pcm->nDOF = 0;
 
+    pcm->poissonErrors = true;
+
     // full convolution with the PSF is expensive.  if we have to save time, we can do a 1D
     // convolution with a Gaussian approximation to the kernel
     pcm->use1Dgauss = false;
-    pcm->nsigma = 3.0; 
+    pcm->nsigma = NAN; // this is set to something defined by the user
     pcm->sigma = 1.0; // this should be set to something sensible when the psf is known
 
@@ -173,21 +180,190 @@
 }
 
+int pmPCMsetParams (psMinConstraint *constraint, pmSourceFitMode mode) {
+
+    // set parameter mask based on fitting mode
+    int nParams = 0;
+    int nParAll = constraint->paramMask->n;
+
+    switch (mode) {
+      case PM_SOURCE_FIT_NORM:
+        // fits only source normalization (Io)
+        nParams = 1;
+        psVectorInit (constraint->paramMask, 1);
+        constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_I0] = 0;
+        break;
+
+      case PM_SOURCE_FIT_PSF:
+        // fits only x,y,Io
+        nParams = 3;
+        psVectorInit (constraint->paramMask, 1);
+        constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_I0] = 0;
+        constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_XPOS] = 0;
+        constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_YPOS] = 0;
+        break;
+
+      case PM_SOURCE_FIT_EXT:
+        // fits all params except sky
+        nParams = nParAll - 1;
+        psVectorInit (constraint->paramMask, 0);
+        constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_SKY] = 1;
+        break;
+
+      case PM_SOURCE_FIT_EXT_AND_SKY:
+        // fits all params including sky
+        nParams = nParAll;
+        psVectorInit (constraint->paramMask, 0);
+        break;
+
+      case PM_SOURCE_FIT_SHAPE:
+	// fits shape (Sxx, Sxy, Syy) and Io
+	nParams = 5;
+	psVectorInit (constraint->paramMask, 1);
+	constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_SKY] = 0;
+	constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_I0] = 0;
+	constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_SXX] = 0;
+	constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_SXY] = 0;
+	constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_SYY] = 0;
+	break;
+
+      case PM_SOURCE_FIT_INDEX:
+        // fits only Io, index (PAR7) -- only Io for models with < 8 params
+	psVectorInit (constraint->paramMask, 1);
+	constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_I0] = 0;
+        if (nParAll == 7) {
+	    nParams = 1;
+	} else {
+	    nParams = 2;
+	    constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_7] = 0;
+	}
+	break;
+
+      case PM_SOURCE_FIT_NO_INDEX:
+        // fits all but index (PAR7) including sky
+	psVectorInit (constraint->paramMask, 0);
+        if (nParAll == 7) {
+	    nParams = nParAll;
+	} else {
+	    nParams = nParAll - 1;
+	    constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_7] = 1;
+	}
+	break;
+      default:
+	psAbort("invalid fitting mode");
+    }
+    return nParams;
+}
+
+static int modelType_GAUSS = -1;
+static int modelType_PS1_V1 = -1;
+
+// generate a Gaussian smoothing kernel for supplied sigma.  sigma here does not need to match
+// that used to allocate the structure, but it is recommended
+bool psImageSmoothCacheKernel_PS1_V1 (psImageSmoothCacheData *smdata, float sigma, float kappa) {
+    // check for NULL structure elements?
+
+    int size = smdata->Nrange;
+
+    psFree (smdata->kernel);
+    smdata->kernel = psVectorAlloc(2 * smdata->Nrange + 1, PS_TYPE_F32);
+
+    double sum = 0.0;			// Sum of Gaussian, for normalization
+    double factor = 1.0 / (sigma * M_SQRT2);	// Multiplier for i -> z
+
+    // PS1_V1 is a power-law with fitted linear term:
+    // 1 / (1 + kappa z + z^1.666)  where z = (r/sigma)^2
+
+    // generate the kernel (not normalized)
+    for (int i = -size, j = 0; i <= size; i++, j++) {
+	float z = PS_SQR(i * factor);
+        sum += smdata->kernel->data.F32[j] = 1.0 / (1 + kappa * z + pow(z,1.666));
+    }
+
+    // renormalize kernel to integral of 1.0
+    for (int i = 0; i < 2 * size + 1; i++) {
+        smdata->kernel->data.F32[i] /= sum;
+    }
+
+    return true;
+}
+
+psImageSmoothCacheData *psImageSmoothCacheSetKernel (float *sigma, float *kappa, float nsigma, psImage *flux, pmModel *modelPSF) {
+
+    psAssert (modelPSF, "psf model must be defined");
+    
+    psEllipseAxes axes;
+    bool useReff = modelPSF->class->useReff;
+    psF32 *PAR = modelPSF->params->data.F32;
+    pmModelParamsToAxes (&axes, PAR[PM_PAR_SXX], PAR[PM_PAR_SXY], PAR[PM_PAR_SYY], useReff);
+    
+    *sigma = NAN;
+    *kappa = NAN;
+
+    // XXX need to do this more carefully
+    if (modelPSF->type == modelType_GAUSS) {
+	float FWHM_MAJOR = 2*modelPSF->class->modelRadius (modelPSF->params, 0.5*PAR[PM_PAR_I0]);
+	float FWHM_MINOR = FWHM_MAJOR * (axes.minor / axes.major);
+	*sigma = 0.50 * (FWHM_MAJOR + FWHM_MINOR) / 2.35;
+    }
+    if (modelPSF->type == modelType_PS1_V1) {
+	*sigma = 0.5 * (axes.major + axes.minor);
+	*kappa = PAR[PM_PAR_7];
+    }
+    psAssert (isfinite(*sigma), "invalid model type");
+
+    // psImageSmoothCacheAlloc generates a structure but does not assign the smoothing vector
+    psImageSmoothCacheData *smdata = psImageSmoothCacheAlloc (flux, *sigma, nsigma);
+
+    if (modelPSF->type == modelType_GAUSS) {
+	psImageSmoothCacheKernel_Gauss (smdata, *sigma);
+    }
+    if (modelPSF->type == modelType_PS1_V1) {
+	psImageSmoothCacheKernel_PS1_V1 (smdata, *sigma, *kappa);
+    }
+
+    return smdata;
+}
+
+psImageSmooth2dCacheData *psImageSmooth2dCacheSetKernel (float *sigma, float *kappa, float nsigma, psImage *flux, pmModel *modelPSF) {
+
+    psAssert (modelPSF, "psf model must be defined");
+    
+    psEllipseAxes axes;
+    bool useReff = modelPSF->class->useReff;
+    psF32 *PAR = modelPSF->params->data.F32;
+    pmModelParamsToAxes (&axes, PAR[PM_PAR_SXX], PAR[PM_PAR_SXY], PAR[PM_PAR_SYY], useReff);
+    
+    *sigma = NAN;
+    *kappa = NAN;
+
+    // XXX need to do this more carefully
+    if (modelPSF->type == modelType_GAUSS) {
+	float FWHM_MAJOR = 2*modelPSF->class->modelRadius (modelPSF->params, 0.5*PAR[PM_PAR_I0]);
+	float FWHM_MINOR = FWHM_MAJOR * (axes.minor / axes.major);
+	*sigma = 0.50 * (FWHM_MAJOR + FWHM_MINOR) / 2.35;
+    }
+    if (modelPSF->type == modelType_PS1_V1) {
+	*sigma = 0.5 * (axes.major + axes.minor);
+	*kappa = PAR[PM_PAR_7];
+    }
+    psAssert (isfinite(*sigma), "invalid model type");
+
+    // psImageSmoothCacheAlloc generates a structure but does not assign the smoothing vector
+    psImageSmooth2dCacheData *smdata = psImageSmooth2dCacheAlloc (nsigma);
+
+    if (modelPSF->type == modelType_GAUSS) {
+	psImageSmooth2dCacheKernel_Gauss (smdata, *sigma);
+    }
+    if (modelPSF->type == modelType_PS1_V1) {
+	psImageSmooth2dCacheKernel_PS1_V1 (smdata, *sigma, *kappa);
+    }
+
+    return smdata;
+}
+
 pmPCMdata *pmPCMinit(pmSource *source, pmSourceFitOptions *fitOptions, pmModel *model, psImageMaskType maskVal, float psfSize) {
 
-    // make sure we save a cached copy of the psf flux
-    pmSourceCachePSF (source, maskVal);
-
-    // convert the cached cached psf model for this source to a psKernel
-    psKernel *psf = pmPCMkernelFromPSF (source, psfSize);
-    if (!psf) {
-	// NOTE: this only happens if the source is too close to an edge
-        model->flags |= PM_MODEL_STATUS_BADARGS;
-	return NULL;
-    }
-
-# if (USE_DELTA_PSF)
-    psImageInit (psf->image, 0.0);
-    psf->image->data.F32[(int)(0.5*psf->image->numRows)][(int)(0.5*psf->image->numCols)] = 1.0;
-# endif
+    modelType_GAUSS = pmModelClassGetType ("PS_MODEL_GAUSS");
+    modelType_PS1_V1 = pmModelClassGetType ("PS_MODEL_PS1_V1");
 
     // count the number of unmasked pixels:
@@ -217,58 +393,10 @@
     psMinConstraint *constraint = psMinConstraintAlloc();
     constraint->paramMask = psVectorAlloc (params->n, PS_TYPE_VECTOR_MASK);
-    constraint->checkLimits = model->modelLimits;
-
-    // set parameter mask based on fitting mode
-    int nParams = 0;
-    switch (fitOptions->mode) {
-      case PM_SOURCE_FIT_NORM:
-        // NORM-only model fits only source normalization (Io)
-        nParams = 1;
-        psVectorInit (constraint->paramMask, 1);
-        constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_I0] = 0;
-        break;
-      case PM_SOURCE_FIT_PSF:
-        // PSF model only fits x,y,Io
-        nParams = 3;
-        psVectorInit (constraint->paramMask, 1);
-        constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_I0] = 0;
-        constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_XPOS] = 0;
-        constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_YPOS] = 0;
-        break;
-      case PM_SOURCE_FIT_EXT:
-        // EXT model fits all params (except sky)
-        nParams = params->n - 1;
-        psVectorInit (constraint->paramMask, 0);
-        constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_SKY] = 1;
-        break;
-      case PM_SOURCE_FIT_INDEX:
-        // PSF model only fits Io, index (PAR7) -- only Io for models with < 8 params
-	psVectorInit (constraint->paramMask, 1);
-	constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_I0] = 0;
-        if (params->n == 7) {
-	    nParams = 1;
-	} else {
-	    nParams = 2;
-	    constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_7] = 0;
-	}
-	break;
-      case PM_SOURCE_FIT_NO_INDEX:
-        // PSF model only fits Io, index (PAR7) -- only Io for models with < 8 params
-	psVectorInit (constraint->paramMask, 0);
-	constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_SKY] = 1;
-        if (params->n == 7) {
-	    nParams = params->n - 1;
-	} else {
-	    nParams = params->n - 2;
-	    constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_7] = 1;
-	}
-	break;
-      default:
-	psAbort("invalid fitting mode");
-    }
+    constraint->checkLimits = model->class->modelLimits;
+
+    int nParams = pmPCMsetParams (constraint, fitOptions->mode);
 
     if (nPix <  nParams + 1) {
         psTrace ("psModules.objects", 4, "insufficient valid pixels\n");
-	psFree (psf);
 	psFree (constraint);
         model->flags |= PM_MODEL_STATUS_BADARGS;
@@ -278,8 +406,9 @@
     // generate PCM data storage structure
     pmPCMdata *pcm = pmPCMdataAlloc (params, constraint->paramMask, source);
-
-    pcm->psf = psf;
     pcm->modelConv = psMemIncrRefCounter(model);
     pcm->constraint = constraint;
+
+    pcm->poissonErrors = fitOptions->poissonErrors;
+    pcm->nsigma = fitOptions->nsigma;
 
     pcm->nPix = nPix;
@@ -288,21 +417,29 @@
 
 # if (USE_1D_GAUSS)
-    pmModel *modelPSF = source->modelPSF;
-    psAssert (modelPSF, "psf model must be defined");
-    
-    psEllipseAxes axes;
-    bool useReff = pmModelUseReff (modelPSF->type);
-    psF32 *PAR = modelPSF->params->data.F32;
-    pmModelParamsToAxes (&axes, PAR[PM_PAR_SXX], PAR[PM_PAR_SXY], PAR[PM_PAR_SYY], useReff);
-    
-    float FWHM_MAJOR = 2*modelPSF->modelRadius (modelPSF->params, 0.5*PAR[PM_PAR_I0]);
-    float FWHM_MINOR = FWHM_MAJOR * (axes.minor / axes.major);
 
     pcm->use1Dgauss = true;
-    pcm->sigma = 0.5 * (FWHM_MAJOR + FWHM_MINOR) / 2.35;
-    pcm->nsigma = 2.0;
-
-    pcm->smdata = psImageSmooth_PreAlloc_DataAlloc (source->pixels, pcm->sigma, pcm->nsigma);
+    if (USE_1D_CACHE) {
+	pcm->smdata = psImageSmoothCacheSetKernel (&pcm->sigma, &pcm->kappa, pcm->nsigma, source->pixels, source->modelPSF);
+    } else {
+	pcm->smdata2d = psImageSmooth2dCacheSetKernel (&pcm->sigma, &pcm->kappa, pcm->nsigma, source->pixels, source->modelPSF);
+    }
+
 # else
+    // make sure we save a cached copy of the psf flux
+    pmSourceCachePSF (source, maskVal);
+
+    // convert the cached cached psf model for this source to a psKernel
+    psKernel *psf = pmPCMkernelFromPSF (source, psfSize);
+    if (!psf) {
+	// NOTE: this only happens if the source is too close to an edge
+        model->flags |= PM_MODEL_STATUS_BADARGS;
+	return NULL;
+    }
+
+# if (USE_DELTA_PSF)
+    psImageInit (psf->image, 0.0);
+    psf->image->data.F32[(int)(0.5*psf->image->numRows)][(int)(0.5*psf->image->numCols)] = 1.0;
+# endif
+    pcm->psf = psf;
     pcm->smdata = NULL;
 # endif
@@ -341,53 +478,5 @@
     }
 
-    // if we changed the fit mode, we need to update nDOF
-    int nParams = 0;
-    // set parameter mask based on fitting mode
-    switch (fitOptions->mode) {
-      case PM_SOURCE_FIT_NORM:
-	// NORM-only model fits only source normalization (Io)
-	nParams = 1;
-	psVectorInit (pcm->constraint->paramMask, 1);
-	pcm->constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_I0] = 0;
-	break;
-      case PM_SOURCE_FIT_PSF:
-	// PSF model only fits x,y,Io
-	nParams = 3;
-	psVectorInit (pcm->constraint->paramMask, 1);
-	pcm->constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_I0] = 0;
-	pcm->constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_XPOS] = 0;
-	pcm->constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_YPOS] = 0;
-	break;
-      case PM_SOURCE_FIT_EXT:
-	// EXT model fits all params (except sky)
-	nParams = model->params->n - 1;
-	psVectorInit (pcm->constraint->paramMask, 0);
-	pcm->constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_SKY] = 1;
-	break;
-      case PM_SOURCE_FIT_INDEX:
-	// PSF model only fits Io, index (PAR7) -- only Io for models with < 8 params
-	psVectorInit (pcm->constraint->paramMask, 1);
-	pcm->constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_I0] = 0;
-	if (model->params->n == 7) {
-	    nParams = 1;
-	} else {
-	    nParams = 2;
-	    pcm->constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_7] = 0;
-	}
-	break;
-      case PM_SOURCE_FIT_NO_INDEX:
-	// PSF model only fits Io, index (PAR7) -- only Io for models with < 8 params
-	psVectorInit (pcm->constraint->paramMask, 0);
-	pcm->constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_SKY] = 1;
-	if (model->params->n == 7) {
-	    nParams = model->params->n - 1;
-	} else {
-	    nParams = model->params->n - 2;
-	    pcm->constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_7] = 1;
-	}
-	break;
-      default:
-	psAbort("invalid fitting mode");
-    }
+    int nParams = pmPCMsetParams (pcm->constraint, fitOptions->mode);
 
     if (pcm->nPix <  nParams + 1) {
@@ -415,6 +504,29 @@
 	    pcm->dmodelsConvFlux->data[n] = psImageCopy (pcm->dmodelsConvFlux->data[n], source->pixels, PS_TYPE_F32);
 	}
-	psFree(pcm->smdata);
-	pcm->smdata = psImageSmooth_PreAlloc_DataAlloc (source->pixels, pcm->sigma, pcm->nsigma);
+
+	// If we have changed the window, we need to redefine the smoothing target vectors (but pcm->sigma,kappa,nsigma remain)
+	if (USE_1D_CACHE) {
+	    psFree(pcm->smdata);
+	    pcm->smdata = psImageSmoothCacheAlloc (source->pixels, pcm->sigma, pcm->nsigma);
+
+	    pmModel *modelPSF = source->modelPSF;
+	    if (modelPSF->type == modelType_GAUSS) {
+		psImageSmoothCacheKernel_Gauss (pcm->smdata, pcm->sigma);
+	    }
+	    if (modelPSF->type == modelType_PS1_V1) {
+		psImageSmoothCacheKernel_PS1_V1 (pcm->smdata, pcm->sigma, pcm->kappa);
+	    }
+	} else {
+	    psFree(pcm->smdata2d);
+	    pcm->smdata2d = psImageSmooth2dCacheAlloc (pcm->nsigma);
+
+	    pmModel *modelPSF = source->modelPSF;
+	    if (modelPSF->type == modelType_GAUSS) {
+		// psImageSmooth2dCacheKernel_Gauss (pcm->smdata2d, pcm->sigma);
+	    }
+	    if (modelPSF->type == modelType_PS1_V1) {
+		psImageSmooth2dCacheKernel_PS1_V1 (pcm->smdata2d, pcm->sigma, pcm->kappa);
+	    }
+	}
     }
 
@@ -423,5 +535,5 @@
 
 // construct a realization of the source model
-bool pmPCMCacheModel (pmSource *source, psImageMaskType maskVal, int psfSize) {
+bool pmPCMCacheModel (pmSource *source, psImageMaskType maskVal, int psfSize, float nsigma) {
 
     PS_ASSERT_PTR_NON_NULL(source, false);
@@ -440,24 +552,18 @@
     // convolve the model image with the PSF
     if (USE_1D_GAUSS) {
-	// do not use the threaded, mask-aware version of this code (psImageSmoothMaskPixelsThread):
-	// * the model flux is not masked
-	// * threading takes place above this level
 	
-	// define the Gauss parameters from the psf
-	pmModel *modelPSF = source->modelPSF;
-	psAssert (modelPSF, "psf model must be defined");
-    
-	psEllipseAxes axes;
-	bool useReff = pmModelUseReff (modelPSF->type);
-	psF32 *PAR = modelPSF->params->data.F32;
-	pmModelParamsToAxes (&axes, PAR[PM_PAR_SXX], PAR[PM_PAR_SXY], PAR[PM_PAR_SYY], useReff);
-    
-	float FWHM_MAJOR = 2*modelPSF->modelRadius (modelPSF->params, 0.5*PAR[PM_PAR_I0]);
-	float FWHM_MINOR = FWHM_MAJOR * (axes.minor / axes.major);
-
-	float sigma = 0.5 * (FWHM_MAJOR + FWHM_MINOR) / 2.35;
-	float nsigma = 2.0;
-
-	psImageSmooth (source->modelFlux, sigma, nsigma);
+	float sigma = NAN;
+	float kappa = NAN;
+
+	if (USE_1D_CACHE) {
+	    psImageSmoothCacheData *smdata = psImageSmoothCacheSetKernel (&sigma, &kappa, nsigma, source->modelFlux, source->modelPSF);
+	    psImageSmoothCache_F32 (source->modelFlux, smdata);
+	    psFree (smdata);
+	} else {
+	    psImageSmooth2dCacheData *smdata = psImageSmooth2dCacheSetKernel (&sigma, &kappa, nsigma, source->modelFlux, source->modelPSF);
+	    psImageSmooth2dCache_F32 (source->modelFlux, smdata);
+	    psFree (smdata);
+	}
+	// old call: psImageSmooth (source->modelFlux, sigma, nsigma);
     } else {
 	// make sure we save a cached copy of the psf flux
@@ -478,2 +584,48 @@
 }
 
+// construct a realization of the source model
+bool pmPCMMakeModel (pmSource *source, pmModel *model, float Nsigma, psImageMaskType maskVal, int psfSize) {
+
+    PS_ASSERT_PTR_NON_NULL(source, false);
+
+    // if we already have a cached image, re-use that memory
+    source->modelFlux = psImageCopy (source->modelFlux, source->pixels, PS_TYPE_F32);
+    psImageInit (source->modelFlux, 0.0);
+
+    // modelFlux always has unity normalization (I0 = 1.0)
+    // pmModelAdd (source->modelFlux, source->maskObj, model, PM_MODEL_OP_FULL | PM_MODEL_OP_NORM, maskVal);
+    pmModelAdd (source->modelFlux, NULL, model, PM_MODEL_OP_FULL | PM_MODEL_OP_SKY | PM_MODEL_OP_NORM, maskVal);
+
+    // convolve the model image with the PSF
+    if (USE_1D_GAUSS) {
+
+	float sigma = NAN;
+	float kappa = NAN;
+
+	if (USE_1D_CACHE) {
+	    psImageSmoothCacheData *smdata = psImageSmoothCacheSetKernel (&sigma, &kappa, Nsigma, source->modelFlux, source->modelPSF);
+	    psImageSmoothCache_F32 (source->modelFlux, smdata);
+	    psFree (smdata);
+	} else {
+	    psImageSmooth2dCacheData *smdata = psImageSmooth2dCacheSetKernel (&sigma, &kappa, Nsigma, source->modelFlux, source->modelPSF);
+	    psImageSmooth2dCache_F32 (source->modelFlux, smdata);
+	    psFree (smdata);
+	}
+	// old call: psImageSmooth (source->modelFlux, sigma, nsigma);
+    } else {
+	// make sure we save a cached copy of the psf flux
+	pmSourceCachePSF (source, maskVal);
+
+	// convert the cached cached psf model for this source to a psKernel
+	psKernel *psf = pmPCMkernelFromPSF (source, psfSize);
+	if (!psf) {
+	    // NOTE: this only happens if the source is too close to an edge
+	    model->flags |= PM_MODEL_STATUS_BADARGS;
+	    return NULL;
+	}
+
+	// XXX not sure if I can place the output on top of the input
+	psImageConvolveFFT (source->modelFlux, source->modelFlux, NULL, 0, psf);
+    }
+    return true;
+}
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmPCMdata.h
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmPCMdata.h	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmPCMdata.h	(revision 37066)
@@ -14,4 +14,8 @@
 /// @addtogroup Objects Object Detection / Analysis Functions
 /// @{
+
+// XXX this is basically for testing -- when I am happy with the convolution process, I'll strip this out
+# define USE_1D_CACHE 0
+# define USE_1D_GAUSS 1
 
 /** pmPCMdata : PSF Convolved Model data storage structure
@@ -36,9 +40,14 @@
     int nDOF;
 
+    bool poissonErrors;
+
     bool use1Dgauss;
+    float kappa;
     float sigma;
     float nsigma;
 
-    psImageSmooth_PreAlloc_Data *smdata;
+    // psArray *smdata;
+    psImageSmoothCacheData *smdata;
+    psImageSmooth2dCacheData *smdata2d;
 } pmPCMdata;
 
@@ -96,5 +105,7 @@
 bool pmSourceFitPCM (pmPCMdata *pcm, pmSource *source, pmSourceFitOptions *fitOptions, psImageMaskType maskVal, psImageMaskType markVal, int psfSize);
 
-bool pmPCMCacheModel (pmSource *source, psImageMaskType maskVal, int psfSize);
+bool pmPCMCacheModel (pmSource *source, psImageMaskType maskVal, int psfSize, float nsigma);
+
+bool pmPCMMakeModel (pmSource *source, pmModel *model, float Nsigma, psImageMaskType maskVal, int psfSize);
 
 /// @}
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmPSF.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmPSF.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmPSF.c	(revision 37066)
@@ -37,11 +37,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceFitModel.h"
@@ -328,5 +329,5 @@
 // convert the parameters used in the fitted source model to the psEllipseAxes representation
 // (major,minor,theta)
-psEllipseAxes pmPSF_ModelToAxes (psF32 *modelPar, pmModelType type)
+psEllipseAxes pmPSF_ModelToAxes (psF32 *modelPar, bool useReff)
 {
     psEllipseAxes axes;
@@ -337,5 +338,4 @@
     PS_ASSERT_PTR_NON_NULL(modelPar, axes);
 
-    bool useReff = pmModelUseReff (type);
     pmModelParamsToAxes (&axes, modelPar[PM_PAR_SXX], modelPar[PM_PAR_SXY], modelPar[PM_PAR_SYY], useReff);
     return axes;
@@ -344,5 +344,5 @@
 // convert the psEllipseAxes representation (major,minor,theta) to the parameters used in the
 // fitted source model
-bool pmPSF_AxesToModel (psF32 *modelPar, psEllipseAxes axes, pmModelType type)
+bool pmPSF_AxesToModel (psF32 *modelPar, psEllipseAxes axes, bool useReff)
 {
     PS_ASSERT_PTR_NON_NULL(modelPar, false);
@@ -356,5 +356,4 @@
     }
     
-    bool useReff = pmModelUseReff (type);
     pmModelAxesToParams (&modelPar[PM_PAR_SXX], &modelPar[PM_PAR_SXY], &modelPar[PM_PAR_SYY], axes, useReff);
     return true;
@@ -419,9 +418,9 @@
 
     // get the model full-width at half-max
-    float fwhmMajor = 2*model->modelRadius (model->params, 0.5);
+    float fwhmMajor = 2*model->class->modelRadius (model->params, 0.5);
 
 # if (0)
     psF32 *params = model->params->data.F32; // Model parameters
-    psEllipseAxes axes = pmPSF_ModelToAxes(params, MAX_AXIS_RATIO, model->type); // Ellipse axes
+    psEllipseAxes axes = pmPSF_ModelToAxes(params, MAX_AXIS_RATIO, model->class->useReff); // Ellipse axes
 
     // Curiously, the minor axis can be larger than the major axis, so need to check.
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmPSF.h
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmPSF.h	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmPSF.h	(revision 37066)
@@ -106,9 +106,9 @@
 pmPSF *pmPSFBuildSimple (char *typeName, float sxx, float syy, float sxy, ...);
 
-bool pmPSF_AxesToModel (psF32 *modelPar, psEllipseAxes axes, pmModelType type);
+bool pmPSF_AxesToModel (psF32 *modelPar, psEllipseAxes axes, bool useReff);
 bool pmPSF_FitToModel (psF32 *fittedPar, float minMinorAxis, bool useReff);
 
 psEllipsePol pmPSF_ModelToFit (psF32 *modelPar, bool useReff);
-psEllipseAxes pmPSF_ModelToAxes (psF32 *modelPar, pmModelType type);
+psEllipseAxes pmPSF_ModelToAxes (psF32 *modelPar, bool useReff);
 
 /// Calculate FWHM value from a PSF
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmPSF_IO.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmPSF_IO.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmPSF_IO.c	(revision 37066)
@@ -47,11 +47,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceFitModel.h"
@@ -510,11 +511,13 @@
         psMetadataAddF32 (header, PS_LIST_TAIL, "SKY_BIAS", PS_DATA_F32, "sky bias level", psf->skyBias);
 
-	float PSF_APERTURE =  psMetadataLookupF32(&status, roAnalysis, "PSF_APERTURE");
-	if (status) {
+	if (roAnalysis) {
+	  float PSF_APERTURE =  psMetadataLookupF32(&status, roAnalysis, "PSF_APERTURE");
+	  if (status) {
 	    psMetadataAddF32 (header, PS_LIST_TAIL, "PSF_APERTURE", PS_DATA_F32, "aperture for psf objects", PSF_APERTURE);
-	}
-	float PSF_FIT_RADIUS =  psMetadataLookupF32(&status, roAnalysis, "PSF_FIT_RADIUS");
-	if (status) {
+	  }
+	  float PSF_FIT_RADIUS =  psMetadataLookupF32(&status, roAnalysis, "PSF_FIT_RADIUS");
+	  if (status) {
 	    psMetadataAddF32 (header, PS_LIST_TAIL, "PSF_FIT_RADIUS", PS_DATA_F32, "aperture for psf objects", PSF_FIT_RADIUS);
+	  }
 	}
 
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmPSFtry.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmPSFtry.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmPSFtry.c	(revision 37066)
@@ -29,11 +29,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceFitModel.h"
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmPSFtryFitEXT.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmPSFtryFitEXT.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmPSFtryFitEXT.c	(revision 37066)
@@ -29,11 +29,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceUtils.h"
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmPSFtryFitPSF.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmPSFtryFitPSF.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmPSFtryFitPSF.c	(revision 37066)
@@ -27,11 +27,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceFitModel.h"
@@ -118,38 +119,46 @@
     psfTry->psf->nPSFstars = Npsf;
 
-    // DEBUG code: save the PSF model fit data in detail
-# ifdef DEBUG
-
-    char filename[64];
-    snprintf (filename, 64, "psffit.%dx%d.dat", psfTry->psf->trendNx, psfTry->psf->trendNy);
-    FILE *f = fopen (filename, "w");
-    psAssert (f, "failed open");
-
-    for (int i = 0; i < psfTry->sources->n; i++) {
-
-	// skip masked sources
-        if (psfTry->mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & PSFTRY_MASK_ALL) continue;
-
-        pmSource *source = psfTry->sources->data[i];
-
-	fprintf (f, "%6.1f %6.1f : %6.1f %6.1f : %8.3f %8.3f %8.3f : %f : %f %f %f : %f\n",
-		 source->peak->xf, source->peak->yf, 
-		 source->modelPSF->params->data.F32[PM_PAR_XPOS], source->modelPSF->params->data.F32[PM_PAR_YPOS], 
-		 source->psfMag, source->apMag, source->psfMagErr,
-		 source->modelPSF->params->data.F32[PM_PAR_I0], 
-		 source->modelPSF->params->data.F32[PM_PAR_SXX], source->modelPSF->params->data.F32[PM_PAR_SXY], 
-		 source->modelPSF->params->data.F32[PM_PAR_SYY], source->modelPSF->params->data.F32[PM_PAR_7]);
-    }
-    fclose (f);
-# endif
-
     pmSourceVisualShowModelFits (psfTry->psf, psfTry->sources, maskVal);
 
-    psLogMsg ("psphot.psftry", PS_LOG_MINUTIA, "fit psf:   %f sec for %d of %ld sources\n", psTimerMark ("psf.fit"), Npsf, psfTry->sources->n);
+    psLogMsg ("psphot.psftry", PS_LOG_MINUTIA, "fit psf:   %f sec for %d of %ld sources (%d x %d model)\n", psTimerMark ("psf.fit"), Npsf, psfTry->sources->n, psfTry->psf->trendNx, psfTry->psf->trendNy);
     psTrace ("psModules.object", 3, "keeping %d of %ld PSF candidates (PSF)\n", Npsf, psfTry->sources->n);
 
     if (Npsf == 0) {
-        psError(PS_ERR_UNKNOWN, false, "No sources with good PSF fits after model is built.");
-        return false;
+#if 0
+	// DEBUG code: save the PSF model fit data in detail
+
+	char hostname[256];
+	gethostname (hostname, 256);
+
+	int pid = getpid();
+
+	char filename[64];
+	snprintf (filename, 64, "psffit.%s.%d.%dx%d.dat", hostname, pid, psfTry->psf->trendNx, psfTry->psf->trendNy);
+	FILE *f = fopen (filename, "w");
+	psAssert (f, "failed open");
+
+	for (int i = 0; i < psfTry->sources->n; i++) {
+
+	    // skip masked sources
+	  // if (psfTry->mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & PSFTRY_MASK_ALL) continue;
+
+	    pmSource *source = psfTry->sources->data[i];
+
+            if (!source->modelPSF) continue;
+
+	    float par7 = (source->modelPSF->params->n == 7) ? -100 : source->modelPSF->params->data.F32[PM_PAR_7];
+	    fprintf (f, "%6.1f %6.1f : %6.1f %6.1f : %8.3f %8.3f %8.3f : %f : %f %f %f : %f %d\n",
+		     source->peak->xf, source->peak->yf, 
+		     source->modelPSF->params->data.F32[PM_PAR_XPOS], source->modelPSF->params->data.F32[PM_PAR_YPOS], 
+		     source->psfMag, source->apMag, source->psfMagErr,
+		     source->modelPSF->params->data.F32[PM_PAR_I0], 
+		     source->modelPSF->params->data.F32[PM_PAR_SXX], source->modelPSF->params->data.F32[PM_PAR_SXY], 
+		     source->modelPSF->params->data.F32[PM_PAR_SYY], par7,
+		     psfTry->mask->data.PS_TYPE_VECTOR_MASK_DATA[i]);
+	}
+	fclose (f);
+#endif
+	psError(PS_ERR_UNKNOWN, false, "No sources with good PSF fits after model is built.");
+	return false;
     }
 
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmPSFtryMakePSF.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmPSFtryMakePSF.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmPSFtryMakePSF.c	(revision 37066)
@@ -28,11 +28,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceFitModel.h"
@@ -211,5 +212,5 @@
         assert (source->modelEXT); // all unmasked sources should have modelEXT
 
-	bool useReff = pmModelUseReff (source->modelEXT->type);
+	bool useReff = source->modelEXT->class->useReff;
         psEllipsePol pol = pmPSF_ModelToFit (source->modelEXT->params->data.F32, useReff);
 
@@ -217,4 +218,26 @@
         e1->data.F32[i] = pol.e1;
         e2->data.F32[i] = pol.e2;
+    }
+
+    // weed out extreme e0 outliers here: find the median and exclude points not in the
+    // range MEDIAN / 5 < e0 < 5 * MEDIAN
+    { 
+      psStats *e0stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN);
+      if (psVectorStats (e0stats, e0, NULL, srcMask, 0xff)) {
+	float e0med = e0stats->sampleMedian;
+    
+	for (int i = 0; i < sources->n; i++) {
+	  // skip any masked sources (failed to fit one of the model steps or get a magnitude)
+	  if (srcMask->data.PS_TYPE_VECTOR_MASK_DATA[i]) continue;
+
+	  if (e0->data.F32[i] < 0.2*e0med) {
+	    srcMask->data.PS_TYPE_VECTOR_MASK_DATA[i] = PSFTRY_MASK_OUTLIER;
+	  }
+	  if (e0->data.F32[i] > 5.0*e0med) {
+	    srcMask->data.PS_TYPE_VECTOR_MASK_DATA[i] = PSFTRY_MASK_OUTLIER;
+	  }
+	}
+      }
+      psFree (e0stats);
     }
 
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmPSFtryMetric.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmPSFtryMetric.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmPSFtryMetric.c	(revision 37066)
@@ -28,11 +28,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceFitModel.h"
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmPSFtryModel.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmPSFtryModel.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmPSFtryModel.c	(revision 37066)
@@ -29,11 +29,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceFitModel.h"
@@ -111,10 +112,19 @@
 
     // set the max order (0 = constant) which the number of psf stars can support:
+    int MaxOrderForStars = 0;
+
+    // we require only 3 stars for n = 0, increase stars / cell for higher order
+    if (sources->n >=  16) MaxOrderForStars = 1; //  4 cells, 4 per cell
+    if (sources->n >=  54) MaxOrderForStars = 2; //  9 cells, 6 per cell
+    if (sources->n >= 128) MaxOrderForStars = 3; // 16 cells, 8 per cell
+    if (sources->n >= 300) MaxOrderForStars = 4; // 25 cells, 12 per cell
+    if (sources->n >  576) MaxOrderForStars = 5; // 36 cells, 16 per cell
+
     // rule of thumb: require 3 stars per 'cell' (order+1)^2
-    int MaxOrderForStars = 0;
-    if (sources->n >= 12) MaxOrderForStars = 1; // 4 cells
-    if (sources->n >= 27) MaxOrderForStars = 2; // 9 cells
-    if (sources->n >= 48) MaxOrderForStars = 3; // 16 cells
-    if (sources->n >  75) MaxOrderForStars = 4; // 25 cells
+    // if (sources->n >= 12) MaxOrderForStars = 1; // 4 cells
+    // if (sources->n >= 27) MaxOrderForStars = 2; // 9 cells
+    // if (sources->n >= 48) MaxOrderForStars = 3; // 16 cells
+    // if (sources->n >= 75) MaxOrderForStars = 4; // 25 cells
+    // if (sources->n > 108) MaxOrderForStars = 5; // 36 cells
 
     int orderMax = PS_MAX (options->psfTrendNx, options->psfTrendNy);
@@ -236,4 +246,14 @@
     // linear clipped fit of chisq trend vs flux
     if (options->chiFluxTrend) {
+
+	if (0) {
+	    FILE *f = fopen ("test.psf.dat", "w");
+	    int fd = fileno (f);
+	    p_psVectorPrint (fd, flux, "flux");
+	    p_psVectorPrint (fd, chisq, "chisq");
+	    p_psVectorPrint (fd, mask, "mask");
+	    fclose (f);
+	}
+
         bool result = psVectorClipFitPolynomial1D(psfTry->psf->ChiTrend, options->stats,
                                                   mask, 0xff, chisq, NULL, flux);
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmPhotObj.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmPhotObj.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmPhotObj.c	(revision 37066)
@@ -29,11 +29,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSource.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSource.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSource.c	(revision 37066)
@@ -33,7 +33,7 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
@@ -41,4 +41,5 @@
 #include "pmSourcePhotometry.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 
@@ -66,5 +67,8 @@
     psFree(tmp->extpars);
     psFree(tmp->diffStats);
+    psFree(tmp->galaxyFits);
     psFree(tmp->radialAper);
+    psFree(tmp->lensingOBJ);
+    psFree(tmp->lensingPSF);
     psTrace("psModules.objects", 10, "---- end ----\n");
 }
@@ -142,4 +146,5 @@
     source->apMagRaw  	     = NAN;
     source->apRadius  	     = NAN;
+    source->apNpixels  	     = 0;
     source->apFlux    	     = NAN;
     source->apFluxErr 	     = NAN; 
@@ -158,4 +163,5 @@
     source->sky    	     = NAN;
     source->skyErr 	     = NAN;    
+    source->extSN  	     = NAN;    
 
     source->region = psRegionSet(NAN, NAN, NAN, NAN);
@@ -164,4 +170,7 @@
     source->extpars = NULL;
     source->diffStats = NULL;
+    source->galaxyFits = NULL;
+    source->lensingOBJ = NULL;
+    source->lensingPSF = NULL;
     source->radialAper = NULL;
     source->parent = NULL;
@@ -229,4 +238,5 @@
     source->apMagRaw  	     = in->apMagRaw;
     source->apRadius  	     = in->apRadius;
+    source->apNpixels  	     = in->apNpixels;
     source->apFlux    	     = in->apFlux;
     source->apFluxErr 	     = in->apFluxErr;
@@ -247,4 +257,6 @@
 
     source->region           = in->region;
+
+    // XXX I am not copying the pointers to things like the blends, satstar profile, galaxyFits, etc
 
     return(source);
@@ -690,5 +702,4 @@
             // why do we recalculate moments here?
 	    // we already attempt to do this in psphotSourceStats
-            // pmSourceMoments (source, INNER_RADIUS);
             Nsatstar ++;
             continue;
@@ -804,191 +815,4 @@
     return true;
 }
-
-/******************************************************************************
-pmSourceMoments(source, radius): this function takes a subImage defined in the
-pmSource data structure, along with the peak location, and determines the
-various moments associated with that peak.
-
-Requires the following to have been created:
-    pmSource
-    pmSource->peak
-    pmSource->pixels
-    pmSource->variance
-    pmSource->mask
-
-XXX: The peak calculations are done in image coords, not subImage coords.
-
-XXX EAM : this version clips input pixels on S/N
-XXX EAM : this version returns false for several reasons
-*****************************************************************************/
-# define VALID_RADIUS(X,Y,RAD2) (((RAD2) >= (PS_SQR(X) + PS_SQR(Y))) ? 1 : 0)
-
-/*** this been moved to pmSourceMoments.c ***/
-# if (0)
-bool pmSourceMoments(pmSource *source,
-                     psF32 radius)
-{
-    psTrace("psModules.objects", 10, "---- begin ----\n");
-    PS_ASSERT_PTR_NON_NULL(source, false);
-    PS_ASSERT_PTR_NON_NULL(source->peak, false);
-    PS_ASSERT_PTR_NON_NULL(source->pixels, false);
-    PS_ASSERT_FLOAT_LARGER_THAN(radius, 0.0, false);
-
-    //
-    // XXX: Verify the setting for sky if source->moments == NULL.
-    //
-    psF32 sky = 0.0;
-    if (source->moments == NULL) {
-        source->moments = pmMomentsAlloc();
-    } else {
-        sky = source->moments->Sky;
-    }
-
-    //
-    // Sum = SUM (z - sky)
-    // X1  = SUM (x - xc)*(z - sky)
-    // X2  = SUM (x - xc)^2 * (z - sky)
-    // XY  = SUM (x - xc)*(y - yc)*(z - sky)
-    //
-    psF32 peakPixel = -PS_MAX_F32;
-    psS32 numPixels = 0;
-    psF32 Sum = 0.0;
-    psF32 Var = 0.0;
-    psF32 X1 = 0.0;
-    psF32 Y1 = 0.0;
-    psF32 X2 = 0.0;
-    psF32 Y2 = 0.0;
-    psF32 XY = 0.0;
-    psF32 x  = 0;
-    psF32 y  = 0;
-    psF32 R2 = PS_SQR(radius);
-
-    psF32 xPeak = source->peak->x;
-    psF32 yPeak = source->peak->y;
-    psF32 xOff = source->pixels->col0 - source->peak->x;
-    psF32 yOff = source->pixels->row0 - source->peak->y;
-
-    // XXX why do I get different results for these two methods of finding Sx?
-    // XXX Sx, Sy would be better measured if we clip pixels close to sky
-    // XXX Sx, Sy can still be imaginary, so we probably need to keep Sx^2?
-    // We loop through all pixels in this subimage (source->pixels), and for each
-    // pixel that is not masked, AND within the radius of the peak pixel, we
-    // proceed with the moments calculation.  need to do two loops for a
-    // numerically stable result.  first loop: get the sums.
-    // XXX EAM : mask == 0 is valid
-
-    for (psS32 row = 0; row < source->pixels->numRows ; row++) {
-
-        psF32 *vPix = source->pixels->data.F32[row];
-        psF32 *vWgt = source->variance->data.F32[row];
-        psImageMaskType *vMsk = (source->maskObj == NULL) ? NULL : source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[row];
-
-        for (psS32 col = 0; col < source->pixels->numCols ; col++, vPix++, vWgt++) {
-            if (vMsk) {
-                if (*vMsk) {
-                    vMsk++;
-                    psTrace("psModules.objects", 10, "Ignoring pixel %d,%d due to mask: %d\n",
-                            col, row, (int)*vMsk);
-                    continue;
-                }
-                vMsk++;
-            }
-            if (isnan(*vPix)) continue;
-
-            psF32 xDiff = col + xOff;
-            psF32 yDiff = row + yOff;
-
-            // radius is just a function of (xDiff, yDiff)
-            if (!VALID_RADIUS(xDiff, yDiff, R2)) {
-#if 1
-                psTrace("psModules.objects", 10, "Ignoring pixel %d,%d due to position: %f %f\n",
-                        col, row, xDiff, yDiff);
-#endif
-                continue;
-            }
-
-            psF32 pDiff = *vPix - sky;
-            psF32 wDiff = *vWgt;
-
-            // XXX EAM : check for valid S/N in pixel
-            // XXX EAM : should this limit be user-defined?
-#if 1
-            if (PS_SQR(pDiff) < wDiff) {
-                psTrace("psModules.objects", 10, "Ignoring pixel %d,%d due to insignificance: %f, %f\n",
-                        col, row, pDiff, wDiff);
-                continue;
-            }
-#endif
-
-            Var += wDiff;
-            Sum += pDiff;
-
-            psF32 xWght = xDiff * pDiff;
-            psF32 yWght = yDiff * pDiff;
-
-            X1  += xWght;
-            Y1  += yWght;
-
-            XY  += xDiff * yWght;
-            X2  += xDiff * xWght;
-            Y2  += yDiff * yWght;
-
-            peakPixel = PS_MAX (*vPix, peakPixel);
-            numPixels++;
-        }
-    }
-
-    // if we have less than (1/4) of the possible pixels, force a retry
-    // XXX EAM - the limit is a bit arbitrary.  make it user defined?
-    if ((numPixels < 0.75*R2) || (Sum <= 0)) {
-        psTrace ("psModules.objects", 3, "insufficient valid pixels (%d vs %d; %f) for source\n",
-                 numPixels, (int)(0.75*R2), Sum);
-        psTrace("psModules.objects", 10, "---- end (false) ----\n");
-        return (false);
-    }
-
-    psTrace ("psModules.objects", 4, "sky: %f  Sum: %f  X1: %f  Y1: %f  X2: %f  Y2: %f  XY: %f  Npix: %d\n",
-             sky, Sum, X1, Y1, X2, Y2, XY, numPixels);
-
-    //
-    // first moment X  = X1/Sum + xc
-    // second moment X = sqrt (X2/Sum - (X1/Sum)^2)
-    // Sxy             = XY / Sum
-    //
-    x = X1/Sum;
-    y = Y1/Sum;
-    if ((fabs(x) > radius) || (fabs(y) > radius)) {
-        psTrace ("psModules.objects", 3, "large centroid swing; invalid peak %d, %d\n",
-                 source->peak->x, source->peak->y);
-        psTrace("psModules.objects", 10, "---- end(false)  ----\n");
-        return (false);
-    }
-
-    source->moments->Mx = x + xPeak;
-    source->moments->My = y + yPeak;
-
-    // XXX EAM : Sxy needs to have x*y subtracted
-    source->moments->Mxy = XY/Sum - x*y;
-    source->moments->Sum = Sum;
-    source->moments->SN  = Sum / sqrt(Var);
-    source->moments->Peak = peakPixel;
-    source->moments->nPixels = numPixels;
-
-    // XXX EAM : these values can be negative, so we need to limit the range
-    // XXX EAM : make the use of this consistent: should this be the second moment or sqrt?
-    // source->moments->Mxx = sqrt(PS_MAX(X2/Sum - PS_SQR(x), 0));
-    // source->moments->Myy = sqrt(PS_MAX(Y2/Sum - PS_SQR(y), 0));
-    source->moments->Mxx = PS_MAX(X2/Sum - PS_SQR(x), 0);
-    source->moments->Myy = PS_MAX(Y2/Sum - PS_SQR(y), 0);
-
-    psTrace ("psModules.objects", 4,
-             "sky: %f  Sum: %f  Mx: %f  My: %f  Mxx: %f  Myy: %f  Mxy: %f\n",
-             sky, Sum, source->moments->Mx, source->moments->My,
-             source->moments->Mxx, source->moments->Myy, source->moments->Mxy);
-
-    psTrace("psModules.objects", 10, "---- end ----\n");
-    return(true);
-}
-# endif
 
 // construct a realization of the source model
@@ -1165,5 +989,5 @@
     if (!isfinite(oldI0)) return false;
 
-    bool useReff = pmModelUseReff (model->type);
+    bool useReff = model->class->useReff;
     pmModelParamsToAxes (&axes, PAR[PM_PAR_SXX], PAR[PM_PAR_SXY], PAR[PM_PAR_SYY], useReff);
 
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSource.h
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSource.h	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSource.h	(revision 37066)
@@ -40,4 +40,6 @@
     PM_SOURCE_TMPF_PETRO_KEEP        = 0x0100,
     PM_SOURCE_TMPF_PETRO_SKIP        = 0x0200,
+    PM_SOURCE_TMPF_EXT_FIT           = 0x0400,  // not just galaxies (trails as well)
+    PM_SOURCE_TMPF_PETRO             = 0x0800,
 } pmSourceTmpF;
 
@@ -95,4 +97,5 @@
     float apMagRaw;                     ///< raw mag in given aperture
     float apRadius;			///< radius for aperture magnitude
+    int   apNpixels;			///< number of unmasked pixels in aperture
     float apFlux;                       ///< apFlux corresponding to psfMag or extMag (depending on type)
     float apFluxErr;                    ///< apFluxErr corresponding to psfMag or extMag (depending on type)
@@ -111,4 +114,5 @@
     float sky;				///< The sky at the center of the object 
     float skyErr;			///< The sky error at the center of the object
+    float extSN;                        ///< for externally supplied source the kron signal to noise (used by full force)
 
     psRegion region;                    ///< area on image covered by selected pixels
@@ -117,4 +121,7 @@
     pmSourceExtendedPars *extpars;      ///< extended source parameters
     pmSourceDiffStats *diffStats;       ///< extra parameters for difference detections
+    psArray *galaxyFits;                ///< fits to galaxy models (psphotFullForce only)
+    pmSourceLensing *lensingOBJ;        ///< lensing moments parameters (per object)
+    pmSourceLensing *lensingPSF;        ///< lensing moments parameters (psf, interpolated)
     psArray *radialAper;		///< radial flux in circular apertures
     pmSource *parent;			///< reference to the master source from which this is derived
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceContour.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceContour.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceContour.c	(revision 37066)
@@ -33,11 +33,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceExtendedPars.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceExtendedPars.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceExtendedPars.c	(revision 37066)
@@ -286,2 +286,25 @@
     return pars;
 }
+
+// *** pmSourceExtFitPars describes extra metadata related to an extended fit
+static void pmSourceGalaxyFitsFree (pmSourceGalaxyFits *tmp) {
+  
+    psFree (tmp->Flux);
+    psFree (tmp->dFlux);
+    psFree (tmp->chisq);
+
+    return;
+}
+
+pmSourceGalaxyFits *pmSourceGalaxyFitsAlloc (void) {
+
+    pmSourceGalaxyFits *tmp = (pmSourceGalaxyFits *) psAlloc(sizeof(pmSourceGalaxyFits));
+    psMemSetDeallocator(tmp, (psFreeFunc) pmSourceGalaxyFitsFree);
+
+    tmp->Flux  = psVectorAllocEmpty (25, PS_TYPE_F32);
+    tmp->dFlux = psVectorAllocEmpty (25, PS_TYPE_F32);
+    tmp->chisq = psVectorAllocEmpty (25, PS_TYPE_F32);
+    tmp->nPix = 0;
+
+    return tmp;
+}
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceExtendedPars.h
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceExtendedPars.h	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceExtendedPars.h	(revision 37066)
@@ -82,4 +82,19 @@
 } pmSourceExtFitPars;
 
+typedef struct {
+  int       modelType;
+  psVector *Flux;
+  psVector *dFlux;
+  psVector *chisq;
+  int       nPix;
+  bool      reducedTrials;
+  float     fRmajorMin;
+  float     fRmajorMax;
+  float     fRmajorDel;
+  float     fRminorMin;
+  float     fRminorMax;
+  float     fRminorDel;
+} pmSourceGalaxyFits;
+
 pmSourceRadialFlux *pmSourceRadialFluxAlloc();
 bool psMemCheckSourceRadialFlux(psPtr ptr);
@@ -109,4 +124,6 @@
 pmSourceExtFitPars *pmSourceExtFitParsAlloc (void);
 
+pmSourceGalaxyFits *pmSourceGalaxyFitsAlloc (void);
+
 /// @}
 # endif /* PM_SOURCE_H */
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceFitModel.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceFitModel.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceFitModel.c	(revision 37066)
@@ -33,11 +33,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourcePhotometry.h"
@@ -59,4 +60,5 @@
     opt->maxTol = 1.00;
     opt->weight = 1.00;
+    opt->nsigma = 5.00;
     opt->maxChisqDOF = NAN;
     opt->poissonErrors = true;
@@ -66,4 +68,5 @@
     opt->gainFactorMode = 0;
     opt->chisqConvergence = true;
+    opt->isInteractive = false;
 
     return opt;
@@ -167,5 +170,5 @@
     psMinConstraint *constraint = psMinConstraintAlloc();
     constraint->paramMask = psVectorAlloc (params->n, PS_TYPE_VECTOR_MASK);
-    constraint->checkLimits = model->modelLimits;
+    constraint->checkLimits = model->class->modelLimits;
 
     // set parameter mask based on fitting mode
@@ -230,6 +233,6 @@
     // force the floating parameters to fall within the contraint ranges
     for (int i = 0; i < params->n; i++) {
-	model->modelLimits (PS_MINIMIZE_PARAM_MIN, i, params->data.F32, NULL);
-	model->modelLimits (PS_MINIMIZE_PARAM_MAX, i, params->data.F32, NULL);
+	model->class->modelLimits (PS_MINIMIZE_PARAM_MIN, i, params->data.F32, NULL);
+	model->class->modelLimits (PS_MINIMIZE_PARAM_MAX, i, params->data.F32, NULL);
     }
 
@@ -247,8 +250,9 @@
     myMin->gainFactorMode = options->gainFactorMode;
     myMin->chisqConvergence = options->chisqConvergence;
+    myMin->isInteractive = options->isInteractive;
 
     psImage *covar = psImageAlloc (params->n, params->n, PS_TYPE_F32);
 
-    fitStatus = psMinimizeLMChi2(myMin, covar, params, constraint, x, y, yErr, model->modelFunc);
+    fitStatus = psMinimizeLMChi2(myMin, covar, params, constraint, x, y, yErr, model->class->modelFunc);
     for (int i = 0; i < dparams->n; i++) {
         if ((constraint->paramMask != NULL) && constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[i])
@@ -279,5 +283,11 @@
     // set the model success or failure status
     model->flags |= PM_MODEL_STATUS_FITTED;
-    if (!fitStatus) model->flags |= PM_MODEL_STATUS_NONCONVERGE;
+    if (!fitStatus) {
+	if (isnan(myMin->value)) {
+	  model->flags |= PM_MODEL_STATUS_NAN_CHISQ;
+	} else {
+	  model->flags |= PM_MODEL_STATUS_NONCONVERGE;
+	}
+    }
 
     if (myMin->chisqConvergence) {
@@ -296,5 +306,5 @@
             altmask->data.PS_TYPE_VECTOR_MASK_DATA[i] = (constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[i]) ? 0 : 1;
         }
-        psMinimizeGaussNewtonDelta(delta, params, altmask, x, y, yErr, model->modelFunc);
+        psMinimizeGaussNewtonDelta(delta, params, altmask, x, y, yErr, model->class->modelFunc);
 
         for (int i = 0; i < dparams->n; i++) {
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceFitModel.h
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceFitModel.h	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceFitModel.h	(revision 37066)
@@ -21,4 +21,5 @@
     PM_SOURCE_FIT_EXT_AND_SKY,
     PM_SOURCE_FIT_INDEX,
+    PM_SOURCE_FIT_SHAPE,
     PM_SOURCE_FIT_NO_INDEX,
     PM_SOURCE_FIT_TRAIL,
@@ -33,8 +34,10 @@
     float weight;			///< use this weight for constant-weight fits
     float covarFactor;			///< covariance factor for calculating the chisq
+    float nsigma;                       ///< how far out to convolve
     bool poissonErrors;			///< use poisson errors for fits?
     bool saveCovariance;
     int gainFactorMode;
     bool chisqConvergence; 
+    bool isInteractive;
 } pmSourceFitOptions;
 
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceFitPCM.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceFitPCM.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceFitPCM.c	(revision 37066)
@@ -31,11 +31,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourcePhotometry.h"
@@ -51,4 +52,6 @@
 # define TIMING 0
 
+bool pmSourceChisqModelFlux (pmSource *source, pmModel *model, psImageMaskType maskVal);
+
 bool pmSourceFitPCM (pmPCMdata *pcm, pmSource *source, pmSourceFitOptions *fitOptions, psImageMaskType maskVal, psImageMaskType markVal, int psfSize) {
     
@@ -60,6 +63,6 @@
     // force the floating parameters to fall within the contraint ranges
     for (int i = 0; i < params->n; i++) {
-	pcm->modelConv->modelLimits (PS_MINIMIZE_PARAM_MIN, i, params->data.F32, NULL);
-	pcm->modelConv->modelLimits (PS_MINIMIZE_PARAM_MAX, i, params->data.F32, NULL);
+	pcm->modelConv->class->modelLimits (PS_MINIMIZE_PARAM_MIN, i, params->data.F32, NULL);
+	pcm->modelConv->class->modelLimits (PS_MINIMIZE_PARAM_MAX, i, params->data.F32, NULL);
     }
 
@@ -68,4 +71,5 @@
     myMin->chisqConvergence = fitOptions->chisqConvergence;
     myMin->gainFactorMode = fitOptions->gainFactorMode;
+    myMin->isInteractive = fitOptions->isInteractive;
 
     psImage *covar = psImageAlloc (params->n, params->n, PS_TYPE_F32);
@@ -112,5 +116,6 @@
     } else {
 	// xxx this is wrong because it does not convolve with the psf
-	pmSourceChisqUnsubtracted (source, pcm->modelConv, maskVal);
+	pmPCMMakeModel (source, pcm->modelConv, pcm->nsigma, maskVal, psfSize);
+	pmSourceChisqModelFlux (source, pcm->modelConv, maskVal);
     }
     if (TIMING) { t4 = psTimerMark ("pmSourceFitPCM"); }
@@ -118,5 +123,12 @@
     // set the model success or failure status
     pcm->modelConv->flags |= PM_MODEL_STATUS_FITTED;
-    if (!fitStatus) pcm->modelConv->flags |= PM_MODEL_STATUS_NONCONVERGE;
+
+    if (!fitStatus) {
+	if (isnan(myMin->value)) {
+	    pcm->modelConv->flags |= PM_MODEL_STATUS_NAN_CHISQ;
+	} else {
+	    pcm->modelConv->flags |= PM_MODEL_STATUS_NONCONVERGE;
+	}
+    }
 
     if (myMin->chisqConvergence) {
@@ -153,5 +165,5 @@
 bool pmSourceModelGuessPCM (pmPCMdata *pcm, pmSource *source, psImageMaskType maskVal, psImageMaskType markVal) {
 
-    if (!pcm->modelConv->modelGuess(pcm->modelConv, source, maskVal, markVal)) {
+    if (!pcm->modelConv->class->modelGuess(pcm->modelConv, source, maskVal, markVal)) {
 	return false;
     }
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceFitSet.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceFitSet.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceFitSet.c	(revision 37066)
@@ -32,11 +32,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourcePhotometry.h"
@@ -222,5 +223,5 @@
     float *paramOne = params + nParamBase;
     float *betaOne = betas + nParamBase;
-    bool status = model->modelLimits (mode, nParamOne, paramOne, betaOne);
+    bool status = model->class->modelLimits (mode, nParamOne, paramOne, betaOne);
     return status;
 }
@@ -352,5 +353,11 @@
         // set the model success or failure status
         model->flags |= PM_MODEL_STATUS_FITTED;
-        if (!fitStatus) model->flags |= PM_MODEL_STATUS_NONCONVERGE;
+	if (!fitStatus) {
+	  if (isnan(myMin->value)) {
+	    model->flags |= PM_MODEL_STATUS_NAN_CHISQ;
+	  } else {
+	    model->flags |= PM_MODEL_STATUS_NONCONVERGE;
+	  }
+	}
 
         // models can go insane: reject these
@@ -381,5 +388,5 @@
         psVector *derivOne = thisSet->derivSet->data[i];
 
-        chisqOne = model->modelFunc (derivOne, paramOne, x);
+        chisqOne = model->class->modelFunc (derivOne, paramOne, x);
         chisqSum += chisqOne;
     }
@@ -570,4 +577,5 @@
     myMin->gainFactorMode = options->gainFactorMode;
     myMin->chisqConvergence = options->chisqConvergence;
+    myMin->isInteractive = options->isInteractive;
 
     psImage *covar = psImageAlloc (params->n, params->n, PS_TYPE_F32);
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceGroups.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceGroups.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceGroups.c	(revision 37066)
@@ -18,11 +18,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceFitModel.h"
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceIO.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceIO.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceIO.c	(revision 37066)
@@ -40,11 +40,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceFitModel.h"
@@ -61,4 +62,5 @@
 static bool pmReadoutReadXFIT(pmFPAfile *file, pmReadout *readout, char * exttype, psMetadata *hduHeader, psString xfitname, psArray *sources, long *sourceIndex);
 static bool pmReadoutReadXRAD(pmFPAfile *file, pmReadout *readout, char * exttype, psMetadata *hduHeader, psString xfitname, psArray *sources, long *sourceIndex);
+static bool pmReadoutReadXGAL(pmFPAfile *file, pmReadout *readout, char * exttype, psMetadata *hduHeader, psString xfitname, psArray *sources, long *sourceIndex);
 
 // lookup the EXTNAME values used for table data and image header segments
@@ -69,4 +71,5 @@
 			psString *xfitname,    // Extension name for extended fitted measurements
 			psString *xradname,    // Extension name for radial apertures
+			psString *xgalname,    // Extension name for galaxy shapes
 			const pmFPAfile *file, // File of interest
 			const pmFPAview *view  // View to level of interest
@@ -140,4 +143,14 @@
         }
         *xradname = pmFPAfileNameFromRule (rule, file, view);
+    }
+
+    // EXTNAME for radial apertures
+    if (xgalname) {
+        const char *rule = psMetadataLookupStr(&status, menu, "CMF.XGAL");
+        if (!rule) {
+            psError(PS_ERR_UNKNOWN, true, "missing entry for CMF.XGAL in EXTNAME.RULES in camera.config");
+            return false;
+        }
+        *xgalname = pmFPAfileNameFromRule (rule, file, view);
     }
 
@@ -352,5 +365,5 @@
 # define PM_SOURCES_WRITE(NAME,TYPE)					\
     if (!strcmp (exttype, NAME)) {					\
-	status &= pmSourcesWrite_##TYPE(file->fits, readout, sources, file->header, outhead, dataname, recipe); \
+	status = pmSourcesWrite_##TYPE(file->fits, readout, sources, file->header, outhead, dataname, recipe); \
 	if (xsrcname) {							\
 	    status &= pmSourcesWrite_##TYPE##_XSRC(file->fits, readout, sources, file->header, xsrcname, recipe); \
@@ -362,4 +375,7 @@
 	    status &= pmSourcesWrite_##TYPE##_XRAD (file->fits, readout, sources, file->header, xradname, recipe); \
 	}								\
+	if (xgalname) {							\
+	    status &= pmSourcesWrite_##TYPE##_XGAL (file->fits, readout, sources, xgalname, recipe); \
+	}								\
     }
 
@@ -464,8 +480,11 @@
         }
 
-        // if this is not TRUE, the output files only contain the psf measurements.
-        bool XSRC_OUTPUT = psMetadataLookupBool(&status, recipe, "EXTENDED_SOURCE_ANALYSIS");
+        // if none of these are TRUE, the output files only contain the psf measurements.
+	bool doPetrosian = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_PETROSIAN");
+	bool doAnnuli    = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_ANNULI");
+        bool XSRC_OUTPUT = doPetrosian || doAnnuli;
         bool XFIT_OUTPUT = psMetadataLookupBool(&status, recipe, "EXTENDED_SOURCE_FITS");
         bool XRAD_OUTPUT = psMetadataLookupBool(&status, recipe, "RADIAL_APERTURES");
+        bool XGAL_OUTPUT = psMetadataLookupBool(&status, recipe, "GALAXY_SHAPES");
 
         // define the EXTNAME values for the different data segments:
@@ -476,8 +495,10 @@
         psString xfitname = NULL;
         psString xradname = NULL;
+        psString xgalname = NULL;
         if (!pmSourceIOextnames(&headname, &dataname, &deteffname, 
 				XSRC_OUTPUT ? &xsrcname : NULL,
 				XFIT_OUTPUT ? &xfitname : NULL, 
 				XRAD_OUTPUT ? &xradname : NULL, 
+				XGAL_OUTPUT ? &xgalname : NULL, 
 				file, view)) {
             return false;
@@ -563,7 +584,10 @@
 		psMetadataAddStr (outhead, PS_LIST_TAIL, "XRADNAME", PS_META_REPLACE, "name of XRAD table extension", xradname);
             }
+            if (xgalname) {
+		psMetadataAddStr (outhead, PS_LIST_TAIL, "XGALNAME", PS_META_REPLACE, "name of XGAL table extension", xgalname);
+            }
 
             // these are case-sensitive since the EXTYPE is case-sensitive
-            status = true;
+            status = false;
 	    PM_SOURCES_WRITE("SMPDATA",   SMPDATA);
 	    PM_SOURCES_WRITE("PS1_DEV_0", PS1_DEV_0);
@@ -574,9 +598,12 @@
 	    PM_SOURCES_WRITE("PS1_V3",    CMF_PS1_V3);
 	    PM_SOURCES_WRITE("PS1_V4",    CMF_PS1_V4);
+	    PM_SOURCES_WRITE("PS1_V5",    CMF_PS1_V5);
 	    PM_SOURCES_WRITE("PS1_SV1",   CMF_PS1_SV1);
 	    PM_SOURCES_WRITE("PS1_SV2",   CMF_PS1_SV2);
+	    PM_SOURCES_WRITE("PS1_SV3",   CMF_PS1_SV3);
 	    PM_SOURCES_WRITE("PS1_DV1",   CMF_PS1_DV1);
 	    PM_SOURCES_WRITE("PS1_DV2",   CMF_PS1_DV2);
 	    PM_SOURCES_WRITE("PS1_DV3",   CMF_PS1_DV3);
+	    PM_SOURCES_WRITE("PS1_DV4",   CMF_PS1_DV4);
 
 	    psFree (outhead);
@@ -609,4 +636,5 @@
 	psFree (xfitname);
 	psFree (xradname);
+	psFree (xgalname);
 	psFree (deteffname);
 
@@ -620,7 +648,28 @@
 	psFree (xfitname);
 	psFree (xradname);
+	psFree (xgalname);
 	psFree (deteffname);
 	return false;
 
+      case PM_FPA_FILE_CFF: {
+        // determine the output table format
+        psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, "PSPHOT");
+        if (!status) {
+	    psError(PS_ERR_UNKNOWN, true, "missing recipe PSPHOT in config data");
+	    return false;
+        }
+
+        hdu = pmFPAviewThisHDU (view, fpa);
+        pmConfigConformHeader(hdu->header, file->format);
+        psFitsWriteBlank (file->fits, hdu->header, NULL);
+        file->header = hdu->header;
+        file->wrote_phu = true;
+	if (!pmSourcesWrite_CFF(readout, file->fits, sources, hdu->header, recipe)) {
+            psError(PS_ERR_UNKNOWN, false, "failed to write CFF");
+            return false;
+        }
+        break;
+      }
+        
       default:
         fprintf (stderr, "warning: type mismatch\n");
@@ -914,4 +963,16 @@
     psArray *sources = NULL;
     pmHDU *hdu;
+
+    // define the EXTNAME values for the different data segments:
+    psString headname = NULL;
+    psString dataname = NULL;
+    psString deteffname = NULL;
+    psString xsrcname = NULL;
+    psString xfitname = NULL;
+    psString xradname = NULL;
+    psString xgalname = NULL;
+
+    psMetadata *tableHeader = NULL;
+    char *xtension = NULL;
 
     switch (file->type) {
@@ -963,12 +1024,4 @@
         hdu = pmFPAviewThisHDU (view, file->fpa);
 
-        // define the EXTNAME values for the different data segments:
-        psString headname = NULL;
-        psString dataname = NULL;
-        psString deteffname = NULL;
-        psString xsrcname = NULL;
-        psString xfitname = NULL;
-        psString xradname = NULL;
-
         // determine the output table format. Assume if we need to output extendend source
         // parameters that they may exist in the input. 
@@ -981,8 +1034,12 @@
         }
 
-        // if this is not TRUE, the output files only contain the psf measurements.
-        bool XSRC_OUTPUT = psMetadataLookupBool(&status, recipe, "EXTENDED_SOURCE_ANALYSIS");
+        // if none of these are TRUE, we only read the psf measurements
+        // XXX: shouldn't we look for these extensions and read the regardless of the recipe values?
+	bool doPetrosian = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_PETROSIAN");
+	bool doAnnuli    = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_ANNULI");
+        bool XSRC_OUTPUT = doPetrosian || doAnnuli;
         bool XFIT_OUTPUT = psMetadataLookupBool(&status, recipe, "EXTENDED_SOURCE_FITS");
         bool XRAD_OUTPUT = psMetadataLookupBool(&status, recipe, "RADIAL_APERTURES");
+        bool XGAL_OUTPUT = psMetadataLookupBool(&status, recipe, "GALAXY_SHAPES");
 
         if (!pmSourceIOextnames(&headname, &dataname, &deteffname, 
@@ -990,4 +1047,5 @@
                 XFIT_OUTPUT ? &xfitname : NULL, 
                 XRAD_OUTPUT ? &xradname : NULL,
+                XGAL_OUTPUT ? &xgalname : NULL,
                 file, view)) {
             return false;
@@ -1033,8 +1091,8 @@
         }
 
-        psMetadata *tableHeader = psFitsReadHeader(NULL, file->fits); // The FITS header
+        tableHeader = psFitsReadHeader(NULL, file->fits); // The FITS header
         if (!tableHeader) psAbort("cannot read table header");
 
-        char *xtension = psMetadataLookupStr (NULL, tableHeader, "XTENSION");
+        xtension = psMetadataLookupStr (NULL, tableHeader, "XTENSION");
         if (!xtension) psAbort("cannot read table type");
 	if (strcmp (xtension, "BINTABLE")) {
@@ -1062,12 +1120,24 @@
 	    PM_SOURCES_READ_PSF("PS1_V3",    CMF_PS1_V3);
 	    PM_SOURCES_READ_PSF("PS1_V4",    CMF_PS1_V4);
+	    PM_SOURCES_READ_PSF("PS1_V5",    CMF_PS1_V5);
 	    PM_SOURCES_READ_PSF("PS1_SV1",   CMF_PS1_SV1);
 	    PM_SOURCES_READ_PSF("PS1_SV2",   CMF_PS1_SV2);
+	    PM_SOURCES_READ_PSF("PS1_SV3",   CMF_PS1_SV3);
 	    PM_SOURCES_READ_PSF("PS1_DV1",   CMF_PS1_DV1);
 	    PM_SOURCES_READ_PSF("PS1_DV2",   CMF_PS1_DV2);
 	    PM_SOURCES_READ_PSF("PS1_DV3",   CMF_PS1_DV3);
+	    PM_SOURCES_READ_PSF("PS1_DV4",   CMF_PS1_DV4);
+
+            if (!sources) {
+                psError(PS_ERR_IO, false, "reading CMF data from %s with format %s\n", file->filename, exttype);
+		return false;
+            }
 
             long *sourceIndex = NULL;
-            if (XSRC_OUTPUT || XFIT_OUTPUT || XRAD_OUTPUT) {
+            if (XSRC_OUTPUT || XFIT_OUTPUT || XRAD_OUTPUT || XGAL_OUTPUT) {
+                // Build sourceIndex. Lookup table from source->seq to index in sources array.
+                // Consists of an array of length max(source->seq) + 1.
+
+                // find maximum sequence number
                 long seq_max = -1;
                 for (long i = sources->n -1; i >= 0; i--) {
@@ -1082,8 +1152,10 @@
                     }
                 }
+                // allocate and initialize the index
                 sourceIndex = psAlloc((seq_max + 1) * sizeof(long));
                 for (long i = 0; i < seq_max; i++) {
                     sourceIndex[i] = -1;
                 }
+                // populate the index
                 for (long i = 0; i < sources->n; i++) {
                     pmSource *source = sources->data[i];
@@ -1111,4 +1183,11 @@
                 }
                 psFree(xradname);
+            }
+            if (XGAL_OUTPUT && xgalname) {
+		// a cmf file may have an XGAL extension, but it is not required
+                if (!pmReadoutReadXGAL(file, readout, exttype, hdu->header, xgalname, sources, sourceIndex)) {
+		    // do anything?
+                }
+                psFree(xgalname);
             }
             psFree(sourceIndex);
@@ -1132,4 +1211,61 @@
         break;
 
+      case PM_FPA_FILE_CFF: {
+        // determine the output table format
+        psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, "PSPHOT");
+        if (!status) {
+	    psError(PS_ERR_UNKNOWN, true, "missing recipe PSPHOT in config data");
+	    return false;
+        }
+        // read in header, if not yet loaded
+        hdu = pmFPAviewThisHDU (view, file->fpa);
+
+	// look these up in the camera config?
+	// headrule = {CHIP.NAME}.hdr
+	// datarule = {CHIP.NAME}.cff
+
+        // define the EXTNAME values for the different data segments:
+        headname = pmFPAfileNameFromRule("{CHIP.NAME}.hdr", file, view);
+        dataname = pmFPAfileNameFromRule("{CHIP.NAME}.cff", file, view);
+
+        // advance to the IMAGE HEADER extension
+        if (hdu->header == NULL) {
+            // if the IMAGE header does not exist, we have no data for this view
+            if (!psFitsMoveExtNameClean (file->fits, headname)) {
+                readout->data_exists = false;
+                psFree (headname);
+                psFree (dataname);
+                return true;
+            }
+            hdu->header = psFitsReadHeader (NULL, file->fits);
+        }
+
+        // advance to the table data extension
+        // since we have read the IMAGE header, the TABLE header should exist
+        if (!psFitsMoveExtName (file->fits, dataname)) {
+            psAbort("cannot find data extension %s in %s", dataname, file->filename);
+        }
+
+        tableHeader = psFitsReadHeader(NULL, file->fits); // The FITS header
+        if (!tableHeader) psAbort("cannot read table header");
+
+	// verify this is a binary table
+        char *xtension = psMetadataLookupStr (NULL, tableHeader, "XTENSION");
+        if (!xtension) psAbort("cannot read table type");
+	if (strcmp (xtension, "BINTABLE")) {
+	    psWarning ("no binary table in extension %s, skipping\n", dataname);
+            psFree(tableHeader);
+	    return false;
+	}
+
+	sources = pmSourcesRead_CFF(file->fits, hdu->header, recipe);
+
+        psTrace("psModules.objects", 6, "read CMF table from %s : %s : %s", file->filename, headname, dataname);
+        psFree (headname);
+        psFree (dataname);
+        psFree (tableHeader);
+        }
+        break;
+
       default:
         fprintf (stderr, "warning: type mismatch\n");
@@ -1272,9 +1408,12 @@
 	PM_SOURCES_READ_XSRC("PS1_V3",    CMF_PS1_V3);
 	PM_SOURCES_READ_XSRC("PS1_V4",    CMF_PS1_V4);
+	PM_SOURCES_READ_XSRC("PS1_V5",    CMF_PS1_V5);
 	PM_SOURCES_READ_XSRC("PS1_SV1",   CMF_PS1_SV1);
 	PM_SOURCES_READ_XSRC("PS1_SV2",   CMF_PS1_SV2);
+	PM_SOURCES_READ_XSRC("PS1_SV3",   CMF_PS1_SV3);
 	PM_SOURCES_READ_XSRC("PS1_DV1",   CMF_PS1_DV1);
 	PM_SOURCES_READ_XSRC("PS1_DV2",   CMF_PS1_DV2);
 	PM_SOURCES_READ_XSRC("PS1_DV3",   CMF_PS1_DV3);
+	PM_SOURCES_READ_XSRC("PS1_DV4",   CMF_PS1_DV4);
     }
     psFree(tableHeader);
@@ -1311,9 +1450,12 @@
 	PM_SOURCES_READ_XFIT("PS1_V3",    CMF_PS1_V3);
 	PM_SOURCES_READ_XFIT("PS1_V4",    CMF_PS1_V4);
+	PM_SOURCES_READ_XFIT("PS1_V5",    CMF_PS1_V5);
 	PM_SOURCES_READ_XFIT("PS1_SV1",   CMF_PS1_SV1);
 	PM_SOURCES_READ_XFIT("PS1_SV2",   CMF_PS1_SV2);
+	PM_SOURCES_READ_XFIT("PS1_SV3",   CMF_PS1_SV3);
 	PM_SOURCES_READ_XFIT("PS1_DV1",   CMF_PS1_DV1);
 	PM_SOURCES_READ_XFIT("PS1_DV2",   CMF_PS1_DV2);
 	PM_SOURCES_READ_XFIT("PS1_DV3",   CMF_PS1_DV3);
+	PM_SOURCES_READ_XFIT("PS1_DV4",   CMF_PS1_DV4);
     }
     psFree(tableHeader);
@@ -1349,11 +1491,55 @@
 	PM_SOURCES_READ_XRAD("PS1_V3",    CMF_PS1_V3);
 	PM_SOURCES_READ_XRAD("PS1_V4",    CMF_PS1_V4);
+	PM_SOURCES_READ_XRAD("PS1_V5",    CMF_PS1_V5);
 	PM_SOURCES_READ_XRAD("PS1_SV1",   CMF_PS1_SV1);
 	PM_SOURCES_READ_XRAD("PS1_SV2",   CMF_PS1_SV2);
+	PM_SOURCES_READ_XRAD("PS1_SV3",   CMF_PS1_SV3);
 	PM_SOURCES_READ_XRAD("PS1_DV1",   CMF_PS1_DV1);
 	PM_SOURCES_READ_XRAD("PS1_DV2",   CMF_PS1_DV2);
 	PM_SOURCES_READ_XRAD("PS1_DV3",   CMF_PS1_DV3);
+	PM_SOURCES_READ_XRAD("PS1_DV4",   CMF_PS1_DV4);
     }
     psFree(tableHeader);
     return status;
 }
+static bool pmReadoutReadXGAL(pmFPAfile *file, pmReadout *readout, char *exttype, psMetadata *hduHeader, psString xgalname, psArray *sources, long *sourceIndex) 
+{
+    if (!psFitsMoveExtNameClean (file->fits, xgalname)) {
+        psTrace ("pmFPAfile", 1, "cannot find xgal extension %s in %s, skipping", xgalname, file->filename);
+        return false;
+    }
+
+    psMetadata *tableHeader = psFitsReadHeader(NULL, file->fits); // The FITS header
+    if (!tableHeader) psAbort("cannot read table header");
+
+    char *xtension = psMetadataLookupStr (NULL, tableHeader, "XTENSION");
+    if (!xtension) psAbort("cannot read table type");
+    if (strcmp (xtension, "BINTABLE")) {
+        psFree(tableHeader);
+        psWarning ("no binary table in extension %s, skipping\n", xgalname);
+        return false;
+    }
+
+# define PM_SOURCES_READ_XGAL(NAME,TYPE)				\
+    if (!strcmp (exttype, NAME)) {					\
+	status = pmSourcesRead_##TYPE##_XGAL(file->fits, readout, hduHeader, tableHeader, sources, sourceIndex); \
+    }									
+
+    bool status = false;
+    if (file->type == PM_FPA_FILE_CMF) {
+	PM_SOURCES_READ_XGAL("PS1_V1",    CMF_PS1_V1);
+	PM_SOURCES_READ_XGAL("PS1_V2",    CMF_PS1_V2);
+	PM_SOURCES_READ_XGAL("PS1_V3",    CMF_PS1_V3);
+	PM_SOURCES_READ_XGAL("PS1_V4",    CMF_PS1_V4);
+	PM_SOURCES_READ_XGAL("PS1_V5",    CMF_PS1_V5);
+	PM_SOURCES_READ_XGAL("PS1_SV1",   CMF_PS1_SV1);
+	PM_SOURCES_READ_XGAL("PS1_SV2",   CMF_PS1_SV2);
+	PM_SOURCES_READ_XGAL("PS1_SV3",   CMF_PS1_SV3);
+	PM_SOURCES_READ_XGAL("PS1_DV1",   CMF_PS1_DV1);
+	PM_SOURCES_READ_XGAL("PS1_DV2",   CMF_PS1_DV2);
+	PM_SOURCES_READ_XGAL("PS1_DV3",   CMF_PS1_DV3);
+	PM_SOURCES_READ_XGAL("PS1_DV4",   CMF_PS1_DV4);
+    }
+    psFree(tableHeader);
+    return status;
+}
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceIO.h
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceIO.h	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceIO.h	(revision 37066)
@@ -21,8 +21,10 @@
   bool pmSourcesWrite_##TYPE##_XFIT(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname); \
   bool pmSourcesWrite_##TYPE##_XRAD(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe); \
+  bool pmSourcesWrite_##TYPE##_XGAL(psFits *fits, pmReadout *readout, psArray *sources, char *extname, psMetadata *recipe); \
   psArray *pmSourcesRead_##TYPE (psFits *fits, psMetadata *header); \
   bool pmSourcesRead_##TYPE##_XSRC (psFits *fits, pmReadout *readout, psMetadata *header, psMetadata *tableHeader, psArray *sources, long *index); \
   bool pmSourcesRead_##TYPE##_XFIT (psFits *fits, pmReadout *readout, psMetadata *header, psMetadata *tableHeader, psArray *sources, long *index); \
   bool pmSourcesRead_##TYPE##_XRAD (psFits *fits, pmReadout *readout, psMetadata *header, psMetadata *tableHeader, psArray *sources, long *index);\
+  bool pmSourcesRead_##TYPE##_XGAL (psFits *fits, pmReadout *readout, psMetadata *header, psMetadata *tableHeader, psArray *sources, long *index);\
   
 // All of these functions need to use the same API, even if not all elements are used in a specific case
@@ -35,9 +37,12 @@
 MK_PROTO(CMF_PS1_V3);
 MK_PROTO(CMF_PS1_V4);
+MK_PROTO(CMF_PS1_V5);
 MK_PROTO(CMF_PS1_SV1);
 MK_PROTO(CMF_PS1_SV2);
+MK_PROTO(CMF_PS1_SV3);
 MK_PROTO(CMF_PS1_DV1);
 MK_PROTO(CMF_PS1_DV2);
 MK_PROTO(CMF_PS1_DV3);
+MK_PROTO(CMF_PS1_DV4);
 
 int pmSourceGetDophotType (pmSource *source);
@@ -52,4 +57,6 @@
 
 psArray *pmSourcesReadCMP (char *filename, psMetadata *header);
+psArray *pmSourcesRead_CFF (psFits *fits, psMetadata *header, psMetadata *recipe);
+bool pmSourcesWrite_CFF (pmReadout *readout, psFits *fits, psArray *sources, psMetadata *header, psMetadata *recipe);
 
 bool pmSourcesWritePSFs (psArray *sources, char *filename);
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceIO_CFF.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceIO_CFF.c	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceIO_CFF.c	(revision 37066)
@@ -0,0 +1,551 @@
+/** @file  pmSourceIO.c
+ *
+ *  @author EAM, IfA
+ *
+ *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-02-18 02:44:19 $
+ *
+ *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <math.h>
+#include <string.h>
+#include <pslib.h>
+
+#include "pmConfig.h"
+#include "pmDetrendDB.h"
+
+#include "pmHDU.h"
+#include "pmFPA.h"
+#include "pmFPALevel.h"
+#include "pmFPAview.h"
+#include "pmFPAfile.h"
+
+#include "pmTrend2D.h"
+#include "pmResiduals.h"
+#include "pmGrowthCurve.h"
+#include "pmSpan.h"
+#include "pmFootprintSpans.h"
+#include "pmFootprint.h"
+#include "pmPeaks.h"
+#include "pmMoments.h"
+#include "pmModelFuncs.h"
+#include "pmModelClass.h"
+#include "pmModel.h"
+#include "pmModelUtils.h"
+#include "pmSourceMasks.h"
+#include "pmSourceExtendedPars.h"
+#include "pmSourceDiffStats.h"
+#include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
+#include "pmSource.h"
+#include "pmSourceFitModel.h"
+#include "pmPSF.h"
+#include "pmPSFtry.h"
+
+#include "pmSourceIO.h"
+#include "pmSourceOutputs.h"
+
+// read in sources readout from a cff fits file
+psArray *pmSourcesRead_CFF (psFits *fits, psMetadata *header, psMetadata *recipe)
+{
+    PS_ASSERT_PTR_NON_NULL(fits, false);
+    PS_ASSERT_PTR_NON_NULL(header, false);
+
+    bool status;
+    psEllipseAxes axes;
+
+    // define PSF model type
+    // XXX need to carry the extra model parameters
+    int modelType = pmModelClassGetType ("PS_MODEL_GAUSS");
+
+    // Read lookup table for model classes (if defined)
+    pmModelClassReadHeader(header);
+
+    char *PSF_NAME = psMetadataLookupStr (&status, header, "PSFMODEL");
+    if (PSF_NAME != NULL) {
+        modelType = pmModelClassGetType (PSF_NAME);
+    }
+    PS_ASSERT_INT_NONNEGATIVE(modelType, NULL);
+
+    pmModelType sersicModelType = pmModelClassGetType("PS_MODEL_SERSIC");
+    pmModelType devModelType    = pmModelClassGetType("PS_MODEL_DEV");
+
+    psString modelForce = psMetadataLookupStr(&status, recipe, "EXT_MODEL_TYPE_FORCE");
+    psF32 forceDevSersicMin = NAN;
+    bool forceAll = false;
+    int modelTypeForce = 0;
+    if (!strcmp(modelForce, "ALL")) {
+        forceAll = true;
+    } else if (!strcmp(modelForce, "PS_MODEL_SERSIC")) {
+        modelTypeForce = sersicModelType;
+        forceDevSersicMin = psMetadataLookupF32(&status, recipe, "EXT_MODEL_FORCE_DEV_SERSIC_MIN");
+    } else {
+        modelTypeForce = pmModelClassGetType(modelForce);
+        PS_ASSERT_INT_NONNEGATIVE(modelTypeForce, NULL);
+    }
+
+    // skip extended model types for likely stars
+    // max value of KronMag - psfMag to keep ...
+    psF32 starCut = psMetadataLookupF32(&status, recipe, "EXT_MODEL_FORCE_MAGDIFF_MAX");
+    if (!status) {
+        starCut = 0;
+    }
+    // ... unless SN is less than this value
+    psF32 SNMinForCut = psMetadataLookupF32(&status, recipe, "EXT_MODEL_FORCE_CUT_SN_MIN");
+    if (!status) {
+        SNMinForCut = 10;
+    }
+
+    // We get the size of the table, and allocate the array of sources first because the table
+    // is large and ephemeral --- when the table gets blown away, whatever is allocated after
+    // the table is read blocks the free.  In fact, it's better to read the table row by row.
+    long numRows = psFitsTableSize(fits); // Number of rows in table
+    psArray *sources = psArrayAllocEmpty(numRows); // Array of sources, to return
+
+    // convert the table to the pmSource entries
+    pmSource *source = NULL;
+    for (int i = 0; i < numRows; i++) {
+        psMetadata *row = psFitsReadTableRow(fits, i); // Table row
+        if (!row) {
+            psError(psErrorCodeLast(), false, "Unable to read row %d of sources", i);
+            psFree(sources);
+            return NULL;
+        }
+
+	// here are the things we read from the FITS table (XXX modify names if needed)
+
+	unsigned int ID  = psMetadataLookupU32 (&status, row, "ID");
+	float X          = psMetadataLookupF32 (&status, row, "X");
+        assert(status);  // poorly constructed cff
+	float Y          = psMetadataLookupF32 (&status, row, "Y");
+        assert(status);  // poorly constructed cff
+        float flux       = psMetadataLookupF32 (&status, row, "FLUX"); // guess at the instrumental flux
+        if (!isfinite(X) || !isfinite(Y) || !isfinite(flux)) {
+            psError(PS_ERR_IO, true, "source ID %d is invalid x: %f y: %f flux: %f", ID, X, Y, flux);
+            psFree(sources);
+            return NULL;
+        }
+
+
+        float apRadius   = psMetadataLookupF32 (&status, row, "AP_RADIUS");
+        float kronRadius = psMetadataLookupF32 (&status, row, "KRON_RADIUS");
+        float petRadius  = psMetadataLookupF32 (&status, row, "PETRO_RADIUS");
+        float SN         = psMetadataLookupF32 (&status, row, "SN");
+        bool fitGalaxy   = psMetadataLookupU8 (&status, row, "FIT_GALAXY");
+        bool psfStar     = psMetadataLookupU8 (&status, row, "PSF_STAR");
+
+        float Rmajor     = psMetadataLookupF32 (&status, row, "R_MAJOR");
+        float Rminor     = psMetadataLookupF32 (&status, row, "R_MINOR");
+        float theta      = psMetadataLookupF32 (&status, row, "THETA");
+        float chisq      = psMetadataLookupF32 (&status, row, "CHISQ");
+        float nDOF       = psMetadataLookupF32 (&status, row, "NDOF");
+        float magDiff    = psMetadataLookupF32 (&status, row, "MAG_DIFF");
+        psS16 modelFlags = psMetadataLookupS32 (&status, row, "MODEL_FLAGS");
+
+        int   galaxyModelType = psMetadataLookupS32(&status, row, "MODEL_TYPE");
+        if (status && galaxyModelType >= 0) {
+            galaxyModelType = pmModelClassGetLocalType(galaxyModelType);
+        } else {
+            galaxyModelType = -1;
+        }
+        float Sindex     = psMetadataLookupF32 (&status, row, "INDEX"); // Should this be PAR_07 not sersic index
+
+        if (!source || ID != source->seq) {
+            if (source) {
+                psArrayAdd (sources, 1, source);
+                psFree(source);
+            }
+            source = pmSourceAlloc ();
+            pmModel *model = pmModelAlloc (modelType);
+            source->modelPSF  = model;
+            //        RoughClass wants source type to be unknown
+            //        source->type = PM_SOURCE_TYPE_STAR; // XXX this should be added to the flags
+            source->type = PM_SOURCE_TYPE_UNKNOWN;
+
+            // XXX we can set this in general, but for a specific image, we need to weed out SATSTARS and
+            // stars that are masked
+            if (psfStar) {
+                source->tmpFlags |= PM_SOURCE_TMPF_CANDIDATE_PSFSTAR;
+            }
+
+            // NOTE: A SEGV here because "model" is NULL is probably caused by not initialising the models.
+            psF32 *PAR = model->params->data.F32;
+            psF32 *dPAR = model->dparams->data.F32;
+
+            source->seq       = ID;
+
+            PAR[PM_PAR_XPOS]  = X;
+            PAR[PM_PAR_YPOS]  = Y;
+
+            dPAR[PM_PAR_XPOS] = 0.0;
+            dPAR[PM_PAR_YPOS] = 0.0;
+
+            PAR[PM_PAR_SKY]   = 0.0;
+            dPAR[PM_PAR_SKY]  = 0.0;
+
+            PAR[PM_PAR_I0]    = 1.0;
+            dPAR[PM_PAR_I0]   = 0.0;
+
+            source->sky       = PAR[PM_PAR_SKY];
+            source->skyErr    = dPAR[PM_PAR_SKY];
+
+            source->psfMag    = 0.0;
+            source->psfMagErr = 0.0;
+            source->apMag     = 0.0;
+            source->apRadius  = apRadius;
+
+            // we generate a somewhat fake PSF model here -- 
+            // in most (all?) contexts, we will replace this with a measured psf model
+            // elsewhere
+            axes.major        = 1.0;
+            axes.minor        = 1.0;
+            axes.theta        = 0.0;
+            pmPSF_AxesToModel (PAR, axes, model->class->useReff);
+
+            // peak->detValue, rawFlux, smoothFlux are all set to the flux argument which is counts per second
+            source->peak      = pmPeakAlloc(X, Y, flux, PM_PEAK_LONE);
+            source->peak->xf  = X; // pmPeakAlloc converts X,Y to int, so reset here
+            source->peak->yf  = Y; // pmPeakAlloc converts X,Y to int, so reset here
+            source->peak->dx  = 0.0;
+            source->peak->dy  = 0.0;
+
+            source->extSN     = SN;
+
+            source->moments = pmMomentsAlloc ();
+            source->moments->Mx = X;
+            source->moments->My = Y;
+            source->moments->Mrf = kronRadius * 0.4; // kronRadius is 2.5 * first radial moment
+
+            // Don't mark the moments as measured because that causes many fields to be left blank.
+            // The moments code knows not to change the position or the Mrf for external sources
+            // source->tmpFlags |= PM_SOURCE_TMPF_MOMENTS_MEASURED;
+
+            if (isfinite(petRadius)) {
+                source->extpars = pmSourceExtendedParsAlloc ();
+                source->extpars->petrosianRadius = petRadius;
+            }
+
+        }
+        bool saveExtModelParams = false;
+        if (fitGalaxy && galaxyModelType >= 0) {
+            // skip likely stars 
+            if (magDiff < starCut || SN < SNMinForCut) {
+                if (forceAll) {
+                    saveExtModelParams = true;
+                } else if (galaxyModelType == modelTypeForce) {
+                    // This is the model type that we are looking for
+                    // proceed
+                    saveExtModelParams = true;
+                } else if (modelTypeForce == sersicModelType && galaxyModelType == devModelType) {
+                    // We're doing sersic models, if sersic index is greater than the recipe's minimum index
+                    // do dev model as well
+                    if (isfinite(forceDevSersicMin) || Sindex >= forceDevSersicMin) {
+                        saveExtModelParams = true;
+                    }
+                } else {
+                    // not interested in this model
+                }
+            }
+        }
+
+        if (saveExtModelParams) {
+            if (!source->modelFits) {
+                source->modelFits = psArrayAllocEmpty (1);
+            }
+            pmModel *model = pmModelAlloc(galaxyModelType);
+            psF32 *xPAR = model->params->data.F32;
+
+            xPAR[PM_PAR_SKY]  = 0.0;
+            xPAR[PM_PAR_I0]   = 1.0;
+            xPAR[PM_PAR_XPOS] = X;
+	    xPAR[PM_PAR_YPOS] = Y;
+	    
+	    psEllipseAxes galaxyAxes;
+	    galaxyAxes.major = Rmajor;
+	    galaxyAxes.minor = Rminor;
+	    galaxyAxes.theta = theta * PS_RAD_DEG;
+
+	    pmPSF_AxesToModel (xPAR, galaxyAxes, model->class->useReff);
+	    if (model->params->n > 7) {
+                xPAR[PM_PAR_7] = 0.5 / Sindex;
+	    }
+
+            model->chisq = chisq;
+            model->nDOF = nDOF;
+            model->flags = modelFlags;
+
+	    psArrayAdd (source->modelFits, 1, model);
+
+	    psFree (model);
+        }
+
+        psFree(row);
+    }
+    if (source) {
+        // close out last source
+        psArrayAdd (sources, 1, source);
+        psFree(source);
+    }
+
+    return sources;
+}
+
+bool pmSourcesWrite_CFF(pmReadout *readout, psFits *fits, psArray *sources, psMetadata *header, psMetadata *recipe) {
+    
+    char *extname = "SkyChip.cff";
+    
+    bool mdok;
+    psF32 exptime = psMetadataLookupF32(&mdok, readout->parent->concepts, "CELL.EXPOSURE");
+    PS_ASSERT(mdok, false);
+
+    // write the definition of the model class type values to the header
+    psMetadata *outputHeader = psMetadataAlloc();
+    pmModelClassWriteHeader(outputHeader);
+
+    psArray *table = psArrayAllocEmpty(sources->n);
+
+    pmModelType sersicModelType = pmModelClassGetType("PS_MODEL_SERSIC");
+    pmModelType devModelType    = pmModelClassGetType("PS_MODEL_DEV");
+    pmModelType selectedModelType = -1;
+    bool chooseBest = false;
+    bool chooseAll = false;
+
+    psString modelToChoose = psMetadataLookupStr(&mdok, recipe, "EXT_MODEL_TYPE_FOR_CFF");
+
+    if (mdok && modelToChoose != NULL) {
+        if (!strcmp(modelToChoose, "BEST")) {
+            chooseBest = true;
+        } else if (!strcmp(modelToChoose, "ALL")) {
+            chooseAll = true;
+        } else if (strcmp(modelToChoose, "PS_MODEL_SERSIC")) {
+            // We have selected a model type other than Sersic. 
+            // Save it's type for use below.  Sersic is handled specially
+            selectedModelType = pmModelClassGetType(modelToChoose);
+        }
+    }
+
+    // minimum sersic index to force devModel
+    psF32 sersicMinDev = psMetadataLookupF32(&mdok, recipe, "EXT_MODEL_FORCE_DEV_SERSIC_MIN");
+    if (!mdok) {
+        sersicMinDev = NAN;
+    }
+
+    sources = psArraySort (sources, pmSourceSortBySeq);
+
+    for (int i = 0; i < sources->n; i++) {
+        pmSource *thisSource = sources->data[i];
+        pmSource *source = thisSource->parent ? thisSource->parent : thisSource;
+
+        #define MAX_ROWS_PER_SRC 10
+        psF32 xPos[MAX_ROWS_PER_SRC], yPos[MAX_ROWS_PER_SRC], flux[MAX_ROWS_PER_SRC];
+        psF32 rMajor[MAX_ROWS_PER_SRC], rMinor[MAX_ROWS_PER_SRC], theta[MAX_ROWS_PER_SRC];
+        psF32 chisq[MAX_ROWS_PER_SRC], nDOF[MAX_ROWS_PER_SRC];
+        psS32 modelFlags[MAX_ROWS_PER_SRC];
+        psS32 modelType[MAX_ROWS_PER_SRC];
+        psF32 sersicIndex = NAN;
+        bool fitGalaxy = false;
+        bool psfStar = (source->mode & PM_SOURCE_MODE_PSFSTAR) ? true : false;
+        int n_rows = 0;
+
+        psF32 kronFlux = source->moments->KronFlux;
+        psF32 SN = NAN;
+        psF32 magDiff = NAN;
+        if (isfinite(kronFlux) && isfinite(source->moments->KronFluxErr) && isfinite(source->psfMag)) {
+            SN = kronFlux/source->moments->KronFluxErr;
+            // kronMag - psfMag for use as star/glaxy separator
+            magDiff = -2.5 * log10(kronFlux) - source->psfMag ;
+        }
+
+        // start with psf model
+        pmModel *model = source->modelPSF;
+        if (model == NULL) continue;
+        psF32 *PAR = model->params->data.F32;
+        if (!isfinite(PAR[PM_PAR_SXX]) || !isfinite(PAR[PM_PAR_SYY])  || !isfinite(PAR[PM_PAR_SXY]) ||
+            !isfinite(source->psfFlux)) {
+            continue;
+        }
+
+        xPos[0] = model->params->data.F32[PM_PAR_XPOS];
+        yPos[0] = model->params->data.F32[PM_PAR_YPOS];
+        flux[0] = source->psfFlux;
+        rMajor[0] = 0;
+        rMinor[0] = 0;
+        theta[0] = 0;
+        modelType[0] = -1;
+        sersicIndex = NAN;
+        chisq[0] = NAN;
+        nDOF[0] = NAN;
+        modelFlags[0] = 0;
+
+        if (source->modelFits != NULL) {
+            // figure out which models to use based on recipe paramters
+            if (chooseAll) {
+                // Save parameters for all valid extended models
+
+                // but make sure we aren't going to overflow our arrays
+                assert (source->modelFits->n < MAX_ROWS_PER_SRC);
+
+                for (int j=0; j<source->modelFits->n; j++) {
+                    pmModel *model = source->modelFits->data[j];
+                    psF32 *PAR = model->params->data.F32;
+
+                    if (isfinite(PAR[PM_PAR_SXX]) && isfinite(PAR[PM_PAR_SYY])  && isfinite(PAR[PM_PAR_SXY]) &&
+                        isfinite(model->mag)) {
+
+                        xPos[n_rows] = PAR[PM_PAR_XPOS];
+                        yPos[n_rows] = PAR[PM_PAR_YPOS];
+
+                        psEllipseAxes axes = pmPSF_ModelToAxes (PAR, model->class->useReff);
+                        rMajor[n_rows] = axes.major;
+                        rMinor[n_rows] = axes.minor;
+                        theta[n_rows]  = axes.theta*PS_DEG_RAD;
+                        flux[n_rows] = pow(10.0, -0.4*model->mag);
+                        modelType[n_rows] = model->type;
+                        chisq[n_rows] = model->chisq;
+                        nDOF[n_rows] = model->nDOF;
+                        modelFlags[n_rows] = model->flags;
+                        fitGalaxy = true;
+                        if (model->params->n == 8) {
+                            // this will save the sersic index in all models but that might
+                            // be useful
+                            sersicIndex = 0.5 / PAR[PM_PAR_7];
+                        } else {
+                            sersicIndex = NAN;
+                        }
+
+                        n_rows++;
+                    }
+                }
+            } else {
+                int jModelSersic = -1;
+                int jModelDev = -1;
+                int jModelSelected = -1;
+                psF32 minChisq = NAN;
+                for (int j=0; j<source->modelFits->n; j++) {
+                    pmModel *model = source->modelFits->data[j];
+                    if (chooseBest) {
+                        // choose the model with lowest chisq
+                        if (isfinite(model->chisq) && (!isfinite(minChisq) || model->chisq < minChisq)) {
+                            jModelSelected = j;
+                            minChisq = model->chisq;
+                        }
+                    } else {
+                        // find the index of models of interest
+                        if (model->type == selectedModelType) {
+                            jModelSelected = j;
+                        } else if (model->type == sersicModelType) {
+                            jModelSersic = j;
+                        } else if (model->type == devModelType) {
+                            jModelDev = j;
+                        }
+                    }
+                }
+                if (jModelSelected >= 0 || jModelSersic >= 0) {
+                    // If a specific non-sersic model we take paramers from that one.
+                    // Otherwise we do the sersic model.
+                    pmModel *model = jModelSelected >= 0 ? source->modelFits->data[jModelSelected] :
+                                                           source->modelFits->data[jModelSersic];
+                    psF32 *PAR = model->params->data.F32;
+
+                    if (isfinite(PAR[PM_PAR_SXX]) && isfinite(PAR[PM_PAR_SYY])  && isfinite(PAR[PM_PAR_SXY]) &&
+                        isfinite(model->mag)) {
+
+                        xPos[0] = PAR[PM_PAR_XPOS];
+                        yPos[0] = PAR[PM_PAR_YPOS];
+
+                        psEllipseAxes axes = pmPSF_ModelToAxes (PAR, model->class->useReff);
+                        rMajor[0] = axes.major;
+                        rMinor[0] = axes.minor;
+                        theta[0]  = axes.theta*PS_DEG_RAD;
+                        flux[0] = pow(10.0, -0.4*model->mag);
+                        modelType[0] = model->type;
+                        chisq[0] = model->chisq;
+                        nDOF[0] = model->nDOF;
+                        modelFlags[0] = model->flags;
+                        fitGalaxy = true;
+                        if (model->type == sersicModelType) {
+                            PS_ASSERT_FLOAT_LARGER_THAN(PAR[PM_PAR_7], 0.0, false);
+                            sersicIndex = 0.5 / PAR[PM_PAR_7];
+                        }
+
+                        n_rows = 1;
+
+                        // Unless a specific non-sersic model type was selected do dev model for sources with
+                        // sersic index above the recipe limit.
+                        if (jModelSelected == -1 && jModelDev >= 0 && isfinite(sersicMinDev) &&
+                            sersicIndex > sersicMinDev) {
+
+                            model = source->modelFits->data[jModelDev];
+                            if (isfinite(PAR[PM_PAR_SXX]) && isfinite(PAR[PM_PAR_SYY])  && isfinite(PAR[PM_PAR_SXY]) &&
+                                isfinite(model->mag)) { 
+
+                                xPos[1] = PAR[PM_PAR_XPOS];
+                                yPos[1] = PAR[PM_PAR_YPOS];
+
+                                psEllipseAxes axes = pmPSF_ModelToAxes (PAR, model->class->useReff);
+                                rMajor[1] = axes.major;
+                                rMinor[1] = axes.minor;
+                                theta[1]  = axes.theta*PS_DEG_RAD;
+                                flux[1] = pow(10.0, -0.4*model->mag);
+                                modelType[1] = model->type;
+                                sersicIndex = NAN;
+                                chisq[1] = model->chisq;
+                                nDOF[1] = model->nDOF;
+                                modelFlags[1] = model->flags;
+                                n_rows = 2;
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        if (n_rows == 0) {
+            // didn't find a suitable extended model we have one row with the psf parameters
+            n_rows = 1;
+        }
+
+        for (int j = 0; j < n_rows; j++) {
+            psMetadata *row = psMetadataAlloc();
+            psMetadataAddU32 (row, PS_LIST_TAIL, "ID",         0,   "IPP detection identifier",  source->seq);
+            psMetadataAddF32 (row, PS_LIST_TAIL, "X",                0, "x coordinate",          xPos[j]);
+            psMetadataAddF32 (row, PS_LIST_TAIL, "Y",                0, "y coordinate",          yPos[j]);
+            psMetadataAddF32 (row, PS_LIST_TAIL, "FLUX",             0, "flux per second",       flux[j]/exptime);
+            psMetadataAddF32 (row, PS_LIST_TAIL, "SN",               0, "kron flux signal to noise", SN);
+            psMetadataAddF32 (row, PS_LIST_TAIL, "MAG_DIFF",         0, "psf mag - kron mag",    magDiff);
+            psMetadataAddF32 (row, PS_LIST_TAIL, "AP_RADIUS",        0, "aperture radius",       source->apRadius);
+            psMetadataAddF32 (row, PS_LIST_TAIL, "KRON_RADIUS",      0, "Kron radius",           source->moments->Mrf * 2.5);
+            psMetadataAddF32 (row, PS_LIST_TAIL, "PETRO_RADIUS",     0, "Petrosian Radius",      source->extpars ? source->extpars->petrosianRadius : NAN);
+            psMetadataAddBool (row, PS_LIST_TAIL, "FIT_GALAXY",      0, "source has xfit",       fitGalaxy); 
+            psMetadataAddBool (row, PS_LIST_TAIL, "PSF_STAR",        0, "source was psf star",   psfStar);
+            psMetadataAddF32 (row, PS_LIST_TAIL, "R_MAJOR",          0, "radius of major axis",  rMajor[j]);
+            psMetadataAddF32 (row, PS_LIST_TAIL, "R_MINOR",          0, "radius of minor axis",  rMinor[j]);
+            psMetadataAddF32 (row, PS_LIST_TAIL, "THETA",            0, "theta",                 theta[j]);
+            psMetadataAddS32 (row, PS_LIST_TAIL, "MODEL_TYPE",       0, "model type",            modelType[j]);
+            psMetadataAddF32 (row, PS_LIST_TAIL, "INDEX",            0, "sersic index",          sersicIndex);
+            psMetadataAddF32 (row, PS_LIST_TAIL, "CHISQ",            0, "chisq",                 chisq[j]);
+            psMetadataAddF32 (row, PS_LIST_TAIL, "NDOF",             0, "n degrees of freedom",  nDOF[j]);
+            psMetadataAddS32 (row, PS_LIST_TAIL, "MODEL_FLAGS",      0, "model flags",           modelFlags[j]);
+
+            psArrayAdd(table, 100, row);
+            psFree(row);
+        }
+    }
+
+    if (!psFitsWriteTable(fits, outputHeader, table, extname)) {
+        psError(psErrorCodeLast(), false, "writing ext data %s\n", extname);
+        psFree(table);
+        psFree(outputHeader);
+        return false;
+    }
+    psFree(table);
+    psFree(outputHeader);
+
+    return true;
+}
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceIO_CMF.c.in
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceIO_CMF.c.in	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceIO_CMF.c.in	(revision 37066)
@@ -37,11 +37,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceFitModel.h"
@@ -141,7 +142,8 @@
         @ALL@      		    psMetadataAdd (row, PS_LIST_TAIL, "AP_MAG",           PS_DATA_F32, "magnitude in standard aperture",             source->apMag);
 	@>PS1_V2,PS1_SV?,>PS1_DV1@  psMetadataAdd (row, PS_LIST_TAIL, "AP_MAG_RAW",       PS_DATA_F32, "magnitude in reported aperture",             source->apMagRaw);
-        @ALL@      		    psMetadataAdd (row, PS_LIST_TAIL, "AP_MAG_RADIUS",    PS_DATA_F32, "radius used for aperture mags",              outputs.apRadius);
+        @ALL@      		    psMetadataAdd (row, PS_LIST_TAIL, "AP_MAG_RADIUS",    PS_DATA_F32, "radius used for aperture mags",              source->apRadius);
 	@>PS1_DV1,>PS1_V3,>PS1_SV1@ psMetadataAdd (row, PS_LIST_TAIL, "AP_FLUX",          PS_DATA_F32, "instrumental flux in standard aperture",     source->apFlux);
 	@>PS1_DV1,>PS1_V3,>PS1_SV1@ psMetadataAdd (row, PS_LIST_TAIL, "AP_FLUX_SIG",      PS_DATA_F32, "aperture flux error",                        source->apFluxErr);
+	@>PS1_V4,>PS1_SV2,>PS1_DV3@ psMetadataAdd (row, PS_LIST_TAIL, "AP_NPIX",          PS_DATA_S32, "aperture unmasked pixels",                   source->apNpixels);
 
 	@<PS1_V3,PS1_SV1,PS1_DV?@ psMetadataAdd (row, PS_LIST_TAIL, "PEAK_FLUX_AS_MAG", PS_DATA_F32, "Peak flux expressed as magnitude",           outputs.peakMag);
@@ -162,7 +164,15 @@
         @ALL@     		  psMetadataAdd (row, PS_LIST_TAIL, "EXT_NSIGMA",       PS_DATA_F32, "Nsigma deviations from PSF to EXT",          source->extNsigma);
 
+        // PSF shape parameters:
         @ALL@     		  psMetadataAdd (row, PS_LIST_TAIL, "PSF_MAJOR",        PS_DATA_F32, "PSF width (major axis)",                     outputs.psfMajor);
         @ALL@     		  psMetadataAdd (row, PS_LIST_TAIL, "PSF_MINOR",        PS_DATA_F32, "PSF width (minor axis)",                     outputs.psfMinor);
         @ALL@     		  psMetadataAdd (row, PS_LIST_TAIL, "PSF_THETA",        PS_DATA_F32, "PSF orientation angle",                      outputs.psfTheta);
+        @>PS1_V4,>PS1_SV2,>PS1_DV3@ psMetadataAdd (row, PS_LIST_TAIL, "PSF_CORE",         PS_DATA_F32, "k term if defined",                          outputs.psfCore);
+
+	// I use a look-up table and linear interpolation to map PSF_MAJOR,PSF_MINOR + PSF_CORE to FWHM values
+        @>PS1_V4,>PS1_SV2,>PS1_DV3@ psMetadataAdd (row, PS_LIST_TAIL, "PSF_FWHM_MAJ",        PS_DATA_F32, "PSF FWHM (major axis)",                   outputs.psfMajorFWHM);
+        @>PS1_V4,>PS1_SV2,>PS1_DV3@ psMetadataAdd (row, PS_LIST_TAIL, "PSF_FWHM_MIN",        PS_DATA_F32, "PSF FWHM (minor axis)",                   outputs.psfMinorFWHM);
+
+        // psf data quality
         @ALL@     		  psMetadataAdd (row, PS_LIST_TAIL, "PSF_QF",           PS_DATA_F32, "PSF coverage/quality factor (bad)",          source->pixWeightNotBad);
 	@>PS1_V2,PS1_SV?,>PS1_DV1@ psMetadataAdd (row, PS_LIST_TAIL, "PSF_QF_PERFECT",   PS_DATA_F32, "PSF coverage/quality factor (poor)",         source->pixWeightNotPoor);
@@ -178,4 +188,37 @@
 	@>PS1_V2,PS1_SV?@ 	  psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_M4C",      PS_DATA_F32, "fourth momemt cos theta",                    moments.M_c4);
 	@>PS1_V2,PS1_SV?@ 	  psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_M4S",      PS_DATA_F32, "fourth momemt sin theta",                    moments.M_s4);
+
+	// Lensing parameters:
+	if (source->lensingOBJ && source->lensingOBJ->smear) {
+	  @>PS1_V4@               psMetadataAdd (row, PS_LIST_TAIL, "LENS_X11_SM_OBJ",  PS_DATA_F32, "smear polarizability element (objects)",     source->lensingOBJ->smear->X11);
+	  @>PS1_V4@               psMetadataAdd (row, PS_LIST_TAIL, "LENS_X12_SM_OBJ",  PS_DATA_F32, "smear polarizability element (objects)",     source->lensingOBJ->smear->X12);
+	  @>PS1_V4@               psMetadataAdd (row, PS_LIST_TAIL, "LENS_X22_SM_OBJ",  PS_DATA_F32, "smear polarizability element (objects)",     source->lensingOBJ->smear->X22);
+	  @>PS1_V4@               psMetadataAdd (row, PS_LIST_TAIL, "LENS_E1_SM_OBJ",   PS_DATA_F32, "smear polarizability element (objects)",     source->lensingOBJ->smear->e1);
+	  @>PS1_V4@               psMetadataAdd (row, PS_LIST_TAIL, "LENS_E2_SM_OBJ",   PS_DATA_F32, "smear polarizability element (objects)",     source->lensingOBJ->smear->e2);
+	}
+
+	if (source->lensingOBJ && source->lensingOBJ->shear) {
+	  @>PS1_V4@               psMetadataAdd (row, PS_LIST_TAIL, "LENS_X11_SH_OBJ",  PS_DATA_F32, "shear polarizability element (objects)",     source->lensingOBJ->shear->X11);
+	  @>PS1_V4@               psMetadataAdd (row, PS_LIST_TAIL, "LENS_X12_SH_OBJ",  PS_DATA_F32, "shear polarizability element (objects)",     source->lensingOBJ->shear->X12);
+	  @>PS1_V4@               psMetadataAdd (row, PS_LIST_TAIL, "LENS_X22_SH_OBJ",  PS_DATA_F32, "shear polarizability element (objects)",     source->lensingOBJ->shear->X22);
+	  @>PS1_V4@               psMetadataAdd (row, PS_LIST_TAIL, "LENS_E1_SH_OBJ",   PS_DATA_F32, "shear polarizability element (objects)",     source->lensingOBJ->shear->e1); 
+	  @>PS1_V4@               psMetadataAdd (row, PS_LIST_TAIL, "LENS_E2_SH_OBJ",   PS_DATA_F32, "shear polarizability element (objects)",     source->lensingOBJ->shear->e2); 
+	}
+
+	if (source->lensingPSF && source->lensingPSF->smear) {
+	  @>PS1_V4@               psMetadataAdd (row, PS_LIST_TAIL, "LENS_X11_SM_PSF",  PS_DATA_F32, "smear polarizability element (objects)",     source->lensingPSF->smear->X11);
+	  @>PS1_V4@               psMetadataAdd (row, PS_LIST_TAIL, "LENS_X12_SM_PSF",  PS_DATA_F32, "smear polarizability element (objects)",     source->lensingPSF->smear->X12);
+	  @>PS1_V4@               psMetadataAdd (row, PS_LIST_TAIL, "LENS_X22_SM_PSF",  PS_DATA_F32, "smear polarizability element (objects)",     source->lensingPSF->smear->X22);
+	  @>PS1_V4@               psMetadataAdd (row, PS_LIST_TAIL, "LENS_E1_SM_PSF",   PS_DATA_F32, "smear polarizability element (objects)",     source->lensingPSF->smear->e1); 
+	  @>PS1_V4@               psMetadataAdd (row, PS_LIST_TAIL, "LENS_E2_SM_PSF",   PS_DATA_F32, "smear polarizability element (objects)",     source->lensingPSF->smear->e2); 
+	}
+
+	if (source->lensingPSF && source->lensingPSF->shear) {
+	  @>PS1_V4@               psMetadataAdd (row, PS_LIST_TAIL, "LENS_X11_SH_PSF",  PS_DATA_F32, "shear polarizability element (objects)",     source->lensingPSF->shear->X11);
+	  @>PS1_V4@               psMetadataAdd (row, PS_LIST_TAIL, "LENS_X12_SH_PSF",  PS_DATA_F32, "shear polarizability element (objects)",     source->lensingPSF->shear->X12);
+	  @>PS1_V4@               psMetadataAdd (row, PS_LIST_TAIL, "LENS_X22_SH_PSF",  PS_DATA_F32, "shear polarizability element (objects)",     source->lensingPSF->shear->X22);
+	  @>PS1_V4@               psMetadataAdd (row, PS_LIST_TAIL, "LENS_E1_SH_PSF",   PS_DATA_F32, "shear polarizability element (objects)",     source->lensingPSF->shear->e1); 
+	  @>PS1_V4@               psMetadataAdd (row, PS_LIST_TAIL, "LENS_E2_SH_PSF",   PS_DATA_F32, "shear polarizability element (objects)",     source->lensingPSF->shear->e2); 
+	}
 
         @>PS1_V2,PS1_SV?,>PS1_DV1@ psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_R1",       PS_DATA_F32, "first radial moment",                        moments.Mrf);
@@ -268,12 +311,16 @@
 
     // define PSF model type
-    // XXX need to carry the extra model parameters
     int modelType = pmModelClassGetType ("PS_MODEL_GAUSS");
 
-    char *PSF_NAME = psMetadataLookupStr (&status, header, "PSF_NAME");
+    // if header does not define the model, default to a gaussian
+    char *PSF_NAME = psMetadataLookupStr (&status, header, "PSFMODEL");
     if (PSF_NAME != NULL) {
         modelType = pmModelClassGetType (PSF_NAME);
     }
     assert (modelType > -1);
+
+    // do we expect to find lensing parameters?
+    bool haveLensOBJ = psMetadataLookupBool (&status, header, "LENS_OBJ");
+    bool haveLensPSF = psMetadataLookupBool (&status, header, "LENS_PSF");
 
     // We get the size of the table, and allocate the array of sources first because the table
@@ -310,4 +357,8 @@
         @ALL@     axes.theta        = psMetadataLookupF32 (&status, row, "PSF_THETA");
         @ALL@     axes.theta        = axes.theta * PS_RAD_DEG;
+	
+	@>PS1_V4,>PS1_SV2,>PS1_DV3@ if (model->params->n > PM_PAR_7) {
+	@>PS1_V4,>PS1_SV2,>PS1_DV3@     PAR[PM_PAR_7] = psMetadataLookupF32 (&status, row, "PSF_CORE");
+	@>PS1_V4,>PS1_SV2,>PS1_DV3@ } 
 
         @ALL@     PAR[PM_PAR_SKY]   = psMetadataLookupF32 (&status, row, "SKY");
@@ -321,4 +372,6 @@
         @ALL@     source->apMag     = psMetadataLookupF32 (&status, row, "AP_MAG");
         @>PS1_V2,PS1_SV?,>PS1_DV1@ source->apMagRaw  = psMetadataLookupF32 (&status, row, "AP_MAG_RAW");
+	@>PS1_DV1,>PS1_V3,>PS1_SV1@ source->apFlux = psMetadataLookupF32 (&status, row, "AP_FLUX");
+	@>PS1_DV1,>PS1_V3,>PS1_SV1@ source->apFluxErr = psMetadataLookupF32 (&status, row, "AP_FLUX_SIG");
 
         // XXX use these to determine PAR[PM_PAR_I0] if they exist?
@@ -331,5 +384,5 @@
         @ALL@     dPAR[PM_PAR_I0]   = (isfinite(source->psfMag)) ? PAR[PM_PAR_I0] * source->psfMagErr : NAN;
 
-        pmPSF_AxesToModel (PAR, axes, modelType);
+        pmPSF_AxesToModel (PAR, axes, model->class->useReff);
 
         @ALL@     float peakMag     = psMetadataLookupF32 (&status, row, "PEAK_FLUX_AS_MAG");
@@ -349,5 +402,6 @@
         @ALL@     source->crNsigma  = psMetadataLookupF32 (&status, row, "CR_NSIGMA");
         @ALL@     source->extNsigma = psMetadataLookupF32 (&status, row, "EXT_NSIGMA");
-        @ALL@     source->apRadius  = psMetadataLookupS32 (&status, row, "AP_MAG_RADIUS");
+        @ALL@     source->apRadius  = psMetadataLookupF32 (&status, row, "AP_MAG_RADIUS");
+	@>PS1_V4,>PS1_SV2,>PS1_DV3@ source->apNpixels = psMetadataLookupS32 (&status, row, "AP_NPIX");
 
         // note that some older versions used PSF_PROBABILITY: this was not well defined.
@@ -376,4 +430,39 @@
         @>PS1_V2,PS1_SV?@ source->moments->Mxyyy = -0.25 * psMetadataLookupF32 (&status, row, "MOMENTS_M4S");
         @>PS1_V2,PS1_SV?@ source->moments->Myyyy = 0.0;
+
+	// Lensing parameters (on read if PS1_V5+)
+	if (haveLensOBJ) {
+	  source->lensingOBJ = pmSourceLensingAlloc ();
+	  source->lensingOBJ->smear = pmLensingParsAlloc();
+	  source->lensingOBJ->shear = pmLensingParsAlloc();
+
+	  @>PS1_V4@ source->lensingOBJ->smear->X11 = psMetadataLookupF32 (&status, row, "LENS_X11_SM_OBJ");
+	  @>PS1_V4@ source->lensingOBJ->smear->X12 = psMetadataLookupF32 (&status, row, "LENS_X12_SM_OBJ");
+	  @>PS1_V4@ source->lensingOBJ->smear->X22 = psMetadataLookupF32 (&status, row, "LENS_X22_SM_OBJ");
+	  @>PS1_V4@ source->lensingOBJ->smear->e1  = psMetadataLookupF32 (&status, row, "LENS_E1_SM_OBJ");
+	  @>PS1_V4@ source->lensingOBJ->smear->e2  = psMetadataLookupF32 (&status, row, "LENS_E2_SM_OBJ");
+	  @>PS1_V4@ source->lensingOBJ->shear->X11 = psMetadataLookupF32 (&status, row, "LENS_X11_SH_OBJ");
+	  @>PS1_V4@ source->lensingOBJ->shear->X12 = psMetadataLookupF32 (&status, row, "LENS_X12_SH_OBJ");
+	  @>PS1_V4@ source->lensingOBJ->shear->X22 = psMetadataLookupF32 (&status, row, "LENS_X22_SH_OBJ");
+	  @>PS1_V4@ source->lensingOBJ->shear->e1  = psMetadataLookupF32 (&status, row, "LENS_E1_SH_OBJ");
+	  @>PS1_V4@ source->lensingOBJ->shear->e2  = psMetadataLookupF32 (&status, row, "LENS_E2_SH_OBJ");
+	}
+
+	if (haveLensPSF) {
+	  source->lensingPSF = pmSourceLensingAlloc ();
+	  source->lensingPSF->smear = pmLensingParsAlloc();
+	  source->lensingPSF->shear = pmLensingParsAlloc();
+
+	  @>PS1_V4@ source->lensingPSF->smear->X11 = psMetadataLookupF32 (&status, row, "LENS_X11_SM_PSF");
+	  @>PS1_V4@ source->lensingPSF->smear->X12 = psMetadataLookupF32 (&status, row, "LENS_X12_SM_PSF");
+	  @>PS1_V4@ source->lensingPSF->smear->X22 = psMetadataLookupF32 (&status, row, "LENS_X22_SM_PSF");
+	  @>PS1_V4@ source->lensingPSF->smear->e1  = psMetadataLookupF32 (&status, row, "LENS_E1_SM_PSF");
+	  @>PS1_V4@ source->lensingPSF->smear->e2  = psMetadataLookupF32 (&status, row, "LENS_E2_SM_PSF");
+	  @>PS1_V4@ source->lensingPSF->shear->X11 = psMetadataLookupF32 (&status, row, "LENS_X11_SH_PSF");
+	  @>PS1_V4@ source->lensingPSF->shear->X12 = psMetadataLookupF32 (&status, row, "LENS_X12_SH_PSF");
+	  @>PS1_V4@ source->lensingPSF->shear->X22 = psMetadataLookupF32 (&status, row, "LENS_X22_SH_PSF");
+	  @>PS1_V4@ source->lensingPSF->shear->e1  = psMetadataLookupF32 (&status, row, "LENS_E1_SH_PSF");
+	  @>PS1_V4@ source->lensingPSF->shear->e2  = psMetadataLookupF32 (&status, row, "LENS_E2_SH_PSF");
+	}
 
         @>PS1_V2,PS1_SV?,>PS1_DV1@ source->moments->Mrf         = psMetadataLookupF32 (&status, row, "MOMENTS_R1");
@@ -448,6 +537,8 @@
     }
 
+#ifdef SORT_EXTENSIONS_BY_FLUX
     // let's write these out in S/N order
     sources = psArraySort (sources, pmSourceSortByFlux);
+#endif
 
     table = psArrayAllocEmpty (sources->n);
@@ -708,21 +799,9 @@
             return false;
         }
-        // Find the source with this sequence number. 
-        // XXX: I am assuming that sources is sorted in order of seq
+        // Find the source with this sequence number using the sourceIndex. 
         long seq = psMetadataLookupU32 (&status, row, "IPP_IDET");
-        pmSource *source = NULL;
-#ifndef ASSUME_SORTED
-        long j = seq < sources->n ? seq : sources->n - 1;
-        for (; j >= 0; j--) {
-            source = sources->data[j];
-            if (source->seq == seq) {
-                break;
-            }
-        }
-#else
         long j = sourceIndex[seq];
         psAssert(j >= 0 && j < sources->n, "invalid sourceIndex");
-        source = sources->data[j];
-#endif
+        pmSource *source = sources->data[j];
         if (!source) {
             psError(PS_ERR_UNKNOWN, false, "Failed to find source for row %ld sequence number %ld\n", i, seq);
@@ -789,18 +868,24 @@
     char name[64];
 
+    pmModelType modelTypeTrail = pmModelClassGetType("PS_MODEL_TRAIL");
+
     // create a header to hold the output data
     psMetadata *outhead = psMetadataAlloc ();
 
+    pmModelClassWriteHeader(outhead);
+
     // write the links to the image header
     psMetadataAddStr (outhead, PS_LIST_TAIL, "EXTNAME", PS_META_REPLACE, "xsrc table extension", extname);
 
+#ifdef SORT_EXTENSIONS_BY_FLUX
     // let's write these out in S/N order
     sources = psArraySort (sources, pmSourceSortByFlux);
-
-    @>PS1_DV2@ float magOffset; 
-    @>PS1_DV2@ float zeroptErr; 
-    @>PS1_DV2@ float fwhmMajor; 
-    @>PS1_DV2@ float fwhmMinor;
-    @>PS1_DV2@ pmSourceOutputsCommonValues (&magOffset, &zeroptErr, &fwhmMajor, &fwhmMinor, readout, imageHeader);
+#endif
+
+    float magOffset; 
+    float zeroptErr; 
+    float fwhmMajor; 
+    float fwhmMinor;
+    pmSourceOutputsCommonValues (&magOffset, &zeroptErr, &fwhmMajor, &fwhmMinor, readout, imageHeader);
 
     // we are writing one row per model; we need to write out same number of columns for each row: find the max Nparams
@@ -823,4 +908,12 @@
     @>PS1_DV2@ pmChip *chip = readout->parent->parent;
 
+    pmModelStatus badModel = PM_MODEL_STATUS_NONE;
+    badModel |= PM_MODEL_STATUS_BADARGS;
+    badModel |= PM_MODEL_STATUS_OFFIMAGE;
+    badModel |= PM_MODEL_STATUS_NAN_CHISQ;
+    badModel |= PM_MODEL_SERSIC_PCM_FAIL_GUESS;
+    badModel |= PM_MODEL_SERSIC_PCM_FAIL_GRID;
+    badModel |= PM_MODEL_PCM_FAIL_GUESS;
+
     table = psArrayAllocEmpty (sources->n);
 
@@ -847,5 +940,6 @@
 
 	    // skip models which were not actually fitted
-	    if (model->flags & PM_MODEL_STATUS_BADARGS) continue;
+	    // XXX 
+	    if (model->flags & badModel) continue;
 
             PAR = model->params->data.F32;
@@ -853,6 +947,21 @@
             xPos = PAR[PM_PAR_XPOS];
             yPos = PAR[PM_PAR_YPOS];
-            xErr = dPAR[PM_PAR_XPOS];
-            yErr = dPAR[PM_PAR_YPOS];
+
+	    // for the extended source models, we do not always fit the centroid in the non-linear fitting process
+	    // current situation (hard-wired into psphotSourceFits.c:psphotFitPCM,
+	    // SERSIC, DEV, EXP : X,Y not fitted (PCM and not PCM)
+	    // TRAIL : X,Y are fitted
+	    // 
+	    
+	    // XXX this should be based on what happened, not on the model type
+	    if (model->type == modelTypeTrail) {
+		xErr = dPAR[PM_PAR_XPOS];
+		yErr = dPAR[PM_PAR_YPOS];
+	    } else {
+		// this is definitely an underestimate since it does not
+		// account for the extent of the source
+		xErr = fwhmMajor * model->magErr / 2.35;
+		yErr = fwhmMinor * model->magErr / 2.35;
+	    }
 
 	    @>PS1_DV2@ psSphere ptSky = {0.0, 0.0, 0.0, 0.0};
@@ -870,5 +979,4 @@
             row = psMetadataAlloc ();
 
-            // XXX we are not writing out the mode (flags) or the type (psf, ext, etc)
 	    // the psMetadataAdd entry and the double quotes are used by grep to select the output fields for automatic documentation
 	    // This set of psMetadataAdd Entries marks the "----" "Start of the XFIT segment"
@@ -888,6 +996,10 @@
 	    @>PS1_DV2@ float calMag = isfinite(magOffset) ? model->mag + magOffset : NAN;
 	    @>PS1_DV2@ psMetadataAdd (row, PS_LIST_TAIL, "EXT_CAL_MAG", PS_DATA_F32, "EXT Magnitude using supplied calibration",   calMag);
-	    @>PS1_DV2@ psMetadataAdd (row, PS_LIST_TAIL, "EXT_CHISQ",   PS_DATA_F32, "EXT Magnitude using supplied calibration",   model->chisq);
-	    @>PS1_DV2@ psMetadataAdd (row, PS_LIST_TAIL, "EXT_NDOF",    PS_DATA_S32, "EXT Magnitude using supplied calibration",   model->nDOF);
+	    @>PS1_DV2,PS1_SV?@ psMetadataAdd (row, PS_LIST_TAIL, "EXT_CHISQ",   PS_DATA_F32, "EXT Model Chisq",   model->chisq);
+	    @>PS1_DV2,PS1_SV?@ psMetadataAdd (row, PS_LIST_TAIL, "EXT_NDOF",    PS_DATA_S32, "EXT Model num degrees of freedom",   model->nDOF);
+	    @>PS1_SV1,PS1_SV?@ psMetadataAdd (row, PS_LIST_TAIL, "EXT_MODEL_TYPE",    PS_DATA_S32, "type for chosen EXT_MODEL",   source->modelEXT ? source->modelEXT->type : -1);
+
+	    // EAM : adding for PV2 outputs:
+	    @>PS1_SV1@ psMetadataAdd (row, PS_LIST_TAIL, "EXT_FLAGS", PS_DATA_S16, "model fit flags (pmModelStatus)", model->flags);
 
             @>PS1_DV2@ psMetadataAddF32 (row, PS_LIST_TAIL, "POSANGLE",   0, "position angle at source (degrees)",         posAngle);
@@ -925,5 +1037,5 @@
 		    psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_THETA_ERR",     0, "EXT angle err (SXY, isnan)", dPAR[PM_PAR_SXY]);
 		} else {
-		    psEllipseAxes axes = pmPSF_ModelToAxes (PAR, model->type);
+		    psEllipseAxes axes = pmPSF_ModelToAxes (PAR, model->class->useReff);
 		    psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_WIDTH_MAJ",    0, "EXT width (major axis), length for trail", axes.major);
 		    psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_WIDTH_MIN",    0, "EXT width (minor axis), sigma for trail",  axes.minor);
@@ -946,5 +1058,5 @@
 
                 snprintf (name, 64, "EXT_PAR_%02d", k);
-
+	       
                 if (k < model->params->n) {
                     psMetadataAddF32 (row, PS_LIST_TAIL, name, 0, "", model->params->data.F32[k]);
@@ -956,5 +1068,5 @@
 	    // optionally, write out the covariance matrix values
 	    // XXX do I need to pad this to match the biggest covar matrix?
-	    if (model->covar) {
+	    if (false && model->covar) {
 		for (int iy = 0; iy < model->covar->numCols; iy++) {
 		    for (int ix = iy; ix < model->covar->numCols; ix++) {
@@ -1005,4 +1117,7 @@
         return false;
     }
+    // set up the lookup table to translate between input model types and output model types
+    // if not defined it is assumed that the tables are the same
+    pmModelClassReadHeader(tableHeader);
 
     for (long i = 0; i < numSources; i++) {
@@ -1013,15 +1128,8 @@
             return false;
         }
-        // Find the source with this sequence number. 
-        // XXX: I am assuming that sources is sorted in order of seq.
         long seq = psMetadataLookupU32 (&status, row, "IPP_IDET");
-        long j = seq < sources->n ? seq : sources->n - 1;
-        pmSource *source = NULL;
-        for (; j >= 0; j--) {
-            source = sources->data[j];
-            if (source->seq == seq) {
-                break;
-            }
-        }
+        long j = sourceIndex[seq];
+        psAssert(j >= 0 && j < sources->n, "invalid sourceIndex");
+        pmSource *source = sources->data[j];
         if (!source) {
             psError(PS_ERR_UNKNOWN, false, "Failed to find source for row %ld sequence number %ld\n", i, seq);
@@ -1058,9 +1166,26 @@
         model->magErr = psMetadataLookupF32(&status, row, "EXT_INST_MAG_SIG");
 
+        model->chisq = psMetadataLookupF32(&status, row, "EXT_CHISQ");
+        model->nDOF = psMetadataLookupF32(&status, row, "EXT_NDOF");
+        model->flags = psMetadataLookupS16(&status, row, "EXT_FLAGS");
+
+        // EXT_MODEL_TYPE gives the model chosen by psphot as the best.
+        // Putting this into the XFIT table makes 3 copies of it (one for each model)
+        // but since we have many fewer XFIT rows than psf rows that is cheaper than putting it
+        // in the psf table.
+        psS32 extModelType = psMetadataLookupS32(&status, row, "EXT_MODEL_TYPE");
+        if (status) {
+            // translate between the type value in xfit and values used by this program
+            extModelType = pmModelClassGetLocalType(extModelType);
+        } else {
+            // older cmfs don't have this column
+            extModelType = -1;
+        } 
+
         psEllipseAxes axes;
         axes.major = psMetadataLookupF32(&status, row, "EXT_WIDTH_MAJ");
         axes.minor = psMetadataLookupF32(&status, row, "EXT_WIDTH_MIN");
         axes.theta = psMetadataLookupF32(&status, row, "EXT_THETA");
-        if (!pmPSF_AxesToModel(PAR, axes, modelType)) {
+        if (!pmPSF_AxesToModel(PAR, axes, model->class->useReff)) {
             // Do we need to fail here or can this happen?
             psError(PS_ERR_UNKNOWN, false, "Failed to convert psf axes to model");
@@ -1072,20 +1197,40 @@
         if (model->params->n > 7) {
             PAR[7] = psMetadataLookupF32(&status, row, "EXT_PAR_07");
-        }
-        // read the covariance matrix
-        int nparams = model->params->n;
-        psImage *covar = psImageAlloc(nparams, nparams, PS_TYPE_F32);
-        for (int y = 0; y < nparams; y++) {
-            for (int x = 0; x < nparams; x++) {
-                char name[64];
-                snprintf(name, 64, "EXT_COVAR_%02d_%02d", y, x);
-                covar->data.F32[y][x] = psMetadataLookupF32(&status, row, name);
+            // XXX add an error:
+	    // dPAR[7] = psMetadataLookupF32(&status, row, "EXT_PAR_07_");
+        }
+
+	// XXX : make this depend on what is in the cmf
+	if (0) {
+	    // read the covariance matrix
+	    int nparams = model->params->n;
+	    psImage *covar = psImageAlloc(nparams, nparams, PS_TYPE_F32);
+	    for (int y = 0; y < nparams; y++) {
+		for (int x = 0; x < nparams; x++) {
+		    char name[64];
+		    snprintf(name, 64, "EXT_COVAR_%02d_%02d", y, x);
+		    covar->data.F32[y][x] = psMetadataLookupF32(&status, row, name);
+		}
+	    }
+	    model->covar = covar;
+	}
+
+        if (modelType == extModelType) {
+            // The software that created this source picked this model as the best of the fits. 
+            // Set the extModel to point to it.
+            // This is important for programs like psastro (skycal) so that its output cmfs
+            // will have valid EXT_MODEL_TYPE
+            psFree(source->modelEXT);
+            source->modelEXT = psMemIncrRefCounter(model);
+            source->type = PM_SOURCE_TYPE_EXTENDED;
+            if (0) {
+                // since FLAGS were read we don't need to do this
+                source->mode |= PM_SOURCE_MODE_EXTMODEL;
+                source->mode |= PM_SOURCE_MODE_NONLINEAR_FIT;
             }
         }
-        model->covar = covar;
 
         psArrayAdd(source->modelFits, 1, model);
         psFree(model);
-
         psFree(row);
     }
@@ -1140,6 +1285,8 @@
     psVector *fwhmValues = psMetadataLookupVector(&status, readout->analysis, "STACK.PSF.FWHM.VALUES");
 
+#ifdef SORT_EXTENSIONS_BY_FLUX
     // let's write these out in S/N order
     sources = psArraySort (sources, pmSourceSortByFlux);
+#endif
 
     table = psArrayAllocEmpty (sources->n);
@@ -1209,8 +1356,8 @@
 
 	write_annuli:
-	    psMetadataAdd (row, PS_LIST_TAIL, "APER_FLUX",     	 PS_DATA_VECTOR, "flux within annuli",       radFlux);
-	    psMetadataAdd (row, PS_LIST_TAIL, "APER_FLUX_ERR", 	 PS_DATA_VECTOR, "flux error in annuli",     radFluxErr);
-	    psMetadataAdd (row, PS_LIST_TAIL, "APER_FLUX_STDEV", PS_DATA_VECTOR, "flux standard deviation",  radFluxStdev);
-	    psMetadataAdd (row, PS_LIST_TAIL, "APER_FILL",       PS_DATA_VECTOR, "fill factor of annuli",    radFill);
+	    psMetadataAddVector (row, PS_LIST_TAIL, "APER_FLUX",       PS_META_REPLACE, "flux within annuli",       radFlux);
+	    psMetadataAddVector (row, PS_LIST_TAIL, "APER_FLUX_ERR",   PS_META_REPLACE, "flux error in annuli",     radFluxErr);
+	    psMetadataAddVector (row, PS_LIST_TAIL, "APER_FLUX_STDEV", PS_META_REPLACE, "flux standard deviation",  radFluxStdev);
+	    psMetadataAddVector (row, PS_LIST_TAIL, "APER_FILL",       PS_META_REPLACE, "fill factor of annuli",    radFill);
 	    psFree (radFlux);
 	    psFree (radFluxErr);
@@ -1277,15 +1424,8 @@
             return false;
         }
-        // Find the source with this sequence number. 
-        // XXX: I am assuming that sources is sorted in order of seq.
         long seq = psMetadataLookupU32 (&status, row, "IPP_IDET");
-        long j = seq < sources->n ? seq : sources->n - 1;
-        pmSource *source = NULL;
-        for (; j >= 0; j--) {
-            source = sources->data[j];
-            if (source->seq == seq) {
-                break;
-            }
-        }
+        long j = sourceIndex[seq];
+        psAssert(j >= 0 && j < sources->n, "invalid sourceIndex");
+        pmSource *source = sources->data[j];
         if (!source) {
             psError(PS_ERR_UNKNOWN, false, "Failed to find source for row %ld sequence number %ld\n", i, seq);
@@ -1343,2 +1483,203 @@
     return true;
 }
+
+// XXX where should I record the number of columns??
+bool pmSourcesWrite_CMF_@CMFMODE@_XGAL (psFits *fits, pmReadout *readout, psArray *sources, char *extname, psMetadata *recipe)
+{
+    bool status = false;
+
+    // perform full non-linear fits / extended source analysis?
+    if (!psMetadataLookupBool (&status, recipe, "GALAXY_SHAPES")) {
+	psLogMsg ("psphot", PS_LOG_INFO, "galaxy shapes were not measured, skipping\n");
+	return true;
+    }
+
+    // create a header to hold the output data
+    psMetadata *outhead = psMetadataAlloc ();
+
+    // write the links to the image header
+    psMetadataAddStr (outhead, PS_LIST_TAIL, "EXTNAME", PS_META_REPLACE, "galaxy table extension", extname);
+
+    psF32 Q = psMetadataLookupF32(&status, recipe, "GALAXY_SHAPES_Q");
+    psMetadataAddF32 (outhead, PS_LIST_TAIL, "GALAXY_SHAPES_Q", PS_META_REPLACE, "", Q);
+
+    psF32 NSigma = psMetadataLookupF32(&status, recipe, "GALAXY_SHAPES_NSIGMA");
+    psMetadataAddF32 (outhead, PS_LIST_TAIL, "GALAXY_SHAPES_NSIGMA", PS_META_REPLACE, "", NSigma);
+
+    psF32 clampSN = psMetadataLookupF32(&status, recipe, "GALAXY_SHAPES_CLAMP_SN");
+    psMetadataAddF32 (outhead, PS_LIST_TAIL, "GALAXY_SHAPES_CLAMP_SN", PS_META_REPLACE, "", clampSN);
+
+    // They are probably already in this order but ...
+    sources = psArraySort (sources, pmSourceSortBySeq);
+
+    psArray *table = psArrayAllocEmpty (sources->n);
+
+    for (int i = 0; i < sources->n; i++) {
+
+        pmSource *thisSource = sources->data[i];
+
+	// this is the "real" version of this source 
+	pmSource *source = thisSource->parent ? thisSource->parent : thisSource;
+
+	// if we did not fit the galaxy model, modelFits will be NULL
+        if (source->modelFits == NULL) continue;
+
+	// if we did not fit the galaxy model, galaxyFits will also be NULL
+        if (source->galaxyFits == NULL) continue;
+
+        for (int iModel = 0; iModel < source->modelFits->n; iModel++) {
+            pmModel *model = source->modelFits->data[iModel];
+            if (!model) continue;
+
+            pmSourceGalaxyFits *galaxyFits = NULL;
+            for (int iFit = 0; iFit < source->galaxyFits->n; iFit++) {
+                galaxyFits = source->galaxyFits->data[iFit];
+                if (model->type == galaxyFits->modelType) break;
+                galaxyFits = NULL;
+            }
+
+            if (!galaxyFits) continue;
+
+            // X,Y coordinates are stored with the model parameters
+            psF32 *PAR = model->params->data.F32;
+
+            psMetadata *row = psMetadataAlloc ();
+
+            // we write out the x,y positions so people can link to the psf either way (position or ID)
+            psMetadataAddU32 (row, PS_LIST_TAIL, "IPP_IDET",         0, "IPP detection identifier index", source->seq);
+            psMetadataAddS32 (row, PS_LIST_TAIL, "MODEL_TYPE",       0, "model type",                     galaxyFits->modelType);
+            psMetadataAddF32 (row, PS_LIST_TAIL, "X_FIT",            0, "model x coordinate",             PAR[PM_PAR_XPOS]);
+            psMetadataAddF32 (row, PS_LIST_TAIL, "Y_FIT",            0, "model y coordinate",             PAR[PM_PAR_YPOS]);
+            psMetadataAddF32 (row, PS_LIST_TAIL, "NPIX",             0, "number of pixels for fits",      galaxyFits->nPix);
+            // psMetadataAddS32 (row, PS_LIST_TAIL, "REDUCED_TRIALS",   0, "source has reduced number of trials",      galaxyFits->reducedTrials);
+
+            psVector *Flux = galaxyFits->Flux;
+            psVector *dFlux = galaxyFits->dFlux;
+            psVector *chisq = galaxyFits->chisq;
+
+            psMetadataAddVector (row, PS_LIST_TAIL, "GAL_FLUX",     PS_META_REPLACE, "normalization for galaxy flux", Flux);
+            psMetadataAddVector (row, PS_LIST_TAIL, "GAL_FLUX_ERR", PS_META_REPLACE, "error on normalization", dFlux);
+            psMetadataAddVector (row, PS_LIST_TAIL, "GAL_CHISQ",    PS_META_REPLACE, "galaxy fit chisq", chisq);
+
+            psMetadataAddF32 (row, PS_LIST_TAIL, "FR_MAJOR_MIN",    0, "fractional major axis min",      galaxyFits->fRmajorMin);
+            psMetadataAddF32 (row, PS_LIST_TAIL, "FR_MAJOR_MAX",    0, "fractional major axis max",      galaxyFits->fRmajorMax);
+            psMetadataAddF32 (row, PS_LIST_TAIL, "FR_MAJOR_DEL",    0, "fractional major axis max",      galaxyFits->fRmajorDel);
+            psMetadataAddF32 (row, PS_LIST_TAIL, "FR_MINOR_MIN",    0, "fractional minor axis min",      galaxyFits->fRminorMin);
+            psMetadataAddF32 (row, PS_LIST_TAIL, "FR_MINOR_MAX",    0, "fractional minor axis max",      galaxyFits->fRminorMax);
+            psMetadataAddF32 (row, PS_LIST_TAIL, "FR_MINOR_DEL",    0, "fractional minor axis max",      galaxyFits->fRminorDel);
+
+            psArrayAdd (table, 100, row);
+            psFree (row);
+        }
+    }
+
+    if (table->n == 0) {
+        if (!psFitsWriteBlank (fits, outhead, extname)) {
+            psError(psErrorCodeLast(), false, "Unable to write empty sources file.");
+            psFree(outhead);
+            psFree(table);
+            return false;
+        }
+        psFree (outhead);
+        psFree (table);
+        return true;
+    }
+
+    psTrace ("pmFPAfile", 5, "writing galaxy data %s\n", extname);
+    if (!psFitsWriteTable (fits, outhead, table, extname)) {
+        psError(psErrorCodeLast(), false, "writing galaxy data %s\n", extname);
+        psFree (outhead);
+        psFree(table);
+        return false;
+    }
+    psFree (outhead);
+    psFree (table);
+    return true;
+}
+
+bool pmSourcesRead_CMF_@CMFMODE@_XGAL(psFits *fits, pmReadout *readout, psMetadata *hduHeader, psMetadata *tableHeader, psArray *sources, long *sourceIndex)
+{
+    PS_ASSERT_PTR_NON_NULL(fits, false);
+    PS_ASSERT_PTR_NON_NULL(sources, false);
+
+    bool status;
+    long numSources = psFitsTableSize(fits); // Number of sources in table
+    if (numSources == 0) {
+        psError(psErrorCodeLast(), false, "XGAL Table contains no entries\n");
+        return false;
+    }
+    if (!readout->analysis) {
+        readout->analysis = psMetadataAlloc();
+    }
+    psF32 Q = psMetadataLookupF32(&status, tableHeader, "GALAXY_SHAPES_Q");
+    // XXX: turn this into an assert once we're done
+    if (status) {
+        psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "GALAXY_SHAPES_Q", PS_META_REPLACE, "", Q);
+
+        psF32 NSigma = psMetadataLookupF32(&status, tableHeader, "GALAXY_SHAPES_NSIGMA");
+        psAssert(status, "missing GALAXY_SHAPES_NSIGMA");
+        psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "GALAXY_SHAPES_NSIGMA", PS_META_REPLACE, "", NSigma);
+
+        psF32 clampSN = psMetadataLookupF32(&status, tableHeader, "GALAXY_SHAPES_CLAMP_SN");
+        psAssert(status, "missing GALAXY_SHAPES_CLAMP_SN");
+        psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "GALAXY_SHAPES_CLAMP_SN", PS_META_REPLACE, "", clampSN);
+    }
+
+    for (long i = 0; i < numSources; i++) {
+        psMetadata *row = psFitsReadTableRow(fits, i); // Table row
+        if (!row) {
+            psError(psErrorCodeLast(), false, "Unable to read row %ld of sources", i);
+            psFree(row);
+            return false;
+        }
+        // Find the source with this sequence number. 
+        // XXX: I am assuming that sources is sorted in order of seq
+        long seq = psMetadataLookupU32 (&status, row, "IPP_IDET");
+        long j = sourceIndex[seq];
+        psAssert(j >= 0 && j < sources->n, "invalid sourceIndex");
+
+        pmSource *source = sources->data[j];
+        if (!source) {
+            psError(PS_ERR_UNKNOWN, false, "Failed to find source for row %ld sequence number %ld\n", i, seq);
+            psFree(row);
+            return false;
+        }
+
+        int modelType = psMetadataLookupS32 (&status,    row, "MODEL_TYPE");
+        psVector *Flux  = psMetadataLookupVector(&status, row, "GAL_FLUX");
+        psVector *dFlux = psMetadataLookupVector(&status, row, "GAL_FLUX_ERR");
+        psVector *chisq = psMetadataLookupVector(&status, row, "GAL_CHISQ");
+
+        if (Flux && Flux->n > 0) {
+            if (!source->galaxyFits) {
+                source->galaxyFits = psArrayAllocEmpty(1);
+            }
+
+            pmSourceGalaxyFits *galaxyFits = pmSourceGalaxyFitsAlloc();
+
+            psArrayAdd(source->galaxyFits, 1, galaxyFits);
+
+            psFree(galaxyFits);
+            galaxyFits->modelType = modelType;
+            galaxyFits->nPix = psMetadataLookupF32(&status, row, "NPIX");
+
+            galaxyFits->fRmajorMin = psMetadataLookupF32(&status, row, "FR_MAJOR_MIN");
+            galaxyFits->fRmajorMax = psMetadataLookupF32(&status, row, "FR_MAJOR_MAX");
+            galaxyFits->fRmajorDel = psMetadataLookupF32(&status, row, "FR_MAJOR_DEL");
+            galaxyFits->fRminorMin = psMetadataLookupF32(&status, row, "FR_MINOR_MIN");
+            galaxyFits->fRminorMax = psMetadataLookupF32(&status, row, "FR_MINOR_MAX");
+            galaxyFits->fRminorDel = psMetadataLookupF32(&status, row, "FR_MINOR_DEL");
+
+            psFree(galaxyFits->Flux);
+            galaxyFits->Flux  = psMemIncrRefCounter(Flux);
+            psFree(galaxyFits->dFlux);
+            galaxyFits->dFlux = psMemIncrRefCounter(dFlux);
+            psFree(galaxyFits->chisq);
+            galaxyFits->chisq = psMemIncrRefCounter(chisq);
+        }
+
+        psFree(row);
+    }
+
+    return true;
+}
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceIO_CMP.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceIO_CMP.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceIO_CMP.c	(revision 37066)
@@ -37,11 +37,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceFitModel.h"
@@ -135,5 +136,5 @@
         lsky = (source->sky < 1.0) ? 0.0 : log10(source->sky);
 
-        axes = pmPSF_ModelToAxes (PAR, model->type);
+        axes = pmPSF_ModelToAxes (PAR, model->class->useReff);
 
         float psfMagErr = isfinite(source->psfMagErr) ? source->psfMagErr : 999;
@@ -292,5 +293,5 @@
                 goto skip_source;
 
-            pmPSF_AxesToModel (PAR, axes, modelType);
+            pmPSF_AxesToModel (PAR, axes, source->modelPSF->class->useReff);
 
             psArrayAdd (sources, 100, source);
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceIO_MatchedRefs.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceIO_MatchedRefs.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceIO_MatchedRefs.c	(revision 37066)
@@ -37,11 +37,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceFitModel.h"
@@ -98,22 +99,11 @@
 
                     // select the raw objects for this readout
-                    psArray *rawstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.RAWSTARS");
+                    psArray *rawstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.RAWSTARS.SUBSET");
                     if (rawstars == NULL) continue;
 
                     // select the raw objects for this readout
-                    psArray *refstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.REFSTARS");
+                    psArray *refstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.REFSTARS.SUBSET");
                     if (refstars == NULL) continue;
                     psTrace ("psastro", 4, "Trying %ld refstars\n", refstars->n);
-
-# if (0)
-                    // XXX test
-                    FILE *outfile = fopen ("refstars.dat", "w");
-                    assert (outfile);
-                    for (int nn = 0; nn < refstars->n; nn++) {
-                        pmAstromObj *ref = refstars->data[nn];
-                        fprintf (outfile, "%lf %lf\n", ref->sky->r*PS_DEG_RAD, ref->sky->d*PS_DEG_RAD);
-                    }
-                    fclose (outfile);
-# endif
 
                     psArray *matches = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.MATCH");
@@ -127,16 +117,18 @@
 
                         psMetadata *row = psMetadataAlloc ();
-                        psMetadataAdd (row, PS_LIST_TAIL, "RA",       PS_DATA_F64, "right ascension (deg, J2000)", PM_DEG_RAD*ref->sky->r);
-                        psMetadataAdd (row, PS_LIST_TAIL, "DEC",      PS_DATA_F64, "declination (deg, J2000)",     PM_DEG_RAD*ref->sky->d);
-                        psMetadataAdd (row, PS_LIST_TAIL, "X_CHIP",   PS_DATA_F32, "x coord on chip",              raw->chip->x);
-                        psMetadataAdd (row, PS_LIST_TAIL, "Y_CHIP",   PS_DATA_F32, "y coord on chip",              raw->chip->y);
-                        psMetadataAdd (row, PS_LIST_TAIL, "X_CHIP_FIT",PS_DATA_F32, "x fitted coord on chip",      ref->chip->x);
-                        psMetadataAdd (row, PS_LIST_TAIL, "Y_CHIP_FIT",PS_DATA_F32, "y fitted coord on chip",      ref->chip->y);
-                        psMetadataAdd (row, PS_LIST_TAIL, "X_FPA",    PS_DATA_F32, "x coord on focal plane",       raw->FP->x);
-                        psMetadataAdd (row, PS_LIST_TAIL, "Y_FPA",    PS_DATA_F32, "y coord on focal plane",       raw->FP->y);
-                        psMetadataAdd (row, PS_LIST_TAIL, "MAG_INST", PS_DATA_F32, "instrumental magnitude",       raw->Mag);
-                        psMetadataAdd (row, PS_LIST_TAIL, "MAG_REF",  PS_DATA_F32, "reference star magnitude",     ref->Mag);
-                        psMetadataAdd (row, PS_LIST_TAIL, "COLOR_REF",PS_DATA_F32, "reference star color",         ref->Color);
-                        psMetadataAdd (row, PS_LIST_TAIL, "CHIP_ID",  PS_DATA_STRING, "chip identifier",           chipName);
+                        psMetadataAdd (row, PS_LIST_TAIL, "RA_REF",     PS_DATA_F64, "right ascension (deg, J2000)", PM_DEG_RAD*ref->sky->r);
+                        psMetadataAdd (row, PS_LIST_TAIL, "DEC_REF",    PS_DATA_F64, "declination (deg, J2000)",     PM_DEG_RAD*ref->sky->d);
+                        psMetadataAdd (row, PS_LIST_TAIL, "X_CHIP_REF", PS_DATA_F32, "x fitted coord on chip",       ref->chip->x);
+                        psMetadataAdd (row, PS_LIST_TAIL, "Y_CHIP_REF", PS_DATA_F32, "y fitted coord on chip",       ref->chip->y);
+                        psMetadataAdd (row, PS_LIST_TAIL, "X_CHIP_RAW", PS_DATA_F32, "x coord on chip",              raw->chip->x);
+                        psMetadataAdd (row, PS_LIST_TAIL, "Y_CHIP_RAW", PS_DATA_F32, "y coord on chip",              raw->chip->y);
+                        psMetadataAdd (row, PS_LIST_TAIL, "X_FPA_RAW",  PS_DATA_F32, "x coord on focal plane",       raw->FP->x);
+                        psMetadataAdd (row, PS_LIST_TAIL, "Y_FPA_RAW",  PS_DATA_F32, "y coord on focal plane",       raw->FP->y);
+                        psMetadataAdd (row, PS_LIST_TAIL, "X_TPA_RAW",  PS_DATA_F32, "x coord on focal plane",       raw->TP->x);
+                        psMetadataAdd (row, PS_LIST_TAIL, "Y_TPA_RAW",  PS_DATA_F32, "y coord on focal plane",       raw->TP->y);
+                        psMetadataAdd (row, PS_LIST_TAIL, "MAG_INST",   PS_DATA_F32, "instrumental magnitude",       raw->Mag);
+                        psMetadataAdd (row, PS_LIST_TAIL, "MAG_REF",    PS_DATA_F32, "reference star magnitude",     ref->Mag);
+                        psMetadataAdd (row, PS_LIST_TAIL, "COLOR_REF",  PS_DATA_F32, "reference star color",         ref->Color);
+                        psMetadataAdd (row, PS_LIST_TAIL, "CHIP_ID",    PS_DATA_STRING, "chip identifier",           chipName);
                         // XXX need to add the reference color, but this needs getstar / dvo.photcodes for the reference to be refined.
 
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceIO_OBJ.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceIO_OBJ.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceIO_OBJ.c	(revision 37066)
@@ -37,11 +37,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceFitModel.h"
@@ -92,5 +93,5 @@
         }
 
-        axes = pmPSF_ModelToAxes (PAR, model->type);
+        axes = pmPSF_ModelToAxes (PAR, model->class->useReff);
 
         psLineInit (line);
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceIO_PS1_CAL_0.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceIO_PS1_CAL_0.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceIO_PS1_CAL_0.c	(revision 37066)
@@ -37,11 +37,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceFitModel.h"
@@ -114,5 +115,5 @@
             yErr = dPAR[PM_PAR_YPOS];
 	    if (isfinite(PAR[PM_PAR_SXX]) && isfinite(PAR[PM_PAR_SXX]) && isfinite(PAR[PM_PAR_SXX])) {
-		axes = pmPSF_ModelToAxes (PAR, model->type);
+		axes = pmPSF_ModelToAxes (PAR, model->class->useReff);
 	    } else {
 		axes.major = NAN;
@@ -289,5 +290,5 @@
 	dPAR[PM_PAR_I0]   = (isfinite(source->psfMag)) ? PAR[PM_PAR_I0] * source->psfMagErr : NAN;
 
-        pmPSF_AxesToModel (PAR, axes, modelType);
+        pmPSF_AxesToModel (PAR, axes, model->class->useReff);
 
         float peakMag     = psMetadataLookupF32 (&status, row, "PEAK_FLUX_AS_MAG");
@@ -623,5 +624,5 @@
 	    yErr = dPAR[PM_PAR_YPOS];
 
-	    axes = pmPSF_ModelToAxes (PAR, model->type);
+	    axes = pmPSF_ModelToAxes (PAR, model->class->useReff);
 
 	    // generate RA,DEC
@@ -713,2 +714,7 @@
     return true;
 }
+
+bool pmSourcesWrite_PS1_CAL_0_XGAL (psFits *fits, pmReadout *readout, psArray *sources, char *extname, psMetadata *recipe)
+{
+    return true;
+}
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceIO_PS1_DEV_0.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceIO_PS1_DEV_0.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceIO_PS1_DEV_0.c	(revision 37066)
@@ -37,11 +37,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceFitModel.h"
@@ -90,5 +91,5 @@
             yErr = dPAR[PM_PAR_YPOS];
 
-            axes = pmPSF_ModelToAxes (PAR, model->type);
+            axes = pmPSF_ModelToAxes (PAR, model->class->useReff);
         } else {
             // XXX: This code seg faults if source->peak is NULL.
@@ -215,5 +216,5 @@
         source->psfMagErr    = psMetadataLookupF32 (&status, row, "PSF_INST_MAG_SIG");
 
-        pmPSF_AxesToModel (PAR, axes, modelType);
+        pmPSF_AxesToModel (PAR, axes, model->class->useReff);
 
         float peakMag = psMetadataLookupF32 (&status, row, "PEAK_FLUX_AS_MAG");
@@ -255,2 +256,7 @@
     return true;
 }
+
+bool pmSourcesWrite_PS1_DEV_0_XGAL(psFits *fits, pmReadout *readout, psArray *sources, char *extname, psMetadata *recipe)
+{
+    return true;
+}
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceIO_PS1_DEV_1.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceIO_PS1_DEV_1.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceIO_PS1_DEV_1.c	(revision 37066)
@@ -37,11 +37,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceFitModel.h"
@@ -96,5 +97,5 @@
             yErr = dPAR[PM_PAR_YPOS];
 	    if (isfinite(PAR[PM_PAR_SXX]) && isfinite(PAR[PM_PAR_SXX]) && isfinite(PAR[PM_PAR_SXX])) {
-		axes = pmPSF_ModelToAxes (PAR, model->type);
+		axes = pmPSF_ModelToAxes (PAR, model->class->useReff);
 	    } else {
 		axes.major = NAN;
@@ -258,5 +259,5 @@
 	dPAR[PM_PAR_I0]   = (isfinite(source->psfMag)) ? PAR[PM_PAR_I0] * source->psfMagErr : NAN;
 
-        pmPSF_AxesToModel (PAR, axes, modelType);
+        pmPSF_AxesToModel (PAR, axes, model->class->useReff);
 
         float peakMag     = psMetadataLookupF32 (&status, row, "PEAK_FLUX_AS_MAG");
@@ -523,5 +524,5 @@
 	    yErr = dPAR[PM_PAR_YPOS];
 
-	    axes = pmPSF_ModelToAxes (PAR, model->type);
+	    axes = pmPSF_ModelToAxes (PAR, model->class->useReff);
 
 	    row = psMetadataAlloc ();
@@ -595,2 +596,7 @@
     return true;
 }
+
+bool pmSourcesWrite_PS1_DEV_1_XGAL(psFits *fits, pmReadout *readout, psArray *sources, char *extname, psMetadata *recipe)
+{
+    return true;
+}
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceIO_RAW.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceIO_RAW.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceIO_RAW.c	(revision 37066)
@@ -37,11 +37,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceFitModel.h"
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceIO_SMPDATA.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceIO_SMPDATA.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceIO_SMPDATA.c	(revision 37066)
@@ -37,11 +37,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceFitModel.h"
@@ -92,5 +93,5 @@
 	    lsky = (source->sky < 1.0) ? 0.0 : log10(source->sky);
 
-	    axes = pmPSF_ModelToAxes (PAR, model->type);
+	    axes = pmPSF_ModelToAxes (PAR, model->class->useReff);
 
 	} else {
@@ -189,5 +190,5 @@
         axes.theta       = psMetadataLookupF32 (&status, row, "THETA");
 
-	pmPSF_AxesToModel (PAR, axes, modelType);
+	pmPSF_AxesToModel (PAR, axes, model->class->useReff);
 
         source->psfMag = psMetadataLookupF32 (&status, row, "MAG_RAW") - ZERO_POINT;
@@ -225,2 +226,7 @@
     return true;
 } 
+
+bool pmSourcesWrite_SMPDATA_XGAL(psFits *fits, pmReadout *readout, psArray *sources, char *extname, psMetadata *recipe)
+{
+    return true;
+} 
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceIO_SX.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceIO_SX.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceIO_SX.c	(revision 37066)
@@ -37,11 +37,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceFitModel.h"
@@ -81,5 +82,5 @@
         // pmSourceSextractType (source, &type, &flags);
 
-        axes = pmPSF_ModelToAxes (PAR, model->type);
+        axes = pmPSF_ModelToAxes (PAR, model->class->useReff);
 
         psLineInit (line);
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceLensing.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceLensing.c	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceLensing.c	(revision 37066)
@@ -0,0 +1,112 @@
+/** @file  pmSourceLensing.c
+ *
+ *  Functions to measure the local sky and sky variance for sources on images
+ *  @author EAM, IfA: 
+ *  @date $Date: 2014-03-20 $
+ *
+ *  Copyright 2014 Ifa, University of Hawaii
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <math.h>
+#include <string.h>
+#include <pslib.h>
+
+#include "pmMoments.h"
+#include "pmSourceLensing.h"
+
+static void pmLensingParsFree (pmLensingPars *pars) {
+  if (!pars) return;
+  return;
+}
+
+pmLensingPars *pmLensingParsAlloc () {
+
+  pmLensingPars *tmp = (pmLensingPars *) psAlloc(sizeof(pmLensingPars));;
+  psMemSetDeallocator(tmp, (psFreeFunc) pmLensingParsFree);
+
+  tmp->X11 = NAN;
+  tmp->X12 = NAN;
+  tmp->X22 = NAN;
+
+  tmp->e1 = NAN;
+  tmp->e2 = NAN;
+
+  return tmp;
+}
+
+static void pmSourceLensingFree (pmSourceLensing *lensing) {
+  if (!lensing) return;
+  psFree (lensing->smear);
+  psFree (lensing->shear);
+  return;
+}
+
+pmSourceLensing *pmSourceLensingAlloc () {
+
+  pmSourceLensing *tmp = (pmSourceLensing *) psAlloc(sizeof(pmSourceLensing));;
+  psMemSetDeallocator(tmp, (psFreeFunc) pmSourceLensingFree);
+
+  tmp->smear = NULL;
+  tmp->shear = NULL;
+
+  return tmp;
+}
+
+// need to supply the moments and the window-function sigma
+bool pmSourceLensingShearFromMoments (pmSourceLensing *lensing, pmMoments *moments, float sigma) {
+  
+  if (!lensing->shear) {
+    lensing->shear = pmLensingParsAlloc();
+  }
+  
+  pmLensingPars *shear = lensing->shear;
+
+  float R = 1.0 / (moments->Mxx + moments->Myy);
+  float s2 = 1.0 / PS_SQR(sigma);
+  // NOTE : not used by shear : float s4 = PS_SQR(s2);
+
+  shear->X11 = R*(2.0*(moments->Mxx + moments->Myy) - s2 * (moments->Mxxxx - 2.0*moments->Mxxyy + moments->Myyyy));
+
+  shear->X22 = R*(2.0*(moments->Mxx + moments->Myy) - s2 * 4.0 * moments->Mxxyy);
+
+  shear->X12 = R*2.0*s2*(moments->Mxyyy - moments->Mxxxy);
+
+  shear->e1  = R*(2.0*(moments->Mxx - moments->Myy) + s2 * (moments->Myyyy - moments->Mxxxx));
+
+  shear->e2  = R*(4.0*moments->Mxy - 2.0*s2*(moments->Mxxxy + moments->Mxyyy));
+  
+  return true;
+}
+
+// need to supply the moments and the window-function sigma
+// NOTE: I'm using the coefficients from Hoekstra et al 1998, not KSB96
+bool pmSourceLensingSmearFromMoments (pmSourceLensing *lensing, pmMoments *moments, float sigma) {
+  
+  if (!lensing->smear) {
+    lensing->smear = pmLensingParsAlloc();
+  }
+  
+  pmLensingPars *smear = lensing->smear;
+
+  float R = 1.0 / (moments->Mxx + moments->Myy);
+  float s2 = 1.0 / PS_SQR(sigma);
+  float s4 = PS_SQR(s2);
+
+  smear->X11 = R*(1.0 - s2*(moments->Mxx + moments->Myy) + 0.25*s4 * (moments->Mxxxx - 2.0*moments->Mxxyy + moments->Myyyy));
+
+  smear->X22 = R*(1.0 - s2*(moments->Mxx + moments->Myy) + 1.00*s4 * (moments->Mxxyy));
+
+  smear->X12 = R*0.5*s4*(moments->Mxxxy - moments->Mxyyy);
+
+  smear->e1  = R*(s2*(moments->Myy - moments->Mxx) + 0.25*s4 * (moments->Myyyy - moments->Mxxxx));
+
+  smear->e2  = R*(0.5*s4*(moments->Mxxxy + moments->Mxyyy) - 2.0*s2*moments->Mxy);
+  
+  return true;
+}
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceLensing.h
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceLensing.h	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceLensing.h	(revision 37066)
@@ -0,0 +1,36 @@
+/* @file  pmSourceLensing.h
+ *
+ * @author EAM, IfA
+ *
+ * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2014-03-20 02:31:25 $
+ * Copyright 2014 IfA, University of Hawaii
+ */
+
+# ifndef PM_SOURCE_LENSING_H
+# define PM_SOURCE_LENSING_H
+
+/// @addtogroup Objects Object Detection / Analysis Functions
+/// @{
+
+typedef struct {
+  float X11;
+  float X12;
+  float X22;
+  float e1;
+  float e2;
+} pmLensingPars;
+
+typedef struct {
+  pmLensingPars *smear;
+  pmLensingPars *shear;
+} pmSourceLensing; 
+
+pmLensingPars *pmLensingParsAlloc ();
+pmSourceLensing *pmSourceLensingAlloc ();
+
+bool pmSourceLensingShearFromMoments (pmSourceLensing *lensing, pmMoments *moments, float sigma);
+bool pmSourceLensingSmearFromMoments (pmSourceLensing *lensing, pmMoments *moments, float sigma);
+
+/// @}
+# endif /* PM_SOURCE_LENSING_H */
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceMasks.h
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceMasks.h	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceMasks.h	(revision 37066)
@@ -56,4 +56,19 @@
     PM_SOURCE_MODE2_DIFF_SELF_MATCH  	  = 0x00000800, ///< positive detection match is probably this source 
     PM_SOURCE_MODE2_SATSTAR_PROFILE       = 0x00001000, ///< saturated source is modeled with a radial profile
+
+    PM_SOURCE_MODE2_ECONTOUR_FEW_PTS      = 0x00002000, ///< too few points to measure the elliptical contour
+    PM_SOURCE_MODE2_RADBIN_NAN_CENTER     = 0x00004000, ///< radial bins failed with too many NaN center bin
+    PM_SOURCE_MODE2_PETRO_NAN_CENTER      = 0x00008000, ///< petrosian radial bins failed with too many NaN center bin
+    PM_SOURCE_MODE2_PETRO_NO_PROFILE      = 0x00010000, ///< petrosian not build because radial bins missing
+
+    PM_SOURCE_MODE2_PETRO_INSIG_RATIO     = 0x00020000, ///< insignificant measurement of petrosian ratio
+    PM_SOURCE_MODE2_PETRO_RATIO_ZEROBIN   = 0x00040000, ///< petrosian ratio in the 0th bin (likely bad)
+    
+    PM_SOURCE_MODE2_EXT_FITS_RUN          = 0x00080000, ///< we attempted to run extended fits on this source
+    PM_SOURCE_MODE2_EXT_FITS_FAIL         = 0x00100000, ///< at least one of the model fits failed
+    PM_SOURCE_MODE2_EXT_FITS_RETRY        = 0x00200000, ///< one of the model fits was re-tried with new window
+    PM_SOURCE_MODE2_EXT_FITS_NONE         = 0x00400000, ///< ALL of the model fits failed
+    
+    
 } pmSourceMode2;
 
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceMatch.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceMatch.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceMatch.c	(revision 37066)
@@ -18,11 +18,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceFitModel.h"
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceMoments.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceMoments.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceMoments.c	(revision 37066)
@@ -35,11 +35,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 
@@ -65,6 +66,9 @@
 void pmSourceMomentsSetVerbose(bool state){ beVerbose = state; }
 
+bool pmSourceMomentsHighOrder    (pmSource *source, float radius, float sigma, float minSN, psImageMaskType maskVal);
+bool pmSourceMomentsRadialMoment (pmSource *source, float radius, float minKronRadius, psImageMaskType maskVal);
+bool pmSourceMomentsKronFluxes   (pmSource *source, float sigma,  float minSN, psImageMaskType maskVal);
+
 // if mode & EXTERNAL or mode2 & MATCHED, do not re-calculate the centroid (use peak as centroid)
-
 bool pmSourceMoments(pmSource *source, float radius, float sigma, float minSN, float minKronRadius, psImageMaskType maskVal)
 {
@@ -74,18 +78,7 @@
     PS_ASSERT_FLOAT_LARGER_THAN(radius, 0.0, false);
 
-    // this function assumes the sky has been well-subtracted for the image
-    float sky = 0.0;
-
     if (source->moments == NULL) {
       source->moments = pmMomentsAlloc();
     }
-
-    float Sum = 0.0;
-    float Var = 0.0;
-    float SumCore = 0.0;
-    float VarCore = 0.0;
-    float R2 = PS_SQR(radius);
-    float minSN2 = PS_SQR(minSN);
-    float rsigma2 = 0.5 / PS_SQR(sigma);
 
     // a note about coordinates: coordinates of objects throughout psphot refer to the primary
@@ -110,10 +103,229 @@
     // of any object drops pretty quickly outside 1-2 sigmas.  (The exception is bright
     // saturated stars, for which we need to use a very large radius here)
+    // NOTE: if (mode & EXTERNAL) or (mode2 & MATCHED), do not re-calculate the centroid (use peak as centroid)
+    // (we still call this function because it sets moments->Sum,SN,Peak,nPixels
     if (!pmSourceMomentsGetCentroid (source, 1.5*sigma, 0.0, minSN, maskVal, source->peak->xf, source->peak->yf)) {
 	return false;
     }
 
+    pmSourceMomentsHighOrder (source, radius, sigma, minSN, maskVal);
+
+    // now calculate the 1st radial moment (for kron flux) using symmetrical averaging
+    pmSourceMomentsRadialMoment (source, radius, minKronRadius, maskVal);
+
+    // now calculate the kron flux values using the 1st radial moment
+    pmSourceMomentsKronFluxes (source, sigma, minSN, maskVal);
+
+    psTrace ("psModules.objects", 4, "Mrf: %f  KronFlux: %f  Mxx: %f  Mxy: %f  Myy: %f  Mxxx: %f  Mxxy: %f  Mxyy: %f  Myyy: %f  Mxxxx: %f  Mxxxy: %f  Mxxyy: %f  Mxyyy: %f  Mxyyy: %f\n",
+	     source->moments->Mrf,   source->moments->KronFlux, 
+	     source->moments->Mxx,   source->moments->Mxy,   source->moments->Myy,
+	     source->moments->Mxxx,  source->moments->Mxxy,  source->moments->Mxyy,  source->moments->Myyy,
+	     source->moments->Mxxxx, source->moments->Mxxxy, source->moments->Mxxyy, source->moments->Mxyyy, source->moments->Myyyy);
+
+    psTrace ("psModules.objects", 3, "peak %f %f (%f = %f) Mx: %f  My: %f  Sum: %f  Mxx: %f  Mxy: %f  Myy: %f  Npix: %d\n",
+	     source->peak->xf, source->peak->yf, 
+	     source->peak->rawFlux, sqrt(source->peak->detValue), 
+	     source->moments->Mx, source->moments->My, 
+	     source->moments->Sum, 
+	     source->moments->Mxx, source->moments->Mxy, source->moments->Myy, 
+	     source->moments->nPixels);
+
+    return(true);
+}
+
+bool pmSourceMomentsGetCentroid(pmSource *source, float radius, float sigma, float minSN, psImageMaskType maskVal, float xGuess, float yGuess) { 
+
+    // First Pass: calculate the first moments (these are subtracted from the coordinates below)
+    // Sum = SUM (z - sky)
+    // X1  = SUM (x - xc)*(z - sky)
+    // .. etc
+
+    float sky = 0.0;
+
+    float peakPixel = -PS_MAX_F32;
+    psS32 numPixels = 0;
+    float Sum = 0.0;
+    float Var = 0.0;
+    float X1 = 0.0;
+    float Y1 = 0.0;
+    float R2 = PS_SQR(radius);
+    float minSN2 = PS_SQR(minSN);
+    float rsigma2 = 0.5 / PS_SQR(sigma);
+
+    float xPeak = xGuess - source->pixels->col0; // coord of peak in subimage
+    float yPeak = yGuess - source->pixels->row0; // coord of peak in subimage
+
+    // we are guaranteed to have a valid pixel and variance at this location (right? right?)
+    // float weightNorm = source->pixels->data.F32[yPeak][xPeak] / sqrt (source->variance->data.F32[yPeak][xPeak]);
+    // psAssert (isfinite(source->pixels->data.F32[yPeak][xPeak]), "peak must be on valid pixel");
+    // psAssert (isfinite(source->variance->data.F32[yPeak][xPeak]), "peak must be on valid pixel");
+    // psAssert (source->variance->data.F32[yPeak][xPeak] > 0, "peak must be on valid pixel");
+
+    // the moments [Sum(x*f) / Sum(f)] are calculated in pixel index values, and should
+    // not depend on the fractional pixel location of the source.  However, the aperture
+    // (radius) and the Gaussian window (sigma) depend subtly on the fractional pixel
+    // position of the expected centroid
+
+    for (psS32 row = 0; row < source->pixels->numRows ; row++) {
+
+	float yDiff = row + 0.5 - yPeak;
+	if (fabs(yDiff) > radius) continue;
+
+	float *vPix = source->pixels->data.F32[row];
+	float *vWgt = source->variance ? source->variance->data.F32[row] : source->pixels->data.F32[row];
+
+	psImageMaskType *vMsk = (source->maskObj == NULL) ? NULL : source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[row];
+	// psImageMaskType *vMsk = (source->maskView == NULL) ? NULL : source->maskView->data.PS_TYPE_IMAGE_MASK_DATA[row];
+
+	for (psS32 col = 0; col < source->pixels->numCols ; col++, vPix++, vWgt++) {
+	    if (vMsk) {
+		if (*vMsk & maskVal) {
+		    vMsk++;
+		    continue;
+		}
+		vMsk++;
+	    }
+	    if (isnan(*vPix)) continue;
+
+	    float xDiff = col + 0.5 - xPeak;
+	    if (fabs(xDiff) > radius) continue;
+
+	    // radius is just a function of (xDiff, yDiff)
+	    float r2  = PS_SQR(xDiff) + PS_SQR(yDiff);
+	    if (r2 > R2) continue;
+
+	    float pDiff = *vPix - sky;
+	    float wDiff = *vWgt;
+
+	    // skip pixels below specified significance level.  for a PSFs, this
+	    // over-weights the wings of bright stars compared to those of faint stars.
+	    // for the estimator used for extended source analysis (where the window
+	    // function is allowed to be arbitrarily large), we need to clip to avoid
+	    // negative second moments.
+	    if (PS_SQR(pDiff) < minSN2*wDiff) continue; // 
+	    if ((minSN > 0.0) && (pDiff < 0)) continue; // 
+
+	    // Apply a Gaussian window function.  Be careful with the window function.  S/N
+	    // weighting over weights the sky for faint sources
+	    if (sigma > 0.0) {
+		float z  = r2*rsigma2;
+		assert (z >= 0.0);
+		float weight  = exp(-z);
+
+		wDiff *= weight;
+		pDiff *= weight;
+	    } 
+
+	    Var += wDiff;
+	    Sum += pDiff;
+
+	    float xWght = xDiff * pDiff;
+	    float yWght = yDiff * pDiff;
+
+	    X1  += xWght;
+	    Y1  += yWght;
+
+	    peakPixel = PS_MAX (*vPix, peakPixel);
+	    numPixels++;
+	}
+    }
+
+    // if we have less than (1/4) of the possible pixels (in circle or box), force a retry
+    int minPixels = PS_MIN(0.75*R2, source->pixels->numCols*source->pixels->numRows/4.0);
+
+    // XXX EAM - the limit is a bit arbitrary.  make it user defined?
+    if ((numPixels < minPixels) || (Sum <= 0)) {
+	psTrace ("psModules.objects", 3, "insufficient valid pixels (%d vs %d; %f) for source\n", numPixels, minPixels, Sum);
+	return (false);
+    }
+
+    // calculate the first moment.
+    float Mx = X1/Sum;
+    float My = Y1/Sum;
+    if ((fabs(Mx) > radius) || (fabs(My) > radius)) {
+	psTrace ("psModules.objects", 3, "extreme centroid swing; invalid peak %d, %d\n", source->peak->x, source->peak->y);
+	return (false);
+    }
+    if ((fabs(Mx) > 2.0) || (fabs(My) > 2.0)) {
+	psTrace ("psModules.objects", 3, " big centroid swing; ok peak? %d, %d\n", source->peak->x, source->peak->y);
+    }
+
+    psTrace ("psModules.objects", 5, "id: %d, sky: %f  Mx: %f  My: %f  Sum: %f  X1: %f  Y1: %f  Npix: %d\n", source->id, sky, Mx, My, Sum, X1, Y1, numPixels);
+
+    // add back offset of peak in primary image
+    // also offset from pixel index to pixel coordinate
+    // (the calculation above uses pixel index instead of coordinate)
+    // 0.5 PIX: moments are calculated using the pixel index and converted here to pixel coords
+
+    // we only update the centroid if the position is not supplied from elsewhere
+    bool skipCentroid = false;
+    skipCentroid |= (source->mode  & PM_SOURCE_MODE_EXTERNAL); // skip externally supplied positions
+    skipCentroid |= (source->mode2 & PM_SOURCE_MODE2_MATCHED); // skip sources defined by other image positions
+
+    if (skipCentroid) {
+	source->moments->Mx = source->peak->xf;
+	source->moments->My = source->peak->yf;
+    } else {
+	source->moments->Mx = Mx + xGuess;
+	source->moments->My = My + yGuess;
+    }
+
+    source->moments->Sum = Sum;
+    source->moments->SN  = Sum / sqrt(Var);
+    source->moments->Peak = peakPixel;
+    source->moments->nPixels = numPixels;
+
+    return true;
+}
+
+float pmSourceMinKronRadius(psArray *sources, float PSF_SN_LIM) {
+
+    psVector *radii = psVectorAllocEmpty(100, PS_TYPE_F32);
+
+    for (int i = 0; i < sources->n; i++) {
+	pmSource *src = sources->data[i]; // Source of interest
+	if (!src || !src->moments) {
+	    continue;
+	}
+
+	if (src->mode & PM_SOURCE_MODE_BLEND) {
+	    continue;
+	}
+
+	if (!src->moments->nPixels) continue;
+
+	if (src->moments->SN < PSF_SN_LIM) continue;
+
+	// XXX put in Mxx,Myy cut based on clump location
+
+	psVectorAppend(radii, src->moments->Mrf);
+    }
+
+    // find the peak in this image
+    psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN);
+
+    if (!psVectorStats (stats, radii, NULL, NULL, 0)) {
+	psError(PS_ERR_UNKNOWN, false, "Unable to get image statistics.\n");
+	psFree(stats);
+	return NAN;
+    }
+
+    float minRadius = stats->sampleMedian;
+
+    psFree(radii);
+    psFree(stats);
+    return minRadius;
+}
+
+bool pmSourceMomentsHighOrder (pmSource *source, float radius, float sigma, float minSN, psImageMaskType maskVal) {
+
+    // this function assumes the sky has been well-subtracted for the image
+    float Sum = 0.0;
+    float R2 = PS_SQR(radius);
+    float minSN2 = PS_SQR(minSN);
+    float rsigma2 = 0.5 / PS_SQR(sigma);
+
     // Now calculate higher-order moments, using the above-calculated first moments to adjust coordinates
-    // Xn  = SUM (x - xc)^n * (z - sky)
+    // Xn  = SUM (x - xc)^n * (z - sky) -- note that sky is 0.0 by definition here
     float XX = 0.0;
     float XY = 0.0;
@@ -129,11 +341,4 @@
     float YYYY = 0.0;
 
-    Sum = 0.0;  // the second pass may include slightly different pixels, re-determine Sum
-
-    // float dX = source->moments->Mx - source->peak->xf;
-    // float dY = source->moments->My - source->peak->yf;
-    // float dR = hypot(dX, dY);
-    // float Xo = (dR < 2.0) ? source->moments->Mx : source->peak->xf;
-    // float Yo = (dR < 2.0) ? source->moments->My : source->peak->yf;
     float Xo = source->moments->Mx;
     float Yo = source->moments->My;
@@ -154,5 +359,4 @@
 
 	psImageMaskType  *vMsk = (source->maskObj == NULL) ? NULL : source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[row];
-	// psImageMaskType  *vMsk = (source->maskView == NULL) ? NULL : source->maskView->data.PS_TYPE_IMAGE_MASK_DATA[row];
 
 	for (psS32 col = 0; col < source->pixels->numCols ; col++, vPix++, vWgt++) {
@@ -173,5 +377,5 @@
 	    if (r2 > R2) continue;
 
-	    float fDiff = *vPix - sky;
+	    float fDiff = *vPix;
 	    float pDiff = fDiff;
 	    float wDiff = *vWgt;
@@ -181,8 +385,8 @@
 	    // stars.
 	    if (PS_SQR(pDiff) < minSN2*wDiff) continue;
-	    if ((minSN > 0.0) && (pDiff < 0)) continue; // 
+	    if ((minSN > 0.0) && (pDiff < 0)) continue; 
 
 	    // Apply a Gaussian window function.  Be careful with the window function.  S/N
-	    // weighting over weights the sky for faint sources
+	    // weighting over-weights the sky for faint sources
 	    if (sigma > 0.0) {
 		float z = r2 * rsigma2;
@@ -230,22 +434,8 @@
 	    XYYY  += xyyy;
 	    YYYY  += yyyy;
-
-	    // Kron Flux uses the 1st radial moment (NOT Gaussian windowed?)
-	    // XXX float r = sqrt(r2);
-	    // XXX float rf = r * fDiff;
-	    // XXX float rh = sqrt(r) * fDiff;
-	    // XXX float rs = fDiff;
-	    // XXX 
-	    // XXX float rfw = r * pDiff;
-	    // XXX float rhw = sqrt(r) * pDiff;
-	    // XXX 
-	    // XXX RF  += rf;
-	    // XXX RH  += rh;
-	    // XXX RS  += rs;
-	    // XXX 
-	    // XXX RFW  += rfw;
-	    // XXX RHW  += rhw;
 	}
     }
+    // NOT needed : source->moments->wSum = Sum;
+
     source->moments->Mxx = XX/Sum;
     source->moments->Mxy = XY/Sum;
@@ -263,8 +453,11 @@
     source->moments->Myyyy = YYYY/Sum;
 
-    // *** now calculate the 1st radial moment (for kron flux) -- symmetrical averaging
+    return true;
+}
+
+bool pmSourceMomentsRadialMoment (pmSource *source, float radius, float minKronRadius, psImageMaskType maskVal) {
+
 
     float **vPix = source->pixels->data.F32;
-    float **vWgt = source->variance ? source->variance->data.F32 : source->pixels->data.F32;
     psImageMaskType **vMsk = (source->maskObj == NULL) ? NULL : source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA;
 
@@ -272,4 +465,15 @@
     float RH = 0.0;
     float RS = 0.0;
+
+    // centroid around which to calculate the moments
+    float Xo = source->moments->Mx;
+    float Yo = source->moments->My;
+
+    // center of mass in subimage.  Note: the calculation below uses pixel index, so we correct
+    // xCM, yCM from pixel coords to pixel index here.
+    float xCM = Xo - 0.5 - source->pixels->col0; // coord of peak in subimage
+    float yCM = Yo - 0.5 - source->pixels->row0; // coord of peak in subimage
+
+    float R2 = PS_SQR(radius);
 
     for (psS32 row = 0; row < source->pixels->numRows ; row++) {
@@ -304,6 +508,6 @@
 	    if (r2 > R2) continue;
 
-	    float fDiff1 = vPix[row][col] - sky;
-	    float fDiff2 = vPix[yFlip][xFlip] - sky;
+	    float fDiff1 = vPix[row][col];
+	    float fDiff2 = vPix[yFlip][xFlip];
 	    float pDiff = (fDiff1 > 0.0) ? sqrt(fabs(fDiff1*fDiff2)) : -sqrt(fabs(fDiff1*fDiff2));
 
@@ -329,11 +533,22 @@
 	kronRefRadius = MIN(radius, kronRefRadius);
     }
-    source->moments->Mrf = kronRefRadius;
-
-    // *** now calculate the kron flux values using the 1st radial moment
-
-    float radKinner = 1.0*kronRefRadius;
-    float radKron   = 2.5*kronRefRadius;
-    float radKouter = 4.0*kronRefRadius;
+
+    // if source is externally supplied and it already has a finite Mrf do not change it
+    if (! ((source->mode & PM_SOURCE_MODE_EXTERNAL) && isfinite(source->moments->Mrf))) {
+        source->moments->Mrf = kronRefRadius;
+    }
+
+    return true;
+}
+
+bool pmSourceMomentsKronFluxes (pmSource *source, float sigma, float minSN, psImageMaskType maskVal) {
+
+    float **vPix = source->pixels->data.F32;
+    float **vWgt = source->variance ? source->variance->data.F32 : source->pixels->data.F32;
+    psImageMaskType **vMsk = (source->maskObj == NULL) ? NULL : source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA;
+
+    float radKinner = 1.0*source->moments->Mrf;
+    float radKron   = 2.5*source->moments->Mrf;
+    float radKouter = 4.0*source->moments->Mrf;
 
     int nKronPix = 0;
@@ -341,7 +556,22 @@
     int nInner = 0;
     int nOuter = 0;
-    Sum = Var = 0.0;
+    
+    float Sum = 0.0;
+    float Var = 0.0;
+    float SumCore = 0.0;
+    float VarCore = 0.0;
     float SumInner = 0.0;
     float SumOuter = 0.0;
+
+    // centroid around which to calculate the moments
+    float Xo = source->moments->Mx;
+    float Yo = source->moments->My;
+
+    // center of mass in subimage.  Note: the calculation below uses pixel index, so we correct
+    // xCM, yCM from pixel coords to pixel index here.
+    float xCM = Xo - 0.5 - source->pixels->col0; // coord of peak in subimage
+    float yCM = Yo - 0.5 - source->pixels->row0; // coord of peak in subimage
+
+    float minSN2 = PS_SQR(minSN);
 
     // calculate the Kron flux, and related fluxes (NO symmetrical averaging)
@@ -362,5 +592,5 @@
 	    float r2  = PS_SQR(xDiff) + PS_SQR(yDiff);
 
-	    float fDiff1 = vPix[row][col] - sky;
+	    float fDiff1 = vPix[row][col];
 	    float pDiff = fDiff1;
 	    float wDiff = vWgt[row][col];
@@ -376,5 +606,4 @@
 		Var += wDiff;
 		nKronPix ++;
-		// if (beVerbose) fprintf (stderr, "mome: %d %d  %f  %f  %f\n", col, row, sky, *vPix, Sum);
 	    }
 
@@ -397,10 +626,10 @@
     }
     // *** should I rescale these fluxes by pi R^2 / nNpix?
-    // XXX source->moments->KronCore    = SumCore       * M_PI * PS_SQR(sigma) / nCorePix;
-    // XXX source->moments->KronCoreErr = sqrt(VarCore) * M_PI * PS_SQR(sigma) / nCorePix;
-    // XXX source->moments->KronFlux    = Sum       * M_PI * PS_SQR(radKron) / nKronPix;
-    // XXX source->moments->KronFluxErr = sqrt(Var) * M_PI * PS_SQR(radKron) / nKronPix;
-    // XXX source->moments->KronFinner = SumInner * M_PI * (PS_SQR(radKron)   - PS_SQR(radKinner)) / nInner;
-    // XXX source->moments->KronFouter = SumOuter * M_PI * (PS_SQR(radKouter) -   PS_SQR(radKron)) / nOuter;
+    // XXX source->moments->KronCore    = SumCore       * M_PI *  PS_SQR(sigma) / nCorePix;
+    // XXX source->moments->KronCoreErr = sqrt(VarCore) * M_PI *  PS_SQR(sigma) / nCorePix;
+    // XXX source->moments->KronFlux    = Sum           * M_PI *  PS_SQR(radKron) / nKronPix;
+    // XXX source->moments->KronFluxErr = sqrt(Var)     * M_PI *  PS_SQR(radKron) / nKronPix;
+    // XXX source->moments->KronFinner  = SumInner      * M_PI * (PS_SQR(radKron)   - PS_SQR(radKinner)) / nInner;
+    // XXX source->moments->KronFouter  = SumOuter      * M_PI * (PS_SQR(radKouter) -   PS_SQR(radKron)) / nOuter;
 
     source->moments->KronCore    = SumCore;
@@ -408,6 +637,6 @@
     source->moments->KronFlux    = Sum;
     source->moments->KronFluxErr = sqrt(Var);
-    source->moments->KronFinner = SumInner;
-    source->moments->KronFouter = SumOuter;
+    source->moments->KronFinner  = SumInner;
+    source->moments->KronFouter  = SumOuter;
 
     // XXX not sure I should save this here...
@@ -416,198 +645,4 @@
     source->moments->KronRadiusPSF  = source->moments->Mrf;
 
-    psTrace ("psModules.objects", 4, "Mrf: %f  KronFlux: %f  Mxx: %f  Mxy: %f  Myy: %f  Mxxx: %f  Mxxy: %f  Mxyy: %f  Myyy: %f  Mxxxx: %f  Mxxxy: %f  Mxxyy: %f  Mxyyy: %f  Mxyyy: %f\n",
-	     source->moments->Mrf,   source->moments->KronFlux, 
-	     source->moments->Mxx,   source->moments->Mxy,   source->moments->Myy,
-	     source->moments->Mxxx,  source->moments->Mxxy,  source->moments->Mxyy,  source->moments->Myyy,
-	     source->moments->Mxxxx, source->moments->Mxxxy, source->moments->Mxxyy, source->moments->Mxyyy, source->moments->Myyyy);
-
-    psTrace ("psModules.objects", 3, "peak %f %f (%f = %f) Mx: %f  My: %f  Sum: %f  Mxx: %f  Mxy: %f  Myy: %f  sky: %f  Npix: %d\n",
-	     source->peak->xf, source->peak->yf, source->peak->rawFlux, sqrt(source->peak->detValue), source->moments->Mx,   source->moments->My, Sum, source->moments->Mxx,   source->moments->Mxy,   source->moments->Myy, sky, source->moments->nPixels);
-
-    return(true);
-}
-
-bool pmSourceMomentsGetCentroid(pmSource *source, float radius, float sigma, float minSN, psImageMaskType maskVal, float xGuess, float yGuess) { 
-
-    // First Pass: calculate the first moments (these are subtracted from the coordinates below)
-    // Sum = SUM (z - sky)
-    // X1  = SUM (x - xc)*(z - sky)
-    // .. etc
-
-    float sky = 0.0;
-
-    float peakPixel = -PS_MAX_F32;
-    psS32 numPixels = 0;
-    float Sum = 0.0;
-    float Var = 0.0;
-    float X1 = 0.0;
-    float Y1 = 0.0;
-    float R2 = PS_SQR(radius);
-    float minSN2 = PS_SQR(minSN);
-    float rsigma2 = 0.5 / PS_SQR(sigma);
-
-    float xPeak = xGuess - source->pixels->col0; // coord of peak in subimage
-    float yPeak = yGuess - source->pixels->row0; // coord of peak in subimage
-
-    // we are guaranteed to have a valid pixel and variance at this location (right? right?)
-    // float weightNorm = source->pixels->data.F32[yPeak][xPeak] / sqrt (source->variance->data.F32[yPeak][xPeak]);
-    // psAssert (isfinite(source->pixels->data.F32[yPeak][xPeak]), "peak must be on valid pixel");
-    // psAssert (isfinite(source->variance->data.F32[yPeak][xPeak]), "peak must be on valid pixel");
-    // psAssert (source->variance->data.F32[yPeak][xPeak] > 0, "peak must be on valid pixel");
-
-    // the moments [Sum(x*f) / Sum(f)] are calculated in pixel index values, and should
-    // not depend on the fractional pixel location of the source.  However, the aperture
-    // (radius) and the Gaussian window (sigma) depend subtly on the fractional pixel
-    // position of the expected centroid
-
-    for (psS32 row = 0; row < source->pixels->numRows ; row++) {
-
-	float yDiff = row + 0.5 - yPeak;
-	if (fabs(yDiff) > radius) continue;
-
-	float *vPix = source->pixels->data.F32[row];
-	float *vWgt = source->variance ? source->variance->data.F32[row] : source->pixels->data.F32[row];
-
-	psImageMaskType *vMsk = (source->maskObj == NULL) ? NULL : source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[row];
-	// psImageMaskType *vMsk = (source->maskView == NULL) ? NULL : source->maskView->data.PS_TYPE_IMAGE_MASK_DATA[row];
-
-	for (psS32 col = 0; col < source->pixels->numCols ; col++, vPix++, vWgt++) {
-	    if (vMsk) {
-		if (*vMsk & maskVal) {
-		    vMsk++;
-		    continue;
-		}
-		vMsk++;
-	    }
-	    if (isnan(*vPix)) continue;
-
-	    float xDiff = col + 0.5 - xPeak;
-	    if (fabs(xDiff) > radius) continue;
-
-	    // radius is just a function of (xDiff, yDiff)
-	    float r2  = PS_SQR(xDiff) + PS_SQR(yDiff);
-	    if (r2 > R2) continue;
-
-	    float pDiff = *vPix - sky;
-	    float wDiff = *vWgt;
-
-	    // skip pixels below specified significance level.  for a PSFs, this
-	    // over-weights the wings of bright stars compared to those of faint stars.
-	    // for the estimator used for extended source analysis (where the window
-	    // function is allowed to be arbitrarily large), we need to clip to avoid
-	    // negative second moments.
-	    if (PS_SQR(pDiff) < minSN2*wDiff) continue; // 
-	    if ((minSN > 0.0) && (pDiff < 0)) continue; // 
-
-	    // Apply a Gaussian window function.  Be careful with the window function.  S/N
-	    // weighting over weights the sky for faint sources
-	    if (sigma > 0.0) {
-		float z  = r2*rsigma2;
-		assert (z >= 0.0);
-		float weight  = exp(-z);
-
-		wDiff *= weight;
-		pDiff *= weight;
-	    } 
-
-	    Var += wDiff;
-	    Sum += pDiff;
-
-	    float xWght = xDiff * pDiff;
-	    float yWght = yDiff * pDiff;
-
-	    X1  += xWght;
-	    Y1  += yWght;
-
-	    peakPixel = PS_MAX (*vPix, peakPixel);
-	    numPixels++;
-	}
-    }
-
-    // if we have less than (1/4) of the possible pixels (in circle or box), force a retry
-    int minPixels = PS_MIN(0.75*R2, source->pixels->numCols*source->pixels->numRows/4.0);
-
-    // XXX EAM - the limit is a bit arbitrary.  make it user defined?
-    if ((numPixels < minPixels) || (Sum <= 0)) {
-	psTrace ("psModules.objects", 3, "insufficient valid pixels (%d vs %d; %f) for source\n", numPixels, minPixels, Sum);
-	return (false);
-    }
-
-    // calculate the first moment.
-    float Mx = X1/Sum;
-    float My = Y1/Sum;
-    if ((fabs(Mx) > radius) || (fabs(My) > radius)) {
-	psTrace ("psModules.objects", 3, "extreme centroid swing; invalid peak %d, %d\n", source->peak->x, source->peak->y);
-	return (false);
-    }
-    if ((fabs(Mx) > 2.0) || (fabs(My) > 2.0)) {
-	psTrace ("psModules.objects", 3, " big centroid swing; ok peak? %d, %d\n", source->peak->x, source->peak->y);
-    }
-
-    psTrace ("psModules.objects", 5, "id: %d, sky: %f  Mx: %f  My: %f  Sum: %f  X1: %f  Y1: %f  Npix: %d\n", source->id, sky, Mx, My, Sum, X1, Y1, numPixels);
-
-    // add back offset of peak in primary image
-    // also offset from pixel index to pixel coordinate
-    // (the calculation above uses pixel index instead of coordinate)
-    // 0.5 PIX: moments are calculated using the pixel index and converted here to pixel coords
-
-    // we only update the centroid if the position is not supplied from elsewhere
-    bool skipCentroid = false;
-    skipCentroid |= (source->mode  & PM_SOURCE_MODE_EXTERNAL); // skip externally supplied positions
-    skipCentroid |= (source->mode2 & PM_SOURCE_MODE2_MATCHED); // skip sources defined by other image positions
-
-    if (skipCentroid) {
-	source->moments->Mx = source->peak->xf;
-	source->moments->My = source->peak->yf;
-    } else {
-	source->moments->Mx = Mx + xGuess;
-	source->moments->My = My + yGuess;
-    }
-
-    source->moments->Sum = Sum;
-    source->moments->SN  = Sum / sqrt(Var);
-    source->moments->Peak = peakPixel;
-    source->moments->nPixels = numPixels;
-
     return true;
 }
-
-float pmSourceMinKronRadius(psArray *sources, float PSF_SN_LIM) {
-
-    psVector *radii = psVectorAllocEmpty(100, PS_TYPE_F32);
-
-    for (int i = 0; i < sources->n; i++) {
-	pmSource *src = sources->data[i]; // Source of interest
-	if (!src || !src->moments) {
-	    continue;
-	}
-
-	if (src->mode & PM_SOURCE_MODE_BLEND) {
-	    continue;
-	}
-
-	if (!src->moments->nPixels) continue;
-
-	if (src->moments->SN < PSF_SN_LIM) continue;
-
-	// XXX put in Mxx,Myy cut based on clump location
-
-	psVectorAppend(radii, src->moments->Mrf);
-    }
-
-    // find the peak in this image
-    psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN);
-
-    if (!psVectorStats (stats, radii, NULL, NULL, 0)) {
-	psError(PS_ERR_UNKNOWN, false, "Unable to get image statistics.\n");
-	psFree(stats);
-	return NAN;
-    }
-
-    float minRadius = stats->sampleMedian;
-
-    psFree(radii);
-    psFree(stats);
-    return minRadius;
-}
-
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceOutputs.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceOutputs.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceOutputs.c	(revision 37066)
@@ -26,11 +26,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceFitModel.h"
@@ -107,17 +108,29 @@
 	}
 	if (isfinite(PAR[PM_PAR_SXX]) && isfinite(PAR[PM_PAR_SXY]) && isfinite(PAR[PM_PAR_SYY])) {
-	    axes = pmPSF_ModelToAxes (PAR, model->type);
+	    axes = pmPSF_ModelToAxes (PAR, model->class->useReff);
 	    outputs->psfMajor = axes.major;
 	    outputs->psfMinor = axes.minor;
 	    outputs->psfTheta = axes.theta*PS_DEG_RAD;
+
+	    // some models (PS1_V1, QGAUSS) have an extra 'core' parameter
+	    outputs->psfCore = NAN;
+	    if (model->type == pmModelClassGetType ("PS_MODEL_PS1_V1")) {
+		outputs->psfCore = PAR[PM_PAR_7];
+	    }
+	    if (model->type == pmModelClassGetType ("PS_MODEL_QGAUSS")) {
+		outputs->psfCore = PAR[PM_PAR_7];
+	    }
+
+	    outputs->psfMajorFWHM = model->class->modelSetFWHM(model->params, axes.major);
+	    outputs->psfMinorFWHM = model->class->modelSetFWHM(model->params, axes.minor);
 	} else {
 	    outputs->psfMajor = NAN;
 	    outputs->psfMinor = NAN;
 	    outputs->psfTheta = NAN;
+	    outputs->psfCore = NAN;
 	}
 	outputs->chisq = model->chisq;
 	outputs->nDOF = model->nDOF;
 	outputs->nPix = model->nPix;
-	outputs->apRadius = source->apRadius;
     } else {
 	bool useMoments = pmSourcePositionUseMoments(source);
@@ -137,8 +150,8 @@
 	outputs->psfMinor = NAN;
 	outputs->psfTheta = NAN;
+	outputs->psfCore = NAN;
 	outputs->chisq = NAN;
 	outputs->nDOF = 0;
 	outputs->nPix = 0;
-	outputs->apRadius = NAN;
     }
 
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceOutputs.h
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceOutputs.h	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceOutputs.h	(revision 37066)
@@ -26,6 +26,8 @@
     float psfMinor;
     float psfTheta;
+    float psfCore;
+    float psfMajorFWHM;
+    float psfMinorFWHM;
     float chisq;
-    float apRadius;
     int nPix;
     int nDOF;
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourcePhotometry.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourcePhotometry.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourcePhotometry.c	(revision 37066)
@@ -33,11 +33,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceFitModel.h"
@@ -113,4 +114,12 @@
     source->apFluxErr = NAN;
 
+    pmModelStatus badModel = PM_MODEL_STATUS_NONE;
+    badModel |= PM_MODEL_STATUS_BADARGS;
+    badModel |= PM_MODEL_STATUS_OFFIMAGE;
+    badModel |= PM_MODEL_STATUS_NAN_CHISQ;
+    badModel |= PM_MODEL_SERSIC_PCM_FAIL_GUESS;
+    badModel |= PM_MODEL_SERSIC_PCM_FAIL_GRID;
+    badModel |= PM_MODEL_PCM_FAIL_GUESS;
+
     // XXXXXX review:
     // Select the 'best' model -- this is used for PSF_QF,_PERFECT & ???. isPSF is true if this
@@ -162,5 +171,5 @@
         for (int i = 0; i < source->modelFits->n; i++) {
             pmModel *model = source->modelFits->data[i];
-	    if (model->flags & PM_MODEL_STATUS_BADARGS) continue;
+	    if (model->flags & badModel) continue;
             status = pmSourcePhotometryModel (&model->mag, NULL, model);
             if (model == source->modelEXT) foundEXT = true;
@@ -321,5 +330,5 @@
 
     // measure fitMag
-    flux = model->modelFlux (model->params);
+    flux = model->class->modelFlux (model->params);
     if (flux > 0) {
         mag = -2.5*log10(flux);
@@ -350,6 +359,5 @@
 
     bool status;
-    int nPix = 0;
-    status = pmSourcePhotometryAper(&nPix, &source->apMagRaw, &source->apFlux, &source->apFluxErr, model, image, variance, mask, maskVal);
+    status = pmSourcePhotometryAper(&source->apNpixels, &source->apMagRaw, &source->apFlux, &source->apFluxErr, model, image, variance, mask, maskVal);
     if (status) {
 	source->mode |= PM_SOURCE_MODE_AP_MAGS;
@@ -481,5 +489,5 @@
 
             // for the full model, add all points
-            value = fabs(model->modelFunc (NULL, params, coord) - sky);
+            value = fabs(model->class->modelFunc (NULL, params, coord) - sky);
             modelSum += value;
 
@@ -884,5 +892,5 @@
 
             // for the full model, add all points
-            float value = model->modelFunc (NULL, params, coord);
+            float value = model->class->modelFunc (NULL, params, coord);
 
 	    // fprintf (stderr, "%d, %d : %f, %f : %f - %f : %f\n", 
@@ -899,4 +907,40 @@
 
     psFree (coord);
+    return (true);
+}
+
+bool pmSourceChisqModelFlux (pmSource *source, pmModel *model, psImageMaskType maskVal)
+{
+    PS_ASSERT_PTR_NON_NULL(source, false);
+    PS_ASSERT_PTR_NON_NULL(model, false);
+
+    float dC = 0.0;
+    int Npix = 0;
+
+    psVector *params = model->params;
+    psImage  *image = source->pixels;
+    psImage  *modelFlux = source->modelFlux;
+    psImage  *mask = source->maskObj;
+    psImage  *variance = source->variance;
+
+    float Io = params->data.F32[PM_PAR_I0];
+
+    for (int iy = 0; iy < image->numRows; iy++) {
+        for (int ix = 0; ix < image->numCols; ix++) {
+
+	    // skip pixels which are masked
+            if (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & maskVal) continue;
+
+            if (variance->data.F32[iy][ix] <= 0) continue;
+
+            dC += PS_SQR (image->data.F32[iy][ix] - Io*modelFlux->data.F32[iy][ix]) / variance->data.F32[iy][ix];
+            Npix ++;
+        }
+    }
+    model->nPix = Npix;
+    model->nDOF = Npix - model->nPar;
+    model->chisq = dC;
+    model->chisqNorm = dC / model->nDOF;
+
     return (true);
 }
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourcePlotApResid.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourcePlotApResid.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourcePlotApResid.c	(revision 37066)
@@ -35,11 +35,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceFitModel.h"
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourcePlotMoments.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourcePlotMoments.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourcePlotMoments.c	(revision 37066)
@@ -38,11 +38,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceFitModel.h"
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourcePlotPSFModel.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourcePlotPSFModel.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourcePlotPSFModel.c	(revision 37066)
@@ -39,11 +39,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceFitModel.h"
@@ -146,5 +147,5 @@
         // force the axis ratio to be < 20.0
         psEllipseAxes axes_mnt = psEllipseMomentsToAxes (moments, 20.0);
-        psEllipseAxes axes_psf = pmPSF_ModelToAxes (PAR, model->type);
+        psEllipseAxes axes_psf = pmPSF_ModelToAxes (PAR, model->class->useReff);
 
         // moments major axis
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceSky.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceSky.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceSky.c	(revision 37066)
@@ -34,11 +34,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceUtils.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceUtils.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceUtils.c	(revision 37066)
@@ -34,11 +34,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 
@@ -64,5 +65,5 @@
     pmModel *model = pmModelAlloc(modelType);
 
-    if (!model->modelGuess(model, source, maskVal, markVal)) {
+    if (!model->class->modelGuess(model, source, maskVal, markVal)) {
 	psFree (model);
 	return NULL;
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceVisual.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceVisual.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmSourceVisual.c	(revision 37066)
@@ -16,11 +16,12 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmModelUtils.h"
-#include "pmModelClass.h"
 #include "pmSourceMasks.h"
 #include "pmSourceExtendedPars.h"
 #include "pmSourceDiffStats.h"
 #include "pmSourceSatstar.h"
+#include "pmSourceLensing.h"
 #include "pmSource.h"
 #include "pmSourceFitModel.h"
@@ -544,7 +545,31 @@
     psFree (model);
 
+    bool dumpData = false;
+
     // pause and wait for user input:
     // continue, save (provide name), ??
-    pmVisualAskUser(&plotPSF);
+retry:
+    pmVisualAskUserOrDump(&plotPSF, &dumpData);
+    if (dumpData) {
+      char name[128];
+      fprintf (stderr, "filename: ");
+      int status = fscanf (stdin, "%127s", name);
+      if (status != 1) {
+	fprintf (stderr, "odd response\n");
+	goto retry;
+      }
+
+      FILE *f = fopen (name, "w");
+      if (!f) {
+	fprintf (stderr, "cannot open %s for output\n", name);
+	goto retry;
+      }
+      for (int i = 0; i < x->n; i++) {
+        float vModel = pmTrend2DEval (trend, x->data.F32[i], y->data.F32[i]);
+	fprintf (f, "%f %f %f %f %d\n", x->data.F32[i], y->data.F32[i], param->data.F32[i], vModel, mask->data.PS_TYPE_VECTOR_MASK_DATA[i]);
+      }
+      fclose (f);
+      goto retry;
+    }
 
     return true;
Index: /branches/eam_branches/ipp-ops-20130712/psModules/src/psmodules.h
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/src/psmodules.h	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/src/psmodules.h	(revision 37066)
@@ -95,4 +95,5 @@
 #include <pmAstrometryDistortion.h>
 #include <pmAstrometryVisual.h>
+#include <pmKHcorrect.h>
 
 // the following headers are from psModule:imcombine
@@ -128,5 +129,7 @@
 
 #include <pmModelFuncs.h>
+#include <pmModelClass.h>
 #include <pmModel.h>
+#include <pmModel_CentralPixel.h>
 
 #include <pmSourceMasks.h>
@@ -134,4 +137,5 @@
 #include <pmSourceSatstar.h>
 #include <pmSourceDiffStats.h>
+#include <pmSourceLensing.h>
 #include <pmSource.h>
 #include <pmSourceFitModel.h>
@@ -146,5 +150,4 @@
 #include <pmSourcePlots.h>
 #include <pmPSF_IO.h>
-#include <pmModelClass.h>
 #include <pmModelUtils.h>
 #include <pmSourcePhotometry.h>
Index: /branches/eam_branches/ipp-ops-20130712/psModules/test/objects/Makefile.am
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/test/objects/Makefile.am	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/test/objects/Makefile.am	(revision 37066)
@@ -19,4 +19,6 @@
 	tap_pmModelUtils \
 	tap_pmModelClass \
+	tap_pmModel_CentralPixel \
+	tap_pmModel_CentralPixel_v2 \
 	tap_pmPSF \
 	tap_pmTrend2D \
Index: /branches/eam_branches/ipp-ops-20130712/psModules/test/objects/tap_pmModel_CentralPixel.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/test/objects/tap_pmModel_CentralPixel.c	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/test/objects/tap_pmModel_CentralPixel.c	(revision 37066)
@@ -0,0 +1,202 @@
+#include <stdio.h>
+#include <string.h>
+#include <pslib.h>
+#include <psmodules.h>
+
+#include "tap.h"
+#include "pstap.h"
+
+int main (int argc, char **argv)
+{
+    if (argc != 3) {
+	fprintf (stderr, "USAGE: tap_pmModel_CentralPixel (model) (set)\n");
+	exit (2);
+    }
+
+    int set = atoi(argv[2]);
+
+    psMemId id = psMemGetId();
+
+    plan_tests(240);
+
+    pmModelCP *t0 = pmModelCP_Alloc();
+    ok (t0, "allocated pmModelCP");
+    psFree (t0);
+
+    pmModelCPset *t1 = pmModelCPset_Alloc();
+    ok (t1, "allocated pmModelCPset");
+    psFree (t1);
+    
+    pmModelCPset *cpset = pmModelCP_Load (argv[1]);
+    ok (cpset, "loaded pmModelCPset from file");
+
+    ok (cpset->RmajorNitem ==  4, "correct number of Rmajor values");
+    ok (cpset->AratioNitem ==  7, "correct number of Aratio values");
+    ok (cpset->SindexNitem == 10, "correct number of Sindex values");
+    ok (cpset->images->n == 280, "correct number of CP images");
+
+    pmModelCP *cp = NULL;
+    
+    if (1) {
+	cp = pmModelCP_GetImage (cpset, 0.0, 1.0, 1.0);
+	ok (cp, "returned a cp image");
+	if (cp) {
+	    ok_float_tol (cp->Rmajor, 0.0, 0.001, "got image with correct Rmajor");
+	    ok_float_tol (cp->Aratio, 1.0, 0.001, "got image with correct Aratio");
+	    ok_float_tol (cp->Sindex, 1.0, 0.001, "got image with correct Sindex");
+	}
+
+	cp = pmModelCP_GetImage (cpset, 1.0, 1.0, 1.0);
+	ok (cp, "returned a cp image");
+	if (cp) {
+	    ok_float_tol (cp->Rmajor, 1.0, 0.001, "got image with correct Rmajor");
+	    ok_float_tol (cp->Aratio, 1.0, 0.001, "got image with correct Aratio");
+	    ok_float_tol (cp->Sindex, 1.0, 0.001, "got image with correct Sindex");
+	}
+    
+	cp = pmModelCP_GetImage (cpset, 0.0, 0.4, 1.0);
+	ok (cp, "returned a cp image");
+	if (cp) {
+	    ok_float_tol (cp->Rmajor, 0.0, 0.001, "got image with correct Rmajor");
+	    ok_float_tol (cp->Aratio, 0.4, 0.001, "got image with correct Aratio");
+	    ok_float_tol (cp->Sindex, 1.0, 0.001, "got image with correct Sindex");
+	}
+    
+	cp = pmModelCP_GetImage (cpset, 0.0, 0.4, 3.5);
+	ok (cp, "returned a cp image");
+	if (cp) {
+	    ok_float_tol (cp->Rmajor, 0.0, 0.001, "got image with correct Rmajor");
+	    ok_float_tol (cp->Aratio, 0.4, 0.001, "got image with correct Aratio");
+	    ok_float_tol (cp->Sindex, 3.5, 0.001, "got image with correct Sindex");
+	}
+    }
+    
+    float valuePixel = NAN;
+    float valueModel = NAN;
+
+    switch (set) {
+      case 0:
+	cp = pmModelCP_GetImage (cpset, 1.0, 1.0, 1.0);
+	valuePixel = pmModelCP_GetFlux (cp, 0.0, 0.0, 0.0);
+	valueModel = pmModelCP_FullSersic (0.0, 0.0, 0.0, pow(10.0, cp->Rmajor), cp->Aratio, cp->Sindex);
+	fprintf (stdout, "%f / %f = %f\n", valuePixel, valueModel, valuePixel / valueModel);
+	break;
+
+      case 1:
+	for (int i = 0; i < cpset->images->n; i++) {
+	    cp = cpset->images->data[i];
+	    valuePixel = pmModelCP_GetFlux (cp, 0.0, 0.0, 0.0);
+	    valueModel = pmModelCP_FullSersic (0.0, 0.0, 0.0, pow(10.0, cp->Rmajor), cp->Aratio, cp->Sindex);
+	    fprintf (stdout, "%f / %f = %f | %f  %f  %f\n", valuePixel, valueModel, valuePixel / valueModel, pow(10.0, cp->Rmajor), cp->Aratio, cp->Sindex);
+	}
+	break;
+
+      case 2:
+	for (int i = 0; i < cpset->images->n; i++) {
+	    cp = cpset->images->data[i];
+	    valuePixel = pmModelCP_GetFlux (cp, 0.0, 0.0, 30.0);
+	    valueModel = pmModelCP_FullSersic (0.0, 0.0, 30.0, pow(10.0, cp->Rmajor), cp->Aratio, cp->Sindex);
+	    fprintf (stdout, "%f / %f = %f | %f  %f  %f\n", valuePixel, valueModel, valuePixel / valueModel, pow(10.0, cp->Rmajor), cp->Aratio, cp->Sindex);
+	}
+	break;
+
+      case 3:
+	for (int i = 0; i < cpset->images->n; i++) {
+	    cp = cpset->images->data[i];
+	    valuePixel = pmModelCP_GetFlux (cp, 0.0, 0.5, 0.0);
+	    valueModel = pmModelCP_FullSersic (0.0, 0.5, 0.0, pow(10.0, cp->Rmajor), cp->Aratio, cp->Sindex);
+	    fprintf (stdout, "%f / %f = %f | %f  %f  %f\n", valuePixel, valueModel, valuePixel / valueModel, pow(10.0, cp->Rmajor), cp->Aratio, cp->Sindex);
+	}
+	break;
+
+      case 4:
+	for (int i = 0; i < cpset->images->n; i++) {
+	    cp = cpset->images->data[i];
+	    valuePixel = pmModelCP_GetFlux (cp, 0.5, 0.5, 0.0);
+	    valueModel = pmModelCP_FullSersic (0.5, 0.5, 0.0, pow(10.0, cp->Rmajor), cp->Aratio, cp->Sindex);
+	    fprintf (stdout, "%f / %f = %f | %f  %f  %f\n", valuePixel, valueModel, valuePixel / valueModel, pow(10.0, cp->Rmajor), cp->Aratio, cp->Sindex);
+	}
+	break;
+
+      case 5:
+	for (int i = 0; i < cpset->images->n; i++) {
+	    cp = cpset->images->data[i];
+	    valuePixel = pmModelCP_GetFlux (cp, -0.5, 0.5, 30.0);
+	    valueModel = pmModelCP_FullSersic (-0.5, 0.5, 30.0, pow(10.0, cp->Rmajor), cp->Aratio, cp->Sindex);
+	    fprintf (stdout, "%f / %f = %f | %f  %f  %f\n", valuePixel, valueModel, valuePixel / valueModel, pow(10.0, cp->Rmajor), cp->Aratio, cp->Sindex);
+	}
+	break;
+
+      case 6:
+	for (int i = 0; i < cpset->images->n; i++) {
+	    cp = cpset->images->data[i];
+	    valuePixel = pmModelCP_GetFlux (cp, 0.0, -0.5, 0.0);
+	    valueModel = pmModelCP_FullSersic (0.0, -0.5, 0.0, pow(10.0, cp->Rmajor), cp->Aratio, cp->Sindex);
+	    fprintf (stdout, "%f / %f = %f | %f  %f  %f\n", valuePixel, valueModel, valuePixel / valueModel, pow(10.0, cp->Rmajor), cp->Aratio, cp->Sindex);
+	}
+	break;
+
+      case 7:
+	cp = cpset->images->data[224];
+	float delta = 1.0 / 11.0;
+	float offset = -10*delta;
+	for (float dx = offset; dx <= 1.0; dx += delta) {
+	    valuePixel = pmModelCP_GetFlux (cp, dx, 0.0, 0.0);
+	    valueModel = pmModelCP_FullSersic (dx, 0.0, 0.0, pow(10.0, cp->Rmajor), cp->Aratio, cp->Sindex);
+	    fprintf (stdout, "%f / %f = %f | %f  %f  %f\n", valuePixel, valueModel, valuePixel / valueModel, pow(10.0, cp->Rmajor), cp->Aratio, cp->Sindex);
+	}
+	break;
+
+      case 8:
+	cp = cpset->images->data[224];
+	valuePixel = pmModelCP_GetFlux (cp, 0.0, 0.0, 45.0);
+	valueModel = pmModelCP_FullSersic (0.0, 0.0, 45.0, pow(10.0, cp->Rmajor), cp->Aratio, cp->Sindex);
+	fprintf (stdout, "%f / %f = %f | %f  %f  %f\n", valuePixel, valueModel, valuePixel / valueModel, pow(10.0, cp->Rmajor), cp->Aratio, cp->Sindex);
+	break;
+
+      case 9:
+	for (int i = 0; i < cpset->images->n; i++) {
+	    cp = cpset->images->data[i];
+	    valuePixel = pmModelCP_GetFlux (cp, -0.5, -0.5, 0.0);
+	    valueModel = pmModelCP_FullSersic (-0.5, -0.5, 0.0, pow(10.0, cp->Rmajor), cp->Aratio, cp->Sindex);
+	    fprintf (stdout, "%f / %f = %f | %f  %f  %f\n", valuePixel, valueModel, valuePixel / valueModel, pow(10.0, cp->Rmajor), cp->Aratio, cp->Sindex);
+	}
+	break;
+      case 10:
+	for (int i = 0; i < cpset->images->n; i++) {
+	    cp = cpset->images->data[i];
+	    valuePixel = pmModelCP_GetFlux (cp, 0.5, 0.0, 0.0);
+	    valueModel = pmModelCP_FullSersic (0.5, 0.0, 0.0, pow(10.0, cp->Rmajor), cp->Aratio, cp->Sindex);
+	    fprintf (stdout, "%f / %f = %f | %f  %f  %f\n", valuePixel, valueModel, valuePixel / valueModel, pow(10.0, cp->Rmajor), cp->Aratio, cp->Sindex);
+	}
+	break;
+
+      case 11:
+	for (int i = 0; i < cpset->images->n; i++) {
+	    cp = cpset->images->data[i];
+	    valuePixel = pmModelCP_GetFlux (cp, -0.5, 0.0, 0.0);
+	    valueModel = pmModelCP_FullSersic (-0.5, 0.0, 0.0, pow(10.0, cp->Rmajor), cp->Aratio, cp->Sindex);
+	    fprintf (stdout, "%f / %f = %f | %f  %f  %f\n", valuePixel, valueModel, valuePixel / valueModel, pow(10.0, cp->Rmajor), cp->Aratio, cp->Sindex);
+	}
+	break;
+      case 12:
+	psTimerStart ("test");
+	for (int i = 0; i < cpset->images->n; i++) {
+	    cp = cpset->images->data[i];
+	    valuePixel = pmModelCP_GetFlux (cp, 0.0, 0.0, 0.0);
+	}
+	fprintf (stderr, "CP code: %f\n", psTimerMark ("test"));
+	psTimerStart ("test");
+	for (int i = 0; i < cpset->images->n; i++) {
+	    cp = cpset->images->data[i];
+	    valueModel = pmModelCP_FullSersic (0.0, 0.0, 0.0, pow(10.0, cp->Rmajor), cp->Aratio, cp->Sindex);
+	}
+	fprintf (stderr, "Full code: %f\n", psTimerMark ("test"));
+	break;
+    }
+
+    psFree (cpset);
+    ok(!psMemCheckLeaks (id, NULL, stderr, false), "no memory leaks");
+
+    return exit_status();
+}
Index: /branches/eam_branches/ipp-ops-20130712/psModules/test/objects/tap_pmModel_CentralPixel_v2.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psModules/test/objects/tap_pmModel_CentralPixel_v2.c	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/psModules/test/objects/tap_pmModel_CentralPixel_v2.c	(revision 37066)
@@ -0,0 +1,52 @@
+#include <stdio.h>
+#include <string.h>
+#include <pslib.h>
+#include <psmodules.h>
+
+#include "tap.h"
+#include "pstap.h"
+
+int main (int argc, char **argv)
+{
+    if (argc != 8) {
+	fprintf (stderr, "USAGE: tap_pmModel_CentralPixel (model) (dx) (dy) (theta) (Reff) (Arat) (Sidx)\n");
+	exit (2);
+    }
+
+    float dx = atof(argv[2]);
+    float dy = atof(argv[3]);
+    float theta = atof(argv[4]);
+
+    float Reff = atof(argv[5]);
+    float Arat = atof(argv[6]);
+    float Sidx = atof(argv[7]);
+
+    psMemId id = psMemGetId();
+
+    plan_tests(6);
+
+    pmModelCPset *cpset = pmModelCP_Load (argv[1]);
+    ok (cpset, "loaded pmModelCPset from file");
+
+    ok (cpset->RmajorNitem ==  4, "correct number of Rmajor values");
+    ok (cpset->AratioNitem ==  7, "correct number of Aratio values");
+    ok (cpset->SindexNitem == 10, "correct number of Sindex values");
+    ok (cpset->images->n == 280, "correct number of CP images");
+
+    pmModelCP *cp = NULL;
+    
+    float valuePixel = NAN;
+    float valueModel = NAN;
+
+    cp = pmModelCP_GetImage (cpset, log10(Reff), Arat, Sidx);
+    valuePixel = pmModelCP_GetFlux (cp, dx, dy, theta);
+    valueModel = pmModelCP_FullSersic (dx, dy, theta, Reff, Arat, Sidx);
+    fprintf (stdout, "%f / %f = %f\n", valuePixel, valueModel, valuePixel / valueModel);
+
+    fprintf (stdout, "%f, %f, %f\n", cp->Rmajor, cp->Aratio, cp->Sindex);
+
+    psFree (cpset);
+    ok(!psMemCheckLeaks (id, NULL, stderr, false), "no memory leaks");
+
+    return exit_status();
+}
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/Makefile.am
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/Makefile.am	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/Makefile.am	(revision 37066)
@@ -25,5 +25,5 @@
 libpsphot_la_LDFLAGS = $(PSPHOT_LIBS) $(PSMODULE_LIBS) $(PSLIB_LIBS)
 
-bin_PROGRAMS = psphot psphotForced psphotMinimal psphotMakePSF psphotStack psphotModelTest
+bin_PROGRAMS = psphot psphotForced psphotFullForce psphotFullForceSummary psphotMinimal psphotMakePSF psphotStack psphotModelTest psmakecff
 # bin_PROGRAMS = psphotPetrosianStudy psphotTest psphotMomentsStudy 
 
@@ -36,4 +36,12 @@
 psphotForced_LDADD = libpsphot.la
 
+psphotFullForce_CFLAGS = $(PSPHOT_CFLAGS) $(PSMODULE_CFLAGS) $(PSLIB_CFLAGS)
+psphotFullForce_LDFLAGS = $(PSPHOT_LIBS) $(PSMODULE_LIBS) $(PSLIB_LIBS)
+psphotFullForce_LDADD = libpsphot.la
+
+psphotFullForceSummary_CFLAGS = $(PSPHOT_CFLAGS) $(PSMODULE_CFLAGS) $(PSLIB_CFLAGS)
+psphotFullForceSummary_LDFLAGS = $(PSPHOT_LIBS) $(PSMODULE_LIBS) $(PSLIB_LIBS)
+psphotFullForceSummary_LDADD = libpsphot.la
+
 psphotMinimal_CFLAGS = $(PSPHOT_CFLAGS) $(PSMODULE_CFLAGS) $(PSLIB_CFLAGS)
 psphotMinimal_LDFLAGS = $(PSPHOT_LIBS) $(PSMODULE_LIBS) $(PSLIB_LIBS)
@@ -51,4 +59,9 @@
 psphotModelTest_LDFLAGS = $(PSPHOT_LIBS) $(PSMODULE_LIBS) $(PSLIB_LIBS)
 psphotModelTest_LDADD = libpsphot.la
+
+psmakecff_CFLAGS = $(PSPHOT_CFLAGS) $(PSMODULE_CFLAGS) $(PSLIB_CFLAGS)
+psmakecff_LDFLAGS = $(PSPHOT_LIBS) $(PSMODULE_LIBS) $(PSLIB_LIBS)
+psmakecff_LDADD = libpsphot.la
+
 
 # psphotMomentsStudy_CFLAGS = $(PSPHOT_CFLAGS) $(PSMODULE_CFLAGS) $(PSLIB_CFLAGS)
@@ -81,4 +94,18 @@
 	psphotMosaicChip.c	   \
 	psphotCleanup.c
+
+# generalized forced photometry (including Kron, Petro, and Models) of specified positions given a specified psf
+psphotFullForce_SOURCES = \
+        psphotFullForce.c             \
+	psphotFullForceArguments.c    \
+	psphotParseCamera.c        \
+	psphotImageLoop.c	   \
+	psphotMosaicChip.c	   \
+	psphotCleanup.c
+
+# combine full force results from several inputs
+psphotFullForceSummary_SOURCES = \
+        psphotFullForceSummary.c \
+        psphotFullForceSummaryReadout.c
 
 # forced photometry of specified positions given a specified psf
@@ -129,4 +156,8 @@
 	psphotCleanup.c
 
+# a program that takes a cmf file and makes a cff file (input file for psphotFullForce
+psmakecff_SOURCES = \
+	psmakecff.c
+
 # psphotTest_SOURCES = \
 #         psphotTest.c
@@ -155,4 +186,6 @@
 	psphotReadoutMinimal.c	       \
 	psphotForcedReadout.c	       \
+	psphotFullForceReadout.c       \
+	psphotFullForce.SourceStats.c \
 	psphotMakePSFReadout.c	       \
 	psphotModelBackground.c	       \
@@ -175,4 +208,5 @@
 	psphotMakeGrowthCurve.c	       \
 	psphotMagnitudes.c	       \
+	psphotLensing.c	       \
 	psphotSetMaskBits.c	       \
 	psphotSkyReplace.c	       \
@@ -181,4 +215,5 @@
 	psphotSourceFits.c	       \
 	psphotRadiusChecks.c	       \
+	psphotChooseAnalysisOptions.c  \
 	psphotOutput.c		       \
 	psphotFakeSources.c	       \
@@ -198,4 +233,7 @@
 	psphotRadialPlot.c	       \
 	psphotKronIterate.c            \
+	psphotKronFlux.c            \
+	psphotPetroFlux.c            \
+	psphotGalaxyShape.c            \
 	psphotRadialProfileWings.c     \
 	psphotDeblendSatstars.c	       \
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psmakecff.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psmakecff.c	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psmakecff.c	(revision 37066)
@@ -0,0 +1,163 @@
+# ifdef HAVE_CONFIG_H
+# include <config.h>
+# endif
+
+// psmakecff : A program to make read a cmf file and write a cff file
+// The real work is done in psModules.
+
+#include <stdio.h>
+#include <pslib.h>
+#include <psmodules.h>
+#include "psphot.h"
+
+// For simplicilty, this program's (simple) functions are all contained in this file.
+static pmConfig* psmakecffArguments(int, char**);
+static bool psmakecffParseCamera(pmConfig *);
+static bool psmakecffImageLoop(pmConfig*);
+
+int main (int argc, char **argv) {
+
+    psMemInit();
+    psTimerStart ("complete");
+    pmErrorRegister();                  // register psModule's error codes/messages
+    psphotInit();
+
+    // load command-line arguments, options, and system config data
+    pmConfig *config = psmakecffArguments (argc, argv);
+    assert(config);
+
+//    psphotVersionPrint();
+
+    if (!psmakecffParseCamera (config)) {
+        psErrorStackPrint(stderr, "Error setting up the camera\n");
+        exit (1);
+    }
+
+    if (!psmakecffImageLoop (config)) {
+        psErrorStackPrint(stderr, "Error in the psphot image loop\n");
+        exit(1);
+    }
+
+    exit (0);
+}
+
+// all functions which return to this level must raise one of the top-level error codes if they
+// exit with an error.  these error codes are used to specify the program exit status
+
+void usage() {
+    fprintf(stderr, "usage: psmakecff -sources <input cmf> <output>\n");
+    exit (1);
+}
+
+static pmConfig* psmakecffArguments(int argc, char **argv) {
+
+    pmConfig *config =  pmConfigRead(&argc, argv, PSPHOT_RECIPE);
+    int N;
+
+    if (config == NULL) {
+      psErrorStackPrint(stderr, "Can't read site configuration");
+	exit(PS_EXIT_CONFIG_ERROR);
+    }
+    if ((N = psArgumentGet (argc, argv, "-sources"))) {
+        pmConfigFileSetsMD(config->arguments, &argc, argv, "SOURCES", "-sources", "-sourceslist");
+    } else {
+        usage();
+    }
+    if (argc < 2) {
+        usage();
+    }
+    psMetadataAddStr(config->arguments, PS_LIST_TAIL, "OUTPUT", PS_DATA_STRING, "", argv[1]);
+
+    return config;
+}
+
+static bool psmakecffParseCamera(pmConfig *config) {
+    bool status = false;
+
+    pmFPAfile *sources = pmFPAfileDefineFromArgs(&status, config, "PSPHOT.INPUT.CMF", "SOURCES");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to build FPA from sources file");
+        return false;
+    }
+
+    pmFPAfile *output = pmFPAfileDefineOutputFromFile (config, sources, "PSPHOT.OUTPUT.CFF");
+    if (!output) {
+        psError(PS_ERR_UNKNOWN, false, "failed to build output FPA");
+        return false;
+    }
+    output->save = true;
+
+    return true;
+}
+
+# define ESCAPE(MESSAGE) {				\
+	psError(PSPHOT_ERR_DATA, false, MESSAGE);	        \
+	psFree (view);					\
+	return false;					\
+    }
+
+bool psmakecffImageLoop (pmConfig *config) {
+
+    bool status;
+    pmChip *chip;
+    pmCell *cell;
+    pmReadout *readout;
+
+    pmFPAfile *input = psMetadataLookupPtr (&status, config->files, "PSPHOT.INPUT.CMF");
+    if (!status) {
+        psError(PSPHOT_ERR_PROG, false, "Can't find input data!");
+        return false;
+    }
+
+    pmFPAfile *output = psMetadataLookupPtr (&status, config->files, "PSPHOT.OUTPUT.CFF");
+    if (!output) {
+        psError(PSPHOT_ERR_PROG, false, "Can't find output data!");
+        return false;
+    }
+
+    pmFPAview *view = pmFPAviewAlloc (0);
+    pmHDU *lastHDU = NULL;              // Last HDU updated
+
+    // files associated with the science image
+    if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE ("failed input for fpa in psphot.");
+
+    // select the appropriate recipe information
+    psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE);
+    psAssert (recipe, "missing recipe?");
+
+
+    // for psphot, we force data to be read at the chip level
+    while ((chip = pmFPAviewNextChip (view, input->fpa, 1)) != NULL) {
+        psLogMsg ("psmakecff", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
+        if (! chip->process || ! chip->file_exists) { continue; }
+
+        if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE ("failed input for Chip in psmakecff.");
+
+        // there is now only a single chip (multiple readouts?). loop over it and process
+        while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) {
+            psLogMsg ("psmakecff", 5, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
+
+            // process each of the readouts
+            while ((readout = pmFPAviewNextReadout (view, input->fpa, 1)) != NULL) {
+                psLogMsg ("psmakecff", 6, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
+                if (! readout->data_exists) { continue; }
+
+		pmHDU *hdu = pmHDUGetHighest(input->fpa, chip, cell);
+		if (hdu && hdu != lastHDU) {
+                    // XXX: probably should do this
+		    // psphotVersionHeaderFull(hdu->header);
+		    lastHDU = hdu;
+                }
+            }
+
+        }
+        if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE ("failed pmFPAfileIOChecks for Chip in psmakecff.");
+    }
+    if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE ("failed pmFPAfileIOChecks for FPA in psphot.");
+
+    // fail if we encountered an unhandled error
+    if (psErrorCodeLast() != PS_ERR_NONE) psAbort ("failed to handle an error!");
+
+    psFree (view);
+    return true;
+}
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphot.h
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphot.h	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphot.h	(revision 37066)
@@ -18,4 +18,5 @@
     PSPHOT_SINGLE,
     PSPHOT_FORCED,
+    PSPHOT_FULL_FORCE,
     PSPHOT_MAKE_PSF,
     PSPHOT_MODEL_TEST,
@@ -81,4 +82,7 @@
 bool            psphotSourceStatsReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe, bool setWindow);
 
+bool            psphotFullForceSourceStats (pmConfig *config, const pmFPAview *view, const char *filerule, bool setWindow);
+bool            psphotFullForceSourceStatsReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe, bool setWindow);
+
 bool            psphotDeblendSatstars (pmConfig *config, const pmFPAview *view, const char *filerule);
 bool            psphotDeblendSatstarsReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe);
@@ -122,4 +126,8 @@
 bool            psphotAddOrSubNoise_Threaded (psThreadJob *job);
 
+bool            psphotChooseAnalysisOptions (pmConfig *config, const pmFPAview *view, const char *filerule);
+bool            psphotChooseAnalysisOptionsReadout(pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe);
+bool            psphotChooseAnalysisOptionsByObject(pmConfig *config, const pmFPAview *view, const char *filerule, psArray *objects);
+
 bool            psphotExtendedSourceAnalysis (pmConfig *config, const pmFPAview *view, const char *filerule);
 bool            psphotExtendedSourceAnalysisReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe);
@@ -136,4 +144,8 @@
 bool            psphotMagnitudesReadout(pmConfig *config, psMetadata *recipe, const pmFPAview *view, pmReadout *readout, psArray *sources, pmPSF *psf);
 bool            psphotMagnitudes_Threaded (psThreadJob *job);
+
+bool            psphotLensing (pmConfig *config, const pmFPAview *view, const char *filerule);
+bool            psphotLensingReadout(pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe);
+bool            psphotLensingPSFtrendsReadout(pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe);
 
 bool            psphotEfficiency (pmConfig *config, const pmFPAview *view, const char *filerule);
@@ -341,4 +353,7 @@
 bool psphotForcedReadout(pmConfig *config, const pmFPAview *view, const char *filerule);
 
+pmConfig *psphotFullForceArguments(int argc, char **argv);
+bool psphotFullForceReadout(pmConfig *config, const pmFPAview *view, const char *filerule);
+
 pmConfig *psphotMinimalArguments(int argc, char **argv);
 bool psphotReadoutMinimal(pmConfig *config, const pmFPAview *view, const char *filerule);
@@ -349,4 +364,6 @@
 pmConfig *psphotModelTestArguments(int argc, char **argv);
 bool psphotModelTestReadout(pmConfig *config, const pmFPAview *view, const char *filerule);
+
+bool psphotFullForceSummaryReadout (pmConfig * config, const pmFPAview *view);
 
 int psphotFileruleCount(const pmConfig *config, const char *filerule);
@@ -414,4 +431,11 @@
 } psphotStackOptions;
 
+typedef struct {
+    float   Q;
+    float   NSigma;
+    float   clampSN;
+    int     extModelType;
+} psphotGalaxyShapeOptions;
+
 /*** psphotStackMatchPSF prototypes ***/
 bool psphotStackMatchPSFs (pmConfig *config, const pmFPAview *view);
@@ -475,5 +499,5 @@
 bool psphotSourceChildren (pmConfig *config, const pmFPAview *view, const char *ruleOut, const char *ruleSrc);
 bool psphotSourceChildrenReadout (pmConfig *config, const pmFPAview *view, const char *ruleOut, const char *ruleSrc, int index);
-psArray *psphotSourceChildrenByObject (pmConfig *config, const pmFPAview *view, const char *filerule, psArray *objectsSrc);
+psArray *psphotSourceChildrenByObject (pmConfig *config, const pmFPAview *view, const char *filerule, psArray *objectsSrc, bool sourcesSubtracted);
 
 bool psphotSourceParents (pmConfig *config, const pmFPAview *view, const char *ruleOut, const char *ruleSrc);
@@ -496,4 +520,22 @@
 bool psphotKronIterateReadout(pmConfig *config, psMetadata *recipe, const pmFPAview *view, const char * filerule, pmReadout *readout, psArray *sources, pmPSF *psf, int index, int pass);
 bool psphotKronIterate_Threaded (psThreadJob *job);
+
+bool psphotKronFlux (pmConfig *config, const pmFPAview *view, const char *filerule);
+bool psphotKronFluxReadout(pmConfig *config, psMetadata *recipe, const pmFPAview *view, const char *filerule, pmReadout *readout, psArray *sources);
+bool psphotKronFlux_Threaded (psThreadJob *job);
+bool psphotKronFluxSource (pmSource *source, psImageMaskType maskVal);
+
+bool psphotPetroFlux (pmConfig *config, const pmFPAview *view, const char *filerule);
+bool psphotPetroFluxReadout(pmConfig *config, psMetadata *recipe, const pmFPAview *view, const char * filerule, pmReadout *readout, psArray *sources);
+bool psphotPetroFlux_Threaded (psThreadJob *job);
+bool psphotPetroFluxSource (pmSource *source, psImageMaskType maskVal);
+
+bool psphotGalaxyShape (pmConfig *config, const pmFPAview *view, const char *filerule);
+bool psphotGalaxyShapeReadout(pmConfig *config, psMetadata *recipe, const pmFPAview *view, const char * filerule, pmReadout *readout, psArray *sources, pmPSF *psf);
+bool psphotGalaxyShape_Threaded (psThreadJob *job);
+bool psphotGalaxyShapeGrid (pmSource *source, pmSourceFitOptions *fitOptions, psphotGalaxyShapeOptions *opt, psImageMaskType maskVal, int psfSize);
+bool psphotGalaxyShapeSource (pmPCMdata *pcm, pmSource *source, pmSourceGalaxyFits *galaxyFits, psImageMaskType maskVal, int psfSize, bool saveResults);
+psphotGalaxyShapeOptions *psphotGalaxyShapeOptionsAlloc();
+bool psphotGalaxyShapeOptionsSet(pmSource *source, pmSourceGalaxyFits *galaxyFits, psphotGalaxyShapeOptions *defaultOptions);
 
 bool psphotRadialProfileWings (pmConfig *config, const pmFPAview *view, const char *filerule);
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotApResid.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotApResid.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotApResid.c	(revision 37066)
@@ -214,5 +214,5 @@
 
         // XXX make this user-configurable?
-        if (source->psfMagErr > 0.01) continue;
+        if (source->psfMagErr > 0.03) continue;
 
         // aperture residual for this source
@@ -267,10 +267,11 @@
 
     // set the max order (0 = constant) which the number of psf stars can support:
-    // rule of thumb: require 3 stars per 'cell' (order+1)^2
+    // we require only 3 stars for n = 0, increase stars / cell for higher order
     int MaxOrderForStars = 0;
-    if (Npsf >= 12) MaxOrderForStars = 1; // 4 cells
-    if (Npsf >= 27) MaxOrderForStars = 2; // 9 cells
-    if (Npsf >= 48) MaxOrderForStars = 3; // 16 cells
-    if (Npsf >  75) MaxOrderForStars = 4; // 25 cells
+    if (Npsf >=  16) MaxOrderForStars = 1; // 4 cells
+    if (Npsf >=  54) MaxOrderForStars = 2; // 9 cells
+    if (Npsf >= 128) MaxOrderForStars = 3; // 16 cells
+    if (Npsf >= 300) MaxOrderForStars = 4; // 25 cells
+    if (Npsf >  576) MaxOrderForStars = 5; // 36 cells
 
     pmTrend2DMode mode = PM_TREND_MAP;
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotArguments.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotArguments.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotArguments.c	(revision 37066)
@@ -217,4 +217,5 @@
     pmConfigFileSetsMD (config->arguments, &argc, argv, "PSPHOT.PSF", "-psf",      "-psflist");
     pmConfigFileSetsMD (config->arguments, &argc, argv, "SRC",        "-src",      "-srclist");
+    // XXX allow this format? pmConfigFileSetsMD (config->arguments, &argc, argv, "FORCE",      "-force",    "-forcelist");
     pmConfigFileSetsMD (config->arguments, &argc, argv, "EXPNUM",     "-expnum",   "-expnumlist");
 
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotBlendFit.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotBlendFit.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotBlendFit.c	(revision 37066)
@@ -273,9 +273,10 @@
         pmSource *source = sources->data[i];
 
-	int TEST_ON = false;
-# if (0)
+# if (PS_TRACE_ON)
 # define TEST_X 653
 # define TEST_Y 466
-	if ((fabs(source->peak->xf - TEST_X) < 5) && (fabs(source->peak->yf - TEST_Y) < 5)) {
+# define TESTING 1
+	int TEST_ON = false;
+	if (TESTING && (fabs(source->peak->xf - TEST_X) < 5) && (fabs(source->peak->yf - TEST_Y) < 5)) {
 	    fprintf (stderr, "test object\n");
 	    psTraceSetLevel("psLib.math.psMinimizeLMChi2", 5);
@@ -342,7 +343,9 @@
         if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) {
             if (psphotFitBlob (readout, source, newSources, psf, fitOptions, maskVal, markVal)) {
+# if (PS_TRACE_ON)
 		if (TEST_ON) {
 		    psTraceSetLevel("psLib.math.psMinimizeLMChi2", 0);
 		}
+# endif
                 psTrace ("psphot", 5, "source at %7.1f, %7.1f is ext", source->peak->xf, source->peak->yf);
                 Next ++;
@@ -351,7 +354,9 @@
         } else {
             if (psphotFitBlend (readout, source, psf, fitOptions, maskVal, markVal)) {
+# if (PS_TRACE_ON)
 		if (TEST_ON) {
 		    psTraceSetLevel("psLib.math.psMinimizeLMChi2", 0);
 		}
+# endif
                 source->type = PM_SOURCE_TYPE_STAR;
                 psTrace ("psphot", 5, "source at %7.1f, %7.1f is psf", source->peak->xf, source->peak->yf);
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotChooseAnalysisOptions.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotChooseAnalysisOptions.c	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotChooseAnalysisOptions.c	(revision 37066)
@@ -0,0 +1,647 @@
+# include "psphotInternal.h"
+
+// choose which sources will be processed for the petrosian radii and/or galaxy/trail model fits
+// a source for which we want galaxy models or petrosians gets 
+
+// currently we also skip the following items (regardless of recipe values):
+// TYPE_DEFECT, TYPE_SATURATED, MODE_DEFECT, MODE_SATSTAR, SATSTAR_PROFILE 
+
+// RULES:
+// * global override:
+// ** PSPHOT.EXT.FIT.ALL.SOURCES
+// ** PSPHOT.EXT.FIT.ALL.THRESH (density limit)
+
+// * select by Star/Galaxy?
+// ** PSPHOT.EXT.NSIGMA.LIMIT (sets EXT_LIMIT bit -- star or galaxy)
+// -- PSPHOT.FIT.EXT_LIMIT (bool : ignore or not EXT_LIMIT) 
+
+// * select by S/N?
+// ** EXTENDED_SOURCE_MODELS : SNLIM (per model value)
+
+// * select by Flux?
+// * needs to depend on the filter
+// * define a metadata block 
+// -- EXT.ANALYSIS.MAG.LIMITS (metadata block per filter)
+
+// * select by galactic latitude (global override)?
+// * if (|b| > LIM) do not limit the number of sources by density 
+// -- GLAT_MAX
+
+// * de-select by density (global override)?
+// ??
+
+// for which sources do we want to run the extended source analysis (petrosian and/or galaxy fits)?
+bool psphotChooseAnalysisOptions (pmConfig *config, const pmFPAview *view, const char *filerule)
+{
+    bool status = true;
+
+    fprintf (stdout, "\n");
+    psLogMsg ("psphot", PS_LOG_INFO, "--- psphot Choose Analysis Options ---");
+
+    // select the appropriate recipe information
+    psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE);
+    psAssert (recipe, "missing recipe?");
+
+    int num = psphotFileruleCount(config, filerule);
+
+    // skip the chisq image (optionally?)
+    int chisqNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.CHISQ.NUM");
+    if (!status) chisqNum = -1;
+
+    // loop over the available readouts
+    for (int i = 0; i < num; i++) {
+        if (i == chisqNum) continue; // skip chisq image
+        if (!psphotChooseAnalysisOptionsReadout (config, view, filerule, i, recipe)) {
+	    psError (PSPHOT_ERR_CONFIG, false, "failed on source size analysis for %s entry %d", filerule, i);
+            return false;
+        }
+    }
+    return true;
+}
+
+static bool GetGalacticCoords (psSphere *ptGal, psSphere *ptSky, psSphereRot *toGal, pmChip *chip, float xPos, float yPos);
+
+// this function use an internal flag to mark sources which have already been measured
+bool psphotChooseAnalysisOptionsReadout(pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe)
+{
+    bool status;
+
+    psTimerStart ("psphot.options");
+
+    // find the currently selected readout
+    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, index); // File of interest
+    psAssert (file, "missing file?");
+
+    pmReadout *readout = pmFPAviewThisReadout(view, file->fpa);
+    psAssert (readout, "missing readout?");
+
+    pmChip *chip = pmFPAviewThisChip(view, file->fpa);
+    psAssert (chip, "missing chip?");
+
+    pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS");
+    psAssert (detections, "missing detections?");
+
+    psArray *sources = detections->allSources;
+    psAssert (sources, "missing sources?");
+
+    if (!sources->n) {
+        psLogMsg ("psphot", PS_LOG_INFO, "no sources, skipping source size");
+        return true;
+    }
+
+    // we do the petrosian analysis for the same sources as the extended source fits IFF
+    // this recipe value is turned on (otherwise we only make a selection based on the mag limits)
+    bool doPetrosian    = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_PETROSIAN");
+
+    // Option to enable fitting of all objects with extended model.
+    bool extFitAll = psMetadataLookupBool(&status, recipe, "PSPHOT.EXT.FIT.ALL.SOURCES");
+    assert (status);
+
+    // Fitting everything is fine, but if the source density is high, we probably shouldn't.
+    float extFitAllThresh = psMetadataLookupF32(&status, recipe, "PSPHOT.EXT.FIT.ALL.THRESH");
+    assert (status);
+    
+    // Determine if this readout is above the threshold to ext fit all sources
+    if (extFitAll) {
+      float maskFrac = psMetadataLookupF32(&status,readout->analysis,"READOUT.MASK.FRAC");
+      if (status) maskFrac = 0.0;
+      if (sources->n * (1.0 - maskFrac) > extFitAllThresh) {
+	extFitAll = false;
+      }
+    }
+
+    // use EXT_LIMIT bit to select objects?
+    bool useEXT_LIMIT = psMetadataLookupBool(&status, recipe, "EXT.NSIGMA.LIMIT.USE");
+    assert (status);
+
+    float SN_LIM = psMetadataLookupF32 (&status, recipe, "EXTENDED_SOURCE_SN_LIM");
+    assert (status);
+
+    // use GAL_LIMIT to select / skip objects?
+    psSphereRot *toGal = NULL;
+    float GAL_LIMIT = 0.0;
+    float GAL_LIMIT_BULGE = 0.0;
+    float GAL_LIMIT_SIGMA2 = 0.0;
+    bool useGAL_LIMIT = psMetadataLookupBool(&status, recipe, "EXT.FIT.MIN.GAL.LIMIT.USE");
+    assert (status);
+    if (useGAL_LIMIT) {
+	toGal = psSphereRotICRSToGalactic();
+	GAL_LIMIT = psMetadataLookupF32(&status, recipe, "EXT.FIT.MIN.GAL.LIMIT");
+        assert (status);
+        GAL_LIMIT = DEG_TO_RAD(GAL_LIMIT);
+	GAL_LIMIT_BULGE = psMetadataLookupF32(&status, recipe, "EXT.FIT.MIN.GAL.LIMIT.BULGE");
+        assert (status);
+        GAL_LIMIT_BULGE = DEG_TO_RAD(GAL_LIMIT_BULGE);
+	float GAL_LIMIT_SIGMA = psMetadataLookupF32(&status, recipe, "EXT.FIT.MIN.GAL.LIMIT.BULGE.SIGMA");
+        assert (status);
+        assert(GAL_LIMIT_SIGMA > 0);
+        GAL_LIMIT_SIGMA = DEG_TO_RAD(GAL_LIMIT_SIGMA);
+	GAL_LIMIT_SIGMA2 = GAL_LIMIT_SIGMA * GAL_LIMIT_SIGMA;
+    }
+
+    // use MAG.LIMITS
+    psMetadata *magLimits = psMetadataLookupPtr (&status, recipe, "EXT.ANALYSIS.MAG.LIMITS");
+    if (!status || !magLimits) {   
+        psLogMsg ("psphot", PS_LOG_WARN, "EXT.ANALYSIS.MAG.LIMITS not found in the recipe, will use other criteria.");
+        magLimits = NULL;
+    }
+
+    float petroFluxLim = NAN;
+    float extFitFluxLim = NAN;
+
+    if (magLimits) {
+	float extFitMagLimDefault = NAN;
+	float extFitMagLim = NAN;
+	float petroMagLimDefault = NAN;
+	float petroMagLim = NAN;
+
+	// match to the given filter
+	psString filterID = psMetadataLookupStr(&status, file->fpa->concepts, "FPA.FILTERID");
+	psAssert (filterID, "missing FPA.FILTERID?");
+
+        psMetadataIterator *iter = psMetadataIteratorAlloc(magLimits, PS_LIST_HEAD, NULL);
+        psMetadataItem *item = NULL;
+        while ((item = psMetadataGetAndIncrement (iter)) != NULL) {
+            if (item->type != PS_DATA_METADATA) {
+                psAbort ("Invalid type for EXT.ANALYSIS.MAG.LIMITS: %s, not a metadata folder", item->name);
+            }
+            psString thisFilter = psMetadataLookupStr (&status, item->data.md, "FILTER.ID");
+            psAssert(thisFilter, "missing FILTER.ID");
+
+	    // find a matching filter or default to 'any'
+	    if (!strcasecmp (thisFilter, "any")) {
+		psString petroMagLimStr = psMetadataLookupStr (&status, item->data.md, "MAG.LIMIT.PETRO");
+		psAssert(petroMagLimStr, "missing MAG.LIMIT.PETRO");
+		petroMagLimDefault = atof (petroMagLimStr);
+
+		psString extFitMagLimStr = psMetadataLookupStr (&status, item->data.md, "MAG.LIMIT.EXTFIT");
+		psAssert(extFitMagLimStr, "missing MAG.LIMIT.EXTFIT");
+		extFitMagLimDefault = atof (extFitMagLimStr);
+	    }
+
+	    if (!strcasecmp (thisFilter, filterID)) {
+		psString petroMagLimStr = psMetadataLookupStr (&status, item->data.md, "MAG.LIMIT.PETRO");
+		psAssert(petroMagLimStr, "missing MAG.LIMIT.PETRO");
+		petroMagLim = atof (petroMagLimStr);
+
+		psString extFitMagLimStr = psMetadataLookupStr (&status, item->data.md, "MAG.LIMIT.EXTFIT");
+		psAssert(extFitMagLimStr, "missing MAG.LIMIT.EXTFIT");
+		extFitMagLim = atof (extFitMagLimStr);
+		break;
+	    }
+	}
+        psFree(iter);
+	if (!isfinite (petroMagLim)) petroMagLim = petroMagLimDefault;
+	if (!isfinite (extFitMagLim)) extFitMagLim = extFitMagLimDefault;
+
+	// now I need to convert the mag limits into instrumental flux limits
+	// I need to get a zero point and exposure time for this image
+	
+	// select the exposure time
+	float exptime = psMetadataLookupF32(&status, file->fpa->concepts, "CELL.EXPOSURE");
+	if (!status) {
+	    exptime = psMetadataLookupF32(&status, file->fpa->concepts, "FPA.EXPOSURE");
+	    psAssert (status, "missing CELL.EXPOSURE and FPA.EXPOSURE?");
+	}
+
+	// select the exposure time
+	float zeropt = psMetadataLookupF32(&status, file->fpa->concepts, "FPA.ZP");
+	psAssert (status, "missing FPA.ZP?");
+
+	petroFluxLim = exptime * pow (10.0, 0.4*(zeropt - petroMagLim));
+	extFitFluxLim = exptime * pow (10.0, 0.4*(zeropt - extFitMagLim));
+    }
+
+    pmSourceTmpF clearBits = ~(PM_SOURCE_TMPF_EXT_FIT | PM_SOURCE_TMPF_PETRO);
+    for (psS32 i = 0 ; i < sources->n ; i++) {
+
+        pmSource *source = (pmSource *) sources->data[i];
+
+	// clear the 2 relevant bits
+	source->tmpFlags &= clearBits;
+
+        // skip PSF-like and non-astronomical objects
+        if (source->type == PM_SOURCE_TYPE_DEFECT) continue;
+        if (source->type == PM_SOURCE_TYPE_SATURATED) continue;
+	if (source->mode & PM_SOURCE_MODE_DEFECT) continue;
+	if (source->mode & PM_SOURCE_MODE_SATSTAR) continue;
+
+	// skip saturated stars modeled with a radial profile 
+        if (source->mode2 & PM_SOURCE_MODE2_SATSTAR_PROFILE) continue;
+
+        // skip sources without a psf model
+        if (source->modelPSF == NULL) continue;
+
+	// Do the fits if the recipe requests we do extended source fits to everything
+	if (extFitAll) {
+	  source->tmpFlags |= PM_SOURCE_TMPF_EXT_FIT;
+	  if (doPetrosian) source->tmpFlags |= PM_SOURCE_TMPF_PETRO;
+	  continue;
+	}
+
+	if (useEXT_LIMIT) {
+	    if (!(source->mode & PM_SOURCE_MODE_EXT_LIMIT)) {
+		// not extended so skip
+		continue;
+	    }
+	}
+
+	if (useGAL_LIMIT) {
+	    psSphere ptGal, ptSky;
+	    GetGalacticCoords (&ptGal, &ptSky, toGal, chip, source->peak->xf, source->peak->yf);
+            float l = ptGal.r;
+            float b_min = GAL_LIMIT + GAL_LIMIT_BULGE * exp(-0.5*(l*l/GAL_LIMIT_SIGMA2));
+            if (fabs(ptGal.d) < b_min) continue;
+	    // include an exception for low density skycells below the limit?
+	}
+
+	// for petro and extFit, we will either use the mag limits or the S/N
+        if (doPetrosian) {
+            if (isfinite(petroFluxLim)) {
+                if (source->moments->KronFlux > petroFluxLim) {
+                    source->tmpFlags |= PM_SOURCE_TMPF_PETRO;
+                }
+            } else if (source->moments->KronFlux > SN_LIM * source->moments->KronFluxErr) {
+                source->tmpFlags |= PM_SOURCE_TMPF_PETRO;
+	    }
+	}
+	if (isfinite(extFitFluxLim)) {
+	    if (source->moments->KronFlux > extFitFluxLim) {
+		source->tmpFlags |= PM_SOURCE_TMPF_EXT_FIT;
+	    }
+	} else {
+	    if (source->moments->KronFlux > SN_LIM * source->moments->KronFluxErr) {
+		source->tmpFlags |= PM_SOURCE_TMPF_EXT_FIT;
+	    }
+	}
+    }
+
+    psLogMsg ("psphot.options", PS_LOG_WARN, "choose analysis options for %ld sources: %f sec\n", sources->n, psTimerMark ("psphot.options"));
+
+    psFree(toGal);
+
+    return true;
+}
+
+// this function use an internal flag to mark sources which have already been measured
+bool psphotChooseAnalysisOptionsByObject(pmConfig *config, const pmFPAview *view, const char *filerule, psArray *objects)
+{
+    bool status;
+
+    psTimerStart ("psphot.options");
+
+    fprintf (stdout, "\n");
+    psLogMsg ("psphot", PS_LOG_INFO, "--- psphot Choose Analysis Options (By Object) ---");
+
+    // select the appropriate recipe information
+    psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE);
+    psAssert (recipe, "missing recipe?");
+
+    // S/N lim to perform radial aperture analysis
+    float SN_LIM_RADIAL = psMetadataLookupF32 (&status, recipe, "RADIAL_APERTURES_SN_LIM");
+
+    // we do the petrosian analysis for the same sources as the extended source fits IFF
+    // this recipe value is turned on (otherwise we only make a selection based on the mag limits)
+    bool doPetrosian    = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_PETROSIAN");
+
+    // Option to enable fitting of all objects with extended model.
+    bool extFitAll = psMetadataLookupBool(&status, recipe, "PSPHOT.EXT.FIT.ALL.SOURCES");
+    assert (status);
+
+    // Fitting everything is fine, but if the source density is high, we probably shouldn't.
+    float extFitAllThresh = psMetadataLookupF32(&status, recipe, "PSPHOT.EXT.FIT.ALL.THRESH");
+    assert (status);
+    
+    // use EXT_LIMIT bit to select objects?
+    bool useEXT_LIMIT = psMetadataLookupBool(&status, recipe, "EXT.NSIGMA.LIMIT.USE");
+    assert (status);
+
+    float SN_LIM = psMetadataLookupF32 (&status, recipe, "EXTENDED_SOURCE_SN_LIM");
+    assert (status);
+
+    // use GAL_LIMIT to select / skip objects?
+    psSphereRot *toGal = NULL;
+    float GAL_LIMIT = 0.0;
+    float GAL_LIMIT_BULGE = 0.0;
+    float GAL_LIMIT_SIGMA2 = 0.0;
+    bool useGAL_LIMIT = psMetadataLookupBool(&status, recipe, "EXT.FIT.MIN.GAL.LIMIT.USE");
+    assert (status);
+    if (useGAL_LIMIT) {
+	toGal = psSphereRotICRSToGalactic();
+	GAL_LIMIT = psMetadataLookupF32(&status, recipe, "EXT.FIT.MIN.GAL.LIMIT");
+        assert (status);
+        GAL_LIMIT = DEG_TO_RAD(GAL_LIMIT);
+	GAL_LIMIT_BULGE = psMetadataLookupF32(&status, recipe, "EXT.FIT.MIN.GAL.LIMIT.BULGE");
+        assert (status);
+        GAL_LIMIT_BULGE = DEG_TO_RAD(GAL_LIMIT_BULGE);
+	float GAL_LIMIT_SIGMA = psMetadataLookupF32(&status, recipe, "EXT.FIT.MIN.GAL.LIMIT.BULGE.SIGMA");
+        assert (status);
+        assert(GAL_LIMIT_SIGMA > 0);
+        GAL_LIMIT_SIGMA = DEG_TO_RAD(GAL_LIMIT_SIGMA);
+	GAL_LIMIT_SIGMA2 = GAL_LIMIT_SIGMA * GAL_LIMIT_SIGMA;
+    }
+
+    // use MAG.LIMITS
+    psMetadata *magLimits = psMetadataLookupPtr (&status, recipe, "EXT.ANALYSIS.MAG.LIMITS");
+    if (!status || !magLimits) {   
+        psLogMsg ("psphot", PS_LOG_WARN, "EXT.ANALYSIS.MAG.LIMITS not found in the recipe, will use other criteria.");
+        magLimits = NULL;
+    }
+
+    int num = psphotFileruleCount(config, filerule);
+
+    int chisqNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.CHISQ.NUM");
+    if (!status) chisqNum = -1;
+
+    // Find the filter for each of the inputs in fpa concepts
+    psArray *inputFilters = psArrayAlloc(num);
+    psArray *chips = psArrayAlloc(num);
+    psVector *zeropt = psVectorAlloc (inputFilters->n, PS_TYPE_F32);
+    psVector *exptime = psVectorAlloc (inputFilters->n, PS_TYPE_F32);
+
+    // we will not use the chisq image to set the fitting limits
+    if (chisqNum >= 0) {
+      inputFilters->data[chisqNum] = psStringCopy("chisq");
+      chips->data[chisqNum] = NULL;
+      zeropt->data.F32[chisqNum] = NAN;
+      exptime->data.F32[chisqNum] = NAN;
+    }
+
+    // get the needed metadata for the non-chisq images
+    for (int i = 0 ; i < num; i++) {
+      if (i == chisqNum) continue;
+
+      pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, i);
+      psAssert (file, "missing file?");
+
+      pmChip *chip = pmFPAviewThisChip(view, file->fpa);
+      psAssert (chip, "missing chip?");
+      chips->data[i] = psMemIncrRefCounter (chip);
+
+      pmReadout *readout = pmFPAviewThisReadout(view, file->fpa);
+      psAssert (readout, "missing readout?");
+
+      pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS");
+      psAssert (detections, "missing detections?");
+
+      psArray *sources = detections->allSources;
+      psAssert (sources, "missing sources?");
+
+      float maskFrac = psMetadataLookupF32(&status,readout->analysis,"READOUT.MASK.FRAC");
+      if (!status) maskFrac = 0.0;
+      if (sources->n * (1.0 - maskFrac) > extFitAllThresh) {
+	extFitAll = false;
+      }
+
+      // select the filterID for this image
+      char *filterID = psMetadataLookupStr(&status, file->fpa->concepts, "FPA.FILTERID");
+      psAssert (status, "missing FPA.FILTERID?");
+      inputFilters->data[i] = psStringCopy (filterID);
+
+      // select the exposure time for this image
+      exptime->data.F32[i] = psMetadataLookupF32(&status, file->fpa->concepts, "CELL.EXPOSURE");
+      if (!status) {
+	exptime->data.F32[i] = psMetadataLookupF32(&status, file->fpa->concepts, "FPA.EXPOSURE");
+	psAssert (status, "missing CELL.EXPOSURE and FPA.EXPOSURE?");
+      }
+
+      // select the zero point for this image
+      zeropt->data.F32[i] = psMetadataLookupF32(&status, file->fpa->concepts, "FPA.ZP");
+      psAssert (status, "missing FPA.ZP?");
+    }
+
+    // find extFitFluxLim->data.F32[i] for i == image number
+    psVector *extFitFluxLim = NULL;
+    psVector *petroFluxLim = NULL;
+    if (magLimits) {
+	extFitFluxLim = psVectorAlloc (inputFilters->n, PS_TYPE_F32);
+        petroFluxLim = psVectorAlloc (inputFilters->n, PS_TYPE_F32);
+	psVectorInit (extFitFluxLim, NAN);
+	psVectorInit (petroFluxLim, NAN);
+
+	float extFitMagLimDefault = NAN;
+	float petroMagLimDefault = NAN;
+
+	// match mag limits (flux limits) to the filters
+        psMetadataIterator *iter = psMetadataIteratorAlloc(magLimits, PS_LIST_HEAD, NULL);
+        psMetadataItem *item = NULL;
+        while ((item = psMetadataGetAndIncrement (iter)) != NULL) {
+            if (item->type != PS_DATA_METADATA) {
+                psAbort ("Invalid type for EXT.ANALYSIS.MAG.LIMITS: %s, not a metadata folder", item->name);
+            }
+            psString thisFilter = psMetadataLookupStr (&status, item->data.md, "FILTER.ID");
+            psAssert(thisFilter, "missing FILTER.ID");
+
+	    // save the default value to assign to unset filters
+	    if (!strcasecmp (thisFilter, "any")) {
+		psString magString = psMetadataLookupStr (&status, item->data.md, "MAG.LIMIT.EXTFIT");
+		psAssert(magString, "missing MAG.LIMIT.EXTFIT");
+		extFitMagLimDefault = atof (magString);
+
+		magString = psMetadataLookupStr (&status, item->data.md, "MAG.LIMIT.PETRO");
+		psAssert(magString, "missing MAG.LIMIT.PETRO");
+		petroMagLimDefault = atof (magString);
+		continue;
+	    }
+
+	    // not every entry in the metadata block needs to match to an image in our list
+	    for (int i = 0; i < num; i++) {
+		if (i == chisqNum) continue;
+		if (!strcasecmp (thisFilter, inputFilters->data[i])) {
+		    psString magString = psMetadataLookupStr (&status, item->data.md, "MAG.LIMIT.PETRO");
+		    psAssert(magString, "missing MAG.LIMIT.PETRO");
+		    float magvalue = atof (magString);
+		    petroFluxLim->data.F32[i] = exptime->data.F32[i] * pow (10.0, 0.4*(zeropt->data.F32[i] - magvalue));
+
+		    magString = psMetadataLookupStr (&status, item->data.md, "MAG.LIMIT.EXTFIT");
+		    psAssert(magString, "missing MAG.LIMIT.EXTFIT");
+		    magvalue = atof (magString);
+		    extFitFluxLim->data.F32[i] = exptime->data.F32[i] * pow (10.0, 0.4*(zeropt->data.F32[i] - magvalue));
+		    break;
+		}
+	    }
+	}
+        psFree(iter);
+
+	for (int i = 0; i < num; i++) {
+	    if (i == chisqNum) continue;
+	    if (!isfinite(petroFluxLim->data.F32[i])) {
+                petroFluxLim->data.F32[i] = exptime->data.F32[i] * pow (10.0, 0.4*(zeropt->data.F32[i] - petroMagLimDefault));
+            }
+	    if (!isfinite(extFitFluxLim->data.F32[i])) {
+                extFitFluxLim->data.F32[i] = exptime->data.F32[i] * pow (10.0, 0.4*(zeropt->data.F32[i] - extFitMagLimDefault));
+            }
+	}
+    }
+
+    pmSourceTmpF clearBits = ~(PM_SOURCE_TMPF_EXT_FIT | PM_SOURCE_TMPF_PETRO);
+
+    for (int i = 0; i < objects->n; i++) {
+        pmPhotObj *object = objects->data[i];
+	if (!object) continue;
+	if (!object->sources) continue;
+
+	// we check each source for an object and keep the object if any source is valid
+
+	bool doObjectRadial = false;
+	bool doObjectExtFit = false;
+	bool doObjectPetrosian = false;
+	for (int j = 0; !doObjectExtFit && !doObjectRadial && !doObjectPetrosian && (j < object->sources->n); j++) {
+
+	    pmSource *source = object->sources->data[j];
+	    if (!source) continue;
+	    if (!source->peak) continue;
+	    if (source->imageID < 0) continue; // skip sources which come from other images?
+	    if (source->imageID >= num) continue; // skip sources which come from other images?
+
+	    // skip PSF-like and non-astronomical objects
+	    if (source->type == PM_SOURCE_TYPE_DEFECT) continue;
+	    if (source->type == PM_SOURCE_TYPE_SATURATED) continue;
+	    if (source->mode & PM_SOURCE_MODE_DEFECT) continue;
+	    if (source->mode & PM_SOURCE_MODE_SATSTAR) continue;
+	
+	    // skip saturated stars modeled with a radial profile 
+	    if (source->mode2 & PM_SOURCE_MODE2_SATSTAR_PROFILE) continue;
+	
+	    // XXX should I fit all even if one of the detections matches the above?
+
+	    // check on radial aperture analysis (fewer options for now)
+	    if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) {
+		bool doSourceRadial = (source->moments->KronFlux > SN_LIM_RADIAL * source->moments->KronFluxErr);
+		doObjectRadial = doObjectRadial | doSourceRadial;
+	    } else {
+		bool doSourceRadial = (sqrt(source->peak->detValue) > SN_LIM_RADIAL);
+		doObjectRadial = doObjectRadial | doSourceRadial;
+	    }
+
+	    // Do the fits if the recipe requests we do extended source fits to everything
+	    if (extFitAll) {
+		doObjectExtFit = true;
+		doObjectPetrosian = doPetrosian;
+		continue;
+	    }
+
+	    if (useEXT_LIMIT) {
+		if (!(source->mode & PM_SOURCE_MODE_EXT_LIMIT)) {
+		    continue; // not extended so skip
+		}
+	    }
+
+	    int imageID = source->imageID;
+
+	    if (useGAL_LIMIT) {
+		psSphere ptGal, ptSky;
+		GetGalacticCoords (&ptGal, &ptSky, toGal, chips->data[imageID], source->peak->xf, source->peak->yf);
+                float l = ptGal.r;
+                float b_min = GAL_LIMIT + GAL_LIMIT_BULGE * exp(-0.5*(l*l/GAL_LIMIT_SIGMA2));
+		if (fabs(ptGal.d) < b_min) continue;
+	    }
+
+	    float fluxLim = NAN;
+	    // for petro and extFit, we will either use the mag limits or the S/N
+            if (doPetrosian) {
+                fluxLim = petroFluxLim ? petroFluxLim->data.F32[imageID] : NAN;
+                if (isfinite(fluxLim)) {
+                    if (source->moments->KronFlux > extFitFluxLim->data.F32[imageID]) {
+                        doObjectPetrosian = true;
+                    }
+                } else {
+                    if (source->moments->KronFlux > SN_LIM * source->moments->KronFluxErr) {
+                        doObjectPetrosian = true;
+                    }
+                }
+	    }
+	    fluxLim = extFitFluxLim ? extFitFluxLim->data.F32[imageID] : NAN;
+	    // for petro and extFit, we will either use the mag limits or the S/N
+	    if (isfinite(fluxLim)) {
+		if (source->moments->KronFlux > extFitFluxLim->data.F32[imageID]) {
+		    doObjectExtFit = true;
+		}
+	    } else {
+		if (source->moments->KronFlux > SN_LIM * source->moments->KronFluxErr) {
+		    doObjectExtFit = true;
+		}
+	    }
+	}
+
+	for (int j = 0; j < object->sources->n; j++) {
+		
+	    pmSource *source = object->sources->data[j];
+	    if (!source) continue;
+	    if (!source->peak) continue;
+		
+	    // clear the 2 relevant bits
+	    source->tmpFlags &= clearBits;
+		
+	    // skip PSF-like and non-astronomical objects??
+	    if (source->type == PM_SOURCE_TYPE_DEFECT) continue;
+	    if (source->type == PM_SOURCE_TYPE_SATURATED) continue;
+	    if (source->mode & PM_SOURCE_MODE_DEFECT) continue;
+	    if (source->mode & PM_SOURCE_MODE_SATSTAR) continue;
+		
+	    // skip saturated stars modeled with a radial profile 
+	    if (source->mode2 & PM_SOURCE_MODE2_SATSTAR_PROFILE) continue;
+
+            // skip sources without a psf model
+            if (source->modelPSF == NULL) continue;
+		
+	    if (doObjectExtFit) {
+		source->tmpFlags |= PM_SOURCE_TMPF_EXT_FIT;
+	    }
+            if (doObjectPetrosian) {
+                source->tmpFlags |= PM_SOURCE_TMPF_PETRO;
+            }
+
+	    // Do the fits if the recipe requests we do extended source fits to everything
+	    if (doObjectRadial) {
+		source->tmpFlags |=  PM_SOURCE_TMPF_RADIAL_KEEP;
+		source->tmpFlags &= ~PM_SOURCE_TMPF_RADIAL_SKIP;
+	    } else {
+		source->tmpFlags |=  PM_SOURCE_TMPF_RADIAL_SKIP;
+		source->tmpFlags &= ~PM_SOURCE_TMPF_RADIAL_KEEP;
+	    }
+	}
+    }
+
+    psLogMsg ("psphot.options", PS_LOG_WARN, "choose analysis options for %ld objects: %f sec\n", objects->n, psTimerMark ("psphot.options"));
+
+    psFree(toGal);
+
+    return true;
+}
+
+static bool GetGalacticCoords (psSphere *ptGal, psSphere *ptSky, psSphereRot *toGal, pmChip *chip, float xPos, float yPos) {
+
+    pmFPA *fpa = chip->parent;
+
+    if (!chip->toFPA) goto escape;
+    if (!fpa->toTPA) goto escape;
+    if (!fpa->toSky) goto escape;
+
+    psPlane ptCH, ptFP, ptTP;
+
+    // calculate the astrometry for the coordinate of interest
+    ptCH.x = xPos;
+    ptCH.y = yPos;
+    psPlaneTransformApply (&ptFP, chip->toFPA, &ptCH);
+    psPlaneTransformApply (&ptTP, fpa->toTPA, &ptFP);
+    psDeproject (ptSky, &ptTP, fpa->toSky);
+    psSphereRotApply (ptGal, toGal, ptSky);
+
+    // psSphereRotApply insures that 0 < r < 2PI. We want -PI < b <= PI
+    if (ptGal->r > M_PI) {
+        ptGal->r -= 2.0 * M_PI;
+    }
+
+    return true;
+
+escape:
+    // no astrometry calibration, give up
+    ptSky->r = NAN;
+    ptSky->d = NAN;
+
+    ptGal->r = NAN;
+    ptGal->d = NAN;
+
+    return false;
+}
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotChoosePSF.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotChoosePSF.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotChoosePSF.c	(revision 37066)
@@ -399,5 +399,5 @@
     char *modelName = pmModelClassGetName (psf->type);
     psLogMsg ("psphot.pspsf", PS_LOG_WARN, "select psf model: %f sec\n", psTimerMark ("psphot.choose.psf"));
-    psLogMsg ("psphot.pspsf", PS_LOG_INFO, "psf model %s, ApResid: %f +/- %f\n", modelName, psf->ApResid, psf->dApResid);
+    psLogMsg ("psphot.pspsf", PS_LOG_INFO, "psf model %s, ApResid: %f +/- %f (%d x %d model)\n", modelName, psf->ApResid, psf->dApResid, psf->trendNx, psf->trendNy);
 
     psFree (options);
@@ -448,5 +448,5 @@
 
             // get the model full-width at half-max
-            float FWHM_MAJOR = 2*modelPSF->modelRadius (modelPSF->params, 0.5);
+            float FWHM_MAJOR = 2*modelPSF->class->modelRadius (modelPSF->params, 0.5);
 
             // XXX make sure this is consistent with the re-definition of PM_PAR_SXX
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotCleanup.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotCleanup.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotCleanup.c	(revision 37066)
@@ -22,6 +22,9 @@
     pmVisualCleanup ();
     psLibFinalize();
+#if (PS_TRACE_ON)
+    // don't display memory leaks unless trace is on. 
     // fprintf (stderr, "found %d leaks at %s\n", psMemCheckLeaks (0, NULL, NULL, false), "psphot");
     fprintf (stderr, "found %d leaks at %s\n", psMemCheckLeaks (0, NULL, stdout, false), "psphot");
+#endif
     return;
 }
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotDeblendSatstars.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotDeblendSatstars.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotDeblendSatstars.c	(revision 37066)
@@ -128,4 +128,6 @@
     // int display = psphotKapaChannel (1);
     // psphotVisualScaleImage (display, (psImage *) source->pixels->parent, NULL, "image", 1.0, 0);
+
+    int Nsatstar = 0;
 
     // examine sources in decreasing SN order
@@ -179,4 +181,6 @@
 	source->mode2 |= PM_SOURCE_MODE2_SATSTAR_PROFILE; // and we have in fact subtracted the profile
 
+	Nsatstar ++;
+
 	// XXX visualize, model, and subtract
 	// if (!psphotVisualRadialProfileSatstar (source, maskVal)) {
@@ -192,5 +196,5 @@
     psFree (index);
 
-    psLogMsg ("psphot", PS_LOG_INFO, "deblend satstar: %f sec\n", psTimerMark ("psphot.deblend.sat"));
+    psLogMsg ("psphot", PS_LOG_INFO, "deblend %d satstars: %f sec\n", Nsatstar, psTimerMark ("psphot.deblend.sat"));
     return true;
 }
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotDefineFiles.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotDefineFiles.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotDefineFiles.c	(revision 37066)
@@ -150,4 +150,11 @@
     }
 
+    if (psMetadataLookupPtr(NULL, config->arguments, "FORCE")) {
+        if (!pmFPAfileDefineFromArgs (&status, config, "PSPHOT.INPUT.CFF", "FORCE")) {
+            psError(PSPHOT_ERR_CONFIG, false, "Failed to find/build PSPHOT.INPUT.CFF");
+            return status;
+        }
+    }
+
     if (psMetadataLookupPtr(NULL, config->arguments, "SRCTEXT")) {
 	// XXX cannot use pmFPAfileDefineFromArgs: this is explicitly a FITS-based I/O function
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotEfficiency.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotEfficiency.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotEfficiency.c	(revision 37066)
@@ -71,5 +71,5 @@
                 continue;
             }
-            float flux = normModel->modelFlux(normModel->params); // Total flux for peak of 1.0
+            float flux = normModel->class->modelFlux(normModel->params); // Total flux for peak of 1.0
             psFree(normModel);
             if (!isfinite(flux)) {
@@ -424,5 +424,5 @@
                     continue;
                 }
-                float sourceRadius = PS_MAX(radius, model->modelRadius(model->params, minFlux)); // Radius for source
+                float sourceRadius = PS_MAX(radius, model->class->modelRadius(model->params, minFlux)); // Radius for source
                 psFree(model);
                 if (!isfinite(sourceRadius)) {
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotEllipticalContour.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotEllipticalContour.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotEllipticalContour.c	(revision 37066)
@@ -64,4 +64,5 @@
 	psFree (y);
 	psFree (yErr);
+	source->mode2 |= PM_SOURCE_MODE2_ECONTOUR_FEW_PTS;
 	return false;
     }
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotEvalFLT.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotEvalFLT.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotEvalFLT.c	(revision 37066)
@@ -53,5 +53,5 @@
     } 
 
-    keep = model->modelFitStatus(model);
+    keep = model->class->modelFitStatus(model);
     if (keep) return true;
 
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotExtendedSourceAnalysis.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotExtendedSourceAnalysis.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotExtendedSourceAnalysis.c	(revision 37066)
@@ -1,5 +1,6 @@
 # include "psphotInternal.h"
-
-// measure the elliptical radial profile and use this to measure the petrosian parameters for the sources
+void psphotRadialProfileShowSkips ();
+
+// measure the petrosian parameters for the sources
 
 // for now, let's store the detections on the readout->analysis for each readout
@@ -15,6 +16,9 @@
     psAssert (recipe, "missing recipe?");
 
-    // perform full non-linear fits / extended source analysis?
-    if (!psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_ANALYSIS")) {
+    bool doPetrosian = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_PETROSIAN");
+    bool doAnnuli    = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_ANNULI");
+
+    // measure petrosians?
+    if (!doPetrosian && !doAnnuli) {
 	psLogMsg ("psphot", PS_LOG_INFO, "skipping extended source measurements\n");
 	return true;
@@ -33,4 +37,15 @@
 }
 
+/*** for the moment, this test code : it is not thread safe ***/
+int    Nall = 0;
+int  Nskip1 = 0;
+int  Nskip2 = 0;
+int  Nskip3 = 0;
+int  Nskip4 = 0;
+int  Nskip5 = 0;
+int  Nskip6 = 0;
+
+# define SKIP(VALUE) { VALUE++; continue; }
+
 // aperture-like measurements for extended sources
 bool psphotExtendedSourceAnalysisReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe) {
@@ -110,5 +125,5 @@
 
 // set this to 0 to run without threading
-# if (1)	    
+# if (0)	    
             if (!psThreadJobAddPending(job)) {
                 psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
@@ -164,10 +179,18 @@
     psLogMsg ("psphot", PS_LOG_INFO, "  %d annuli\n", Nannuli);
 
+# if (PS_TRACE_ON)
+    fprintf (stderr, "ext analysis skipped @ 1  : %d\n", Nskip1);
+    fprintf (stderr, "ext analysis skipped @ 2  : %d\n", Nskip2);
+    fprintf (stderr, "ext analysis skipped @ 3  : %d\n", Nskip3);
+    fprintf (stderr, "ext analysis skipped @ 4  : %d\n", Nskip4);
+    fprintf (stderr, "ext analysis skipped @ 5  : %d\n", Nskip5);
+    fprintf (stderr, "ext analysis skipped @ 6  : %d\n", Nskip6);
+#endif
+
+    psphotRadialProfileShowSkips ();
+
     psphotVisualShowResidualImage (readout, false);
 
-    bool doPetrosian    = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_PETROSIAN");
-    if (doPetrosian) {
-	psphotVisualShowPetrosians (sources);
-    }
+    psphotVisualShowPetrosians (sources);
 
     return true;
@@ -190,11 +213,5 @@
     float skynoise          = PS_SCALAR_VALUE(job->args->data[4],F32);
 
-    // S/N limit to perform full non-linear fits
-    float SN_LIM = psMetadataLookupF32 (&status, recipe, "EXTENDED_SOURCE_SN_LIM");
-
-    // which extended source analyses should we perform?
     bool doPetrosian    = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_PETROSIAN");
-    bool doAnnuli       = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_ANNULI");
-    bool doPetroStars   = psMetadataLookupBool (&status, recipe, "PETROSIAN_FOR_STARS");
 
     // user-defined masks to test for good/bad pixels (build from recipe list if not yet set)
@@ -207,42 +224,15 @@
 	pmSource *source = sources->data[i];
 
-	// if we have checked the source validity on the basis of the object set, then 
-	// we either skip these tests below or we skip the source completely
-	if (source->tmpFlags & PM_SOURCE_TMPF_PETRO_SKIP) continue;
-	if (source->tmpFlags & PM_SOURCE_TMPF_PETRO_KEEP) goto keepSource;
-
-	// skip PSF-like and non-astronomical objects
-	if (source->type == PM_SOURCE_TYPE_DEFECT) continue;
-	if (source->type == PM_SOURCE_TYPE_SATURATED) continue;
-	if (source->mode & PM_SOURCE_MODE_DEFECT) continue;
-	if (source->mode & PM_SOURCE_MODE_SATSTAR) continue;
-
-	// skip saturated stars modeled with a radial profile 
-        if (source->mode2 & PM_SOURCE_MODE2_SATSTAR_PROFILE) continue;
-
-	// optionally allow non-extended objects to get petrosians as well
-	if (!doPetroStars) {
-	    if (!(source->mode & PM_SOURCE_MODE_EXT_LIMIT)) continue;
-	    if (source->type == PM_SOURCE_TYPE_STAR) continue;
-	}
-
-	// limit selection to some SN limit
-	// assert (source->peak); // how can a source not have a peak?
-	// limit selection to some SN limit
-	bool skipSource = false;
-	if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) {
-	    skipSource = (source->moments->KronFlux < SN_LIM * source->moments->KronFluxErr);
-	} else {
-	    skipSource = (sqrt(source->peak->detValue) < SN_LIM);
-	}
-	if (skipSource) continue;
-
-	// limit selection by analysis region (this automatically apply
-	if (source->peak->x < region->x0) continue;
-	if (source->peak->y < region->y0) continue;
-	if (source->peak->x > region->x1) continue;
-	if (source->peak->y > region->y1) continue;
-
-    keepSource:
+	Nall ++;
+
+	// rules for measuring petrosian parameters for specific objects are set in
+	// psphotChooseAnalysisOptions.c
+	if (!(source->tmpFlags & PM_SOURCE_TMPF_PETRO)) SKIP (Nskip1);
+
+	// limit selection by analysis region (XXX move this into psphotChooseAnalysisOption?)
+	if (source->peak->x < region->x0) SKIP (Nskip2);
+	if (source->peak->y < region->y0) SKIP (Nskip3);
+	if (source->peak->x > region->x1) SKIP (Nskip4);
+	if (source->peak->y > region->y1) SKIP (Nskip5);
 
 	// replace object in image
@@ -259,26 +249,24 @@
 	pmSourceRedefinePixels (source, readout, source->peak->xf, source->peak->yf, 1.5*radius);
 
-	// if we request any of these measurements, we require the radial profile
-	if (doPetrosian || doAnnuli) {
-	    if (!psphotRadialProfile (source, recipe, skynoise, maskVal)) {
-		// all measurements below require the radial profile; skip them all
-		// re-subtract the object, leave local sky
-		psTrace ("psphot", 5, "failed to extract radial profile for source at %7.1f, %7.1f", source->moments->Mx, source->moments->My);
-		pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
-		continue;
-	    }
-	    Nannuli ++;
-	    source->mode |= PM_SOURCE_MODE_RADIAL_FLUX;
-	}
+	// measure the radial profile
+	if (!psphotRadialProfile (source, recipe, skynoise, maskVal)) {
+	  // re-subtract the object, leave local sky
+	  psTrace ("psphot", 5, "failed to extract radial profile for source at %7.1f, %7.1f", source->moments->Mx, source->moments->My);
+	  pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
+	  SKIP (Nskip6);
+	}
+
+	Nannuli ++;
+	source->mode |= PM_SOURCE_MODE_RADIAL_FLUX;
 
 	// Petrosian Mags
 	if (doPetrosian) {
-	    if (!psphotPetrosian (source, recipe, skynoise, maskVal)) {
-		psTrace ("psphot", 5, "FAILED petrosian flux & radius for source at %7.1f, %7.1f", source->moments->Mx, source->moments->My);
-	    } else {
-		psTrace ("psphot", 5, "measured petrosian flux & radius for source at %7.1f, %7.1f", source->moments->Mx, source->moments->My);
-		Npetro ++;
-		source->mode |= PM_SOURCE_MODE_EXTENDED_STATS;
-	    }
+	  if (!psphotPetrosian (source, recipe, skynoise, maskVal)) {
+	    psTrace ("psphot", 5, "FAILED petrosian flux & radius for source at %7.1f, %7.1f", source->moments->Mx, source->moments->My);
+	  } else {
+	    psTrace ("psphot", 5, "measured petrosian flux & radius for source at %7.1f, %7.1f", source->moments->Mx, source->moments->My);
+	    Npetro ++;
+	    source->mode |= PM_SOURCE_MODE_EXTENDED_STATS;
+	  }
 	}
 
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotExtendedSourceFits.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotExtendedSourceFits.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotExtendedSourceFits.c	(revision 37066)
@@ -111,4 +111,9 @@
     }
 
+    float fitNsigmaConv = psMetadataLookupF32 (&status, recipe, "EXT_FIT_NSIGMA_CONV"); // number of sigma for the convolution
+    if (!status || !isfinite(fitNsigmaConv) || fitNsigmaConv <= 0) {
+	fitNsigmaConv = 5.0;
+    }
+
     bool chisqConvergence = psMetadataLookupBool (&status, recipe, "LMM_FIT_CHISQ_CONVERGENCE"); // Fit tolerance
     if (!status) {
@@ -123,7 +128,11 @@
     }
 
+    // perform full extended source non-linear fits?
+    bool isInteractive = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_FITS_INTERACTIVE");
+    if (!status) isInteractive = false;
+
     // Define source fitting parameters for extended source fits
     pmSourceFitOptions *fitOptions = pmSourceFitOptionsAlloc();
-    fitOptions->mode           = PM_SOURCE_FIT_EXT;
+    fitOptions->mode           = PM_SOURCE_FIT_EXT_AND_SKY;
     fitOptions->saveCovariance = true;  // XXX make this a user option?
     fitOptions->covarFactor    = psImageCovarianceFactorForAperture(readout->covariance, 10.0); // Covariance matrix
@@ -131,7 +140,13 @@
     fitOptions->minTol         = fitMinTol;
     fitOptions->maxTol         = fitMaxTol;
+    fitOptions->nsigma         = fitNsigmaConv;
 
     fitOptions->gainFactorMode   = gainFactorMode;
     fitOptions->chisqConvergence = chisqConvergence;
+    fitOptions->isInteractive    = isInteractive;
+
+    // use poissonian errors or local-sky errors
+    fitOptions->poissonErrors = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_FITS_POISSON");
+    if (!status) fitOptions->poissonErrors = true;
 
     // maskVal is used to test for rejected pixels, and must include markVal
@@ -278,4 +293,5 @@
             psArrayAdd(job->args, 1, cells->data[j]); // sources
             psArrayAdd(job->args, 1, models);
+
             // Allocate a metadata iterator here because psMetadataIteratorAlloc/Free are not thread safe
             psMetadataIterator *iter = psMetadataIteratorAlloc (models, PS_LIST_HEAD, NULL);
@@ -296,41 +312,42 @@
             PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfail
 
-// set this to 0 to run without threading
-# if (1)	    
-            if (!psThreadJobAddPending(job)) {
-                psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
-		psFree(AnalysisRegion);
-		psFree (fitOptions);
-		psFree (models);
-		psphotSersicModelClassCleanup();
-                return false;
-            } 
-# else
-	    if (!psphotExtendedSourceFits_Threaded(job)) {
-		psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
-		psFree(AnalysisRegion);
-		psFree (fitOptions);
-		psFree (models);
-		psphotSersicModelClassCleanup();
-		return false;
+// XXX TEST 
+	    if (!isInteractive) {
+		if (!psThreadJobAddPending(job)) {
+		    psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
+		    psFree(AnalysisRegion);
+		    psFree (fitOptions);
+		    psFree (models);
+		    psphotSersicModelClassCleanup();
+		    return false;
+		} 
+	    } else {
+		// run without threading
+		if (!psphotExtendedSourceFits_Threaded(job)) {
+		    psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
+		    psFree(AnalysisRegion);
+		    psFree (fitOptions);
+		    psFree (models);
+		    psphotSersicModelClassCleanup();
+		    return false;
+		}
+		psScalar *scalar = NULL;
+		scalar = job->args->data[9];
+		Next += scalar->data.S32;
+		scalar = job->args->data[10];
+		Nconvolve += scalar->data.S32;
+		scalar = job->args->data[11];
+		NconvolvePass += scalar->data.S32;
+		scalar = job->args->data[12];
+		Nplain += scalar->data.S32;
+		scalar = job->args->data[13];
+		NplainPass += scalar->data.S32;
+		scalar = job->args->data[14];
+		Nfaint += scalar->data.S32;
+		scalar = job->args->data[15];
+		Nfail += scalar->data.S32;
+		psFree(job->args->data[3]); // iterator allocated above
+		psFree(job);
 	    }
-	    psScalar *scalar = NULL;
-	    scalar = job->args->data[9];
-	    Next += scalar->data.S32;
-	    scalar = job->args->data[10];
-	    Nconvolve += scalar->data.S32;
-	    scalar = job->args->data[11];
-	    NconvolvePass += scalar->data.S32;
-	    scalar = job->args->data[12];
-	    Nplain += scalar->data.S32;
-	    scalar = job->args->data[13];
-	    NplainPass += scalar->data.S32;
-	    scalar = job->args->data[14];
-	    Nfaint += scalar->data.S32;
-	    scalar = job->args->data[15];
-	    Nfail += scalar->data.S32;
-            psFree(job->args->data[3]); // iterator allocated above
-	    psFree(job);
-# endif
 	}
 
@@ -418,4 +435,12 @@
     // psTraceSetLevel ("psLib.math.psMinimizeLMChi2_Alt", 5);
 
+    pmModelStatus badModel = PM_MODEL_STATUS_NONE;
+    badModel |= PM_MODEL_STATUS_BADARGS;
+    badModel |= PM_MODEL_STATUS_OFFIMAGE;
+    badModel |= PM_MODEL_STATUS_NAN_CHISQ;
+    badModel |= PM_MODEL_SERSIC_PCM_FAIL_GUESS;
+    badModel |= PM_MODEL_SERSIC_PCM_FAIL_GRID;
+    badModel |= PM_MODEL_PCM_FAIL_GUESS;
+
     // choose the sources of interest
     for (int i = 0; i < sources->n; i++) {
@@ -423,23 +448,13 @@
         pmSource *source = sources->data[i];
 
-        // skip PSF-like and non-astronomical objects
-        if (!(source->mode & PM_SOURCE_MODE_EXT_LIMIT)) continue;
-        if (source->type == PM_SOURCE_TYPE_DEFECT) continue;
-        if (source->type == PM_SOURCE_TYPE_SATURATED) continue;
-
-	// skip saturated stars modeled with a radial profile 
-        if (source->mode2 & PM_SOURCE_MODE2_SATSTAR_PROFILE) continue;
-
-        // XXX this should use peak?
+	// rules for measuring petrosian parameters for specific objects are set in
+	// psphotChooseAnalysisOptions.c
+	if (!(source->tmpFlags & PM_SOURCE_TMPF_EXT_FIT)) continue;
+
+	// limit selection by analysis region (XXX move this into psphotChooseAnalysisOption?)
         if (source->peak->x < region->x0) continue;
         if (source->peak->y < region->y0) continue;
         if (source->peak->x > region->x1) continue;
         if (source->peak->y > region->y1) continue;
-
-
-	// XXX for a test, just do the obvious trail
-	// XXX if (source->peak->xf < 1100) continue;
-	// XXX if (source->peak->xf > 1400) continue;
-	// XXX if (source->peak->yf >  245) continue;
 
         // replace object in image
@@ -452,7 +467,4 @@
 	psphotSetRadiusMomentsExact(&fitRadius, &windowRadius, readout, source, markVal); // NOTE : 6 allocs
 
-	// XXX WATCH OUT HERE!!
-	// fitRadius = 30;
-
 	// UPDATE : we have changed the moments calculation.  There is now an iteration within 
 	// psphotKronMasked to determine moments appropriate for a larger object.  The values
@@ -464,4 +476,14 @@
             source->modelFits = psArrayAllocEmpty (models->list->n);
         }
+
+# ifdef TEST_OBJECT
+	bool testObject = false;
+	testObject |= ((fabs(source->peak->xf -  179) < 5) && (fabs(source->peak->yf - 1138) < 5));
+	if (testObject) {
+	    fprintf (stderr, "test object @ %f, %f\n", source->peak->xf, source->peak->yf);
+	    psTraceSetLevel ("psModules.objects.pmPCM_MinimizeChisq", 5);
+	    psTraceSetLevel ("psphot.psphotExtendedSourceFits_Threaded", 5);
+	}
+# endif 
 
         // loop here over the models chosen for each source (exclude by S/N)
@@ -479,15 +501,13 @@
           assert (status);
 
-	  // limit selection to some SN limit
-	  bool skipSource = false;
-	  if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) {
-	      skipSource = (source->moments->KronFlux < FIT_SN_LIM * source->moments->KronFluxErr);
-	  } else {
-	      skipSource = (sqrt(source->peak->detValue) < FIT_SN_LIM);
-	  }
-          if (skipSource) {
+	  // limit selection to some SN limit for specific models (this value only applies if > EXTENDED_SOURCE_SN_LIM)
+	  if (isfinite(FIT_SN_LIM)) {
+	    if (source->moments->KronFlux < FIT_SN_LIM * source->moments->KronFluxErr) {
 	      Nfaint ++;
 	      continue;
+	    }
 	  }
+
+	  source->mode2 |= PM_SOURCE_MODE2_EXT_FITS_RUN;
 
           // check on the model type
@@ -507,4 +527,5 @@
                   psTrace ("psphot", 5, "failed to fit psf-conv model for object at %f, %f", source->moments->Mx, source->moments->My);
 		  Nfail ++;
+		  source->mode2 |= PM_SOURCE_MODE2_EXT_FITS_FAIL;
                   continue;
               }
@@ -512,5 +533,5 @@
 		       source->moments->Mx, source->moments->My, pmModelClassGetName (modelFit->type), modelFit->chisq, modelFit->nPix, modelFit->nIter);
               Nconvolve ++;
-              if (!(modelFit->flags & (PM_MODEL_STATUS_BADARGS | PM_MODEL_STATUS_NONCONVERGE | PM_MODEL_STATUS_OFFIMAGE))) {
+              if (!(modelFit->flags & badModel)) {
                   NconvolvePass ++;
 		  source->mode |= PM_SOURCE_MODE_EXTENDED_FIT;
@@ -526,9 +547,10 @@
 		      Nfail ++;
 		      doneFits = true;
+		      source->mode2 |= PM_SOURCE_MODE2_EXT_FITS_FAIL;
 		      continue;
 		  }
 		  psTrace ("psphot", 4, "fit plain model for %f, %f : %s chisq = %f (npix: %d, niter: %d)\n", source->moments->Mx, source->moments->My, pmModelClassGetName (modelFit->type), modelFit->chisq, modelFit->nPix, modelFit->nIter);
 		  Nplain ++;
-		  if (!(modelFit->flags & (PM_MODEL_STATUS_BADARGS | PM_MODEL_STATUS_NONCONVERGE | PM_MODEL_STATUS_OFFIMAGE))) {
+		  if (!(modelFit->flags & badModel)) {
 		      NplainPass ++;
 		      source->mode |= PM_SOURCE_MODE_EXTENDED_FIT;
@@ -544,7 +566,5 @@
 		      float Ymax = PAR[PM_PAR_YPOS] + 0.5*PAR[PM_PAR_LENGTH]*cos(PAR[PM_PAR_THETA]);
 
-		      if (false && (source->peak->xf > 1100) && 
-			  (source->peak->xf < 1400) && 
-			  (source->peak->yf < 245)) {
+		      if ((fabs(source->peak->xf - 2572) < 20) && (fabs(source->peak->yf - 5874) < 20)) {
 			  fprintf (stderr, "src vs fit : %d %d - %d %d | %f %f - %f %f\n", 
 				   source->pixels->col0, source->pixels->row0, 
@@ -556,10 +576,10 @@
 			  fprintf (stderr, "update window : %f %f : %f -> %f\n", source->peak->xf, source->peak->yf, fitRadius, 2*fitRadius);
 			  psphotSetWindowTrail (&fitRadius, &windowRadius, readout, source, markVal, fitRadius*2.0);
+			  source->mode2 |= PM_SOURCE_MODE2_EXT_FITS_RETRY;
 		      }
 		  }
 	      }
           }
-	  // XXX really need to do this in a cleaner way:
-	  if (!modelFit) continue;
+	  psAssert (modelFit, "modelFit not set?");
 
           // test for fit quality / result
@@ -570,5 +590,16 @@
         }
 
+	// we are allowed to fit both stars and non-stars here -- if we have fitted
+	// something which we think is a star, we should use that model to subtract the
+	// object from the image.
+        if (source->type == PM_SOURCE_TYPE_STAR) {
+	  // ensure the modelPSF is cached
+	  pmSourceCacheModel (source, maskVal);
+          pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
+          continue;
+        }
+
         // evaluate the relative quality of the models, choose one
+	// the PSF model might be the best fit : allow it to succeed
         float minChisq = NAN;
         int minModel = -1;
@@ -576,9 +607,9 @@
             pmModel *model = source->modelFits->data[i];
 
+	    // skip the really bad fits
             if (!(model->flags & PM_MODEL_STATUS_FITTED)) continue;
-
-            if (model->flags & (PM_MODEL_STATUS_BADARGS)) continue;
-            if (model->flags & (PM_MODEL_STATUS_NONCONVERGE)) continue;
-            if (model->flags & (PM_MODEL_STATUS_OFFIMAGE)) continue;
+            if (model->flags & badModel) continue;
+
+            // if (model->flags & (PM_MODEL_STATUS_NONCONVERGE)) continue;
 
             if ((minModel < 0) || (model->chisq < minChisq)) {
@@ -598,6 +629,15 @@
 	  pmSourceCacheModel (source, maskVal);
 
+# if (PS_TRACE_ON)
+	  pmModel *model = source->modelFits->data[0];
+	  int flags = 0xffffffff;
+	  if (model) {
+	    flags = model->flags;
+	  }
+          fprintf (stderr, "failed to fit extended source model to object %d @ %f, %f (%x)\n", source->id, source->moments->Mx, source->moments->My, flags);
+#endif
           pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
 
+	  source->mode2 |= PM_SOURCE_MODE2_EXT_FITS_NONE;
           continue;
         }
@@ -615,8 +655,11 @@
 	// cache the model flux
 	if (source->modelEXT->isPCM) {
-	    pmPCMCacheModel (source, maskVal, psfSize);
+	    // fprintf (stderr, "subtract PCM extended source model for object %d @ %f, %f\n", source->id, source->moments->Mx, source->moments->My);
+	    pmPCMCacheModel (source, maskVal, psfSize, fitOptions->nsigma);
 	} else {
+	    // fprintf (stderr, "subtract non-PCM extended source model for object %d @ %f, %f\n", source->id, source->moments->Mx, source->moments->My);
 	    pmSourceCacheModel (source, maskVal);
 	}
+        source->modelEXT->flags |= PM_MODEL_BEST_FIT;
 
         // subtract the best fit from the object, leave local sky
@@ -625,4 +668,11 @@
         psTrace ("psphot", 4, "best ext model for %f, %f : %s chisq = %f\n", source->moments->Mx, source->moments->My, pmModelClassGetName (source->modelEXT->type), source->modelEXT->chisq);
         psTrace ("psphot", 5, "extended source model for source at %7.1f, %7.1f", source->moments->Mx, source->moments->My);
+
+# ifdef TEST_OBJECT
+	if (testObject) {
+	    psTraceSetLevel ("psModules.objects.pmPCM_MinimizeChisq", 0);
+	    psTraceSetLevel ("psphot.psphotExtendedSourceFits_Threaded", 0);
+	}
+# endif
     }
 
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotFullForce.SourceStats.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotFullForce.SourceStats.c	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotFullForce.SourceStats.c	(revision 37066)
@@ -0,0 +1,199 @@
+# include "psphotInternal.h"
+
+// construct pixels and measure moments for sources. 
+// NOTE: this function differs from psphotSourceStats in the following ways:
+// 1) detections->allSources are used instead of newSources
+// 2) the sources are used directly (peaks are not assigned to sources here)
+
+// NOTE: this function is meant to be used by psphotFullForce, and the mode of the loaded
+// sources should have (MODE_EXTERNAL) set.  If so, the Mx,My values will not be recalculated
+
+bool psphotFullForceSourceStats (pmConfig *config, const pmFPAview *view, const char *filerule, bool setWindow)
+{
+    bool status = true;
+
+    fprintf (stdout, "\n");
+    psLogMsg ("psphot", PS_LOG_INFO, "--- psphot Source Stats ---");
+
+    // select the appropriate recipe information
+    psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE);
+    psAssert (recipe, "missing recipe?");
+
+    int num = psphotFileruleCount(config, filerule);
+
+    // skip the chisq image (optionally?)
+    // int chisqNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.CHISQ.NUM");
+    // if (!status) chisqNum = -1;
+
+    // loop over the available readouts
+    for (int i = 0; i < num; i++) {
+        // if (i == chisqNum) continue; // skip chisq image
+        if (!psphotFullForceSourceStatsReadout (config, view, filerule, i, recipe, setWindow)) {
+            psError (PSPHOT_ERR_CONFIG, false, "failed to find initial detections for %s entry %d", filerule, i);
+            return false;
+        }
+    }
+    return true;
+}
+
+bool psphotFullForceSourceStatsReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe, bool setWindow) {
+
+    bool status = false;
+
+    psTimerStart ("psphot.stats");
+
+    // find the currently selected readout
+    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, index); // File of interest
+    psAssert (file, "missing file?");
+
+    pmReadout *readout = pmFPAviewThisReadout(view, file->fpa);
+    psAssert (readout, "missing readout?");
+
+    if (psTraceGetLevel("psphot") > 5) {
+	static int pass = 0;
+        char name[64];
+        sprintf (name, "srstats.v%d.fits", pass);
+        psphotSaveImage(NULL, readout->image, name);
+	pass ++;
+    }
+
+    pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS");
+    psAssert (detections, "missing detections?");
+
+    // determine the number of allowed threads
+    int nThreads = psMetadataLookupS32(&status, config->arguments, "NTHREADS"); // Number of threads
+    if (!status) {
+        nThreads = 0;
+    }
+
+    // determine properties (sky, moments) of initial sources
+    float OUTER = psMetadataLookupF32 (&status, recipe, "SKY_OUTER_RADIUS");
+    psAssert (status, "missing SKY_OUTER_RADIUS in recipe?");
+
+    // XXX this seems like an arbitrary number...
+    OUTER = PS_MAX(OUTER, 20.0); // XXX Guarantee that we can encompass the max moments radius
+
+    float INNER        = psMetadataLookupF32 (&status, recipe, "SKY_INNER_RADIUS"); psAssert (status, "missing SKY_INNER_RADIUS");
+    float MIN_SN       = psMetadataLookupF32 (&status, recipe, "MOMENTS_SN_MIN"); psAssert (status, "missing MOMENTS_SN_MIN");
+
+    // bit-masks to test for good/bad pixels
+    psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT");
+    psAssert (maskVal, "missing MASK.PSPHOT");
+
+    // bit-mask to mark pixels not used in analysis
+    psImageMaskType markVal = psMetadataLookupImageMask(&status, recipe, "MARK.PSPHOT");
+    psAssert (markVal, "missing MARK.PSPHOT");
+
+    // psArray *sources = detections->allSources;
+    psArray *sources = detections->newSources ? detections->newSources : detections->allSources;
+
+    // generate the array of sources, define the associated pixel
+    for (int i = 0; i < sources->n; i++) {
+
+        pmSource *source = sources->data[i];
+        psAssert (source->peak, "how can we have a peak-less source?");
+        psAssert (source->moments, "how can we have a moments-less source?");
+
+        // allocate image, weight, mask arrays for each peak (square of radius OUTER)
+        pmSourceDefinePixels (source, readout, source->peak->x, source->peak->y, OUTER);
+    }
+
+    if (setWindow) {
+	// calculate the best gaussian window (keep centroid positions)
+	// NOTE: if sources->mode,mode2 has MODE_EXTERNAL,MODE2_MATCHED, Mx,My are not changed
+        if (!psphotSetMomentsWindow(recipe, readout->analysis, sources, maskVal)) {
+            psError(PS_ERR_UNEXPECTED_NULL, false, "Failed to determine Moments Window!");
+            psFree(detections->newSources);
+            return false;
+        }
+    }
+
+    // if we have measured the window, we will be saving the modified version of these recipe values on readout->analysis
+    float SIGMA = psMetadataLookupF32 (&status, readout->analysis, "MOMENTS_GAUSS_SIGMA");
+    if (!status) {
+        SIGMA = psMetadataLookupF32 (&status, recipe, "MOMENTS_GAUSS_SIGMA");
+    }
+    float RADIUS = psMetadataLookupF32 (&status, readout->analysis, "PSF_MOMENTS_RADIUS");
+    if (!status) {
+        RADIUS = psMetadataLookupF32 (&status, recipe, "PSF_MOMENTS_RADIUS");
+    }
+    float MIN_KRON_RADIUS = psMetadataLookupF32 (&status, readout->analysis, "MOMENTS_MIN_KRON");
+    if (!status) {
+        MIN_KRON_RADIUS = 0.75*SIGMA;
+    }
+
+    // threaded measurement of the source magnitudes
+    int Nfail = 0;
+    int Nmoments = 0;
+    int Nfaint = 0;
+
+    // choose Cx, Cy (see psphotThreadTools.c for overview of the concepts)
+    int Cx = 1, Cy = 1;
+    psphotChooseCellSizes (&Cx, &Cy, readout, nThreads);
+
+    psArray *cellGroups = psphotAssignSources (Cx, Cy, sources);
+
+    for (int i = 0; i < cellGroups->n; i++) {
+
+        psArray *cells = cellGroups->data[i];
+
+        for (int j = 0; j < cells->n; j++) {
+
+            // allocate a job -- if threads are not defined, this just runs the job
+            psThreadJob *job = psThreadJobAlloc ("PSPHOT_SOURCE_STATS");
+
+            psArrayAdd(job->args, 1, cells->data[j]); // sources
+
+            PS_ARRAY_ADD_SCALAR(job->args, INNER,   PS_TYPE_F32);
+            PS_ARRAY_ADD_SCALAR(job->args, MIN_SN,  PS_TYPE_F32);
+            PS_ARRAY_ADD_SCALAR(job->args, RADIUS,  PS_TYPE_F32);
+            PS_ARRAY_ADD_SCALAR(job->args, SIGMA,   PS_TYPE_F32);
+            PS_ARRAY_ADD_SCALAR(job->args, MIN_KRON_RADIUS, PS_TYPE_F32);
+
+            PS_ARRAY_ADD_SCALAR(job->args, maskVal, PS_TYPE_IMAGE_MASK);
+            PS_ARRAY_ADD_SCALAR(job->args, markVal, PS_TYPE_IMAGE_MASK);
+
+            PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nmoments
+            PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfail
+            PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfaint
+
+            if (!psThreadJobAddPending(job)) {
+                psError(PS_ERR_UNKNOWN, false, "Unable to launch thread job PSPHOT_SOURCE_STATS");
+                psFree(detections->newSources);
+                return false;
+            }
+        }
+
+        // wait for the threads to finish and manage results
+        if (!psThreadPoolWait (false, true)) {
+            psError(PS_ERR_UNKNOWN, false, "Failure in thread job PSPHOT_SOURCE_STATS");
+            psFree(detections->newSources);
+            return false;
+        }
+
+        // we have only supplied one type of job, so we can assume the types here
+        psThreadJob *job = NULL;
+        while ((job = psThreadJobGetDone()) != NULL) {
+            if (job->args->n < 1) {
+                fprintf (stderr, "error with job\n");
+            } else {
+                psScalar *scalar = NULL;
+                scalar = job->args->data[8];
+                Nmoments += scalar->data.S32;
+                scalar = job->args->data[9];
+                Nfail += scalar->data.S32;
+                scalar = job->args->data[10];
+                Nfaint += scalar->data.S32;
+            }
+            psFree(job);
+        }
+    }
+
+    psFree (cellGroups);
+
+    psLogMsg ("psphot", PS_LOG_WARN, "%ld sources, %d moments, %d faint, %d failed: %f sec\n", sources->n, Nmoments, Nfaint, Nfail, psTimerMark ("psphot.stats"));
+
+    psphotVisualShowMoments (sources);
+
+    return true;
+}
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotFullForce.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotFullForce.c	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotFullForce.c	(revision 37066)
@@ -0,0 +1,35 @@
+# include "psphotStandAlone.h"
+
+int main (int argc, char **argv) {
+
+    psTimerStart ("complete");
+    pmErrorRegister();                  // register psModule's error codes/messages
+    psphotInit();
+
+    // load command-line arguments, options, and system config data
+    pmConfig *config = psphotFullForceArguments (argc, argv);
+    assert(config);
+
+    psphotVersionPrint();
+
+    // load input data (config and images (signal, noise, mask)
+    if (!psphotParseCamera (config)) {
+        psErrorStackPrint(stderr, "Error setting up the camera\n");
+        exit (psphotGetExitStatus());
+    }
+
+    // call psphot for each readout
+    if (!psphotImageLoop (config, PSPHOT_FULL_FORCE)) {
+        psErrorStackPrint(stderr, "Error in the psphot image loop\n");
+        exit (psphotGetExitStatus());
+    }
+
+    psLogMsg ("psphot", 3, "complete psphot run: %f sec\n", psTimerMark ("complete"));
+
+    psErrorCode exit_status = psphotGetExitStatus();
+    psphotCleanup (config);
+    exit (exit_status);
+}
+
+// all functions which return to this level must raise one of the top-level error codes if they
+// exit with an error.  these error codes are used to specify the program exit status
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotFullForceArguments.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotFullForceArguments.c	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotFullForceArguments.c	(revision 37066)
@@ -0,0 +1,202 @@
+# include "psphotStandAlone.h"
+
+static void usage(const char *program, psMetadata *arg, pmConfig *config, int exitCode);
+static void writeHelpInfo(const char* program, pmConfig* config, FILE* ofile);
+
+pmConfig *psphotFullForceArguments(int argc, char **argv) {
+
+    int N;
+    bool status, status1, status2, status3;
+
+    // load config data from default locations
+    pmConfig *config = pmConfigRead(&argc, argv, PSPHOT_RECIPE);
+    if (config == NULL) {
+      psErrorStackPrint(stderr, "Can't read site configuration");
+	exit(PS_EXIT_CONFIG_ERROR);
+    }
+
+    PS_ARGUMENTS_GENERIC (psphot, config, argc, argv);
+
+    // save the following additional recipe values based on command-line options
+    // these options override the PSPHOT recipe values loaded from recipe files
+    psMetadata *options = pmConfigRecipeOptions (config, PSPHOT_RECIPE);
+
+    // Number of threads is handled
+    PS_ARGUMENTS_THREADS( psphot, config, argc, argv );
+
+    if (psArgumentGet(argc, argv, "-help")) writeHelpInfo(argv[0], config, stdout);
+    if (psArgumentGet(argc, argv, "-h"))    writeHelpInfo(argv[0], config, stdout);
+      
+    // visual : interactive display mode
+    if ((N = psArgumentGet (argc, argv, "-visual"))) {
+        psArgumentRemove (N, &argc, argv);
+        pmVisualSetVisual(true);
+    }
+
+    // break : used from recipe throughout psphotReadout
+    if ((N = psArgumentGet (argc, argv, "-break"))) {
+	if (argc<=N+1) {
+	  psErrorStackPrint(stderr, "Expected to see 1 more argument; saw %d", argc - 1);
+	  exit(PS_EXIT_CONFIG_ERROR);
+	}
+        psArgumentRemove (N, &argc, argv);
+        psMetadataAddStr (options, PS_LIST_TAIL, "BREAK_POINT", PS_META_REPLACE, "", argv[N]);
+        psArgumentRemove (N, &argc, argv);
+    }
+
+    // analysis region : overrides recipe value, used in psphotReadout/psphotEnsemblePSF
+    if ((N = psArgumentGet (argc, argv, "-region"))) {
+	if (argc<=N+1) {
+	  psErrorStackPrint(stderr, "Expected to see 1 more argument; saw %d", argc - 1);
+	  exit(PS_EXIT_CONFIG_ERROR);
+	}
+        psArgumentRemove (N, &argc, argv);
+        psMetadataAddStr (options, PS_LIST_TAIL, "ANALYSIS_REGION", 0, "", argv[N]);
+        psArgumentRemove (N, &argc, argv);
+    }
+
+    // chip selection is used to limit chips to be processed
+    if ((N = psArgumentGet (argc, argv, "-chip"))) {
+	if (argc<=N+1) {
+	  psErrorStackPrint(stderr, "Expected to see 1 more argument; saw %d", argc - 1);
+	  exit(PS_EXIT_CONFIG_ERROR);
+	}
+        psArgumentRemove (N, &argc, argv);
+        psMetadataAddStr (config->arguments, PS_LIST_TAIL, "CHIP_SELECTIONS", PS_DATA_STRING, "", argv[N]);
+        psArgumentRemove (N, &argc, argv);
+    }
+
+    // if these command-line options are supplied, load the file name lists into config->arguments
+    // override any configuration-specified source for these files
+    //
+    pmConfigFileSetsMD (config->arguments, &argc, argv, "MASK",       "-mask",     "-masklist");
+    pmConfigFileSetsMD (config->arguments, &argc, argv, "VARIANCE",   "-variance", "-variancelist");
+
+    pmConfigFileSetsMD (config->arguments, &argc, argv, "PSPHOT.PSF", "-psf",      "-psflist");
+
+    status1 = pmConfigFileSetsMD (config->arguments, &argc, argv, "SRC",     "-src",     "-srclist");
+    status2 = pmConfigFileSetsMD (config->arguments, &argc, argv, "SRCTEXT", "-srctext", "-srctextlist");
+    status3 = pmConfigFileSetsMD (config->arguments, &argc, argv, "FORCE",   "-force",   "-forcelist");
+    
+    if (!(status1 || status2 || status3)) {
+      // XXX require -force version?
+        psError(PSPHOT_ERR_ARGUMENTS, true, "No source list is supplied (use one of -force, -forcelist, -src, -srctext, -srclist, or -srctextlist)");
+	usage(argv[0], config->arguments, config, PS_EXIT_CONFIG_ERROR);
+    }
+
+    if (argc == 1) {
+        psError(PSPHOT_ERR_ARGUMENTS, true, "Too few arguments: %d", argc);
+	usage(argv[0], config->arguments, config, PS_EXIT_CONFIG_ERROR);
+    }
+
+    // the input file is a required argument; if not found, we will exit
+    status = pmConfigFileSetsMD (config->arguments, &argc, argv, "INPUT", "-file", "-list");
+    if (!status) {
+        psError(PSPHOT_ERR_ARGUMENTS, false, "pmConfigFileSetsMD failed to parse arguments");
+	usage(argv[0], config->arguments, config, PS_EXIT_CONFIG_ERROR);
+    }
+
+    if (argc != 2) {
+        psError(PSPHOT_ERR_ARGUMENTS, true, "Expected to see one more argument; saw %d", argc - 1);
+	usage(argv[0], config->arguments, config, PS_EXIT_CONFIG_ERROR);
+    }
+
+    // output position is fixed
+    psMetadataAddStr (config->arguments, PS_LIST_TAIL, "OUTPUT", 0, "", argv[1]);
+
+    psTrace("psphot", 1, "Done with psphotFullForceArguments...\n");
+    return (config);
+}
+
+static void writeHelpInfo(const char* program, pmConfig* config, FILE* ofile)
+{
+  fprintf(ofile,
+	  "Usage: one of the following\n"
+	  "%s -file fname1[,fname2,...] -mask maskfile1[,maskfile2,...]\n"
+	  "     -variance varfile1[,varfile2,...] OutFileBaseName\n"
+	  "\n"
+	  "%s -list FileNameList [-masklist MaskFileNameList] \n"
+	  "     -variancelist VarFileNameList OutFileBaseName\n"
+	  "\n"
+	  "%s -help\n"
+	  "\n"
+	  "%s -version\n"
+	  "\n"
+	  "where:\n"
+	  "  FileNameList is a text file containing filenames, one per line\n"
+	  "  MaskFileNameList is a text file of mask filenames, one per line\n"
+	  "  VarFileNameList is a text file of variance filenames, one per line\n"
+	  "  OutFileBaseName is the 'root name' for output files\n"
+	  "also required:\n"
+	  "  -src SrcFile1[,SrcFile2,...] or -srclist SrcFileNameList\n"
+	  "     specify sources to be measured (required)\n"
+	  "\n"
+	  "additional options:\n"
+	  "  -psf PsfFile1[,PsfFile2,...] or -psflist PsfFileNameList\n"
+	  "     specify PSF rather than letting %s estimate it\n"
+	  "  -chip nn[,nn,...]\n"
+	  "     select detector chips to process; default is all.\n"
+	  "     Indices correspond to zero-based offset in the FPA metadata table.\n"
+	  "  -region RegionString\n"
+	  "     specify analysis region.  String is of form '[x0:x1,y0:y1]'\n"
+	  "     To use this option you must define a default in psphot.config\n"
+	  "  -visual\n"
+	  "     turns on interactive display mode\n"
+	  "  -dumpconfig CfgFileName\n"
+          "     causes config info to be dumped to the named file.\n"
+	  "  -break NOTHING|BACKMDL|PEAKS|MOMENTS|PSFMODEL|ENSEMBLE|PASS1\n"
+	  "     choose a point at which to exit processing early\n"
+	  "  -threads n\n"
+	  "     set number of parallel threads of execution\n"
+	  "  -F OldFileRule ReplacementFileRule\n"
+	  "     change file naming rule; e.g. '-F PSPHOT.OUTPUT PSPHOT.OUT.CMF.MEF'\n"
+	  "  -D name stringval\n"
+	  "     set a string-valued config parameter\n"
+	  "  -Di name intval\n"
+	  "     set an integer-valued config parameter\n"
+	  "  -Df name fval\n"
+	  "     set a float-valued config parameter\n"
+	  "  -Db name boolval\n"
+	  "     set a boolean-valued config parameter\n"
+	  "  -v, -vv, -vvv\n"
+	  "     set increasing levels of verbosity\n"
+	  "  -logfmt FormatString\n"
+	  "     set format string used for log messages\n"
+	  "  -trace Fac Lvl\n"
+	  "     set tracing for facility Fac to integer Lvl, e.g. '-trace err 10'\n"
+	  "  -trace-levels\n"
+	  "     print current trace levels\n",
+	  program,program,program,program,program);
+    psFree(config);
+    pmConfigDone();
+    psLibFinalize();
+    exit(PS_EXIT_SUCCESS);
+}
+
+static void usage(const char *program,  // Name of the program
+                  psMetadata *arguments, // Command-line arguments
+                  pmConfig *config,      // Configuration
+		  int exitCode
+		  ) 
+{
+  fprintf(stderr,
+	  "Usage: one of the following\n"
+	  "%s -file fname1[,fname2,...] -mask maskfile1[,maskfile2,...]\n"
+	  "     -variance varfile1[,varfile2,...] OutFileBaseName\n"
+	  "\n"
+	  "%s -list FileNameList [-masklist MaskFileNameList] \n"
+	  "     -variancelist VarFileNameList OutFileBaseName\n"
+	  "also required:\n"
+	  "  -src SrcFile1[,SrcFile2,...] or -srclist SrcFileNameList\n"
+	  "     specify sources to be measured (required)\n"
+	  "\n"
+	  "Try '%s -help' for more options and explanation\n",
+	  program,program,program);
+    if (exitCode != PS_EXIT_SUCCESS)
+      psErrorStackPrint(stderr, "Error reading arguments\n");
+    psFree(config);
+    pmConfigDone();
+    psLibFinalize();
+    exit(exitCode);
+}
+
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotFullForceImageLoop.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotFullForceImageLoop.c	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotFullForceImageLoop.c	(revision 37066)
@@ -0,0 +1,153 @@
+# include "psphotStandAlone.h"
+
+# define ESCAPE(MESSAGE) {				\
+	psError(PSPHOT_ERR_DATA, false, MESSAGE);	\
+	psFree (view);					\
+	return false;					\
+    }
+
+bool psphotFullForceImageLoop (pmConfig *config) {
+
+    bool status;
+    pmChip *chip;
+    pmCell *cell;
+    pmReadout *readout;
+
+    pmFPAfile *load = psMetadataLookupPtr (&status, config->files, "PSPHOT.LOAD");
+    if (!status) {
+        psError(PSPHOT_ERR_PROG, false, "Can't find input data!");
+        return false;
+    }
+    pmFPAfile *input = psMetadataLookupPtr (&status, config->files, "PSPHOT.INPUT");
+    if (!status) {
+        psError(PSPHOT_ERR_PROG, false, "Can't find input data!");
+        return false;
+    }
+
+    pmFPAview *view = pmFPAviewAlloc (0);
+    pmHDU *lastHDU = NULL;              // Last HDU updated
+
+    // files associated with the science image
+    if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE ("failed input for fpa in psphot.");
+
+    // select the appropriate recipe information
+    psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE);
+    psAssert (recipe, "missing recipe?");
+
+    psImageMaskType maskTest = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT");
+
+    // for psphot, we force data to be read at the chip level
+    while ((chip = pmFPAviewNextChip (view, load->fpa, 1)) != NULL) {
+        psLogMsg ("psphot", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
+        if (! chip->process || ! chip->file_exists) { continue; }
+
+        // load just the input image data (image, mask, weight)
+        pmFPAfileActivate (config->files, false, NULL);
+        pmFPAfileActivate (config->files, true, "PSPHOT.LOAD");
+        pmFPAfileActivate (config->files, true, "PSPHOT.MASK");
+        pmFPAfileActivate (config->files, true, "PSPHOT.VARIANCE");
+        if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE ("failed input for Chip in psphot.");
+
+        // mosaic the cells of a chip into a single contiguous (trimmed) chip
+        if (!psphotMosaicChip(config, view, "PSPHOT.INPUT", "PSPHOT.LOAD")) ESCAPE ("Unable to mosaic chip.");
+
+        // Read WCS if easy.
+        // XXX Since we're mosaicking cells, we ignore the case where the WCS is defined for a cell.
+        {
+            pmChip *inChip = pmFPAviewThisChip(view, input->fpa); // Mosaicked chip
+            pmHDU *hduLow = pmHDUGetLowest(input->fpa, inChip, NULL);
+            if (hduLow && !pmAstromReadWCS(input->fpa, inChip, hduLow->header, 1.0)) {
+                psWarning("Unable to read WCS astrometry from header.");
+                psErrorClear();
+                pmHDU *hduHigh = pmHDUGetHighest(input->fpa, inChip, NULL);
+                if (hduHigh && hduHigh != hduLow &&
+                    !pmAstromReadWCS(input->fpa, chip, hduHigh->header, 1.0)) {
+                    psWarning("Unable to read WCS astrometry from primary header.");
+                    psErrorClear();
+                }
+            }
+        }
+
+        // try to load other supporting data (PSF, SRC, etc).
+        // do not re-load the following three files
+        pmFPAfileActivate (config->files, true, NULL);
+        pmFPAfileActivate (config->files, false, "PSPHOT.LOAD");
+        pmFPAfileActivate (config->files, false, "PSPHOT.MASK");
+        pmFPAfileActivate (config->files, false, "PSPHOT.VARIANCE");
+        if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE ("failed input for Chip in psphot.");
+
+        // re-activate files so they will be closed and freed below
+        pmFPAfileActivate (config->files, true, NULL);
+
+        // there is now only a single chip (multiple readouts?). loop over it and process
+        while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) {
+            psLogMsg ("psphot", 5, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
+
+            // process each of the readouts
+            while ((readout = pmFPAviewNextReadout (view, input->fpa, 1)) != NULL) {
+                psLogMsg ("psphot", 6, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
+                if (! readout->data_exists) { continue; }
+
+                // Update the header
+		pmHDU *hdu = pmHDUGetHighest(input->fpa, chip, cell);
+		if (hdu && hdu != lastHDU) {
+		    psphotVersionHeaderFull(hdu->header);
+		    lastHDU = hdu;
+                }
+
+		// if an external mask is supplied, ensure that NAN pixels are also masked
+		if (readout->mask) {
+		    psImageMaskType maskSat = pmConfigMaskGet("SAT", config); // Mask value for saturated pixels
+                    if (!pmReadoutMaskInvalid(readout, maskTest, maskSat)) {
+			psError(psErrorCodeLast(), false, "Unable to mask non-finite pixels.");
+			psFree(view);
+			return false;
+		    }
+		}
+
+                // run the actual photometry analysis on this chip/cell/readout
+                if (!psphotFullForceReadout (config, view, "PSPHOT.INPUT")) {
+                    psError(psErrorCodeLast(), false, "failure in psphotReadout for chip %d, cell %d, readout %d\n", view->chip, view->cell, view->readout);
+                    psFree (view);
+                    return false;
+                }
+            }
+
+            // drop all versions of the internal files
+            status = true;
+            status &= pmFPAfileDropInternal (config->files, "PSPHOT.BACKMDL");
+            status &= pmFPAfileDropInternal (config->files, "PSPHOT.BACKMDL.STDEV");
+            status &= pmFPAfileDropInternal (config->files, "PSPHOT.BACKGND");
+            if (!status) {
+                psError(PSPHOT_ERR_PROG, false, "trouble dropping internal files");
+                psFree (view);
+                return false;
+            }
+        }
+
+        // save output which is saved at the chip level
+        if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE ("failed output for Chip in psphot.");
+    }
+    // save output which is saved at the fpa level
+    if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE ("failed ouput for FPA in psphot.");
+
+    // fail if we failed to handle an error
+    if (psErrorCodeLast() != PS_ERR_NONE) psAbort ("failed to handle an error!");
+
+    psFree (view);
+    return true;
+}
+
+// I/O files related to psphot:
+// PSPHOT.INPUT   : input image file(s)
+// PSPHOT.RESID   : residual image
+// PSPHOT.OUTPUT  : output object tables (object)
+
+// PSPHOT.BACKSUB : background subtracted image
+// PSPHOT.BACKGND : background model (full-scale image?)
+// PSPHOT.BACKMDL : background model (binned image?)
+// PSPHOT.PSF     : sample PSF images
+
+// PSPHOT.MASK
+// PSPHOT.VARIANCE
+//
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotFullForceReadout.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotFullForceReadout.c	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotFullForceReadout.c	(revision 37066)
@@ -0,0 +1,134 @@
+# include "psphotInternal.h"
+
+bool psphotFullForceReadout(pmConfig *config, const pmFPAview *view, const char *filerule) {
+
+    // measure the total elapsed time in psphotReadout.  
+    psTimerStart ("psphotReadout");
+
+    // allow objects to be fit with ugly models (central holes, extreme asymmetry, etc)
+    pmModelClassSetLimits(PM_MODEL_LIMITS_LAX);
+
+    // select the current recipe
+    psMetadata *recipe = psMetadataLookupPtr (NULL, config->recipes, PSPHOT_RECIPE);
+    if (!recipe) {
+        psError(PSPHOT_ERR_CONFIG, false, "missing recipe %s", PSPHOT_RECIPE);
+        return false;
+    }
+
+    // set the photcode for this image
+    if (!psphotAddPhotcode (config, view, filerule)) {
+        psError (PSPHOT_ERR_CONFIG, false, "trouble defining the photcode");
+        return false;
+    }
+
+    // optional break-point for processing
+    char *breakPt = psMetadataLookupStr (NULL, recipe, "BREAK_POINT");
+    PS_ASSERT_PTR_NON_NULL (breakPt, false);
+
+    // Generate the mask and weight images, including the user-defined analysis region of interest
+    psphotSetMaskAndVariance (config, view, filerule);
+    if (!strcasecmp (breakPt, "NOTHING")) {
+        return psphotReadoutCleanup (config, view, filerule);
+    }
+
+    // generate a background model (median, smoothed image)
+    if (!psphotModelBackground (config, view, filerule)) {
+        return psphotReadoutCleanup (config, view, filerule);
+    }
+    if (!psphotSubtractBackground (config, view, filerule)) {
+        return psphotReadoutCleanup (config, view, filerule);
+    }
+    if (!strcasecmp (breakPt, "BACKMDL")) {
+        return psphotReadoutCleanup (config, view, filerule);
+    }
+
+    if (!psphotLoadPSF (config, view, filerule)) {
+    	// this only happens if we had a programming error in psphotLoadPSF
+        psError (PSPHOT_ERR_UNKNOWN, false, "error loading psf model");
+        return psphotReadoutCleanup (config, view, filerule);
+    }
+
+    // include externally-supplied sources (loaded onto detections->newSources)
+    psphotLoadExtSources (config, view, filerule);
+
+#ifdef notmoved
+    // XXX: moved down below
+    // merge the newly selected sources into the existing list (detections->allSources)
+    // NOTE: merge OLD and NEW
+    psphotMergeSources (config, view, filerule);
+#endif
+
+    // construct sources and measure moments and other basic stats (saved on detections->allSources)
+    // all sources use the auto-scaled window appropriate to a PSF, except for the saturated
+    // stars : these use a larger window (3x the basic window)
+    if (!psphotFullForceSourceStats (config, view, filerule, true)) { // pass 1
+        psError(PSPHOT_ERR_UNKNOWN, false, "failure to generate sources");
+        return psphotReadoutCleanup (config, view, filerule);
+    }
+    
+    // classify sources based on moments, brightness.  if a PSF model has been loaded, the PSF
+    // clump defined for it is used not measured (detections->newSources)
+    if (!psphotRoughClass (config, view, filerule)) { // pass 1
+        psError (PSPHOT_ERR_UNKNOWN, false, "failed to determine rough classifications");
+        return psphotReadoutCleanup (config, view, filerule);
+    }
+
+    // merge the newly selected sources into the existing list (detections->allSources)
+    // NOTE: merge OLD and NEW
+    psphotMergeSources (config, view, filerule);
+
+    // generate a psf model for any readouts which need one
+    // psphotFullForcePSF (config, view, filerule);
+    // XXX I'm not sure we need a different algorithm here or not : we are supplying the
+    // sources; we should mark with a flag bit the ones we actually want to use as PSF
+    // stars (this means we need to supply this info in the load).
+    if (!psphotChoosePSF (config, view, filerule, false)) {
+        // PSPHOT_ERR_DATA causes this program to exit gracefully
+        psError (PSPHOT_ERR_DATA, false, "failed to construct psf model");
+        return  psphotReadoutCleanup (config, view, filerule);
+    }
+
+    // Construct an initial model for each object, set the radius to fitRadius, set circular
+    // fit mask.  NOTE: only applied to sources without guess models
+    // XXX this currently only generates a PSF model
+    psphotGuessModels (config, view, filerule);
+
+    // linear PSF fit to source peaks, subtract the models from the image (in PSF mask)
+    // XXX this will fit non-PSF sources if they are supplied
+    psphotFitSourcesLinear (config, view, filerule, false, false);
+
+    // measure moments
+    // XXX does this set the correct gaussian window (how to do multiple windows?)
+    // we are calling this above...
+    // psphotSourceStats (config, view, filerule, false);
+
+    // measure kron fluxes
+    psphotKronFlux (config, view, filerule);
+
+    // measure petro fluxes
+    psphotPetroFlux (config, view, filerule);
+
+    // measure radial apertures
+    psphotRadialApertures (config, view, filerule, 0);
+
+    // measure galaxy shapes
+    psphotGalaxyShape (config, view, filerule);
+
+    // calculate source magnitudes (psf mag and ap mag)
+    psphotMagnitudes(config, view, filerule);
+
+    // calculate lensing parameters
+    if (!psphotLensing(config, view, filerule)) {
+	psErrorStackPrint(stderr, "Unable to do lensing parameters.");
+        psErrorClear();
+    }
+
+    // replace background in residual image
+    psphotSkyReplace (config, view, filerule);
+
+    // drop the references to the image pixels held by each source
+    psphotSourceFreePixels (config, view, filerule);
+
+    // create the exported-metadata and free local data
+    return psphotReadoutCleanup (config, view, filerule);
+}
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotFullForceSummary.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotFullForceSummary.c	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotFullForceSummary.c	(revision 37066)
@@ -0,0 +1,337 @@
+# ifdef HAVE_CONFIG_H
+# include <config.h>
+# endif
+
+#include <stdio.h>
+#include <pslib.h>
+#include <psmodules.h>
+#include "psphot.h"
+
+// For simplicilty, this program's (simple) functions are all contained in this file.
+static pmConfig* psphotFullForceSummaryArguments(int, char**);
+static bool psphotFullForceSummaryParseCamera(pmConfig *);
+static bool psphotFullForceSummaryImageLoop(pmConfig*);
+
+int main (int argc, char **argv) {
+
+    psMemInit();
+    psTimerStart ("complete");
+    pmErrorRegister();                  // register psModule's error codes/messages
+    psphotInit();
+
+    // load command-line arguments, options, and system config data
+    pmConfig *config = psphotFullForceSummaryArguments (argc, argv);
+    assert(config);
+
+//    psphotVersionPrint();
+
+    if (!psphotFullForceSummaryParseCamera (config)) {
+        psErrorStackPrint(stderr, "Error setting up the camera\n");
+        exit (1);
+    }
+
+    if (!psphotFullForceSummaryImageLoop (config)) {
+        psErrorStackPrint(stderr, "Error in the psphot image loop\n");
+        exit(1);
+    }
+
+    // XXX:check for memory leaks
+    exit (0);
+}
+
+// all functions which return to this level must raise one of the top-level error codes if they
+// exit with an error.  these error codes are used to specify the program exit status
+
+void usage() {
+    fprintf(stderr, "usage: psphotFullForceSummary -inputs <input list> <output>\n");
+    exit (1);
+}
+
+static pmConfig* psphotFullForceSummaryArguments(int argc, char **argv) {
+
+    pmConfig *config =  pmConfigRead(&argc, argv, PSPHOT_RECIPE);
+    int N;
+
+    if (config == NULL) {
+        psErrorStackPrint(stderr, "Can't read site configuration");
+	exit(PS_EXIT_CONFIG_ERROR);
+    }
+    if ((N = psArgumentGet(argc, argv, "-input"))) {
+        if (argc <= N+1) {
+          psErrorStackPrint(stderr, "Expected to see 1 more argument; saw %d", argc - 1);
+          usage();
+        }
+        psArgumentRemove(N, &argc, argv);
+
+        unsigned int numBad = 0;                     // Number of bad lines
+        psMetadata *inputs = psMetadataConfigRead(NULL, &numBad, argv[N], false); // Input file info
+        if (!inputs || numBad > 0) {
+            psErrorStackPrint(stderr, "Unable to cleanly read MDC file with inputs.");
+            exit(PS_EXIT_CONFIG_ERROR);
+        }
+        psMetadataAddMetadata(config->arguments, PS_LIST_TAIL, "INPUTS", 0, "Metadata with input details", inputs);
+        psFree(inputs);
+
+        psArgumentRemove(N, &argc, argv);
+    } else {
+        psErrorStackPrint(stderr, "-input must be supplied.");
+        usage();
+    }
+    if ((N = psArgumentGet(argc, argv, "-cff"))) {
+        if (argc <= N+1) {
+          psErrorStackPrint(stderr, "Expected to see 1 more argument; saw %d", argc - 1);
+          usage();
+        }
+        psArgumentRemove(N, &argc, argv);
+
+        // We read CFF file as table not as sources. All we want are the nominal parameters input to psphotFullForce
+        psMetadataAddStr(config->arguments, PS_LIST_TAIL, "CFF_FILE", 0, "CFF file with nominal parameters", argv[N]);
+        psArgumentRemove(N, &argc, argv);
+    } else {
+        psErrorStackPrint(stderr, "-cff must be supplied.");
+        usage();
+    }
+ 
+    if (argc < 2) {
+        psErrorStackPrint(stderr, "Output is required.");
+        usage();
+    }
+    psMetadataAddStr(config->arguments, PS_LIST_TAIL, "OUTPUT", PS_DATA_STRING, "", argv[1]);
+
+    return config;
+}
+
+static bool psphotFullForceSummaryParseCamera(pmConfig *config) {
+    bool status = false;
+
+    psMetadata *inputs = psMetadataLookupMetadata(&status, config->arguments, "INPUTS"); // The inputs info
+    if (!inputs) {
+	psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find inputs.");
+	return false;
+    }
+
+    int nInputs = inputs->list->n;
+
+    for (int i = 0; i < nInputs; i++) {
+        psMetadataItem *item = psMetadataGet(inputs, i);
+
+        if (item->type != PS_DATA_STRING) {
+            psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Component %s of the input metadata is not of type STRING", item->name);
+	    return false;
+
+        }
+        psString sourcesFilename = item->data.str;
+
+        psArray *dummy = psArrayAlloc(1);   // dummy array of filenames
+        dummy->data[0] = psStringCopy(sourcesFilename);
+
+        psMetadataAddArray(config->arguments, PS_LIST_TAIL, "FILENAMES", PS_META_REPLACE, 
+            "Filenames for file rule definition", dummy);
+        psFree(dummy);
+
+        bool found = false;
+        pmFPAfile *file = pmFPAfileDefineFromArgs(&found, config, "PSPHOT.INPUT.CMF", "FILENAMES");
+        if (!file || !found) {
+            psError(PS_ERR_UNKNOWN, false, "Unable to define file %s from %s", "PSPHOT.INPUT.CMF", sourcesFilename);
+            return false;
+        }
+        if (file->type != PM_FPA_FILE_CMF) {
+            psError(PS_ERR_IO, true, "%s is not of type %s", sourcesFilename, pmFPAfileStringFromType(PM_FPA_FILE_CMF));
+            return false;
+        }
+    }
+    psMetadataRemoveKey(config->arguments, "FILENAMES");
+    psMetadataAddS32 (config->arguments, PS_LIST_TAIL, "PSPHOT.INPUT.CMF.NUM", PS_META_REPLACE, "number of inputs",
+        nInputs);
+
+
+    pmFPA *outputFPA = pmFPAConstruct(config->camera, config->cameraName);
+        if (!outputFPA) {
+        psError(psErrorCodeLast(), false, "Unable to construct an FPA from camera configuration.");
+        return false;
+    }
+    pmFPAfile *output = pmFPAfileDefineOutput(config, outputFPA, "PSPHOT.FULLFORCE.OUTPUT");
+    psFree(outputFPA);                        // Drop reference
+    if (!output) {
+        psError(psErrorCodeLast(), false, _("Unable to generate output file from PSPHOT.FULLFORCE.OUTPUT"));
+        return false;
+    }
+    if (output->type != PM_FPA_FILE_CMF) {
+        psError(PSPHOT_ERR_CONFIG, true, "PSPHOT.FULLFORCE.OUTPUT is not of type CMF");
+        return false;
+    }
+    output->save = true;
+
+    // We read cff file as a table not as sources
+    psString cffName = psMetadataLookupStr(NULL, config->arguments, "CFF_FILE");
+    if (!cffName) {
+        psError(PSPHOT_ERR_CONFIG, true, "CFF_FILE is missing from arguments");
+        return false;
+    }
+    psString resolvedName = pmConfigConvertFilename(cffName, config, false, false);
+    if (!resolvedName) {
+        psError(PSPHOT_ERR_CONFIG, false, "failed to resolve CFF_FILE %s", cffName);
+        return false;
+    }
+    psFits *fits = psFitsOpen(resolvedName, "r");
+    if (!fits) {
+        psError(PSPHOT_ERR_CONFIG, false, "failed to open fits CFF_FILE %s", resolvedName);
+        return false;
+    }
+    psArray *inTable = psFitsReadTable(fits);
+    if (!inTable) {
+        psError(PSPHOT_ERR_CONFIG, false, "failed to read cff fits table from CFF_FILE %s", resolvedName);
+        return false;
+    }
+    psFitsClose(fits);
+
+    // Convert to a set of arrays indexed by model type + 1
+    // which contain pointers to arrays indexed by ID
+#define MAX_MODEL_TYPE 10
+    psArray *sortedTables = psArrayAlloc(MAX_MODEL_TYPE+1);
+    for (int i=0; i<inTable->n; i++) {
+        psMetadata *row = inTable->data[i];
+        psS32 ID = psMetadataLookupS32(&status, row, "ID");
+        psS32 modelType = psMetadataLookupS32(&status, row, "MODEL_TYPE");
+        // XXX: need to use the lookup table functions to be ready for changes in the model type numbers
+        if (modelType+1 >= MAX_MODEL_TYPE) {
+            psError(PSPHOT_ERR_CONFIG, false, "found modelType %d max allowed is %d", modelType, MAX_MODEL_TYPE);
+            return false;
+        }
+        psArray *sortedTable = sortedTables->data[modelType+1];
+        if (!sortedTable) {
+            sortedTable = psArrayAlloc(4*inTable->n);
+            sortedTables->data[modelType+1] = sortedTable;
+            // dont' free sortedTable the array of tables gets our reference
+        }
+        if (ID >= sortedTable->n) {
+            sortedTable = psArrayRealloc(sortedTable, 2*ID);
+            // Why doesn't psArrayRealloc do this?????
+                sortedTable->n = sortedTable->nalloc;
+        }
+        if (sortedTable->data[ID]) {
+            psError(PSPHOT_ERR_CONFIG, true, "Duplicate row with ID %d", ID);
+            return false;
+        }
+        sortedTable->data[ID] = psMemIncrRefCounter(row);
+    }
+    psMetadataAddArray(config->arguments, PS_LIST_TAIL, "CFF_TABLES", PS_META_REPLACE, "cff tables", sortedTables);
+    psFree(inTable);
+    psFree(sortedTables);
+
+    return true;
+}
+
+# define ESCAPE(MESSAGE) {				\
+	psError(PSPHOT_ERR_DATA, false, MESSAGE);	        \
+	psFree (view);					\
+	return false;					\
+    }
+
+bool psphotFullForceSummaryImageLoop (pmConfig *config) {
+
+    bool status;
+    pmChip *chip;
+    pmCell *cell;
+    pmReadout *readout;
+
+    pmFPAfile *input = psMetadataLookupPtr (&status, config->files, "PSPHOT.INPUT.CMF");
+    if (!status) {
+        psError(PSPHOT_ERR_PROG, false, "Can't find input data!");
+        return false;
+    }
+
+    pmFPAfile *output = psMetadataLookupPtr (&status, config->files, "PSPHOT.FULLFORCE.OUTPUT");
+    if (!output) {
+        psError(PSPHOT_ERR_PROG, false, "Can't find output data!");
+        return false;
+    }
+
+    pmFPAview *view = pmFPAviewAlloc (0);
+    if (!pmFPAAddSourceFromView(output->fpa, view, output->format)) {
+        psError(PS_ERR_UNKNOWN, false, "Unable to insert HDU into FPA for writing.\n");
+        psFree(view);
+        return NULL;
+    }
+
+    // files associated with the science image
+    if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE ("failed input for fpa in psphot.");
+
+
+    // select the appropriate recipe information
+    psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE);
+    psAssert (recipe, "missing recipe?");
+
+    while ((chip = pmFPAviewNextChip (view, input->fpa, 1)) != NULL) {
+//        psLogMsg ("psphotFullForceSummary", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
+        if (! chip->process || ! chip->file_exists) { continue; }
+
+        if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE ("failed input for Chip in psphotFullForceSummary.");
+
+        // We read the WCS from the first input
+        {
+            pmHDU *hduLow = pmHDUGetLowest(input->fpa, chip, NULL);
+            if (hduLow && !pmAstromReadWCS(input->fpa, chip, hduLow->header, 1.0)) {
+                psWarning("Unable to read WCS astrometry from header.");
+                psErrorClear();
+                pmHDU *hduHigh = pmHDUGetHighest(input->fpa, chip, NULL);
+                if (hduHigh && hduHigh != hduLow &&
+                    !pmAstromReadWCS(input->fpa, chip, hduHigh->header, 1.0)) {
+                    psWarning("Unable to read WCS astrometry from primary header.");
+                    psErrorClear();
+                }
+            }
+        }
+
+        // Copy the transformations from the input
+        output->fpa->fromTPA = psMemIncrRefCounter(input->fpa->fromTPA);
+        output->fpa->toTPA = psMemIncrRefCounter(input->fpa->toTPA);
+        output->fpa->toSky = psMemIncrRefCounter(input->fpa->toSky);
+        pmChip *outputChip = pmFPAviewThisChip(view, output->fpa);
+        outputChip->toFPA = psMemIncrRefCounter(chip->toFPA);
+        outputChip->fromFPA = psMemIncrRefCounter(chip->fromFPA);
+        if (output->fpa->hdu->header == NULL) {
+            output->fpa->hdu->header = psMetadataAlloc();
+        }
+        // XXX: how come psphot and psphotStack don't have to do this?
+        if (!pmAstromWriteWCS(output->fpa->hdu->header, output->fpa, outputChip, 0.001)) {
+            ESCAPE("failure to copy WCS to header");
+        }
+
+        // there is now only a single chip (multiple readouts?). loop over it and process
+        while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) {
+ //           psLogMsg ("psphotFullForceSummary", 5, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
+
+            // process each of the readouts
+            while ((readout = pmFPAviewNextReadout (view, input->fpa, 1)) != NULL) {
+//                psLogMsg ("psphotFullForceSummary", 6, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
+                if (! readout->data_exists) { continue; }
+
+                if (!psphotFullForceSummaryReadout(config, view)) {
+                    ESCAPE ("failure in psphotFullForceSummaryReadout");
+                }
+            }
+        }
+        if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE ("failed pmFPAfileIOChecks for Chip in psphotFullForceSummary.");
+    }
+
+
+    // If these keywords are not set we get a warning message on output. Since we are not copying the input header
+    // and do not have an image pmFPA stuff doesn't have values for these
+    // XXX: What other keywords and concepts should be set (or copied)?
+    int numCols = psMetadataLookupS32(&status, input->fpa->hdu->header, "IMNAXIS1");
+    int numRows = psMetadataLookupS32(&status, input->fpa->hdu->header, "IMNAXIS2");
+    psMetadataAddS32(output->fpa->hdu->header, PS_LIST_TAIL, "IMNAXIS1", PS_META_REPLACE, "", numCols);
+    psMetadataAddS32(output->fpa->hdu->header, PS_LIST_TAIL, "IMNAXIS2", PS_META_REPLACE, "", numRows);
+
+    // XXX: Also add psphot version information
+
+    if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE ("failed pmFPAfileIOChecks for FPA in psphot.");
+
+    // fail if we encountered an unhandled error
+    if (psErrorCodeLast() != PS_ERR_NONE) psAbort ("failed to handle an error!");
+
+    psFree (view);
+
+    return true;
+}
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotFullForceSummaryReadout.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotFullForceSummaryReadout.c	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotFullForceSummaryReadout.c	(revision 37066)
@@ -0,0 +1,739 @@
+#include "psphotInternal.h"
+
+
+typedef struct {
+    psF32   Q;
+    psF32   NSigma;
+    psF32   clampSN;
+#ifdef notdef
+    // these are per object now
+    int     numTrials;
+    psF64   fRmajorMin;
+    psF64   fRmajorMax;
+    psF64   fRmajorDel;
+    psF64   fRminorMin;
+    psF64   fRminorMax;
+    psF64   fRminorDel;
+    psVector    *fRmajor;
+    psVector    *fRminor;
+#endif
+    psArray *zeroPt;    // zero points for each input used with exptime to scale flux
+    psArray *exptime;   // exposure times for each input
+    psArray *cffTables; // one for each model type index is (model_type + 1) entry 0 is no extended model (star)
+} galaxyShapeSummaryOptions;
+
+
+
+static pmSource *psphotFullForceSummarizeObject(pmConfig *config, pmPhotObj *obj, psVector *fluxScaleFactor, galaxyShapeSummaryOptions *options);
+static pmPhotObj *findObjectForSource(psArray **pObjects, pmSource *source);
+
+static bool setOptions(galaxyShapeSummaryOptions *options, pmReadout *readout, psMetadata *recipe, bool saveVectors);
+static bool checkOptions(galaxyShapeSummaryOptions *options, pmReadout *readout, psMetadata *recipe);
+
+
+bool psphotFullForceSummaryReadout (pmConfig *config, const pmFPAview *view) {
+
+    bool status;
+    psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE);
+    psAssert (recipe, "missing recipe?");
+
+    int num = psphotFileruleCount(config, "PSPHOT.INPUT.CMF");
+
+    pmFPAfile *output = psMetadataLookupPtr (&status, config->files, "PSPHOT.FULLFORCE.OUTPUT");
+    pmCell *outputCell = pmFPAviewThisCell(view, output->fpa);
+    pmReadout *outputReadout = pmFPAviewThisReadout(view, output->fpa);
+    if (!outputReadout) {
+        outputReadout = pmReadoutAlloc(outputCell);
+    }
+
+    // Get the exposure parameters for the output from recipe and set them on the output
+    psF32 outputZeroPoint = psMetadataLookupF32(&status, recipe, "PSPHOT.FULLFORCE.ZERO_PT");
+    psF32 outputExptime = psMetadataLookupF32(&status, recipe, "PSPHOT.FULLFORCE.EXPTIME");
+
+    psMetadataAddF32(output->fpa->concepts, PS_LIST_TAIL, "FPA.ZP", PS_META_REPLACE, "Magnitude zero point",
+        outputZeroPoint);
+    psMetadataAddF32(outputCell->concepts, PS_LIST_TAIL, "CELL.EXPOSURE", PS_META_REPLACE, "Exposure time (sec)",
+        outputExptime);
+
+    // Create objects from the various input's sources
+    // loop over the available readouts
+
+    psVector *fluxScaleFactor = psVectorAlloc(num, PS_TYPE_F32);
+    galaxyShapeSummaryOptions options;
+    psArray *objects = NULL;
+    for (int index = 0; index < num; index++) {
+        // find the currently selected readout
+        pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PSPHOT.INPUT.CMF", index); // File of interest
+        psAssert (file, "missing file?");
+
+        pmReadout *readout = pmFPAviewThisReadout(view, file->fpa);
+        psAssert (readout, "missing readout?");
+
+        if (index == 0) {
+            // Get the galaxy shape recipe values, from the analysis if present
+            // or from the recipe if not
+            if (!setOptions(&options, readout, recipe, true)) {
+                psError (PS_ERR_UNKNOWN, false, "problem determining galaxy shape options.");
+                return false;
+            }
+            options.cffTables = psMetadataLookupPtr(NULL, config->arguments, "CFF_TABLES");
+            if (!options.cffTables) {
+                psError (PS_ERR_UNKNOWN, true, "Cannot find cff table in arguments.");
+                return false;
+            }
+        } else { 
+            // Make sure that this input was created with the same galaxy shapes recipe
+            if (!checkOptions(&options, readout, recipe)) {
+                psError (PS_ERR_UNKNOWN, false, "galaxy shape options do not match for input %d", index);
+                return false;
+            }
+        }
+
+        // look up zero point
+        psF32 zero_point = psMetadataLookupF32(&status, readout->parent->parent->parent->concepts, "FPA.ZP");
+        psF32 exptime = psMetadataLookupF32(&status, readout->parent->parent->parent->concepts, "FPA.EXPOSURE");
+
+        psF32 scaleFactor = pow(10, 0.4 * (outputZeroPoint - zero_point)) * outputExptime / exptime;
+        fluxScaleFactor->data.F32[index] = scaleFactor;
+
+        // find detections
+        pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS");
+        psAssert (detections, "missing detections?");
+        psArray *sources = detections->allSources;
+        psAssert (sources, "missing sources?");
+        sources = psArraySort (sources, pmSourceSortBySeq);
+
+        if (objects == NULL) {
+            pmSource *lastSource = sources->data[sources->n - 1];
+            psAssert(lastSource, "last source is null!");
+            objects = psArrayAlloc(lastSource->seq + 1);
+        }
+
+        for (int i=0; i < sources->n; i++) {
+            pmSource *source = sources->data[i];
+            source->imageID = index;
+            findObjectForSource(&objects, source);
+        }
+    }
+
+    pmDetections *outputDetections = pmDetectionsAlloc();
+    if (!psMetadataAddPtr (outputReadout->analysis, PS_LIST_TAIL, "PSPHOT.DETECTIONS", 
+            PS_META_REPLACE | PS_DATA_UNKNOWN, "psphot detections", outputDetections)) {
+        psError (PSPHOT_ERR_CONFIG, false, "problem saving detections on readout");
+        return false;
+    }
+
+    psArray *outputSources = psArrayAllocEmpty (objects->n);
+
+    // Loop over objects and compute the summaries
+    long nObjects = 0;
+    long nSources = 0;
+    for (int i=0 ; i<objects->n; i++) {
+        pmPhotObj *obj = objects->data[i];
+        if (!obj) continue;
+
+        ++nObjects;
+        pmSource *source = psphotFullForceSummarizeObject(config, obj, fluxScaleFactor, &options);
+        if (source) {
+            psArrayAdd (outputSources, 100, source);
+            ++nSources;
+        }
+    }
+
+    psLogMsg("psphot", PS_LOG_INFO, "constructed %ld output sources, from %ld objects.", nSources, nObjects);
+
+    psFree(fluxScaleFactor);
+
+    if (nSources) {
+        // We have data
+        outputDetections->allSources = outputSources;
+        outputReadout->data_exists = true;
+        outputReadout->parent->data_exists = true;
+        outputReadout->parent->parent->data_exists = true;
+    } else {
+        // XXX: tooo set a quality or fault code
+        return false;
+    }
+
+    return true;
+}
+
+static pmPhotObj *findObjectForSource(psArray **pObjects, pmSource *source) {
+    int seq = source->seq;
+
+    psArray *objects = *pObjects;
+    if (seq >= objects->n) {
+        // We need to expand the object array. Kind of suprising.
+        objects = *pObjects = psArrayRealloc(objects, seq+1);
+    }
+
+    // Look up object for this seq
+    pmPhotObj *obj = objects->data[seq];
+    if (!obj) {
+        // not found allocate one
+        obj = pmPhotObjAlloc();
+        objects->data[seq] = obj;
+    }
+    pmPhotObjAddSource(obj, source);
+
+    return obj;
+}
+
+static pmSource *psphotFullForceSummarizeObject(pmConfig *config, pmPhotObj *obj, psVector *fluxScaleFactor, galaxyShapeSummaryOptions *options) {
+
+    pmSource *outSrc = NULL;
+
+
+    pmSource *source0 = obj->sources->data[0];
+    int ID = source0->seq;
+
+    // Find the parameters from the cff tables. nModels is the number of extended model types that
+    // this source has an entry for
+    int nModels = 0;
+    // skip table 0 which is modelType -1 not extended
+    for (int i=1; i<options->cffTables->n; i++) {
+        psArray *table = options->cffTables->data[i];
+        if (!table) continue;
+        if (ID >= table->n) continue;
+        if (table->data[ID]) {
+            nModels++;
+        }
+    }
+
+    // Loop over sources for this object. Start output source for first input that has
+    // good pixel frac
+    for (int i=0; i < obj->sources->n; i++) {
+        pmSource *source = obj->sources->data[i];
+
+        // XXX: get cut from recipe
+        if (source->pixWeightNotPoor < .9) continue;
+
+        // For now just start the output source as a copy of the first input source that makes cuts
+        if (!outSrc) {
+            outSrc = pmSourceCopy(source);
+            // This copies 
+            //  the peak 
+            //  the moments which are mostly nan except for Mrf Mx, My, and some of the kron parameters
+            //
+            // type, mode, flags
+            // magnitudes
+            outSrc->imageID = 0;
+            outSrc->seq = source->seq;
+
+            if (source->modelPSF) {
+                outSrc->modelPSF = psMemIncrRefCounter(source->modelPSF);
+            }
+            if (source->extpars) {
+                outSrc->extpars =  psMemIncrRefCounter(source->extpars);
+            }
+        }
+        if (nModels && source->modelFits && source->modelFits->n) {
+            if (!outSrc->modelFits) {
+                outSrc->modelFits = psArrayAllocEmpty(nModels);
+            }
+            for (int iModel = 0; iModel < source->modelFits->n; iModel++) {
+                pmModel *newModel = source->modelFits->data[iModel];
+                pmModel *outModel = NULL;
+                for (int jModel = 0; jModel < outSrc->modelFits->n; jModel++) {
+                    outModel = outSrc->modelFits->data[jModel];
+                    if (newModel->type == outModel->type)  {
+                        // already have an entry for this type
+                        break;
+                    }
+                    outModel = NULL;
+                }
+                if (!outModel) {
+                    // no model of this type in output source yet. Add this one.
+                    // Note: the parameters that we need (position, angle, index, if applicable)
+                    // are the same for all sources so copying any of them is fine
+                    psArrayAdd(outSrc->modelFits, 1, newModel);
+                }
+            }
+        }
+    }
+
+    if (!outSrc) {
+        // no good measurements for this source (how?)
+        return NULL;
+    }
+
+    // now loop over the model fits and summarize the galaxy shape measurements for each
+    for (int iModel=0; outSrc->modelFits && iModel < outSrc->modelFits->n; iModel++) {
+        pmModel *model = outSrc->modelFits->data[iModel];
+        int modelType = model->type;
+        psAssert(modelType >= 0 && modelType+1 < options->cffTables->n, "model type out of range");
+
+        psArray *cffTable = options->cffTables->data[modelType+1];
+        psAssert(cffTable, "missing cff table?");
+
+        psMetadata *cffRow = cffTable->data[outSrc->seq];
+        if (!cffRow) {
+            psError (PS_ERR_PROGRAMMING, true, "NO cff data for object %d model %d", outSrc->seq, modelType);
+            psFree(outSrc);
+            return NULL;
+        }
+        bool mdok;
+        psF32 R_MAJOR = psMetadataLookupF32(&mdok, cffRow, "R_MAJOR");
+        if (!mdok) {
+            psError (PS_ERR_PROGRAMMING, true, "can't find R_MAJOR for object %d type %d", outSrc->seq, modelType);
+            psFree(outSrc);
+            return NULL;
+        }
+        psF32 R_MINOR = psMetadataLookupF32(&mdok, cffRow, "R_MINOR");
+        if (!mdok) {
+            psError (PS_ERR_PROGRAMMING, true, "can't find R_MINOR for object %d type %d", outSrc->seq, modelType);
+            psFree(outSrc);
+            return NULL;
+        }
+
+        psVector *sumWeightedFlux = NULL;
+        psVector *sumInvSig2 = NULL;
+        psVector *numerator   = NULL;
+        psVector *fRmajorVec = NULL;
+        psVector *fRminorVec = NULL;
+        psF32   totalNPix = 0;
+        long    vectorLength = 0;
+        psF32   fRmajorMin = 0;
+        psF32   fRmajorMax = 0;
+        psF32   fRmajorDel = 0;
+        psF32   fRminorMin = 0;
+        psF32   fRminorMax = 0;
+        psF32   fRminorDel = 0;
+        for (int i=0; i < obj->sources->n; i++) {
+            pmSource *source = obj->sources->data[i];
+
+            if (source->pixWeightNotPoor < .9) continue;
+
+            // The only parameters that we are summarizing currently are galaxy shapes. 
+            if (!source->modelFits) continue;
+            if (!source->galaxyFits) continue;
+
+            // XXX: put this into a function
+            pmSourceGalaxyFits *galaxyFits = NULL;
+            for (int j=0; j<source->galaxyFits->n; j++) {
+                galaxyFits = source->galaxyFits->data[j];
+                if (galaxyFits && galaxyFits->modelType == modelType) break;
+                galaxyFits = NULL;
+            }
+
+            if (galaxyFits && isfinite(galaxyFits->nPix) && galaxyFits->chisq->n) {
+                if (numerator == NULL) {
+                    // first source with galaxyFits allocate accumulators
+                    vectorLength = galaxyFits->chisq->n;
+                    sumWeightedFlux = psVectorAlloc(vectorLength, PS_TYPE_F32);
+                    psVectorInit(sumWeightedFlux, 0.0);
+                    sumInvSig2 = psVectorAlloc(vectorLength, PS_TYPE_F32);
+                    psVectorInit(sumInvSig2, 0.0);
+                    numerator   = psVectorAlloc(vectorLength, PS_TYPE_F32);
+                    psVectorInit(numerator, 0.0);
+
+                    // Initialize the fractional radius vectors
+                    // save these to initialize the output galaxy fits
+                    fRmajorMin = galaxyFits->fRmajorMin;
+                    fRmajorMax = galaxyFits->fRmajorMax;
+                    fRmajorDel = galaxyFits->fRmajorDel;
+                    fRminorMin = galaxyFits->fRminorMin;
+                    fRminorMax = galaxyFits->fRminorMax;
+                    fRminorDel = galaxyFits->fRminorDel;
+                    fRmajorVec = psVectorAlloc(vectorLength, PS_TYPE_F32);
+                    fRminorVec = psVectorAlloc(vectorLength, PS_TYPE_F32);
+                    int k = 0;
+                    for (float fRmajor = fRmajorMin; fRmajor < fRmajorMax + 0.5*fRmajorDel; fRmajor += fRmajorDel) {
+                        for (float fRminor = fRminorMin; fRminor < fRminorMax + 0.5*fRminorDel; fRminor += fRminorDel) {
+                            fRminorVec->data.F32[k] = fRminor;
+                            fRmajorVec->data.F32[k] = fRmajor;
+                            k++;
+                        }
+                    }
+                    psAssert(k == vectorLength, "mismatched vectors");
+                }
+
+                // Die if the lengths of the vectors is not the same in all sources
+#ifdef notdef
+                psAssert(vectorLength == options->numTrials, "length of chisq vector %ld does not match options %d",
+                    vectorLength, options->numTrials);
+#endif
+                psAssert(galaxyFits->chisq->n == vectorLength, "length of chisq vectors do not match %ld %ld",
+                             galaxyFits->chisq->n, vectorLength);
+
+                psF32 scaleFactor = fluxScaleFactor->data.F32[source->imageID];
+
+                totalNPix += galaxyFits->nPix;
+
+                for (int k = 0; k < vectorLength; k++) {
+                    psF32 chisq = galaxyFits->chisq->data.F32[k];
+                    psF32 flux  = galaxyFits->Flux->data.F32[k]  * scaleFactor;
+                    psF32 dFlux = galaxyFits->dFlux->data.F32[k] * scaleFactor;
+
+                    numerator->data.F32[k] += chisq * galaxyFits->nPix;
+
+                    psF32 invSig2 = 1.0 / (dFlux * dFlux);
+                    sumInvSig2->data.F32[k] += invSig2;
+
+                    sumWeightedFlux->data.F32[k] += flux * invSig2;
+                }
+            }
+        }
+
+        if (vectorLength) {
+            // allocate galaxyFits for the output source
+            if (!outSrc->galaxyFits) {
+                outSrc->galaxyFits = psArrayAllocEmpty(1);
+            }
+            pmSourceGalaxyFits *galaxyFits = pmSourceGalaxyFitsAlloc();
+            psArrayAdd(outSrc->galaxyFits, 1, galaxyFits);
+            psFree(galaxyFits);
+
+            galaxyFits->nPix  = totalNPix;
+            galaxyFits->modelType = modelType;
+            psVector *fluxVec = 
+                galaxyFits->Flux  = psVectorRecycle(galaxyFits->Flux,  vectorLength, PS_TYPE_F32);
+            psVector *dFluxVec = 
+                galaxyFits->dFlux = psVectorRecycle(galaxyFits->dFlux, vectorLength, PS_TYPE_F32);
+            psVector *chisqVec = 
+                galaxyFits->chisq = psVectorRecycle(galaxyFits->chisq, vectorLength, PS_TYPE_F32);
+
+            galaxyFits->fRmajorMin = fRmajorMin;
+            galaxyFits->fRmajorMax = fRmajorMax;
+            galaxyFits->fRmajorDel = fRmajorDel;
+            galaxyFits->fRminorMin = fRminorMin;
+            galaxyFits->fRminorMax = fRminorMax;
+            galaxyFits->fRminorDel = fRminorDel;
+
+            // fill the summary galaxyFits vectors and find the trial with the minimum value for chisq
+
+            int min_k = -1;
+            psF32 minChisq = NAN;
+
+            for (int k = 0; k < vectorLength; k++) {
+                fluxVec->data.F32[k]  = sumWeightedFlux->data.F32[k] / sumInvSig2->data.F32[k];
+                dFluxVec->data.F32[k] = 1.0 / sumInvSig2->data.F32[k];
+
+                psF32 thischisq = chisqVec->data.F32[k] = numerator->data.F32[k] / totalNPix;
+
+                if (isfinite(thischisq)  && (!isfinite(minChisq) || thischisq < minChisq)) {
+                    min_k = k;
+                    minChisq = thischisq;
+                }
+            }
+
+            psFree(numerator);
+            psFree(sumInvSig2);
+            psFree(sumWeightedFlux);
+
+            if (min_k >= 0 && isfinite(minChisq)) {
+                // copy the best fit params to the model
+                // fractional radii with the lowest chisq
+                psEllipseAxes axes = pmPSF_ModelToAxes(model->params->data.F32, model->class->useReff);
+
+                // examine the params for the trial with minimum chisq.
+                bool fitMajor = true;
+                bool fitMinor = true;
+                psF64 fRmajorBest = fRmajorVec->data.F32[min_k];
+                if ((fabs(fRmajorBest - galaxyFits->fRmajorMin) < galaxyFits->fRmajorDel) || 
+                    (fabs(fRmajorBest - galaxyFits->fRmajorMax) < galaxyFits->fRmajorDel)) {
+                    fitMajor = false;
+                }
+                psF64 fRminorBest = fRminorVec->data.F32[min_k];
+                if ((fabs(fRminorBest - galaxyFits->fRminorMin) < galaxyFits->fRminorDel) || 
+                    (fabs(fRminorBest - galaxyFits->fRminorMax) < galaxyFits->fRminorDel)) {
+                    fitMinor = false;
+                }
+                // If either major or minor is at one of the limits do not fit report the minimum value
+                bool useFit = fitMajor && fitMinor;
+
+                // save the flux and dFlux values from entry with lowest chisq
+                psF64 fluxBest = fluxVec->data.F32[min_k];
+                psF64 dFluxBest = dFluxVec->data.F32[min_k];
+                psF64 dFlux0   = NAN;
+                psF64 flux0    = NAN;
+
+                if (useFit) {
+                    #define NUM_TRIALS_INIT 9
+                    psVector *major = psVectorAllocEmpty(NUM_TRIALS_INIT, PS_TYPE_F64);
+                    psVector *minor = psVectorAllocEmpty(NUM_TRIALS_INIT, PS_TYPE_F64);
+                    psVector *chisq = psVectorAllocEmpty(NUM_TRIALS_INIT, PS_TYPE_F64);
+                    psVector *flux = psVectorAllocEmpty(NUM_TRIALS_INIT, PS_TYPE_F64);
+                    psVector *dFlux = psVectorAllocEmpty(NUM_TRIALS_INIT, PS_TYPE_F64);
+
+                    // XXX: use a recipe parameter instead of 2.2
+                    psF64 maxDeltaMaj = 2.2 * galaxyFits->fRmajorDel;
+                    psF64 maxDeltaMin = 2.2 * galaxyFits->fRminorDel;
+
+                    psF64 majorMin = NAN;
+                    psF64 majorMax = NAN;
+                    psF64 minorMin = NAN;
+                    psF64 minorMax = NAN;
+                    psF64 chisqMin = NAN;
+                    psF64 chisqMax = NAN;
+                    for (int k = 0; k < vectorLength; k++) {
+
+                        if (fabs(fRmajorVec->data.F32[k] - fRmajorBest) < maxDeltaMaj &&
+                            fabs(fRminorVec->data.F32[k] - fRminorBest) < maxDeltaMin) {
+
+                            if (isfinite(chisqVec->data.F32[k]) && 
+                                isfinite(fluxVec->data.F32[k])  &&
+                                isfinite(dFluxVec->data.F32[k])) {
+
+                                // compute major and minor radius vectors from nominal and trial fractions
+                                // also find the ranges in the vectors
+                                psF64 thisMajor = R_MAJOR * fRmajorVec->data.F32[k];
+                                if (!isfinite(majorMin) || thisMajor < majorMin) {
+                                    majorMin = thisMajor;
+                                }
+                                if (!isfinite(majorMax) || thisMajor > majorMax) {
+                                    majorMax = thisMajor;
+                                }
+                                psVectorAppend(major, thisMajor);
+
+                                psF64 thisMinor = R_MINOR * fRminorVec->data.F32[k];
+                                if (!isfinite(minorMin) || thisMinor < minorMin) {
+                                    minorMin = thisMinor;
+                                }
+                                if (!isfinite(minorMax) || thisMinor > minorMax) {
+                                    minorMax = thisMinor;
+                                }
+                                psVectorAppend(minor, thisMinor);
+
+                                psF64 thisChisq = chisqVec->data.F32[k];
+                                if (!isfinite(chisqMin) || thisChisq < chisqMin) {
+                                    chisqMin = thisChisq;
+                                }
+                                if (!isfinite(chisqMax) || thisChisq > chisqMax) {
+                                    chisqMax = thisChisq;
+                                }
+                                psVectorAppend(chisq, thisChisq);
+
+                                psVectorAppend(flux,  fluxVec->data.F32[k]);
+                                psVectorAppend(dFlux, dFluxVec->data.F32[k]);
+                            }
+                        }
+                    }
+
+
+                    // see if we ever get too few good values (haven't seen this happen)
+                    if (major->n < NUM_TRIALS_INIT) {
+                        fprintf(stderr, "only found %ld good points wanted %d for seq: %d\n",
+                            major->n, NUM_TRIALS_INIT, outSrc->seq); 
+                    }
+
+                    // rescale data - this helps avoid precision errors.
+                    psF64 majorRange = majorMax - majorMin;
+                    if (majorRange == 0) {
+                        majorRange = 1;
+                    }
+                    psF64 minorRange = minorMax - minorMin;
+                    if (minorRange == 0) {
+                        minorRange = 1;
+                    }
+                    psF64 chisqRange = chisqMax - chisqMin;
+                    if (chisqRange == 0) {
+                        chisqRange = 1;
+                    }
+                    for (int k = 0; k < major->n; k++) {
+                        major->data.F64[k] = (major->data.F64[k] - majorMin) / majorRange;
+                        minor->data.F64[k] = (minor->data.F64[k] - minorMin) / minorRange;
+                        chisq->data.F64[k] = (chisq->data.F64[k] - chisqMin) / chisqRange;
+                    }
+
+                    // Fit chisq versus rMajor and rMinor
+                    psPolynomial2D *chisqFit = psPolynomial2DAlloc(PS_POLYNOMIAL_ORD, 2, 2);
+                    psPolynomial2D *fluxFit = psPolynomial2DAlloc(PS_POLYNOMIAL_ORD, 2, 2);
+                    psPolynomial2D *fluxErrorFit = psPolynomial2DAlloc(PS_POLYNOMIAL_ORD, 2, 2);
+                    chisqFit->coeffMask[2][2] = PS_POLY_MASK_SET;
+                    chisqFit->coeffMask[2][1] = PS_POLY_MASK_SET;
+                    chisqFit->coeffMask[1][2] = PS_POLY_MASK_SET;
+                    fluxFit->coeffMask[2][2] = PS_POLY_MASK_SET;
+                    fluxFit->coeffMask[2][1] = PS_POLY_MASK_SET;
+                    fluxFit->coeffMask[1][2] = PS_POLY_MASK_SET;
+                    fluxErrorFit->coeffMask[2][2] = PS_POLY_MASK_SET;
+                    fluxErrorFit->coeffMask[2][1] = PS_POLY_MASK_SET;
+                    fluxErrorFit->coeffMask[1][2] = PS_POLY_MASK_SET;
+
+                    bool goodFit = psVectorFitPolynomial2D (chisqFit, NULL, 0xff, chisq, NULL, major, minor);
+
+                    if (goodFit) {
+                        // find the axes for the minimum chisq from the formula
+                        psF64 **coeff = chisqFit->coeff;
+                        psF64 D = 4*coeff[2][0]*coeff[0][2] - coeff[1][1]*coeff[1][1];
+                        psF64 major0 = ((coeff[1][1]*coeff[0][1] - 2*coeff[0][2]*coeff[1][0]) / D) * majorRange + majorMin;
+                        psF64 minor0 = ((coeff[1][1]*coeff[1][0] - 2*coeff[2][0]*coeff[0][1]) / D) * minorRange + minorMin;
+
+                        // estimated chisq at the minimum
+                        psF64 chisq0 = psPolynomial2DEval(chisqFit, major0, minor0) * chisqRange + chisqMin;
+
+                        // now fit the flux ...
+                        bool goodFluxFit = psVectorFitPolynomial2D(fluxFit, NULL, 0xFF, flux, NULL, major, minor);
+
+                        // .. and compute flux at the minimum chisq position
+                        if (goodFluxFit) {
+                            flux0  = psPolynomial2DEval(fluxFit, major0, minor0);
+                        } else {
+                            flux0 = fluxBest;
+                        }
+
+                        // .. and compute dFlux at the minimum chisq position
+                        bool goodFluxErrorFit = psVectorFitPolynomial2D(fluxErrorFit, NULL, 0xFF, dFlux, NULL, major, minor);
+                        if (goodFluxErrorFit) {
+                            dFlux0  = psPolynomial2DEval(fluxErrorFit, major0, minor0);
+                        } else {
+                            dFlux0 = dFluxBest;
+                        }
+
+#ifdef PRINTVALS
+                        fprintf (stderr, "%4d %3d %3ld | %6.3f %6.3f %6.3f %4.2f |  %6.3f %6.3f %6.3f %4.2f | %7.4f %7.4f %7.1f %7.1f\n", 
+                            outSrc->seq, min_k, major->n, R_MAJOR, fRmajorBest*R_MAJOR, major0, major0/R_MAJOR, R_MINOR, fRminorBest*R_MINOR, minor0, minor0/R_MINOR, minChisq, chisq0, fluxBest, flux0);
+#endif 
+
+
+                        axes.major = major0;
+                        axes.minor = minor0;
+                        model->chisq = chisq0;
+#ifdef DUMPVECTORS
+                        char fn[80];
+
+                        sprintf(fn, "vectors/%s.%05d.txt", goodFit ? "g" : "b", outSrc->seq);
+
+                        FILE *f = fopen(fn, "w");
+                        fprintf(f, "#major minor chisq i\n");
+                        for (int k = 0; k < chisq->n; k++) {
+                            fprintf(f, "%10.6f %10.6f %10.6f %5d\n", 
+                                major->data.F64[k]/R_MAJOR, minor->data.F64[k]/R_MINOR, chisq->data.F64[k], k);
+                        }
+                        fclose(f);
+#endif
+                    } else {
+                        model->flags |= PM_MODEL_STATUS_NONCONVERGE;
+
+#ifdef PRINTVALS
+                        fprintf(stderr, "%4d %3d %3ld | %6.3f %6.3f %6.3f %6.3f bad fit\n", 
+                            outSrc->seq, min_k, major->n, R_MAJOR, fRmajorBest, R_MINOR, fRminorBest);
+#endif
+                        psErrorClear();
+                        // psFree(outSrc->galaxyFits);
+
+                    }
+                    psFree(chisqFit);
+                    psFree(fluxFit);
+                    psFree(fluxErrorFit);
+                    psFree(major);
+                    psFree(minor);
+                    psFree(chisq);
+                    psFree(flux);
+                    psFree(dFlux);
+                } else {
+                    // No fit
+                    // Set the values based on the trial with the best chisq
+                    axes.major = R_MAJOR * fRmajorBest;
+                    axes.minor = R_MINOR * fRminorBest;
+                    model->chisq = minChisq; 
+                    flux0 = fluxBest;
+                    dFlux0 = dFluxBest;
+#ifdef PRINTVALS
+                    fprintf(stderr, "%4d %3d %3ld | %6.3f %6.3f %6.3f %6.3f skip fit\n", 
+                            outSrc->seq, min_k, 0L, R_MAJOR, fRmajorBest, R_MINOR, fRminorBest);
+#endif
+                }
+                // now save the model parameters in the model structure
+
+                pmPSF_AxesToModel (model->params->data.F32, axes, model->class->useReff);
+
+                model->mag = -2.5 * log10(flux0);
+                model->magErr = dFlux0 / flux0; // 1 / SN
+                // XXX: should there be a different flag if we didn't do a fit of the chisq
+                model->flags |= PM_MODEL_STATUS_FITTED;
+            }
+        }
+        psFree(fRminorVec);
+        psFree(fRmajorVec);
+    }
+
+    return outSrc;
+}
+
+#define GETVAL(member, key) \
+    opt->member = psMetadataLookupF32(&status, md, key); \
+    if (!status) { \
+        psError (PSPHOT_ERR_CONFIG, true, "failed to looup value for %s in %s", key, \
+            useAnalysis ? "readout->analysis" : "recipe"); \
+    }
+
+static bool setOptions(galaxyShapeSummaryOptions *opt, pmReadout *readout, psMetadata *recipe, bool makeVectors) {
+    bool status;
+    bool useAnalysis;   // fall back to recipe if we dont' find values in analysis. Probably should no longer do this
+
+#ifdef notdef
+    psMetadataLookupF32(&useAnalysis, readout->analysis, "GALAXY_SHAPES_FR_MAJOR_MIN");
+#endif
+    psMetadataLookupF32(&useAnalysis, readout->analysis, "GALAXY_SHAPES_Q");
+    psMetadata *md = useAnalysis ? readout->analysis : recipe;
+
+    GETVAL(Q, "GALAXY_SHAPES_Q");
+    GETVAL(NSigma, "GALAXY_SHAPES_NSIGMA");
+    GETVAL(clampSN, "GALAXY_SHAPES_CLAMP_SN");
+
+#ifdef notdef
+    // these are per object now
+    GETVAL(fRmajorMin, "GALAXY_SHAPES_FR_MAJOR_MIN");
+    GETVAL(fRmajorMax, "GALAXY_SHAPES_FR_MAJOR_MAX");
+    GETVAL(fRmajorDel, "GALAXY_SHAPES_FR_MAJOR_DEL");
+    GETVAL(fRminorMin, "GALAXY_SHAPES_FR_MINOR_MIN");
+    GETVAL(fRminorMax, "GALAXY_SHAPES_FR_MINOR_MAX");
+    GETVAL(fRminorDel, "GALAXY_SHAPES_FR_MINOR_DEL");
+
+    opt->numTrials = ceil((opt->fRmajorMax - opt->fRmajorMin + 0.5*opt->fRmajorDel) / opt->fRmajorDel) *
+                         ceil((opt->fRminorMax - opt->fRminorMin + 0.5*opt->fRminorDel) / opt->fRminorDel) ;
+
+    if (makeVectors) {
+        opt->fRminor = psVectorAlloc(opt->numTrials, PS_TYPE_F32);
+        opt->fRmajor = psVectorAlloc(opt->numTrials, PS_TYPE_F32);
+        int i = 0;
+        for (float fRmajor = opt->fRmajorMin; fRmajor < opt->fRmajorMax + 0.5*opt->fRmajorDel;
+                fRmajor += opt->fRmajorDel) {
+            for (float fRminor = opt->fRminorMin; fRminor < opt->fRminorMax + 0.5*opt->fRminorDel;
+                    fRminor += opt->fRminorDel) {
+                opt->fRminor->data.F32[i] = fRminor;
+                opt->fRmajor->data.F32[i] = fRmajor;
+                i++;
+            }
+        }
+        psAssert(i == opt->numTrials, "Something's wrong with my loop got %d entries expected %d", i, opt->numTrials);
+    } else {
+        opt->fRminor = NULL;
+        opt->fRmajor = NULL;
+    }
+#endif
+        
+    return true;
+}
+
+#define CHECKVAL(left, right, val, message) \
+    if (left->val != right.val) { \
+        psError (PSPHOT_ERR_CONFIG, true, message); \
+        return false; \
+    }
+
+static bool checkOptions(galaxyShapeSummaryOptions *options, pmReadout *readout, psMetadata *recipe) {
+    galaxyShapeSummaryOptions thisReadoutsOptions;
+    
+    if (!setOptions(&thisReadoutsOptions, readout, recipe, false)) {
+        psError (PS_ERR_UNKNOWN, false, "problem determining galaxy shape options for readout");
+        return false;
+    }
+    CHECKVAL(options, thisReadoutsOptions, Q, "mismatched Q");
+    CHECKVAL(options, thisReadoutsOptions, NSigma, "mismatched NSIGMA");
+    CHECKVAL(options, thisReadoutsOptions, clampSN, "mismatched cleampSN");
+
+#ifdef notdef
+    // these are per object now
+    CHECKVAL(options, thisReadoutsOptions, numTrials, "mismatched number of trials")
+    CHECKVAL(options, thisReadoutsOptions, fRmajorMin, "mismatched fRmajorMin")
+    CHECKVAL(options, thisReadoutsOptions, fRmajorMax, "mismatched fRmajorMax")
+    CHECKVAL(options, thisReadoutsOptions, fRmajorDel, "mismatched fRmajorDel")
+    CHECKVAL(options, thisReadoutsOptions, fRminorMin, "mismatched fRminorMin")
+    CHECKVAL(options, thisReadoutsOptions, fRminorMax, "mismatched fRminorMax")
+    CHECKVAL(options, thisReadoutsOptions, fRminorDel, "mismatched fRminorDel")
+#endif
+
+    return true;
+}
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotGalaxyShape.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotGalaxyShape.c	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotGalaxyShape.c	(revision 37066)
@@ -0,0 +1,453 @@
+# include "psphotInternal.h"
+
+bool psphotGalaxyShape (pmConfig *config, const pmFPAview *view, const char *filerule)
+{
+    bool status = true;
+
+    fprintf (stdout, "\n");
+    psLogMsg ("psphot", PS_LOG_INFO, "--- psphot Galaxy Shapes ---");
+
+    // select the appropriate recipe information
+    psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE);
+    psAssert (recipe, "missing recipe?");
+
+    // perform full non-linear fits / extended source analysis?
+    // XXX for this to be true for psphotFullForce??
+    if (!psMetadataLookupBool (&status, recipe, "GALAXY_SHAPES")) {
+	psLogMsg ("psphot", PS_LOG_INFO, "skipping galaxy shape measurements\n");
+	return true;
+    }
+
+    int num = psphotFileruleCount(config, filerule);
+
+    // skip the chisq image (optionally?)
+    int chisqNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.CHISQ.NUM");
+    if (!status) chisqNum = -1;
+
+    // loop over the available readouts
+    for (int i = 0; i < num; i++) {
+        if (i == chisqNum) continue; // skip chisq image
+
+        // find the currently selected readout
+        pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, i); // File of interest
+        psAssert (file, "missing file?");
+
+        pmReadout *readout = pmFPAviewThisReadout(view, file->fpa);
+        psAssert (readout, "missing readout?");
+
+        pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS");
+        psAssert (detections, "missing detections?");
+
+        psArray *sources = detections->newSources ? detections->newSources : detections->allSources;
+        psAssert (sources, "missing sources?");
+
+        pmPSF *psf = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.PSF");
+        // psAssert (psf, "missing psf?");
+
+        if (!psphotGalaxyShapeReadout (config, recipe, view, filerule, readout, sources, psf)) {
+            psError (PSPHOT_ERR_CONFIG, false, "failed to measure magnitudes for %s entry %d", filerule, i);
+            return false;
+        }
+    }
+    return true;
+}
+
+bool psphotGalaxyShapeReadout(pmConfig *config, psMetadata *recipe, const pmFPAview *view, const char * filerule, pmReadout *readout, psArray *sources, pmPSF *psf) {
+
+    bool status = false;
+
+    if (!sources->n) {
+        psLogMsg ("psphot", PS_LOG_INFO, "no sources, skipping galaxy shapes");
+        return true;
+    }
+
+    psTimerStart ("psphot.galaxy");
+
+    psphotInitRadiusEXT (recipe, readout);
+
+    // determine the number of allowed threads
+    int nThreads = psMetadataLookupS32(&status, config->arguments, "NTHREADS"); // Number of threads
+    if (!status) {
+        nThreads = 0;
+    }
+
+    // bit-masks to test for good/bad pixels
+    psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT");
+    assert (maskVal);
+
+    // bit-mask to mark pixels not used in analysis
+    psImageMaskType markVal = psMetadataLookupImageMask(&status, recipe, "MARK.PSPHOT");
+    assert (markVal);
+
+    maskVal |= markVal;
+
+    psphotGalaxyShapeOptions *opt = psphotGalaxyShapeOptionsAlloc();
+    opt->Q = psMetadataLookupF32(&status, recipe, "GALAXY_SHAPES_Q"); 
+    psAssert (status, "missing GALAXY_SHAPES_Q");
+    opt->NSigma = psMetadataLookupF32(&status, recipe, "GALAXY_SHAPES_NSIGMA"); 
+    psAssert (status, "missing GALAXY_SHAPES_NSIGMA");
+    opt->clampSN = psMetadataLookupF32(&status, recipe, "GALAXY_SHAPES_CLAMP_SN"); 
+    psAssert (status, "missing GALAXY_SHAPES_NSIGMA");
+    psString modelTypeToSave = psMetadataLookupStr(&status, recipe, "EXT_MODEL_TYPE_FORCE");
+    if (modelTypeToSave && strcmp(modelTypeToSave, "ALL") && strcmp(modelTypeToSave, "BEST")) {
+        opt->extModelType = pmModelClassGetType(modelTypeToSave);
+    } else {
+        opt->extModelType = pmModelClassGetType("PS_MODEL_SERSIC");
+    }
+
+#ifdef notdef
+    opt->fRmajorMin = psMetadataLookupF32(&status, recipe, "GALAXY_SHAPES_FR_MAJOR_MIN"); if (!status) opt->fRmajorMin = 0.5;
+    opt->fRmajorMax = psMetadataLookupF32(&status, recipe, "GALAXY_SHAPES_FR_MAJOR_MAX"); if (!status) opt->fRmajorMax = 2.0;
+    opt->fRmajorDel = psMetadataLookupF32(&status, recipe, "GALAXY_SHAPES_FR_MAJOR_DEL"); if (!status) opt->fRmajorDel = 0.1;
+    opt->fRminorMin = psMetadataLookupF32(&status, recipe, "GALAXY_SHAPES_FR_MINOR_MIN"); if (!status) opt->fRminorMin = 0.5;
+    opt->fRminorMax = psMetadataLookupF32(&status, recipe, "GALAXY_SHAPES_FR_MINOR_MAX"); if (!status) opt->fRminorMax = 2.0;
+    opt->fRminorDel = psMetadataLookupF32(&status, recipe, "GALAXY_SHAPES_FR_MINOR_DEL"); if (!status) opt->fRminorDel = 0.1;
+#endif
+
+    // what fraction of the PSF is used? (radius in pixels : 2 -> 5x5 box)
+    // NOTE: this is only used if we are NOT smoothing with a 1D Gaussian
+    int psfSize = psMetadataLookupS32 (&status, recipe, "PCM_BOX_SIZE");
+    assert (status);
+
+    float fitNsigmaConv = psMetadataLookupF32 (&status, recipe, "EXT_FIT_NSIGMA_CONV"); // number of sigma for the convolutio
+    if (!status || !isfinite(fitNsigmaConv) || fitNsigmaConv <= 0) {
+	fitNsigmaConv = 5.0;
+    }
+
+    // Define source fitting parameters for extended source fits
+    // we are not doing LMM fitting, so most options are irrelevant
+    pmSourceFitOptions *fitOptions = pmSourceFitOptionsAlloc();
+    fitOptions->mode           = PM_SOURCE_FIT_EXT_AND_SKY;
+    fitOptions->covarFactor    = psImageCovarianceFactorForAperture(readout->covariance, 10.0); // Covariance matrix
+    fitOptions->nsigma         = fitNsigmaConv;
+
+    // Poisson or Constant weight for chisq tests?
+    fitOptions->poissonErrors = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_FITS_POISSON");
+    if (!status) fitOptions->poissonErrors = true;
+
+    // source analysis is done in S/N order (brightest first)
+    sources = psArraySort (sources, pmSourceSortByFlux);
+    if (!sources->n) {
+        psLogMsg ("psphot", PS_LOG_INFO, "no sources, skipping blend");
+        return true;
+    }
+
+    // threaded measurement of the source magnitudes
+    // choose Cx, Cy (see psphotThreadTools.c for overview of the concepts)
+    int Cx = 1, Cy = 1;
+    psphotChooseCellSizes (&Cx, &Cy, readout, nThreads);
+
+    psArray *cellGroups = psphotAssignSources (Cx, Cy, sources);
+
+    for (int i = 0; i < cellGroups->n; i++) {
+
+        psArray *cells = cellGroups->data[i];
+
+        for (int j = 0; j < cells->n; j++) {
+
+            // allocate a job -- if threads are not defined, this just runs the job
+            psThreadJob *job = psThreadJobAlloc ("PSPHOT_GALAXY_SHAPES");
+
+            psArrayAdd(job->args, 1, readout);
+            psArrayAdd(job->args, 1, cells->data[j]); // sources
+            psArrayAdd(job->args, 1, fitOptions);
+            psArrayAdd(job->args, 1, opt);
+            PS_ARRAY_ADD_SCALAR(job->args, markVal, PS_TYPE_IMAGE_MASK);
+            PS_ARRAY_ADD_SCALAR(job->args, maskVal, PS_TYPE_IMAGE_MASK);
+            PS_ARRAY_ADD_SCALAR(job->args, psfSize, PS_TYPE_S32);
+
+// set this to 0 to run without threading
+# if (1)
+            if (!psThreadJobAddPending(job)) {
+                psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
+                return false;
+            }
+# else
+	    if (!psphotGalaxyShape_Threaded(job)) {
+		psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
+		// psFree(AnalysisRegion);
+		return false;
+	    }
+	    psFree(job);
+# endif
+        }
+
+        // wait for the threads to finish and manage results
+        if (!psThreadPoolWait (false, true)) {
+            psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
+            return false;
+        }
+
+        // we have only supplied one type of job, so we can assume the types here
+        psThreadJob *job = NULL;
+        while ((job = psThreadJobGetDone()) != NULL) {
+            if (job->args->n < 1) {
+                fprintf (stderr, "error with job\n");
+            }
+            psFree(job);
+        }
+    }
+    psFree (cellGroups);
+    psFree (fitOptions);
+    psFree (opt);
+
+    psLogMsg ("psphot.galaxy", PS_LOG_WARN, "measure galaxy shapes : %f sec for %ld objects\n", psTimerMark ("psphot.galaxy"), sources->n);
+    return true;
+}
+
+bool psphotGalaxyShape_Threaded (psThreadJob *job) {
+
+    pmReadout *readout      	   = job->args->data[0];
+    psArray *sources        	   = job->args->data[1];
+    pmSourceFitOptions *fitOptions = job->args->data[2];
+    psphotGalaxyShapeOptions *opt  = job->args->data[3];
+    psImageMaskType markVal 	   = PS_SCALAR_VALUE(job->args->data[4],PS_TYPE_IMAGE_MASK_DATA);
+    psImageMaskType maskVal 	   = PS_SCALAR_VALUE(job->args->data[5],PS_TYPE_IMAGE_MASK_DATA);
+    int psfSize             	   = PS_SCALAR_VALUE(job->args->data[6],S32);
+
+    float fitRadius;
+    float windowRadius;
+
+    for (int i = 0; i < sources->n; i++) {
+
+	pmSource *source = sources->data[i];
+	if (!source->peak) continue; // XXX how can we have a peak-less source?
+
+	// check status of this source's moments
+	if (!source->moments) continue;
+	if (!(source->tmpFlags & PM_SOURCE_TMPF_MOMENTS_MEASURED)) continue;
+	if (source->mode & PM_SOURCE_MODE_MOMENTS_FAILURE) continue;
+        if (!source->modelPSF) continue;
+
+	// psphotSetRadiusMomentsExact sets the radius based on Mrf
+	if (!isfinite(source->moments->Mrf)) continue;
+
+        // modelFits is allocated if a galaxy fit is requested
+        if (!source->modelFits) continue;
+
+	psphotSetRadiusMomentsExact(&fitRadius, &windowRadius, readout, source, markVal); // NOTE : 6 allocs
+
+	// skip saturated stars modeled with a radial profile 
+	// XXX worry about this at some point..
+	if (source->mode2 & PM_SOURCE_MODE2_SATSTAR_PROFILE) continue;
+
+	// replace object in image
+	if (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED) {
+	    pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);
+	}
+
+	// this function populates moments->Mrf,GalaxyShape,GalaxyShapeErr
+	// do the following for a set of shapes (Ex,Ey)
+	psphotGalaxyShapeGrid (source, fitOptions, opt, maskVal, psfSize);
+
+	psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal));
+
+	pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
+    }
+
+    return true;
+}
+
+bool psphotGalaxyShapeGrid (pmSource *source, pmSourceFitOptions *fitOptions, psphotGalaxyShapeOptions *opt, psImageMaskType maskVal, int psfSize) {
+
+
+    for (int iModel = 0 ; iModel < source->modelFits->n; iModel++) {
+        pmModel *model = source->modelFits->data[iModel];
+        if (!model) return false;
+
+        pmModelType modelType = model->type;
+        model->flags = PM_MODEL_STATUS_NONE;
+
+        // we are using fitOptions->mode : be sure this makes sense
+        pmPCMdata *pcm = pmPCMinit (source, fitOptions, model, maskVal, psfSize);
+        if (!pcm) return false;
+
+        // we are fitting only PM_PAR_I0; the shape elements are generated from a grid
+        psF32 *PAR = pcm->modelConv->params->data.F32;
+
+        pmSourceGalaxyFits *galaxyFits = pmSourceGalaxyFitsAlloc();
+
+        // set the options for this source
+        if (!psphotGalaxyShapeOptionsSet(source, galaxyFits, opt)) {
+            // this source won't work
+            psFree(pcm);
+            psFree(galaxyFits);
+            continue;
+        }
+
+        if (!source->galaxyFits) {
+            source->galaxyFits = psArrayAllocEmpty(1);
+        }
+        psArrayAdd(source->galaxyFits, 1, galaxyFits);
+        psFree(galaxyFits);
+
+        // I have some source guess (e0, e1, e2)
+        psEllipseAxes guessAxes = pmPSF_ModelToAxes (PAR, model->class->useReff);
+
+        float fRmajorBest = NAN;
+        float fRminorBest = NAN;
+        float chisqBest = NAN;
+        for (float fRmajor = galaxyFits->fRmajorMin; fRmajor < galaxyFits->fRmajorMax + 0.5*galaxyFits->fRmajorDel; fRmajor += galaxyFits->fRmajorDel) {
+            for (float fRminor = galaxyFits->fRminorMin; fRminor < galaxyFits->fRminorMax + 0.5*galaxyFits->fRminorDel; fRminor += galaxyFits->fRminorDel) {
+      
+                psEllipseAxes testAxes = guessAxes;
+                testAxes.major = guessAxes.major * fRmajor;
+                testAxes.minor = guessAxes.minor * fRminor;
+                
+                pmPSF_AxesToModel (PAR, testAxes, model->class->useReff);
+                
+                psphotGalaxyShapeSource (pcm, source, galaxyFits, maskVal, psfSize, true);
+
+                int i = galaxyFits->chisq->n - 1;
+                float flux = galaxyFits->Flux->data.F32[i];
+                if (isfinite(flux)) {
+                    float thisChisq = galaxyFits->chisq->data.F32[i];
+                    if (isfinite(thisChisq) && isfinite(flux) && (!isfinite(chisqBest) || thisChisq < chisqBest)) {
+                        chisqBest = thisChisq;
+                        fRmajorBest = fRmajor;
+                        fRminorBest = fRminor;
+                    }
+                }
+                // reset I0 to avoid potential problems on the next iteration
+                PAR[PM_PAR_I0] = 1.0;
+            }
+        }
+
+        if (isfinite(chisqBest)) {
+            // now save the best fitting model as the source's extended model ...
+            psEllipseAxes testAxes = guessAxes;
+
+            // ... unless this macro is defined
+#ifndef SAVE_NOMINAL_MODEL
+            testAxes.major = guessAxes.major * fRmajorBest;
+            testAxes.minor = guessAxes.minor * fRminorBest;
+#endif
+            
+            pmPSF_AxesToModel (PAR, testAxes, model->class->useReff);
+                
+            psphotGalaxyShapeSource (pcm, source, galaxyFits, maskVal, psfSize, false);
+
+            // Replace modelEXT with the best model from the first of the model fits if one of them is good
+            if (isfinite(PAR[PM_PAR_I0]) && modelType == opt->extModelType) {
+                psFree (source->modelEXT);
+
+                source->modelEXT = psMemIncrRefCounter (pcm->modelConv);
+                source->type = PM_SOURCE_TYPE_EXTENDED;
+                source->mode |= PM_SOURCE_MODE_EXTMODEL;
+                source->mode |= PM_SOURCE_MODE_NONLINEAR_FIT;
+
+                // cache the model flux
+                pmPCMCacheModel (source, maskVal, psfSize, fitOptions->nsigma);
+            }
+        }
+
+        psFree (pcm);
+    }
+    return true;
+}
+
+// fit the given model to the source and find chisq & normalization
+// XXX is this a single-component model? sersic with a supplied index, Reff, axis ratio, and theta?
+bool psphotGalaxyShapeSource (pmPCMdata *pcm, pmSource *source, pmSourceGalaxyFits *galaxyFits, psImageMaskType maskVal, int psfSize, bool saveResults) {
+
+    PS_ASSERT_PTR_NON_NULL(source, false);
+    PS_ASSERT_PTR_NON_NULL(source->peak, false);
+    PS_ASSERT_PTR_NON_NULL(source->pixels, false);
+
+    // generate the modelFlux
+    // need to reset here each time since we assign below to calculate the flux
+    // XXX note that this does not add sky to model
+    pmPCMMakeModel (source, pcm->modelConv, pcm->nsigma, maskVal, psfSize);
+    pcm->modelConv->params->data.F32[PM_PAR_I0] = 1.0;
+	
+    int nPix = 0;
+    float YY = 0.0;
+    float YM = 0.0;
+    float MM = 0.0;
+    bool usePoisson = pcm->poissonErrors;
+
+    for (int iy = 0; iy < source->pixels->numRows; iy++) {
+	for (int ix = 0; ix < source->pixels->numCols; ix++) {
+	    // skip masked points
+	    if (source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix]) {
+		continue;
+	    }
+	    // skip zero-variance points
+	    if (source->variance->data.F32[iy][ix] == 0) {
+		continue;
+	    }
+
+	    // skip nan value points
+	    if (!isfinite(source->pixels->data.F32[iy][ix])) {
+		continue;
+	    }
+
+	    float fy = source->pixels->data.F32[iy][ix];
+	    float fm = source->modelFlux->data.F32[iy][ix];
+	    float wt = (usePoisson) ? 1.0 / source->variance->data.F32[iy][ix] : 1.0;
+
+	    YY += PS_SQR(fy) * wt;
+	    YM += fm * fy * wt;
+	    MM += PS_SQR(fm) * wt;
+	    nPix ++;
+	}
+    }
+
+    float Io = YM / MM;
+    float dIo = sqrt (1.0 / MM);
+    float Chisq = (YY - 2 * Io * YM + Io * Io * MM) / (float) nPix;
+    // NOTE : if !poissonErrors, Chisq is not really the chisq, but is scaled by the flux.
+
+    pcm->modelConv->params->data.F32[PM_PAR_I0] = Io;
+    float flux = pcm->modelConv->class->modelFlux (pcm->modelConv->params);
+    float dflux = flux * (dIo / Io);
+
+
+    if (saveResults) {
+        psVectorAppend (galaxyFits->Flux, flux);
+        psVectorAppend (galaxyFits->dFlux, dflux);
+        psVectorAppend (galaxyFits->chisq, Chisq);
+        galaxyFits->nPix = nPix;
+        galaxyFits->modelType = pcm->modelConv->type;
+    }
+
+    return true;
+}
+
+/**** support functions ****/
+
+void psphotGalaxyShapeOptionsFree (psphotGalaxyShapeOptions *opt) {
+    return;
+}
+
+psphotGalaxyShapeOptions *psphotGalaxyShapeOptionsAlloc()
+{
+    psphotGalaxyShapeOptions *opt = (psphotGalaxyShapeOptions *) psAlloc(sizeof(psphotGalaxyShapeOptions));
+    psMemSetDeallocator(opt, (psFreeFunc) psphotGalaxyShapeOptionsFree);
+    
+    return opt;
+}
+
+bool psphotGalaxyShapeOptionsSet(pmSource *source, pmSourceGalaxyFits *galaxyFits, psphotGalaxyShapeOptions *options)
+{
+    // XXX: put these in recipe
+    // doesn't make sense to use too small of a spacing
+    float clampedSN = source->extSN < options->clampSN ? source->extSN : options->clampSN;
+
+    float f_del = options->Q / clampedSN;
+    float f_min = 1 - options->NSigma * f_del;
+    float f_max = 1 + options->NSigma * f_del;
+
+    // if f_min goes negative skip this object
+    if (f_min < 0) return false;
+
+    galaxyFits->fRmajorMin = f_min;
+    galaxyFits->fRmajorMax = f_max;
+    galaxyFits->fRmajorDel = f_del;
+    galaxyFits->fRminorMin = f_min;
+    galaxyFits->fRminorMax = f_max;
+    galaxyFits->fRminorDel = f_del;
+
+    return true;
+}
+
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotImageLoop.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotImageLoop.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotImageLoop.c	(revision 37066)
@@ -132,4 +132,11 @@
 		    }
 		    break;
+		  case PSPHOT_FULL_FORCE:
+		    if (!psphotFullForceReadout (config, view, "PSPHOT.INPUT")) {
+			psError(psErrorCodeLast(), false, "failure in psphotReadout for chip %d, cell %d, readout %d\n", view->chip, view->cell, view->readout);
+			psFree (view);
+			return false;
+		    }
+		    break;
 		  case PSPHOT_MAKE_PSF:
 		    if (!psphotMakePSFReadout (config, view, "PSPHOT.INPUT")) {
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotKronFlux.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotKronFlux.c	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotKronFlux.c	(revision 37066)
@@ -0,0 +1,250 @@
+# include "psphotInternal.h"
+
+bool psphotKronFlux (pmConfig *config, const pmFPAview *view, const char *filerule)
+{
+    bool status = true;
+
+    fprintf (stdout, "\n");
+    psLogMsg ("psphot", PS_LOG_INFO, "--- psphot Kron Fluxes ---");
+
+    // select the appropriate recipe information
+    psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE);
+    psAssert (recipe, "missing recipe?");
+
+    int num = psphotFileruleCount(config, filerule);
+
+    // skip the chisq image (optionally?)
+    int chisqNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.CHISQ.NUM");
+    if (!status) chisqNum = -1;
+
+    // loop over the available readouts
+    for (int i = 0; i < num; i++) {
+        if (i == chisqNum) continue; // skip chisq image
+
+        // find the currently selected readout
+        pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, i); // File of interest
+        psAssert (file, "missing file?");
+
+        pmReadout *readout = pmFPAviewThisReadout(view, file->fpa);
+        psAssert (readout, "missing readout?");
+
+        pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS");
+        psAssert (detections, "missing detections?");
+
+        psArray *sources = detections->newSources ? detections->newSources : detections->allSources;
+        psAssert (sources, "missing sources?");
+
+        if (!psphotKronFluxReadout (config, recipe, view, filerule, readout, sources)) {
+            psError (PSPHOT_ERR_CONFIG, false, "failed to measure magnitudes for %s entry %d", filerule, i);
+            return false;
+        }
+    }
+
+    return true;
+}
+
+bool psphotKronFluxReadout(pmConfig *config, psMetadata *recipe, const pmFPAview *view, const char *filerule, pmReadout *readout, psArray *sources) {
+
+    bool status = false;
+
+    if (!sources->n) {
+        psLogMsg ("psphot", PS_LOG_INFO, "no sources, skipping kron fluxes");
+        return true;
+    }
+
+    psTimerStart ("psphot.kron");
+
+    // determine the number of allowed threads
+    int nThreads = psMetadataLookupS32(&status, config->arguments, "NTHREADS"); // Number of threads
+    if (!status) {
+        nThreads = 0;
+    }
+
+    // bit-masks to test for good/bad pixels
+    psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT");
+    assert (maskVal);
+
+    // bit-mask to mark pixels not used in analysis
+    psImageMaskType markVal = psMetadataLookupImageMask(&status, recipe, "MARK.PSPHOT");
+    assert (markVal);
+
+    // maskVal is used to test for rejected pixels, and must include markVal
+    maskVal |= markVal;
+
+    // source analysis is done in S/N order (brightest first)
+    sources = psArraySort (sources, pmSourceSortByFlux);
+    if (!sources->n) {
+        psLogMsg ("psphot", PS_LOG_INFO, "no sources, skipping blend");
+        return true;
+    }
+
+    // threaded measurement of the source magnitudes
+    // choose Cx, Cy (see psphotThreadTools.c for overview of the concepts)
+    int Cx = 1, Cy = 1;
+    psphotChooseCellSizes (&Cx, &Cy, readout, nThreads);
+
+    psArray *cellGroups = psphotAssignSources (Cx, Cy, sources);
+
+    for (int i = 0; i < cellGroups->n; i++) {
+
+        psArray *cells = cellGroups->data[i];
+
+        for (int j = 0; j < cells->n; j++) {
+
+            // allocate a job -- if threads are not defined, this just runs the job
+            psThreadJob *job = psThreadJobAlloc ("PSPHOT_KRON_FLUX");
+
+            psArrayAdd(job->args, 1, readout);
+            psArrayAdd(job->args, 1, cells->data[j]); // sources
+            PS_ARRAY_ADD_SCALAR(job->args, markVal,            PS_TYPE_IMAGE_MASK);
+            PS_ARRAY_ADD_SCALAR(job->args, maskVal,            PS_TYPE_IMAGE_MASK);
+
+// set this to 0 to run without threading
+# if (1)
+            if (!psThreadJobAddPending(job)) {
+                psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
+                return false;
+            }
+# else
+	    if (!psphotKronFlux_Threaded(job)) {
+		psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
+		// psFree(AnalysisRegion);
+		return false;
+	    }
+	    psFree(job);
+# endif
+        }
+
+        // wait for the threads to finish and manage results
+        if (!psThreadPoolWait (false, true)) {
+            psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
+            return false;
+        }
+
+        // we have only supplied one type of job, so we can assume the types here
+        psThreadJob *job = NULL;
+        while ((job = psThreadJobGetDone()) != NULL) {
+            if (job->args->n < 1) {
+                fprintf (stderr, "error with job\n");
+            }
+            psFree(job);
+        }
+    }
+    psFree (cellGroups);
+
+    psLogMsg ("psphot.kron", PS_LOG_WARN, "measure kron fluxes : %f sec for %ld objects\n", psTimerMark ("psphot.kron"), sources->n);
+    return true;
+}
+
+bool psphotKronFlux_Threaded (psThreadJob *job) {
+
+    pmReadout *readout              = job->args->data[0];
+    psArray *sources                = job->args->data[1];
+    psImageMaskType markVal         = PS_SCALAR_VALUE(job->args->data[2],PS_TYPE_IMAGE_MASK_DATA);
+    psImageMaskType maskVal         = PS_SCALAR_VALUE(job->args->data[3],PS_TYPE_IMAGE_MASK_DATA);
+
+    for (int i = 0; i < sources->n; i++) {
+
+	pmSource *source = sources->data[i];
+	if (!source->peak) continue; // XXX how can we have a peak-less source?
+
+	// check status of this source's moments
+	if (!source->moments) continue;
+	if (!(source->tmpFlags & PM_SOURCE_TMPF_MOMENTS_MEASURED)) continue;
+	if (source->mode & PM_SOURCE_MODE_MOMENTS_FAILURE) continue;
+
+	// XXX where are we storing the supplied kron radius?
+	if (!isfinite(source->moments->Mrf)) continue;
+
+	// skip saturated stars modeled with a radial profile 
+	if (source->mode2 & PM_SOURCE_MODE2_SATSTAR_PROFILE) continue;
+
+	// replace object in image
+	if (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED) {
+	    pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);
+	}
+
+	// is this right??
+	float windowRadius = 2.5*source->moments->Mrf ;
+
+	// re-allocate image, weight, mask arrays for each peak with box big enough to fit BIG_RADIUS
+	pmSourceRedefinePixels (source, readout, source->peak->x, source->peak->y, windowRadius + 2);
+	psAssert (source->pixels, "WTF?");
+
+	// this function populates moments->Mrf,KronFlux,KronFluxErr
+	psphotKronFluxSource (source, maskVal);
+	psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal));
+
+	pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
+    }
+
+    return true;
+}
+
+// measure just the flux in the given aperture (this is probably a single common function -- can I use one of the pmSourcePhotometry functions?)
+bool psphotKronFluxSource (pmSource *source, psImageMaskType maskVal) {
+
+    PS_ASSERT_PTR_NON_NULL(source, false);
+    PS_ASSERT_PTR_NON_NULL(source->peak, false);
+    PS_ASSERT_PTR_NON_NULL(source->pixels, false);
+
+    // the peak position is less accurate but less subject to extreme deviations
+    // XXX do this or just use the peak position?
+    float dX = source->moments->Mx - source->peak->xf;
+    float dY = source->moments->My - source->peak->yf;
+    float dR = hypot(dX, dY);
+    float Xo = (dR < 2.0) ? source->moments->Mx : source->peak->xf;
+    float Yo = (dR < 2.0) ? source->moments->My : source->peak->yf;
+
+    // center of mass in subimage.  Note: the calculation below uses pixel index, so we correct
+    // xCM, yCM from pixel coords to pixel index here.
+    psF32 xCM = Xo - 0.5 - source->pixels->col0; // coord of peak in subimage
+    psF32 yCM = Yo - 0.5 - source->pixels->row0; // coord of peak in subimage
+
+    // Calculate the Kron magnitude (make this block optional?)
+    // XXX set the aperture here
+    float radKron  = 2.5*source->moments->Mrf;
+    float radKron2 = radKron*radKron;
+
+    int nKronPix = 0;
+    float Sum = 0.0;
+    float Var = 0.0;
+
+    // set vPix to the source pixels (it may have been set to the
+    // smoothed image above)
+    psF32 **vPix = source->pixels->data.F32;
+    psF32 **vWgt = source->variance->data.F32;
+    psImageMaskType **vMsk = (source->maskObj == NULL) ? NULL : source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA;
+
+    for (psS32 row = 0; row < source->pixels->numRows ; row++) {
+
+	psF32 yDiff = row - yCM;
+	if (fabs(yDiff) > radKron) continue;
+
+	for (psS32 col = 0; col < source->pixels->numCols ; col++) {
+	    // check mask and value for this pixel
+	    if (vMsk && (vMsk[row][col] & maskVal)) continue;
+	    if (isnan(vPix[row][col])) continue;
+
+	    psF32 xDiff = col - xCM;
+	    if (fabs(xDiff) > radKron) continue;
+
+	    // radKron is just a function of (xDiff, yDiff)
+	    psF32 r2  = PS_SQR(xDiff) + PS_SQR(yDiff);
+	    if (r2 > radKron2) continue;
+
+	    float pDiff = vPix[row][col];
+	    psF32 wDiff = vWgt[row][col];
+
+	    Sum += pDiff;
+	    Var += wDiff;
+	    nKronPix ++;
+	}
+    }
+
+    // return the flux and error to parameters?
+    source->moments->KronFlux    = Sum;
+    source->moments->KronFluxErr = sqrt(Var);
+
+    return true;
+}
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotKronIterate.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotKronIterate.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotKronIterate.c	(revision 37066)
@@ -166,5 +166,7 @@
     }
 
+# if (PS_TRACE_ON)
     fprintf (stderr, "--- starting KRON ---\n");
+#endif
 
     // We measure the Kron Radius on a smoothed copy of the readout image
@@ -530,4 +532,6 @@
             source->moments->KronFlux  = NAN;
             source->moments->KronFluxErr  = NAN;
+            source->moments->KronFinner = NAN;
+            source->moments->KronFouter = NAN;
             return false;
         }
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotLensing.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotLensing.c	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotLensing.c	(revision 37066)
@@ -0,0 +1,331 @@
+# include "psphotInternal.h"
+
+// calculate lensing parameters (we have the moments already)
+bool psphotLensing (pmConfig *config, const pmFPAview *view, const char *filerule)
+{
+    bool status = true;
+
+    fprintf (stdout, "\n");
+    psLogMsg ("psphot", PS_LOG_INFO, "--- psphot Lensing Parameters ---");
+
+    // select the appropriate recipe information
+    psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE);
+    psAssert (recipe, "missing recipe?");
+
+    // perform full extended source non-linear fits?
+    if (!psMetadataLookupBool (&status, recipe, "LENSING_PARAMETERS")) {
+        psLogMsg ("psphot", PS_LOG_INFO, "skipping extended source fits\n");
+        return true;
+    }
+
+    int num = psphotFileruleCount(config, filerule);
+
+    // skip the chisq image (optionally?)
+    int chisqNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.CHISQ.NUM");
+    if (!status) chisqNum = -1;
+
+    // loop over the available readouts
+    for (int i = 0; i < num; i++) {
+        if (i == chisqNum) continue; // skip chisq image
+        if (!psphotLensingReadout (config, view, filerule, i, recipe)) {
+            psError (PSPHOT_ERR_CONFIG, false, "failed to measure lensing parameters for %s entry %d", filerule, i);
+            return false;
+        }
+        if (!psphotLensingPSFtrendsReadout (config, view, filerule, i, recipe)) {
+            psError (PSPHOT_ERR_CONFIG, false, "failed to measure lensing parameters for %s entry %d", filerule, i);
+            return false;
+        }
+    }
+    return true;
+}
+
+// this block measures the lensing parameters for all objects
+bool psphotLensingReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe)
+{
+    bool status;
+    pmSource *source;
+
+    psTimerStart ("psphot.lensing");
+
+    // find the currently selected readout
+    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, index); // File of interest
+    psAssert (file, "missing file?");
+
+    pmReadout *readout = pmFPAviewThisReadout(view, file->fpa);
+    psAssert (readout, "missing readout?");
+
+    // if we have measured the window, we will be saving the modified version of these recipe values on readout->analysis
+    float SIGMA = psMetadataLookupF32 (&status, readout->analysis, "MOMENTS_GAUSS_SIGMA");
+    if (!status) {
+        SIGMA = psMetadataLookupF32 (&status, recipe, "MOMENTS_GAUSS_SIGMA");
+    }
+
+    pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS");
+    psAssert (detections, "missing detections?");
+
+    psArray *sources = detections->allSources;
+    psAssert (sources, "missing sources?");
+
+    if (!sources->n) {
+        psLogMsg ("psphot", PS_LOG_INFO, "no sources, skipping lensing");
+        return true;
+    }
+
+    for (int i = 0; i < sources->n; i++) {
+        source = sources->data[i];
+
+	// skip saturated stars modeled with a radial profile 
+        if (source->mode2 & PM_SOURCE_MODE2_SATSTAR_PROFILE) continue;
+        if (source->mode  & PM_SOURCE_MODE_SATSTAR) continue;
+
+        if (source->mode &  PM_SOURCE_MODE_CR_LIMIT) continue;
+        if (source->mode &  PM_SOURCE_MODE_DEFECT) continue;
+
+        pmMoments *moments = source->moments;
+
+	if (!source->lensingOBJ) {
+	  source->lensingOBJ = pmSourceLensingAlloc ();
+	}
+
+	// XXX big objects (eg, saturated stars) use 3*SIGMA.  I'm ignoring this for now
+	pmSourceLensingShearFromMoments (source->lensingOBJ, moments, SIGMA);
+	pmSourceLensingSmearFromMoments (source->lensingOBJ, moments, SIGMA);
+    }
+
+    psMetadataAddBool(readout->analysis, PS_LIST_TAIL, "LENS_OBJ", PS_META_REPLACE, "per-object lensing stats measured", true);
+    psLogMsg ("psphot.lensing", PS_LOG_DETAIL, "calculate lensing parameters for %d objects\n", (int) sources->n);
+
+    return true;
+}
+
+// generate image maps for the Xij,ei elements based only on good stars
+bool psphotLensingPSFtrendsReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe)
+{
+    int Nfail = 0;
+    bool status;
+    pmSource *source;
+
+    psTimerStart ("psphot.lensing");
+
+    // find the currently selected readout
+    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, index); // File of interest
+    psAssert (file, "missing file?");
+
+    pmReadout *readout = pmFPAviewThisReadout(view, file->fpa);
+    psAssert (readout, "missing readout?");
+
+    pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS");
+    psAssert (detections, "missing detections?");
+
+    psArray *sources = detections->allSources;
+    psAssert (sources, "missing sources?");
+
+    if (!sources->n) {
+        psLogMsg ("psphot", PS_LOG_INFO, "no sources, skipping lensing psf trends");
+        return true;
+    }
+
+    // gather the stats to assess the aperture residuals
+    int Npsf = 0;
+    psVector *psfX11sm = psVectorAllocEmpty (300, PS_TYPE_F32);
+    psVector *psfX12sm = psVectorAllocEmpty (300, PS_TYPE_F32);
+    psVector *psfX22sm = psVectorAllocEmpty (300, PS_TYPE_F32);
+    psVector *psf_e1sm = psVectorAllocEmpty (300, PS_TYPE_F32);
+    psVector *psf_e2sm = psVectorAllocEmpty (300, PS_TYPE_F32);
+    psVector *psfX11sh = psVectorAllocEmpty (300, PS_TYPE_F32);
+    psVector *psfX12sh = psVectorAllocEmpty (300, PS_TYPE_F32);
+    psVector *psfX22sh = psVectorAllocEmpty (300, PS_TYPE_F32);
+    psVector *psf_e1sh = psVectorAllocEmpty (300, PS_TYPE_F32);
+    psVector *psf_e2sh = psVectorAllocEmpty (300, PS_TYPE_F32);
+    psVector *xPos     = psVectorAllocEmpty (300, PS_TYPE_F32);
+    psVector *yPos     = psVectorAllocEmpty (300, PS_TYPE_F32);
+
+    for (int i = 0; i < sources->n; i++) {
+        source = sources->data[i];
+
+	// only use good stars:
+        if (source->type != PM_SOURCE_TYPE_STAR) continue;
+        if (source->mode &  PM_SOURCE_MODE_SATSTAR) continue;
+        if (source->mode &  PM_SOURCE_MODE_BLEND) continue;
+        if (source->mode &  PM_SOURCE_MODE_FAIL) continue;
+        if (source->mode &  PM_SOURCE_MODE_POOR) continue;
+
+	// skip saturated stars modeled with a radial profile 
+        if (source->mode2 & PM_SOURCE_MODE2_SATSTAR_PROFILE) continue;
+
+        if (source->mode &  PM_SOURCE_MODE_EXT_LIMIT) continue;
+        if (source->mode &  PM_SOURCE_MODE_CR_LIMIT) continue;
+        if (source->mode &  PM_SOURCE_MODE_DEFECT) continue;
+        if (source->mode2 & PM_SOURCE_MODE2_MATCHED) continue; // XXX ???
+
+	// use psf - ap to limit to good stars?
+	// XXX need to be sure if this is before or after ap corrections are done
+        if (!isfinite(source->apMag)) continue;
+	if (!isfinite(source->psfMag)) continue;
+
+        // XXX make this user-configurable?
+        if (source->psfMagErr > 0.03) continue;
+
+        // aperture residual for this source
+        float dap = source->apMag - source->psfMag;
+
+	// good stars have |dap| < 0.2
+        if (fabs(dap) > 0.2) {
+            Nfail ++;
+            psTrace ("psphot", 3, "fail : bad dap: %f", dap);
+            continue;
+        }
+
+	pmModel *model = source->modelPSF;
+
+        psVectorAppend (xPos, model->params->data.F32[PM_PAR_XPOS]);
+        psVectorAppend (yPos, model->params->data.F32[PM_PAR_YPOS]);
+        psVectorAppend (psfX11sm, source->lensingOBJ->smear->X11);
+        psVectorAppend (psfX12sm, source->lensingOBJ->smear->X12);
+        psVectorAppend (psfX22sm, source->lensingOBJ->smear->X22);
+        psVectorAppend (psf_e1sm, source->lensingOBJ->smear->e1);
+        psVectorAppend (psf_e2sm, source->lensingOBJ->smear->e2);
+        psVectorAppend (psfX11sh, source->lensingOBJ->shear->X11);
+        psVectorAppend (psfX12sh, source->lensingOBJ->shear->X12);
+        psVectorAppend (psfX22sh, source->lensingOBJ->shear->X22);
+        psVectorAppend (psf_e1sh, source->lensingOBJ->shear->e1);
+        psVectorAppend (psf_e2sh, source->lensingOBJ->shear->e2);
+	Npsf ++;
+    }
+
+    // this is a bit tricky, because we have two cases (MAP vs POLY), and they have a different
+    // definition for 'order' (order_MAP = order_POLY + 1).  in addition, we have a
+    // user-specified MAX order, which we should respect, regardless of the mode
+
+    // set the max order (0 = constant) which the number of psf stars can support:
+    // we require only 3 stars for n = 0, increase stars / cell for higher order
+    if (Npsf < 3) {
+        psLogMsg ("psphot", PS_LOG_INFO, "no sources passed selection criteria, skipping lensing psf trends");
+        return true;
+    }
+    int LensingTrendOrder = 0;
+    if (Npsf >=  16) LensingTrendOrder = 1; // 4 cells
+    if (Npsf >=  54) LensingTrendOrder = 2; // 9 cells
+    if (Npsf >= 128) LensingTrendOrder = 3; // 16 cells
+    if (Npsf >= 300) LensingTrendOrder = 4; // 25 cells
+    if (Npsf >  576) LensingTrendOrder = 5; // 36 cells
+
+    pmTrend2DMode mode = PM_TREND_MAP;
+    if (mode == PM_TREND_MAP) {
+        LensingTrendOrder ++;
+    }
+
+    // Nx,Ny are the superpixel size; but I need to choose them to allow a max of LensingTrendOrder values
+    // I'm not sure this is really sensible, but... 
+    int NX = readout->image->numCols;
+    int NY = readout->image->numRows;
+    int Nx, Ny;
+    if (NX > NY) {
+      Nx = LensingTrendOrder;
+      Ny = PS_MAX (1, (int)(LensingTrendOrder * (NY / (float)(NX)) + 0.5));
+    } else {
+      Ny = LensingTrendOrder;
+      Nx = PS_MAX (1, (int)(LensingTrendOrder * (NX / (float)(NY)) + 0.5));
+    }
+
+    psLogMsg ("psphot.lensing", PS_LOG_DETAIL, "generate lensing maps using %d objects (%d x %d grid)\n", Npsf, Nx, Ny);
+
+    // XXX allow user to set this optionally?
+    psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV);
+
+    // measure Trend2D for the current spatial scale
+    pmTrend2D *trendX11sm = pmTrend2DAlloc (PM_TREND_MAP, readout->image, Nx, Ny, stats);
+    pmTrend2D *trendX12sm = pmTrend2DAlloc (PM_TREND_MAP, readout->image, Nx, Ny, stats);
+    pmTrend2D *trendX22sm = pmTrend2DAlloc (PM_TREND_MAP, readout->image, Nx, Ny, stats);
+    pmTrend2D *trend_e1sm = pmTrend2DAlloc (PM_TREND_MAP, readout->image, Nx, Ny, stats);
+    pmTrend2D *trend_e2sm = pmTrend2DAlloc (PM_TREND_MAP, readout->image, Nx, Ny, stats);
+
+    pmTrend2D *trendX11sh = pmTrend2DAlloc (PM_TREND_MAP, readout->image, Nx, Ny, stats);
+    pmTrend2D *trendX12sh = pmTrend2DAlloc (PM_TREND_MAP, readout->image, Nx, Ny, stats);
+    pmTrend2D *trendX22sh = pmTrend2DAlloc (PM_TREND_MAP, readout->image, Nx, Ny, stats);
+    pmTrend2D *trend_e1sh = pmTrend2DAlloc (PM_TREND_MAP, readout->image, Nx, Ny, stats);
+    pmTrend2D *trend_e2sh = pmTrend2DAlloc (PM_TREND_MAP, readout->image, Nx, Ny, stats);
+
+    bool goodFit = false;
+    if (!pmTrend2DFit (&goodFit, trendX11sm, NULL, 0xff, xPos, yPos, psfX11sm, NULL)) { psWarning ("failed to measure X11 smear trend"); }
+    if (!pmTrend2DFit (&goodFit, trendX12sm, NULL, 0xff, xPos, yPos, psfX12sm, NULL)) { psWarning ("failed to measure X12 smear trend"); }
+    if (!pmTrend2DFit (&goodFit, trendX22sm, NULL, 0xff, xPos, yPos, psfX22sm, NULL)) { psWarning ("failed to measure X22 smear trend"); }
+    if (!pmTrend2DFit (&goodFit, trend_e1sm, NULL, 0xff, xPos, yPos, psf_e1sm, NULL)) { psWarning ("failed to measure  e1 smear trend"); }
+    if (!pmTrend2DFit (&goodFit, trend_e2sm, NULL, 0xff, xPos, yPos, psf_e2sm, NULL)) { psWarning ("failed to measure  e2 smear trend"); }
+
+    if (!pmTrend2DFit (&goodFit, trendX11sh, NULL, 0xff, xPos, yPos, psfX11sh, NULL)) { psWarning ("failed to measure X11 shear trend"); }
+    if (!pmTrend2DFit (&goodFit, trendX12sh, NULL, 0xff, xPos, yPos, psfX12sh, NULL)) { psWarning ("failed to measure X12 shear trend"); }
+    if (!pmTrend2DFit (&goodFit, trendX22sh, NULL, 0xff, xPos, yPos, psfX22sh, NULL)) { psWarning ("failed to measure X22 shear trend"); }
+    if (!pmTrend2DFit (&goodFit, trend_e1sh, NULL, 0xff, xPos, yPos, psf_e1sh, NULL)) { psWarning ("failed to measure  e1 shear trend"); }
+    if (!pmTrend2DFit (&goodFit, trend_e2sh, NULL, 0xff, xPos, yPos, psf_e2sh, NULL)) { psWarning ("failed to measure  e2 shear trend"); }
+
+    // evaluate the PSF trend maps at the location of all sources
+    for (int i = 0; i < sources->n; i++) {
+        source = sources->data[i];
+	pmPeak *peak = source->peak;
+	if (!peak) continue;
+
+	float xPos = peak->xf;
+	float yPos = peak->yf;
+
+	if (!source->lensingPSF) {
+	  source->lensingPSF = pmSourceLensingAlloc ();
+	}
+	pmSourceLensing *lensing = source->lensingPSF;
+
+	if (!lensing->shear) {
+	  lensing->shear = pmLensingParsAlloc();
+	}
+	pmLensingPars *shear = lensing->shear;
+
+	shear->X11 = pmTrend2DEval (trendX11sh, xPos, yPos);
+	shear->X12 = pmTrend2DEval (trendX12sh, xPos, yPos);
+	shear->X22 = pmTrend2DEval (trendX22sh, xPos, yPos);
+	shear->e1  = pmTrend2DEval (trend_e1sh, xPos, yPos);
+	shear->e2  = pmTrend2DEval (trend_e2sh, xPos, yPos);
+	
+	if (!lensing->smear) {
+	  lensing->smear = pmLensingParsAlloc();
+	}
+	pmLensingPars *smear = lensing->smear;
+
+	smear->X11 = pmTrend2DEval (trendX11sm, xPos, yPos);
+	smear->X12 = pmTrend2DEval (trendX12sm, xPos, yPos);
+	smear->X22 = pmTrend2DEval (trendX22sm, xPos, yPos);
+	smear->e1  = pmTrend2DEval (trend_e1sm, xPos, yPos);
+	smear->e2  = pmTrend2DEval (trend_e2sm, xPos, yPos);
+    }
+
+    psFree (trendX11sm);
+    psFree (trendX12sm);
+    psFree (trendX22sm);
+    psFree (trend_e1sm);
+    psFree (trend_e2sm);
+	              
+    psFree (trendX11sh);
+    psFree (trendX12sh);
+    psFree (trendX22sh);
+    psFree (trend_e1sh);
+    psFree (trend_e2sh);
+
+    psFree (psfX11sm);
+    psFree (psfX12sm);
+    psFree (psfX22sm);
+    psFree (psf_e1sm);
+    psFree (psf_e2sm);
+    psFree (psfX11sh);
+    psFree (psfX12sh);
+    psFree (psfX22sh);
+    psFree (psf_e1sh);
+    psFree (psf_e2sh);
+    psFree (xPos    );
+    psFree (yPos    );
+
+    psFree (stats);
+
+    psMetadataAddBool(readout->analysis, PS_LIST_TAIL, "LENS_PSF", PS_META_REPLACE, "psf-trend lensing stats measured", true);
+    psLogMsg ("psphot.lensing", PS_LOG_DETAIL, "calculate lensing parameters for %d objects: %f sec\n", (int) sources->n, psTimerMark ("psphot.lensing"));
+
+    return true;
+}
+
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotLoadPSF.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotLoadPSF.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotLoadPSF.c	(revision 37066)
@@ -1,3 +1,20 @@
 # include "psphotInternal.h"
+
+// PSPHOT.PSF.LOAD vs input file -- see note at top
+bool psphotLoadPSF (pmConfig *config, const pmFPAview *view, const char *filerule) {
+
+    int num = psphotFileruleCount(config, filerule);
+
+    // loop over the available readouts
+    for (int i = 0; i < num; i++) {
+
+        // Generate the mask and weight images, including the user-defined analysis region of interest
+        if (!psphotLoadPSFReadout (config, view, filerule, "PSPHOT.PSF.LOAD", i)) {
+            psError (PSPHOT_ERR_CONFIG, false, "failed to load PSF model for PSPHOT.PSF.LOAD entry %d", i);
+            return false;
+        }
+    }
+    return true;
+}
 
 // NOTE : pmPSF_IO.c functions must load the psf model onto the chip->analysis metadata because
@@ -58,19 +75,2 @@
     return true;
 }
-
-// PSPHOT.PSF.LOAD vs input file -- see note at top
-bool psphotLoadPSF (pmConfig *config, const pmFPAview *view, const char *filerule) {
-
-    int num = psphotFileruleCount(config, filerule);
-
-    // loop over the available readouts
-    for (int i = 0; i < num; i++) {
-
-        // Generate the mask and weight images, including the user-defined analysis region of interest
-        if (!psphotLoadPSFReadout (config, view, filerule, "PSPHOT.PSF.LOAD", i)) {
-            psError (PSPHOT_ERR_CONFIG, false, "failed to load PSF model for PSPHOT.PSF.LOAD entry %d", i);
-            return false;
-        }
-    }
-    return true;
-}
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotLoadSRCTEXT.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotLoadSRCTEXT.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotLoadSRCTEXT.c	(revision 37066)
@@ -73,5 +73,5 @@
 	    dPAR[PM_PAR_I0]   = 0.0;
 
-	    pmPSF_AxesToModel (PAR, axes, modelType);
+	    pmPSF_AxesToModel (PAR, axes, model->class->useReff);
 
 	    float peakFlux    = 1.0;
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotMakeFluxScale.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotMakeFluxScale.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotMakeFluxScale.c	(revision 37066)
@@ -38,5 +38,5 @@
             } else {
 		// measure the fitMag for this model
-		fitSum = model->modelFlux (model->params);
+		fitSum = model->class->modelFlux (model->params);
 	    }
 	    if (fitSum < 1.e-6) continue;
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotMergeSources.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotMergeSources.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotMergeSources.c	(revision 37066)
@@ -39,12 +39,4 @@
     psAssert (newSources, "missing sources?");
 
-    // XXX TEST:
-    if (detections->allSources) {
-        psphotMaskCosmicRayFootprintCheck(detections->allSources);
-    }
-    if (detections->newSources) {
-        psphotMaskCosmicRayFootprintCheck(detections->newSources);
-    }
-
     if (!detections->allSources) {
         detections->allSources = psArrayAllocEmpty(newSources->n);
@@ -65,4 +57,7 @@
 // Merge the externally supplied sources with the existing sources.  Mark them as having mode
 // PM_SOURCE_MODE_EXTERNAL.
+
+// XXX this function needs to be updated slightly for psphotFullForce:
+// * load the additional parameters to guide the new concepts
 
 // XXX This function needs to be updated to loop over set of input files.  At the moment, we
@@ -73,4 +68,5 @@
     bool status;
     pmDetections *extCMF = NULL;
+    pmDetections *extCFF = NULL;
     psArray *extSourcesTXT = NULL;
     int index = 0;
@@ -102,5 +98,5 @@
     {
         pmReadout *readoutCMF = pmFPAfileThisReadout (config->files, view, "PSPHOT.INPUT.CMF");
-        if (!readoutCMF) goto loadTXT;
+        if (!readoutCMF) goto loadCFF;
 
         extCMF = psMetadataLookupPtr (NULL, readoutCMF->analysis, "PSPHOT.DETECTIONS");
@@ -125,4 +121,37 @@
     }
 
+loadCFF:
+    // load data from input CFF file:
+    {
+        pmReadout *readoutCFF = pmFPAfileThisReadout (config->files, view, "PSPHOT.INPUT.CFF");
+        if (!readoutCFF) goto loadTXT;
+
+        extCFF = psMetadataLookupPtr (NULL, readoutCFF->analysis, "PSPHOT.DETECTIONS");
+        if (extCFF) {
+            psF32 exptime = psMetadataLookupF32(NULL, readout->parent->concepts, "CELL.EXPOSURE");
+            for (int i = 0; i < extCFF->allSources->n; i++) {
+                pmSource *source = extCFF->allSources->data[i];
+
+		// setting this bit not only tracks the inputs, it makes pmSourceMoments
+		// keep the Mx,My values for the centroid.  
+                source->mode |= PM_SOURCE_MODE_EXTERNAL;
+
+		// source->peak->detValue,rawFlux,smoothFlux all set to input flux value which is scaled
+                // to 1 second exposure time. Scale to this image's exposure.
+                source->peak->rawFlux    *= exptime;
+                source->peak->smoothFlux *= exptime;
+                source->peak->detValue   *= exptime;
+		// source->peak->xf,yf, moments->Mx,My all set to input position
+
+                // drop the loaded source modelPSF
+                psFree (source->modelPSF);
+                source->modelPSF = NULL;
+		source->imageID = index;
+
+                psArrayAdd (detections->newSources, 100, source);
+            }
+        }
+    }
+
 loadTXT:
 
@@ -157,5 +186,5 @@
     psFree (detections);
 
-    if (!extCMF && !extSourcesTXT) {
+    if (!(extCMF || extCFF || extSourcesTXT)) {
         psLogMsg ("psphot", 3, "no external sources for this readout");
         return true;
@@ -163,8 +192,9 @@
 
     int nCMF = extCMF        ? extCMF->allSources->n        : 0;
-    int nTXT = extSourcesTXT ? extSourcesTXT->n : 0;
-
-    psLogMsg ("psphot", 3, "%d external sources (%d cmf, %d text) merged to yield %ld total sources",
-              nCMF + nTXT, nCMF, nTXT, sources->n);
+    int nCFF = extCFF        ? extCFF->allSources->n        : 0;
+    int nTXT = extSourcesTXT ? extSourcesTXT->n             : 0;
+
+    psLogMsg ("psphot", 3, "%d external sources (%d cmf, %d cff, %d text) merged to yield %ld total sources",
+              nCMF + nCFF + nTXT, nCMF, nCFF, nTXT, sources->n);
     return true;
 }
@@ -812,5 +842,5 @@
 // array containing the child sources.  XXX currently, this is only used by psphotStackReadout
 // (sources go on allSources so that psphotChoosePSF can be called repeatedly)
-psArray *psphotSourceChildrenByObject (pmConfig *config, const pmFPAview *view, const char *filerule, psArray *objectsSrc) {
+psArray *psphotSourceChildrenByObject (pmConfig *config, const pmFPAview *view, const char *filerule, psArray *objectsSrc, bool sourcesSubtracted) {
 
     bool status;
@@ -919,5 +949,10 @@
 	    // child sources have not been subtracted in this image, but this flag may be raised if
 	    // they were subtracted in the parent's image
-	    sourceOut->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED;
+	    // XXX NOTE : in the pre-20130914 version of psphotStack, we carried a copy of the pixels 
+	    // generated before the subtraction took place (and then we smoothed to match the desired PSF).  
+	    // in the new version, we copy the image after subtraction; we need to distinguish these cases
+	    if (!sourcesSubtracted) {
+		sourceOut->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED;
+	    }
 
 	    // set the output detections:
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotModelTestReadout.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotModelTestReadout.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotModelTestReadout.c	(revision 37066)
@@ -125,5 +125,5 @@
 
 	    // get the source moments
-	    status = pmSourceMoments (source, radius, 0.25*radius, 0.0, MIN_KRON_RADIUS, maskVal);
+	  status = pmSourceMoments (source, radius, 0.25*radius, 0.0, MIN_KRON_RADIUS, maskVal);
 	    if (!status) psAbort("psSourceMoments error");
 
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotOldCode.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotOldCode.c	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotOldCode.c	(revision 37066)
@@ -0,0 +1,350 @@
+
+/***************
+
+  In the process of developing psphot, I have written a bunch of code that has been used
+  for some tests or for a period, but which we no longer think is appropriate.  I am
+  trying to clean up the kruft of old psphot bits and will but various such functions in
+  this file if they are worth keeping
+
+****************/
+
+bool psphotMaskCosmicRayFootprintCheck (psArray *sources);
+
+
+// maybe move this into psModules, pmFootprints?
+bool psphotMaskCosmicRayFootprintCheck (psArray *sources) {
+#ifdef CHECK_FOOTPRINTS
+    // This gets really expensive for complex images
+    for (int i = 0; i < sources->n; i++) {
+        pmSource *source = sources->data[i];
+        pmPeak *peak = source->peak;
+        pmFootprint *footprint = peak->footprint;
+        if (!footprint) continue;
+        for (int j = 0; j < footprint->spans->n; j++) {
+            pmSpan *sp = footprint->spans->data[j];
+            psAssert (sp, "missing span");
+        }
+    }
+#endif
+    return true;
+}
+
+// mark the isophotal boundary
+bool psphotMaskCosmicRayIsophot (pmSource *source, psImageMaskType maskVal, psImageMaskType crMask) {
+
+    source->mode |= PM_SOURCE_MODE_CR_LIMIT;
+    pmPeak *peak = source->peak;
+    psAssert (peak, "NULL peak");
+
+    psImage *mask   = source->maskView;
+    psImage *pixels = source->pixels;
+    psImage *variance = source->variance;
+
+    // XXX This should be a recipe variable
+# define SN_LIMIT 5.0
+
+    int xo = peak->x - pixels->col0;
+    int yo = peak->y - pixels->row0;
+
+    // mark the pixels in this row to the left, then the right
+    for (int ix = xo; ix >= 0; ix--) {
+        float SN = pixels->data.F32[yo][ix] / sqrt(variance->data.F32[yo][ix]);
+        if (SN > SN_LIMIT) {
+            mask->data.PS_TYPE_IMAGE_MASK_DATA[yo][ix] |= crMask;
+        }
+    }
+    for (int ix = xo + 1; ix < pixels->numCols; ix++) {
+        float SN = pixels->data.F32[yo][ix] / sqrt(variance->data.F32[yo][ix]);
+        if (SN > SN_LIMIT) {
+            mask->data.PS_TYPE_IMAGE_MASK_DATA[yo][ix] |= crMask;
+        }
+    }
+
+    // for each of the neighboring rows, mark the high pixels if they have a marked neighbor
+    // first go up:
+    for (int iy = PS_MIN(yo, mask->numRows-2); iy >= 0; iy--) {
+        // mark the pixels in this row to the left, then the right
+        for (int ix = 0; ix < pixels->numCols; ix++) {
+            float SN = pixels->data.F32[iy][ix] / sqrt(variance->data.F32[iy][ix]);
+            if (SN < SN_LIMIT) continue;
+
+            bool valid = false;
+            valid |= (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+1][ix] & crMask);
+            valid |= (ix > 0) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+1][ix-1] & crMask) : 0;
+            valid |= (ix <= mask->numCols) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+1][ix+1] & crMask) : 0;
+
+            if (!valid) continue;
+            mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= crMask;
+        }
+    }
+    // next go down:
+    for (int iy = PS_MIN(yo+1, mask->numRows-1); iy < pixels->numRows; iy++) {
+        // mark the pixels in this row to the left, then the right
+        for (int ix = 0; ix < pixels->numCols; ix++) {
+            float SN = pixels->data.F32[iy][ix] / sqrt(variance->data.F32[iy][ix]);
+            if (SN < SN_LIMIT) continue;
+
+            bool valid = false;
+            valid |= (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy-1][ix] & crMask);
+            valid |= (ix > 0) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy-1][ix-1] & crMask) : 0;
+            valid |= (ix <= mask->numCols) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy-1][ix+1] & crMask) : 0;
+
+            if (!valid) continue;
+            mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= crMask;
+        }
+    }
+    return true;
+}
+
+// This attempt to mask the cosmic rays used the isophotal boundary
+bool psphotMaskCosmicRay_V1 (psImage *mask, pmSource *source, psImageMaskType maskVal, psImageMaskType crMask) {
+
+    // replace the source flux
+    pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);
+
+    // flag this as a CR
+    source->mode |= PM_SOURCE_MODE_CR_LIMIT;
+    pmPeak *peak = source->peak;
+    psAssert (peak, "NULL peak");
+
+    // grab the matching footprint
+    pmFootprint *footprint = peak->footprint;
+    if (!footprint) {
+      psTrace("psphot.czw",2,"Using isophot CR mask code.");
+
+        // if we have not footprint, use the old code to mask by isophot
+        psphotMaskCosmicRayIsophot (source, maskVal, crMask);
+        return true;
+    }
+
+    if (!footprint->spans) {
+      psTrace("psphot.czw",2,"Using isophot CR mask code.");
+
+        // if we have no footprint, use the old code to mask by isophot
+        psphotMaskCosmicRayIsophot (source, maskVal, crMask);
+        return true;
+    }
+    psphotMaskCosmicRayIsophot (source, maskVal, crMask);
+    // mask all of the pixels covered by the spans of the footprint
+    for (int j = 1; j < footprint->spans->n; j++) {
+        pmSpan *span1 = footprint->spans->data[j];
+
+        int iy = span1->y;
+        int xs = span1->x0;
+        int xe = span1->x1;
+
+        for (int ix = xs; ix < xe; ix++) {
+            mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= crMask;
+        }
+    }
+    return true;
+}
+
+// given the PSF ellipse parameters, navigate around the 1sigma contour, return the total
+// deviation in sigmas.  This is measured on the residual image - should we ignore negative
+// deviations?  NOTE: This function was an early attempt to classify extended objects, and is
+// no longer used by psphot.
+float psphotModelContour(const psImage *image, const psImage *variance, const psImage *mask,
+                         psImageMaskType maskVal, const pmModel *model, float Ro)
+{
+    psF32 *PAR = model->params->data.F32; // Model parameters
+    float sxx = PAR[PM_PAR_SXX], sxy = PAR[PM_PAR_SXY], syy = PAR[PM_PAR_SYY]; // Ellipse parameters
+
+    // We treat the contour as an ellipse:
+    // Ro = (x / SXX)^2 + (y / SYY)^2 + x y SXY
+    // y^2 (1/SYY^2) + y (x SXY) + (x / SXX)^2 - Ro = 0;
+    // This is a quadratic, Ay^2 + By + C with A = 1/SYY^2, B = x*SXY, C = (x / SXX)^2 - Ro
+    // The solution is y = [-B +/- sqrt (B^2 - 4 A C)] / [2 A], so:
+    // y = [-(x SXY) +/- sqrt ((x SXY)^2 - 4 (1/SYY^2) ((x/SXX)^2 - Ro))] * [SYY^2 / 2]
+
+    // min/max value of x is where B^2 - 4AC = 0; solve this for x
+    float Q = Ro * PS_SQR(sxx) / (1.0 - PS_SQR(sxx * syy * sxy) / 4.0);
+    if (Q < 0.0) {
+        // ellipse is imaginary
+        return NAN;
+    }
+
+    int radius = sqrtf(Q) + 0.5;        // Radius of ellipse
+    int nPts = 0;                       // Number of points in ellipse
+    float nSigma = 0.0;                 //
+
+    for (int x = -radius; x <= radius; x++) {
+        // Polynomial coefficients
+        // XXX Should we be using the centre of the pixel as x or x+0.5?
+        float A = PS_SQR (1.0 / syy);
+        float B = x * sxy;
+        float C = PS_SQR (x / sxx) - Ro;
+        float T = PS_SQR(B) - 4*A*C;
+        if (T < 0.0) {
+            continue;
+        }
+
+        // y position in source frame
+        float yP = (-B + sqrt (T)) / (2.0 * A);
+        float yM = (-B - sqrt (T)) / (2.0 * A);
+
+        // Get the closest pixel positions (image frame)
+        int xPix  = x  + PAR[PM_PAR_XPOS] - image->col0 + 0.5;
+        int yPixM = yM + PAR[PM_PAR_YPOS] - image->row0 + 0.5;
+        int yPixP = yP + PAR[PM_PAR_YPOS] - image->row0 + 0.5;
+
+        if (xPix < 0 || xPix >= image->numCols) {
+            continue;
+        }
+
+        if (yPixM >= 0 && yPixM < image->numRows &&
+            !(mask && (mask->data.PS_TYPE_IMAGE_MASK_DATA[yPixM][xPix] & maskVal))) {
+            float dSigma = image->data.F32[yPixM][xPix] / sqrtf(variance->data.F32[yPixM][xPix]);
+            nSigma += dSigma;
+            nPts++;
+        }
+
+        if (yPixM == yPixP) {
+            continue;
+        }
+
+        if (yPixP >= 0 && yPixP < image->numRows &&
+            !(mask && (mask->data.PS_TYPE_IMAGE_MASK_DATA[yPixP][xPix] & maskVal))) {
+            float dSigma = image->data.F32[yPixP][xPix] / sqrtf(variance->data.F32[yPixP][xPix]);
+            nSigma += dSigma;
+            nPts++;
+        }
+    }
+    nSigma /= nPts;
+    return nSigma;
+}
+
+// this was an old attempt to identify cosmic rays based on the peak curvature
+bool psphotSourcePeakCurvature (pmReadout *readout, psArray *sources, psphotSourceSizeOptions *options) {
+
+    // classify the sources based on the CR test (place this in a function?)
+    // XXX use an internal flag to mark sources which have already been measured
+    for (int i = 0; i < sources->n; i++) {
+        pmSource *source = sources->data[i];
+
+        // skip source if it was already measured
+        if (source->tmpFlags & PM_SOURCE_TMPF_SIZE_MEASURED) {
+            psTrace("psphot", 7, "Not calculating source size since it has already been measured\n");
+            continue;
+        }
+
+        // source must have been subtracted
+        if (!(source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED)) {
+            source->mode |= PM_SOURCE_MODE_SIZE_SKIPPED;
+            psTrace("psphot", 7, "Not calculating source size since source is not subtracted\n");
+            continue;
+        }
+
+        psF32 **resid  = source->pixels->data.F32;
+        psF32 **variance = source->variance->data.F32;
+        psImageMaskType **mask = source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA;
+
+        // Integer position of peak
+        int xPeak = source->peak->xf - source->pixels->col0 + 0.5;
+        int yPeak = source->peak->yf - source->pixels->row0 + 0.5;
+
+        // Skip sources which are too close to a boundary.  These are mostly caught as DEFECT
+        if (xPeak < 1 || xPeak > source->pixels->numCols - 2 ||
+            yPeak < 1 || yPeak > source->pixels->numRows - 2) {
+            psTrace("psphot", 7, "Not calculating crNsigma due to edge\n");
+            continue;
+        }
+
+        // Skip sources with masked pixels.  These are mostly caught as DEFECT
+        bool keep = true;
+        for (int iy = -1; (iy <= +1) && keep; iy++) {
+            for (int ix = -1; (ix <= +1) && keep; ix++) {
+                if (mask[yPeak+iy][xPeak+ix] & options->maskVal) {
+                    keep = false;
+                }
+            }
+        }
+        if (!keep) {
+            psTrace("psphot", 7, "Not calculating crNsigma due to masked pixels\n");
+            continue;
+        }
+
+        // Compare the central pixel with those on either side, for the four possible lines through it.
+
+        // Soften variances (add systematic error)
+        float softening = options->soft * PS_SQR(source->peak->rawFlux); // Softening for variances
+
+        // Across the middle: y = 0
+        float cX = 2*resid[yPeak][xPeak]   - resid[yPeak+0][xPeak-1]  - resid[yPeak+0][xPeak+1];
+        float dcX = 4*variance[yPeak][xPeak] + variance[yPeak+0][xPeak-1] + variance[yPeak+0][xPeak+1];
+        float nX = cX / sqrtf(dcX + softening);
+
+        // Up the centre: x = 0
+        float cY = 2*resid[yPeak][xPeak]   - resid[yPeak-1][xPeak+0]  - resid[yPeak+1][xPeak+0];
+        float dcY = 4*variance[yPeak][xPeak] + variance[yPeak-1][xPeak+0] + variance[yPeak+1][xPeak+0];
+        float nY = cY / sqrtf(dcY + softening);
+
+        // Diagonal: x = y
+        float cL = 2*resid[yPeak][xPeak]   - resid[yPeak-1][xPeak-1]  - resid[yPeak+1][xPeak+1];
+        float dcL = 4*variance[yPeak][xPeak] + variance[yPeak-1][xPeak-1] + variance[yPeak+1][xPeak+1];
+        float nL = cL / sqrtf(dcL + softening);
+
+        // Diagonal: x = - y
+        float cR = 2*resid[yPeak][xPeak]   - resid[yPeak+1][xPeak-1]  - resid[yPeak-1][xPeak+1];
+        float dcR = 4*variance[yPeak][xPeak] + variance[yPeak+1][xPeak-1] + variance[yPeak-1][xPeak+1];
+        float nR = cR / sqrtf(dcR + softening);
+
+        // P(chisq > chisq_obs; Ndof) = gamma_Q (Ndof/2, chisq/2)
+        // Ndof = 4 ? (four measurements, no free parameters)
+        // XXX this value is going to be biased low because of systematic errors.
+        // we need to calibrate it somehow
+        // source->psfProb = gsl_sf_gamma_inc_Q (2, 0.5*chisq);
+
+        // not strictly accurate: overcounts the chisq contribution from the center pixel (by
+        // factor of 4); also biases a bit low if any pixels are masked
+        // XXX I am not sure I want to keep this value...
+        source->psfChisq = PS_SQR(nX) + PS_SQR(nY) + PS_SQR(nL) + PS_SQR(nR);
+
+        float fCR = 0.0;
+        int nCR = 0;
+        if (nX > 0.0) {
+            fCR += nX;
+            nCR ++;
+        }
+        if (nY > 0.0) {
+            fCR += nY;
+            nCR ++;
+        }
+        if (nL > 0.0) {
+            fCR += nL;
+            nCR ++;
+        }
+        if (nR > 0.0) {
+            fCR += nR;
+            nCR ++;
+        }
+        source->crNsigma  = (nCR > 0)  ? fCR / nCR : 0.0;
+        source->tmpFlags |= PM_SOURCE_TMPF_SIZE_MEASURED;
+
+        if (!isfinite(source->crNsigma)) {
+            continue;
+        }
+
+        // this source is thought to be a cosmic ray.  flag the detection and mask the pixels
+        if (source->crNsigma > options->nSigmaCR) {
+            source->mode |= PM_SOURCE_MODE_CR_LIMIT;
+            // XXX still testing... : psphotMaskCosmicRay (readout->mask, source, maskVal, crMask);
+            // XXX acting strange... psphotMaskCosmicRay_Old (source, maskVal, crMask);
+        }
+    }
+
+    // now that we have masked pixels associated with CRs, we can grow the mask
+    if (options->grow > 0) {
+        bool oldThreads = psImageConvolveSetThreads(true); // Old value of threading for psImageConvolveMask
+        psImage *newMask = psImageConvolveMask(NULL, readout->mask, options->crMask, options->crMask, -options->grow, options->grow, -options->grow, options->grow);
+        psImageConvolveSetThreads(oldThreads);
+        if (!newMask) {
+            psError(PS_ERR_UNKNOWN, false, "Unable to grow CR mask");
+            return false;
+        }
+        psFree(readout->mask);
+        readout->mask = newMask;
+    }
+    return true;
+}
+
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotPetroFlux.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotPetroFlux.c	(revision 37066)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotPetroFlux.c	(revision 37066)
@@ -0,0 +1,259 @@
+# include "psphotInternal.h"
+
+# define PETROSIAN_RADII 2.0
+
+bool psphotPetroFlux (pmConfig *config, const pmFPAview *view, const char *filerule)
+{
+    bool status = true;
+
+    fprintf (stdout, "\n");
+    psLogMsg ("psphot", PS_LOG_INFO, "--- psphot Petro Fluxes ---");
+
+    // select the appropriate recipe information
+    psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE);
+    psAssert (recipe, "missing recipe?");
+
+    int num = psphotFileruleCount(config, filerule);
+
+    // skip the chisq image (optionally?)
+    int chisqNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.CHISQ.NUM");
+    if (!status) chisqNum = -1;
+
+    psMetadataAddBool (recipe, PS_LIST_TAIL, "EXTENDED_SOURCE_ANALYSIS", PS_META_REPLACE, "we measured this, save to disk", true);
+
+    // loop over the available readouts
+    for (int i = 0; i < num; i++) {
+        if (i == chisqNum) continue; // skip chisq image
+
+        // find the currently selected readout
+        pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, i); // File of interest
+        psAssert (file, "missing file?");
+
+        pmReadout *readout = pmFPAviewThisReadout(view, file->fpa);
+        psAssert (readout, "missing readout?");
+
+        pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS");
+        psAssert (detections, "missing detections?");
+
+        psArray *sources = detections->newSources ? detections->newSources : detections->allSources;
+        psAssert (sources, "missing sources?");
+
+        if (!psphotPetroFluxReadout (config, recipe, view, filerule, readout, sources)) {
+            psError (PSPHOT_ERR_CONFIG, false, "failed to measure magnitudes for %s entry %d", filerule, i);
+            return false;
+        }
+    }
+    return true;
+}
+
+bool psphotPetroFluxReadout(pmConfig *config, psMetadata *recipe, const pmFPAview *view, const char * filerule, pmReadout *readout, psArray *sources) {
+
+    bool status = false;
+
+    if (!sources->n) {
+        psLogMsg ("psphot", PS_LOG_INFO, "no sources, skipping petrosian fluxes");
+        return true;
+    }
+
+    psTimerStart ("psphot.petro");
+
+    // determine the number of allowed threads
+    int nThreads = psMetadataLookupS32(&status, config->arguments, "NTHREADS"); // Number of threads
+    if (!status) {
+        nThreads = 0;
+    }
+
+    // bit-masks to test for good/bad pixels
+    psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT");
+    assert (maskVal);
+
+    // bit-mask to mark pixels not used in analysis
+    psImageMaskType markVal = psMetadataLookupImageMask(&status, recipe, "MARK.PSPHOT");
+    assert (markVal);
+
+    // maskVal is used to test for rejected pixels, and must include markVal
+    maskVal |= markVal;
+
+    // source analysis is done in S/N order (brightest first)
+    sources = psArraySort (sources, pmSourceSortByFlux);
+    if (!sources->n) {
+        psLogMsg ("psphot", PS_LOG_INFO, "no sources, skipping blend");
+        return true;
+    }
+
+    // threaded measurement of the source magnitudes
+    // choose Cx, Cy (see psphotThreadTools.c for overview of the concepts)
+    int Cx = 1, Cy = 1;
+    psphotChooseCellSizes (&Cx, &Cy, readout, nThreads);
+
+    psArray *cellGroups = psphotAssignSources (Cx, Cy, sources);
+
+    for (int i = 0; i < cellGroups->n; i++) {
+
+        psArray *cells = cellGroups->data[i];
+
+        for (int j = 0; j < cells->n; j++) {
+
+            // allocate a job -- if threads are not defined, this just runs the job
+            psThreadJob *job = psThreadJobAlloc ("PSPHOT_PETRO_FLUX");
+
+            psArrayAdd(job->args, 1, readout);
+            psArrayAdd(job->args, 1, cells->data[j]); // sources
+            PS_ARRAY_ADD_SCALAR(job->args, markVal,            PS_TYPE_IMAGE_MASK);
+            PS_ARRAY_ADD_SCALAR(job->args, maskVal,            PS_TYPE_IMAGE_MASK);
+
+// set this to 0 to run without threading
+# if (1)
+            if (!psThreadJobAddPending(job)) {
+                psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
+                return false;
+            }
+# else
+	    if (!psphotPetroFlux_Threaded(job)) {
+		psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
+		// psFree(AnalysisRegion);
+		return false;
+	    }
+	    psFree(job);
+# endif
+        }
+
+        // wait for the threads to finish and manage results
+        if (!psThreadPoolWait (false, true)) {
+            psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
+            return false;
+        }
+
+        // we have only supplied one type of job, so we can assume the types here
+        psThreadJob *job = NULL;
+        while ((job = psThreadJobGetDone()) != NULL) {
+            if (job->args->n < 1) {
+                fprintf (stderr, "error with job\n");
+            }
+            psFree(job);
+        }
+    }
+    psFree (cellGroups);
+
+    psLogMsg ("psphot.petro", PS_LOG_WARN, "measure petro fluxes : %f sec for %ld objects\n", psTimerMark ("psphot.petro"), sources->n);
+    return true;
+}
+
+bool psphotPetroFlux_Threaded (psThreadJob *job) {
+
+    pmReadout *readout              = job->args->data[0];
+    psArray *sources                = job->args->data[1];
+    psImageMaskType markVal         = PS_SCALAR_VALUE(job->args->data[2],PS_TYPE_IMAGE_MASK_DATA);
+    psImageMaskType maskVal         = PS_SCALAR_VALUE(job->args->data[3],PS_TYPE_IMAGE_MASK_DATA);
+
+    for (int i = 0; i < sources->n; i++) {
+
+	pmSource *source = sources->data[i];
+	if (!source->peak) continue; // XXX how can we have a peak-less source?
+	if (!source->extpars) continue; // if this is not set, we did not have a valid petRadius
+
+	// check status of this source's moments
+	if (!source->moments) continue;
+	if (!(source->tmpFlags & PM_SOURCE_TMPF_MOMENTS_MEASURED)) continue;
+	if (source->mode & PM_SOURCE_MODE_MOMENTS_FAILURE) continue;
+
+	// XXX where are we storing the supplied petro radius?
+	if (!isfinite(source->moments->Mrf)) continue;
+
+	// skip saturated stars modeled with a radial profile 
+	if (source->mode2 & PM_SOURCE_MODE2_SATSTAR_PROFILE) continue;
+
+	// replace object in image
+	if (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED) {
+	    pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);
+	}
+
+	// is the right??  XXX need the correct location for Rpet
+	float windowRadius = 2.0*source->moments->Mrf ;
+
+	// re-allocate image, weight, mask arrays for each peak with box big enough to fit BIG_RADIUS
+	pmSourceRedefinePixels (source, readout, source->peak->x, source->peak->y, windowRadius + 2);
+	psAssert (source->pixels, "WTF?");
+
+	// this function populates moments->Mrf,PetroFlux,PetroFluxErr
+	psphotPetroFluxSource (source, maskVal);
+	psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal));
+
+	pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
+    }
+
+    return true;
+}
+
+// measure just the flux in the given aperture (this is probably a single common function -- can I use one of the pmSourcePhotometry functions?)
+bool psphotPetroFluxSource (pmSource *source, psImageMaskType maskVal) {
+
+    PS_ASSERT_PTR_NON_NULL(source, false);
+    PS_ASSERT_PTR_NON_NULL(source->peak, false);
+    PS_ASSERT_PTR_NON_NULL(source->pixels, false);
+    PS_ASSERT_PTR_NON_NULL(source->variance, false);
+    PS_ASSERT_PTR_NON_NULL(source->moments, false);
+    PS_ASSERT_PTR_NON_NULL(source->extpars, false);
+
+    // the peak position is less accurate but less subject to extreme deviations
+    float dX = source->moments->Mx - source->peak->xf;
+    float dY = source->moments->My - source->peak->yf;
+    float dR = hypot(dX, dY);
+    float Xo = (dR < 2.0) ? source->moments->Mx : source->peak->xf;
+    float Yo = (dR < 2.0) ? source->moments->My : source->peak->yf;
+
+    // center of mass in subimage.  Note: the calculation below uses pixel index, so we correct
+    // xCM, yCM from pixel coords to pixel index here.
+    psF32 xCM = Xo - 0.5 - source->pixels->col0; // coord of peak in subimage
+    psF32 yCM = Yo - 0.5 - source->pixels->row0; // coord of peak in subimage
+
+    // Calculate the Petro magnitude (make this block optional?)
+    // XXX set the aperture here
+    float radPetro  = PETROSIAN_RADII*source->extpars->petrosianRadius;
+    float radPetro2 = radPetro*radPetro;
+
+    int nPetroPix = 0;
+    float Sum = 0.0;
+    float Var = 0.0;
+
+    // set vPix to the source pixels (it may have been set to the
+    // smoothed image above)
+    psF32 **vPix = source->pixels->data.F32;
+    psF32 **vWgt = source->variance->data.F32;
+    psImageMaskType **vMsk = (source->maskObj == NULL) ? NULL : source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA;
+
+    for (psS32 row = 0; row < source->pixels->numRows ; row++) {
+
+	psF32 yDiff = row - yCM;
+	if (fabs(yDiff) > radPetro) continue;
+
+	for (psS32 col = 0; col < source->pixels->numCols ; col++) {
+	    // check mask and value for this pixel
+	    if (vMsk && (vMsk[row][col] & maskVal)) continue;
+	    if (isnan(vPix[row][col])) continue;
+
+	    psF32 xDiff = col - xCM;
+	    if (fabs(xDiff) > radPetro) continue;
+
+	    // radPetro is just a function of (xDiff, yDiff)
+	    psF32 r2  = PS_SQR(xDiff) + PS_SQR(yDiff);
+	    if (r2 > radPetro2) continue;
+
+	    float pDiff = vPix[row][col];
+	    psF32 wDiff = vWgt[row][col];
+
+	    Sum += pDiff;
+	    Var += wDiff;
+	    nPetroPix ++;
+	}
+    }
+
+    // return the flux and error to parameters?
+    source->extpars->petrosianFlux    = Sum;
+    source->extpars->petrosianFluxErr = sqrt(Var);
+    source->extpars->petrosianFill = nPetroPix / (M_PI * radPetro2);
+
+    // fprintf (stderr, "petro flux: %f +/- %f\n", Sum, sqrt(Var));
+
+    return true;
+}
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotPetrosianRadialBins.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotPetrosianRadialBins.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotPetrosianRadialBins.c	(revision 37066)
@@ -36,5 +36,5 @@
     pmSourceRadialProfile *profile = source->extpars->petProfile;
 
-    float skyModelErrorSQ = PS_SQR(skynoise);
+    // float skyModelErrorSQ = PS_SQR(skynoise);
 
     int nMax = radiusMax;
@@ -133,16 +133,17 @@
 	if (radius->data.F32[i] > Rmax) {
 	    // calculate the value for the nOut bin
-	    float value, dvalue;
+	    float value; // , dvalue;
 	    if (values->n > 0) {
 		psVectorStats (stats, values, NULL, NULL, 0);
 		value = stats->robustMedian;
-		dvalue = stats->robustStdev;
+		// dvalue = stats->robustStdev;
 	    } else {
 		value = NAN;
-		dvalue = NAN;
+		// dvalue = NAN;
 	    }
 
 	    binSB->data.F32[nOut] = value;
-	    binSBstdev->data.F32[nOut] = sqrt(PS_SQR(dvalue) / values->n + skyModelErrorSQ);
+	    // binSBstdev->data.F32[nOut] = sqrt(PS_SQR(dvalue) / values->n + skyModelErrorSQ);
+	    binSBstdev->data.F32[nOut] = skynoise / sqrt(values->n);
 	    binFill->data.F32[nOut] = values->n / binArea->data.F32[nOut];
 
@@ -185,4 +186,5 @@
 	psFree(values);
 	psFree(stats);
+	source->mode2 |= PM_SOURCE_MODE2_RADBIN_NAN_CENTER;
 	return true;
     }
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotPetrosianStats.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotPetrosianStats.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotPetrosianStats.c	(revision 37066)
@@ -6,4 +6,5 @@
 // generate the Petrosian radius and flux from the mean surface brightness (r_i)
 
+float InterpolateValuesQuadratic (float *Xin, float *Yin, float X);
 float InterpolateValues     (float X0, float Y0, float X1, float Y1, float X);
 float InterpolateValuesErrX (float X0, float Y0, float X1, float Y1, float X, float dX0, float dX1);
@@ -20,4 +21,5 @@
     if (!profile->binSB) {
 	psLogMsg ("psphot", PS_LOG_DETAIL, "no petrosian profile, skipping source %f, %f", source->peak->xf, source->peak->yf);
+	source->mode2 |= PM_SOURCE_MODE2_PETRO_NO_PROFILE;
 	return true;
     }
@@ -53,5 +55,5 @@
     float dFsum2 = 0.0;
 
-    float nSigma = 3.0;
+    float nSigma = 2.0;
     int lowestSignificantRadius = 0;
     float lowestSignificantRatio = 1.0;
@@ -117,7 +119,19 @@
 		petRadius    = InterpolateValues     (1.0, 0.0, petRatio->data.F32[nOut], refRadius->data.F32[nOut], PETROSIAN_RATIO);
 		petRadiusErr = InterpolateValuesErrX (1.0, 0.0, petRatio->data.F32[nOut], refRadius->data.F32[nOut], PETROSIAN_RATIO, 0.0, petRatioErr->data.F32[nOut]);
-	    } else {
-		petRadius    = InterpolateValues     (petRatio->data.F32[nOut-1], refRadius->data.F32[nOut-1], petRatio->data.F32[nOut], refRadius->data.F32[nOut], PETROSIAN_RATIO);
-		petRadiusErr = InterpolateValuesErrX (petRatio->data.F32[nOut-1], refRadius->data.F32[nOut-1], petRatio->data.F32[nOut], refRadius->data.F32[nOut], PETROSIAN_RATIO, petRatioErr->data.F32[nOut-1], petRatioErr->data.F32[nOut]);
+		source->mode2 |= PM_SOURCE_MODE2_PETRO_RATIO_ZEROBIN;
+	    } else {
+	      // petRadius    = InterpolateValues     (petRatio->data.F32[nOut-1], refRadius->data.F32[nOut-1], petRatio->data.F32[nOut], refRadius->data.F32[nOut], PETROSIAN_RATIO);
+	      if (nOut > 1) {
+		petRadius    = InterpolateValuesQuadratic (&petRatio->data.F32[nOut-2], &refRadius->data.F32[nOut-2],   PETROSIAN_RATIO);
+	      } else {
+		petRadius    = InterpolateValuesQuadratic (&petRatio->data.F32[nOut-3], &refRadius->data.F32[nOut-3], PETROSIAN_RATIO);
+	      }
+# if (PS_TRACE_ON)
+	      float petRadiusLinear = InterpolateValues     (petRatio->data.F32[nOut-1], refRadius->data.F32[nOut-1], petRatio->data.F32[nOut], refRadius->data.F32[nOut], PETROSIAN_RATIO);
+	      if (fabs(petRadius - petRadiusLinear) > fabs(refRadius->data.F32[nOut] - refRadius->data.F32[nOut-1])) { 
+		fprintf (stderr, "big difference : %f vs %f\n", petRadius, petRadiusLinear); 
+	      }
+#endif
+	      petRadiusErr = InterpolateValuesErrX (petRatio->data.F32[nOut-1], refRadius->data.F32[nOut-1], petRatio->data.F32[nOut], refRadius->data.F32[nOut], PETROSIAN_RATIO, petRatioErr->data.F32[nOut-1], petRatioErr->data.F32[nOut]);
 	    }
 	    above = false;
@@ -148,4 +162,5 @@
 	    fprintf (stderr, "nan pet radius\n");
 	}
+	source->mode2 |= PM_SOURCE_MODE2_PETRO_INSIG_RATIO;
     }
 
@@ -180,4 +195,5 @@
     bool found50 = false;
     bool found90 = false;
+
     // XXX use bisection to do this faster:
     for (int i = 0; !(found50 && found90) && i < refRadius->n; i++) {
@@ -235,4 +251,23 @@
 }
 
+// Lagrange's form of the interpolating polynomial...
+float InterpolateValuesQuadratic (float *Xin, float *Yin, float X) {
+
+  float dx01 = Xin[0] - Xin[1];
+  float dx02 = Xin[0] - Xin[2];
+  float dx12 = Xin[1] - Xin[2];
+
+  float dx0  = X - Xin[0];
+  float dx1  = X - Xin[1];
+  float dx2  = X - Xin[2];
+
+  float y0 = Yin[0]*dx1*dx2/(dx01*dx02);
+  float y1 = Yin[1]*dx0*dx2/(dx01*dx12); // need - sign
+  float y2 = Yin[2]*dx0*dx1/(dx02*dx12); 
+
+  float Y = y0 - y1 + y2;
+  return Y;
+}
+
 float InterpolateValues (float X0, float Y0, float X1, float Y1, float X) {
     float dydx = (Y1 - Y0) / (X1 - X0);
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotRadialBins.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotRadialBins.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotRadialBins.c	(revision 37066)
@@ -44,12 +44,8 @@
     psVector *radMin = psMetadataLookupPtr (&status, recipe, "RADIAL.ANNULAR.BINS.LOWER");
     psVector *radMax = psMetadataLookupPtr (&status, recipe, "RADIAL.ANNULAR.BINS.UPPER");
-    if (!radMin || !radMin->n) {
-	psError (PSPHOT_ERR_CONFIG, true, "error in definition of annular bins (radMin missing or empty)");
-	return false;
-    }
-    if (!radMax || !radMax->n) {
-	psError (PSPHOT_ERR_CONFIG, true, "error in definition of annular bins (radMax missing or empty)");
-	return false;
-    }
+    psAssert (radMin, "RADIAL.ANNULAR.BINS.LOWER is missing from recipe");
+    psAssert (radMin->n, "RADIAL.ANNULAR.BINS.LOWER is empty in recipe");
+    psAssert (radMax, "RADIAL.ANNULAR.BINS.UPPER is missing from recipe");
+    psAssert (radMax->n, "RADIAL.ANNULAR.BINS.UPPER is empty in recipe");
 
     psVector *binSB      = psVectorAllocEmpty(radMin->n, PS_TYPE_F32); // surface brightness of radial bin
@@ -161,4 +157,5 @@
 	psFree(values);
 	psFree(stats);
+	source->mode2 |= PM_SOURCE_MODE2_RADBIN_NAN_CENTER;
 	return true;
     }
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotRadialProfile.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotRadialProfile.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotRadialProfile.c	(revision 37066)
@@ -1,3 +1,11 @@
 # include "psphotInternal.h"
+
+static int Nskip1 = 0;
+static int Nskip2 = 0;
+static int Nskip3 = 0;
+static int Nskip4 = 0;
+static int Nskip5 = 0;
+
+# define SKIP(VALUE) { VALUE++; return false; }
 
 bool psphotRadialProfile (pmSource *source, psMetadata *recipe, float skynoise, psImageMaskType maskVal) {
@@ -23,5 +31,5 @@
     if (!psphotRadialProfilesByAngles (source, Nsec, Rmax)) {
 	psError (PS_ERR_UNKNOWN, false, "failed to measure radial profile for petrosian");
-	return false;
+	SKIP (Nskip1);
     }
     // allocate: extpars->radFlux->radii,fluxes,theta
@@ -32,5 +40,5 @@
     if (!psphotRadiiFromProfiles (source, fluxMin, fluxMax)) {
 	psError (PS_ERR_UNKNOWN, false, "failed to measure isophotal radii from profiles");
-	return false;
+	SKIP (Nskip2);
     }
     // allocate : extpars->radFlux->isophotalRadii (use profile->radii,fluxes)
@@ -40,5 +48,5 @@
     if (!psphotEllipticalContour (source)) {
 	// psLogMsg ("psphot", 3, "failed to measure elliptical contour");
-	return false;
+	SKIP (Nskip3);
     }
     // use extpars->radFlux->isophotalRadii,theta (result in extpars->axes)
@@ -48,5 +56,5 @@
     if (!psphotEllipticalProfile (source, RAW_RADIUS)) {
 	psError (PS_ERR_UNKNOWN, false, "failed to generate elliptical profile");
-	return false;
+	SKIP (Nskip4);
     }
     // allocate extpars->ellipticalFlux->radiusElliptical,fluxElliptical (use axes to scale raw pixels)
@@ -55,5 +63,5 @@
     if (!psphotRadialBins (recipe, source, Rmax, skynoise)) {
 	psError (PS_ERR_UNKNOWN, false, "failed to generate radial bins");
-	return false;
+	SKIP (Nskip5);
     }
     // allocate extpars->radProfile->binSB, binSBstdv, binSum, binFill, radialBins, area (small lengths)
@@ -62,2 +70,12 @@
     return true;
 }
+
+void psphotRadialProfileShowSkips () {
+# if (PS_TRACE_ON)
+  fprintf (stderr, "radial profile skipped @ 1  : %d\n", Nskip1);
+  fprintf (stderr, "radial profile skipped @ 2  : %d\n", Nskip2);
+  fprintf (stderr, "radial profile skipped @ 3  : %d\n", Nskip3);
+  fprintf (stderr, "radial profile skipped @ 4  : %d\n", Nskip4);
+  fprintf (stderr, "radial profile skipped @ 5  : %d\n", Nskip5);
+#endif
+}
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotRadiusChecks.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotRadiusChecks.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotRadiusChecks.c	(revision 37066)
@@ -60,7 +60,7 @@
     if (radiusFit <= 0) {               // use fixed radius
         if (moments == NULL) {
-            radiusFit = model->modelRadius(model->params, PSF_FIT_NSIGMA*moments->dSky);
+            radiusFit = model->class->modelRadius(model->params, PSF_FIT_NSIGMA*moments->dSky);
         } else {
-            radiusFit = model->modelRadius(model->params, 1.0);
+            radiusFit = model->class->modelRadius(model->params, 1.0);
         }
         model->fitRadius = (RADIUS_TYPE)(radiusFit + PSF_FIT_PADDING);
@@ -95,7 +95,7 @@
     if (radiusFit <= 0) {               // use fixed radius
         if (moments == NULL) {
-            radiusFit = model->modelRadius(model->params, PSF_FIT_NSIGMA*moments->dSky);
+            radiusFit = model->class->modelRadius(model->params, PSF_FIT_NSIGMA*moments->dSky);
         } else {
-            radiusFit = model->modelRadius(model->params, 1.0);
+            radiusFit = model->class->modelRadius(model->params, 1.0);
         }
         model->fitRadius = (RADIUS_TYPE)(radiusFit + PSF_FIT_PADDING);
@@ -171,6 +171,9 @@
 # undef MIN_WINDOW
 
+// XXX EAM : 20130724 : for a test, double the window size parameters
+// # define MIN_WINDOW 10.0
+// # define SCALE1 7.0
 # define MIN_WINDOW 5.0
-# define SCALE1 5.0
+# define SCALE1 3.0
 # define PAD_WINDOW 3.0
 
@@ -291,5 +294,5 @@
     float flux = deep ? EXT_FIT_NSIGMA*EXT_FIT_SKY_SIG : 0.1 * model->params->data.F32[PM_PAR_I0];
 
-    float rawRadius = model->modelRadius (model->params, flux);
+    float rawRadius = model->class->modelRadius (model->params, flux);
     if (isnan(rawRadius)) return false;
 
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotReadout.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotReadout.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotReadout.c	(revision 37066)
@@ -316,4 +316,11 @@
     psphotSourceSize (config, view, filerule, false); // pass 2 (detections->allSources)
 
+    // XXX currently we are doing both the analysis of the size and the assessment of "fit ext"
+    // in source size.  this overloads the bit MODE_EXT_LIMIT to mean "fit ext" not just
+    // "bigger than a PSF"
+
+    // decide which source(s) are to be fitted with the extended source analysis code.
+    psphotChooseAnalysisOptions (config, view, filerule);
+
     psphotExtendedSourceAnalysis (config, view, filerule); // pass 1 (detections->allSources)
     psphotExtendedSourceFits (config, view, filerule); // pass 1 (detections->allSources)
@@ -333,7 +340,14 @@
     // calculate source magnitudes
     if (!psphotMagnitudes(config, view, filerule)) { // pass 1 (detections->allSources)
-      psErrorStackPrint(stderr, "Unable to do magnitudes.");
+	psErrorStackPrint(stderr, "Unable to do magnitudes.");
         psErrorClear();
     }
+
+    // calculate lensing parameters
+    if (!psphotLensing(config, view, filerule)) {
+	psErrorStackPrint(stderr, "Unable to do lensing parameters.");
+        psErrorClear();
+    }
+
     if (!psphotEfficiency(config, view, filerule)) { // pass 1
         psErrorStackPrint(stderr, "Unable to determine detection efficiencies from fake sources");
@@ -346,12 +360,12 @@
     // replace background in residual image
     if (!psphotSkyReplace (config, view, filerule)) { // pass 1
-      psErrorStackPrint(stderr, "Unable to replace sky");
-      psErrorClear();
+	psErrorStackPrint(stderr, "Unable to replace sky");
+	psErrorClear();
     }
 
     // drop the references to the image pixels held by each source
     if (!psphotSourceFreePixels (config, view, filerule)) { // pass 1
-      psErrorStackPrint(stderr, "Unable to free source pixels");
-      psErrorClear();
+	psErrorStackPrint(stderr, "Unable to free source pixels");
+	psErrorClear();
     }
 
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotRoughClass.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotRoughClass.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotRoughClass.c	(revision 37066)
@@ -87,5 +87,5 @@
     if (NX > NY) {
 	NXuse = ScaleForClump;
-	NYuse = (int) (ScaleForClump * (NY / NX) + 0.5);
+	NYuse = (int) (ScaleForClump * (NX / NY) + 0.5);
     } else {
 	NYuse = ScaleForClump;
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotSersicModelClass.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotSersicModelClass.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotSersicModelClass.c	(revision 37066)
@@ -586,5 +586,5 @@
             coord->data.F32[1] = (psF32) (i + source->pixels->row0);
 
-            pcm->modelConvFlux->data.F32[i][j] = pcm->modelConv->modelFunc (NULL, params, coord);
+            pcm->modelConvFlux->data.F32[i][j] = pcm->modelConv->class->modelFunc (NULL, params, coord);
         }
     }
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotSetThreads.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotSetThreads.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotSetThreads.c	(revision 37066)
@@ -47,4 +47,19 @@
     psFree(task);
 
+    task = psThreadTaskAlloc("PSPHOT_KRON_FLUX", 4);
+    task->function = &psphotKronFlux_Threaded;
+    psThreadTaskAdd(task);
+    psFree(task);
+
+    task = psThreadTaskAlloc("PSPHOT_PETRO_FLUX", 4);
+    task->function = &psphotPetroFlux_Threaded;
+    psThreadTaskAdd(task);
+    psFree(task);
+
+    task = psThreadTaskAlloc("PSPHOT_GALAXY_SHAPES", 7);
+    task->function = &psphotGalaxyShape_Threaded;
+    psThreadTaskAdd(task);
+    psFree(task);
+
     task = psThreadTaskAlloc("PSPHOT_BLEND_FIT", 10);
     task->function = &psphotBlendFit_Threaded;
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotSourceFits.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotSourceFits.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotSourceFits.c	(revision 37066)
@@ -19,4 +19,7 @@
 static int NfitIterPCM = 0;
 static int NfitPixPCM = 0;
+
+bool psphotPCMfitCheckSize (pmPCMdata *pcm, pmSource *source, psImageMaskType maskVal, float psfSize);
+bool psphotPCMfitRetry (pmPCMdata *pcm, pmSource *source, pmSourceFitOptions *fitOptions, psImageMaskType maskVal, psImageMaskType markVal, float psfSize);
 
 bool psphotFitInit (int nThreads) {
@@ -559,4 +562,10 @@
 
 # define TIMING 0
+# define EXTRA_VERBOSE 0
+
+bool psphotSersicModelGuessPCM (pmPCMdata *pcm, pmSource *source, psImageMaskType maskVal, float psfSize);
+bool psphotFitSersicShapeAndIndex (pmPCMdata *pcm, pmReadout *readout, pmSource *source, pmSourceFitOptions *fitOptions, psImageMaskType maskVal, psImageMaskType markVal, int psfSize);
+bool psphotFitSersicShapeAndIndexGrid (pmPCMdata *pcm, pmReadout *readout, pmSource *source, pmSourceFitOptions *fitOptions, psImageMaskType maskVal, psImageMaskType markVal, int psfSize);
+bool psphotFitSersicShapeAndIndexGridAuto (pmPCMdata *pcm, pmReadout *readout, pmSource *source, pmSourceFitOptions *fitOptions, psImageMaskType maskVal, psImageMaskType markVal, int psfSize);
 
 pmModel *psphotFitPCM (pmReadout *readout, pmSource *source, pmSourceFitOptions *fitOptions, pmModelType modelType, psImageMaskType maskVal, psImageMaskType markVal, int psfSize) {
@@ -573,12 +582,27 @@
     maskVal |= markVal;
 
-    // allocate the model
+    // allocate the model (this can only fail on a config error)
     pmModel *model = pmModelAlloc(modelType);
-    if (!model) {
-	return NULL;
-    }
-
-    float t1, t2, t4, t5;
+    psAssert (model, "invalid extended model name");
+
+    float t1, t2, t3, t4, t5;
+    t1 = t2 = t3 = t4 = t5 = 0.0;
     if (TIMING) { psTimerStart ("psphotFitPCM"); }
+
+    // if we are ever (in a given psphot implementation) going to fit a parameter, we must set the options here to include
+    // that parameter (otherwise pmPCMupdate will fail to allocate the dmodelFlux image)
+    // thus, if the sersic analysis below uses an index fit, need to use this EXT_AND_SKY mode for init
+
+    options.mode = PM_SOURCE_FIT_EXT;
+    if (modelType == pmModelClassGetType("PS_MODEL_SERSIC")) {
+	options.mode = PM_SOURCE_FIT_EXT_AND_SKY;
+    }
+    if (modelType == pmModelClassGetType("PS_MODEL_DEV")) {
+	options.mode = PM_SOURCE_FIT_SHAPE;
+	options.mode = PM_SOURCE_FIT_EXT_AND_SKY;
+    }
+    if (modelType == pmModelClassGetType("PS_MODEL_EXP")) {
+	options.mode = PM_SOURCE_FIT_EXT_AND_SKY;
+    }
 
     pmPCMdata *pcm = pmPCMinit (source, &options, model, maskVal, psfSize);
@@ -594,7 +618,18 @@
     if (modelType == pmModelClassGetType("PS_MODEL_SERSIC")) {
 	// use the source moments, etc to guess basic model parameters
-	if (!psphotSersicModelClassGuessPCM (pcm, source)) {
+	if (!psphotSersicModelGuessPCM (pcm, source, maskVal, psfSize)) {
 	    psFree (pcm);
-	    model->flags |= PM_MODEL_STATUS_BADARGS;
+	    model->flags |= PM_MODEL_SERSIC_PCM_FAIL_GUESS;
+	    return model;
+	}
+	if (TIMING) { t2 = psTimerMark ("psphotFitPCM"); }
+
+	// psphotFitSersicShapeAndIndex (pcm, readout, source, fitOptions, maskVal, markVal, psfSize);
+	options.mode = PM_SOURCE_FIT_NO_INDEX;
+	if (!psphotFitSersicShapeAndIndexGridAuto (pcm, readout, source, &options, maskVal, markVal, psfSize)) {
+	    psFree (pcm);
+	    model->flags |= PM_MODEL_SERSIC_PCM_FAIL_GRID;
+	    psError(PS_ERR_UNKNOWN, true, "Failed to find a index & shape");
+	    psErrorClear (); // clear the polynomial error
 	    return model;
 	}
@@ -603,19 +638,10 @@
 	if (!pmSourceModelGuessPCM (pcm, source, maskVal, markVal)) {
 	    psFree (pcm);
-	    model->flags |= PM_MODEL_STATUS_BADARGS;
+	    model->flags |= PM_MODEL_PCM_FAIL_GUESS;
 	    return model;
 	}
     }
 
-    if (TIMING) { t2 = psTimerMark ("psphotFitPCM"); }
-
-    if (modelType == pmModelClassGetType("PS_MODEL_SERSIC")) {
-	options.mode = PM_SOURCE_FIT_NO_INDEX;
-    } else {
-	options.mode = PM_SOURCE_FIT_EXT;
-    }
-    // update the pcm elements if we have changed the circumstance (options.mode or source->pixels)
-    pmPCMupdate(pcm, source, &options, model);
-    if (TIMING) { t4 = psTimerMark ("psphotFitPCM"); }
+    if (TIMING) { t3 = psTimerMark ("psphotFitPCM"); }
 
     // psTraceSetLevel("psLib.math.psMinimizeLMChi2", 5);
@@ -623,12 +649,25 @@
     NfitIterPCM += pcm->modelConv->nIter;
     NfitPixPCM += pcm->modelConv->nDOF;
+    if (TIMING) { t4 = psTimerMark ("psphotFitPCM"); }
+
+    // XXX we might make this more efficient by setting NITER to be fairly small.  if we hit the iteration
+    // limit, then we could do a small grid search on the size and try again from the best fit 
+
+    if (options.isInteractive) psphotPCMfitCheckSize (pcm, source, maskVal, psfSize);
+    // if (pcm->modelConv->nIter == fitOptions->nIter) {
+    // 	psphotPCMfitRetry (pcm, source, &options, maskVal, markVal, psfSize);
+    // }
     if (TIMING) { t5 = psTimerMark ("psphotFitPCM"); }
 
     if (TIMING) {
 	int nPixBig = source->pixels->numCols * source->pixels->numRows;
-    	fprintf (stderr, "psphotFitPCM : nIter: %2d, radius: %6.1f, npix: %5d of %5d, t1: %6.4f, t2: %6.4f, t4: %6.4f, t5: %6.4f\n", model->nIter, model->fitRadius, model->nPix, nPixBig, t1, t2, t4, t5);
-    }
-
-    // psTraceSetLevel("psLib.math.psMinimizeLMChi2", 0);
+    	fprintf (stderr, "psphotFitPCM : nIter: %2d, radius: %6.1f, npix: %5d of %5d, t1: %6.4f, t2: %6.4f, t3: %6.4f, t4: %6.4f, t5: %6.4f\n", model->nIter, model->fitRadius, model->nPix, nPixBig, t1, t2, t3, t4, t5);
+    }
+    if (EXTRA_VERBOSE && !TIMING) {
+	int nPixBig = source->pixels->numCols * source->pixels->numRows;
+	float *PAR = model->params->data.F32;
+	fprintf (stderr, "source %d : %f - %f %f - %f %f %f - %f | nIter: %2d, radius: %6.1f, npix: %5d of %5d, chisq %f\n", source->id, PAR[7], PAR[2], PAR[3], PAR[4], PAR[5], PAR[6], PAR[1], model->nIter, model->fitRadius, model->nPix, nPixBig, model->chisqNorm);
+    }
+
     psFree (pcm);
 
@@ -661,5 +700,5 @@
 	model->params->data.F32[PM_PAR_7] = 0.5/indexGuess[i];
 
-	if (!model->modelGuess(model, source, maskVal, markVal)) {
+	if (!model->class->modelGuess(model, source, maskVal, markVal)) {
 	    model->flags |= PM_MODEL_STATUS_BADARGS;
 	    return false;
@@ -684,5 +723,5 @@
     model->flags = PM_MODEL_STATUS_NONE; // do not attempt to handle failures here, let the next iteration deal with it
     model->params->data.F32[PM_PAR_7] = 0.5/indexGuess[iMin];
-    model->modelGuess(model, source, maskVal, markVal);
+    model->class->modelGuess(model, source, maskVal, markVal);
 
     return true;
@@ -713,5 +752,5 @@
 	model->params->data.F32[PM_PAR_7] = indexGuess[i];
 	
-	if (!model->modelGuess(model, source, maskVal, markVal)) {
+	if (!model->class->modelGuess(model, source, maskVal, markVal)) {
 	    model->flags |= PM_MODEL_STATUS_BADARGS;
 	    return false;
@@ -748,2 +787,628 @@
     return true;
 }
+
+// 0.5 / n for (1.0, 1.25, 1.66, 2.0, 3.33, 4.0)
+// float indexGuessInv[] = {0.5, 0.4, 0.3, 0.25, 0.20, 0.15, 0.125};
+
+// 0.5 / n for (0.5, 1.0, 1.5, 2.0, 3.0, 4.0, 5.0, 6.0)
+float indexGuessInv[] = {1.00, 0.50, 0.333, 0.25, 0.166, 0.125, 0.10, 0.0833};
+float indexGuessR1q[] = {1.06, 1.19, 1.335, 1.48, 1.840, 2.290, 2.84, 3.5300};
+# define N_INDEX_GUESS_INV 8
+
+// we are going to guess in fractions about the R1-based guess
+float reffGuess[] = {0.8, 0.9, 1.0, 1.12, 1.25};
+# define N_REFF_GUESS 5
+
+// A sersic model is very sensitive to the index.  attempt to find the index first by grid search in just the index
+// for a sersic model, attempt to fit just the index and normalization with a modest number of iterations
+bool psphotSersicModelGuessPCM (pmPCMdata *pcm, pmSource *source, psImageMaskType maskVal, float psfSize) {
+
+    // we get a reasonable guess from:
+    // * Reff = Kron R1 / Q(index) -- Q comes from Graham & Driver 
+    // * Rmajor / Rminor & Theta from moments
+    // * Io from total Kron flux
+
+    // the guesses are used to fill in PAR:
+    psF32 *PAR = pcm->modelConv->params->data.F32;
+
+    // convert the moments to Major,Minor,Theta
+    psEllipseMoments moments;
+
+    if (!isfinite(source->moments->Mrf)) return false;
+    if (!isfinite(source->moments->Mxx)) return false;
+    if (!isfinite(source->moments->Mxy)) return false;
+    if (!isfinite(source->moments->Myy)) return false;
+
+    moments.x2 = source->moments->Mxx;
+    moments.y2 = source->moments->Myy;
+    moments.xy = source->moments->Mxy;
+    
+    // limit axis ratio < 20.0
+    psEllipseAxes momentAxes = psEllipseMomentsToAxes (moments, 20.0);
+
+    // set the model position
+    if (!pmModelSetPosition(&PAR[PM_PAR_XPOS], &PAR[PM_PAR_YPOS], source)) {
+      return false;
+    }
+
+    // sky is zero (no longer fitted, but not yet deprecated)
+    PAR[PM_PAR_SKY]  = 0.0;
+
+    // for the index loop, use Io = 1.0, use fitted values to determine Io
+    PAR[PM_PAR_I0] = 1.0;
+
+    float xMin = NAN;
+    float iMin = NAN;
+    float sMin = NAN;
+    float rMin = NAN;
+
+    // loop over index and Reff, keeping the ARatio and Theta constant?
+    // loop over index guesses and find the best fit
+    for (int j = 0; j < N_REFF_GUESS; j++) {
+	for (int i = 0; i < N_INDEX_GUESS_INV; i++) {
+	    PAR[PM_PAR_7] = indexGuessInv[i];
+
+	    psEllipseAxes guessAxes;
+	    guessAxes.major = reffGuess[j] * source->moments->Mrf / indexGuessR1q[i];
+	    guessAxes.minor = guessAxes.major * (momentAxes.minor / momentAxes.major);
+	    guessAxes.theta = momentAxes.theta;
+
+	    if (!isfinite(guessAxes.major)) return false;
+	    if (!isfinite(guessAxes.minor)) return false;
+	    if (!isfinite(guessAxes.theta)) return false;
+
+	    // convert the major,minor,theta to shape parameters for an Reff-like model
+	    pmModelAxesToParams (&PAR[PM_PAR_SXX], &PAR[PM_PAR_SXY], &PAR[PM_PAR_SYY], guessAxes, true);
+
+	    // generated the modelFlux
+	    // XXX note that this does not add sky to model
+	    pmPCMMakeModel (source, pcm->modelConv, pcm->nsigma, maskVal, psfSize);
+	
+	    float YY = 0.0;
+	    float YM = 0.0;
+	    float MM = 0.0;
+	    bool usePoisson = false;
+
+	    for (int iy = 0; iy < source->pixels->numRows; iy++) {
+		for (int ix = 0; ix < source->pixels->numCols; ix++) {
+		    // skip masked points
+		    if (source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix]) {
+			continue;
+		    }
+		    // skip zero-variance points
+		    if (source->variance->data.F32[iy][ix] == 0) {
+			continue;
+		    }
+		    // skip nan value points
+		    if (!isfinite(source->pixels->data.F32[iy][ix])) {
+			continue;
+		    }
+
+		    float fy = source->pixels->data.F32[iy][ix];
+		    float fm = source->modelFlux->data.F32[iy][ix];
+		    float wt = (usePoisson) ? 1.0 / source->variance->data.F32[iy][ix] : 1.0;
+
+		    YY += PS_SQR(fy) * wt;
+		    YM += fm * fy * wt;
+		    MM += PS_SQR(fm) * wt;
+		}
+	    }
+
+	    float Io = YM / MM;
+	    float Chisq = YY - 2 * Io * YM + Io * Io * MM;
+	    if (isnan(xMin) || (Chisq < xMin)) {
+		xMin = Chisq;
+		iMin = Io;
+		sMin = indexGuessInv[i];
+		rMin = reffGuess[j] / indexGuessR1q[i];
+	    }
+            if (EXTRA_VERBOSE) {
+                fprintf (stderr, "%d | %f %f %f %f | %f %f %f %f", i, indexGuessInv[i], reffGuess[j], Io, Chisq, sMin, rMin, iMin, xMin);
+                fprintf (stderr, "\n");
+            }
+	}
+    }
+
+    {
+	psEllipseAxes guessAxes;
+	guessAxes.major = rMin * source->moments->Mrf;
+	guessAxes.minor = guessAxes.major * (momentAxes.minor / momentAxes.major);
+	guessAxes.theta = momentAxes.theta;
+
+	if (!isfinite(guessAxes.major)) return false;
+	if (!isfinite(guessAxes.minor)) return false;
+	if (!isfinite(guessAxes.theta)) return false;
+
+	// convert the major,minor,theta to shape parameters for an Reff-like model
+	pmModelAxesToParams (&PAR[PM_PAR_SXX], &PAR[PM_PAR_SXY], &PAR[PM_PAR_SYY], guessAxes, true);
+    }
+
+    PAR[PM_PAR_I0] = iMin;
+    PAR[PM_PAR_7] = sMin;
+
+    return true;
+}
+
+// we have a set of guess parameters, do a small number of iterations fitting only SHAPE then only INDEX 
+bool psphotFitSersicShapeAndIndex (pmPCMdata *pcm, pmReadout *readout, pmSource *source, pmSourceFitOptions *fitOptions, psImageMaskType maskVal, psImageMaskType markVal, int psfSize) {
+
+    pmModel *model = pcm->modelConv;
+
+    assert (model->type == pmModelClassGetType("PS_MODEL_SERSIC"));
+
+    pmSourceFitOptions options = *fitOptions;
+    
+    for (int i = 0; i < 3; i++) {
+      // fit EXT (not PSF) model (set/unset the pixel mask)
+      options.mode = PM_SOURCE_FIT_SHAPE;
+      options.nIter = 2;
+
+      // update the pcm elements if we have changed the circumstance (here, options.mode)
+      pmPCMupdate(pcm, source, &options, model);
+      
+      pmSourceFitPCM (pcm, source, &options, maskVal, markVal, psfSize);
+      if (EXTRA_VERBOSE) {
+	float *PAR = model->params->data.F32;
+	fprintf (stderr, "%d >>> %d %f : %f - %f %f - %f %f %f - %f\n", source->id, model->nIter, model->chisqNorm, PAR[7], PAR[2], PAR[3], PAR[4], PAR[5], PAR[6], PAR[1]);
+      }
+      
+      // fit EXT (not PSF) model (set/unset the pixel mask)
+      options.mode = PM_SOURCE_FIT_INDEX;
+      // options.mode = PM_SOURCE_FIT_EXT_AND_SKY;
+      options.nIter = 30;
+      
+      // update the pcm elements if we have changed the circumstance (here, options.mode)
+      pmPCMupdate(pcm, source, &options, model);
+      
+      pmSourceFitPCM (pcm, source, &options, maskVal, markVal, psfSize);
+      if (EXTRA_VERBOSE) {
+	float *PAR = model->params->data.F32;
+	fprintf (stderr, "%d >>> %d %f : %f - %f %f - %f %f %f - %f\n", source->id, model->nIter, model->chisqNorm, PAR[7], PAR[2], PAR[3], PAR[4], PAR[5], PAR[6], PAR[1]);
+      }
+    }
+
+    // update the pcm elements if we have changed the circumstance (here, options.mode)
+    pmPCMupdate(pcm, source, fitOptions, model);
+
+    return true;
+}
+
+// we have a set of guess parameters, do a small number of iterations fitting only SHAPE then only INDEX 
+bool psphotFitSersicShapeAndIndexGridAuto (pmPCMdata *pcm, pmReadout *readout, pmSource *source, pmSourceFitOptions *fitOptions, psImageMaskType maskVal, psImageMaskType markVal, int psfSize) {
+
+    pmModel *model = pcm->modelConv;
+
+    assert (model->type == pmModelClassGetType("PS_MODEL_SERSIC"));
+
+    pmSourceFitOptions options = *fitOptions;
+    
+    psF32 *PAR = pcm->modelConv->params->data.F32;
+
+    options.mode = PM_SOURCE_FIT_SHAPE;
+    options.nIter = 7;
+    
+    // update the pcm elements if we have changed the circumstance (here, options.mode)
+    pmPCMupdate(pcm, source, &options, model);
+    
+    // we have been provided a guess at the index (P[7]) from the list of indexGuessInv
+
+    // find the matching indexGuessInv
+    int nStart = -1;
+    for (int i = 0; i < N_INDEX_GUESS_INV; i++) {
+	if (fabs(PAR[PM_PAR_7] - indexGuessInv[i]) < 0.01) {
+	    nStart = i;
+	    break;
+	}
+    }
+    if (nStart == -1) {
+	fprintf (stderr, "WARNING: could not find start guess %f\n", PAR[PM_PAR_7]);
+	return false;
+    }
+
+    psVector *chi2 = psVectorAllocEmpty (16, PS_TYPE_F32);
+    psVector *Sidx = psVectorAllocEmpty (16, PS_TYPE_F32);
+
+    float Sm = NAN, Sp = NAN, So = NAN;
+    if (nStart == 0) {
+	Sm = indexGuessInv[nStart];
+	So = 0.5*(indexGuessInv[nStart + 1] + indexGuessInv[nStart]);
+	Sp = indexGuessInv[nStart + 1];
+    } else if (nStart == N_INDEX_GUESS_INV - 1) {
+	Sp = indexGuessInv[nStart];
+	So = 0.5*(indexGuessInv[nStart - 1] + indexGuessInv[nStart]);
+	Sm = indexGuessInv[nStart - 1];
+    } else {
+	Sm = 0.5*(indexGuessInv[nStart - 1] + indexGuessInv[nStart]);
+	So = indexGuessInv[nStart];
+	Sp = 0.5*(indexGuessInv[nStart + 1] + indexGuessInv[nStart]);
+    }
+    
+    PAR[PM_PAR_7] = Sm;
+    pmSourceFitPCM (pcm, source, &options, maskVal, markVal, psfSize);
+    if (EXTRA_VERBOSE) fprintf (stderr, "%d >>> %d %f : %f - %f %f - %f %f %f - %f\n", source->id, model->nIter, model->chisqNorm, PAR[7], PAR[2], PAR[3], PAR[4], PAR[5], PAR[6], PAR[1]);
+    psVectorAppend (Sidx, 100*PAR[PM_PAR_7]);
+    psVectorAppend (chi2, model->chisqNorm);
+
+    PAR[PM_PAR_7] = So;
+    pmSourceFitPCM (pcm, source, &options, maskVal, markVal, psfSize);
+    if (EXTRA_VERBOSE) fprintf (stderr, "%d >>> %d %f : %f - %f %f - %f %f %f - %f\n", source->id, model->nIter, model->chisqNorm, PAR[7], PAR[2], PAR[3], PAR[4], PAR[5], PAR[6], PAR[1]);
+    psVectorAppend (Sidx, 100*PAR[PM_PAR_7]);
+    psVectorAppend (chi2, model->chisqNorm);
+
+    PAR[PM_PAR_7] = Sp;
+    pmSourceFitPCM (pcm, source, &options, maskVal, markVal, psfSize);
+    if (EXTRA_VERBOSE) fprintf (stderr, "%d >>> %d %f : %f - %f %f - %f %f %f - %f\n", source->id, model->nIter, model->chisqNorm, PAR[7], PAR[2], PAR[3], PAR[4], PAR[5], PAR[6], PAR[1]);
+    psVectorAppend (Sidx, 100*PAR[PM_PAR_7]);
+    psVectorAppend (chi2, model->chisqNorm);
+
+    psPolynomial1D *poly = psPolynomial1DAlloc (PS_POLYNOMIAL_ORD, 2);
+    if (!psVectorFitPolynomial1D (poly, NULL, 0, chi2, NULL, Sidx)) {
+        psError(PS_ERR_UNKNOWN, true, "Failed to find a good chisq parabola");
+	psFree (chi2);
+	psFree (Sidx);
+	psFree (poly);
+	return false;
+    }
+
+    // where is the minimum of this polynomial fit?
+    float Smin = -0.5 * poly->coeff[1] / poly->coeff[2] / 100.0;
+
+    // constrain Smin to be in a valid range: allow the fitted range to go a bit beyond the 3 trial points, but no further
+    float Smx = Sm - 0.25*(So - Sm);
+    float Spx = Sp + 0.25*(Sp - So);
+    Smin = PS_MAX(PS_MIN(Smin, Smx), Spx);
+    PAR[PM_PAR_7] = Smin;
+
+    // XXX I could set the error on PAR_7 here if I knew how to roughly convert these chisq values to true chisq values
+
+    // return to the original fitting mode (fitOptions)
+    pmPCMupdate(pcm, source, fitOptions, model);
+
+    psFree (chi2);
+    psFree (Sidx);
+    psFree (poly);
+
+    return true;
+}
+
+ 
+// we have a set of guess parameters, do a small number of iterations fitting only SHAPE then only INDEX 
+bool psphotFitSersicShapeAndIndexGridAutoScaled (pmPCMdata *pcm, pmReadout *readout, pmSource *source, pmSourceFitOptions *fitOptions, psImageMaskType maskVal, psImageMaskType markVal, int psfSize) {
+
+    pmModel *model = pcm->modelConv;
+
+    assert (model->type == pmModelClassGetType("PS_MODEL_SERSIC"));
+
+    pmSourceFitOptions options = *fitOptions;
+    
+    psF32 *PAR = pcm->modelConv->params->data.F32;
+
+    options.mode = PM_SOURCE_FIT_SHAPE;
+    options.nIter = 5;
+    
+    // update the pcm elements if we have changed the circumstance (here, options.mode)
+    pmPCMupdate(pcm, source, &options, model);
+    
+    float parStart[8];
+    for (int i = 0; i < 8; i++) parStart[i] = PAR[i];
+
+    // we start with a guess at the index (P[7])
+
+    // get chisq for P[7], P[7]*1.1, P[7]*1.25 (or *0.75 depending on the result of 1.1)
+
+    psVector *chi2 = psVectorAllocEmpty (16, PS_TYPE_F32);
+    psVector *Sidx = psVectorAllocEmpty (16, PS_TYPE_F32);
+
+    PAR[PM_PAR_7] = parStart[7];
+    pmSourceFitPCM (pcm, source, &options, maskVal, markVal, psfSize);
+      if (EXTRA_VERBOSE) fprintf (stderr, "%d >>> %d %f : %f - %f %f - %f %f %f - %f\n", source->id, model->nIter, model->chisqNorm, PAR[7], PAR[2], PAR[3], PAR[4], PAR[5], PAR[6], PAR[1]);
+    psVectorAppend (Sidx, 100*PAR[PM_PAR_7]);
+    psVectorAppend (chi2, model->chisqNorm);
+
+    float fI = 1.1;
+    PAR[PM_PAR_7] = parStart[7]*fI;
+    pmSourceFitPCM (pcm, source, &options, maskVal, markVal, psfSize);
+      if (EXTRA_VERBOSE) fprintf (stderr, "%d >>> %d %f : %f - %f %f - %f %f %f - %f\n", source->id, model->nIter, model->chisqNorm, PAR[7], PAR[2], PAR[3], PAR[4], PAR[5], PAR[6], PAR[1]);
+    psVectorAppend (Sidx, 100*PAR[PM_PAR_7]);
+    psVectorAppend (chi2, model->chisqNorm);
+
+    if (chi2->data.F32[1] < chi2->data.F32[0]) {
+      fI = 1.3;
+    } else {
+      fI = 1.0 / 1.3;
+    }
+    
+    PAR[PM_PAR_7] = parStart[7]*fI;
+    pmSourceFitPCM (pcm, source, &options, maskVal, markVal, psfSize);
+      if (EXTRA_VERBOSE) fprintf (stderr, "%d >>> %d %f : %f - %f %f - %f %f %f - %f\n", source->id, model->nIter, model->chisqNorm, PAR[7], PAR[2], PAR[3], PAR[4], PAR[5], PAR[6], PAR[1]);
+    psVectorAppend (Sidx, 100*PAR[PM_PAR_7]);
+    psVectorAppend (chi2, model->chisqNorm);
+
+    // can we fit the 3 pts with a parabola?
+    int nTry = 0;
+    psPolynomial1D *poly = psPolynomial1DAlloc (PS_POLYNOMIAL_ORD, 2);
+    while (!psVectorFitPolynomial1D (poly, NULL, 0, chi2, NULL, Sidx)) {
+      psErrorClear (); // clear the polynomial error
+      if (nTry > 4) {
+        psError(PS_ERR_UNKNOWN, true, "Failed to find a good chisq parabola");
+	psFree (chi2);
+	psFree (Sidx);
+	psFree (poly);
+	return false;
+      }
+      fI = (fI < 1.0) ? fI / 1.3 : fI * 1.3;
+      PAR[PM_PAR_7] = parStart[7]*fI;
+      pmSourceFitPCM (pcm, source, &options, maskVal, markVal, psfSize);
+      if (EXTRA_VERBOSE) fprintf (stderr, "%d >>> %d %f : %f - %f %f - %f %f %f - %f\n", source->id, model->nIter, model->chisqNorm, PAR[7], PAR[2], PAR[3], PAR[4], PAR[5], PAR[6], PAR[1]);
+      psVectorAppend (Sidx, 100*PAR[PM_PAR_7]);
+      psVectorAppend (chi2, model->chisqNorm);
+      nTry ++;
+    }
+
+    // where is the minimum of this polynomial fit?
+    float Smin = -0.5 * poly->coeff[1] / poly->coeff[2] / 100.0;
+
+    // constrain Smin to be in a valid range (1.0 - 0.1, corresponding to 0.5 (Gauss) to 5.0 (slightly peakier than Dev)
+    Smin = PS_MAX(PS_MIN(Smin, 1.0), 0.1);
+    PAR[PM_PAR_7] = Smin;
+
+    // pmSourceFitPCM (pcm, source, &options, maskVal, markVal, psfSize);
+    // if (EXTRA_VERBOSE) fprintf (stderr, "%d >>> %d %f : %f - %f %f - %f %f %f - %f\n", source->id, model->nIter, model->chisqNorm, PAR[7], PAR[2], PAR[3], PAR[4], PAR[5], PAR[6], PAR[1]);
+    
+    //// for (int i = 0; i < 8; i++) PAR[i] = parStart[i];
+    //// 
+    //// for (float fI = 0.0; fI < 0.15; fI += 0.01) {
+    ////   PAR[PM_PAR_7] = parStart[7] - fI;
+    //// 
+    ////   // fit EXT (not PSF) model (set/unset the pixel mask)
+    ////   
+    ////   pmSourceFitPCM (pcm, source, &options, maskVal, markVal, psfSize);
+    ////   if (TIMING) {
+    //// 	float *PAR = model->params->data.F32;
+    //// 	fprintf (stderr, "%d %f : %f - %f %f %f - %f\n", model->nIter, model->chisqNorm, PAR[7], PAR[4], PAR[5], PAR[6], PAR[1]);
+    ////   }
+    //// }
+
+    // return to the original fitting mode (fitOptions)
+    pmPCMupdate(pcm, source, fitOptions, model);
+
+    psFree (chi2);
+    psFree (Sidx);
+    psFree (poly);
+
+    return true;
+}
+
+ 
+// we have a set of guess parameters, do a small number of iterations fitting only SHAPE then only INDEX 
+bool psphotFitSersicShapeAndIndexGrid (pmPCMdata *pcm, pmReadout *readout, pmSource *source, pmSourceFitOptions *fitOptions, psImageMaskType maskVal, psImageMaskType markVal, int psfSize) {
+
+    pmModel *model = pcm->modelConv;
+
+    assert (model->type == pmModelClassGetType("PS_MODEL_SERSIC"));
+
+    pmSourceFitOptions options = *fitOptions;
+    
+    psF32 *PAR = pcm->modelConv->params->data.F32;
+
+    options.mode = PM_SOURCE_FIT_SHAPE;
+    options.nIter = 10;
+    
+    // update the pcm elements if we have changed the circumstance (here, options.mode)
+    pmPCMupdate(pcm, source, &options, model);
+    
+    psVector *chi2 = psVectorAllocEmpty (16, PS_TYPE_F32);
+    psVector *Sidx = psVectorAllocEmpty (16, PS_TYPE_F32);
+
+    float par7[] = {0.100, 0.125, 0.150, 0.175, 0.200, 0.225, 0.250};
+    for (int i = 0; i < 7; i++) {
+      PAR[PM_PAR_7] = par7[i];
+      pmSourceFitPCM (pcm, source, &options, maskVal, markVal, psfSize);
+      if (EXTRA_VERBOSE) fprintf (stderr, "%d >>> %d %f : %f - %f %f - %f %f %f - %f\n", source->id, model->nIter, model->chisqNorm, PAR[7], PAR[2], PAR[3], PAR[4], PAR[5], PAR[6], PAR[1]);
+      psVectorAppend (Sidx, PAR[PM_PAR_7]);
+      psVectorAppend (chi2, model->chisqNorm);
+    }
+
+    psPolynomial1D *poly = psPolynomial1DAlloc (PS_POLYNOMIAL_ORD, 2);
+    if (!psVectorFitPolynomial1D (poly, NULL, 0, chi2, NULL, Sidx)) {
+      psError(PS_ERR_UNKNOWN, true, "Failed to find a good chisq parabola");
+      psFree (chi2);
+      psFree (Sidx);
+      psFree (poly);
+      return false;
+    }
+
+    // where is the minimum of this polynomial fit?
+    fprintf (stderr, "fit1d: %f + %f x + %f x^2\n", poly->coeff[0], poly->coeff[1], poly->coeff[2]);
+    float Smin = -0.5 * poly->coeff[1] / poly->coeff[2];
+
+    // constrain Smin to be in a valid range (1.0 - 0.1, corresponding to 0.5 (Gauss) to 5.0 (slightly peakier than Dev)
+    Smin = PS_MAX(PS_MIN(Smin, 1.0), 0.1);
+    PAR[PM_PAR_7] = Smin;
+    pmSourceFitPCM (pcm, source, &options, maskVal, markVal, psfSize);
+    if (EXTRA_VERBOSE) fprintf (stderr, "%d >>> %d %f : %f - %f %f - %f %f %f - %f\n", source->id, model->nIter, model->chisqNorm, PAR[7], PAR[2], PAR[3], PAR[4], PAR[5], PAR[6], PAR[1]);
+    
+    //// for (int i = 0; i < 8; i++) PAR[i] = parStart[i];
+    //// 
+    //// for (float fI = 0.0; fI < 0.15; fI += 0.01) {
+    ////   PAR[PM_PAR_7] = parStart[7] - fI;
+    //// 
+    ////   // fit EXT (not PSF) model (set/unset the pixel mask)
+    ////   
+    ////   pmSourceFitPCM (pcm, source, &options, maskVal, markVal, psfSize);
+    ////   if (TIMING) {
+    //// 	float *PAR = model->params->data.F32;
+    //// 	fprintf (stderr, "%d %f : %f - %f %f %f - %f\n", model->nIter, model->chisqNorm, PAR[7], PAR[4], PAR[5], PAR[6], PAR[1]);
+    ////   }
+    //// }
+
+    // return to the original fitting mode (fitOptions)
+    pmPCMupdate(pcm, source, fitOptions, model);
+
+    psFree (chi2);
+    psFree (Sidx);
+    psFree (poly);
+
+    return true;
+}
+
+// # define N_REFF_CHECK 11
+// float drefCheck[] = {-0.02, -0.04, -0.06, 0.0, 0.85, 0.90, 0.95, 1.00, 1.05, 1.10, 1.15, 1.20, 1.25};
+
+// we have an initial fit, check to see if the current size is besst
+bool psphotPCMfitCheckSize (pmPCMdata *pcm, pmSource *source, psImageMaskType maskVal, float psfSize) {
+
+    // PAR is already at my current best guess
+    psF32 *PAR = pcm->modelConv->params->data.F32;
+
+    // store best guess as a shape
+    psEllipseAxes centerAxes;
+    pmModelParamsToAxes (&centerAxes, PAR[PM_PAR_SXX], PAR[PM_PAR_SXY], PAR[PM_PAR_SYY], true);
+
+    float xMin = NAN;
+    float iMin = NAN;
+    float rMin = NAN;
+
+    // loop over Reff, keeping the ARatio and Theta constant
+    for (int j = -4; j <= 4; j++) {
+
+	float dref = j * 0.01;
+
+	psEllipseAxes guessAxes;
+	guessAxes.major = centerAxes.major + dref;
+	guessAxes.minor = guessAxes.major * centerAxes.minor / centerAxes.major;
+	guessAxes.theta = centerAxes.theta;
+
+	if (!isfinite(guessAxes.major)) return false;
+	if (!isfinite(guessAxes.minor)) return false;
+	if (!isfinite(guessAxes.theta)) return false;
+
+	// convert the major,minor,theta to shape parameters for an Reff-like model
+	pmModelAxesToParams (&PAR[PM_PAR_SXX], &PAR[PM_PAR_SXY], &PAR[PM_PAR_SYY], guessAxes, true);
+
+	// generated the modelFlux
+	    // XXX note that this does not add sky to model
+	pmPCMMakeModel (source, pcm->modelConv, pcm->nsigma, maskVal, psfSize);
+	
+	float YY = 0.0;
+	float YM = 0.0;
+	float MM = 0.0;
+	bool usePoisson = false;
+
+	for (int iy = 0; iy < source->pixels->numRows; iy++) {
+	    for (int ix = 0; ix < source->pixels->numCols; ix++) {
+		// skip masked points
+		if (source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix]) {
+		    continue;
+		}
+		// skip zero-variance points
+		if (source->variance->data.F32[iy][ix] == 0) {
+		    continue;
+		}
+		// skip nan value points
+		if (!isfinite(source->pixels->data.F32[iy][ix])) {
+		    continue;
+		}
+
+		float fy = source->pixels->data.F32[iy][ix];
+		float fm = source->modelFlux->data.F32[iy][ix];
+		float wt = (usePoisson) ? 1.0 / source->variance->data.F32[iy][ix] : 1.0;
+
+		YY += PS_SQR(fy) * wt;
+		YM += fm * fy * wt;
+		MM += PS_SQR(fm) * wt;
+	    }
+	}
+
+	float Io = YM / MM;
+	float Chisq = YY - 2 * Io * YM + Io * Io * MM;
+	if (isnan(xMin) || (Chisq < xMin)) {
+	    xMin = Chisq;
+	    iMin = Io;
+	    rMin = dref;
+	}
+	// fprintf (stderr, "%d | %f %f %f | %f %f %f\n", j, dref, Io, Chisq, rMin, iMin, xMin);
+    }
+
+    psEllipseAxes guessAxes;
+    guessAxes.major = centerAxes.major + rMin;
+    guessAxes.minor = guessAxes.major * centerAxes.minor / centerAxes.major;
+    guessAxes.theta = centerAxes.theta;
+
+    if (!isfinite(guessAxes.major)) return false;
+    if (!isfinite(guessAxes.minor)) return false;
+    if (!isfinite(guessAxes.theta)) return false;
+
+    // convert the major,minor,theta to shape parameters for an Reff-like model
+    pmModelAxesToParams (&PAR[PM_PAR_SXX], &PAR[PM_PAR_SXY], &PAR[PM_PAR_SYY], guessAxes, true);
+    PAR[PM_PAR_I0] = iMin;
+
+    return true;
+}
+
+// we have an initial fit, check to see if the current size is besst
+bool psphotPCMfitRetry (pmPCMdata *pcm, pmSource *source, pmSourceFitOptions *fitOptions, psImageMaskType maskVal, psImageMaskType markVal, float psfSize) {
+
+    // PAR is already at my current best guess
+    psF32 *PAR = pcm->modelConv->params->data.F32;
+
+    // store best guess as a shape
+    psEllipseAxes centerAxes;
+    pmModelParamsToAxes (&centerAxes, PAR[PM_PAR_SXX], PAR[PM_PAR_SXY], PAR[PM_PAR_SYY], true);
+
+    // retry with axes smaller by 1 pixel
+    psEllipseAxes guessAxes;
+    guessAxes.major = centerAxes.major - 0.08;
+    guessAxes.minor = guessAxes.major * centerAxes.minor / centerAxes.major;
+    guessAxes.theta = centerAxes.theta;
+
+    if (!isfinite(guessAxes.major)) return false;
+    if (!isfinite(guessAxes.minor)) return false;
+    if (!isfinite(guessAxes.theta)) return false;
+
+    // convert the major,minor,theta to shape parameters for an Reff-like model
+    pmModelAxesToParams (&PAR[PM_PAR_SXX], &PAR[PM_PAR_SXY], &PAR[PM_PAR_SYY], guessAxes, true);
+
+    // generated the modelFlux
+	    // XXX note that this does not add sky to model
+    pmPCMMakeModel (source, pcm->modelConv, pcm->nsigma, maskVal, psfSize);
+	
+    float YY = 0.0;
+    float YM = 0.0;
+    float MM = 0.0;
+    bool usePoisson = false;
+
+    for (int iy = 0; iy < source->pixels->numRows; iy++) {
+	for (int ix = 0; ix < source->pixels->numCols; ix++) {
+	    // skip masked points
+	    if (source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix]) {
+		continue;
+	    }
+	    // skip zero-variance points
+	    if (source->variance->data.F32[iy][ix] == 0) {
+		continue;
+	    }
+	    // skip nan value points
+	    if (!isfinite(source->pixels->data.F32[iy][ix])) {
+		continue;
+	    }
+
+	    float fy = source->pixels->data.F32[iy][ix];
+	    float fm = source->modelFlux->data.F32[iy][ix];
+	    float wt = (usePoisson) ? 1.0 / source->variance->data.F32[iy][ix] : 1.0;
+
+	    YY += PS_SQR(fy) * wt;
+	    YM += fm * fy * wt;
+	    MM += PS_SQR(fm) * wt;
+	}
+    }
+
+    float Io = YM / MM;
+    PAR[PM_PAR_I0] = Io;
+
+    pmSourceFitPCM (pcm, source, fitOptions, maskVal, markVal, psfSize);  // NOTE : 1687 allocs in here
+
+    return true;
+}
+
+
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotSourceSize.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotSourceSize.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotSourceSize.c	(revision 37066)
@@ -1,5 +1,5 @@
 # include "psphotInternal.h"
-# include <gsl/gsl_sf_gamma.h>
-
+
+// this structure is only used internally to simplify the function parameters
 typedef struct {
     psImageMaskType maskVal;
@@ -13,7 +13,4 @@
     bool altDiffExt;
     float altDiffExtThresh;
-    bool extFitAll;
-    bool extFitAllReadout;
-    float extFitAllThresh;
     float soft;
     int grow;
@@ -33,5 +30,4 @@
 bool psphotSourceSelectCR (pmReadout *readout, psArray *sources, psphotSourceSizeOptions *options);
 bool psphotMaskCosmicRay (pmReadout *readout, pmSource *source, psImageMaskType maskVal, int maxWindowCR);
-bool psphotMaskCosmicRayFootprintCheck (psArray *sources);
 int  psphotMaskCosmicRayConnected (int xPeak, int yPeak, psImage *mymask, psImage *myvar, psImage *edges, int binning, float sigma_thresh);
 float psphotSourceSizeFindThreshold (psVector *value, psVector *mask, int maskValue, float minValue, float maxValue, float delta, float guess, float fraction);
@@ -41,8 +37,5 @@
 
 // we need to call this function after sources have been fitted to the PSF model and
-// subtracted.  To determine the CR-nature, this function examines the 9 pixels in the 3x3
-// square containing the peak and compares the observed flux to the model.  To determine
-// the EXT-nature, this function measures the amount of positive or negative total
-// deviation from the psf model at the r = FWHM/2 position
+// subtracted.  
 
 // for now, let's store the detections on the readout->analysis for each readout
@@ -121,21 +114,16 @@
     assert (status);
 
-    // XXX recipe name is not great
+    // XXX recipe name is not great (NOTE : not used!)
     options.nSigmaMoments = psMetadataLookupF32 (&status, recipe, "PSPHOT.EXT.NSIGMA.MOMENTS");
     assert (status);
 
-    // Optional extended source measurement algorithm to improve diff image trails
+    // Optional algorithm to define if a source is extended (used by DIFF analysis)
     options.altDiffExt = psMetadataLookupBool(&status, recipe, "PSPHOT.EXT.DIFF.ALTERNATE");
     assert (status);
+
     // Threshold for this alternate method
     options.altDiffExtThresh = psMetadataLookupF32(&status, recipe, "PSPHOT.EXT.DIFF.ALTERNATE.THRESH");
     assert (status);
-    // Option to enable fitting of all objects with extended model.
-    options.extFitAll = psMetadataLookupBool(&status, recipe, "PSPHOT.EXT.FIT.ALL.SOURCES");
-    assert (status);
-    // Fitting everything is fine, but if the source density is high, we probably shouldn't.
-    options.extFitAllThresh = psMetadataLookupF32(&status, recipe, "PSPHOT.EXT.FIT.ALL.THRESH");
-    assert (status);
-    
+
     // location of a single test source
     options.xtest = psMetadataLookupS32 (&status, recipe, "PSPHOT.CRMASK.XTEST");
@@ -422,19 +410,5 @@
 
     psLogMsg("psModules.objects", PS_LOG_INFO, "Source Size classifications: %4s %4s %4s %4s %4s", "Npsf", "Next", "Nsat", "Ncr", "Nskip");
-    // Determine if this readout is above the threshold to ext fit all sources
-    options->extFitAllReadout = false;
-    if (options->extFitAll) {
-      float maskFrac = psMetadataLookupF32(&status,readout->analysis,"READOUT.MASK.FRAC");
-      if (status) {
-	maskFrac = 0.0;
-      }
-      if (sources->n * (1.0 - maskFrac) > options->extFitAllThresh) {
-	options->extFitAllReadout = false;
-      }
-      else {
-	options->extFitAllReadout = true;
-      }
-    }
-    
+
     if (!psphotSourceClassRegion (NULL, &psfClump, sources, recipe, psf, options)) {
 	psLogMsg ("psphot", 4, "Failed to determine source classification for full image\n");
@@ -444,4 +418,5 @@
     return true;
     
+    // NOTE : this section is deactivated (EAM : I think we were getting poor boundary effects?)
     int nRegions = psMetadataLookupS32 (&status, readout->analysis, "PSF.CLUMP.NREGIONS");
     for (int i = 0; i < nRegions; i ++) {
@@ -582,10 +557,4 @@
         // * SAT stars should not be faint, but defects may?
 
-	// If the recipe requests we do extended source fits to everything, set
-	// the EXT_LIMIT flag
-	if (options->extFitAllReadout) {
-	  psTrace("psphotSourceClassRegion.EXTALT",10,"In extFitAll: %d %d\n",options->extFitAll,options->extFitAllReadout);
-	  source->mode |= PM_SOURCE_MODE_EXT_LIMIT;
-	}
         // Defects may not always match CRs from peak curvature analysis
         // Defects may also be marked as SATSTAR -- XXX deactivate this flag?
@@ -595,5 +564,6 @@
 
         // saturated star (too many saturated pixels or peak above saturation limit).  These
-        // may also be saturated galaxies, or just large saturated regions.
+        // may also be saturated galaxies, or just large saturated regions.  They are never
+        // marked as 'extended'
         if (source->mode & PM_SOURCE_MODE_SATSTAR) {
             psTrace("psphotSourceClassRegion.SAT",4,"CLASS: %g %g\t%g %g\t%g %g\t%g %g\t%g SAT\n",
@@ -604,5 +574,6 @@
         }
 
-        // any sources missing a large fraction should just be treated as PSFs
+        // any sources missing a large fraction should just be treated as PSFs. They are never
+        // marked as 'extended'
         if ((source->pixWeightNotBad < 0.9) || (source->pixWeightNotPoor < 0.9)) {
             psTrace("psphotSourceClassRegion.PSF",4,"CLASS: %g %g\t%g %g  %g %g  %g %g\t%g %g\t%g PSF\t%g %g\n",
@@ -634,4 +605,5 @@
             psTrace("psphotSourceClassRegion.EXT",4,"CLASS: %g %g\t%g %g\t%g %g\t%g %g\t%g EXT\n",
                     source->peak->xf, source->peak->yf, Mminor, kMag, dMag, nSigmaMAG, options->sizeLimitCR, options->magLimitCR, options->nSigmaApResid);
+	    source->type = PM_SOURCE_TYPE_EXTENDED;
             source->mode |= PM_SOURCE_MODE_EXT_LIMIT;
             source->tmpFlags |= PM_SOURCE_TMPF_SIZE_MEASURED;
@@ -639,4 +611,5 @@
             continue;
         }
+
 	// Alternate extended source limit calculation
 	if (options->altDiffExt) {
@@ -652,4 +625,5 @@
                     source->peak->xf, source->peak->yf, Mminor, kMag, dMag, nSigmaMAG, options->sizeLimitCR, options->magLimitCR, options->nSigmaApResid,
 		    momentRatioVeres,options->altDiffExtThresh);
+	    source->type = PM_SOURCE_TYPE_EXTENDED;
             source->mode |= PM_SOURCE_MODE_EXT_LIMIT;
             source->tmpFlags |= PM_SOURCE_TMPF_SIZE_MEASURED;
@@ -968,69 +942,4 @@
 }
 
-bool psphotMaskCosmicRayFootprintCheck (psArray *sources) {
-#ifdef CHECK_FOOTPRINTS
-    // This gets really expensive for complex images
-    for (int i = 0; i < sources->n; i++) {
-        pmSource *source = sources->data[i];
-        pmPeak *peak = source->peak;
-        pmFootprint *footprint = peak->footprint;
-        if (!footprint) continue;
-        for (int j = 0; j < footprint->spans->n; j++) {
-            pmSpan *sp = footprint->spans->data[j];
-            psAssert (sp, "missing span");
-        }
-    }
-#endif
-    return true;
-}
-
-/**** ------ old versions of cosmic ray masking ----- ****/
-
-bool psphotMaskCosmicRayIsophot (pmSource *source, psImageMaskType maskVal, psImageMaskType crMask);
-
-// This attempt to mask the cosmic rays used the isophotal boundary
-bool psphotMaskCosmicRay_V1 (psImage *mask, pmSource *source, psImageMaskType maskVal, psImageMaskType crMask) {
-
-    // replace the source flux
-    pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);
-
-    // flag this as a CR
-    source->mode |= PM_SOURCE_MODE_CR_LIMIT;
-    pmPeak *peak = source->peak;
-    psAssert (peak, "NULL peak");
-
-    // grab the matching footprint
-    pmFootprint *footprint = peak->footprint;
-    if (!footprint) {
-      psTrace("psphot.czw",2,"Using isophot CR mask code.");
-
-        // if we have not footprint, use the old code to mask by isophot
-        psphotMaskCosmicRayIsophot (source, maskVal, crMask);
-        return true;
-    }
-
-    if (!footprint->spans) {
-      psTrace("psphot.czw",2,"Using isophot CR mask code.");
-
-        // if we have no footprint, use the old code to mask by isophot
-        psphotMaskCosmicRayIsophot (source, maskVal, crMask);
-        return true;
-    }
-    psphotMaskCosmicRayIsophot (source, maskVal, crMask);
-    // mask all of the pixels covered by the spans of the footprint
-    for (int j = 1; j < footprint->spans->n; j++) {
-        pmSpan *span1 = footprint->spans->data[j];
-
-        int iy = span1->y;
-        int xs = span1->x0;
-        int xe = span1->x1;
-
-        for (int ix = xs; ix < xe; ix++) {
-            mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= crMask;
-        }
-    }
-    return true;
-}
-
 # define VERBOSE 0
 int psphotMaskCosmicRayConnected (int xPeak, int yPeak, psImage *mymask, psImage *myvar, psImage *edges, int binning, float sigma_thresh) {
@@ -1176,278 +1085,4 @@
 }
 
-bool psphotMaskCosmicRayIsophot (pmSource *source, psImageMaskType maskVal, psImageMaskType crMask) {
-
-    source->mode |= PM_SOURCE_MODE_CR_LIMIT;
-    pmPeak *peak = source->peak;
-    psAssert (peak, "NULL peak");
-
-    psImage *mask   = source->maskView;
-    psImage *pixels = source->pixels;
-    psImage *variance = source->variance;
-
-    // XXX This should be a recipe variable
-# define SN_LIMIT 5.0
-
-    int xo = peak->x - pixels->col0;
-    int yo = peak->y - pixels->row0;
-
-    // mark the pixels in this row to the left, then the right
-    for (int ix = xo; ix >= 0; ix--) {
-        float SN = pixels->data.F32[yo][ix] / sqrt(variance->data.F32[yo][ix]);
-        if (SN > SN_LIMIT) {
-            mask->data.PS_TYPE_IMAGE_MASK_DATA[yo][ix] |= crMask;
-        }
-    }
-    for (int ix = xo + 1; ix < pixels->numCols; ix++) {
-        float SN = pixels->data.F32[yo][ix] / sqrt(variance->data.F32[yo][ix]);
-        if (SN > SN_LIMIT) {
-            mask->data.PS_TYPE_IMAGE_MASK_DATA[yo][ix] |= crMask;
-        }
-    }
-
-    // for each of the neighboring rows, mark the high pixels if they have a marked neighbor
-    // first go up:
-    for (int iy = PS_MIN(yo, mask->numRows-2); iy >= 0; iy--) {
-        // mark the pixels in this row to the left, then the right
-        for (int ix = 0; ix < pixels->numCols; ix++) {
-            float SN = pixels->data.F32[iy][ix] / sqrt(variance->data.F32[iy][ix]);
-            if (SN < SN_LIMIT) continue;
-
-            bool valid = false;
-            valid |= (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+1][ix] & crMask);
-            valid |= (ix > 0) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+1][ix-1] & crMask) : 0;
-            valid |= (ix <= mask->numCols) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+1][ix+1] & crMask) : 0;
-
-            if (!valid) continue;
-            mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= crMask;
-        }
-    }
-    // next go down:
-    for (int iy = PS_MIN(yo+1, mask->numRows-1); iy < pixels->numRows; iy++) {
-        // mark the pixels in this row to the left, then the right
-        for (int ix = 0; ix < pixels->numCols; ix++) {
-            float SN = pixels->data.F32[iy][ix] / sqrt(variance->data.F32[iy][ix]);
-            if (SN < SN_LIMIT) continue;
-
-            bool valid = false;
-            valid |= (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy-1][ix] & crMask);
-            valid |= (ix > 0) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy-1][ix-1] & crMask) : 0;
-            valid |= (ix <= mask->numCols) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy-1][ix+1] & crMask) : 0;
-
-            if (!valid) continue;
-            mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= crMask;
-        }
-    }
-    return true;
-}
-
-// given the PSF ellipse parameters, navigate around the 1sigma contour, return the total
-// deviation in sigmas.  This is measured on the residual image - should we ignore negative
-// deviations?  NOTE: This function was an early attempt to classify extended objects, and is
-// no longer used by psphot.
-float psphotModelContour(const psImage *image, const psImage *variance, const psImage *mask,
-                         psImageMaskType maskVal, const pmModel *model, float Ro)
-{
-    psF32 *PAR = model->params->data.F32; // Model parameters
-    float sxx = PAR[PM_PAR_SXX], sxy = PAR[PM_PAR_SXY], syy = PAR[PM_PAR_SYY]; // Ellipse parameters
-
-    // We treat the contour as an ellipse:
-    // Ro = (x / SXX)^2 + (y / SYY)^2 + x y SXY
-    // y^2 (1/SYY^2) + y (x SXY) + (x / SXX)^2 - Ro = 0;
-    // This is a quadratic, Ay^2 + By + C with A = 1/SYY^2, B = x*SXY, C = (x / SXX)^2 - Ro
-    // The solution is y = [-B +/- sqrt (B^2 - 4 A C)] / [2 A], so:
-    // y = [-(x SXY) +/- sqrt ((x SXY)^2 - 4 (1/SYY^2) ((x/SXX)^2 - Ro))] * [SYY^2 / 2]
-
-    // min/max value of x is where B^2 - 4AC = 0; solve this for x
-    float Q = Ro * PS_SQR(sxx) / (1.0 - PS_SQR(sxx * syy * sxy) / 4.0);
-    if (Q < 0.0) {
-        // ellipse is imaginary
-        return NAN;
-    }
-
-    int radius = sqrtf(Q) + 0.5;        // Radius of ellipse
-    int nPts = 0;                       // Number of points in ellipse
-    float nSigma = 0.0;                 //
-
-    for (int x = -radius; x <= radius; x++) {
-        // Polynomial coefficients
-        // XXX Should we be using the centre of the pixel as x or x+0.5?
-        float A = PS_SQR (1.0 / syy);
-        float B = x * sxy;
-        float C = PS_SQR (x / sxx) - Ro;
-        float T = PS_SQR(B) - 4*A*C;
-        if (T < 0.0) {
-            continue;
-        }
-
-        // y position in source frame
-        float yP = (-B + sqrt (T)) / (2.0 * A);
-        float yM = (-B - sqrt (T)) / (2.0 * A);
-
-        // Get the closest pixel positions (image frame)
-        int xPix  = x  + PAR[PM_PAR_XPOS] - image->col0 + 0.5;
-        int yPixM = yM + PAR[PM_PAR_YPOS] - image->row0 + 0.5;
-        int yPixP = yP + PAR[PM_PAR_YPOS] - image->row0 + 0.5;
-
-        if (xPix < 0 || xPix >= image->numCols) {
-            continue;
-        }
-
-        if (yPixM >= 0 && yPixM < image->numRows &&
-            !(mask && (mask->data.PS_TYPE_IMAGE_MASK_DATA[yPixM][xPix] & maskVal))) {
-            float dSigma = image->data.F32[yPixM][xPix] / sqrtf(variance->data.F32[yPixM][xPix]);
-            nSigma += dSigma;
-            nPts++;
-        }
-
-        if (yPixM == yPixP) {
-            continue;
-        }
-
-        if (yPixP >= 0 && yPixP < image->numRows &&
-            !(mask && (mask->data.PS_TYPE_IMAGE_MASK_DATA[yPixP][xPix] & maskVal))) {
-            float dSigma = image->data.F32[yPixP][xPix] / sqrtf(variance->data.F32[yPixP][xPix]);
-            nSigma += dSigma;
-            nPts++;
-        }
-    }
-    nSigma /= nPts;
-    return nSigma;
-}
-
-// this was an old attempt to identify cosmic rays based on the peak curvature
-bool psphotSourcePeakCurvature (pmReadout *readout, psArray *sources, psphotSourceSizeOptions *options) {
-
-    // classify the sources based on the CR test (place this in a function?)
-    // XXX use an internal flag to mark sources which have already been measured
-    for (int i = 0; i < sources->n; i++) {
-        pmSource *source = sources->data[i];
-
-        // skip source if it was already measured
-        if (source->tmpFlags & PM_SOURCE_TMPF_SIZE_MEASURED) {
-            psTrace("psphot", 7, "Not calculating source size since it has already been measured\n");
-            continue;
-        }
-
-        // source must have been subtracted
-        if (!(source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED)) {
-            source->mode |= PM_SOURCE_MODE_SIZE_SKIPPED;
-            psTrace("psphot", 7, "Not calculating source size since source is not subtracted\n");
-            continue;
-        }
-
-        psF32 **resid  = source->pixels->data.F32;
-        psF32 **variance = source->variance->data.F32;
-        psImageMaskType **mask = source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA;
-
-        // Integer position of peak
-        int xPeak = source->peak->xf - source->pixels->col0 + 0.5;
-        int yPeak = source->peak->yf - source->pixels->row0 + 0.5;
-
-        // Skip sources which are too close to a boundary.  These are mostly caught as DEFECT
-        if (xPeak < 1 || xPeak > source->pixels->numCols - 2 ||
-            yPeak < 1 || yPeak > source->pixels->numRows - 2) {
-            psTrace("psphot", 7, "Not calculating crNsigma due to edge\n");
-            continue;
-        }
-
-        // Skip sources with masked pixels.  These are mostly caught as DEFECT
-        bool keep = true;
-        for (int iy = -1; (iy <= +1) && keep; iy++) {
-            for (int ix = -1; (ix <= +1) && keep; ix++) {
-                if (mask[yPeak+iy][xPeak+ix] & options->maskVal) {
-                    keep = false;
-                }
-            }
-        }
-        if (!keep) {
-            psTrace("psphot", 7, "Not calculating crNsigma due to masked pixels\n");
-            continue;
-        }
-
-        // Compare the central pixel with those on either side, for the four possible lines through it.
-
-        // Soften variances (add systematic error)
-        float softening = options->soft * PS_SQR(source->peak->rawFlux); // Softening for variances
-
-        // Across the middle: y = 0
-        float cX = 2*resid[yPeak][xPeak]   - resid[yPeak+0][xPeak-1]  - resid[yPeak+0][xPeak+1];
-        float dcX = 4*variance[yPeak][xPeak] + variance[yPeak+0][xPeak-1] + variance[yPeak+0][xPeak+1];
-        float nX = cX / sqrtf(dcX + softening);
-
-        // Up the centre: x = 0
-        float cY = 2*resid[yPeak][xPeak]   - resid[yPeak-1][xPeak+0]  - resid[yPeak+1][xPeak+0];
-        float dcY = 4*variance[yPeak][xPeak] + variance[yPeak-1][xPeak+0] + variance[yPeak+1][xPeak+0];
-        float nY = cY / sqrtf(dcY + softening);
-
-        // Diagonal: x = y
-        float cL = 2*resid[yPeak][xPeak]   - resid[yPeak-1][xPeak-1]  - resid[yPeak+1][xPeak+1];
-        float dcL = 4*variance[yPeak][xPeak] + variance[yPeak-1][xPeak-1] + variance[yPeak+1][xPeak+1];
-        float nL = cL / sqrtf(dcL + softening);
-
-        // Diagonal: x = - y
-        float cR = 2*resid[yPeak][xPeak]   - resid[yPeak+1][xPeak-1]  - resid[yPeak-1][xPeak+1];
-        float dcR = 4*variance[yPeak][xPeak] + variance[yPeak+1][xPeak-1] + variance[yPeak-1][xPeak+1];
-        float nR = cR / sqrtf(dcR + softening);
-
-        // P(chisq > chisq_obs; Ndof) = gamma_Q (Ndof/2, chisq/2)
-        // Ndof = 4 ? (four measurements, no free parameters)
-        // XXX this value is going to be biased low because of systematic errors.
-        // we need to calibrate it somehow
-        // source->psfProb = gsl_sf_gamma_inc_Q (2, 0.5*chisq);
-
-        // not strictly accurate: overcounts the chisq contribution from the center pixel (by
-        // factor of 4); also biases a bit low if any pixels are masked
-        // XXX I am not sure I want to keep this value...
-        source->psfChisq = PS_SQR(nX) + PS_SQR(nY) + PS_SQR(nL) + PS_SQR(nR);
-
-        float fCR = 0.0;
-        int nCR = 0;
-        if (nX > 0.0) {
-            fCR += nX;
-            nCR ++;
-        }
-        if (nY > 0.0) {
-            fCR += nY;
-            nCR ++;
-        }
-        if (nL > 0.0) {
-            fCR += nL;
-            nCR ++;
-        }
-        if (nR > 0.0) {
-            fCR += nR;
-            nCR ++;
-        }
-        source->crNsigma  = (nCR > 0)  ? fCR / nCR : 0.0;
-        source->tmpFlags |= PM_SOURCE_TMPF_SIZE_MEASURED;
-
-        if (!isfinite(source->crNsigma)) {
-            continue;
-        }
-
-        // this source is thought to be a cosmic ray.  flag the detection and mask the pixels
-        if (source->crNsigma > options->nSigmaCR) {
-            source->mode |= PM_SOURCE_MODE_CR_LIMIT;
-            // XXX still testing... : psphotMaskCosmicRay (readout->mask, source, maskVal, crMask);
-            // XXX acting strange... psphotMaskCosmicRay_Old (source, maskVal, crMask);
-        }
-    }
-
-    // now that we have masked pixels associated with CRs, we can grow the mask
-    if (options->grow > 0) {
-        bool oldThreads = psImageConvolveSetThreads(true); // Old value of threading for psImageConvolveMask
-        psImage *newMask = psImageConvolveMask(NULL, readout->mask, options->crMask, options->crMask, -options->grow, options->grow, -options->grow, options->grow);
-        psImageConvolveSetThreads(oldThreads);
-        if (!newMask) {
-            psError(PS_ERR_UNKNOWN, false, "Unable to grow CR mask");
-            return false;
-        }
-        psFree(readout->mask);
-        readout->mask = newMask;
-    }
-    return true;
-}
-
 float psphotSourceSizeFindThreshold (psVector *value, psVector *mask, int maskValue, float minValue, float maxValue, float delta, float guess, float fraction) {
 
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotSourceStats.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotSourceStats.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotSourceStats.c	(revision 37066)
@@ -58,12 +58,4 @@
     pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS");
     psAssert (detections, "missing detections?");
-
-    // XXX TEST:
-    if (detections->allSources) {
-        psphotMaskCosmicRayFootprintCheck(detections->allSources);
-    }
-    if (detections->newSources) {
-        psphotMaskCosmicRayFootprintCheck(detections->newSources);
-    }
 
     // determine the number of allowed threads
@@ -246,14 +238,4 @@
     psphotVisualShowMoments (sources);
 
-    // clear the mark bits
-    // psImageMaskPixels (readout->mask, "AND", PS_NOT_IMAGE_MASK(markVal));
-
-    if (detections->allSources) {
-        psphotMaskCosmicRayFootprintCheck(detections->allSources);
-    }
-    if (detections->newSources) {
-        psphotMaskCosmicRayFootprintCheck(detections->newSources);
-    }
-
     return true;
 }
@@ -572,4 +554,6 @@
 
             // measure basic source moments (no S/N clipping on input pixels)
+	    // sources with (mode & MODE_EXTERNAL) or (mode2 & MODE2_MATCHED) use the 
+	    // supplied Mx,My value for the centroid (not recalculated)
             status = pmSourceMoments (source, 4*sigma[i], sigma[i], 0.0, 0.0, maskVal);
         }
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotStackImageLoop.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotStackImageLoop.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotStackImageLoop.c	(revision 37066)
@@ -22,7 +22,5 @@
 
     pmFPAview *view = pmFPAviewAlloc (0);
-    pmFPAfile *inputRaw = psMetadataLookupPtr (&status, config->files, "PSPHOT.STACK.INPUT.RAW");
-    pmFPAfile *inputCnv = psMetadataLookupPtr (&status, config->files, "PSPHOT.STACK.INPUT.CNV");
-    pmFPAfile *input = inputRaw ? inputRaw : inputCnv;
+    pmFPAfile *input = psMetadataLookupPtr (&status, config->files, "PSPHOT.STACK.INPUT.RAW");
 
     if (!input) {
@@ -32,23 +30,7 @@
 
     psMetadata *recipe = psMetadataLookupPtr (NULL, config->recipes, PSPHOT_RECIPE);
-    bool useRaw = psMetadataLookupBool (NULL, recipe, "PSPHOT.STACK.USE.RAW");
-    if (useRaw && inputRaw == NULL) {
-        psLogMsg ("psphot", 1, "PSPHOT.STACK.USE.RAW set but no raw input.");
-        useRaw = false;
-    }
-
-    bool radial_apertures = psMetadataLookupBool(NULL, recipe, "RADIAL_APERTURES");
-    bool match_psfs = radial_apertures;
-    bool needConvolved = radial_apertures || !useRaw;
-    if (!needConvolved) {
-        pmFPAfileActivate (config->files, false, "PSPHOT.STACK.INPUT.CNV");
-        pmFPAfileActivate (config->files, false, "PSPHOT.STACK.MASK.CNV");
-        pmFPAfileActivate (config->files, false, "PSPHOT.STACK.VARIANCE.CNV");
-        pmFPAfileActivate (config->files, false, "PSPHOT.STACK.PSF.CNV");
-    }
 
     // just load the full set of images up front except for EXPNUM which we defer
     pmFPAfileActivate (config->files, false, "PSPHOT.STACK.EXPNUM.RAW");
-    pmFPAfileActivate (config->files, false, "PSPHOT.STACK.EXPNUM.CNV");
     if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE ("failed input for fpa in psphot.");
 
@@ -71,17 +53,8 @@
 		psMemDump("load");
 
-                if (match_psfs) {
-                    // Generate the 1st PSF-matched image set (larger target PSFs are generated by smoothing this image)
-                    if (!psphotStackMatchPSFs (config, view)) {
-                        psError(psErrorCodeLast(), false, "failure in psphotStackMatchPSFs for chip %d, cell %d, readout %d\n", view->chip, view->cell, view->readout);
-                        psFree (view);
-                        return false;
-                    }
-                } else {
-                    if (!psphotStackAllocateOutput (config, view, recipe)) {
-                        psError(psErrorCodeLast(), false, "failure in psphotStackAllocateOutput for chip %d, cell %d, readout %d\n", view->chip, view->cell, view->readout);
-                        psFree (view);
-                        return false;
-                    }
+		if (!psphotStackAllocateOutput (config, view, recipe)) {
+		    psError(psErrorCodeLast(), false, "failure in psphotStackAllocateOutput for chip %d, cell %d, readout %d\n", view->chip, view->cell, view->readout);
+		    psFree (view);
+		    return false;
                 }
 		psMemDump("stackmatch");
@@ -126,5 +99,5 @@
 
     // Load the appropriate EXPNUM image
-    pmFPAfileActivate (config->files, true, useRaw ? "PSPHOT.STACK.EXPNUM.RAW" : "PSPHOT.STACK.EXPNUM.CNV");
+    pmFPAfileActivate (config->files, true, "PSPHOT.STACK.EXPNUM.RAW");
 
     if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE ("failed input for fpa EXPNUM in psphot.");
@@ -146,5 +119,5 @@
                 if (! readout->data_exists) { continue; }
 
-                if (!psphotSetNFrames (config, view, useRaw ? inputRaw->name : inputCnv->name)) ESCAPE ("failed to setNFrames.");
+                if (!psphotSetNFrames (config, view, input->name)) ESCAPE ("failed to setNFrames.");
             }
         }
@@ -167,7 +140,4 @@
 bool UpdateHeadersForReadout (pmConfig *config, pmFPAview *view) {
 
-    psMetadata *recipe = psMetadataLookupPtr (NULL, config->recipes, PSPHOT_RECIPE);
-    bool useRaw = psMetadataLookupBool (NULL, recipe, "PSPHOT.STACK.USE.RAW");
-
     int num = psphotFileruleCount(config, "PSPHOT.INPUT");
 
@@ -179,7 +149,5 @@
 	psAssert (output, "missing file?");
 
-	pmFPAfile *inputRaw = pmFPAfileSelectSingle(config->files, "PSPHOT.STACK.INPUT.RAW", i); // File of interest
-	pmFPAfile *inputCnv = pmFPAfileSelectSingle(config->files, "PSPHOT.STACK.INPUT.CNV", i); // File of interest
-	pmFPAfile *input = useRaw ? inputRaw : inputCnv;
+	pmFPAfile *input = pmFPAfileSelectSingle(config->files, "PSPHOT.STACK.INPUT.RAW", i); // File of interest
 	psAssert (input, "missing input file");
 
@@ -205,7 +173,5 @@
 	psAssert (output, "missing file?");
 
-	pmFPAfile *inputRaw = pmFPAfileSelectSingle(config->files, "PSPHOT.STACK.INPUT.RAW", i); // File of interest
-	pmFPAfile *inputCnv = pmFPAfileSelectSingle(config->files, "PSPHOT.STACK.INPUT.CNV", i); // File of interest
-	pmFPAfile *input = inputRaw ? inputRaw : inputCnv;
+	pmFPAfile *input = pmFPAfileSelectSingle(config->files, "PSPHOT.STACK.INPUT.RAW", i); // File of interest
 	psAssert (input, "missing input file");
 
@@ -242,7 +208,5 @@
 	psAssert (output, "missing file?");
 
-	pmFPAfile *inputRaw = pmFPAfileSelectSingle(config->files, "PSPHOT.STACK.INPUT.RAW", i); // File of interest
-	pmFPAfile *inputCnv = pmFPAfileSelectSingle(config->files, "PSPHOT.STACK.INPUT.CNV", i); // File of interest
-	pmFPAfile *input = inputRaw ? inputRaw : inputCnv;
+	pmFPAfile *input = pmFPAfileSelectSingle(config->files, "PSPHOT.STACK.INPUT.RAW", i); // File of interest
 	psAssert (input, "missing input file");
 
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotStackMatchPSFsNext.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotStackMatchPSFsNext.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotStackMatchPSFsNext.c	(revision 37066)
@@ -43,5 +43,5 @@
     for (int i = 0; i < num; i++) {
 	if (!psphotStackMatchPSFsNextReadout (config, view, filerule, i, lastSize)) {
-            psError (PSPHOT_ERR_CONFIG, false, "failed to smooth image %s (%d) to target PSF", filerule, i);
+	    psLogMsg ("psphot", PS_LOG_INFO, "failed to smooth image %s (%d) to target PSF", filerule, i);
 	    psImageConvolveSetThreads(oldThreads);
 	    return false;
@@ -102,5 +102,8 @@
 
     if (targetFWHM <= currentFWHM) {
-	psError (PSPHOT_ERR_CONFIG, true, "target FWHM cannot be smaller than current FWHM");
+	// psError (PSPHOT_ERR_CONFIG, true, "target FWHM cannot be smaller than current FWHM");
+	psLogMsg ("psphot", PS_LOG_INFO, "target FWHM (%f) is smaller than current FWHM (%f), not smoothing\n", targetFWHM, currentFWHM);
+	fwhmValues->data.F32[lastSize + 1] = currentFWHM;
+        pmReadoutMaskInvalid(readout, maskVal, maskSat);
 	return false;
     }
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotStackMatchPSFsUtils.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotStackMatchPSFsUtils.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotStackMatchPSFsUtils.c	(revision 37066)
@@ -325,5 +325,5 @@
     if (deconv > deconvLimit) {
         rejectReadout = true;
-	psLogMsg("psphot", PS_LOG_WARN, "Maximum deconvolution fraction (%f) exceeds limit (%f) --- rejecting image for matched psf analysis%d\n", deconv, deconvLimit, index);
+	psLogMsg("psphot", PS_LOG_WARN, "Maximum deconvolution fraction (%f) exceeds limit (%f) --- rejecting input %d for matched psf analysis\n", deconv, deconvLimit, index);
     }
     
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotStackReadout.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotStackReadout.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotStackReadout.c	(revision 37066)
@@ -1,16 +1,43 @@
 # include "psphotInternal.h"
 
+static bool psphotStackMatchPSFsetup (pmConfig *config, const pmFPAview *view, const char *filerule, const char *fPSF);
+static bool psphotStackMatchPSFsetupReadout (pmConfig *config, const pmFPAview *view, const char *filerule, const char *fPSF, int index);
 static bool psphotStackLoadWCS(pmConfig *config, const pmFPAview *view, const char *filerule);
 static void logMemStats(const char *heading);
 
-// we have 3 possible real filesets:
+// relevant filesets:
 # define STACK_RAW "PSPHOT.STACK.INPUT.RAW"
-# define STACK_CNV "PSPHOT.STACK.INPUT.CNV"
-# define STACK_OUT "PSPHOT.STACK.OUTPUT.IMAGE"  /* the psf-matched image */
-
-// we have 3 files on which we operate:
-// DET (detection image)       : nominally RAW (optionally CNV?)
-// SRC (source analysis image) : nominally CNV (optionally RAW)
-// OUT (psf-matched images)    : always OUT
+# define STACK_OUT "PSPHOT.STACK.OUTPUT.IMAGE"
+
+// XXX STACK_OUT currently is a copy of STACK_RAW, but should be a pointer to is as in psphot (single)
+
+// TEST CODE, can be removed
+bool psphotDumpImages (pmConfig *config, const pmFPAview *view, const char *filerule, char *base) {
+
+    // XXX do nothing
+    return true;
+
+    int num = psphotFileruleCount(config, "PSPHOT.INPUT");
+
+    for (int i = 0; i < num; i++) {
+	// find the currently selected readout
+	pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, i); // File of interest
+	psAssert (file, "missing file?");
+
+	pmReadout *readout = pmFPAviewThisReadout(view, file->fpa);
+	psAssert (readout, "missing readout?");
+
+	char line[256];
+	snprintf (line, 256, "%s.%d.im.fits", base, i);
+	psphotSaveImage (NULL, readout->image, line);
+
+	snprintf (line, 256, "%s.%d.wt.fits", base, i);
+	psphotSaveImage (NULL, readout->variance, line);
+
+	snprintf (line, 256, "%s.%d.mk.fits", base, i);
+	psphotSaveImage (NULL, readout->mask, line);
+    }
+    return true;
+}
 
 bool psphotStackVisualFilerule(pmConfig *config, const pmFPAview *view, const char *filerule) {
@@ -67,18 +94,12 @@
     psAssert (breakPt, "configuration error: set BREAK_POINT");
 
-    // we have 3 relevant files: RAW (unconvolved), CNV (convolved stack), OUT (psf-matched stack)
-    // select which image (RAW or CNV) is used for analysis (RAW always used for detection)
-    bool useRaw = psMetadataLookupBool (NULL, recipe, "PSPHOT.STACK.USE.RAW");
-    char *STACK_SRC = useRaw ? STACK_RAW : STACK_CNV;
-    char *STACK_DET = STACK_RAW;
-
     // load WCS 
-    if (!psphotStackLoadWCS(config, view, STACK_SRC)) {
-        psError (PSPHOT_ERR_CONFIG, false, "trouble loading WCS for %s", STACK_SRC);
+    if (!psphotStackLoadWCS(config, view, STACK_RAW)) {
+        psError (PSPHOT_ERR_CONFIG, false, "trouble loading WCS for %s", STACK_RAW);
         return false;
     }
 
     // set the photcode for each image
-    if (!psphotAddPhotcode (config, view, STACK_SRC)) {
+    if (!psphotAddPhotcode (config, view, STACK_RAW)) {
         psError (PSPHOT_ERR_CONFIG, false, "trouble defining the photcode");
         return false;
@@ -86,77 +107,49 @@
 
     // Generate the mask and weight images (if not supplied) and set mask bits. 
-    // This also insures that all invalid pixels are masked (this is done for STACK_CNV in psphotStackMatchPSFs)
-    if (!psphotSetMaskAndVariance (config, view, STACK_DET)) {
-	return psphotReadoutCleanup (config, view, STACK_SRC);
-    }
-    if (!psphotSetMaskAndVariance (config, view, STACK_OUT)) {
-	return psphotReadoutCleanup (config, view, STACK_SRC);
+    if (!psphotSetMaskAndVariance (config, view, STACK_RAW)) {
+	return psphotReadoutCleanup (config, view, STACK_RAW);
     }
     if (!strcasecmp (breakPt, "NOTHING")) {
-	return psphotReadoutCleanup (config, view, STACK_SRC);
+	return psphotReadoutCleanup (config, view, STACK_RAW);
     }
 
     // generate a background model (median, smoothed image)
-    if (!psphotModelBackground (config, view, STACK_DET)) {
-	return psphotReadoutCleanup (config, view, STACK_SRC);
-    }
-    if (!psphotSubtractBackground (config, view, STACK_DET)) {
-	return psphotReadoutCleanup (config, view, STACK_SRC);
-    }
-    if (strcmp(STACK_SRC, STACK_DET)) {
-#define MODEL_BACKGROUND_SRC 1
-#ifdef MODEL_BACKGROUND_SRC
-        // work around the fact that the background levels on the convolved
-        // and unconvolved stacks can be different
-        if (!psphotModelBackground (config, view, STACK_SRC)) {
-            return psphotReadoutCleanup (config, view, STACK_SRC);
-        }
-#endif
-        if (!psphotSubtractBackground (config, view, STACK_SRC)) {
-            return psphotReadoutCleanup (config, view, STACK_SRC);
-        }
+    if (!psphotModelBackground (config, view, STACK_RAW)) {
+	return psphotReadoutCleanup (config, view, STACK_RAW);
+    }
+    if (!psphotSubtractBackground (config, view, STACK_RAW)) {
+	return psphotReadoutCleanup (config, view, STACK_RAW);
     }
     if (!strcasecmp (breakPt, "BACKMDL")) {
-	return psphotReadoutCleanup (config, view, STACK_SRC);
+	return psphotReadoutCleanup (config, view, STACK_RAW);
     }
 
 #ifdef MAKE_CHISQ_IMAGE
     // also make the chisq detection image
-    if (!psphotStackChisqImage(config, view, STACK_DET, STACK_SRC)) {
+    if (!psphotStackChisqImage(config, view, STACK_RAW, STACK_RAW)) {
         psError (PSPHOT_ERR_UNKNOWN, false, "failure to generate chisq image");
-        return psphotReadoutCleanup (config, view, STACK_SRC);
+        return psphotReadoutCleanup (config, view, STACK_RAW);
+    }
+    if (!strcasecmp (breakPt, "CHISQ")) {
+	return psphotReadoutCleanup (config, view, STACK_RAW);
     }
 #endif
-    if (!strcasecmp (breakPt, "CHISQ")) {
-	return psphotReadoutCleanup (config, view, STACK_SRC);
-    }
 
     // find the detections (by peak and/or footprint) in the image.
     // This finds the detections on Chisq image as well as the individuals
-    if (!psphotFindDetections (config, view, STACK_DET, true)) { // pass 1
-        // this only happens if we had an error in psphotFindDetections
+    if (!psphotFindDetections (config, view, STACK_RAW, true)) { // pass 1
         psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis");
-        return psphotReadoutCleanup (config, view, STACK_SRC);
-    }
-
-    // If DET and SRC are different images, copy the detections from DET to SRC.  This 'copy'
-    // is just a copy of the container pointer; the sources on both DET and SRC are the same
-    // memory objects
-    if (strcmp(STACK_SRC, STACK_DET)) {
-	if (!psphotCopySources (config, view, STACK_SRC, STACK_DET)) {
-	    psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis");
-	    return psphotReadoutCleanup (config, view, STACK_SRC);
-	}
+        return psphotReadoutCleanup (config, view, STACK_RAW);
     }
 
     // construct sources and measure basic stats (saved on detections->newSources)
-    if (!psphotSourceStats (config, view, STACK_SRC, true)) { // pass 1
+    if (!psphotSourceStats (config, view, STACK_RAW, true)) { // pass 1
         psError(PSPHOT_ERR_UNKNOWN, false, "failure to generate sources");
-        return psphotReadoutCleanup (config, view, STACK_SRC);
+        return psphotReadoutCleanup (config, view, STACK_RAW);
     }
     if (!strcasecmp (breakPt, "PEAKS")) {
-	return psphotReadoutCleanup (config, view, STACK_SRC);
-    }
-    // psphotDumpTest (config, view, STACK_SRC);
+	return psphotReadoutCleanup (config, view, STACK_RAW);
+    }
+    // psphotDumpTest (config, view, STACK_RAW);
     psMemDump("sourcestats");
     logMemStats("sourcestats");
@@ -164,60 +157,48 @@
     // classify sources based on moments, brightness
     // only run this on detections from the input images, not chisq image
-    if (!psphotRoughClass (config, view, STACK_SRC)) {
+    if (!psphotRoughClass (config, view, STACK_RAW)) {
         psError (PSPHOT_ERR_UNKNOWN, false, "failed to determine rough classifications");
-	return psphotReadoutCleanup (config, view, STACK_SRC);
-    }
-
-    // If DET and SRC are different images, subtract radial profiles for the convolved
-    // image first.  The profiles found on the convolved image will be replaced by those
-    // found for the unconvolved image.  Downstream, in psphotFindDetections, we will
-    // replace the the profiles (and re-subtract them) for the detection image, so we want
-    // to keep those versions of the profiles on the sources.
-    if (strcmp(STACK_SRC, STACK_DET)) {
-      // find and subtract radial profile models for saturated stars (XXX change name eventually)
-      if (!psphotDeblendSatstars (config, view, STACK_SRC)) {
+	return psphotReadoutCleanup (config, view, STACK_RAW);
+    }
+
+    // find and subtract radial profile models for saturated stars (XXX change name eventually)
+    if (!psphotDeblendSatstars (config, view, STACK_RAW)) {
 	psError (PSPHOT_ERR_UNKNOWN, false, "failed on satstar deblend analysis");
-	return psphotReadoutCleanup (config, view, STACK_SRC);
-      }
-    }
-    // find and subtract radial profile models for saturated stars (XXX change name eventually)
-    if (!psphotDeblendSatstars (config, view, STACK_DET)) {
-	psError (PSPHOT_ERR_UNKNOWN, false, "failed on satstar deblend analysis");
-	return psphotReadoutCleanup (config, view, STACK_SRC);
+	return psphotReadoutCleanup (config, view, STACK_RAW);
     }
 
     // if we were not supplied a PSF model, determine the IQ stats here (detections->newSources)
     // only run this on detections from the input images, not chisq image
-    if (!psphotImageQuality (config, view, STACK_SRC)) { // pass 1
+    if (!psphotImageQuality (config, view, STACK_RAW)) { // pass 1
         psError (PSPHOT_ERR_UNKNOWN, false, "failed to measure image quality");
-        return psphotReadoutCleanup (config, view, STACK_SRC);
+        return psphotReadoutCleanup (config, view, STACK_RAW);
     }
     if (!strcasecmp (breakPt, "MOMENTS")) {
-	return psphotReadoutCleanup (config, view, STACK_SRC);
+	return psphotReadoutCleanup (config, view, STACK_RAW);
     }
 
     // use bright stellar objects to measure PSF
-    if (!psphotChoosePSF (config, view, STACK_SRC, true)) { // pass 1
+    if (!psphotChoosePSF (config, view, STACK_RAW, true)) { // pass 1
         psLogMsg ("psphot", 3, "failure to construct a psf model");
-        return psphotReadoutCleanup (config, view, STACK_SRC);
+        return psphotReadoutCleanup (config, view, STACK_RAW);
     }
     if (!strcasecmp (breakPt, "PSFMODEL")) {
-        return psphotReadoutCleanup (config, view, STACK_SRC);
+        return psphotReadoutCleanup (config, view, STACK_RAW);
     }
 
     // merge the newly selected sources into the existing list
     // NOTE: merge OLD and NEW
-    psphotMergeSources (config, view, STACK_SRC);
+    psphotMergeSources (config, view, STACK_RAW);
 
     // Construct an initial model for each object, set the radius to fitRadius, set circular
     // fit mask.  NOTE: only applied to sources without guess models
-    psphotGuessModels (config, view, STACK_SRC);
+    psphotGuessModels (config, view, STACK_RAW);
 
     // linear PSF fit to source peaks, subtract the models from the image (in PSF mask)
-    psphotFitSourcesLinear (config, view, STACK_SRC, false, false);
-    psphotStackVisualFilerule(config, view, STACK_SRC);
+    psphotFitSourcesLinear (config, view, STACK_RAW, false, false);
+    psphotStackVisualFilerule(config, view, STACK_RAW);
 
     // measure the radial profiles to the sky
-    psphotRadialProfileWings (config, view, STACK_SRC);
+    psphotRadialProfileWings (config, view, STACK_RAW);
 
     // re-measure the kron mags with models subtracted.  this pass starts with a circular
@@ -225,16 +206,16 @@
     // but iterates to an appropriately larger size
     logMemStats("before.kron.1");
-    psphotKronIterate(config, view, STACK_SRC, 1);
+    psphotKronIterate(config, view, STACK_RAW, 1);
     logMemStats("after.kron.1");
 	
     // identify CRs and extended sources
-    psphotSourceSize (config, view, STACK_SRC, true);
+    psphotSourceSize (config, view, STACK_RAW, true);
 
     // non-linear PSF and EXT fit to brighter sources
     // replace model flux, adjust mask as needed, fit, subtract the models (full stamp)
-    psphotBlendFit (config, view, STACK_SRC); // pass 1 (detections->allSources)
+    psphotBlendFit (config, view, STACK_RAW); // pass 1 (detections->allSources)
 
     // replace all sources (do NOT ignore subtraction state)
-    psphotReplaceAllSources (config, view, STACK_SRC, false); // pass 1 (detections->allSources)
+    psphotReplaceAllSources (config, view, STACK_RAW, false); // pass 1 (detections->allSources)
 
     logMemStats("pass1");
@@ -245,6 +226,6 @@
     // linear fit to include all sources (subtract again)
     // NOTE : apply to ALL sources (extended + psf)
-    // NOTE 2 : this function subtracts the models from the given filerule (SRC), not DET
-    psphotFitSourcesLinear (config, view, STACK_SRC, true, false); // pass 2 (detections->allSources)
+    // NOTE 2 : this function subtracts the models from the given filerule
+    psphotFitSourcesLinear (config, view, STACK_RAW, true, false); // pass 2 (detections->allSources)
 
     // NOTE: possibly re-measure background model here with objects subtracted / or masked
@@ -252,22 +233,10 @@
     // NOTE: this block performs the 2nd pass low-significance PSF detection stage
     { 
-	// if DET and SRC are different images, generate children sources for all sources in
-	// the SRC image.  This operation replaces the existing DETECTION container on DET
-	// which is currently a view to the one on SRC).  children sources go to
-	// det->allSources
-	if (strcmp(STACK_SRC, STACK_DET)) {
-	    psphotSourceChildren (config, view, STACK_DET, STACK_SRC); 
-
-	    //  subtract all sources from DET (this will subtract using the psf model for SRC, which
-	    //  will somewhat oversubtract the sources -- this is OK
-	    psphotRemoveAllSources (config, view, STACK_DET, false); // do not ignore subtraction state for sources
-	}
-
 	// add noise for subtracted objects
-	psphotAddNoise (config, view, STACK_DET); // pass 1 (detections->allSources)
+	psphotAddNoise (config, view, STACK_RAW); // pass 1 (detections->allSources)
 
 	// find fainter sources
 	// NOTE: finds new peaks and new footprints, OLD and FULL set are saved on detections
-	psphotFindDetections (config, view, STACK_DET, false); // pass 2 (detections->peaks, detections->footprints)
+	psphotFindDetections (config, view, STACK_RAW, false); // pass 2 (detections->peaks, detections->footprints)
 
 	// remove noise for subtracted objects (ie, return to normal noise level)
@@ -276,43 +245,30 @@
         bool footprintsUseUnsubtracted = psMetadataLookupBool(NULL, recipe, "FOOTPRINT_USE_UNSUBTRACTED");
         if (!footprintsUseUnsubtracted) {
-    	    psphotSubNoise (config, view, STACK_DET); // pass 1 (detections->allSources)
+    	    psphotSubNoise (config, view, STACK_RAW); // pass 1 (detections->allSources)
         }
-
-	// if DET and SRC are different images, copy the detections from DET to SRC 
-	// (this operation just ensures the metadata container has a view on SRC as well
-	if (strcmp(STACK_SRC, STACK_DET)) {
-	    // replace all sources in DET
-	    psphotReplaceAllSources (config, view, STACK_DET, false); // ignore subtraction state for sources
-
-	    // copy the newly detected peaks from DET to SRC so SourceStats below can operate on them
-	    if (!psphotCopyPeaks (config, view, STACK_SRC, STACK_DET)) {
-		psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis");
-		return psphotReadoutCleanup (config, view, STACK_SRC);
-	    }
-	}
 
 	// define new sources based on only the new peaks & measure moments
 	// NOTE: new sources are saved on detections->newSources
-	psphotSourceStats (config, view, STACK_SRC, false); // pass 2 (detections->newSources)
+	psphotSourceStats (config, view, STACK_RAW, false); // pass 2 (detections->newSources)
 
 	// set source type
 	// NOTE: apply only to detections->newSources
-	if (!psphotRoughClass (config, view, STACK_SRC)) { // pass 2 (detections->newSources)
+	if (!psphotRoughClass (config, view, STACK_RAW)) { // pass 2 (detections->newSources)
 	    psLogMsg ("psphot", 3, "failed to find a valid PSF clump for image");
-	    return psphotReadoutCleanup (config, view, STACK_SRC);
+	    return psphotReadoutCleanup (config, view, STACK_RAW);
 	}
 
 	// replace all sources so fit below applies to all at once
 	// NOTE: apply only to OLD sources (which have been subtracted)
-	psphotReplaceAllSources (config, view, STACK_SRC, false); // pass 2
+	psphotReplaceAllSources (config, view, STACK_RAW, false); // pass 2
 
 	// merge the newly selected sources into the existing list
 	// NOTE: merge OLD and NEW
 	// XXX check on free of sources...
-	psphotMergeSources (config, view, STACK_SRC); // (detections->newSources + detections->allSources -> detections->allSources)
+	psphotMergeSources (config, view, STACK_RAW); // (detections->newSources + detections->allSources -> detections->allSources)
 
 	// Construct an initial model for each object, set the radius to fitRadius, set circular
 	// fit mask.  NOTE: only applied to sources without guess models
-	psphotGuessModels (config, view, STACK_SRC);
+	psphotGuessModels (config, view, STACK_RAW);
     }
 
@@ -325,7 +281,7 @@
     if (splitLinearFit) {
         psLogMsg ("psphot", 3, "splitting fit of detected and matched soures\n");
-        // Fit the detected sources separately from matched that wea are about to create.
+        // Fit the detected sources separately from matched ones that we are about to create.
         // NOTE: apply to ALL sources but only include sources with postitive flux in the fit
-        psphotFitSourcesLinear (config, view, STACK_SRC, true, true); // pass 3 (detections->allSources)
+        psphotFitSourcesLinear (config, view, STACK_RAW, true, true); // pass 3 (detections->allSources)
     }
 
@@ -335,5 +291,5 @@
     // this just match the detections for the chisq image, and not bother measuring the source
     // stats in that case...?
-    objects = psphotMatchSources (config, view, STACK_SRC);
+    objects = psphotMatchSources (config, view, STACK_RAW);
     psMemDump("matchsources");
 
@@ -344,26 +300,26 @@
     // Construct an initial model for each object, set the radius to fitRadius, set circular
     // fit mask.  NOTE: only applied to sources without guess models
-    psphotGuessModels (config, view, STACK_SRC);
+    psphotGuessModels (config, view, STACK_RAW);
 
     psphotStackObjectsUnifyPosition (objects);
 
-    psphotStackObjectsSelectForAnalysis (config, view, STACK_SRC, objects);
+    // psphotStackObjectsSelectForAnalysis (config, view, STACK_RAW, objects);
 
     // final linear fit. NOTE: if splitLinearFit is true above, this pass will only fit
     // the unsubtracted (matched) sources (the sources that we fit above are subtracted)
-    psphotFitSourcesLinear (config, view, STACK_SRC, true, false); // pass 4 (detections->allSources)
+    psphotFitSourcesLinear (config, view, STACK_RAW, true, false); // pass 4 (detections->allSources)
 
     // measure the radial profiles to the sky (only measures new objects)
-    psphotRadialProfileWings (config, view, STACK_SRC);
+    psphotRadialProfileWings (config, view, STACK_RAW);
 
     // re-measure the kron mags with models subtracted
     // psphotKronMasked(config, view, STACK_SRC);
     logMemStats("before.kron.2");
-    psphotKronIterate(config, view, STACK_SRC, 2);
+    psphotKronIterate(config, view, STACK_RAW, 2);
     logMemStats("after.kron.2");
 
     // measure source size for the remaining sources
     // NOTE: applies only to NEW (unmeasured) sources
-    psphotSourceSize (config, view, STACK_SRC, false); // pass 2 (detections->allSources)
+    psphotSourceSize (config, view, STACK_RAW, false); // pass 2 (detections->allSources)
 
     psMemDump("psfstats");
@@ -371,22 +327,30 @@
     // drop matched sources without any useful measurements and set kron radii for the ones
     // we decide to keep
-    psphotFilterMatchedSources (config, view, STACK_SRC, objects);
+    psphotFilterMatchedSources (config, view, STACK_RAW, objects);
 
     // measure kron fluxes for the matched sources only
-    psphotKronIterate(config, view, STACK_SRC, 3);
+    psphotKronIterate(config, view, STACK_RAW, 3);
+
+    // decide which source(s) are to be fitted with the extended source analysis code.
+    psphotChooseAnalysisOptionsByObject (config, view, STACK_RAW, objects);
 
     // measure elliptical apertures, petrosians (objects sorted by S/N)
     // psphotExtendedSourceAnalysisByObject (config, objects, view, STACK_SRC); // pass 1 (detections->allSources)
-    psphotExtendedSourceAnalysis (config, view, STACK_SRC); // pass 1 (detections->allSources)
+    psphotExtendedSourceAnalysis (config, view, STACK_RAW); // pass 1 (detections->allSources)
 
     // measure non-linear extended source models (exponential, deVaucouleur, Sersic) (sources sorted by S/N)
-    psphotExtendedSourceFits (config, view, STACK_SRC); // pass 1 (detections->allSources)
+    psphotExtendedSourceFits (config, view, STACK_RAW); // pass 1 (detections->allSources)
 
     // create source children for the OUT filerule (for radial aperture photometry and output) 
-    psArray *objectsOut = psphotSourceChildrenByObject (config, view, STACK_OUT, objects);
+    // NOTE: The new source children have image arrays pointing to the readout associated with 
+    // STACK_OUT.  in psphotStackMatchPSFsetup, we copy the current pixel values from RAW to OUT, 
+    // but keep the pointers the same so we do not break these source image references
+    // XXX NOTE : if we use the pre-20130914 psphotStackReadout code, we need to use 'false' for the
+    // sourcesSubtracted argument
+    psArray *objectsOut = psphotSourceChildrenByObject (config, view, STACK_OUT, objects, true);
     if (!objectsOut) {
 	psFree(objects);
 	psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis");
-	return psphotReadoutCleanup (config, view, STACK_SRC);
+	return psphotReadoutCleanup (config, view, STACK_RAW);
     }
 
@@ -396,98 +360,91 @@
         // this forces photometry on the undetected sources from other images
 
-        // NOTE: we always do the radial apertures analysis on the convolved image since
-        // those are the ones that are psf matched and are the source of STACK_OUT's pixels
-        // XXX: Actually if PSPHOT.STACK.MATCH.PSF.SOURCE were set to RAW this wouldn't be true.
-        // but in that case we don't get past the psf matching step because there is no
-        // target psf for the RAW inputs
-
-        // If useRaw copy the sources to the convolved readout
-        if (strcmp(STACK_SRC, STACK_CNV)) {
-            if (!psphotCopySources (config, view, STACK_CNV, STACK_SRC)) {
-                psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis");
-                return psphotReadoutCleanup (config, view, STACK_SRC);
-            }
-        }
-        // mark any inputs that we want to skip the matched apertures for
-        psphotStackSetInputsToSkip(config, view, STACK_CNV, true);
-        psphotStackSetInputsToSkip(config, view, STACK_OUT, true);
-        psphotRadialApertures (config, view, STACK_CNV, 0); // entry 0 == unmatched
-        psMemDump("extmeas");
-
+	// set up the FWHM vector
+	psphotStackMatchPSFsetup (config, view, STACK_OUT, STACK_RAW);
+	psphotDumpImages (config, view, STACK_RAW, "raw.t0");
+	psphotDumpImages (config, view, STACK_OUT, "out.t0");
 
         int nRadialEntries = psphotStackMatchPSFsEntries(config, view, STACK_OUT);
-        for (int entry = 1; entry < nRadialEntries; entry++) {
+
+        for (int entry = 0; entry < nRadialEntries; entry++) {
             // NOTE: entry 0 is the unmatched image set
 
-            // re-measure the PSF for the smoothed image (using entries in 'allSources')
-            psphotChoosePSF (config, view, STACK_OUT, false);
-
-            // this is necessary to update the models based on the new PSF
-            psphotResetModels (config, view, STACK_OUT);
-
-            // this is necessary to get the right normalization for the new models
-            psphotFitSourcesLinear (config, view, STACK_OUT, false, false);
+	    char line[256];
 
             // measure circular, radial apertures (objects sorted by S/N)
             psphotRadialApertures (config, view, STACK_OUT, entry); 
+	    snprintf (line, 256, "%s.%d", "out.t1", entry);
+	    psphotDumpImages (config, view, STACK_OUT, line);
 
             // replace the flux in the image so it is returned to its original state
             psphotReplaceAllSources (config, view, STACK_OUT, false);
-
-            // smooth to the next FWHM, or set 'smoothAgain' to false if no more 
-            psphotStackMatchPSFsNext(config, view, STACK_OUT, entry);
-            psMemDump("matched");
+	    snprintf (line, 256, "%s.%d", "out.t2", entry);
+	    psphotDumpImages (config, view, STACK_OUT, line);
+
+	    if (entry < nRadialEntries - 1) {
+		// smooth to the next FWHM
+		// this function does nothing if the targetFWHM is smaller than the currentFWHM
+		psphotStackMatchPSFsNext(config, view, STACK_OUT, entry);
+		snprintf (line, 256, "%s.%d", "out.t3", entry);
+		psphotDumpImages (config, view, STACK_OUT, line);
+		psMemDump("matched");
+
+		// re-measure the PSF for the smoothed image (using entries in 'allSources')
+		if (!psphotChoosePSF (config, view, STACK_OUT, false)) {
+                    psLogMsg ("psphot", 3, "failure to construct a psf model in radial aperture loop for entry :%d", entry);
+                    return psphotReadoutCleanup (config, view, STACK_RAW);
+                }
+
+		// this is necessary to update the models based on the new PSF
+		psphotResetModels (config, view, STACK_OUT);
+
+		// this is necessary to get the right normalization for the new models
+		// and to subtract the sources
+		psphotFitSourcesLinear (config, view, STACK_OUT, false, false);
+		snprintf (line, 256, "%s.%d", "out.t4", entry);
+		psphotDumpImages (config, view, STACK_OUT, line);
+	    }
         }
     }
-    psphotStackSetInputsToSkip(config, view, STACK_CNV, false);
-    psphotStackSetInputsToSkip(config, view, STACK_OUT, false);
 
     // measure aperture photometry corrections
-    if (!psphotApResid (config, view, STACK_SRC)) {
+    if (!psphotApResid (config, view, STACK_RAW)) {
 	psFree (objects);
 	psFree (objectsOut);
         psLogMsg ("psphot", 3, "failed on psphotApResid");
-	return psphotReadoutCleanup (config, view, STACK_SRC);
+	return psphotReadoutCleanup (config, view, STACK_RAW);
     }
 
     // calculate source magnitudes
-    psphotMagnitudes(config, view, STACK_SRC);
-
-    if (!useRaw) {
-        // psphotEfficiency wants to have the PSF of the image, but since we are measuring on
-        // the convolved images we need to generate PSFs for the DET images
-        if (!psphotChoosePSF (config, view, STACK_DET, false)) {
-            psLogMsg ("psphot", 3, "failure to construct a psf model for raw input");
-            return psphotReadoutCleanup (config, view, STACK_DET);
-        }
-    }
-    if (!psphotEfficiency(config, view, STACK_DET)) {
+    psphotMagnitudes(config, view, STACK_RAW);
+
+    // calculate lensing parameters
+    if (!psphotLensing(config, view, STACK_RAW)) {
+	psErrorStackPrint(stderr, "Unable to do lensing parameters.");
+        psErrorClear();
+    }
+
+    if (!psphotEfficiency(config, view, STACK_RAW)) {
         psErrorStackPrint(stderr, "Unable to determine detection efficiencies from fake sources");
         psErrorClear();
     }
-    psphotCopyEfficiency (config, view, STACK_OUT, STACK_DET);
+    psphotCopyEfficiency (config, view, STACK_OUT, STACK_RAW);
 
     logMemStats("final");
 #if (1)
-    psphotSourceMemory(config, view, STACK_SRC);
+    psphotSourceMemory(config, view, STACK_RAW);
     psphotSourceMemory(config, view, STACK_OUT);
 #endif
 
-    // replace failed sources?
-    // psphotReplaceUnfitSources (sources);
-
     // replace background in residual image
-    psphotSkyReplace (config, view, STACK_DET);
+    psphotSkyReplace (config, view, STACK_RAW);
 
     // drop the references to the image pixels held by each source
+    psphotSourceFreePixels (config, view, STACK_RAW);
     psphotSourceFreePixels (config, view, STACK_OUT);
-    psphotSourceFreePixels (config, view, STACK_SRC);
 
 #ifdef MAKE_CHISQ_IMAGE
     // remove chisq image from config->file:PSPHOT.INPUT
-    psphotStackRemoveChisqFromInputs(config, STACK_DET);
-    if (strcmp(STACK_SRC, STACK_DET)) {
-	psphotStackRemoveChisqFromInputs(config, STACK_SRC);
-    }
+    psphotStackRemoveChisqFromInputs(config, STACK_RAW);
 #endif
 
@@ -496,5 +453,5 @@
 
     // create the exported-metadata and free local data
-    return psphotReadoutCleanup (config, view, STACK_SRC);
+    return psphotReadoutCleanup (config, view, STACK_RAW);
 }
 
@@ -552,11 +509,8 @@
 }
 
-
-
 /* here is the process:
 
- * we have three(*) images:
- * RAW : unconvolved image stack 
- * CNV : input convolved image
+ * we have two image sets:
+ * RAW : unconvolved image stacks
 
  * OUT : psf-matched output image (there may be more than one of
@@ -649,2 +603,124 @@
 
    */
+
+
+// generate a vector fwhmValues where the first has the fwhm of the raw image and the
+// successive entries have the target values
+
+bool psphotStackMatchPSFsetup (pmConfig *config, const pmFPAview *view, const char *filerule, const char *filerulePSF) {
+
+    bool status;
+
+    int num = psphotFileruleCount(config, filerule);
+
+    // skip the chisq image (optionally?)
+    int chisqNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.CHISQ.NUM");
+    if (!status) chisqNum = -1;
+
+    // loop over the available readouts
+    for (int i = 0; i < num; i++) {
+        if (i == chisqNum) continue; // skip chisq image
+
+	if (!psphotStackMatchPSFsetupReadout (config, view, filerule, filerulePSF, i)) {
+            psError (PSPHOT_ERR_CONFIG, false, "failed to define target PSF sizes");
+	    return false;
+	}
+    }
+
+    return true;
+}
+
+float psphotPSFseeing (pmPSF *psf, pmReadout *readout, int index);
+
+// copy the pixels from RAW to OUT (
+
+bool psphotStackMatchPSFsetupReadout (pmConfig *config, const pmFPAview *view, const char *fileruleOut, const char *fileruleRaw, int index) {
+
+    bool status;
+
+    // select the appropriate recipe information
+    psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE);
+
+    // find the currently selected readout
+    pmFPAfile *fileOut = pmFPAfileSelectSingle(config->files, fileruleOut, index); // File of interest
+    psAssert (fileOut, "missing file?");
+
+    pmReadout *readoutOut = pmFPAviewThisReadout(view, fileOut->fpa);
+    psAssert (readoutOut, "missing readout?");
+
+    // find the currently selected readout
+    pmFPAfile *fileRaw = pmFPAfileSelectSingle(config->files, fileruleRaw, index); // File of interest
+    psAssert (fileRaw, "missing file?");
+
+    pmReadout *readoutRaw = pmFPAviewThisReadout(view, fileRaw->fpa);
+    psAssert (readoutRaw, "missing readout?");
+
+    readoutOut->image = psImageCopy(readoutOut->image, readoutRaw->image, PS_TYPE_F32);
+    if (readoutRaw->variance) {
+	readoutOut->variance = psImageCopy(readoutOut->variance, readoutRaw->variance, PS_TYPE_F32);
+    }
+    if (readoutRaw->mask) {
+	readoutOut->mask = psImageCopy(readoutOut->mask, readoutRaw->mask, PS_TYPE_IMAGE_MASK);
+    }
+
+    // pmChip *chipRaw = pmFPAviewThisChip(view, fileRaw->fpa); // The chip holds the PSF
+    // psAssert (chipRaw, "missing chip");
+
+    pmPSF *psf = psMetadataLookupPtr(&status, readoutRaw->analysis, "PSPHOT.PSF"); // PSF
+    if (!psf) {
+	// we should have a PSF by this point in psphot
+	psError(PSPHOT_ERR_PROG, true, "Unable to find PSF.");
+	return false;
+    }
+
+    float fwhmRaw = psphotPSFseeing (psf, readoutRaw, index);
+
+    psVector *fwhmValues = psVectorAllocEmpty(10, PS_TYPE_F32);
+    psVectorAppend(fwhmValues, fwhmRaw);
+
+    // is a single target FWHM specified, or a set of values?  set up the vector options->targetSeeing and the local 1st value
+    float targetSeeing = psMetadataLookupF32 (&status, recipe, "PSPHOT.STACK.TARGET.PSF.FWHM");
+    if (!status) {
+	psVector *targetSeeing = psMetadataLookupVector(&status, recipe, "PSPHOT.STACK.TARGET.PSF.FWHM"); // Magnitude offsets
+	psAssert (status, "missing psphot recipe value PSPHOT.STACK.TARGET.PSF.FWHM");
+	for (int i = 0; i < targetSeeing->n; i++) {
+	    psVectorAppend(fwhmValues, targetSeeing->data.F32[i]);
+	}	    
+    } else {
+        psVectorAppend(fwhmValues, targetSeeing);
+    }
+
+    psMetadataAddVector(readoutOut->analysis, PS_LIST_TAIL, "STACK.PSF.FWHM.VALUES", PS_META_REPLACE, "PSF sizes", fwhmValues);
+    psFree (fwhmValues);
+
+    return true;
+}
+
+float psphotPSFseeing (pmPSF *psf, pmReadout *readout, int index) {
+
+    psImage *image = readout->image;
+
+    int Nx = image->numCols;
+    int Ny = image->numRows;
+
+    float sumFWHM = 0.0;		  // FWHM for image
+    int numFWHM = 0;			  // Number of FWHM measurements
+    for (float x = 0; x < Nx; x += 0.25*Nx) {
+	for (float y = 0; y < Ny; y += 0.25*Ny) {
+	    float fwhm = pmPSFtoFWHM(psf, x, y);
+	    if (isfinite(fwhm)) {
+		sumFWHM += fwhm;
+		numFWHM++;
+	    }
+	}
+    }
+    if (numFWHM == 0) {
+	psLogMsg("ppStack", PS_LOG_INFO, "Unable to measure PSF FWHM for image %d --- rejected.", index);
+	return NAN;
+    } 
+
+    float fwhm = sumFWHM / (float) numFWHM;
+    psLogMsg ("psphotStack", PS_LOG_INFO, "Input Seeing for %d: %f\n", index, fwhm);
+
+    return fwhm;
+}
Index: /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotVisual.c
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotVisual.c	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/src/psphotVisual.c	(revision 37066)
@@ -1444,14 +1444,14 @@
 	    coord->data.F32[1] = r;
 	    coord->data.F32[0] = 0.0;
-	    fmaj->data.F32[i] = log10(source->modelPSF->modelFunc (NULL, params, coord));
+	    fmaj->data.F32[i] = log10(source->modelPSF->class->modelFunc (NULL, params, coord));
 
 	    coord->data.F32[0] = r;
 	    coord->data.F32[1] = 0.0;
-	    fmin->data.F32[i] = log10(source->modelPSF->modelFunc (NULL, params, coord));
+	    fmin->data.F32[i] = log10(source->modelPSF->class->modelFunc (NULL, params, coord));
 	}
 	psFree (coord);
 	psFree (params);
 
-	float FWHM_MAJOR = 2.0*source->modelPSF->modelRadius (source->modelPSF->params, 0.5*source->modelPSF->params->data.F32[PM_PAR_I0]);
+	float FWHM_MAJOR = 2.0*source->modelPSF->class->modelRadius (source->modelPSF->params, 0.5*source->modelPSF->params->data.F32[PM_PAR_I0]);
 	float FWHM_MINOR = FWHM_MAJOR * (axes.minor / axes.major);
 	if (FWHM_MAJOR < FWHM_MINOR) PS_SWAP (FWHM_MAJOR, FWHM_MINOR); 
Index: /branches/eam_branches/ipp-ops-20130712/psphot/test/tap_psphot_galaxies.pro
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/test/tap_psphot_galaxies.pro	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/test/tap_psphot_galaxies.pro	(revision 37066)
@@ -32,4 +32,5 @@
 $FakeOptions = $BaseOptions
 $FakeOptions = $FakeOptions -exptime 30.0
+# $FakeOptions = $FakeOptions -D PSF.MODEL PS_MODEL_PS1_V1
 $FakeOptions = $FakeOptions -D PSF.MODEL PS_MODEL_GAUSS
   
@@ -44,27 +45,56 @@
 
 # basic config for ppSim with randomly distributed stars and gridded galaxies
-$FakeConfig = -camera SIMTEST
-$FakeConfig = $FakeConfig -recipe PPSIM STACKTEST.RUN
-$FakeConfig = $FakeConfig -D PSASTRO:PSASTRO.CATDIR catdir.ref
-$FakeConfig = $FakeConfig -Db STARS.FAKE F                         ; # only use stars from catdir.ref
-$FakeConfig = $FakeConfig -Db MATCH.DENSITY F
-$FakeConfig = $FakeConfig -Db PSF.CONVOLVE T
-$FakeConfig = $FakeConfig -Db GALAXY.FAKE T                        ; # generate a "realistic" distribution of galaxies
-$FakeConfig = $FakeConfig -Df GALAXY.MAG 17.0
-$FakeConfig = $FakeConfig -Db GALAXY.GRID T                        ; # generate a grid of galaxies (constant mag)
-#$FakeConfig = $FakeConfig -D GALAXY.MODEL PS_MODEL_GAUSS
-#$FakeConfig = $FakeConfig -D GALAXY.MODEL PS_MODEL_EXP
-#$FakeConfig = $FakeConfig -D GALAXY.MODEL PS_MODEL_SERSIC
-#$FakeConfig = $FakeConfig -D GALAXY.MODEL PS_MODEL_DEV
-$FakeConfig = $FakeConfig -Df GALAXY.RMAJOR.MIN 10.0
-$FakeConfig = $FakeConfig -Df GALAXY.RMAJOR.MAX 10.0
-$FakeConfig = $FakeConfig -Df GALAXY.ARATIO.MIN 0.25
-$FakeConfig = $FakeConfig -Df GALAXY.ARATIO.MAX 0.25
-$FakeConfig = $FakeConfig -Df GALAXY.THETA.MIN 0 
-$FakeConfig = $FakeConfig -Df GALAXY.THETA.MAX 180
-$FakeConfig = $FakeConfig -Df GALAXY.INDEX.MIN 1.66
-$FakeConfig = $FakeConfig -Df GALAXY.INDEX.MAX 1.66
-$FakeConfig = $FakeConfig -Di GALAXY.GRID.DX 120
-$FakeConfig = $FakeConfig -Di GALAXY.GRID.DY 120
+if (1)
+  $FakeConfig = -camera SIMTEST
+  $FakeConfig = $FakeConfig -recipe PPSIM STACKTEST.RUN
+  $FakeConfig = $FakeConfig -D PSASTRO:PSASTRO.CATDIR catdir.ref
+  $FakeConfig = $FakeConfig -Db STARS.FAKE F                         ; # only use stars from catdir.ref
+  $FakeConfig = $FakeConfig -Db MATCH.DENSITY F
+  $FakeConfig = $FakeConfig -Db PSF.CONVOLVE T
+  $FakeConfig = $FakeConfig -Db GALAXY.FAKE T                        ; # generate a "realistic" distribution of galaxies
+  $FakeConfig = $FakeConfig -Df GALAXY.MAG 17.0
+  $FakeConfig = $FakeConfig -Db GALAXY.GRID F                        ; # generate a grid of galaxies (constant mag)
+  #$FakeConfig = $FakeConfig -D GALAXY.MODEL PS_MODEL_GAUSS
+  #$FakeConfig = $FakeConfig -D GALAXY.MODEL PS_MODEL_EXP
+  #$FakeConfig = $FakeConfig -D GALAXY.MODEL PS_MODEL_SERSIC
+  #$FakeConfig = $FakeConfig -D GALAXY.MODEL PS_MODEL_DEV
+  $FakeConfig = $FakeConfig -Df GALAXY.RMAJOR.MIN 10.0
+  $FakeConfig = $FakeConfig -Df GALAXY.RMAJOR.MAX  1.0
+  $FakeConfig = $FakeConfig -Df GALAXY.ARATIO.MIN 0.25
+  $FakeConfig = $FakeConfig -Df GALAXY.ARATIO.MAX 1.00
+  $FakeConfig = $FakeConfig -Df GALAXY.THETA.MIN 0 
+  $FakeConfig = $FakeConfig -Df GALAXY.THETA.MAX 180
+  $FakeConfig = $FakeConfig -Df GALAXY.INDEX.MIN 1.66
+  $FakeConfig = $FakeConfig -Df GALAXY.INDEX.MAX 1.66
+  $FakeConfig = $FakeConfig -Di GALAXY.GRID.DX 120
+  $FakeConfig = $FakeConfig -Di GALAXY.GRID.DY 120
+end
+
+# basic config for ppSim with randomly distributed stars and gridded galaxies
+if (0) 
+  $FakeConfig = -camera SIMTEST
+  $FakeConfig = $FakeConfig -recipe PPSIM STACKTEST.RUN
+  $FakeConfig = $FakeConfig -D PSASTRO:PSASTRO.CATDIR catdir.ref
+  $FakeConfig = $FakeConfig -Db STARS.FAKE F                         ; # only use stars from catdir.ref
+  $FakeConfig = $FakeConfig -Db MATCH.DENSITY F
+  $FakeConfig = $FakeConfig -Db PSF.CONVOLVE T
+  $FakeConfig = $FakeConfig -Db GALAXY.FAKE T                        ; # generate a "realistic" distribution of galaxies
+  $FakeConfig = $FakeConfig -Df GALAXY.MAG 17.0
+  $FakeConfig = $FakeConfig -Db GALAXY.GRID T                        ; # generate a grid of galaxies (constant mag)
+  #$FakeConfig = $FakeConfig -D GALAXY.MODEL PS_MODEL_GAUSS
+  #$FakeConfig = $FakeConfig -D GALAXY.MODEL PS_MODEL_EXP
+  #$FakeConfig = $FakeConfig -D GALAXY.MODEL PS_MODEL_SERSIC
+  #$FakeConfig = $FakeConfig -D GALAXY.MODEL PS_MODEL_DEV
+  $FakeConfig = $FakeConfig -Df GALAXY.RMAJOR.MIN 10.0
+  $FakeConfig = $FakeConfig -Df GALAXY.RMAJOR.MAX 10.0
+  $FakeConfig = $FakeConfig -Df GALAXY.ARATIO.MIN 0.25
+  $FakeConfig = $FakeConfig -Df GALAXY.ARATIO.MAX 0.25
+  $FakeConfig = $FakeConfig -Df GALAXY.THETA.MIN 0 
+  $FakeConfig = $FakeConfig -Df GALAXY.THETA.MAX 180
+  $FakeConfig = $FakeConfig -Df GALAXY.INDEX.MIN 1.66
+  $FakeConfig = $FakeConfig -Df GALAXY.INDEX.MAX 1.66
+  $FakeConfig = $FakeConfig -Di GALAXY.GRID.DX 120
+  $FakeConfig = $FakeConfig -Di GALAXY.GRID.DY 120
+end
 
 list fwhm 
@@ -164,5 +194,10 @@
   $psphotConfig = $psphotConfig -Di PSPHOT:LMM_FIT_GAIN_FACTOR_MODE 2
   $psphotConfig = $psphotConfig -Db PSPHOT:SAVE.RESID T
+  $psphotConfig = $psphotConfig -D  PSPHOT:PSF_MODEL PS_MODEL_PS1_V1
+  # $psphotConfig = $psphotConfig -D  PSPHOT:PSF_MODEL PS_MODEL_GAUSS
   $psphotConfig = $psphotConfig -D  PSPHOT:EXTENDED_SOURCE_MODELS_SELECTION $fitModel
+  # $psphotConfig = $psphotConfig -D  PSPHOT:OUTPUT.FORMAT PS1_V5
+  $psphotConfig = $psphotConfig -D  PSPHOT:OUTPUT.FORMAT PS1_SV3
+  $psphotConfig = $psphotConfig -Db PSPHOT:LENSING_PARAMETERS T
 
   # ppImage / psphot on the output
@@ -217,4 +252,16 @@
 
   # plot (input - output) vs mag
+end
+
+macro ck.poserrors
+  reindex X_raw_m = X_raw using index2
+  reindex X_out_m = X_PSF_out using index1
+  reindex dX_out_m = X_PSF_SIG_out using index1
+  set Xoff = X_raw_m - X_out_m
+  reindex M_raw_m = PSF_INST_MAG_raw using index2
+
+  # lim M_raw_m Xoff; clear; box; plot M_raw_m Xoff
+  set dC = Xoff^2 / dX_out_m^2
+  lim M_raw_m dX_out_m; clear; box; plot M_raw_m dX_out_m
 end
 
Index: /branches/eam_branches/ipp-ops-20130712/psphot/test/tap_psphot_galaxygrid.pro
===================================================================
--- /branches/eam_branches/ipp-ops-20130712/psphot/test/tap_psphot_galaxygrid.pro	(revision 37065)
+++ /branches/eam_branches/ipp-ops-20130712/psphot/test/tap_psphot_galaxygrid.pro	(revision 37066)
@@ -28,9 +28,17 @@
 $RefOptions = $RefOptions -Df STARS.DENSITY 10.0
 $RefOptions = $RefOptions -Df STARS.SIGMA.LIM 0.5
-
+$RefOptions = $RefOptions -nx 3000 -ny 3000
+
+if (not($?PSFMODEL))
+  $PSFMODEL = PS1_V1
+end
+
+macro reset.options
 # options for the simulated images (using the refimage for the stars)
 $FakeOptions = $BaseOptions
 $FakeOptions = $FakeOptions -exptime 30.0
-$FakeOptions = $FakeOptions -D PSF.MODEL PS_MODEL_GAUSS
+# $FakeOptions = $FakeOptions -D PSF.MODEL PS_MODEL_GAUSS
+$FakeOptions = $FakeOptions -D PSF.MODEL PS_MODEL_$PSFMODEL
+$FakeOptions = $FakeOptions -nx 3000 -ny 3000
   
 # sample alternate options:
@@ -65,6 +73,9 @@
 $FakeConfig = $FakeConfig -Df GALAXY.INDEX.MIN 1.66
 $FakeConfig = $FakeConfig -Df GALAXY.INDEX.MAX 1.66
-$FakeConfig = $FakeConfig -Di GALAXY.GRID.DX 120
-$FakeConfig = $FakeConfig -Di GALAXY.GRID.DY 120
+$FakeConfig = $FakeConfig -Di GALAXY.GRID.DX 300
+$FakeConfig = $FakeConfig -Di GALAXY.GRID.DY 300
+end
+
+if (not($?FakeConfig)) reset.options
 
 list fwhm 
@@ -75,5 +86,20 @@
 end
 
-macro go.grid.set.devexp
+if (not($?CONVOLVE_NSIGMA)) set CONVOLVE_NSIGMA = 5.0
+
+# generate fake images and run psphot on them
+macro mkexp.devexp.single
+  if ($0 != 5)
+    echo "USAGE: mkexp.devexp.single (basename) (type) (Rmajor) (fwhm)"  
+    break
+  end
+
+  $basename = $1
+  $type = $2
+  $Rmajor = $3
+  $fwhm = $4
+
+  $Aratio = 1.0
+
   $FakeConfig = -camera SIMTEST
   $FakeConfig = $FakeConfig -recipe PPSIM STACKTEST.RUN
@@ -84,11 +110,43 @@
   $FakeConfig = $FakeConfig -Db GALAXY.FAKE T                        ; # generate a "realistic" distribution of galaxies
   $FakeConfig = $FakeConfig -Df GALAXY.MAG 17.0
+  $FakeConfig = $FakeConfig -Df GALAXY.GRID.MAG 14.5
   $FakeConfig = $FakeConfig -Db GALAXY.GRID T                        ; # generate a grid of galaxies (constant mag)
   $FakeConfig = $FakeConfig -Df GALAXY.THETA.MIN 0 
   $FakeConfig = $FakeConfig -Df GALAXY.THETA.MAX 180
-  $FakeConfig = $FakeConfig -Di GALAXY.GRID.DX 120
-  $FakeConfig = $FakeConfig -Di GALAXY.GRID.DY 120
+  $FakeConfig = $FakeConfig -Di GALAXY.GRID.DX 300
+  $FakeConfig = $FakeConfig -Di GALAXY.GRID.DY 300
   $FakeConfig = $FakeConfig -Df GALAXY.INDEX.MIN 1.0
   $FakeConfig = $FakeConfig -Df GALAXY.INDEX.MAX 1.0
+  $FakeConfig = $FakeConfig -Df CONVOLVE.NSIGMA $CONVOLVE_NSIGMA 
+  $BaseConfig = $FakeConfig
+
+  $FakeConfig = $BaseConfig
+  $FakeConfig = $FakeConfig -Df GALAXY.RMAJOR.MIN $Rmajor
+  $FakeConfig = $FakeConfig -Df GALAXY.RMAJOR.MAX $Rmajor
+  $FakeConfig = $FakeConfig -Df GALAXY.ARATIO.MIN $Aratio
+  $FakeConfig = $FakeConfig -Df GALAXY.ARATIO.MAX $Aratio
+	  
+  mkexp $basename $fwhm $type
+end
+
+# generate fake images and run psphot on them
+macro normtest.mkexp.devexp
+  $FakeConfig = -camera SIMTEST
+  $FakeConfig = $FakeConfig -recipe PPSIM STACKTEST.RUN
+  $FakeConfig = $FakeConfig -D PSASTRO:PSASTRO.CATDIR catdir.ref
+  $FakeConfig = $FakeConfig -Db STARS.FAKE F                         ; # only use stars from catdir.ref
+  $FakeConfig = $FakeConfig -Db MATCH.DENSITY F
+  $FakeConfig = $FakeConfig -Db PSF.CONVOLVE T
+  $FakeConfig = $FakeConfig -Db GALAXY.FAKE T                        ; # generate a "realistic" distribution of galaxies
+  $FakeConfig = $FakeConfig -Df GALAXY.MAG 17.0
+  $FakeConfig = $FakeConfig -Df GALAXY.GRID.MAG 14.5
+  $FakeConfig = $FakeConfig -Db GALAXY.GRID T                        ; # generate a grid of galaxies (constant mag)
+  $FakeConfig = $FakeConfig -Df GALAXY.THETA.MIN 0 
+  $FakeConfig = $FakeConfig -Df GALAXY.THETA.MAX 180
+  $FakeConfig = $FakeConfig -Di GALAXY.GRID.DX 300
+  $FakeConfig = $FakeConfig -Di GALAXY.GRID.DY 300
+  $FakeConfig = $FakeConfig -Df GALAXY.INDEX.MIN 1.0
+  $FakeConfig = $FakeConfig -Df GALAXY.INDEX.MAX 1.0
+  $BaseConfig = $FakeConfig
 
   # $FakeConfig = $FakeConfig -D GALAXY.MODEL PS_MODEL_GAUSS
@@ -103,9 +161,12 @@
   # $FakeConfig = $FakeConfig -Df GALAXY.INDEX.MAX 1.66
 
+  mkdir normtest
+
   $Nseq = 0
   foreach type EXP DEV
     foreach Rmajor 3 10 30
       foreach Aratio 0.25 0.5 1.0
-        foreach fwhm 0.8 1.0 1.5
+        foreach fwhm 1.0
+          $FakeConfig = $BaseConfig
           $FakeConfig = $FakeConfig -Df GALAXY.RMAJOR.MIN $Rmajor
           $FakeConfig = $FakeConfig -Df GALAXY.RMAJOR.MAX $Rmajor
@@ -113,7 +174,6 @@
           $FakeConfig = $FakeConfig -Df GALAXY.ARATIO.MAX $Aratio
 	  
-          sprint name "sample.%02d" $Nseq
+          sprint name "normtest/test.%02d" $Nseq
           mkexp $name $fwhm $type
-          fitexp $name $name.fit $type\_CONV
 	  $Nseq ++
         end
@@ -123,5 +183,13 @@
 end
 
-macro go.grid.set.sersic
+# generate fake images and run psphot on them
+macro grid.mkexp.devexp
+  if ($0 != 2)
+    echo "USAGE: grid.mkexp.devexp (dir)"
+    break
+  end
+
+  mkdir $1
+
   $FakeConfig = -camera SIMTEST
   $FakeConfig = $FakeConfig -recipe PPSIM STACKTEST.RUN
@@ -132,19 +200,205 @@
   $FakeConfig = $FakeConfig -Db GALAXY.FAKE T                        ; # generate a "realistic" distribution of galaxies
   $FakeConfig = $FakeConfig -Df GALAXY.MAG 17.0
+  $FakeConfig = $FakeConfig -Df GALAXY.GRID.MAG 14.5
   $FakeConfig = $FakeConfig -Db GALAXY.GRID T                        ; # generate a grid of galaxies (constant mag)
   $FakeConfig = $FakeConfig -Df GALAXY.THETA.MIN 0 
   $FakeConfig = $FakeConfig -Df GALAXY.THETA.MAX 180
-  $FakeConfig = $FakeConfig -Di GALAXY.GRID.DX 120
-  $FakeConfig = $FakeConfig -Di GALAXY.GRID.DY 120
+  $FakeConfig = $FakeConfig -Di GALAXY.GRID.DX 300
+  $FakeConfig = $FakeConfig -Di GALAXY.GRID.DY 300
+  $FakeConfig = $FakeConfig -Df GALAXY.INDEX.MIN 1.0
+  $FakeConfig = $FakeConfig -Df GALAXY.INDEX.MAX 1.0
+  $BaseConfig = $FakeConfig
+
+  $Nseq = 0
+  foreach type EXP DEV
+    foreach Rmajor 3 10 30
+      foreach Aratio 0.25 0.5 1.0
+        foreach fwhm 0.8 1.0 1.5
+          $FakeConfig = $BaseConfig
+          $FakeConfig = $FakeConfig -Df GALAXY.RMAJOR.MIN $Rmajor
+          $FakeConfig = $FakeConfig -Df GALAXY.RMAJOR.MAX $Rmajor
+          $FakeConfig = $FakeConfig -Df GALAXY.ARATIO.MIN $Aratio
+          $FakeConfig = $FakeConfig -Df GALAXY.ARATIO.MAX $Aratio
+	  
+          sprint name "$1/sample.%02d" $Nseq
+          mkexp $name $fwhm $type
+	  $Nseq ++
+        end
+      end
+    end
+  end
+end
+
+# generate fake images and run psphot on them
+macro grid.fitexp.devexp
+  if ($0 != 3)
+    echo "USAGE: grid.fitexp.devexp (srcdir) (outdir)"
+    break
+  end
+
+   #$Nseq = 0
+   #foreach type EXP DEV
+
+  mkdir $2
+
+  $Nseq = 0
+  foreach type EXP DEV
+    foreach Rmajor 3 10 30
+      foreach Aratio 0.25 0.5 1.0
+        foreach fwhm 0.8 1.0 1.5
+          sprint srcname "$1/sample.%02d" $Nseq
+          sprint outname "$2/sample.%02d.fit" $Nseq
+          fitexp $srcname $outname $type\_CONV
+	  $Nseq ++
+        end
+      end
+    end
+  end
+end
+
+macro grid.load.devexp
+  if ($0 != 3)
+    echo "USAGE: grid.load.devexp (srcdir) (fitdir)"
+    break
+  end
+
+  delete -q Xin_s Yin_s Min_s Tin_s Rin_s rin_s
+  delete -q Xot_s Yot_s Mot_s Tot_s Rot_s rot_s
+  delete -q min_S Min_S
+
+  $Nseq = 0
+  foreach type EXP DEV
+    foreach Rmajor 3 10 30
+      foreach Aratio 0.25 0.5 1.0
+        foreach fwhm 0.8 1.0 1.5
+          sprint name "sample.%02d" $Nseq
+          cmf.load.concat $1/$name.dat $2/$name.fit.cmf $type
+	  $Nseq ++
+        end
+      end
+    end
+  end
+end
+
+macro grid.plots.devexp
+  if ($0 != 2)
+    echo "USAGE: grid.plot.devexp (version)"
+    break
+  end
+  # things to examine: theta, Rmajor, AR
+
+  # go.grid.check.devexp
+
+  # check on theta
+  set dT = Tot_s - Tin_s
+  set ARin = rin_s / Rin_s
+  # lim ARin dT; clear; box; plot ARin dT
+
+  subset dTx = dT if (ARin < 0.95)
+  histogram dTx NdT -8 8 0.1 -range dTi
+  lim -n 0$1 dTi NdT; clear; box; plot -x 1 dTi NdT
+  label -x "angle offset (degrees, only non-circular)" -y "number count"
+  resize 700 320
+
+  # check on Rmajor
+  set dR = Rin_s - Rot_s
+  # lim Rin_s dR; clear; box; plot Rin_s dR
+  # lim Rot_s dR; clear; box; plot Rot_s dR
+  # lim Rin_s dR; clear; box; plot Rin_s dR
+  create n 0 dR[]
+  set dRf = dR / Rin_s
+  lim -n 1$1 n -0.5 0.5; clear; box; plot n dRf
+  label -x sequence -y "1 - R_out| / R_in|"
+  resize 700 320
+
+  # check on A.Ratio
+  set ARot = rot_s / Rot_s
+  # lim ARin ARot; clear; box; plot ARin ARot
+  set fAR = ARot / ARin
+  lim -n 2$1 n 0.5 1.5; clear; box; plot n fAR
+  label -x sequence -y "AR_out| / AR_in|"
+  resize 700 320
+
+  # check on magnitude
+  set dM = Mot_s - Min_s
+  lim -n 3$1 n -0.5 0.5; clear; box; plot n dM    
+  label -x sequence -y "M_out| - M_in|"
+  resize 700 320
+
+  # check on magnitude
+  set dI = Iot_s - Iin_s
+  lim -n 4$1 n -1.0 1.0; clear; box; plot n dI
+  label -x sequence -y "I_out| - I_in|"
+  resize 700 320
+end
+
+macro grid.plot.stars
+  if ($0 != 2)
+    echo "USAGE: grid.plot.stars (version)"
+    break
+  end
+  # things to examine: theta, Rmajor, AR
+
+  # go.grid.check.devexp
+
+  # check on position
+  set dX = Xot_s - int(Xin_s) - 0.5
+  set dY = Yot_s - int(Yin_s) - 0.5
+  set ARin = rin_s / Rin_s
+  set dR = Rin_s - Rot_s
+
+  create n 0 dR[]
+  set dRf = dR / Rin_s
+  lim -n 1$1 n -0.5 0.5; clear; box; plot n dRf
+  label -x sequence -y "1 - R_out| / R_in|"
+  resize 700 320
+
+  # check on A.Ratio
+  set ARot = rot_s / Rot_s
+  # lim ARin ARot; clear; box; plot ARin ARot
+  set fAR = ARot / ARin
+  lim -n 2$1 n 0.5 1.5; clear; box; plot n fAR
+  label -x sequence -y "AR_out| / AR_in|"
+  resize 700 320
+
+  # check on magnitude
+  set dM = Mot_s - Min_s
+  lim -n 3$1 n -0.5 0.5; clear; box; plot n dM    
+  label -x sequence -y "M_out| - M_in|"
+  resize 700 320
+
+  lim -n 4$1 n -1.5 1.5; clear; box; plot n dX
+  label -x sequence -y "X_out| - X_in|"
+  resize 700 320
+
+  lim -n 5$1 n -1.5 1.5; clear; box; plot n dY
+  label -x sequence -y "Y_out| - Y_in|"
+  resize 700 320
+end
+
+macro grid.mkexp.sersic
+  if ($0 != 2)
+    echo "USAGE: grid.mkexp.devexp (dir)"
+    break
+  end
+
+  mkdir $1
+
+  $FakeConfig = -camera SIMTEST
+  $FakeConfig = $FakeConfig -recipe PPSIM STACKTEST.RUN
+  $FakeConfig = $FakeConfig -D PSASTRO:PSASTRO.CATDIR catdir.ref
+  $FakeConfig = $FakeConfig -Db STARS.FAKE F                         ; # only use stars from catdir.ref
+  $FakeConfig = $FakeConfig -Db MATCH.DENSITY F
+  $FakeConfig = $FakeConfig -Db PSF.CONVOLVE T
+  $FakeConfig = $FakeConfig -Db GALAXY.FAKE T                        ; # generate a "realistic" distribution of galaxies
+  $FakeConfig = $FakeConfig -Df GALAXY.MAG 17.0
+  $FakeConfig = $FakeConfig -Df GALAXY.GRID.MAG 14.5
+  $FakeConfig = $FakeConfig -Db GALAXY.GRID T                        ; # generate a grid of galaxies (constant mag)
+  $FakeConfig = $FakeConfig -Df GALAXY.THETA.MIN 0 
+  $FakeConfig = $FakeConfig -Df GALAXY.THETA.MAX 180
+  $FakeConfig = $FakeConfig -Di GALAXY.GRID.DX 300
+  $FakeConfig = $FakeConfig -Di GALAXY.GRID.DY 300
   $FakeConfig = $FakeConfig -D GALAXY.MODEL PS_MODEL_SERSIC
-
-  # $FakeConfig = $FakeConfig -Df GALAXY.INDEX.MIN 1.0
-  # $FakeConfig = $FakeConfig -Df GALAXY.INDEX.MAX 1.0
-  # $FakeConfig = $FakeConfig -Df GALAXY.RMAJOR.MIN 10.0
-  # $FakeConfig = $FakeConfig -Df GALAXY.RMAJOR.MAX 10.0
-  # $FakeConfig = $FakeConfig -Df GALAXY.ARATIO.MIN 0.25
-  # $FakeConfig = $FakeConfig -Df GALAXY.ARATIO.MAX 0.25
-  # $FakeConfig = $FakeConfig -Df GALAXY.INDEX.MIN 1.66
-  # $FakeConfig = $FakeConfig -Df GALAXY.INDEX.MAX 1.66
+  $BaseConfig = $FakeConfig
 
   $Nseq = 0
@@ -153,4 +407,5 @@
       foreach Aratio 0.25 0.5 1.0
         foreach fwhm 0.8 1.0 1.5
+          $FakeConfig = $BaseConfig
           $FakeConfig = $FakeConfig -Df GALAXY.RMAJOR.MIN $Rmajor
           $FakeConfig = $FakeConfig -Df GALAXY.RMAJOR.MAX $Rmajor
@@ -160,7 +415,7 @@
   	  $FakeConfig = $FakeConfig -Df GALAXY.INDEX.MAX $index
 	  
-          sprint name "sersic.%02d" $Nseq
+          sprint name "$1/sersic.%02d" $Nseq
           mkexp $name $fwhm SERSIC
-          fitexp $name $name.fit SER\_CONV
+	  echo "$Nseq : $index $Rmajor $Aratio $fwhm"
 	  $Nseq ++
         end
@@ -170,15 +425,19 @@
 end
 
-macro go.grid.check.devexp
-  delete -q Xin_s Yin_s Min_s Tin_s Rin_s rin_s
-  delete -q Xot_s Yot_s Mot_s Tot_s Rot_s rot_s
+macro grid.fitexp.sersic.devexp
+  if ($0 != 3)
+    echo "USAGE: grid.fitexp.sersic.devexp (srcdir) (outdir)"
+    break
+  end
+
+  mkdir $2
 
   $Nseq = 0
-  foreach type EXP DEV
+  foreach index 1 2 3 4
     foreach Rmajor 3 10 30
       foreach Aratio 0.25 0.5 1.0
         foreach fwhm 0.8 1.0 1.5
-          sprint name "sample.%02d" $Nseq
-          ckgalaxy.load $name.dat $name.fit.cmf
+          sprint name "sersic.%02d" $Nseq
+          fitexp $1/$name $2/$name.fit EXP_CONV,DEV_CONV
 	  $Nseq ++
         end
@@ -188,32 +447,105 @@
 end
 
-macro go
-  mkexp test.exp 1.0 EXP
-  fitexp test.exp test.exp.fit EXP_CONV
-
-  mkexp test.ser 1.0 SERSIC
-  fitexp test.ser test.ser.fit SER_CONV
-
-  mkexp test.dev 1.0 DEV
-  fitexp test.dev test.dev.fit DEV_CONV
-
-  mkexp test.gau 1.0 GAUSS
-  fitexp test.gau test.gau.fit GAU_CONV
-
-  mkexp test.pg 1.0 PGAUSS
-  fitexp test.pg test.pg.fit PGA_CONV
-
-  mkexp test.qga 1.0 QGAUSS
-  fitexp test.qga test.qga.fit QGA_CONV
-
-  mkexp test.p1 1.0 PS1_V1
-  fitexp test.p1 test.p1.fit PS1_CONV
-end
-
-macro go.ckgalaxy
-  foreach type exp ser dev gau pg qga p1
-    ckgalaxy test.$type.dat test.$type.fit.cmf
-    wait $type
-  end
+macro grid.fitexp.sersic
+  if ($0 != 3)
+    echo "USAGE: grid.fitexp.sersic (srcdir) (outdir)"
+    break
+  end
+
+  mkdir $2
+
+  $Nseq = 0
+  foreach index 1 2 3 4
+    foreach Rmajor 3 10 30
+      foreach Aratio 0.25 0.5 1.0
+        foreach fwhm 0.8 1.0 1.5
+          sprint name "sersic.%02d" $Nseq
+          fitexp $1/$name $2/$name.fit SER\_CONV
+	  $Nseq ++
+        end
+      end
+    end
+  end
+end
+
+macro grid.load.sersic
+  if ($0 != 3)
+    echo "USAGE: grid.load.devexp (srcdir) (fitdir)"
+    break
+  end
+
+  delete -q Xin_s Yin_s Min_s Tin_s Rin_s rin_s MTin_s Iin_s
+  delete -q Xot_s Yot_s Mot_s Tot_s Rot_s rot_s MTot_s Iot_s
+
+  $Nseq = 0
+  foreach index 1 2 3 4
+    foreach Rmajor 3 10 30
+      foreach Aratio 0.25 0.5 1.0
+        foreach fwhm 0.8 1.0 1.5
+          sprint name "sersic.%02d" $Nseq
+          cmf.load.concat $1/$name.dat $2/$name.fit.cmf SERSIC
+	  $Nseq ++
+        end
+      end
+    end
+  end
+end
+
+# I want to make plots of Iin_s vs Mkron, Mxx, and similar things
+# this means I need to be able to join Chip.xfit things against Chip.psf
+# and to join Chip.xfit(DEV) to Chip.xfit(EXP)
+
+# I think I need a generic 'JOIN' function
+
+macro grid.plots.sersic
+  if ($0 != 2)
+    echo "USAGE: grid.plot.devexp (version)"
+    break
+  end
+  # things to examine: theta, Rmajor, AR
+
+  # go.grid.check.devexp
+
+  # check on theta
+  set dT = Tot_s - Tin_s
+  set ARin = rin_s / Rin_s
+  # lim ARin dT; clear; box; plot ARin dT
+
+  subset dTx = dT if (ARin < 0.95)
+  histogram dTx NdT -8 8 0.1 -range dTi
+  lim -n 0$1 dTi NdT; clear; box; plot -x 1 dTi NdT
+  label -x "angle offset (degrees, only non-circular)" -y "number count"
+  resize 700 320
+
+  # check on Rmajor
+  set dR = Rin_s - Rot_s
+  # lim Rin_s dR; clear; box; plot Rin_s dR
+  # lim Rot_s dR; clear; box; plot Rot_s dR
+  # lim Rin_s dR; clear; box; plot Rin_s dR
+  create n 0 dR[]
+  set dRf = dR / Rin_s
+  lim -n 1$1 n -0.5 0.5; clear; box; plot n dRf
+  label -x sequence -y "1 - R_out| / R_in|"
+  resize 700 320
+
+  # check on A.Ratio
+  set ARot = rot_s / Rot_s
+  # lim ARin ARot; clear; box; plot ARin ARot
+  set fAR = ARot / ARin
+  lim -n 2$1 n 0.5 1.5; clear; box; plot n fAR
+  label -x sequence -y "AR_out| / AR_in|"
+  resize 700 320
+
+  # check on magnitude
+  set dM = Mot_s - Min_s
+  lim -n 3$1 n -0.5 0.5; clear; box; plot n dM    
+  label -x sequence -y "M_out| - M_in|"
+  resize 700 320
+
+  # check on index
+  set dI = Iot_s - Iin_s
+  lim -n 4$1 n -0.5 0.5; clear; box; plot n dI    
+  label -x sequence -y "I_out| - I_in|"
+  resize 700 320
 end
 
@@ -258,4 +590,6 @@
 end
 
+if (not($?NSIGMA_CONV)) set NSIGMA_CONV = 5.0
+
 # create a realistic distribution of fake stars, GAUSS PSF
 macro fitexp
@@ -278,70 +612,62 @@
   $psphotConfig = $psphotConfig -Db PSPHOT:SAVE.RESID T
   $psphotConfig = $psphotConfig -D  PSPHOT:EXTENDED_SOURCE_MODELS_SELECTION $fitModel
+  $psphotConfig = $psphotConfig -D  PSPHOT:PSF_MODEL PS_MODEL_$PSFMODEL
+
+  $psphotConfig = $psphotConfig -Db PSPHOT:PSF.RESIDUALS F
+  $psphotConfig = $psphotConfig -Db PSPHOT:POISSON.ERRORS.PHOT.LMM F
+  $psphotConfig = $psphotConfig -Db PSPHOT:EXTENDED_SOURCE_FITS_POISSON F
+  $psphotConfig = $psphotConfig -Di PSPHOT:EXT_FIT_ITER 15
+  $psphotConfig = $psphotConfig -Df PSPHOT:PSF_FIT_RADIUS_SCALE 3.75
+  $psphotConfig = $psphotConfig -Df PSPHOT:EXT_FIT_NSIGMA_CONV $NSIGMA_CONV
 
   # ppImage / psphot on the output
+  break -auto off
   echo ppImage $ppImageConfig $psphotConfig -file $basename.fits $outname
-  exec ppImage $ppImageConfig $psphotConfig -file $basename.fits $outname
-end
-
-macro ckchip
-  if ($0 != 5)
-    echo "USAGE: ckchip (raw) (out) (output) (zpt_off)"
-    break
-  end
-
-  load.cmf $1 Chip.psf raw
-  load.cmf $2 Chip.psf out
-
-  # images generated with convolution will not have the right output positions
-  set X_raw = int(X_PSF_raw) + 0.5
-  set Y_raw = int(Y_PSF_raw) + 0.5
-  set M_raw = PSF_INST_MAG_raw + $4
-  set K_out = -2.5*log(KRON_FLUX_out)
-  match2d X_PSF_out Y_PSF_out X_PSF_raw Y_PSF_raw 1.5 -index1 index1 -index2 index2
-
-  local i NX NY nx ny N
-
-  device -n compare
-  resize 1000 1000
-
-  # plot trends as a function of mag
-  $NX = 2
-  $NY = 5
-  $nx = 0
-  $ny = 0
-  $N = 0
-  clear -s
-  for i 0 $pairs:n
-    section a$nx\$ny {$nx/$NX} {$ny/$NY} {1/$NX} {1/$NY}
-    show.pair $i
-    $ny ++
-    if ($ny == $NY)
-      $ny = 0
-      $nx ++
-    end
-    if ($nx == $NX)
-      png -name $3.$N.png
-      clear -s
-      $nx = 0
-      $ny = 0
-      $N ++
-    end
-  end
-
-  # plot (input - output) vs mag
-end
-
-macro ckgalaxy.load
-  if ($0 != 3)
-    echo "USAGE: ckgalaxy (dat) (cmf)"
+  exec echo ppImage $ppImageConfig $psphotConfig -file $basename.fits $outname >& $outname.log
+  exec ppImage $ppImageConfig $psphotConfig -file $basename.fits $outname >>& $outname.log
+  break -auto on
+end
+
+macro cmf.load.reset
+  $fields = X Y M T R r MT I
+  foreach field $fields
+    foreach set in ot
+      delete -q $field\$set\_s
+    end
+  end
+
+  delete -q min_S Min_S
+end
+
+macro cmf.load.concat
+  if ($0 != 4)
+    echo "USAGE: cmf.load.concat (dat) (cmf) (inType)"
     break
   end
 
   data $1
-  read Xin_all 1 Yin_all 2 Type 4 Min_all 5 RmajIn_all 7 RminIn_all 8 ThetaIn_all 9
-
+  read Xin_all 1 Yin_all 2 Fin_all 3 Type 4 Min_all 5 RmajIn_all 7 RminIn_all 8 ThetaIn_all 9 IndexIn_all 10
+
+  $TYPE_S = 83
+  $TYPE_D = 68
+  $TYPE_E = 69
+  if ("$3" == "SERSIC")
+    $InType = $TYPE_S
+  end
+  if ("$3" == "DEV")
+    $InType = $TYPE_D
+    set IndexIn_all = 0.125 + zero(Xin_all)
+  end
+  if ("$3" == "EXP")
+    $InType = $TYPE_E
+    set IndexIn_all = 0.5 + zero(Xin_all)
+  end
+
+  # select only the galaxies 
   subset Xin = Xin_all if (Type == 1)
   subset Yin = Yin_all if (Type == 1)
   subset Min = Min_all if (Type == 1)
+  subset Fin = Fin_all if (Type == 1)
+  set min = -2.5*log(Fin)
 
   subset Tin_rad = ThetaIn_all if (Type == 1)
@@ -351,6 +677,19 @@
   subset RminIn = RminIn_all if (Type == 1)
 
+  subset IndexIn = IndexIn_all if (Type == 1)
+
   data $2
-  read -fits Chip.xfit X_EXT Y_EXT EXT_INST_MAG EXT_WIDTH_MAJ EXT_WIDTH_MIN EXT_THETA
+
+  break -auto off
+  output -err /dev/null
+  read -fits Chip.xfit X_EXT Y_EXT EXT_INST_MAG EXT_WIDTH_MAJ EXT_WIDTH_MIN EXT_THETA MODEL_TYPE EXT_PAR_07
+  $reread = not($STATUS)
+  output -err stderr
+  break -auto on
+  if ($reread)
+    read -fits Chip.xfit X_EXT Y_EXT EXT_INST_MAG EXT_WIDTH_MAJ EXT_WIDTH_MIN EXT_THETA MODEL_TYPE 
+    set EXT_PAR_07 = (MODEL_TYPE:9 == 68)*0.125 + (MODEL_TYPE:9 == 69)*0.5
+  end
+
   set EXT_THETA_ALT = EXT_THETA * (EXT_THETA >= 0.0) + (EXT_THETA + 3.14159265) * (EXT_THETA < 0.0)
   set EXT_THETA = EXT_THETA_ALT * 180 / 3.14159265
@@ -364,4 +703,7 @@
   reindex Yin_m = Yin using index2
 
+  set MTin_m = $InType + zero(Xin_m)
+  reindex MTot_m = MODEL_TYPE:9 using index1
+
   reindex Mot_m = EXT_INST_MAG using index1
   reindex Tot_m = EXT_THETA using index1
@@ -376,261 +718,232 @@
   reindex rin_m = RminIn using index2
   
-  foreach field X Y M T R r 
+  reindex Iot_m = EXT_PAR_07 using index1
+  reindex Iin_m = IndexIn using index2
+  $fields = X Y M T R r MT I
+  
+  foreach field $fields
     foreach set in ot
       concat $field\$set\_m $field\$set\_s
     end
   end
-end
-
-macro stats.pair
+
+  concat min min_S
+  concat Min Min_S
+end
+
+macro cmf.load.stars.concat
   if ($0 != 3)
-    echo "USAGE: stats.pair (N) (output)"
-    break
-  end
-
-  list word -split $spairs:$1
-  if ($word:n != 8)
-    echo "invalid pair $1"
-    break
-  end
-
-  $Nr = $word:3
-
-  reindex v1 = $word:0 using index1
-  reindex v2 = $word:1 using index2
-  reindex rv = $word:2 using index$Nr
-
-  set delta = v1 - v2
-  subset d1 = delta if ($word:4 < rv) && (rv < $word:5) && (abs(delta) < $word:7)
-  subset d2 = delta if ($word:5 < rv) && (rv < $word:6) && (abs(delta) < $word:7)
-
-  vstats -q d1 -sigma-clip 3.0
-  $M1 = $MEAN
-  $S1 = $SIGMA
-  vstats -q d2 -sigma-clip 3.0
-  $M2 = $MEAN
-  $S2 = $SIGMA
-
-  output $2
-  fprintf "%-18s  %7.4f %7.4f  %7.4f %7.4f" $word:0  $M1 $S1  $M2 $S2
-  output stdout
-end
-
-macro show.pair
-  if ($0 != 2)
-    echo "USAGE: show.pair (N)"
-    break
-  end
-
-  list word -split $pairs:$1
-  if ($word:n != 7)
-    echo "invalid pair $1"
-    break
-  end
-
-  $Nr = $word:3
-
-  reindex v1 = $word:0 using index1
-  if ("$word:6" == "V") 
-    reindex v2 = $word:1 using index2
-  end
-  if ("$word:6" == "S") 
-    set v2 = $word:1 + zero(index1)
-  end
-  reindex rv = $word:2 using index$Nr
-
-  set delta = v1 - v2
-  if (("$word:4" == "def") || ("$word:5" == "def"))
-    lim rv delta; box; plot rv delta
-  else
-    lim rv $word:4 $word:5; box; plot rv delta
-  end
-  label -y '$word:0' -x '$word:2'
-end
-
-# This list is used to compare a pair of vectors (sans error) or a
-# vector and an expected (constant) value.  The last field defines a
-# vector or constant for the comparison.  It is assumed that the
-# vector sets have been loaded and matched with match2d to generate
-# index vectors 'index1' and index2'.  The macro 'show.pair' generates
-# a plot of the range vector vs (v1 - v2).  The indices for v1, v2 are
-# index1 and 2 respectively.  The index for the range vector is defined
-# by the integer following that vector.  the y-limits of the plot are
-# given by the last two numbers
-list pairs
-  X_PSF_out             X_raw                 PSF_INST_MAG_raw 2 -1.01 1.01 V
-  Y_PSF_out             Y_raw                 PSF_INST_MAG_raw 2 -1.01 1.01 V
-  X_PSF_out             X_PSF_raw             PSF_INST_MAG_raw 2 -1.01 1.01 V
-  Y_PSF_out             Y_PSF_raw             PSF_INST_MAG_raw 2 -1.01 1.01 V
-  X_PSF_SIG_out         X_PSF_SIG_raw         PSF_INST_MAG_raw 2 -1.01 1.01 V
-  Y_PSF_SIG_out         Y_PSF_SIG_raw         PSF_INST_MAG_raw 2 -1.01 1.01 V
-  #PSF_INST_MAG_out      PSF_INST_MAG_raw      PSF_INST_MAG_raw 2 -1.01 1.01 V
-  PSF_INST_MAG_out      M_raw                 PSF_INST_MAG_raw 2 -1.01 1.01 V
-  PSF_INST_MAG_SIG_out  PSF_INST_MAG_SIG_raw  PSF_INST_MAG_raw 2 -1.01 1.01 V
-  #PSF_INST_FLUX_out     PSF_INST_FLUX_raw     PSF_INST_MAG_raw 2   def  def V
-  #PSF_INST_FLUX_SIG_out PSF_INST_FLUX_SIG_raw PSF_INST_MAG_raw 2   def  def V
-  AP_MAG_out            M_raw                 PSF_INST_MAG_raw 2 -1.01 1.01 V
-  AP_MAG_RAW_out        M_raw                 PSF_INST_MAG_raw 2 -1.01 1.01 V
-  AP_MAG_RADIUS_out     0.0                   PSF_INST_MAG_raw 2 -0.01 20.1 S
-  SKY_out               0.0                   PSF_INST_MAG_raw 2   def  def S
-  SKY_SIGMA_out         0.0                   PSF_INST_MAG_raw 2   def  def S
-  PSF_CHISQ_out         1.0                   PSF_INST_MAG_raw 2   def  def S
-  CR_NSIGMA_out         0.0   		      PSF_INST_MAG_raw 2   def  def S
-  EXT_NSIGMA_out        0.0   		      PSF_INST_MAG_raw 2 -5.01 5.01 S
-  PSF_MAJOR_out         0.0   		      PSF_INST_MAG_raw 2 -0.01 5.01 S
-  PSF_MINOR_out         0.0   		      PSF_INST_MAG_raw 2 -0.01 5.01 S
-  PSF_THETA_out         0.0   		      PSF_INST_MAG_raw 2 -1.61 1.61 S
-  PSF_QF_out            0.0   		      PSF_INST_MAG_raw 2 -0.10 1.10 S
-  PSF_QF_PERFECT_out    0.0   		      PSF_INST_MAG_raw 2 -0.10 1.10 S
-  PSF_NDOF_out          0.0   		      PSF_INST_MAG_raw 2  def  def  S
-  PSF_NPIX_out          0.0   		      PSF_INST_MAG_raw 2  def  def  S
-  MOMENTS_XX_out        0.0   		      PSF_INST_MAG_raw 2 -0.01 3.01 S
-  MOMENTS_XY_out        0.0   		      PSF_INST_MAG_raw 2 -3.01 3.01 S
-  MOMENTS_YY_out        0.0   		      PSF_INST_MAG_raw 2 -0.01 3.01 S
-  MOMENTS_M3C_out       0.0   		      PSF_INST_MAG_raw 2 -3.01 3.01 S
-  MOMENTS_M3S_out       0.0   		      PSF_INST_MAG_raw 2 -3.01 3.01 S
-  MOMENTS_M4C_out       0.0   		      PSF_INST_MAG_raw 2 -2.01 2.01 S
-  MOMENTS_M4S_out       0.0   		      PSF_INST_MAG_raw 2 -2.01 2.01 S
-  MOMENTS_R1_out        0.0   		      PSF_INST_MAG_raw 2 -5.01 5.01 S
-  MOMENTS_RH_out        0.0   		      PSF_INST_MAG_raw 2 -5.01 5.01 S
-  K_out                 M_raw  		      PSF_INST_MAG_raw 2  def  def  V
-  KRON_FLUX_ERR_out     0.0   		      PSF_INST_MAG_raw 2  def  def  S
-  KRON_FLUX_INNER_out   0.0   		      PSF_INST_MAG_raw 2  def  def  S
-  KRON_FLUX_OUTER_out   0.0   		      PSF_INST_MAG_raw 2  def  def  S
-# CAL_PSF_MAG          CAL_PSF_MAG          none Mraw 2 -1.01 1.01 V
-# CAL_PSF_MAG_SIG      CAL_PSF_MAG_SIG      none Mraw 2 -1.01 1.01 V
-# RA_PSF               RA_PSF               none Mraw 2 -1.01 1.01 V
-# DEC_PSF              DEC_PSF              none Mraw 2 -1.01 1.01 V
-# PEAK_FLUX_AS_MAG     PEAK_FLUX_AS_MAG     none Mraw 2 -1.01 1.01 V
-# FLAGS                FLAGS                0.0  Mraw 2 -1.01 1.01 S
-# FLAGS2               FLAGS2               0.0  Mraw 2 -1.01 1.01 S
-end
-
-macro load.cmf
-  if ($0 != 4)
-   echo "load.cmf (filename) (ext) (label)"
-   break
+    echo "USAGE: cmf.load.concat (dat) (cmf)"
+    break
   end
 
   data $1
-
-  # create the list of fields to load
-  delete -q myFields
-  for i 0 $fields:n
-    if ($?myFields) 
-      $myFields = $myFields $fields:$i
-    else
-      $myFields = $fields:$i
-    end
-  end
-
-  read -fits $2 $myFields
-
-  # rename the loaded vectors appending the supplied lable
-  for i 0 $fields:n
-    set $fields:$i\_$3 = $fields:$i
-    delete $fields:$i
-  end
-end
-
-# this list defines the fields to be loaded from file
-list fields
-  X_PSF              
-  Y_PSF              
-  X_PSF_SIG          
-  Y_PSF_SIG          
-  PSF_INST_MAG       
-  PSF_INST_MAG_SIG   
-  PSF_INST_FLUX      
-  PSF_INST_FLUX_SIG  
-  AP_MAG             
-  AP_MAG_RAW         
-  AP_MAG_RADIUS      
-  SKY                
-  SKY_SIGMA          
-  PSF_CHISQ          
-  CR_NSIGMA          
-  EXT_NSIGMA         
-  PSF_MAJOR          
-  PSF_MINOR          
-  PSF_THETA          
-  PSF_QF             
-  PSF_QF_PERFECT     
-  PSF_NDOF           
-  PSF_NPIX           
-  MOMENTS_XX         
-  MOMENTS_XY         
-  MOMENTS_YY         
-  MOMENTS_M3C        
-  MOMENTS_M3S        
-  MOMENTS_M4C        
-  MOMENTS_M4S        
-  MOMENTS_R1         
-  MOMENTS_RH         
-  KRON_FLUX          
-  KRON_FLUX_ERR      
-  KRON_FLUX_INNER    
-  KRON_FLUX_OUTER    
-#   CAL_PSF_MAG      
-#   CAL_PSF_MAG_SIG  
-#   RA_PSF           
-#   DEC_PSF          
-#   PEAK_FLUX_AS_MAG 
-#  FLAGS            
-#  FLAGS2           
-end
-
-# use these cmf entries to measure average stats of the given pairs
-list spairs
-  X_PSF_out             X_raw                 PSF_INST_MAG_raw 2 -15 -10 -8.5  0.1
-  Y_PSF_out             Y_raw                 PSF_INST_MAG_raw 2 -15 -10 -8.5  0.1
-  PSF_INST_MAG_out      M_raw                 PSF_INST_MAG_raw 2 -15 -10 -8.5  0.1
-  AP_MAG_out            M_raw                 PSF_INST_MAG_raw 2 -15 -10 -8.5  0.1
-end
-
-macro show.dpair
-  if ($0 != 2)
-    echo "USAGE: show.dpair (N)"
-    break
-  end
-
-  list word -split $dpairs:$1
-  if ($word:n != 7)
-    echo "invalid dpair $1"
-    break
-  end
-
-  $Nr = $word:4
-
-  reindex v1 = $word:0 using index1
-  reindex dv = $word:1 using index1
-  reindex v2 = $word:2 using index2
-  reindex rv = $word:3 using index$Nr
-
-  set delta = (v1 - v2) / dv
-  if (("$word:5" == "def") || ("$word:6" == "def"))
-    lim rv delta; box; plot rv delta
-  else
-    lim rv $word:5 $word:6; box; plot rv delta
-  end
-  label -y '$word:0' -x '$word:3'
-end
-
-# this list is used to compare a pair of vectors with an error it is
-# assumed that the vector sets have been loaded and matched with
-# match2d to generate index vectors 'index1' and index2'.  the macro
-# show.dpair generates a plot of the range vector vs (v1 - v2) / dv1.
-# The indices for v1, dv1, and v2 are index1,1, and 2 respectively.  The
-# index for the range vector is defined by the integer following that
-# vector.  The y-limits of the plot are given by the last two numbers
-# (use 'def') for the full default range of the delta vector
-list dpairs
-  # v1              dv                v2   range 
-  X_PSF             X_PSF_SIG         Xraw Mraw  2 -10.0 10.0
-  Y_PSF             Y_PSF_SIG         Yraw Mraw  2 -10.0 10.0
-  PSF_INST_MAG      PSF_INST_MAG_SIG  Mraw Mraw  2 -10.0 10.0
-  PSF_INST_FLUX     PSF_INST_FLUX_SIG Fraw Mraw  2 -10.0 10.0
-  AP_MAG            PSF_INST_MAG_SIG  Mraw Mraw  2 -10.0 10.0
-  AP_MAG_RAW        PSF_INST_MAG_SIG  Mraw Mraw  2 -10.0 10.0
+  read Xin_all 1 Yin_all 2 Type 4 Min_all 5 RmajIn_all 7 RminIn_all 8 ThetaIn_all 9 IndexIn_all 10
+
+  subset Xin     = Xin_all     if (Type == 0)
+  subset Yin     = Yin_all     if (Type == 0)
+  subset Min     = Min_all     if (Type == 0)
+  subset RmajIn  = RmajIn_all  if (Type == 0)
+  subset RminIn  = RminIn_all  if (Type == 0)
+  subset IndexIn = IndexIn_all if (Type == 0)
+  subset Tin_rad = ThetaIn_all if (Type == 0)
+  set Tin = Tin_rad * 180 / 3.14159265
+
+  data $2
+
+  break -auto off
+  read -fits Chip.psf X_PSF Y_PSF PSF_INST_MAG PSF_MAJOR PSF_MINOR PSF_THETA
+  set PSF_THETA_ALT = PSF_THETA * (PSF_THETA >= 0.0) + (PSF_THETA + 3.14159265) * (PSF_THETA < 0.0)
+  set PSF_THETA = PSF_THETA_ALT * 180 / 3.14159265
+  
+  match2d X_PSF Y_PSF Xin Yin 1.0 -index1 index1 -index2 index2
+
+  reindex Xot_m = X_PSF using index1
+  reindex Yot_m = Y_PSF using index1
+
+  reindex Xin_m = Xin using index2
+  reindex Yin_m = Yin using index2
+
+  reindex Mot_m = PSF_INST_MAG using index1
+  reindex Tot_m = PSF_THETA using index1
+
+  reindex Min_m = Min using index2
+  reindex Tin_m = Tin using index2
+
+  reindex Rot_m = PSF_MAJOR using index1
+  reindex rot_m = PSF_MINOR using index1
+
+  reindex Rin_m = RmajIn using index2
+  reindex rin_m = RminIn using index2
+  
+  $fields = X Y M T R r
+  foreach field $fields
+    foreach set in ot
+      concat $field\$set\_m $field\$set\_s
+    end
+  end
+end
+
+macro grid.load.sersic.test
+  if ($0 != 3)
+    echo "USAGE: grid.load.devexp.test (srcdir) (fitdir)"
+    break
+  end
+
+  $fields_bt = X Y M T R r I
+  $fields_ot = Pmag Kmag Amag IDx MTot
+
+  foreach field $fields_bt
+    foreach set in ot
+      delete -q $field\$set\_dev_s
+      delete -q $field\$set\_exp_s
+    end
+  end
+  foreach field $fields_ot
+    delete -q $field\_dev_s
+    delete -q $field\_exp_s
+  end
+
+  $Nseq = 0
+  foreach index 1 2 3 4
+    foreach Rmajor 3 10 30
+      foreach Aratio 0.25 0.5 1.0
+        foreach fwhm 0.8 1.0 1.5
+          sprint name "sersic.%02d" $Nseq
+          cmf.load.sersic.test $1/$name.dat $2/$name.fit.cmf
+	  $Nseq ++
+        end
+      end
+    end
+  end
+end
+
+# I have run DEV and EXP against input models of type SERSIC
+macro cmf.load.sersic.test
+  if ($0 != 3)
+    echo "USAGE: cmf.load.sersic.test (dat) (cmf)"
+    break
+  end
+
+  # input parameters
+  data $1
+  read Xin_all 1 Yin_all 2 Fin_all 3 Type 4 Min_all 5 RmajIn_all 7 RminIn_all 8 ThetaIn_all 9 IndexIn_all 10
+
+  # galaxies only
+  subset Xin = Xin_all if (Type == 1)
+  subset Yin = Yin_all if (Type == 1)
+  subset Min = Min_all if (Type == 1)
+  subset Fin = Fin_all if (Type == 1)
+  set min = -2.5*log(Fin)
+
+  subset Tin_rad = ThetaIn_all if (Type == 1)
+  set Tin = Tin_rad * 180 / 3.14159265
+
+  subset RmajIn = RmajIn_all if (Type == 1)
+  subset RminIn = RminIn_all if (Type == 1)
+
+  subset IndexIn = IndexIn_all if (Type == 1)
+
+  $TYPE_S = 83
+  $TYPE_D = 68
+  $TYPE_E = 69
+
+  data $2
+
+  # load measured values from xfit
+  read -fits Chip.xfit IPP_IDET X_EXT Y_EXT EXT_INST_MAG EXT_WIDTH_MAJ EXT_WIDTH_MIN EXT_THETA MODEL_TYPE PSF_INST_MAG AP_MAG KRON_MAG
+  set EXT_PAR_07 = (MODEL_TYPE:9 == $TYPE_D)*4 + (MODEL_TYPE:9 == $TYPE_E)
+
+  set EXT_THETA_ALT = EXT_THETA * (EXT_THETA >= 0.0) + (EXT_THETA + 3.14159265) * (EXT_THETA < 0.0)
+  set EXT_THETA = EXT_THETA_ALT * 180 / 3.14159265
+  set IPP_IDET_EXT = IPP_IDET
+  
+  match2d X_EXT Y_EXT Xin Yin 1.0 -index1 index1 -index2 index2
+
+  reindex Xot_m = X_EXT using index1
+  reindex Yot_m = Y_EXT using index1
+
+  reindex Xin_m = Xin using index2
+  reindex Yin_m = Yin using index2
+
+  reindex Mot_m = EXT_INST_MAG using index1
+  reindex Tot_m = EXT_THETA using index1
+
+  reindex Min_m = Min using index2
+  reindex Tin_m = Tin using index2
+
+  reindex Rot_m = EXT_WIDTH_MAJ using index1
+  reindex rot_m = EXT_WIDTH_MIN using index1
+
+  reindex Rin_m = RmajIn using index2
+  reindex rin_m = RminIn using index2
+  
+  reindex Pmag_m = PSF_INST_MAG using index1
+  reindex Kmag_m = KRON_MAG using index1
+  reindex Amag_m = AP_MAG using index1
+
+  reindex IDx_m = IPP_IDET_EXT using index1
+
+  reindex MTot_m = MODEL_TYPE:9 using index1
+
+  reindex Iot_m = EXT_PAR_07 using index1
+  reindex Iin_m = IndexIn using index2
+  
+  # load moments and other kron values from Chip.psf
+  read -fits Chip.psf IPP_IDET X_PSF Y_PSF MOMENTS_XX MOMENTS_XY MOMENTS_YY KRON_FLUX_INNER MOMENTS_R1 MOMENTS_RH
+  set IPP_IDET_PSF = IPP_IDET
+
+  join -outer IPP_IDET_PSF IDx_m 
+  reindex Xp = X_PSF using index2
+  reindex Yp = Y_PSF using index2
+
+  reindex Mxx_m = MOMENTS_XX using index2
+  reindex Mxy_m = MOMENTS_XY using index2
+  reindex Myy_m = MOMENTS_YY using index2
+  reindex Mr1_m = MOMENTS_R1 using index2
+  reindex Mrh_m = MOMENTS_RH using index2
+  reindex Kfi_m = KRON_FLUX_INNER using index2
+  set Kmi_m = -2.5*log(Kfi_m)
+
+  $fields_bt = X Y M T R r I
+  $fields_ot = Pmag Kmag Amag IDx MTot Mxx Mxy Myy Mr1 Mrh Kmi
+
+  foreach field $fields_ot
+    subset $field\_exp_m = $field\_m where (MTot_m == $TYPE_E)
+    subset $field\_dev_m = $field\_m where (MTot_m == $TYPE_D)
+  end
+  foreach field $fields_bt
+    foreach set in ot
+      subset $field\$set\_exp_m = $field\$set\_m where (MTot_m == $TYPE_E)
+      subset $field\$set\_dev_m = $field\$set\_m where (MTot_m == $TYPE_D)
+    end
+  end
+
+  join IDx_exp_m IDx_dev_m
+  foreach field $fields_ot
+    reindex $field\_exp_mr = $field\_exp_m using index1
+    reindex $field\_dev_mr = $field\_dev_m using index2
+  end
+  foreach field $fields_bt
+    foreach set in ot
+      reindex $field\$set\_exp_mr = $field\$set\_exp_m using index1
+      reindex $field\$set\_dev_mr = $field\$set\_dev_m using index2
+    end
+  end
+
+  # concat
+  foreach field $fields_bt
+    foreach set in ot
+      concat $field\$set\_dev_mr $field\$set\_dev_s
+      concat $field\$set\_exp_mr $field\$set\_exp_s
+    end
+  end
+  foreach field $fields_ot
+    concat $field\_dev_mr $field\_dev_s
+    concat $field\_exp_mr $field\_exp_s
+  end
+
+  concat min min_S
+  concat Min Min_S
 end
 
@@ -659,39 +972,304 @@
 end
 
-macro plot.angles
+macro sersic.integral
   if ($0 != 2)
-    echo "USAGE: plot.angles (file.dat)"
+    echo "sersic.integral (index)"
+    break
+  end
+
+  $index = $1
+  create r 0.0 200.0 0.001
+  set q = r^(1/$index)
+  set f = exp(-q)
+  set rf = f*r
+  integrate r rf r[0] r[-1]
+end
+
+macro sersic.integral.rmax
+  if ($0 != 4)
+    echo "sersic.integral.rmax (index) (kappa) (rmax)"
+    echo "kappa is a guess for kappa"
+    break
+  end
+
+  local index kappa
+
+  $index = $1
+  $kappa = $2
+
+  create r 0.0 $3 0.003
+  set q = r^(1/$index)
+  set f = exp(-$kappa*q)
+  set rf = f*r
+  integrate r rf r[0] r[-1]
+end
+
+# S(r) = exp(-kappa*(r/Reff)^(1/index))
+# integrate S(r) r dr [ignores 2pi and change-of-variable factors (Rmaj*Rmin)]
+macro sersic.integral.reff.rmax
+  if ($0 != 5)
+    echo "sersic.integral.rmax (index) (kappa) (reff) (rmax)"
+    echo "kappa is a guess for kappa"
+    break
+  end
+
+  local index kappa Reff
+
+  $index = $1
+  $kappa = $2
+  $Reff = $3
+
+  create r 0.0 $4 0.01
+  set q = (r/$Reff)^(1/$index)
+  set f = exp(-$kappa*q)
+  set rf = f*r
+  integrate r rf r[0] r[-1]
+end
+
+# integrate to r = reff (rho = 1), applying kappa
+macro sersic.integral.reff
+  if ($0 != 3)
+    echo "sersic.integral.reff (index) (kappa)"
+    break
+  end
+
+  local index kappa
+
+  $index = $1
+  $kappa = $2
+  create r 0.0 100.0 0.001
+  set q = r^(1/$index)
+  set f = exp(-$kappa*q)
+  set rf = f*r
+  integrate r rf r[0] r[-1]
+  $S0 = $sum
+  integrate r rf r[0] 1.0
+  $S1 = $sum
+  echo $S0 $S1 {$S1 / $S0}
+end
+
+macro sersic.integral.find.reff
+  if ($0 != 3)
+    echo "sersic.integral.find.reff (index) (kappa)"
+    echo "kappa is a guess for kappa"
+    break
+  end
+
+  local kappa index Rmax i
+  $index = $1
+  $kappa = $1
+
+  $Rmin = 0; $Vmin = 0
+  $Rmax = 4000
+  sersic.integral.rmax $index $kappa $Rmax
+  $Vmax = $sum
+
+  $Rtry = 0.5*($Rmin + $Rmax)
+
+  while (abs($Rmax - $Rmin) > 0.001)
+    sersic.integral.rmax $index $kappa $Rtry
+    $Vtry = $sum
+
+    $Rold = $Rtry
+    if ($Vtry > 0.5*$Vmax)
+      $Rtry = 0.5*($Rmin + $Rtry)
+      $Rmax = $Rold
+    else
+      $Rtry = 0.5*($Rmax + $Rtry)
+      $Rmin = $Rold
+    end
+    # fprintf "%5.2f %5.2f %5.2f | %5.2f | %6.3f %6.3f | %6.3f" $Rmin $Rold $Rmax $Rtry {$Vtry / $Vmax} $Vmax $Vtry
+  end
+  # echo $Rtry
+  # echo {$kappa * $Rtry ^ (1.0/$index)}
+  $KappaReal = $kappa * $Rtry ^ (1.0/$index)
+end
+
+macro sersic.integral.index
+
+  local i kappa
+
+  delete -q sersic_sum sersic_norm 
+  # vlist idx 0.5 0.75 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0
+  # create idx 0.5 5.1 0.1
+  vlist idx 1 2 4
+  for i 0 idx[]
+    $kappa =  -0.275552 + 1.972625*idx[$i] + 0.003487*idx[$i]*idx[$i]
+    sersic.integral.rmax idx[$i] $kappa 300
+    concat $sum sersic_sum
+
+    $bn = 1.9992*idx[$i] - 0.3271;
+    $Io = exp($bn);
+    	    
+    # the integral of a Sersic (supposedly) has an analytical form as follows:
+    $logGamma = lgamma(2.0*idx[$i]);
+    $bnFactor = $bn^(2.0*idx[$i]);
+    $norm = idx[$i] * $Io * exp($logGamma) / $bnFactor;
+    concat $norm sersic_norm
+
+    echo idx[$i] $kappa $sum $logGamma $bn $bnFactor $norm
+  end
+  set lsersic_sum = ln(sersic_sum)
+  break
+  
+  $order = 2
+  delete -q sersic_fit fit_idx
+
+  # fit to ranges:
+  delete lsersic_fit fit_idx
+  vlist bound 0.0 1.0 2.0 3.0 4.0 5.5
+  for i 0 {bound[] - 1}
+    subset idxs = idx if (idx >= bound[$i]) && (idx < bound[$i+1]) 
+    subset sums = lsersic_sum if (idx >= bound[$i]) && (idx < bound[$i+1]) 
+    fit idxs sums $order
+    applyfit idxs fits
+    concat fits lsersic_fit
+    concat idxs fit_idx
+  end
+  set sersic_fit = exp(lsersic_fit)
+
+  lim -n 1 idx sersic_sum; clear; box; plot idx sersic_sum; plot -c blue -pt 7 idx sersic_norm; plot -x 0 -c red fit_idx sersic_fit
+  lim -n 2 idx lsersic_sum; clear; box; plot idx lsersic_sum; plot -x 0 -c red fit_idx lsersic_fit
+end
+
+macro sersic.kappa.index
+
+  local i
+
+  delete -q sersic_kappa
+  # vlist idx 0.5 0.75 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0
+  create idx 0.5 5.1 0.1
+  for i 0 idx[]
+    sersic.integral.find.reff idx[$i] 10
+    concat $KappaReal sersic_kappa
+  end
+  
+  # $order = 2
+  # delete -q sersic_kfit kfit_idx
+  # 
+  # # fit to ranges:
+  # vlist bound 0.0 1.0 2.0 3.0 4.0 5.5
+  # for i 0 {bound[] - 1}
+  #   subset idxs = idx if (idx >= bound[$i]) && (idx < bound[$i+1]) 
+  #   subset sums = lsersic_sum if (idx >= bound[$i]) && (idx < bound[$i+1]) 
+  #   fit idxs sums $order
+  #   applyfit idxs fits
+  #   concat fits lsersic_fit
+  #   concat idxs fit_idx
+  # end
+  # set sersic_fit = exp(lsersic_fit)
+
+  lim -n 1 idx sersic_kappa; clear; box; plot idx sersic_kappa; # plot -c blue -pt 7 idx sersic_norm; plot -x 0 -c red fit_idx sersic_fit
+  # lim -n 2 idx lsersic_sum; clear; box; plot idx lsersic_sum; plot -x 0 -c red fit_idx lsersic_fit
+
+  # kappa(index) :
+  # y = -0.275552 x^0 1.972625 x^1 0.003487 x^2 
+end
+
+macro sersic.central.pixel
+  if ($0 != 3)
+    echo "USAGE: sersic.central.pixel (index) (Reff)"
+    break
+  end
+
+  local index Reff
+
+  $index = $1
+  $Reff = $2
+
+  $kappa = -0.275552 + 1.972625*$index + 0.003487 * $index^2
+  # echo "kappa: $kappa"
+
+  sersic.norm $index
+  sersic.integral.reff.rmax $index $kappa $Reff {10*$Reff}; set sumFull = $sum; echo $sum {$Reff^2*$myNorm} {$sum / ($Reff^2*$myNorm)}
+  # sersic.integral.reff.rmax $index $kappa $Reff $Reff     ; # echo $sum {$sum / $sumFull}
+  # sersic.integral.reff.rmax $index $kappa $Reff 0.1       ; # echo $sum {$sum / $sumFull}
+  # sersic.integral.reff.rmax $index $kappa $Reff 0.2       ; # echo $sum {$sum / $sumFull}
+  # sersic.integral.reff.rmax $index $kappa $Reff 0.5       ; # echo $sum {$sum / $sumFull}
+  # sersic.integral.reff.rmax $index $kappa $Reff 1.0       ; # echo $sum {$sum / $sumFull}
+  # sersic.integral.reff.rmax $index $kappa $Reff 2.0       ; # echo $sum {$sum / $sumFull}
+  sersic.integral.reff.rmax $index $kappa $Reff 0.564     ; echo $index $Reff {$sum / $sumFull}
+
+end
+
+macro sersic.norm
+  if ($0 != 2)
+    echo "USAGE: sersic.norm (index)"
+    break
+  end
+
+  local index
+  $index = $1
+
+  if (($index >= 0.0) && ($index < 1.0))
+      $norm = 0.201545  - 0.950965 * $index - 0.315248 * $index^2
+      echo $norm {exp($norm)}
+      $myNorm = exp($norm)
+      return
+  end
+
+  if (($index >= 1.0) && ($index < 2.0)) 
+      $norm = 0.402084  - 1.357775 * $index - 0.105102 * $index^2
+      echo $norm {exp($norm)}
+      $myNorm = exp($norm)
+      return
+  end
+
+  if (($index >= 2.0) && ($index < 3.0))
+      $norm = 0.619093 - 1.591674 * $index - 0.041576 * $index^2
+      echo $norm {exp($norm)}
+      $myNorm = exp($norm)
+      return
+  end
+
+  if (($index >= 3.0) && ($index < 4.0))
+      $norm = 0.770263 - 1.696421 * $index - 0.023363 * $index^2
+      echo $norm {exp($norm)}
+      $myNorm = exp($norm)
+      return
+  end
+
+  if (($index >= 4.0) && ($index < 5.5)) 
+      $norm = 0.885891 - 1.755684 * $index - 0.015753 * $index^2
+      echo $norm {exp($norm)}
+      $myNorm = exp($norm)
+      return
+  end
+end
+
+macro load.model.im
+  if ($0 != 2)
+    echo "USAGE: load.model.im (N)"
+    break
+  end
+
+  rd obj$1 obj.$1.fits
+  rd cnv$1 cnv.$1.fits
+  rd var$1 var.$1.fits
+  rd msk$1 msk.$1.fits
+  for i 1 7
+    rd dpar$i.$1 dpar.$i.$1.fits
+  end
+  set dC$1 = (msk$1 == 0) * (obj$1 - cnv$1)^2 / var$1
+  tv dC$1 -0.01 3.0
+end
+
+macro load.normdata
+  if ($0 != 3)
+    echo "USAGE: load.normdata (file) [clear/noclear]"
     break
   end
 
   data $1
-  read x 1 y 2 type 4 trad 9 
-  set t = trad * 180 / 3.14159265
-  subset xs = x if (type == 1)
-  subset ys = y if (type == 1)
-  subset ts = t if (type == 1)
-
-  set cs = dcos(ts)
-  set sn = dsin(ts)
-
-  delete xp yp
-  erase red
-  for i 0 xs[]
-    point red LINE xs[$i] ys[$i] {10*cs[$i]} {10*sn[$i]}
-  end
-  plot xp yp -pt 100
-end
-
-macro check.flux
-  if ($0 != 2)
-    echo "USAGE: plot.angles (file.dat)"
-    break
-  end
-
-  data $1
-  read f 3 type 4
-  subset F = f if (type == 1)
-  set M = -2.5*log(F)
-  vstat M
+  read f 3 t 4 m 5
+  set M = -2.5*log(f)
+  subset Mg = M if (t == 1)
+  subset mg = m if (t == 1)
+  set dm = mg - Mg
+  set n = ramp(dm)
+  if ("$2" == "clear")
+    lim n dm; clear; box; 
+  end
+  plot n dm
 end
 
@@ -700,2 +1278,168 @@
   exit 0
 end
+
+# note that t1 = original confi
+# t2 = no residuals
+# t3 = const weight PSF fit
+# t4 = const weight galaxy fits
+
+macro run.radius.loop
+  local radius Nrun 
+
+  if (1)
+    $Nrun = 0
+    foreach radius 1.0 1.5 2.0 2.5 3.0 4.0 6.0 8.0
+      mkexp.devexp.single tests.20131120/testrad.ps1v1.exp.$Nrun EXP $radius 1.0
+      fitexp tests.20131120/testrad.ps1v1.exp.$Nrun tests.20131120/testrad.ps1v1.exp.$Nrun.t4b EXP_CONV
+      $Nrun ++
+    end
+  end
+
+  $Nrun = 0
+  foreach radius 1.0 1.5 2.0 2.5 3.0 4.0 6.0 8.0
+    cmf.load.concat tests.20131120/testrad.ps1v1.exp.$Nrun.dat tests.20131120/testrad.ps1v1.exp.$Nrun.t4b.cmf EXP
+    echo -no-return $radius ""
+    check.fit tests.20131120/testrad.ps1v1.exp.$Nrun.dat tests.20131120/testrad.ps1v1.exp.$Nrun.t4b.cmf EXP
+    $Nrun ++
+  end
+
+  grid.plots.devexp a
+end
+
+macro check.radius.loop
+  if ($0 != 2)
+    echo "USAGE: check.radius.loop (ext)"
+    break
+  end
+
+  # cmf.load.reset
+
+  local radius Nrun 
+
+  $Nrun = 0
+  foreach radius 1.0 1.5 2.0 2.5 3.0 4.0 6.0 8.0
+    echo -no-return $radius ""
+    check.fit tests.20131120/testrad.ps1v1.exp.$Nrun.dat tests.20131120/testrad.ps1v1.exp.$Nrun.$1.cmf EXP
+    $Nrun ++
+  end
+
+  grid.plots.devexp a
+end
+
+macro check.fit
+  if ($0 != 4)
+    echo "USAGE: check.fit (dat) (cmf) (type)"
+    break
+  end
+
+  cmf.load.concat $1 $2 $3
+  set dM_m = Mot_m - Min_m
+  vstat -q dM_m
+  $mag_off = $MEDIAN
+  set dR_m = Rot_m - Rin_m
+  vstat -q dR_m
+  $rad_off = $MEDIAN
+  echo $mag_off $rad_off
+end
+
+macro make.circles
+
+  delete Xo Yo Ro
+
+  for ix 0 16
+    for iy $ix 16
+      $r2 = $ix^2 + $iy^2
+      if ($r2 > 15^2) continue
+      concat $ix Xo
+      concat $iy Yo
+      concat $r2 Ro
+    end
+  end
+
+  sort Ro Xo Yo
+  $Rold = -1
+  $N = -1
+  for i 0 Ro[]
+    if (Ro[$i] != $Rold)
+      $N ++
+      $Rold = Ro[$i]
+    end
+    if ((Xo[$i] == 0) && (Yo[$i] == 0))
+      fprintf "// center is 0,0"
+      continue
+    end
+    if (Xo[$i] == 0)
+      fprintf "ADD_AXIS (%3d, %2d)     // r^2 = %3d" $N Yo[$i] Ro[$i]
+      continue
+    end
+    if (Xo[$i] == Yo[$i])
+      fprintf "ADD_DIAG (%3d, %2d)     // r^2 = %3d" $N Xo[$i] Ro[$i]
+      continue
+    end
+
+    fprintf "ADD_RAND (%3d, %2d, %2d) // r^2 = %3d" $N Xo[$i] Yo[$i] Ro[$i]
+ end
+end
+
+# EXP : tests.20131120/test.nsig
+# DEV : tests.20131120/test.dev
+
+# run.convolve.loop tests.20131120/test.nsig tests.20131120/test.nsig   EXP EXP_CONV
+# run.convolve.loop tests.20131120/test.dev  tests.20131120/test.dev    DEV DEV_CONV
+# run.convolve.loop tests.20131120/test.nsig tests.20131120/test.serexp EXP SER_CONV
+# run.convolve.loop tests.20131120/test.dev  tests.20131120/test.serdev DEV SER_CONV
+
+macro run.convolve.loop
+  if ($0 != 5)
+    echo "run.convolve.loop (inName) (fitName) (inType) (fitType)"
+    break
+  end
+
+  local radius
+  $radius = 3.0
+  cmf.load.reset
+
+  # foreach Cin 3 5 7 9 11
+  foreach Cin 11
+    $CONVOLVE_NSIGMA = $Cin
+    sprintf nameIn %s.%02d $1 $Cin
+    mkexp.devexp.single $nameIn $3 $radius 1.0
+    foreach Cot 3 5 7 9 11
+      $NSIGMA_CONV = $Cot
+      sprintf nameOt %s.%02d.%02d $2 $Cin $Cot
+      fitexp $nameIn $nameOt $4
+    end
+  end
+
+  # foreach Cin 3 5 7 9 11
+  foreach Cin 11
+    sprintf nameIn %s.%02d $1 $Cin
+    foreach Cot 3 5 7 9 11
+      sprintf nameOt %s.%02d.%02d $2 $Cin $Cot
+      check.fit $nameIn.dat $nameOt.cmf 
+    end
+  end
+  grid.plots.devexp a
+end
+
+macro check.convolve.loop
+  if ($0 != 4)
+    echo "run.convolve.loop (inName) (fitName) (inType)"
+    break
+  end
+
+  local radius
+  $radius = 3.0
+  cmf.load.reset
+
+  # foreach Cin 3 5 7 9 11
+  foreach Cin 11
+    sprintf nameIn %s.%02d $1 $Cin
+    foreach Cot 3 5 7 9 11
+      sprintf nameOt %s.%02d.%02d $2 $Cin $Cot
+      echo -no-return $Cin $Cot " "
+      check.fit $nameIn.dat $nameOt.cmf $3
+    end
+  end
+  grid.plots.devexp a
+end
