Index: /branches/eam_branches/ipp-20140610/Ohana/src/getstar/src/ReadImageFiles.c
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/getstar/src/ReadImageFiles.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/getstar/src/ReadImageFiles.c	(revision 36884)
@@ -138,5 +138,7 @@
 	  !strcmp (tmpword, "PS1_V1") ||  
 	  !strcmp (tmpword, "PS1_V2") ||  
-	  !strcmp (tmpword, "PS1_V3")) {
+	  !strcmp (tmpword, "PS1_V3") ||  
+	  !strcmp (tmpword, "PS1_V4") ||  
+	  !strcmp (tmpword, "PS1_V5")) {
 
 	  exttype[Nimage] = strcreate (tmpword);
Index: /branches/eam_branches/ipp-20140610/Ohana/src/relastro/src/launch_region_hosts.c
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/relastro/src/launch_region_hosts.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/relastro/src/launch_region_hosts.c	(revision 36884)
@@ -9,21 +9,21 @@
   for (i = 0; i < regionHosts->Nhosts; i++) {
     char *syncfile = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "meanmags.sync");
-    truncate (syncfile, 0);
+    if (truncate (syncfile, 0)) fprintf (stderr, "trouble clearing syncfile %s\n", syncfile);
     free (syncfile);
 
     char *fitsfile = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "meanmags.fits");
-    truncate (fitsfile, 0);
+    if (truncate (fitsfile, 0)) fprintf (stderr, "trouble clearing fitsfile %s\n", fitsfile);
     free (fitsfile);
 
     char *imsyncfile = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "imagemags.sync");
-    truncate (imsyncfile, 0);
+    if (truncate (imsyncfile, 0)) fprintf (stderr, "trouble clearing imsyncfile %s\n", imsyncfile);
     free (imsyncfile);
 
     char *imfitsfile = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "imagemags.fits");
-    truncate (imfitsfile, 0);
+    if (truncate (imfitsfile, 0)) fprintf (stderr, "trouble clearing imfitsfile %s\n", imfitsfile);
     free (imfitsfile);
 
     char *loopsyncfile = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "loop.sync");
-    truncate (loopsyncfile, 0);
+    if (truncate (loopsyncfile, 0)) fprintf (stderr, "trouble clearing loopsyncfile %s\n", loopsyncfile);
     free (loopsyncfile);
   }
Index: /branches/eam_branches/ipp-20140610/Ohana/src/relastro/src/syncfile.c
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/relastro/src/syncfile.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/relastro/src/syncfile.c	(revision 36884)
@@ -50,5 +50,5 @@
 int clear_sync_file (char *filename) {
   // delete file contents
-  truncate (filename, 0);
+  if (truncate (filename, 0)) fprintf (stderr, "trouble clearing file %s\n", filename);
 
   return TRUE;
Index: /branches/eam_branches/ipp-20140610/Ohana/src/relphot/src/launch_region_hosts.c
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/relphot/src/launch_region_hosts.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/relphot/src/launch_region_hosts.c	(revision 36884)
@@ -22,21 +22,21 @@
   for (i = 0; i < regionHosts->Nhosts; i++) {
     char *syncfile = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "meanmags.sync");
-    truncate (syncfile, 0);
+    if (truncate (syncfile, 0)) fprintf (stderr, "trouble clearing syncfile %s\n", syncfile);
     free (syncfile);
 
     char *fitsfile = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "meanmags.fits");
-    truncate (fitsfile, 0);
+    if (truncate (fitsfile, 0)) fprintf (stderr, "trouble clearing fitsfile %s\n", fitsfile );
     free (fitsfile);
 
     char *imsyncfile = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "imagemags.sync");
-    truncate (imsyncfile, 0);
+    if (truncate (imsyncfile, 0)) fprintf (stderr, "trouble clearing imsyncfile %s\n", imsyncfile);
     free (imsyncfile);
 
     char *imfitsfile = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "imagemags.fits");
-    truncate (imfitsfile, 0);
+    if (truncate (imfitsfile, 0)) fprintf (stderr, "trouble clearing imfitsfile %s\n", imfitsfile);
     free (imfitsfile);
 
     char *loopsyncfile = make_filename (CATDIR, regionHosts->hosts[i].hostname, regionHosts->hosts[i].hostID, "loop.sync");
-    truncate (loopsyncfile, 0);
+    if (truncate (loopsyncfile, 0)) fprintf (stderr, "trouble clearing loopsyncfile %s\n", loopsyncfile);
     free (loopsyncfile);
   }
Index: /branches/eam_branches/ipp-20140610/Ohana/src/relphot/src/syncfile.c
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/relphot/src/syncfile.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/relphot/src/syncfile.c	(revision 36884)
@@ -50,5 +50,5 @@
 int clear_sync_file (char *filename) {
   // delete file contents
-  truncate (filename, 0);
+  if (truncate (filename, 0)) fprintf (stderr, "trouble clearing file %s\n", filename);
 
   return TRUE;
Index: /branches/eam_branches/ipp-20140610/ippScripts/scripts/sc_prepare_camera.pl
===================================================================
--- /branches/eam_branches/ipp-20140610/ippScripts/scripts/sc_prepare_camera.pl	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/ippScripts/scripts/sc_prepare_camera.pl	(revision 36884)
@@ -179,6 +179,9 @@
     $psastro_command   .= " -masklist ${remote_outroot}.masklist ${remote_outroot} ";
 #    $psastro_command   .= " -refmasklist ${remote_outroot}.masklist ${remote_outroot} "; # This is used to do edge calculations.  It should probably be smart enough to know that it can just use the masks I just specified, but it's not.
+    # Uncomment when remote psastro supports this
+    $psastro_command   .= " -kh-correct /turquoise/usr/projects/ps1/watersc1/references/khcorrect.20140606.v0.fits ";
     $psastro_command   .= " -refmasklist /turquoise/usr/projects/ps1/watersc1/references/gpc1.refmask.list ";
-    $psastro_command   .= " -astrommodel /turquoise/usr/projects/ps1/watersc1/references/gpc1.20080909.asm ";
+#    $psastro_command   .= " -astrommodel /turquoise/usr/projects/ps1/watersc1/references/gpc1.20080909.asm ";
+    $psastro_command   .= " -astrommodel /turquoise/usr/projects/ps1/watersc1/references/gpc1.20140505.asm ";
     $psastro_command   .= " -recipe PSASTRO $recipe_psastro ";
     $psastro_command   .= " -tracedest ${remote_outroot}.trace -log ${remote_outroot}.log ";
Index: /branches/eam_branches/ipp-20140610/ippScripts/scripts/sc_prepare_chip.pl
===================================================================
--- /branches/eam_branches/ipp-20140610/ippScripts/scripts/sc_prepare_chip.pl	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/ippScripts/scripts/sc_prepare_chip.pl	(revision 36884)
@@ -315,5 +315,5 @@
 	$ppImage_command .= " -recipe PSPHOT $recipe_psphot ";
 	$ppImage_command .= " -recipe PPSTATS CHIPSTATS -stats ${remote_outroot}.${class_id}.stats ";
-	$ppImage_command .= " -threads $threads ";
+	$ppImage_command .= " -threads 4 ";
 	$ppImage_command .= " -image_id $chip_imfile_id ";
 	$ppImage_command .= " -tracedest ${remote_outroot}.${class_id}.trace ";
Index: /branches/eam_branches/ipp-20140610/ippScripts/scripts/sc_prepare_stack.pl
===================================================================
--- /branches/eam_branches/ipp-20140610/ippScripts/scripts/sc_prepare_stack.pl	(revision 36884)
+++ /branches/eam_branches/ipp-20140610/ippScripts/scripts/sc_prepare_stack.pl	(revision 36884)
@@ -0,0 +1,361 @@
+#! /usr/bin/env perl
+
+use Carp;
+use warnings;
+use strict;
+
+use IPC::Cmd 0.36 qw( can_run run );
+use PS::IPP::Metadata::Config;
+use PS::IPP::Metadata::List qw( parse_md_list );
+use PS::IPP::Config 1.01 qw( :standard );
+use DateTime;
+use Data::Dumper;
+use File::Basename;
+
+use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
+use Pod::Usage qw( pod2usage );
+
+
+# Hard coded values
+my $remote_root   = '/scratch3/watersc1/';  # Far side destination base location
+my $threads       = 2;                      # How many threads are we going to use?
+my $job_cost      = 1500 / 60 / 60;           # Estimate of how long a job runs, in hours.
+my $proc_per_node = 24;                     # processors per node
+my $min_nodes     = 1;                      # smallest allocation to ask for
+my $max_nodes     = 1000;                   # largest allocation to ask for
+my $min_time      = 1;                      # shortest allocation to ask for
+my $max_time      = 8;                      # longest allocation to ask for
+my $remote_hostname   = "LANL/Mustang";         # Name of the remote node.
+my @return_component_list = ("DBINFO.EXP", "PPSTACK.UNCONV","PPSTACK.UNCONV.MASK","PPSTACK.UNCONV.VARIANCE",
+			     "PPSTACK.UNCONV.EXP","PPSTACK.UNCONV.EXPWT","PPSTACK.UNCONV.EXPNUM","PSPHOT.OUTPUT",
+			     "LOG.EXP","TRACE.EXP", "PSASTRO.STATS",
+			     "PPSTACK.CONFIG","PPSTACK.TARGET.PSF");
+#,"PPSTACK.CONV.KERNEL");
+# Look for programs we need
+my $missing_tools;
+
+my $remotetool = can_run('remotetool') or (warn "Can't find remotetool" and $missing_tools = 1);
+my $stacktool    = can_run('stacktool') or (warn "Can't find warptool" and $missing_tools = 1);
+
+if ($missing_tools) {
+    warn("Can't find required tools.");
+    exit($PS_EXIT_CONFIG_ERROR);
+}
+
+my ($remote_id,$stack_id,$camera,$dbname,$verbose,$path_base,$no_update);
+GetOptions(
+    'remote_id=s'    => \$remote_id,
+    'camera|c=s'     => \$camera,
+    'dbname|d=s'     => \$dbname,
+    'path_base=s'    => \$path_base,
+    'no_update'      => \$no_update,
+    'verbose'        => \$verbose,
+    ) or pod2usage( 2 );
+
+pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
+pod2usage( -msg => "Required options: --remote_id --camera --dbname --path_base", -exitval => 3) unless
+    defined($remote_id) and
+    defined($camera) and
+    defined($path_base) and
+    defined($dbname);
+my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $remote_id);
+
+my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
+
+#
+# Step 1: Get a list of the components that make up this remoteRun
+
+# SHould this call listrun to ensure we're in state new?
+my $rt_cmd = "$remotetool -listcomponent -remote_id $remote_id";
+$rt_cmd   .= " -dbname $dbname " if defined($dbname);
+
+my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+    run(command => $rt_cmd, verbose => $verbose);
+unless ($success) {
+    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+    &my_die("Unable to run remotetool to determine stage parameters.",
+            $remote_id,$error_code);
+}
+my $compData = $mdcParser->parse(join "", @$stdout_buf) or
+    &my_die("Unable to determine component information.",
+            $remote_id,$PS_EXIT_PROG_ERROR);
+my $compData2= parse_md_list($compData);
+
+#
+# Step 1b: Open output files
+my $uri_command = $path_base . ".cmd";
+my $uri_transfer= $path_base . ".transfer";
+my $uri_check   = $path_base . ".check";
+my $uri_config  = $path_base . ".config";
+my $uri_generate= $path_base . ".generate";
+my $uri_return  = $path_base . ".return";
+
+my $disk_command = $ipprc->file_resolve($uri_command,1);
+my $disk_transfer= $ipprc->file_resolve($uri_transfer,1);
+my $disk_check   = $ipprc->file_resolve($uri_check,1);
+my $disk_config  = $ipprc->file_resolve($uri_config,1);
+my $disk_generate= $ipprc->file_resolve($uri_generate,1);
+my $disk_return  = $ipprc->file_resolve($uri_return,1);
+
+my (undef, $remote_config) = uri_convert($uri_config); # Needs to be done after we've created it.
+
+open(TRANSFER, ">$disk_transfer")  || &my_die("Couldn't open file? $disk_transfer",$remote_id,$PS_EXIT_SYS_ERROR);
+open(CHECK,    ">$disk_check")  || &my_die("Couldn't open file? $disk_check",$remote_id,$PS_EXIT_SYS_ERROR);
+open(CONFIG,   ">$disk_config")  || &my_die("Couldn't open file? $disk_config",$remote_id,$PS_EXIT_SYS_ERROR);
+open(GENERATE, ">$disk_generate") || &my_die("Couldn't open file? $disk_generate",$remote_id,$PS_EXIT_SYS_ERROR);
+open(RETURN,   ">$disk_return") || &my_die("Couldn't open file? $disk_return", $remote_id, $PS_EXIT_SYS_ERROR);
+
+
+#
+# Step 2: Iterate over all componenets in this remote run.
+my $job_index = 0;
+my @pre_commands = ();
+my @main_commands = ();
+my @post_commands = ();
+my %file_filter = ();
+
+
+foreach my $compEntry (@$compData2) {
+    my $stack_id = $compEntry->{stage_id};
+
+# Get exposure level information from the stackRun we're working from.
+    my $run_command = "$stacktool -tosum -stack_id $stack_id";
+    $run_command .= " -dbname $dbname " if defined($dbname);
+    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+	run(command => $run_command, verbose => 0);
+    unless ($success) {
+	$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+	&my_die("Unable to run stacktool -tosum ",
+		$stack_id,$error_code);
+    }
+
+    my $stackData = $mdcParser->parse(join "", @$stdout_buf) or
+	&my_die("Unable to determine stack component information.",
+		$stack_id,$PS_EXIT_PROG_ERROR);
+    my $stackData2= parse_md_list($stackData);
+
+    my $stack = ${ $stackData2 }[0];
+    my $reduction = $stack->{reduction};
+    $reduction = 'DEFAULT' unless defined($reduction);
+    my $workdir   = $stack->{workdir};
+    my $tess_id   = $stack->{tess_id};
+    my $skycell_id= $stack->{skycell_id};
+
+    my $ipp_outroot    = "${workdir}/${tess_id}/${skycell_id}/${tess_id}.${skycell_id}.stk.${stack_id}";    
+    my $remote_outroot = uri_local_to_remote($ipp_outroot);    
+    my $remote_outdir  = uri_local_to_remote("${workdir}/${tess_id}/${skycell_id}");
+    # This actually returns all the individual stack/skyfiles that comprise this run.  Because consistency.
+    my $command = "$stacktool -inputskyfile -stack_id $stack_id ";
+
+    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+	run(command => $command, verbose => 0);
+    unless ($success) {
+	$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+	&my_die("Unable to run stacktool -inputskyfile ",
+		$stack_id,$error_code);
+    }
+
+    my $warpData = $mdcParser->parse(join "", @$stdout_buf) or
+	&my_die("Unable to determine stack component information.",
+		$stack_id,$PS_EXIT_PROG_ERROR);
+    my $warpData2= parse_md_list($warpData);
+
+#
+# Step 3: Iterate over the sub-components
+    my $warp_path_base_string = "";
+    foreach my $warpEntry ( @{ $warpData2 } ) {
+	my $warp_path_base = $warpEntry->{path_base};
+	my $remote_path_base = uri_local_to_remote($warp_path_base);
+	$warp_path_base_string .= " $remote_path_base ";
+    }
+    my $mk_mdc_command = "mkdir -p $remote_outdir && sc_mk_stack_mdc.pl $warp_path_base_string > ${remote_outroot}.in.mdc";
+    my $recipe_ppstack = $ipprc->reduction($reduction, 'STACK_PPSTACK'); # Recipe to use                                                                          
+    my $ppstack_command  = " ppStack -input ${remote_outroot}.in.mdc ";
+    $ppstack_command    .= " ${remote_outroot} -stats ${remote_outroot}.stats ";
+    $ppstack_command    .= " -recipe PPSTACK $recipe_ppstack ";
+    $ppstack_command    .= " -recipe PPSUB STACK_1DG -recipe PSPHOT STACK -recipe PPSTATS STACKSTATS ";
+    $ppstack_command    .= " -stack-type DEEP_STACK -F PSPHOT.PSF.SAVE PSPHOT.PSF.SKY.SAVE ";
+    $ppstack_command    .= " -F PSPHOT.OUTPUT PSPHOT.OUT.CMF.MEF -F PSPHOT.BACKMDL PSPHOT.BACKMDL.MEF ";
+    $ppstack_command    .= " -F SOURCE.PLOT.MOMENTS SOURCE.PLOT.SKY.MOMENTS -F SOURCE.PLOT.PSFMODEL SOURCE.PLOT.SKY.PSFMODEL ";
+    $ppstack_command    .= " -F SOURCE.PLOT.APRESID SOURCE.PLOT.SKY.APRESID -R PPSTACK.OUTPUT FITS.TYPE COMP_STACK ";
+    $ppstack_command    .= " -R PPSTACK.OUTPUT.VARIANCE FITS.TYPE COMP_STACK  -R PPSTACK.UNCONV FITS.TYPE COMP_STACK ";
+    $ppstack_command    .= " -R PPSTACK.UNCONV.VARIANCE FITS.TYPE COMP_STACK";
+    $ppstack_command    .= " -tracedest ${remote_outroot}.trace -log ${remote_outroot}.log ";
+    $ppstack_command    .= " -threads 10 ";
+    $ppstack_command    .= " -dumpconfig ${remote_outroot}.mdc ";
+    $ppstack_command    .= " -stack_id $stack_id -skycell_id $skycell_id -tess_id $tess_id ";
+
+    my $post_cmd_echo = " echo -n \"stacktool  -addsumskyfile -stack_id $stack_id ";
+    $post_cmd_echo   .= " -path_base $ipp_outroot -uri UNKNOWN ";
+    $post_cmd_echo   .=  " -dbname $dbname " if defined $dbname;
+    $post_cmd_echo   .= " -hostname $remote_hostname -dtime_script 0 \" > ${remote_outroot}.dbinfo ";
+	
+    my $post_cmd_SfM  = " ppStatsFromMetadata ${remote_outroot}.stats - STACK_SKYCELL >> ${remote_outroot}.dbinfo ";
+
+    print CONFIG "${mk_mdc_command} && ${ppstack_command} && ${post_cmd_echo} && ${post_cmd_SfM} ";
+    $job_index++;
+
+    # Determine which output files need to be returned
+    foreach my $component(@return_component_list) {
+	my $filename = $ipprc->filename($component,$ipp_outroot);
+	my ($ipp_disk, $remote_disk) = uri_to_outputs_for_return( $filename);
+	my $remote_outroot_dir = dirname($ipp_disk);
+	print CONFIG " && mkdir -p ${remote_root}/tmp/${remote_outroot_dir} && ln -sf $remote_disk ${remote_root}/tmp/${ipp_disk} ";
+    }
+
+#     my $cleanup_cmd   = " (rm -f /scratch3/watersc1/sys_temp/${tess_id}.${skycell_id}.stk.${stack_id}.*conv.*.fits || true) ";    
+#     print CONFIG " && ${cleanup_cmd} \n";
+
+    print CONFIG "\n";
+}
+close(CONFIG);
+close(TRANSFER);
+close(CHECK);
+close(RETURN);
+close(GENERATE);
+
+#
+# Construct the moab command last, so we can use the job_index counter to estimate resources.  Somehow.
+my $proc_need = $job_index * $threads;       # how many total processors do we need?
+my $node_need = $proc_need / $proc_per_node; # this equals how many nodes?
+my $time_need = $job_index * $job_cost;      # How many seconds will this take?
+
+my $fill_factor = 0.8;  # This is the factor of how much of the time allocation we'd like to fill
+my ($time_req,$node_req);
+if ($node_need * $job_cost < $fill_factor * $min_nodes * $min_time) {
+    $time_req = $min_time;
+    $node_req = $min_nodes;
+}
+elsif ($node_need * $job_cost > $fill_factor * $max_nodes * $max_time) {
+    $time_req = $max_time;
+    $node_req = $max_nodes;
+    print STDERR "You've requested the construction of a bundle that appears to need $node_need nodes and $job_cost time per job.  This exceeds the max limits ($max_nodes, $max_time).  Using those max values instead.  Good luck.\n";
+}
+else {
+    $time_req = int(($node_need * $job_cost) / ($fill_factor * $max_nodes)) + 1;
+    $node_req = int(($node_need * $job_cost) / ($fill_factor * $time_req)) + 1;
+}
+
+$time_req += 2;
+$node_req *= 3;
+open(COMMAND,  ">$disk_command") || &my_die("Couldn't open file? $disk_command",$remote_id,$PS_EXIT_SYS_ERROR);
+print COMMAND "#!/bin/tcsh\n";
+print COMMAND "##### Moab controll lines\n";
+print COMMAND "#MSUB -l nodes=${node_req}:ppn=${proc_per_node},walltime=${time_req}:00:00\n"; ## CHECK RESOURCES
+print COMMAND "#MSUB -j oe\n";
+print COMMAND "#MSUB -V\n";
+print COMMAND "#MSUB -o ${remote_root}stack.${remote_id}.out\n";
+print COMMAND "date\n";
+print COMMAND 'srun -n $SLURM_JOB_NUM_NODES -m cyclic -l /bin/hostname | sort -n | awk \'{printf "%s\n", $2}\' > hosts.${SLURM_JOB_ID}' . "\n";
+print COMMAND "${remote_root}/stask_chip.py $remote_config " . 'hosts.${SLURM_JOB_ID} 3' . "\n";
+print COMMAND "date\n";
+close(COMMAND);
+
+unless($no_update) {
+    my $command = "remotetool -updaterun -remote_id $remote_id ";
+    $command .= " -set_state pending ";
+    $command .= " -dbname $dbname " if defined $dbname;
+
+    system($command);
+}
+
+
+## Common SC routines
+
+sub uri_convert { # (ipp_disk,remote_disk) = uri_convert(neb_uri);
+    my $neb_uri = shift;
+    my $ipp_disk= $ipprc->file_resolve( $neb_uri );
+    my $remote_disk = $ipp_disk;
+    
+    unless(defined($ipp_disk)) {
+        my_die();
+    }
+
+    $remote_disk =~ s%^.*/%%;   # Remove nebulous path
+    $remote_disk =~ s%^\d+\.%%; # Remove ins_id
+    $remote_disk =~ s%:%/%g;    # Replace colons with directories
+    $remote_disk = "${remote_root}/${remote_disk}";
+    return($ipp_disk,$remote_disk);
+}
+
+sub uri_convert_and_create { # (ipp_disk,remote_disk) = uri_convert_and_create(neb_uri); ipp_disk is created if it doesn't exist
+    my $neb_uri = shift;
+    my $ipp_disk= $ipprc->file_resolve( $neb_uri , 1);
+    my $remote_disk = $ipp_disk;
+    
+    unless(defined($ipp_disk)) {
+        my_die();
+    }
+
+    $remote_disk =~ s%^.*/%%;   # Remove nebulous path
+    $remote_disk =~ s%^\d+\.%%; # Remove ins_id
+    $remote_disk =~ s%:%/%g;    # Replace colons with directories
+    $remote_disk = "${remote_root}/${remote_disk}";
+    return($ipp_disk,$remote_disk);
+}
+
+sub uri_to_outputs { # (ipp_disk,remote_disk) = uri_to_output(neb_uri); Appends to TRANSFER and CHECK filehandles
+    my $neb_uri = shift;
+    my ($ipp_disk, $remote_disk) = uri_convert( $neb_uri );
+    
+    unless (exists($file_filter{$neb_uri})) {
+        $file_filter{$neb_uri} = 1;
+        print TRANSFER "$ipp_disk\n";
+        print CHECK    "$remote_disk\n";
+    }
+    return($ipp_disk,$remote_disk);
+}
+
+sub uri_to_outputs_for_return { # (ipp_disk,remote_disk) = uri_to_outputs_for_return(neb_uri); create ipp_disk, append to RETURN and GENERATE
+    my $neb_uri = shift;
+    my ($ipp_disk, $remote_disk) = uri_convert_and_create( $neb_uri );
+    unless (exists($file_filter{$neb_uri})) {
+        $file_filter{$neb_uri} = 1;
+        print RETURN "$ipp_disk\n";
+        print GENERATE "$remote_disk\n";
+    }
+    return($ipp_disk,$remote_disk);
+}
+
+sub uri_local_to_remote { #(remote_uri) = uri_local_to_remote(local_neb_uri);
+    # This needs to replace the nebulous tag with the remote root.
+    my $local_uri = shift;
+    $local_uri =~ s%^.*?/%%; # neb:/
+    $local_uri =~ s%^.*?/%%; # /
+    $local_uri =~ s%^.*?/%%; # @HOST@.0/
+    my $remote_uri = "${remote_root}/" . $local_uri;
+
+    return($remote_uri);
+}
+ 
+sub uri_remote_to_local { #(local_neb_uri) = uri_remote_to_local(remote_uri);
+    # This needs to replace the remote root directory with the nebulous tag.
+    my $remote_uri = shift;
+    $remote_uri =~ s%${remote_root}%%;
+    my $local_uri  = "neb:///" . $remote_uri;
+    
+    return($local_uri);
+}
+
+
+sub my_die { # exit with status; my_die(message,stage_id,exit_code,exit_status);
+    my $msg = shift;
+    my $id  = shift;
+    my $exit_code = shift;
+    my $exit_state = shift;
+
+    $exit_code = $PS_EXIT_PROG_ERROR unless defined $exit_code;
+
+    carp($msg);
+    
+    if (defined $id and not $no_update) {
+        my $command = "remotetool -updaterun -stage_id $id";
+        $command .= " -fault $exit_code " if defined $exit_code;
+        $command .= " -set_state $exit_state " if defined $exit_state;
+        $command .= " -dbname $dbname " if defined $dbname;
+
+        system($command);
+    }
+
+    exit($exit_code);
+}
Index: /branches/eam_branches/ipp-20140610/ippScripts/scripts/sc_prepare_warp.pl
===================================================================
--- /branches/eam_branches/ipp-20140610/ippScripts/scripts/sc_prepare_warp.pl	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/ippScripts/scripts/sc_prepare_warp.pl	(revision 36884)
@@ -199,5 +199,5 @@
 	$pswarp_command    .= " -recipe PSWARP $recipe_pswarp ";
 	$pswarp_command    .= " -tracedest ${remote_outroot}.trace -log ${remote_outroot}.log ";
-	$pswarp_command    .= " -threads $threads "; # -image_id ${image_id} -source_id ${source_id} ";
+	$pswarp_command    .= " -threads 4 "; # -image_id ${image_id} -source_id ${source_id} ";
 	$pswarp_command    .= " -recipe PPSTATS WARPSTATS ";
 	$pswarp_command    .= " -dumpconfig ${remote_outroot}.mdc -stats ${remote_outroot}.stats ";
Index: /branches/eam_branches/ipp-20140610/ippTasks/Makefile.am
===================================================================
--- /branches/eam_branches/ipp-20140610/ippTasks/Makefile.am	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/ippTasks/Makefile.am	(revision 36884)
@@ -49,4 +49,5 @@
 	vp.pro \
 	bg.regeneration.pro \
+	remote.pro \
 	fullforce.pro
 
Index: /branches/eam_branches/ipp-20140610/ippTasks/remote.pro
===================================================================
--- /branches/eam_branches/ipp-20140610/ippTasks/remote.pro	(revision 36884)
+++ /branches/eam_branches/ipp-20140610/ippTasks/remote.pro	(revision 36884)
@@ -0,0 +1,379 @@
+## remote.pro : -*- sh -*-
+
+check.globals
+
+# define chips
+
+book init remotePrepRuns
+book init remoteExecRuns
+book init remotePollRuns
+
+$remote_label_iter = 0
+$remote_stage_iter = 0
+$remoteP_DB = 0
+$remoteE_DB = 0
+$remoteL_DB = 0
+
+list STAGES
+  chip
+  camera
+  warp
+  stack
+end
+
+task          remote.define.chip
+  host        local
+  periods     -poll $LOADPOLL
+  periods     -exec $LOADEXEC
+  periods     -timeout 30
+  npending    1
+
+  task.exec
+    stdout NULL
+    stderr $LOGDIR/remote.define.chip
+
+    $label = $LABEL:$remote_label_iter
+
+    $stage = $STAGES:$remote_stage_iter
+    $remote_stage_iter ++
+
+    if ($remote_stage_iter >= $STAGES:n) 
+       set remote_stage_iter = 0
+       $remote_label_iter ++
+       if ($remote_label_iter >= $LABEL:n) set remote_label_iter = 0
+       echo $remote_stage_iter $remote_label_iter $label $stage
+    end
+
+    $run = remotetool -definebyquery -label $label -stage $stage -path_base neb://@HOST@.0/remote/$label
+    echo $run
+    command $run
+    
+    end
+    # success
+    task.exit  0
+  end
+  # locked list                                                                                                                                    
+  task.exit    default
+    showcommand failure
+  end
+  task.exit    crash
+    showcommand crash
+  end
+  #operation times out?                                                                                                                            
+  task.exit    timeout
+    showcommand timeout
+  end
+end
+
+
+task         remote.prep.load
+  host       local
+  periods    -poll $LOADPOLL
+  periods    -exec $LOADEXEC
+  npending   1
+
+  task.exec
+    stdout NULL
+    stderr $LOGDIR/remote.prep.load
+
+    $run = remotetool -listrun -state new
+
+    if ($DB:n == 0)
+      option DEFAULT
+    else
+      option $DB:$remoteP_DB
+      $run = $run -dbname $DB:$remoteP_DB
+      $remoteP_DB ++
+      if ($remoteP_DB >= $DB:n) set remoteP_DB = 0
+    end
+
+    add_poll_labels run
+    command $run
+  end
+  # success
+  task.exit  0
+    ipptool2book stdout remotePrepRuns -uniq -key remote_id -setword dbname $options:0 -setword pantaskState INIT
+    process_cleanup remotePrepRuns
+
+    if ($VERBOSE > 2)
+      book listbook remotePrepRuns
+    end
+  end
+  # locked list
+  task.exit    default
+    showcommand failure
+  end
+  task.exit    crash
+    showcommand crash
+  end
+  #operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
+
+task           remote.prep.run
+  # this probably shouldn't be local
+  host         local
+  periods      -poll $LOADPOLL
+  periods      -exec $LOADEXEC
+  periods      -timeout 60000
+  active       true
+  npending     10
+
+  task.exec
+    stdout $LOGDIR/remote.prep.run
+    stderr $LOGDIR/remote.prep.run
+
+    book npages remotePrepRuns -var N
+    if ($N == 0) break
+    if ($NETWORK == 0) break
+
+    book getpage remotePrepRuns 0 -var pageName -key pantaskState INIT
+    if ("$pageName" == "NULL") break
+
+    book setword remotePrepRuns $pageName pantaskState RUN
+    book getword remotePrepRuns $pageName remote_id -var REMOTE_ID
+    book getword remotePrepRuns $pageName stage     -var STAGE
+    book getword remotePrepRuns $pageName path_base -var PATH_BASE
+#    book getword remotePrepRuns $pageName label     -var LABEL
+    book getword remotePrepRuns $pageName dbname    -var DBNAME
+
+    sprintf outroot "%s/remote_%s.%s" $PATH_BASE $STAGE $REMOTE_ID
+
+    if ("$STAGE" == "chip")
+      $command = sc_prepare_chip.pl --camera GPC1 --remote_id $REMOTE_ID --path_base $outroot --dbname $DBNAME
+    end
+    if ("$STAGE" == "camera")
+      $command = sc_prepare_camera.pl --camera GPC1 --remote_id $REMOTE_ID --path_base $outroot --dbname $DBNAME
+    end
+    if ("$STAGE" == "warp")
+      $command = sc_prepare_warp.pl --camera GPC1 --remote_id $REMOTE_ID --path_base $outroot --dbname $DBNAME
+    end
+    if ("$STAGE" == "stack")
+      $command = sc_prepare_stack.pl --camera GPC1 --remote_id $REMOTE_ID --path_base $outroot --dbname $DBNAME
+    end
+
+    options $pageName
+    command $command
+  end
+
+  # default exit status
+  task.exit    default
+    process_exit remotePrepRuns $options:0 $JOB_STATUS
+  end
+  # locked list
+  task.exit    crash
+    process_exit remotePrepRuns $options:0 $EXIT_CRASH_ERR
+  end
+
+  # operation timed out?
+  task.exit    timeout
+    showcommand timeout
+    book setword remotePrepRuns $options:0 pantaskState TIMEOUT
+  end
+end
+
+
+task         remote.exec.load
+  host       local
+  periods    -poll $LOADPOLL
+  periods    -exec $LOADEXEC
+  npending   1
+
+  task.exec
+    stdout NULL
+    stderr $LOGDIR/remote.exec.load
+
+#    $end_date = `date +%Y-%m-%dT%H:%M:%S`
+    $run = remotetool -listrun -state pending 
+# -poll_end $end_date
+
+    if ($DB:n == 0)
+      option DEFAULT
+    else
+      option $DB:$remoteE_DB
+      $run = $run -dbname $DB:$remoteE_DB
+      $remoteE_DB ++
+      if ($remoteE_DB >= $DB:n) set remoteE_DB = 0
+    end
+
+    add_poll_labels run
+    command $run
+  end
+  # success
+  task.exit  0
+    ipptool2book stdout remoteExecRuns -uniq -key remote_id -setword dbname $options:0 -setword pantaskState INIT
+    process_cleanup remoteExecRuns
+
+    if ($VERBOSE > 2)
+      book listbook remoteExecRuns
+    end
+  end
+  # locked list
+  task.exit    default
+    showcommand failure
+  end
+  task.exit    crash
+    showcommand crash
+  end
+  #operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
+
+task           remote.exec.run
+  # this probably shouldn't be local
+  host         local
+  periods      -poll $LOADPOLL
+  periods      -exec $LOADEXEC
+  periods      -timeout 60000
+  active       true
+  npending     1
+
+  task.exec
+    stdout $LOGDIR/remote.exec.run
+    stderr $LOGDIR/remote.exec.run
+
+    book npages remoteExecRuns -var N
+    if ($N == 0) break
+    if ($NETWORK == 0) break
+
+    book getpage remoteExecRuns 0 -var pageName -key pantaskState INIT
+    if ("$pageName" == "NULL") break
+
+    book setword remoteExecRuns $pageName pantaskState RUN
+    book getword remoteExecRuns $pageName remote_id -var REMOTE_ID
+    book getword remoteExecRuns $pageName stage     -var STAGE
+    book getword remoteExecRuns $pageName path_base -var PATH_BASE
+#    book getword remoteExecRuns $pageName label     -var LABEL
+    book getword remoteExecRuns $pageName job_id    -var JOB_ID
+    book getword remoteExecRuns $pageName dbname    -var DBNAME
+
+    sprintf outroot "%s/remote_%s.%s" $PATH_BASE $STAGE $REMOTE_ID
+
+    $command = sc_remote_exec.pl --remote_id $REMOTE_ID --path_base $outroot --verbose --dbname $DBNAME --camera GPC1
+
+    options $pageName
+    command $command
+  end
+
+  # default exit status
+  task.exit    default
+    process_exit remoteExecRuns $options:0 $JOB_STATUS
+  end
+  # locked list
+  task.exit    crash
+    process_exit remoteExecRuns $options:0 $EXIT_CRASH_ERR
+  end
+
+  # operation timed out?
+  task.exit    timeout
+    showcommand timeout
+    book setword remoteExecRuns $options:0 pantaskState TIMEOUT
+  end
+end
+
+
+task         remote.poll.load
+  host       local
+  periods    -poll $LOADPOLL
+  periods    -exec $LOADEXEC
+  npending   1
+
+  task.exec
+    stdout NULL
+    stderr $LOGDIR/remote.poll.load
+
+    $end_date = `date +%Y-%m-%dT%H:%M:%S -d '1 hour ago'`
+    $run = remotetool -listrun -state run -poll_end $end_date
+
+    if ($DB:n == 0)
+      option DEFAULT
+    else
+      option $DB:$remoteL_DB
+      $run = $run -dbname $DB:$remoteL_DB
+      $remoteL_DB ++
+      if ($remoteL_DB >= $DB:n) set remoteL_DB = 0
+    end
+
+    add_poll_labels run
+    command $run
+  end
+  # success
+  task.exit  0
+    ipptool2book stdout remotePollRuns -uniq -key remote_id -setword dbname $options:0 -setword pantaskState INIT
+    process_cleanup remotePollRuns
+
+    if ($VERBOSE > 2)
+      book listbook remotePollRuns
+    end
+  end
+  # locked list
+  task.exit    default
+    showcommand failure
+  end
+  task.exit    crash
+    showcommand crash
+  end
+  #operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
+
+task           remote.poll.run
+  # this probably shouldn't be local
+  host         local
+  periods      -poll $LOADPOLL
+  periods      -exec $LOADEXEC
+  periods      -timeout 60000
+  active       true
+  npending     1
+
+  task.exec
+    stdout $LOGDIR/remote.poll.run
+    stderr $LOGDIR/remote.poll.run
+
+    book npages remotePollRuns -var N
+    if ($N == 0) break
+    if ($NETWORK == 0) break
+
+    book getpage remotePollRuns 0 -var pageName -key pantaskState INIT
+    if ("$pageName" == "NULL") break
+
+    book setword remotePollRuns $pageName pantaskState RUN
+    book getword remotePollRuns $pageName remote_id -var REMOTE_ID
+    book getword remotePollRuns $pageName stage     -var STAGE
+    book getword remotePollRuns $pageName path_base -var PATH_BASE
+#    book getword remotePollRuns $pageName label     -var LABEL
+    book getword remotePollRuns $pageName job_id    -var JOB_ID
+    book getword remotePollRuns $pageName dbname    -var DBNAME
+
+    sprintf outroot "%s/remote_%s.%s" $PATH_BASE $STAGE $REMOTE_ID
+
+    # This can't have an invalid job_id
+    if ($JOB_ID == -1) break
+    $command = sc_remote_exec.pl --remote_id $REMOTE_ID --path_base $outroot --verbose --dbname $DBNAME --camera GPC1 --poll --job_id $JOB_ID
+
+    options $pageName
+    command $command
+  end
+
+  # default exit status
+  task.exit    default
+    process_exit remotePollRuns $options:0 $JOB_STATUS
+  end
+  # locked list
+  task.exit    crash
+    process_exit remotePollRuns $options:0 $EXIT_CRASH_ERR
+  end
+
+  # operation timed out?
+  task.exit    timeout
+    showcommand timeout
+    book setword remotePollRuns $options:0 pantaskState TIMEOUT
+  end
+end
+
Index: /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/Detection
===================================================================
--- /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/Detection	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/Detection	(revision 36884)
@@ -8,5 +8,5 @@
 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
@@ -40,5 +40,5 @@
 momentYY        arcsec^2        REAL    4       -999    momeny YY
 momentR1        arcsec          REAL    4       -999    first radial moment 
-momentRH        arcsec          REAL    4       -999    half light radius 
+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) 
@@ -51,8 +51,9 @@
 kronFluxErr     adu/seconds     REAL    4       -999    Kron flux error
 kronRad         arcsec      	REAL    4       -999    Kron radius
-kronRadErr      arcsec      	REAL    4       -999    Kron radius error
+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   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: /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/Detection.txt
===================================================================
--- /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/Detection.txt	(revision 36884)
+++ /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/Detection.txt	(revision 36884)
@@ -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-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetObject
===================================================================
--- /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetObject	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetObject	(revision 36884)
@@ -2,5 +2,5 @@
 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
+diffgcObjID	dimensionless	BIGINT	8       NA 	ODM galactic coordinates identifier
 ippObjID  	dimensionless 	BIGINT 	8 	NA 	IPP object number
 surveyID 	dimensionless 	TINYINT 1 	255 	Survey ID
@@ -10,8 +10,8 @@
 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
+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
Index: /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetObject.txt
===================================================================
--- /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetObject.txt	(revision 36884)
+++ /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetObject.txt	(revision 36884)
@@ -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-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetection
===================================================================
--- /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetection	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetection	(revision 36884)
@@ -1,4 +1,5 @@
+
 diffObjID	dimensionless 	BIGINT 	8 	NA 	diff object identifier
-diffgcObjID		dimensionless	BIGINT	8	  NA 	ODM galactic coordinates 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
@@ -9,5 +10,5 @@
 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
@@ -41,5 +42,5 @@
 momentYY 	arcsec^2     	REAL 	4 	-999 	momeny YY
 momentR1 	arcsec       	REAL 	4 	-999 	first radial moment 
-momentRH 	arcsec       	REAL 	4 	-999 	half light radius  
+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) 
@@ -66,4 +67,5 @@
 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: /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetection.txt
===================================================================
--- /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetection.txt	(revision 36884)
+++ /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/DiffDetection.txt	(revision 36884)
@@ -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-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedMeanObject
===================================================================
--- /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedMeanObject	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedMeanObject	(revision 36884)
@@ -1,4 +1,5 @@
+
 objID           dimensionless   BIGINT   8        NA    ODM object identifier index
-gcObjID		dimensionless	BIGINT	8	  NA 	ODM galactic coordinates identifier
+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
Index: /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedMeanObject.txt
===================================================================
--- /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedMeanObject.txt	(revision 36884)
+++ /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedMeanObject.txt	(revision 36884)
@@ -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-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedWarpMeasurement
===================================================================
--- /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedWarpMeasurement	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedWarpMeasurement	(revision 36884)
@@ -1,4 +1,4 @@
 objID           dimensionless   BIGINT  8       NA      ODM object identifier
-gcObjID		dimensionless	BIGINT	8	  NA 	ODM galactic coordinates 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
@@ -9,5 +9,5 @@
 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
 ------------------------------------------------------ 
@@ -31,5 +31,5 @@
 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  
+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) 
Index: /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedWarpMeasurement.txt
===================================================================
--- /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedWarpMeasurement.txt	(revision 36884)
+++ /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ForcedWarpMeasurement.txt	(revision 36884)
@@ -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-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/MeanObject
===================================================================
--- /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/MeanObject	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/MeanObject	(revision 36884)
@@ -4,5 +4,5 @@
 
 objID           dimensionless   BIGINT  8       NA      ODM object identifier index
-gcObjID		dimensionless	BIGINT	8	  NA 	ODM galactic coordinates identifier
+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"  
Index: /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/MeanObject.txt
===================================================================
--- /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/MeanObject.txt	(revision 36884)
+++ /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/MeanObject.txt	(revision 36884)
@@ -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-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ObjectThin
===================================================================
--- /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ObjectThin	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ObjectThin	(revision 36884)
@@ -10,9 +10,9 @@
 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
-consistencyFlag  dimensionless  SMALLINT 2      0       Value computed from associated detections, it is originally given by IPP and should agree with the ODM validation
+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 
Index: /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ObjectThin.txt
===================================================================
--- /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ObjectThin.txt	(revision 36884)
+++ /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/ObjectThin.txt	(revision 36884)
@@ -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-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackApFlx
===================================================================
--- /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackApFlx	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackApFlx	(revision 36884)
@@ -1,5 +1,6 @@
 
 objID            dimensionless  BIGINT  8       NA      ODM object identifier
-gcObjID		dimensionless	BIGINT	8	  NA 	ODM galactic coordinates 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 
@@ -9,11 +10,10 @@
 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
Index: /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackApFlx.txt
===================================================================
--- /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackApFlx.txt	(revision 36884)
+++ /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackApFlx.txt	(revision 36884)
@@ -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-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFit
===================================================================
--- /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFit	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFit	(revision 36884)
@@ -1,5 +1,6 @@
 
 objID            dimensionless  BIGINT  8       NA      ODM object identifier
-gcObjID		dimensionless	BIGINT	8	  NA 	ODM galactic coordinates 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 
@@ -9,15 +10,19 @@
 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   
+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
-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
Index: /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFit.txt
===================================================================
--- /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFit.txt	(revision 36884)
+++ /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackModelFit.txt	(revision 36884)
@@ -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-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackObject
===================================================================
--- /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackObject	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackObject	(revision 36884)
@@ -1,5 +1,6 @@
 
 objID             dimensionless   BIGINT  8       NA      ODM object identifier
-gcObjID		dimensionless	BIGINT	8	  NA 	ODM galactic coordinates 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 
@@ -9,5 +10,5 @@
 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.
 ------------------------------------------------------------------------------------------
@@ -15,8 +16,8 @@
 -- 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
@@ -41,5 +42,5 @@
 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
+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
@@ -58,5 +59,6 @@
 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
 
Index: /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackObject.txt
===================================================================
--- /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackObject.txt	(revision 36884)
+++ /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/StackObject.txt	(revision 36884)
@@ -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-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/changes.r36847
===================================================================
--- /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/changes.r36847	(revision 36884)
+++ /branches/eam_branches/ipp-20140610/ippToPsps/pspsschema/SchemaNew16.0/PSPS_TABLES/Fundamental_IPP_Data_Product_Tables/changes.r36847	(revision 36884)
@@ -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-20140610/ippTools/share/remotetool_definebyquery_cam.sql
===================================================================
--- /branches/eam_branches/ipp-20140610/ippTools/share/remotetool_definebyquery_cam.sql	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/ippTools/share/remotetool_definebyquery_cam.sql	(revision 36884)
@@ -9,4 +9,4 @@
 WHERE
 camRun.state = 'new' AND
-remoteRun.stage = 'camera' AND
-remote_id IS NULL
+(remoteRun.stage = 'camera' OR remoteRun.state IS NULL) AND
+remoteComponent.remote_id IS NULL
Index: /branches/eam_branches/ipp-20140610/ippTools/share/remotetool_definebyquery_stack.sql
===================================================================
--- /branches/eam_branches/ipp-20140610/ippTools/share/remotetool_definebyquery_stack.sql	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/ippTools/share/remotetool_definebyquery_stack.sql	(revision 36884)
@@ -9,4 +9,4 @@
 WHERE
 stackRun.state = 'new' AND
-remoteRun.stage = 'stack' AND
-remote_id IS NULL
+(remoteRun.stage = 'stack' OR remoteRun.state IS NULL) AND
+remoteComponent.remote_id IS NULL
Index: /branches/eam_branches/ipp-20140610/ippTools/share/remotetool_definebyquery_warp.sql
===================================================================
--- /branches/eam_branches/ipp-20140610/ippTools/share/remotetool_definebyquery_warp.sql	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/ippTools/share/remotetool_definebyquery_warp.sql	(revision 36884)
@@ -9,4 +9,4 @@
 WHERE
 warpRun.state = 'new' AND
-remoteRun.stage = 'warp' AND
-remote_id IS NULL
+(remoteRun.stage = 'warp' OR remoteRun.state IS NULL) AND
+remoteComponent.remote_id IS NULL
Index: /branches/eam_branches/ipp-20140610/ippconfig/gpc1/ppStack.config
===================================================================
--- /branches/eam_branches/ipp-20140610/ippconfig/gpc1/ppStack.config	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/ippconfig/gpc1/ppStack.config	(revision 36884)
@@ -160,5 +160,5 @@
     STACK.TYPE              STR   DEEP_STACK  ## needed?
     PSF.INPUT.CLIP.SIMPLE   BOOL  True
-    PSF.INPUT.MAX           F32   6.0   # never really want >6 pixels in refstack, even on edges 
+    PSF.INPUT.MAX           F32   7.0   # center/edge can vary 1-2 pix, prefer <6 pix but needs to be <7 pix for edges
     PSF.INPUT.CLIP.NSIGMA   F32   1.0   # sample typically on rising side of distribution (set even smaller?)
     PSF.INPUT.THRESH        F32   NAN
@@ -168,4 +168,14 @@
     PSF.TARGET.AS.MAX       BOOL  TRUE      # Set the target PSF FWHM as the maximum of accepted input FWHM values.
     PSF.TARGET.AS.MAX.EPSILON F32 0.1       # Amount to set the target PSF FWHM larger than the maximum input. Target = eps + max(input)
+    THRESHOLD.MASK  F32     0.1             # Threshold for mask deconvolution (0..1)
+    COMBINE.ITER    F32     0.5             # Number of rejection iterations per input
+    COMBINE.REJ     F32     3.0             # Rejection threshold in combination (sigma)
+    COMBINE.SYS     F32     0.1             # Relative systematic error in combination
+    COMBINE.DISCARD F32     0.2             # Discard fraction for Olympic weighted mean
+    IMAGE.REJ       F32     0.1             # Rejected pixel fraction threshold for rejecting entire image
+    NMINPIX         S32     4               # Minimum input per pixel
+    MASK.VAL        STR     SUSPECT,MASK.VALUE,CONV.BAD,GHOST # Mask value of input bad pixels
+    MASK.BLANKBORDER S32    20              # Mask blank border in final stack output
+    BSCALEOFFSET    BOOL    TRUE            # HACK for removing bscale offset from input warps because of compression (0.5*BSCALE)
 END
 
@@ -193,4 +203,5 @@
     MASK.VAL        STR     SUSPECT,MASK.VALUE,CONV.BAD,GHOST # Mask value of input bad pixels
     MASK.BLANKBORDER S32    20              # Mask blank border in final stack output
+    BSCALEOFFSET    BOOL    TRUE            # HACK for removing bscale offset from input warps because of compression (0.5*BSCALE)
 END
 
Index: /branches/eam_branches/ipp-20140610/ippconfig/gpc1/psastro.config
===================================================================
--- /branches/eam_branches/ipp-20140610/ippconfig/gpc1/psastro.config	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/ippconfig/gpc1/psastro.config	(revision 36884)
@@ -122,6 +122,6 @@
 # PSASTRO.CATDIR              STR      SYNTH.GRIZY 
 # PSASTRO.CATDIR		STR	PS1.REF.20120503
-PSASTRO.CATDIR               STR     PS1.REF.20120524
-
+# PSASTRO.CATDIR               STR     PS1.REF.20120524
+PSASTRO.CATDIR               STR     PS1.REF.20140605
 
 DVO.GETSTAR.PHOTCODE        STR      i
@@ -362,6 +362,7 @@
 
 DEFAULT_RECIPE METADATA
-#   PSASTRO.CATDIR               STR     PS1.REF.20120503
-   PSASTRO.CATDIR		STR	PS1.REF.20120524
+#  PSASTRO.CATDIR               STR     PS1.REF.20120503
+#  PSASTRO.CATDIR		STR	PS1.REF.20120524
+   PSASTRO.CATDIR               STR     PS1.REF.20140605
    ZERO.POINT.USE.MEAN		BOOL	TRUE  
 END
@@ -374,7 +375,8 @@
 LAP_ASTRO METADATA
 #  PSASTRO.CATDIR                STR      3PI.20110505.REFCAT
-#   PSASTRO.CATDIR		 STR	  SYNTH.GRIZY
-#   PSASTRO.CATDIR		 STR     PS1.REF.20120503
-   PSASTRO.CATDIR               STR     PS1.REF.20120524
+#  PSASTRO.CATDIR		 STR	  SYNTH.GRIZY
+#  PSASTRO.CATDIR		 STR     PS1.REF.20120503
+#  PSASTRO.CATDIR               STR     PS1.REF.20120524
+   PSASTRO.CATDIR               STR     PS1.REF.20140605
    ZERO.POINT.USE.MEAN		BOOL	TRUE  
 END
@@ -405,5 +407,6 @@
    DVO.GETSTAR.FIXED.ZEROPT    F32   25.0
 
-   PSASTRO.CATDIR               	STR     PS1.REF.20120524
+   PSASTRO.CATDIR               STR     PS1.REF.20140605
+#  PSASTRO.CATDIR               	STR     PS1.REF.20120524
    ZERO.POINT.USE.MEAN          	BOOL    TRUE
    PSASTRO.MAX.NRAW 			S32	0 
@@ -424,5 +427,6 @@
     DVO.GETSTAR.FIXED.ZEROPT    F32   25.0
     DVO.GETSTAR.MIN.MAG.INST	F32   -15.0
-    PSASTRO.CATDIR                       STR     PS1.REF.20120524
+#   PSASTRO.CATDIR                       STR     PS1.REF.20120524
+    PSASTRO.CATDIR               STR     PS1.REF.20140605
     ZERO.POINT.USE.MEAN                  BOOL    TRUE
 
@@ -443,5 +447,6 @@
 # - similar to DEEPCAL except for MIN.NSTAR 5 to attemp more edge skycells if poorer
 STATICSKY_NIGHTCAL   METADATA
-   PSASTRO.CATDIR                  STR   PS1.REF.20120524  # reset here to ensure same catalog is used when reprocessing set uniformly
+#   PSASTRO.CATDIR                  STR   PS1.REF.20120524  # reset here to ensure same catalog is used when reprocessing set uniformly
+   PSASTRO.CATDIR               STR     PS1.REF.20140605
    REFSTAR_MASK                    BOOL  FALSE
    PSASTRO.SAVE.REFMATCH           BOOL  FALSE
@@ -479,5 +484,6 @@
 # revised setup for DEEP/MDS stacks with range of inputs, should work for N~2(edges)--500 inputs with large MIN/MAX.INST.MAG.RAW
 STATICSKY_DEEPCAL   METADATA
-   PSASTRO.CATDIR                  STR   PS1.REF.20120524  # reset here to ensure same catalog is used when reprocessing set uniformly
+   #PSASTRO.CATDIR                  STR   PS1.REF.20120524  # reset here to ensure same catalog is used when reprocessing set uniformly
+   PSASTRO.CATDIR                  STR   PS1.REF.20140605  # ensure same catalog is used when reprocessing MD set uniformly
    REFSTAR_MASK                    BOOL  FALSE
    PSASTRO.SAVE.REFMATCH           BOOL  FALSE
@@ -498,6 +504,6 @@
    DVO.GETSTAR.MAX.RHO		   F32	 6000.0  # N/sqdeg, slightly larger than MAX.NREF 
    DVO.GETSTAR.MIN.MAG.INST        F32   -25.0   # set absurd range to cover large range of exptime, then clamp...
-   DVO.GETSTAR.MIN.MAG		   F32	 15.0    # only used if keyword problem so also using CLAMP_MAG_MIN
-   REFSTAR_CLAMP_MAG_MIN 	   F32	 15.0    # saturation in MD ~14 even in y-band, so toss out brighter in the list
+   DVO.GETSTAR.MIN.MAG		   F32	 16.5    # only used if keyword problem so also using CLAMP_MAG_MIN
+   REFSTAR_CLAMP_MAG_MIN 	   F32	 16.5    # saturation in MD ~14 even in y-band, so toss out brighter in the list. seeing offset in brighter stars
    DVO.GETSTAR.FIXED.ZEROPT        F32   0.0     # not really needed, exptime overly dominates
   
Index: /branches/eam_branches/ipp-20140610/ippconfig/recipes/ppStack.config
===================================================================
--- /branches/eam_branches/ipp-20140610/ippconfig/recipes/ppStack.config	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/ippconfig/recipes/ppStack.config	(revision 36884)
@@ -34,4 +34,5 @@
 TARGET.MINMAG	F32	3.0		# Minimum magnitude difference to tolerate in stamp
 NMINPIX		S32	1 		# Minimum input per pixel 
+BSCALEOFFSET    BOOL    FALSE           # HACK for removing offset from input warps because of compression (0.5*BSCALE)
 
 BACKGROUND.MODEL    BOOL   FALSE        # Construct a stacked version of the warp stage background
Index: /branches/eam_branches/ipp-20140610/ippconfig/recipes/psphot.config
===================================================================
--- /branches/eam_branches/ipp-20140610/ippconfig/recipes/psphot.config	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/ippconfig/recipes/psphot.config	(revision 36884)
@@ -15,5 +15,5 @@
 
 # format for output CMF files
-OUTPUT.FORMAT                       STR   PS1_V3
+OUTPUT.FORMAT                       STR   PS1_V5
 
 # the zero point is used to set a basic scale for DVO
@@ -238,4 +238,6 @@
 
 EXTENDED_SOURCE_MODELS_SELECTION    STR   ALL
+
+LENSING_PARAMETERS                  BOOL  FALSE
 
 # extended source models applied to sources
@@ -492,5 +494,5 @@
   RADIAL_APERTURES                    BOOL  T    # calculate flux in circular radial apertures?
   RADIAL_APERTURES_SN_LIM             F32   0.0  # S/N limit for radial aperture calculation
-  OUTPUT.FORMAT                       STR   PS1_SV2
+  OUTPUT.FORMAT                       STR   PS1_SV3
 
   # subtract radial profiles for extremely bright stars?
@@ -524,5 +526,5 @@
   RADIAL_APERTURES                    BOOL  F    # calculate flux in circular radial apertures?
   RADIAL_APERTURES_SN_LIM             F32   0.0  # S/N limit for radial aperture calculation
-  OUTPUT.FORMAT                       STR   PS1_SV1
+  OUTPUT.FORMAT                       STR   PS1_SV3
 
   EXT_FIT_MAX_RADIUS                  F32   50.0
@@ -731,4 +733,4 @@
     SAVE.BACKMDL            BOOL    FALSE
     SAVE.RESID              BOOL    FALSE
-    OUTPUT.FORMAT           STR     PS1_SV2
-END
+    OUTPUT.FORMAT           STR     PS1_SV3
+END
Index: /branches/eam_branches/ipp-20140610/ppSim/src/ppSimInsertGalaxies.c
===================================================================
--- /branches/eam_branches/ipp-20140610/ppSim/src/ppSimInsertGalaxies.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/ppSim/src/ppSimInsertGalaxies.c	(revision 36884)
@@ -145,5 +145,5 @@
 	    axes.minor       = galaxy->Rmin;
 	    axes.theta       = galaxy->theta;
-	    pmPSF_AxesToModel (PAR, axes, type);
+	    pmPSF_AxesToModel (PAR, axes, model->class->useReff);
 	}
 	psF64 Area = 2.0 * M_PI * galaxy->Rmaj * galaxy->Rmin;
@@ -154,5 +154,5 @@
 
 	// XXX let the flux limit be a user-defined number of sky sigmas (not just 1.0)
-	float radius = model->modelRadius (model->params, 0.1*roughNoise);
+	float radius = model->class->modelRadius (model->params, 0.1*roughNoise);
 	radius = PS_MAX (radius, 1.0);
 
@@ -163,5 +163,5 @@
 	pmSource *source = pmSourceFromModel (model, readout, radius, PM_SOURCE_TYPE_EXTENDED);
 
-	galaxy->flux = model->modelFlux (model->params);
+	galaxy->flux = model->class->modelFlux (model->params);
 
 	// XXX set the mag & err values (should this be done in pmSourceFromModel?)
Index: /branches/eam_branches/ipp-20140610/ppSim/src/ppSimInsertStars.c
===================================================================
--- /branches/eam_branches/ipp-20140610/ppSim/src/ppSimInsertStars.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/ppSim/src/ppSimInsertStars.c	(revision 36884)
@@ -116,5 +116,5 @@
 	// (inserting flux with a variable radius introduces a flux-dependent bias)
 	if (radius < 0) {
-	  radius = model->modelRadius (model->params, nSigmaLim * roughNoise);
+	  radius = model->class->modelRadius (model->params, nSigmaLim * roughNoise);
 	  radius = PS_MAX (radius,  1.0);
 	  radius = PS_MIN (radius, 50.0);
@@ -126,5 +126,5 @@
 	// XXX set the mag & err values (should this be done in pmSourceFromModel?)
 	// XXX i should be applying the gain and the correct effective area
-	psEllipseAxes axes = pmPSF_ModelToAxes (model->params->data.F32, model->type);
+	psEllipseAxes axes = pmPSF_ModelToAxes (model->params->data.F32, model->class->useReff);
 	float Area = 2.0 * M_PI * axes.major * axes.minor;
 
Index: /branches/eam_branches/ipp-20140610/ppStack/src/ppStack.h
===================================================================
--- /branches/eam_branches/ipp-20140610/ppStack/src/ppStack.h	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/ppStack/src/ppStack.h	(revision 36884)
@@ -108,5 +108,6 @@
                          const psVector *addVariance, // Additional variance for rejection
                          bool safety,                 // Enable safety switch?
-                         const psVector *norm         // Normalisations to apply
+                         const psVector *norm,         // Normalisations to apply
+                         const psVector *bscaleApplyOffset  // hack for offset based on bscale
     );
 
Index: /branches/eam_branches/ipp-20140610/ppStack/src/ppStackCombineFinal.c
===================================================================
--- /branches/eam_branches/ipp-20140610/ppStack/src/ppStackCombineFinal.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/ppStack/src/ppStackCombineFinal.c	(revision 36884)
@@ -44,5 +44,5 @@
 
 bool ppStackCombineFinal(ppStackThreadData *stack, psArray *covariances, ppStackOptions *options,
-                         pmConfig *config, bool safe, bool normalise, bool grow)
+                         pmConfig *config, bool safe, bool normalise, bool grow, bool bscaleoffset)
 {
     psAssert(stack, "Require stack");
@@ -107,4 +107,5 @@
         PS_ARRAY_ADD_SCALAR(job->args, safe, PS_TYPE_U8);
         PS_ARRAY_ADD_SCALAR(job->args, normalise, PS_TYPE_U8);
+        PS_ARRAY_ADD_SCALAR(job->args, bscaleoffset, PS_TYPE_U8);
         if (!psThreadJobAddPending(job)) {
             psFree(reject);
Index: /branches/eam_branches/ipp-20140610/ppStack/src/ppStackLoop.c
===================================================================
--- /branches/eam_branches/ipp-20140610/ppStack/src/ppStackLoop.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/ppStack/src/ppStackLoop.c	(revision 36884)
@@ -120,5 +120,5 @@
     psTrace("ppStack", 2, "Final stack of convolved images....\n");
     if (options->convolve) {
-      if (!ppStackCombineFinal(stack, options->convCovars, options, config, false, false, true)) {
+      if (!ppStackCombineFinal(stack, options->convCovars, options, config, false, false, true, false)) {
         psError(psErrorCodeLast(), false, "Unable to perform final combination.");
         psFree(stack);
@@ -128,5 +128,6 @@
     else {
       // Since we haven't convolved, I believe we do need to normalize here.
-      if (!ppStackCombineFinal(stack, options->convCovars, options, config, false, true, true)) {
+      //MEH -- see below for comment on ppStackCombineFinal and bscaleOffset
+      if (!ppStackCombineFinal(stack, options->convCovars, options, config, false, true, true, true)) {
         psError(psErrorCodeLast(), false, "Unable to perform final combination.");
         psFree(stack);
@@ -207,5 +208,8 @@
 	// generate the unconvolved stack. NOTE: this one must be normalized since the inputs have not been
         psTrace("ppStack", 2, "Stack of unconvolved images....\n");
-        if (!ppStackCombineFinal(stack, options->origCovars, options, config, false, true, false)) {
+        //MEH -- terrible hack for bscale offset to input warps -- treat like normalization 
+        // -- if BSCALEOFFSET TRUE, 0.5*bscale for offset values, otherwise value 0.0
+        // -- bscaleOffset set when files read in and applied in CombineFinal (if arg true, only valid for unconv case)
+        if (!ppStackCombineFinal(stack, options->origCovars, options, config, false, true, false, true)) {
             psError(psErrorCodeLast(), false, "Unable to perform unconvolved combination.");
             psFree(stack);
Index: /branches/eam_branches/ipp-20140610/ppStack/src/ppStackLoop.h
===================================================================
--- /branches/eam_branches/ipp-20140610/ppStack/src/ppStackLoop.h	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/ppStack/src/ppStackLoop.h	(revision 36884)
@@ -65,5 +65,6 @@
     bool safe,                          // Allow safe combination?
     bool norm,                          // Normalise images?
-    bool grow                           // Grow rejection masks?
+    bool grow,                           // Grow rejection masks?
+    bool bscaleoffset                   // Apply bscale offset?
     );
 
Index: /branches/eam_branches/ipp-20140610/ppStack/src/ppStackOptions.c
===================================================================
--- /branches/eam_branches/ipp-20140610/ppStack/src/ppStackOptions.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/ppStack/src/ppStackOptions.c	(revision 36884)
@@ -19,4 +19,5 @@
     psFree(options->inputMask);
     psFree(options->sourceLists);
+    psFree(options->bscaleOffset);
     psFree(options->norm);
     psFree(options->sources);
@@ -65,4 +66,5 @@
     options->inputMask = NULL;
     options->sourceLists = NULL;
+    options->bscaleOffset = NULL;
     options->norm = NULL;
     options->sources = NULL;
Index: /branches/eam_branches/ipp-20140610/ppStack/src/ppStackOptions.h
===================================================================
--- /branches/eam_branches/ipp-20140610/ppStack/src/ppStackOptions.h	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/ppStack/src/ppStackOptions.h	(revision 36884)
@@ -35,4 +35,5 @@
     float clippedMean;                  // clipped mean of input fwhm
     float clippedStdev;                 // clipped stdev of input fwhm 
+    psVector *bscaleOffset;             // hack offset of bzero using 0.5*bscale if option, 0.0 if not
     // Convolve
     psArray *cells;                     // Cells for convolved images --- a handle for reading again
Index: /branches/eam_branches/ipp-20140610/ppStack/src/ppStackPrepare.c
===================================================================
--- /branches/eam_branches/ipp-20140610/ppStack/src/ppStackPrepare.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/ppStack/src/ppStackPrepare.c	(revision 36884)
@@ -148,4 +148,9 @@
     }
 
+    //MEH -- bscale offset hack for warps 
+    options->bscaleOffset = psVectorAlloc(options->num, PS_TYPE_F32);
+    psVectorInit(options->bscaleOffset, 0.0);
+    bool setbscaleoffset = psMetadataLookupBool(NULL,recipe, "BSCALEOFFSET");
+
     psArray *psfs = psArrayAlloc(num); // PSFs for PSF envelope
     int numCols = 0, numRows = 0;   // Size of image
@@ -162,4 +167,13 @@
 	}
         options->sumExposure += options->exposures->data.F32[i];
+
+        //MEH -- hdu get redefn again below if conv (lots of this happening..) 
+        if (setbscaleoffset) {
+            pmHDU *hdu = pmHDUFromCell(cell);
+            assert(hdu && hdu->header);
+            float bscale = psMetadataLookupF32(NULL, hdu->header, "BSCALE");
+            options->bscaleOffset->data.F32[i] = 0.5*bscale;
+        }
+        psLogMsg("ppStack", PS_LOG_INFO, "bscaleOffset: %d %f", i,options->bscaleOffset->data.F32[i]);
 
         // Get list of PSFs, to determine target PSF
Index: /branches/eam_branches/ipp-20140610/ppStack/src/ppStackReadout.c
===================================================================
--- /branches/eam_branches/ipp-20140610/ppStack/src/ppStackReadout.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/ppStack/src/ppStackReadout.c	(revision 36884)
@@ -34,4 +34,5 @@
     bool safety = PS_SCALAR_VALUE(args->data[4], U8);    // Safety switch on?
     bool normalise = PS_SCALAR_VALUE(args->data[5], U8); // Normalise images?
+    bool bscaleoffset = PS_SCALAR_VALUE(args->data[6], U8); // Apply bscale offset?
 
     psVector *mask = options->inputMask; // Mask for inputs
@@ -40,7 +41,8 @@
     psVector *addVariance = options->matchChi2; // Additional variance when rejecting
     psVector *norm = normalise ? options->norm : NULL; // Normalisations to apply to images
+    psVector *bscaleApplyOffset = bscaleoffset ? options->bscaleOffset : NULL; // BSCALE offset to apply to images
 
     bool status = ppStackReadoutFinal(config, options->outRO, options->expRO, thread->readouts, mask, reject,
-                                      weightings, exposures, addVariance, safety, norm); // Status of operation
+                                      weightings, exposures, addVariance, safety, norm, bscaleApplyOffset); // Status of operation
 
     thread->busy = false;
@@ -201,5 +203,5 @@
                          const psVector *mask, const psArray *rejected, const psVector *weightings,
                          const psVector *exposures, const psVector *addVariance, bool safety,
-                         const psVector *norm)
+                         const psVector *norm, const psVector *bscaleApplyOffset)
 {
     assert(config);
@@ -271,4 +273,10 @@
         stack->data[i] = data;
 
+        //MEH -- apply bscale offset before norm   
+        if (bscaleApplyOffset) {
+            psLogMsg("ppStack", PS_LOG_INFO, "bscaleApplyOffset: %d %f", i, bscaleApplyOffset->data.F32[i]);
+            psBinaryOp(ro->image, ro->image, "-", psScalarAlloc(bscaleApplyOffset->data.F32[i], PS_TYPE_F32));
+        }
+
         if (norm) {
             float normalise = powf(10.0, -0.4 * norm->data.F32[i]); // Normalisation
Index: /branches/eam_branches/ipp-20140610/ppStack/src/ppStackThread.c
===================================================================
--- /branches/eam_branches/ipp-20140610/ppStack/src/ppStackThread.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/ppStack/src/ppStackThread.c	(revision 36884)
@@ -277,5 +277,5 @@
 
     {
-        psThreadTask *task = psThreadTaskAlloc("PPSTACK_FINAL_COMBINE", 6);
+        psThreadTask *task = psThreadTaskAlloc("PPSTACK_FINAL_COMBINE", 7);
         task->function = &ppStackReadoutFinalThread;
         psThreadTaskAdd(task);
Index: /branches/eam_branches/ipp-20140610/ppViz/src/ppVizPSF/ppVizPSFLoop.c
===================================================================
--- /branches/eam_branches/ipp-20140610/ppViz/src/ppVizPSF/ppVizPSFLoop.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/ppViz/src/ppVizPSF/ppVizPSFLoop.c	(revision 36884)
@@ -117,5 +117,5 @@
 
                         pmModel *model = pmModelFromPSFforXY(psf, xSrc, ySrc, 1.0); // Model for normalisation
-                        float fluxNorm = model->modelFlux(model->params);               // Flux for peak=1
+                        float fluxNorm = model->class->modelFlux(model->params);               // Flux for peak=1
                         float fluxPeak = powf(10.0, -0.4 * data->fakeMag) / fluxNorm; // Peak flux
                         source->peak = pmPeakAlloc(xSrc, ySrc, fluxPeak, PM_PEAK_LONE);
@@ -135,5 +135,5 @@
                     source->peak = pmPeakAlloc(xSrc, ySrc, 1.0, PM_PEAK_LONE);
                     pmModel *model = pmModelFromPSFforXY(psf, xSrc, ySrc, 1.0); // Model for normalisation
-                    float flux = model->modelFlux(model->params);               // Flux for peak=1
+                    float flux = model->class->modelFlux(model->params);               // Flux for peak=1
                     psFree(model);
                     source->psfMag = -2.5 * log10(flux);
Index: /branches/eam_branches/ipp-20140610/psModules/src/camera/pmFPAfileIO.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/camera/pmFPAfileIO.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/camera/pmFPAfileIO.c	(revision 36884)
@@ -34,4 +34,5 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmSourceMasks.h"
Index: /branches/eam_branches/ipp-20140610/psModules/src/camera/pmReadoutFake.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/camera/pmReadoutFake.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/camera/pmReadoutFake.c	(revision 36884)
@@ -20,7 +20,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"
@@ -55,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) {
@@ -62,5 +62,5 @@
         axes.major = axes.minor;
     }
-    return pmPSF_AxesToModel(params, axes, model->type);
+    return pmPSF_AxesToModel(params, axes, model->class->useReff);
 }
 
@@ -122,5 +122,5 @@
             }
 
-            flux /= normModel->modelFlux(normModel->params);
+            flux /= normModel->class->modelFlux(normModel->params);
             psFree(normModel);
         }
@@ -164,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-20140610/psModules/src/extras/pmThreadTools.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/extras/pmThreadTools.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/extras/pmThreadTools.c	(revision 36884)
@@ -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"
Index: /branches/eam_branches/ipp-20140610/psModules/src/extras/pmVisual.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/extras/pmVisual.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/extras/pmVisual.c	(revision 36884)
@@ -22,33 +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 "pmSourceLensing.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)
Index: /branches/eam_branches/ipp-20140610/psModules/src/imcombine/pmPSFEnvelope.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/imcombine/pmPSFEnvelope.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/imcombine/pmPSFEnvelope.c	(revision 36884)
@@ -20,7 +20,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"
@@ -168,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;
                         }
@@ -246,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-20140610/psModules/src/imcombine/pmSubtractionStamps.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/imcombine/pmSubtractionStamps.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/imcombine/pmSubtractionStamps.c	(revision 36884)
@@ -21,4 +21,5 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
 #include "pmSourceMasks.h"
Index: /branches/eam_branches/ipp-20140610/psModules/src/objects/mksource.pl
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/mksource.pl	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/mksource.pl	(revision 36884)
@@ -24,7 +24,9 @@
 		"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-20140610/psModules/src/objects/models/fwhm.sh
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/models/fwhm.sh	(revision 36884)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/models/fwhm.sh	(revision 36884)
@@ -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-20140610/psModules/src/objects/models/pmModel_DEV.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/models/pmModel_DEV.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/models/pmModel_DEV.c	(revision 36884)
@@ -36,7 +36,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"
@@ -59,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
@@ -123,5 +124,5 @@
     if (radius <= 1.5) {
 	// Nsub ~ 10*index^2 + 1
-	psEllipseAxes axes = pmPSF_ModelToAxes(PAR, pmModelClassGetType ("PS_MODEL_DEV"));
+	psEllipseAxes axes = pmPSF_ModelToAxes(PAR, true); // DEV uses Reff
 	int Nsub = 2 * ((int)(25 / axes.minor)) + 1;
 	Nsub = PS_MIN (Nsub, 121);
@@ -336,4 +337,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)
 {
@@ -357,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]);
@@ -411,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-20140610/psModules/src/objects/models/pmModel_DEV.h
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/models/pmModel_DEV.h	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/models/pmModel_DEV.h	(revision 36884)
@@ -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-20140610/psModules/src/objects/models/pmModel_EXP.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/models/pmModel_EXP.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/models/pmModel_EXP.c	(revision 36884)
@@ -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"
@@ -56,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
@@ -343,4 +344,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)
 {
@@ -364,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]);
@@ -418,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);
Index: /branches/eam_branches/ipp-20140610/psModules/src/objects/models/pmModel_EXP.h
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/models/pmModel_EXP.h	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/models/pmModel_EXP.h	(revision 36884)
@@ -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-20140610/psModules/src/objects/models/pmModel_GAUSS.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/models/pmModel_GAUSS.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/models/pmModel_GAUSS.c	(revision 36884)
@@ -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"
@@ -54,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
@@ -257,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)
@@ -279,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]);
@@ -331,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-20140610/psModules/src/objects/models/pmModel_GAUSS.h
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/models/pmModel_GAUSS.h	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/models/pmModel_GAUSS.h	(revision 36884)
@@ -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-20140610/psModules/src/objects/models/pmModel_PGAUSS.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/models/pmModel_PGAUSS.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/models/pmModel_PGAUSS.c	(revision 36884)
@@ -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"
@@ -55,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
@@ -324,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)
 {
@@ -344,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]);
@@ -396,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-20140610/psModules/src/objects/models/pmModel_PGAUSS.h
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/models/pmModel_PGAUSS.h	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/models/pmModel_PGAUSS.h	(revision 36884)
@@ -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-20140610/psModules/src/objects/models/pmModel_PS1_V1.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/models/pmModel_PS1_V1.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/models/pmModel_PS1_V1.c	(revision 36884)
@@ -35,7 +35,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"
@@ -57,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
@@ -336,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;
@@ -357,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]);
@@ -411,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-20140610/psModules/src/objects/models/pmModel_PS1_V1.h
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/models/pmModel_PS1_V1.h	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/models/pmModel_PS1_V1.h	(revision 36884)
@@ -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-20140610/psModules/src/objects/models/pmModel_QGAUSS.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/models/pmModel_QGAUSS.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/models/pmModel_QGAUSS.c	(revision 36884)
@@ -35,7 +35,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"
@@ -57,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
@@ -337,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)
 {
@@ -358,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]);
@@ -416,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-20140610/psModules/src/objects/models/pmModel_QGAUSS.h
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/models/pmModel_QGAUSS.h	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/models/pmModel_QGAUSS.h	(revision 36884)
@@ -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-20140610/psModules/src/objects/models/pmModel_RGAUSS.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/models/pmModel_RGAUSS.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/models/pmModel_RGAUSS.c	(revision 36884)
@@ -34,7 +34,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"
@@ -56,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
@@ -330,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)
 {
@@ -351,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]);
@@ -404,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-20140610/psModules/src/objects/models/pmModel_RGAUSS.h
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/models/pmModel_RGAUSS.h	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/models/pmModel_RGAUSS.h	(revision 36884)
@@ -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-20140610/psModules/src/objects/models/pmModel_SERSIC.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/models/pmModel_SERSIC.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/models/pmModel_SERSIC.c	(revision 36884)
@@ -43,7 +43,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"
@@ -66,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
@@ -124,5 +125,5 @@
     if (radius <= 1.5) {
 	// Nsub ~ 10*index^2 + 1
-	psEllipseAxes axes = pmPSF_ModelToAxes(PAR, pmModelClassGetType ("PS_MODEL_SERSIC"));
+	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);
@@ -357,4 +358,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)
 {
@@ -378,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]);
@@ -432,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-20140610/psModules/src/objects/models/pmModel_SERSIC.h
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/models/pmModel_SERSIC.h	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/models/pmModel_SERSIC.h	(revision 36884)
@@ -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-20140610/psModules/src/objects/models/pmModel_TRAIL.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/models/pmModel_TRAIL.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/models/pmModel_TRAIL.c	(revision 36884)
@@ -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,7 +34,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"
@@ -55,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
@@ -352,5 +354,5 @@
 
     psF32 *psfPAR  = source->modelPSF->params->data.F32;
-    bool useReff = pmModelUseReff (source->modelPSF->type);
+    bool useReff = source->modelPSF->class->useReff;
 
     psEllipseAxes psfAxes;
@@ -413,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-20140610/psModules/src/objects/models/pmModel_TRAIL.h
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/models/pmModel_TRAIL.h	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/models/pmModel_TRAIL.h	(revision 36884)
@@ -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-20140610/psModules/src/objects/pmDetEff.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmDetEff.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmDetEff.c	(revision 36884)
@@ -17,7 +17,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"
Index: /branches/eam_branches/ipp-20140610/psModules/src/objects/pmGrowthCurve.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmGrowthCurve.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmGrowthCurve.c	(revision 36884)
@@ -30,7 +30,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"
Index: /branches/eam_branches/ipp-20140610/psModules/src/objects/pmGrowthCurveGenerate.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmGrowthCurveGenerate.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmGrowthCurveGenerate.c	(revision 36884)
@@ -37,7 +37,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"
Index: /branches/eam_branches/ipp-20140610/psModules/src/objects/pmModel.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmModel.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmModel.c	(revision 36884)
@@ -33,6 +33,6 @@
 #include "pmMoments.h"
 #include "pmModelFuncs.h"
+#include "pmModelClass.h"
 #include "pmModel.h"
-#include "pmModelClass.h"
 
 static void modelFree(pmModel *tmp)
@@ -92,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__);
@@ -158,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__);
@@ -178,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__);
@@ -285,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-20140610/psModules/src/objects/pmModel.h
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmModel.h	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmModel.h	(revision 36884)
@@ -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-20140610/psModules/src/objects/pmModelClass.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmModelClass.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmModelClass.c	(revision 36884)
@@ -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,13 +54,13 @@
 
 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  },
 };
 
Index: /branches/eam_branches/ipp-20140610/psModules/src/objects/pmModelClass.h
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmModelClass.h	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmModelClass.h	(revision 36884)
@@ -35,7 +35,9 @@
     char *name;
     int nParams;
+    bool useReff;
     pmModelFunc          modelFunc;
     pmModelFlux          modelFlux;
     pmModelRadius        modelRadius;
+    pmModelSetFWHM       modelSetFWHM;
     pmModelLimits        modelLimits;
     pmModelGuessFunc     modelGuess;
Index: /branches/eam_branches/ipp-20140610/psModules/src/objects/pmModelFuncs.h
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmModelFuncs.h	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmModelFuncs.h	(revision 36884)
@@ -110,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-20140610/psModules/src/objects/pmModelUtils.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmModelUtils.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmModelUtils.c	(revision 36884)
@@ -32,7 +32,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"
@@ -46,13 +46,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 }
-
 /*****************************************************************************
 pmModelFromPSF (*modelEXT, *psf):  use the model position parameters to
@@ -68,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);
@@ -89,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;
@@ -109,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);
@@ -120,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;
 }
Index: /branches/eam_branches/ipp-20140610/psModules/src/objects/pmPCM_MinimizeChisq.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmPCM_MinimizeChisq.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmPCM_MinimizeChisq.c	(revision 36884)
@@ -31,7 +31,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"
@@ -455,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++) {
Index: /branches/eam_branches/ipp-20140610/psModules/src/objects/pmPCMdata.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmPCMdata.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmPCMdata.c	(revision 36884)
@@ -31,7 +31,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"
@@ -293,5 +293,5 @@
     
     psEllipseAxes axes;
-    bool useReff = pmModelUseReff (modelPSF->type);
+    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);
@@ -302,5 +302,5 @@
     // XXX need to do this more carefully
     if (modelPSF->type == modelType_GAUSS) {
-	float FWHM_MAJOR = 2*modelPSF->modelRadius (modelPSF->params, 0.5*PAR[PM_PAR_I0]);
+	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;
@@ -330,5 +330,5 @@
     
     psEllipseAxes axes;
-    bool useReff = pmModelUseReff (modelPSF->type);
+    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);
@@ -339,5 +339,5 @@
     // XXX need to do this more carefully
     if (modelPSF->type == modelType_GAUSS) {
-	float FWHM_MAJOR = 2*modelPSF->modelRadius (modelPSF->params, 0.5*PAR[PM_PAR_I0]);
+	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;
@@ -393,5 +393,5 @@
     psMinConstraint *constraint = psMinConstraintAlloc();
     constraint->paramMask = psVectorAlloc (params->n, PS_TYPE_VECTOR_MASK);
-    constraint->checkLimits = model->modelLimits;
+    constraint->checkLimits = model->class->modelLimits;
 
     int nParams = pmPCMsetParams (constraint, fitOptions->mode);
Index: /branches/eam_branches/ipp-20140610/psModules/src/objects/pmPSF.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmPSF.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmPSF.c	(revision 36884)
@@ -37,7 +37,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"
@@ -329,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;
@@ -338,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;
@@ -345,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);
@@ -357,5 +356,4 @@
     }
     
-    bool useReff = pmModelUseReff (type);
     pmModelAxesToParams (&modelPar[PM_PAR_SXX], &modelPar[PM_PAR_SXY], &modelPar[PM_PAR_SYY], axes, useReff);
     return true;
@@ -420,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-20140610/psModules/src/objects/pmPSF.h
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmPSF.h	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmPSF.h	(revision 36884)
@@ -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-20140610/psModules/src/objects/pmPSF_IO.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmPSF_IO.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmPSF_IO.c	(revision 36884)
@@ -47,7 +47,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"
Index: /branches/eam_branches/ipp-20140610/psModules/src/objects/pmPSFtry.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmPSFtry.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmPSFtry.c	(revision 36884)
@@ -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"
Index: /branches/eam_branches/ipp-20140610/psModules/src/objects/pmPSFtryFitEXT.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmPSFtryFitEXT.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmPSFtryFitEXT.c	(revision 36884)
@@ -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"
Index: /branches/eam_branches/ipp-20140610/psModules/src/objects/pmPSFtryFitPSF.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmPSFtryFitPSF.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmPSFtryFitPSF.c	(revision 36884)
@@ -27,7 +27,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"
Index: /branches/eam_branches/ipp-20140610/psModules/src/objects/pmPSFtryMakePSF.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmPSFtryMakePSF.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmPSFtryMakePSF.c	(revision 36884)
@@ -28,7 +28,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"
@@ -212,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);
 
Index: /branches/eam_branches/ipp-20140610/psModules/src/objects/pmPSFtryMetric.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmPSFtryMetric.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmPSFtryMetric.c	(revision 36884)
@@ -28,7 +28,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"
Index: /branches/eam_branches/ipp-20140610/psModules/src/objects/pmPSFtryModel.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmPSFtryModel.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmPSFtryModel.c	(revision 36884)
@@ -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"
Index: /branches/eam_branches/ipp-20140610/psModules/src/objects/pmPhotObj.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmPhotObj.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmPhotObj.c	(revision 36884)
@@ -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"
Index: /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSource.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSource.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSource.c	(revision 36884)
@@ -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"
@@ -146,4 +146,5 @@
     source->apMagRaw  	     = NAN;
     source->apRadius  	     = NAN;
+    source->apNpixels  	     = 0;
     source->apFlux    	     = NAN;
     source->apFluxErr 	     = NAN; 
@@ -237,4 +238,5 @@
     source->apMagRaw  	     = in->apMagRaw;
     source->apRadius  	     = in->apRadius;
+    source->apNpixels  	     = in->apNpixels;
     source->apFlux    	     = in->apFlux;
     source->apFluxErr 	     = in->apFluxErr;
@@ -987,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-20140610/psModules/src/objects/pmSource.h
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSource.h	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSource.h	(revision 36884)
@@ -97,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)
Index: /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceContour.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceContour.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceContour.c	(revision 36884)
@@ -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"
Index: /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceFitModel.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceFitModel.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceFitModel.c	(revision 36884)
@@ -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"
@@ -170,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
@@ -233,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);
     }
 
@@ -254,5 +254,5 @@
     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])
@@ -306,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-20140610/psModules/src/objects/pmSourceFitPCM.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceFitPCM.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceFitPCM.c	(revision 36884)
@@ -31,7 +31,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"
@@ -63,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);
     }
 
@@ -165,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-20140610/psModules/src/objects/pmSourceFitSet.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceFitSet.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceFitSet.c	(revision 36884)
@@ -32,7 +32,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"
@@ -223,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;
 }
@@ -388,5 +388,5 @@
         psVector *derivOne = thisSet->derivSet->data[i];
 
-        chisqOne = model->modelFunc (derivOne, paramOne, x);
+        chisqOne = model->class->modelFunc (derivOne, paramOne, x);
         chisqSum += chisqOne;
     }
Index: /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceGroups.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceGroups.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceGroups.c	(revision 36884)
@@ -18,7 +18,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"
Index: /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceIO.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceIO.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceIO.c	(revision 36884)
@@ -40,7 +40,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"
Index: /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceIO_CFF.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceIO_CFF.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceIO_CFF.c	(revision 36884)
@@ -37,7 +37,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"
@@ -208,5 +208,5 @@
             axes.minor        = 1.0;
             axes.theta        = 0.0;
-            pmPSF_AxesToModel (PAR, axes, modelType);
+            pmPSF_AxesToModel (PAR, axes, model->class->useReff);
 
             // peak->detValue, rawFlux, smoothFlux are all set to the flux argument which is counts per second
@@ -273,5 +273,5 @@
 	    galaxyAxes.theta = theta * PS_RAD_DEG;
 
-	    pmPSF_AxesToModel (xPAR, galaxyAxes, galaxyModelType);
+	    pmPSF_AxesToModel (xPAR, galaxyAxes, model->class->useReff);
 	    if (model->params->n > 7) {
                 xPAR[PM_PAR_7] = 0.5 / Sindex;
@@ -403,5 +403,5 @@
                         yPos[n_rows] = PAR[PM_PAR_YPOS];
 
-                        psEllipseAxes axes = pmPSF_ModelToAxes (PAR, model->type);
+                        psEllipseAxes axes = pmPSF_ModelToAxes (PAR, model->class->useReff);
                         rMajor[n_rows] = axes.major;
                         rMinor[n_rows] = axes.minor;
@@ -461,5 +461,5 @@
                         yPos[0] = PAR[PM_PAR_YPOS];
 
-                        psEllipseAxes axes = pmPSF_ModelToAxes (PAR, model->type);
+                        psEllipseAxes axes = pmPSF_ModelToAxes (PAR, model->class->useReff);
                         rMajor[0] = axes.major;
                         rMinor[0] = axes.minor;
@@ -490,5 +490,5 @@
                                 yPos[1] = PAR[PM_PAR_YPOS];
 
-                                psEllipseAxes axes = pmPSF_ModelToAxes (PAR, model->type);
+                                psEllipseAxes axes = pmPSF_ModelToAxes (PAR, model->class->useReff);
                                 rMajor[1] = axes.major;
                                 rMinor[1] = axes.minor;
Index: /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceIO_CMF.c.in
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceIO_CMF.c.in	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceIO_CMF.c.in	(revision 36884)
@@ -37,7 +37,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"
@@ -142,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);
@@ -163,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);
@@ -197,5 +206,5 @@
 	}
 
-	if (source->lensingOBJ && source->lensingPSF->smear) {
+	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);
@@ -205,5 +214,5 @@
 	}
 
-	if (source->lensingOBJ && source->lensingPSF->shear) {
+	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);
@@ -302,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
@@ -344,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");
@@ -355,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?
@@ -365,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");
@@ -383,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.
@@ -410,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");
@@ -982,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);
@@ -1132,5 +1187,5 @@
         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");
Index: /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceIO_CMP.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceIO_CMP.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceIO_CMP.c	(revision 36884)
@@ -37,7 +37,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"
@@ -136,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;
@@ -293,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-20140610/psModules/src/objects/pmSourceIO_MatchedRefs.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceIO_MatchedRefs.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceIO_MatchedRefs.c	(revision 36884)
@@ -37,7 +37,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"
Index: /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceIO_OBJ.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceIO_OBJ.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceIO_OBJ.c	(revision 36884)
@@ -37,7 +37,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"
@@ -93,5 +93,5 @@
         }
 
-        axes = pmPSF_ModelToAxes (PAR, model->type);
+        axes = pmPSF_ModelToAxes (PAR, model->class->useReff);
 
         psLineInit (line);
Index: /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceIO_PS1_CAL_0.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceIO_PS1_CAL_0.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceIO_PS1_CAL_0.c	(revision 36884)
@@ -37,7 +37,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"
@@ -115,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;
@@ -290,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");
@@ -624,5 +624,5 @@
 	    yErr = dPAR[PM_PAR_YPOS];
 
-	    axes = pmPSF_ModelToAxes (PAR, model->type);
+	    axes = pmPSF_ModelToAxes (PAR, model->class->useReff);
 
 	    // generate RA,DEC
Index: /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceIO_PS1_DEV_0.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceIO_PS1_DEV_0.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceIO_PS1_DEV_0.c	(revision 36884)
@@ -37,7 +37,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"
@@ -91,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.
@@ -216,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");
Index: /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceIO_PS1_DEV_1.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceIO_PS1_DEV_1.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceIO_PS1_DEV_1.c	(revision 36884)
@@ -37,7 +37,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"
@@ -97,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;
@@ -259,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");
@@ -524,5 +524,5 @@
 	    yErr = dPAR[PM_PAR_YPOS];
 
-	    axes = pmPSF_ModelToAxes (PAR, model->type);
+	    axes = pmPSF_ModelToAxes (PAR, model->class->useReff);
 
 	    row = psMetadataAlloc ();
Index: /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceIO_RAW.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceIO_RAW.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceIO_RAW.c	(revision 36884)
@@ -37,7 +37,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"
Index: /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceIO_SMPDATA.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceIO_SMPDATA.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceIO_SMPDATA.c	(revision 36884)
@@ -37,7 +37,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"
@@ -93,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 {
@@ -190,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;
Index: /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceIO_SX.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceIO_SX.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceIO_SX.c	(revision 36884)
@@ -37,7 +37,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"
@@ -82,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-20140610/psModules/src/objects/pmSourceMatch.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceMatch.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceMatch.c	(revision 36884)
@@ -18,7 +18,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"
Index: /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceMoments.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceMoments.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceMoments.c	(revision 36884)
@@ -35,7 +35,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"
Index: /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceOutputs.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceOutputs.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceOutputs.c	(revision 36884)
@@ -26,7 +26,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"
@@ -108,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);
@@ -138,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-20140610/psModules/src/objects/pmSourceOutputs.h
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceOutputs.h	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceOutputs.h	(revision 36884)
@@ -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-20140610/psModules/src/objects/pmSourcePhotometry.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourcePhotometry.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourcePhotometry.c	(revision 36884)
@@ -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"
@@ -330,5 +330,5 @@
 
     // measure fitMag
-    flux = model->modelFlux (model->params);
+    flux = model->class->modelFlux (model->params);
     if (flux > 0) {
         mag = -2.5*log10(flux);
@@ -359,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;
@@ -490,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;
 
@@ -893,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", 
Index: /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourcePlotApResid.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourcePlotApResid.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourcePlotApResid.c	(revision 36884)
@@ -35,7 +35,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"
Index: /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourcePlotMoments.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourcePlotMoments.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourcePlotMoments.c	(revision 36884)
@@ -38,7 +38,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"
Index: /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourcePlotPSFModel.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourcePlotPSFModel.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourcePlotPSFModel.c	(revision 36884)
@@ -39,7 +39,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"
@@ -147,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-20140610/psModules/src/objects/pmSourceSky.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceSky.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceSky.c	(revision 36884)
@@ -34,7 +34,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"
Index: /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceUtils.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceUtils.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceUtils.c	(revision 36884)
@@ -34,7 +34,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"
@@ -65,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-20140610/psModules/src/objects/pmSourceVisual.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceVisual.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/objects/pmSourceVisual.c	(revision 36884)
@@ -16,7 +16,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"
Index: /branches/eam_branches/ipp-20140610/psModules/src/psmodules.h
===================================================================
--- /branches/eam_branches/ipp-20140610/psModules/src/psmodules.h	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psModules/src/psmodules.h	(revision 36884)
@@ -129,4 +129,5 @@
 
 #include <pmModelFuncs.h>
+#include <pmModelClass.h>
 #include <pmModel.h>
 #include <pmModel_CentralPixel.h>
@@ -149,5 +150,4 @@
 #include <pmSourcePlots.h>
 #include <pmPSF_IO.h>
-#include <pmModelClass.h>
 #include <pmModelUtils.h>
 #include <pmSourcePhotometry.h>
Index: /branches/eam_branches/ipp-20140610/psastro/doc/outline.txt
===================================================================
--- /branches/eam_branches/ipp-20140610/psastro/doc/outline.txt	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psastro/doc/outline.txt	(revision 36884)
@@ -3,9 +3,12 @@
 
   psastroParseCamera
+    psastroDefineFiles
   psastroDataLoad
-    psastroConvertReadout (save PSASTRO.RAWSTARS & PSASTRO.RAWSTARS.SUBSET on readout->analysis)
+    psastroConvertReadout (saves PSASTRO.RAWSTARS on readout->analysis)
+      psastroCorrectKH
   psastroAnalysis
     psastroUseModel
     psastroAstromGuess (plots PSASTRO.RAWSTARS)
+    psastroRemoveClumpsRawstars (saves PSASTRO.RAWSTARS.SUBSET on readout->analysis)
     psastroLoadRefstars (loads full reference star set)
     psastroChooseRefstars (save PSASTRO.REFSTARS & PSASTRO.REFSTARS.SUBSET on readout->analysis)
Index: /branches/eam_branches/ipp-20140610/psastro/src/psastroConvert.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psastro/src/psastroConvert.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psastro/src/psastroConvert.c	(revision 36884)
@@ -199,5 +199,5 @@
 	// effect (all affected data was processed BEFORE the bug was introduced), and it
 	// does not affect any of the PV2 or PV3 data processed AFTER the bug was fixed.
-	psEllipseAxes axes = pmPSF_ModelToAxes (PAR, model->type);
+	psEllipseAxes axes = pmPSF_ModelToAxes (PAR, model->class->useReff);
 
         pmAstromObj *obj = pmAstromObjAlloc ();
Index: /branches/eam_branches/ipp-20140610/psphot/src/psphotChoosePSF.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psphot/src/psphotChoosePSF.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psphot/src/psphotChoosePSF.c	(revision 36884)
@@ -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-20140610/psphot/src/psphotEfficiency.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psphot/src/psphotEfficiency.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psphot/src/psphotEfficiency.c	(revision 36884)
@@ -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-20140610/psphot/src/psphotEvalFLT.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psphot/src/psphotEvalFLT.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psphot/src/psphotEvalFLT.c	(revision 36884)
@@ -53,5 +53,5 @@
     } 
 
-    keep = model->modelFitStatus(model);
+    keep = model->class->modelFitStatus(model);
     if (keep) return true;
 
Index: /branches/eam_branches/ipp-20140610/psphot/src/psphotFullForceSummaryReadout.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psphot/src/psphotFullForceSummaryReadout.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psphot/src/psphotFullForceSummaryReadout.c	(revision 36884)
@@ -425,5 +425,5 @@
                 // copy the best fit params to the model
                 // fractional radii with the lowest chisq
-                psEllipseAxes axes = pmPSF_ModelToAxes(model->params->data.F32, model->type);
+                psEllipseAxes axes = pmPSF_ModelToAxes(model->params->data.F32, model->class->useReff);
 
                 // examine the params for the trial with minimum chisq.
@@ -637,5 +637,5 @@
                 // now save the model parameters in the model structure
 
-                pmPSF_AxesToModel (model->params->data.F32, axes, modelType);
+                pmPSF_AxesToModel (model->params->data.F32, axes, model->class->useReff);
 
                 model->mag = -2.5 * log10(flux0);
Index: /branches/eam_branches/ipp-20140610/psphot/src/psphotGalaxyShape.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psphot/src/psphotGalaxyShape.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psphot/src/psphotGalaxyShape.c	(revision 36884)
@@ -283,5 +283,5 @@
 
         // I have some source guess (e0, e1, e2)
-        psEllipseAxes guessAxes = pmPSF_ModelToAxes (PAR, modelType);
+        psEllipseAxes guessAxes = pmPSF_ModelToAxes (PAR, model->class->useReff);
 
         float fRmajorBest = NAN;
@@ -295,5 +295,5 @@
                 testAxes.minor = guessAxes.minor * fRminor;
                 
-                pmPSF_AxesToModel (PAR, testAxes, modelType);
+                pmPSF_AxesToModel (PAR, testAxes, model->class->useReff);
                 
                 psphotGalaxyShapeSource (pcm, source, galaxyFits, maskVal, psfSize, true);
@@ -324,5 +324,5 @@
 #endif
             
-            pmPSF_AxesToModel (PAR, testAxes, modelType);
+            pmPSF_AxesToModel (PAR, testAxes, model->class->useReff);
                 
             psphotGalaxyShapeSource (pcm, source, galaxyFits, maskVal, psfSize, false);
@@ -400,5 +400,5 @@
 
     pcm->modelConv->params->data.F32[PM_PAR_I0] = Io;
-    float flux = pcm->modelConv->modelFlux (pcm->modelConv->params);
+    float flux = pcm->modelConv->class->modelFlux (pcm->modelConv->params);
     float dflux = flux * (dIo / Io);
 
Index: /branches/eam_branches/ipp-20140610/psphot/src/psphotLensing.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psphot/src/psphotLensing.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psphot/src/psphotLensing.c	(revision 36884)
@@ -12,4 +12,10 @@
     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);
@@ -87,4 +93,5 @@
     }
 
+    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);
 
@@ -317,4 +324,5 @@
     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"));
 
Index: /branches/eam_branches/ipp-20140610/psphot/src/psphotLoadSRCTEXT.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psphot/src/psphotLoadSRCTEXT.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psphot/src/psphotLoadSRCTEXT.c	(revision 36884)
@@ -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-20140610/psphot/src/psphotMakeFluxScale.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psphot/src/psphotMakeFluxScale.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psphot/src/psphotMakeFluxScale.c	(revision 36884)
@@ -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-20140610/psphot/src/psphotRadiusChecks.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psphot/src/psphotRadiusChecks.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psphot/src/psphotRadiusChecks.c	(revision 36884)
@@ -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);
@@ -294,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-20140610/psphot/src/psphotSersicModelClass.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psphot/src/psphotSersicModelClass.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psphot/src/psphotSersicModelClass.c	(revision 36884)
@@ -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-20140610/psphot/src/psphotSourceFits.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psphot/src/psphotSourceFits.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psphot/src/psphotSourceFits.c	(revision 36884)
@@ -700,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;
@@ -723,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;
@@ -752,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;
Index: /branches/eam_branches/ipp-20140610/psphot/src/psphotVisual.c
===================================================================
--- /branches/eam_branches/ipp-20140610/psphot/src/psphotVisual.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psphot/src/psphotVisual.c	(revision 36884)
@@ -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-20140610/psphot/test/tap_psphot_galaxies.pro
===================================================================
--- /branches/eam_branches/ipp-20140610/psphot/test/tap_psphot_galaxies.pro	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/psphot/test/tap_psphot_galaxies.pro	(revision 36884)
@@ -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,8 @@
   $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
 
   # ppImage / psphot on the output
@@ -217,4 +250,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-20140610/pstamp/scripts/pstamp_webrequest.pl
===================================================================
--- /branches/eam_branches/ipp-20140610/pstamp/scripts/pstamp_webrequest.pl	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/pstamp/scripts/pstamp_webrequest.pl	(revision 36884)
@@ -93,8 +93,15 @@
     my $command = "$psmkreq --req_name $request_name  --output $request_file @ARGV";
 
+if (0) {
+open DEBUG, ">>/tmp/pstamp.debug.log";
+print DEBUG "\ncommand is: $command\n";
+close DEBUG;
+}
+
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
         run(command => $command, verbose => $verbose);
     unless ($success) {
         print STDERR @$stderr_buf;
+        print STDERR "\ncommand was: $command\n";
         die("Unable to perform psmkreq: $error_code");
     }
Index: /branches/eam_branches/ipp-20140610/pswarp/src/pswarpTransformSources.c
===================================================================
--- /branches/eam_branches/ipp-20140610/pswarp/src/pswarpTransformSources.c	(revision 36883)
+++ /branches/eam_branches/ipp-20140610/pswarp/src/pswarpTransformSources.c	(revision 36884)
@@ -120,6 +120,6 @@
 #if 0
         // XXX Note that this will not set the correct axes
-	psEllipseAxes axes = pmPSF_ModelToAxes(source->modelPSF->params->data.F32, 20.0, source->modelPSF->type);
-        pmPSF_AxesToModel(new->modelPSF->params->data.F32, axes, new->modelPSF->type);
+	psEllipseAxes axes = pmPSF_ModelToAxes(source->modelPSF->params->data.F32, 20.0, source->modelPSF->class->useReff);
+        pmPSF_AxesToModel(new->modelPSF->params->data.F32, axes, new->modelPSF->class->useReff);
 #endif
 
