Index: anches/cnb_branches/cnb_branch_20090215/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,1 +1,0 @@
-ippdb.src
Index: /branches/cnb_branches/cnb_branch_20090215/Branches.txt
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Branches.txt	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/Branches.txt	(revision 23197)
@@ -1,2 +1,5 @@
+
+Converted to SVN 2009-02-19
+We have moved to SVN. I am re-working the branch and tag layout.
 
 eam_branch_20090208
Index: anches/cnb_branches/cnb_branch_20090215/DataStore/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/DataStore/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,6 +1,0 @@
-Build
-META.yml
-Makefile
-Makefile.PL
-_build
-blib
Index: anches/cnb_branches/cnb_branch_20090215/DataStoreServer/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/DataStoreServer/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,9 +1,0 @@
-Makefile
-Makefile.in
-aclocal.m4
-autom4te.cache
-config.log
-config.status
-configure
-install-sh
-missing
Index: anches/cnb_branches/cnb_branch_20090215/DataStoreServer/scripts/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/DataStoreServer/scripts/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-Makefile
-Makefile.in
Index: anches/cnb_branches/cnb_branch_20090215/Nebulous-Server/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Nebulous-Server/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,6 +1,0 @@
-Build
-META.yml
-Makefile
-Makefile.PL
-_build
-blib
Index: anches/cnb_branches/cnb_branch_20090215/Nebulous-Server/t/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Nebulous-Server/t/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,3 +1,0 @@
-TEST
-htdocs
-logs
Index: anches/cnb_branches/cnb_branch_20090215/Nebulous/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Nebulous/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,6 +1,0 @@
-Build
-META.yml
-Makefile
-Makefile.PL
-_build
-blib
Index: anches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,21 +1,0 @@
-Doxyfile
-Makefile
-Makefile.in
-aclocal.m4
-autom4te.cache
-compile
-config.guess
-config.h
-config.h.in
-config.log
-config.status
-config.sub
-configure
-depcomp
-docs
-install-sh
-libtool
-ltmain.sh
-missing
-nebclient.pc
-stamp-h1
Index: anches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/src/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/src/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,19 +1,0 @@
-.deps
-.libs
-Makefile
-Makefile.in
-SOAP.nsmap
-libnebclient.la
-nebclient.lo
-nebulous.h
-soapC.c
-soapC.lo
-soapClient.c
-soapClient.lo
-soapClientLib.c
-soapH.h
-soapServer.c
-soapServerLib.c
-soapStub.h
-stdsoap2.lo
-xmalloc.lo
Index: anches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/tests/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/tests/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,5 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-tests
Index: anches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/tests/tap/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/tests/tap/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,13 +1,0 @@
-.in
-Makefile
-Makefile.in
-aclocal.m4
-autom4te.cache
-config.log
-config.status
-configure
-libtool
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/tests/tap/src/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/tests/tap/src/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,13 +1,0 @@
-.deps
-.libs
-Makefile
-Makefile.in
-libtap.la
-tap.lo
-config.h
-config.h.in
-stamp-h1
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/tests/tap/tests/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/tests/tap/tests/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,6 +1,0 @@
-Makefile
-Makefile.in
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/tests/tap/tests/diag/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/tests/tap/tests/diag/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/tests/tap/tests/fail/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/tests/tap/tests/fail/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,15 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/tests/tap/tests/ok/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/tests/tap/tests/ok/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,6 +1,0 @@
-Makefile
-Makefile.in
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/tests/tap/tests/ok/ok-hash/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/tests/tap/tests/ok/ok-hash/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/tests/tap/tests/ok/ok-numeric/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/tests/tap/tests/ok/ok-numeric/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/tests/tap/tests/ok/ok/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/tests/tap/tests/ok/ok/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/tests/tap/tests/pass/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/tests/tap/tests/pass/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/tests/tap/tests/plan/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/tests/tap/tests/plan/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,6 +1,0 @@
-Makefile
-Makefile.in
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/tests/tap/tests/plan/no-tests/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/tests/tap/tests/plan/no-tests/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/tests/tap/tests/plan/no_plan/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/tests/tap/tests/plan/no_plan/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/tests/tap/tests/plan/not-enough-tests/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/tests/tap/tests/plan/not-enough-tests/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/tests/tap/tests/plan/sane/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/tests/tap/tests/plan/sane/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/tests/tap/tests/plan/skip_all/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/tests/tap/tests/plan/skip_all/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/tests/tap/tests/plan/too-many-plans/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/tests/tap/tests/plan/too-many-plans/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/tests/tap/tests/plan/too-many-tests/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/tests/tap/tests/plan/too-many-tests/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/tests/tap/tests/skip/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/tests/tap/tests/skip/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/tests/tap/tests/todo/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Nebulous/nebclient/tests/tap/tests/todo/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: /branches/cnb_branches/cnb_branch_20090215/Nebulous/scripts/old_ptest.pl
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Nebulous/scripts/old_ptest.pl	(revision 23197)
+++ /branches/cnb_branches/cnb_branch_20090215/Nebulous/scripts/old_ptest.pl	(revision 23197)
@@ -0,0 +1,23 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Benchmark qw( timethese );
+use PS::IPP::IData::Client;
+
+my $idata = PS::IPP::IData::Client->new(
+    proxy   => 'http://localhost:80/idata'
+);
+
+my $key = shift || 'foobar';
+
+timethese( -10,
+    {
+        'create/delete' => sub {
+            my $fh = $idata->create( $key );
+            close $fh;
+            $idata->delete( $key );
+        },
+    }
+);
Index: /branches/cnb_branches/cnb_branch_20090215/Nebulous/scripts/ptest.pl
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Nebulous/scripts/ptest.pl	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/Nebulous/scripts/ptest.pl	(revision 23197)
@@ -7,7 +7,10 @@
 
 use Nebulous::Client;
+use IO::Select;
+use IO::Socket;
 
 my $neb = Nebulous::Client->new(
-    proxy   => 'http://localhost:80/nebulous'
+#    proxy   => 'http://localhost:80/nebulous'
+    proxy   => 'http://alala:80/nebulous'
 );
 
@@ -15,35 +18,78 @@
 my $kids = shift || 1;
 
+my $s = IO::Select->new();
+
 foreach my $id ( 1..$kids ) {
+    my ($sock_parent, $sock_child) = IO::Socket->socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC);
+    $s->add($sock_parent);
+
     my $pid = fork;
 
     unless ( $pid )  {
-        my $fname = "${key}_$id";
-        my $fh = $neb->open_create( $fname );
-        die "can't create file $fname" unless $fh;
+        child($sock_child, $id);
+        exit 0;
+    }
+    # parent
+}
 
-        print $fh "fooby\n";
-
-        close $fh;
-
-        $fh = $neb->open( $fname, 'read' ) or die "can't open file";
-        close $fh;
-
-        $neb->lock( $fname, 'read' );
-        $neb->unlock( $fname, 'read' );
-        $neb->replicate( $fname );
-        $neb->cull( $fname );
-        $neb->find( $fname );
-        $neb->copy( $fname, $fname . "_copy" );
-        $neb->move( $fname, $fname . "_move" );
-        $neb->delete( $fname . "_copy" );
-        $neb->delete( $fname . "_move" );
-
-        exit 0;
+while ($kids) {
+    foreach my $child ($s->can_read(1)) {
+        my $string = <$child>;
+        my @events = split(/\n/, $string) if $string;
+        print join("\n", @events), "\n" if scalar @events;
     }
 }
 
-while ( $kids ) {
-    wait();
-    $kids --;
+#while ( $kids ) {
+#    wait();
+#    $kids --;
+#}
+
+our $my_sock;
+
+sub child
+{
+    my ($sock_child, $id) = @_;
+
+    $my_sock = $sock_child;
+
+    # child
+    my $fname = "${key}_$id";
+    print $sock_child "$$ : i'm a little tea pot using key: $fname\n";
+    my $fh = $neb->open_create( $fname );
+    child_die("can't create file $fname") unless $fh;
+
+    print $fh "fooby\n";
+
+    close $fh;
+
+    $fh = $neb->open( $fname, 'read' ) or child_die("can't open file");
+    close $fh;
+
+    $neb->lock( $fname, 'read' );
+    $neb->unlock( $fname, 'read' );
+    $neb->replicate( $fname );
+    $neb->cull( $fname );
+
+    print $sock_child "$$ : half way\n";
+
+    $neb->find( $fname );
+    $neb->copy( $fname, $fname . "_copy" );
+    $neb->move( $fname, $fname . "_move" );
+    $neb->delete( $fname . "_copy" );
+    $neb->delete( $fname . "_move" );
+
+    print $sock_child "$$ : all done!\n";
+
+    $sock_child->flush;
+    sleep 10;
+
+    return 1;
 }
+
+sub child_die
+{
+    print $my_sock $@;
+    shutdown($my_sock, 2);
+    exit 1;
+}
Index: anches/cnb_branches/cnb_branch_20090215/Nebulous/t/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Nebulous/t/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,3 +1,0 @@
-TEST
-htdocs
-logs
Index: anches/cnb_branches/cnb_branch_20090215/Nebulous/t/conf/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Nebulous/t/conf/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,6 +1,0 @@
-apache_test_config.pm
-extra.conf
-httpd.conf
-modperl_inc.pl
-modperl_startup.pl
-startup.pl
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,9 +1,0 @@
-help
-bin
-lib
-include
-man
-CVS
-ohana-config
-Makefile
-Makefile.System
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/doc/www/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/doc/www/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,1 +1,0 @@
-Configure
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/doc/www/html/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/doc/www/html/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,3 +1,0 @@
-*.html
-index.idx
-download
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/doc/www/html/DVO/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/doc/www/html/DVO/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-*.html
-index.idx
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/doc/www/html/Elixir-DB/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/doc/www/html/Elixir-DB/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-*.html
-index.idx
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/doc/www/html/Elixir-System/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/doc/www/html/Elixir-System/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-*.html
-index.idx
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/doc/www/html/Elixir-Tools/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/doc/www/html/Elixir-Tools/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-*.html
-index.idx
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/doc/www/html/IPP-subsystems/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/doc/www/html/IPP-subsystems/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-*.html
-index.idx
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/doc/www/html/IPP-subsystems/pclient/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/doc/www/html/IPP-subsystems/pclient/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-*.html
-index.idx
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/doc/www/html/IPP-subsystems/pcontrol/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/doc/www/html/IPP-subsystems/pcontrol/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-*.html
-index.idx
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/doc/www/html/IPP-subsystems/psched/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/doc/www/html/IPP-subsystems/psched/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-*.html
-index.idx
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/doc/www/html/Opihi-Programs/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/doc/www/html/Opihi-Programs/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-*.html
-index.idx
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/doc/www/html/Opihi-Programs/DIMM/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/doc/www/html/Opihi-Programs/DIMM/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-*.html
-index.idx
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/doc/www/html/Opihi-Programs/Mana/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/doc/www/html/Opihi-Programs/Mana/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-*.html
-index.idx
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/doc/www/html/developer/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/doc/www/html/developer/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-*.html
-index.idx
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/doc/www/html/developer/download/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/doc/www/html/developer/download/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-*.html *.tgz
-index.idx
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/doc/www/html/icons/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/doc/www/html/icons/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,1 +1,0 @@
-.xvpics
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/src/absphot/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/absphot/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,1 +1,0 @@
-bin
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/src/addstar/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/addstar/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,1 +1,0 @@
-bin
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/src/addstar/bin/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/addstar/bin/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,5 +1,0 @@
-*.linux *.lin64 *.sol *.sun *.sid *.hp *.irix
-*.linrh
-*.darwin
-*.darwin
-*.darwin_x86
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/src/addstar/test/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/addstar/test/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,5 +1,0 @@
-test.1.cmf
-test.2.cmf
-test.in.txt
-catdir.test
-.dvo
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/src/delstar/bin/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/delstar/bin/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,4 +1,0 @@
-*.linux *.lin64 *.sol *.sun *.sid *.hp *.irix
-*.linrh
-*.darwin
-*.darwin_x86
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/src/dvosplit/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/dvosplit/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,1 +1,0 @@
-bin
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/src/elixir/bin/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/elixir/bin/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,4 +1,0 @@
-*.linux *.lin64 *.sol *.sun *.sid *.hp *.irix
-*.linrh
-*.darwin
-*.darwin_x86
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/src/gastro/bin/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/gastro/bin/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,4 +1,0 @@
-*.linux *.lin64 *.sol *.sun *.sid *.hp *.irix
-*.linrh
-*.darwin
-*.darwin_x86
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/src/gastro2/bin/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/gastro2/bin/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,4 +1,0 @@
-*.linux *.lin64 *.sol *.sun *.sid *.hp *.irix
-*.linrh
-*.darwin
-*.darwin_x86
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/src/gcompare/bin/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/gcompare/bin/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,4 +1,0 @@
-*.linux *.lin64 *.sol *.sun *.sid *.hp *.irix
-*.linrh
-*.darwin
-*.darwin_x86
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/src/getstar/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/getstar/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,1 +1,0 @@
-bin
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/src/getstar/bin/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/getstar/bin/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,4 +1,0 @@
-*.linux *.lin64 *.sol *.sun *.sid *.hp *.irix
-*.linrh
-*.darwin
-*.darwin_x86
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/src/gophot/bin/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/gophot/bin/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,4 +1,0 @@
-*.linux *.lin64 *.sol *.sun *.sid *.hp *.irix
-*.linrh
-*.darwin
-*.darwin_x86
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/src/imclean/bin/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/imclean/bin/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,4 +1,0 @@
-*.linux *.lin64 *.sol *.sun *.sid *.hp *.irix
-*.linrh
-*.darwin
-*.darwin_x86
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/src/imregister/bin/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/imregister/bin/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,4 +1,0 @@
-*.linux *.lin64 *.sol *.sun *.sid *.hp *.irix
-*.linrh
-*.darwin
-*.darwin_x86
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/src/kapa/bin/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/kapa/bin/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,4 +1,0 @@
-*.linux *.lin64 *.sol *.sun *.sid *.hp *.irix
-*.linrh
-*.darwin
-*.darwin_x86
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/src/kapa2/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/kapa2/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,1 +1,0 @@
-bin
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/src/kii/bin/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/kii/bin/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,4 +1,0 @@
-*.linux *.lin64 *.sol *.sun *.sid *.hp *.irix
-*.linrh
-*.darwin
-*.darwin_x86
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/src/libautocode/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/libautocode/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,4 +1,0 @@
-include
-lib
-src
-tex
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/src/libdvo/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/libdvo/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,1 +1,0 @@
-lib
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/src/libdvo/lib/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/libdvo/lib/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,3 +1,0 @@
-*.linux *.lin64 *.sol *.sun *.sid *.hp *.irix
-*.darwin.dylib
-*.darwin_x86.dylib
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/src/libfits/lib/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/libfits/lib/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,3 +1,0 @@
-*.linux *.lin64 *.sol *.sun *.sid *.hp *.irix
-*.darwin.dylib
-*.darwin_x86.dylib
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/src/libkapa/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/libkapa/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,1 +1,0 @@
-lib
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/src/libkapa/lib/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/libkapa/lib/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,3 +1,0 @@
-*.linux *.lin64 *.sol *.sun *.sid *.hp *.irix
-*.darwin.dylib
-*.darwin_x86.dylib
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/src/libkapa/rotfont/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/libkapa/rotfont/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,1 +1,0 @@
-fixfont
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/src/libohana/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/libohana/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,1 +1,0 @@
-lib
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/src/libohana/lib/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/libohana/lib/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,3 +1,0 @@
-*.linux *.lin64 *.sol *.sun *.sid *.hp *.irix
-*.darwin.dylib
-*.darwin_x86.dylib
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/src/libohana/test/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/libohana/test/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,1 +1,0 @@
-*.linux *.lin64 *.sol
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/src/libtap/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/libtap/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,1 +1,0 @@
-lib
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/src/libtap/lib/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/libtap/lib/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,3 +1,0 @@
-*.linux *.lin64 *.sol *.sun *.sid *.hp *.irix
-*.darwin.dylib
-*.darwin_x86.dylib
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/src/misc/bin/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/misc/bin/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,4 +1,0 @@
-*.linux *.lin64 *.sol *.sun *.sid *.hp *.irix
-*.linrh
-*.darwin
-*.darwin_x86
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/src/mosastro/bin/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/mosastro/bin/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,4 +1,0 @@
-*.linux *.lin64 *.sol *.sun *.sid *.hp *.irix
-*.linrh
-*.darwin
-*.darwin_x86
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/src/nightd/bin/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/nightd/bin/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,4 +1,0 @@
-*.linux *.lin64 *.sol *.sun *.sid *.hp *.irix
-*.linrh
-*.darwin
-*.darwin_x86
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/src/opihi/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/opihi/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-lib
-bin
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/src/opihi/bin/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/opihi/bin/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,4 +1,0 @@
-*.linux *.lin64 *.sol *.sun *.sid *.hp *.irix
-*.linrh
-*.darwin
-*.darwin_x86
Index: /branches/cnb_branches/cnb_branch_20090215/Ohana/src/opihi/lib.shell/gprint.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/opihi/lib.shell/gprint.c	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/Ohana/src/opihi/lib.shell/gprint.c	(revision 23197)
@@ -153,12 +153,12 @@
     if (streams[i][0].file == stream[0].file) Nmatch ++;
   }
-  pthread_mutex_unlock (&init_stream_mutex);
-
   if (Nmatch == 0) {
+    // fprintf (stderr, "closed %x, opened %x (%s) -- thread %d\n", stream[0].file, file, stream[0].name, stream[0].thread);
     fflush (stream[0].file);
     fclose (stream[0].file);
   }
-
   stream[0].file = file;
+  pthread_mutex_unlock (&init_stream_mutex);
+
   return;
 }
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/src/opihi/pantasks/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/opihi/pantasks/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,3 +1,0 @@
-pantasks.c
-pantasks_client.c
-pantasks_server.c
Index: /branches/cnb_branches/cnb_branch_20090215/Ohana/src/opihi/pcontrol/CheckIdleHost.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/opihi/pcontrol/CheckIdleHost.c	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/Ohana/src/opihi/pcontrol/CheckIdleHost.c	(revision 23197)
@@ -95,5 +95,5 @@
     gettimeofday (&now, (void *) NULL);
     dtime = DTIME (now, job[0].start);
-    if (dtime > 10.0) continue;
+    if (dtime < 10.0) continue;
 
     if (logfile) fprintf (logfile, "start wanthost(2) %s (job host %s) : %s\n", host[0].hostname, job[0].hostname, job[0].argv[0]);
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/src/photdbc/bin/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/photdbc/bin/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,4 +1,0 @@
-*.linux *.lin64 *.sol *.sun *.sid *.hp *.irix
-*.linrh
-*.darwin
-*.darwin_x86
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/src/relastro/bin/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/relastro/bin/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,4 +1,0 @@
-*.linux *.lin64 *.sol *.sun *.sid *.hp *.irix
-*.linrh
-*.darwin
-*.darwin_x86
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/src/relphot/bin/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/relphot/bin/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,4 +1,0 @@
-*.linux *.lin64 *.sol *.sun *.sid *.hp *.irix
-*.linrh
-*.darwin
-*.darwin_x86
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/src/skycalc/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/skycalc/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-lib
-old
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/src/skycalc/bin/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/skycalc/bin/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,4 +1,0 @@
-*.linux *.lin64 *.sol *.sun *.sid *.hp *.irix
-*.linrh
-*.darwin
-*.darwin_x86
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/src/tools/bin/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/tools/bin/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,4 +1,0 @@
-*.linux *.lin64 *.sol *.sun *.sid *.hp *.irix
-*.linrh
-*.darwin
-*.darwin_x86
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/src/uniphot/bin/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/src/uniphot/bin/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,4 +1,0 @@
-*.linux *.lin64 *.sol *.sun *.sid *.hp *.irix
-*.linrh
-*.darwin
-*.darwin_x86
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/test/addstar/image.sa/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/test/addstar/image.sa/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,1 +1,0 @@
-catdir.*
Index: anches/cnb_branches/cnb_branch_20090215/Ohana/test/addstar/refcat.sa/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/Ohana/test/addstar/refcat.sa/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,1 +1,0 @@
-catdir.*
Index: anches/cnb_branches/cnb_branch_20090215/PS-IPP-Config/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/PS-IPP-Config/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,5 +1,0 @@
-Build
-_build
-blib
-META.yml
-Makefile.PL
Index: anches/cnb_branches/cnb_branch_20090215/PS-IPP-MetaDB/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/PS-IPP-MetaDB/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,6 +1,0 @@
-Build
-META.yml
-Makefile
-Makefile.PL
-_build
-blib
Index: anches/cnb_branches/cnb_branch_20090215/PS-IPP-Metadata-Config/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/PS-IPP-Metadata-Config/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,6 +1,0 @@
-Build
-META.yml
-Makefile
-Makefile.PL
-_build
-blib
Index: anches/cnb_branches/cnb_branch_20090215/PS-IPP-Metadata-Config/lib/PS/IPP/Metadata/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/PS-IPP-Metadata-Config/lib/PS/IPP/Metadata/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,1 +1,0 @@
-Parser.pm
Index: anches/cnb_branches/cnb_branch_20090215/PS-IPP-PSFTP/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/PS-IPP-PSFTP/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,6 +1,0 @@
-Build
-META.yml
-Makefile
-Makefile.PL
-_build
-blib
Index: anches/cnb_branches/cnb_branch_20090215/PStamp/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/PStamp/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,6 +1,0 @@
-Build
-META.yml
-Makefile
-Makefile.PL
-_build
-blib
Index: anches/cnb_branches/cnb_branch_20090215/archive/pslib/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/archive/pslib/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,1 +1,0 @@
-*.log *.dvi *.aux *.toc *.log *.out
Index: anches/cnb_branches/cnb_branch_20090215/archive/pslib/include/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/archive/pslib/include/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-psErrorCodes.h
-dox
Index: anches/cnb_branches/cnb_branch_20090215/archive/pslib/lib/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/archive/pslib/lib/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,1 +1,0 @@
-libUtils.dylib
Index: anches/cnb_branches/cnb_branch_20090215/archive/pslib/src/Metadata/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/archive/pslib/src/Metadata/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,1 +1,0 @@
-tst_metadata
Index: anches/cnb_branches/cnb_branch_20090215/archive/pslib/src/Utils/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/archive/pslib/src/Utils/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-tst_trace tst_logmsg tst_dlist tst_memory tst_array tst_hash tst_error
-psErrorCodes.c
Index: anches/cnb_branches/cnb_branch_20090215/archive/scripts/src/phase2/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/archive/scripts/src/phase2/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,16 +1,0 @@
-Makefile.in
-aclocal.m4
-autom4te.cache
-configure
-Makefile
-config.log
-config.status
-compile
-config.guess
-config.sub
-depcomp
-install-sh
-ltmain.sh
-missing
-stamp-h1
-.deps
Index: anches/cnb_branches/cnb_branch_20090215/dbconfig/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/dbconfig/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-ippdb.m4
-ippdb.mdc
Index: anches/cnb_branches/cnb_branch_20090215/doc/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/doc/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,1 +1,0 @@
-*.log *.dvi *.aux *.toc *.log *.out
Index: anches/cnb_branches/cnb_branch_20090215/doc/config/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/doc/config/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,8 +1,0 @@
-config.out
-config.pdf
-*.aux
-*.dvi
-*.lof
-*.log
-*.tbd
-*.toc
Index: anches/cnb_branches/cnb_branch_20090215/doc/design/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/doc/design/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-*.log *.dvi *.aux *.toc *.log *.out *.lof *.tbr *.tbd *.ent *.pdf
-ippSRSout.tex ippSRStrace.tex
Index: anches/cnb_branches/cnb_branch_20090215/doc/dvo/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/doc/dvo/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,1 +1,0 @@
-*.log *.dvi *.aux *.toc *.log *.out *.lof *.tbr *.tbd *.pdf
Index: anches/cnb_branches/cnb_branch_20090215/doc/ipptools/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/doc/ipptools/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,1 +1,0 @@
-*.log *.dvi *.aux *.toc *.log *.out *.lof *.tbr *.tbd *.pdf
Index: anches/cnb_branches/cnb_branch_20090215/doc/manual/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/doc/manual/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,8 +1,0 @@
-*.aux
-*.dvi
-*.lof
-*.log
-*.tbd
-*.toc
-*.pdf
-manual.ps
Index: anches/cnb_branches/cnb_branch_20090215/doc/misc/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/doc/misc/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,1 +1,0 @@
-*.log *.dvi *.aux *.toc *.log *.out *.lof *.tbd *.tbr *.pdf
Index: anches/cnb_branches/cnb_branch_20090215/doc/modules/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/doc/modules/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,1 +1,0 @@
-*.log *.dvi *.aux *.toc *.log *.out *.tpm *.pdf
Index: anches/cnb_branches/cnb_branch_20090215/doc/pantasks/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/doc/pantasks/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,1 +1,0 @@
-*.log *.dvi *.aux *.toc *.log *.out *.lof *.tbr *.tbd *.pdf
Index: anches/cnb_branches/cnb_branch_20090215/doc/pslib/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/doc/pslib/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,1 +1,0 @@
-*.log *.dvi *.aux *.toc *.log *.out *.lof *.tbr *.tbd *.pdf
Index: anches/cnb_branches/cnb_branch_20090215/doc/psphot/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/doc/psphot/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,1 +1,0 @@
-*.log *.dvi *.aux *.toc *.log *.out *.lof *.tbr *.tbd *.pdf
Index: anches/cnb_branches/cnb_branch_20090215/doc/stamps/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/doc/stamps/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,1 +1,0 @@
-*.log *.dvi *.aux *.toc *.log *.out *.lof *.tbr *.tbd *.pdf *.ps *.tmp
Index: anches/cnb_branches/cnb_branch_20090215/dvoTools/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/dvoTools/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,16 +1,0 @@
-Makefile
-Makefile.in
-aclocal.m4
-autom4te.cache
-compile
-config.guess
-config.log
-config.status
-config.sub
-configure
-depcomp
-install-sh
-ltmain.sh
-missing
-
-libtool
Index: anches/cnb_branches/cnb_branch_20090215/dvoTools/src/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/dvoTools/src/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,9 +1,0 @@
-.deps
-Makefile
-Makefile.in
-config.h
-config.h.in
-dvoApplyCorr
-dvoMakeCorr
-stamp-h1
-.libs
Index: anches/cnb_branches/cnb_branch_20090215/glueforge/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/glueforge/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-Makefile
-Makefile.in
-aclocal.m4
-configure
-autom4te.cache
-config.log
-config.status
-install-sh
-missing
-glueforge
-glueforge.1
Index: anches/cnb_branches/cnb_branch_20090215/glueforge/templates/latex/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/glueforge/templates/latex/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-Makefile
-Makefile.in
Index: anches/cnb_branches/cnb_branch_20090215/glueforge/templates/psdb/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/glueforge/templates/psdb/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-Makefile
-Makefile.in
Index: anches/cnb_branches/cnb_branch_20090215/icd-demo/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/icd-demo/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,1 +1,0 @@
-bin fits
Index: anches/cnb_branches/cnb_branch_20090215/ippMonitor/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippMonitor/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-src
-Makefile
Index: anches/cnb_branches/cnb_branch_20090215/ippMonitor/raw/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippMonitor/raw/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,1 +1,0 @@
-site.php
Index: anches/cnb_branches/cnb_branch_20090215/ippMonitor/src/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippMonitor/src/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,1 +1,0 @@
-*.php
Index: anches/cnb_branches/cnb_branch_20090215/ippScripts/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippScripts/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,6 +1,0 @@
-Build
-META.yml
-Makefile
-Makefile.PL
-_build
-blib
Index: /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/camera_exp.pl
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/camera_exp.pl	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/camera_exp.pl	(revision 23197)
@@ -27,4 +27,17 @@
 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
 use Pod::Usage qw( pod2usage );
+
+# Look for programs we need
+my $missing_tools;
+my $camtool = can_run('camtool') or (warn "Can't find camtool" and $missing_tools = 1);
+my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1);
+my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
+my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
+my $psastro = can_run('psastro') or (warn "Can't find psastro" and $missing_tools = 1);
+my $addstar = can_run('addstar') or (warn "Can't find addstar" and $missing_tools = 1);
+if ($missing_tools) {
+    warn("Can't find required tools.");
+    exit($PS_EXIT_CONFIG_ERROR);
+}
 
 my ( $exp_tag, $cam_id, $camera, $outroot, $recipe, $dbname, $reduction, $dvodb, $verbose, $no_update,
@@ -57,4 +70,8 @@
     defined $camera;
 
+# Unhandled exceptions should be passed on to my_die so they get pushed into the database
+$SIG{__DIE__} = sub { die @_ if $^S;
+                      my_die( $_[0], $cam_id, $PS_EXIT_UNKNOWN_ERROR ); };
+
 $ipprc->define_camera($camera);
 
@@ -84,20 +101,4 @@
 my $recipe_addstar = $ipprc->reduction($reduction, 'ADDSTAR'); # Recipe to use
 &my_die("Unrecognised ADDSTAR recipe", $cam_id, $PS_EXIT_CONFIG_ERROR) unless defined $recipe1;
-
-# Look for programs we need
-my $missing_tools;
-my $camtool = can_run('camtool') or (warn "Can't find camtool" and $missing_tools = 1);
-my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1);
-my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
-my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
-
-# test for addstar and psastro:
-my $psastro = can_run('psastro') or (warn "Can't find psastro" and $missing_tools = 1);
-my $addstar = can_run('addstar') or (warn "Can't find addstar" and $missing_tools = 1);
-
-if ($missing_tools) {
-    warn("Can't find required tools.");
-    exit($PS_EXIT_CONFIG_ERROR);
-}
 
 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
@@ -272,19 +273,19 @@
 
         if ($do_stats) {
-	    my $fpaStatsReal = $ipprc->file_resolve($fpaStats);
-	    &my_die("Couldn't find expected output file: $fpaStats", $cam_id, $PS_EXIT_SYS_ERROR) unless -f $fpaStatsReal;
-
-	    # parse stats from metadata
-	    $command = "$ppStatsFromMetadata $fpaStatsReal - CAMERA_EXP_FPA";
-	    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-		run(command => $command, verbose => $verbose);
-	    unless ($success) {
-		$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-		&my_die("Unable to perform ppStatsFromMetadata: $error_code", $cam_id, $error_code);
-	    }
-	    foreach my $line (@$stdout_buf) {
-		$cmdflags .= " $line";
-	    }
-	    chomp $cmdflags;
+            my $fpaStatsReal = $ipprc->file_resolve($fpaStats);
+            &my_die("Couldn't find expected output file: $fpaStats", $cam_id, $PS_EXIT_SYS_ERROR) unless -f $fpaStatsReal;
+
+            # parse stats from metadata
+            $command = "$ppStatsFromMetadata $fpaStatsReal - CAMERA_EXP_FPA";
+            ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+                run(command => $command, verbose => $verbose);
+            unless ($success) {
+                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+                &my_die("Unable to perform ppStatsFromMetadata: $error_code", $cam_id, $error_code);
+            }
+            foreach my $line (@$stdout_buf) {
+                $cmdflags .= " $line";
+            }
+            chomp $cmdflags;
         }
 
@@ -323,5 +324,5 @@
             $command .= " $realFile";
 
-	    my $mjd_addstar_start = DateTime->now->mjd;   # MJD of starting script
+            my $mjd_addstar_start = DateTime->now->mjd;   # MJD of starting script
 
             my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
@@ -331,5 +332,5 @@
                 &my_die("Unable to perform addstar: $error_code", $cam_id, $error_code);
             }
-	    $dtime_addstar = 86400.0*(DateTime->now->mjd - $mjd_addstar_start);   # MJD of starting script
+            $dtime_addstar = 86400.0*(DateTime->now->mjd - $mjd_addstar_start);   # MJD of starting script
         }
     }
Index: /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/chip_imfile.pl
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/chip_imfile.pl	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/chip_imfile.pl	(revision 23197)
@@ -25,4 +25,15 @@
 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
 use Pod::Usage qw( pod2usage );
+
+# Look for programs we need
+my $missing_tools;
+my $chiptool = can_run('chiptool') or (warn "Can't find chiptool" and $missing_tools = 1);
+my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1);
+my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
+my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
+if ($missing_tools) {
+    warn("Can't find required tools.");
+    exit($PS_EXIT_CONFIG_ERROR);
+}
 
 # Parse the command-line arguments
@@ -53,9 +64,13 @@
     defined $chip_id and
     defined $class_id and
-    defined $chip_imfile_id and 
+    defined $chip_imfile_id and
     defined $uri and
     defined $camera and
     defined $outroot and
     defined $run_state;
+
+# Unhandled exceptions should be passed on to my_die so they get pushed into the database
+$SIG{__DIE__} = sub { die @_ if $^S;
+                      my_die( $_[0], $exp_id, $chip_id, $class_id, $PS_EXIT_UNKNOWN_ERROR ); };
 
 $ipprc->define_camera($camera);
@@ -69,15 +84,4 @@
     print STDOUT "Starting script $0 on $host\n\n";
     print STDOUT "COMMAND IS: @ARGV\n\n";
-}
-
-# Look for programs we need
-my $missing_tools;
-my $chiptool = can_run('chiptool') or (warn "Can't find chiptool" and $missing_tools = 1);
-my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1);
-my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
-my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
-if ($missing_tools) {
-    warn("Can't find required tools.");
-    exit($PS_EXIT_CONFIG_ERROR);
 }
 
@@ -132,6 +136,6 @@
         $command .= " -threads $threads" if defined $threads;
         $command .= " -dbname $dbname" if defined $dbname;
-	$command .= " -image_id $chip_imfile_id" if defined $chip_imfile_id;
-	$command .= " -source_id $source_id" if defined $source_id;
+        $command .= " -image_id $chip_imfile_id" if defined $chip_imfile_id;
+        $command .= " -source_id $source_id" if defined $source_id;
         $command .= " -dumpconfig $configuration";
         $command .= " -tracedest $traceDest -log $logDest";
@@ -142,6 +146,6 @@
         $command .= " -threads $threads" if defined $threads;
         $command .= " -dbname $dbname" if defined $dbname;
-	$command .= " -image_id $chip_imfile_id" if defined $chip_imfile_id;
-	$command .= " -source_id $source_id" if defined $source_id;
+        $command .= " -image_id $chip_imfile_id" if defined $chip_imfile_id;
+        $command .= " -source_id $source_id" if defined $source_id;
         $command .= " -tracedest $traceDest -log $logDest";
         $command .= " -Db PPIMAGE:PHOTOM FALSE";
Index: /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/detrend_correct_imfile.pl
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/detrend_correct_imfile.pl	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/detrend_correct_imfile.pl	(revision 23197)
@@ -24,4 +24,13 @@
 use Pod::Usage qw( pod2usage );
 
+# Look for programs we need
+my $missing_tools;
+my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
+my $dvoApplyCorr = can_run('dvoApplyCorr') or (warn "Can't find dvoApplyCorr" and $missing_tools = 1);
+if ($missing_tools) {
+    warn("Can't find required tools.");
+    exit($PS_EXIT_CONFIG_ERROR);
+}
+
 my ( $det_id, $class_id, $det_type, $input_uri, $camera, $dbname,
      $verbose, $no_update, $no_op, $outroot, $redirect, $corr_uri );
@@ -43,5 +52,5 @@
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
 pod2usage( -msg => "Required options: --det_id --class_id --det_type --input_uri --camera --outroot",
-	   -exitval => 3)
+           -exitval => 3)
     unless defined $det_id
     and defined $class_id
@@ -50,4 +59,8 @@
     and defined $outroot
     and defined $camera;
+
+# Unhandled exceptions should be passed on to my_die so they get pushed into the database
+$SIG{__DIE__} = sub { die @_ if $^S;
+                      my_die( $_[0], $det_id, $class_id, $PS_EXIT_UNKNOWN_ERROR ); };
 
 # XXX this exits with status = 0 on failure
@@ -60,6 +73,6 @@
 }
 
-# Recipes to use as a function of detrend type 
-# XXX there are no recipe options for dvoApplyCorr... 
+# Recipes to use as a function of detrend type
+# XXX there are no recipe options for dvoApplyCorr...
 # XXX in the future, we may define corrections other than the flat-field correction
 # $reduction = "DETREND" unless defined $reduction;
@@ -69,13 +82,4 @@
 # det_type is type of the CORRECTED (output) file
 if ($det_type ne "FLAT") { warn ("unexpected input detrend type: correcting data of type $det_type"); }
-
-# Look for programs we need
-my $missing_tools;
-my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
-my $dvoApplyCorr = can_run('dvoApplyCorr') or (warn "Can't find dvoApplyCorr" and $missing_tools = 1);
-if ($missing_tools) { 
-    warn("Can't find required tools.");
-    exit($PS_EXIT_CONFIG_ERROR); 
-}
 
 &my_die("Couldn't find input file: $input_uri\n", $det_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($input_uri);
@@ -91,8 +95,8 @@
 
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-	run(command => $command, verbose => $verbose);
+        run(command => $command, verbose => $verbose);
     unless ($success) {
-	$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-	&my_die("Unable to perform ppImage: $error_code", $det_id, $class_id, $error_code);
+        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+        &my_die("Unable to perform ppImage: $error_code", $det_id, $class_id, $error_code);
     }
 
@@ -111,9 +115,9 @@
 unless ($no_update) {
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-	run(command => $command, verbose => $verbose);
+        run(command => $command, verbose => $verbose);
     unless ($success) {
-	$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-	warn("Unable to perform dettool -addcorrectimfile: $error_code\n");
-	exit($error_code);
+        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+        warn("Unable to perform dettool -addcorrectimfile: $error_code\n");
+        exit($error_code);
     }
 } else {
@@ -124,5 +128,5 @@
 {
     my $msg = shift; # Warning message on die
-    my $det_id = shift;		# Detrend identifier
+    my $det_id = shift;         # Detrend identifier
     my $class_id = shift; # Class identifier
     my $exit_code = shift; # Exit code to add
@@ -130,10 +134,10 @@
     carp($msg);
     if (defined $det_id and defined $class_id and not $no_update) {
-	my $command = "$dettool -addcorrectimfile";
-	$command .= " -det_id $det_id";
-	$command .= " -class_id $class_id";
-	$command .= " -path_base $outroot";
-	$command .= " -code $exit_code";
-	$command .= " -dbname $dbname" if defined $dbname;
+        my $command = "$dettool -addcorrectimfile";
+        $command .= " -det_id $det_id";
+        $command .= " -class_id $class_id";
+        $command .= " -path_base $outroot";
+        $command .= " -code $exit_code";
+        $command .= " -dbname $dbname" if defined $dbname;
         system ($command);
     }
Index: /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/detrend_norm_apply.pl
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/detrend_norm_apply.pl	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/detrend_norm_apply.pl	(revision 23197)
@@ -22,4 +22,14 @@
 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
 use Pod::Usage qw( pod2usage );
+
+# Look for programs we need
+my $missing_tools;
+my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
+my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1);
+my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
+if ($missing_tools) {
+    warn("Can't find required tools.");
+    exit($PS_EXIT_CONFIG_ERROR);
+}
 
 # Parse the command-line
@@ -54,7 +64,11 @@
     defined $outroot;
 
+# Unhandled exceptions should be passed on to my_die so they get pushed into the database
+$SIG{__DIE__} = sub { die @_ if $^S;
+                      my_die( $_[0], $det_id, $iter, $class_id, $PS_EXIT_UNKNOWN_ERROR ); };
+
 $ipprc->define_camera($camera);
 
-my $logDest = $ipprc->filename("LOG.IMFILE", $outroot, $class_id) 
+my $logDest = $ipprc->filename("LOG.IMFILE", $outroot, $class_id)
         or &my_die("Missing entry from camera config", $det_id, $iter, $class_id, $PS_EXIT_CONFIG_ERROR);
 $ipprc->redirect_output($logDest) if $redirect;
@@ -64,8 +78,8 @@
 # Define which detrend types we normalise
 use constant DETTYPE => {
-    'bias'     	       => 'bias',
-    'dark'     	       => 'dark',   
+    'bias'             => 'bias',
+    'dark'             => 'dark',
     'dark_premask'     => 'dark',
-    'shutter'  	       => 'shutter',
+    'shutter'          => 'shutter',
     'flat_premask'     => 'flat',
     'domeflat_premask' => 'flat',
@@ -73,27 +87,17 @@
     'flat_raw'         => 'flat',
     'domeflat_raw'     => 'flat',
-    'skyflat_raw'      => 'flat',   
-    'flat'     	       => 'flat',
-    'domeflat' 	       => 'flat',
-    'skyflat'  	       => 'flat',   
-    'fringe'   	       => 'fringe',   
-    'mask'     	       => 'mask',
-    'darkmask' 	       => 'mask',
-    'flatmask' 	       => 'mask',
-    }; 
+    'skyflat_raw'      => 'flat',
+    'flat'             => 'flat',
+    'domeflat'         => 'flat',
+    'skyflat'          => 'flat',
+    'fringe'           => 'fringe',
+    'mask'             => 'mask',
+    'darkmask'         => 'mask',
+    'flatmask'         => 'mask',
+    };
 
 # convert supplied detrend type to a controlled namespace
 &my_die("Unrecognised detrend type: $det_type", $det_id, $iter, $class_id, $PS_EXIT_PROG_ERROR) unless exists DETTYPE()->{lc($det_type)};
 my $det_type_real = DETTYPE()->{lc($det_type)};
-
-# Look for programs we need
-my $missing_tools;
-my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
-my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1);
-my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
-if ($missing_tools) {
-    warn("Can't find required tools.");
-    exit($PS_EXIT_CONFIG_ERROR);
-}
 
 &my_die("Couldn't find input file: $input_uri\n", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($input_uri);
@@ -124,8 +128,8 @@
     # we cannot use ppImage to load a normalized mask : just copy it and build the jpeg images
     if ($det_type_real eq 'mask') {
-	$RECIPE_PPIMAGE = 'PPIMAGE_BIN';
-	my $input_real = $ipprc->file_resolve($input_uri, 0);
-	my $output_real = $ipprc->file_resolve($output, 1);
-	system ("cp $input_real $output_real");
+        $RECIPE_PPIMAGE = 'PPIMAGE_BIN';
+        my $input_real = $ipprc->file_resolve($input_uri, 0);
+        my $output_real = $ipprc->file_resolve($output, 1);
+        system ("cp $input_real $output_real");
     }
 
@@ -162,5 +166,5 @@
     }
     foreach my $line (@$stdout_buf) {
-	$cmdflags .= " $line";
+        $cmdflags .= " $line";
     }
     chomp $cmdflags;
@@ -204,5 +208,5 @@
         $command .= " -iteration $iter";
         $command .= " -class_id $class_id";
-	$command .= " -path_base $outroot";
+        $command .= " -path_base $outroot";
         $command .= " -code $exit_code";
         $command .= " -dbname $dbname" if defined $dbname;
Index: /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/detrend_norm_calc.pl
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/detrend_norm_calc.pl	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/detrend_norm_calc.pl	(revision 23197)
@@ -25,15 +25,24 @@
 use Pod::Usage qw( pod2usage );
 
+# Look for programs we need
+my $missing_tools;
+my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
+my $ppNormCalc = can_run('ppNormCalc') or (warn "Can't find ppNormCalc" and $missing_tools = 1);
+if ($missing_tools) {
+    warn("Can't find required tools.");
+    exit($PS_EXIT_CONFIG_ERROR);
+}
+
 # Parse command-line arguments
 my ($det_id, $iter, $detType, $outroot, $dbname, $verbose, $no_update, $no_op, $redirect );
 GetOptions(
-    'det_id|d=s'	=> \$det_id,    # Detrend id			     
-    'iteration|i=s'	=> \$iter,	# Iteration			     
-    'det_type|t=s'  	=> \$detType,	# Detrend type			     
-    'outroot|w=s'   	=> \$outroot,   # output file base name
-    'dbname|d=s'    	=> \$dbname,	# Database name			     
-    'verbose'       	=> \$verbose,   # Print to stdout
-    'no-update'     	=> \$no_update,	# Don't update the database?	     
-    'no-op'         	=> \$no_op,	# Don't do operations                
+    'det_id|d=s'        => \$det_id,    # Detrend id
+    'iteration|i=s'     => \$iter,      # Iteration
+    'det_type|t=s'      => \$detType,   # Detrend type
+    'outroot|w=s'       => \$outroot,   # output file base name
+    'dbname|d=s'        => \$dbname,    # Database name
+    'verbose'           => \$verbose,   # Print to stdout
+    'no-update'         => \$no_update, # Don't update the database?
+    'no-op'             => \$no_op,     # Don't do operations
     'redirect-output'   => \$redirect,
     ) or pod2usage( 2 );
@@ -41,11 +50,15 @@
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
 pod2usage( -msg => "Required options --det_id --iteration --det_type --outroot",
-	   -exitval => 3,
-	   ) unless 
-    defined $det_id  and 
-    defined $iter    and 
+           -exitval => 3,
+           ) unless
+    defined $det_id  and
+    defined $iter    and
     defined $detType and
     defined $outroot;
 
+# Unhandled exceptions should be passed on to my_die so they get pushed into the database
+$SIG{__DIE__} = sub { die @_ if $^S;
+                      my_die( $_[0], $det_id, $iter, $PS_EXIT_UNKNOWN_ERROR ); };
+
 my $logfile = $outroot . ".log";
 
@@ -56,8 +69,8 @@
 # Define which detrend types we normalise
 use constant NORMALIZE => {
-    'bias'     	       => 0,
-    'dark'     	       => 0,   
+    'bias'             => 0,
+    'dark'             => 0,
     'dark_premask'     => 0,
-    'shutter'  	       => 0,
+    'shutter'          => 0,
     'flat_premask'     => 1,
     'domeflat_premask' => 1,
@@ -66,21 +79,12 @@
     'domeflat_raw'     => 1,
     'skyflat_raw'      => 1,
-    'flat'     	       => 1,
-    'domeflat' 	       => 1,
-    'skyflat'  	       => 1,   
-    'fringe'   	       => 0,   
-    'mask'     	       => 0,
-    'darkmask' 	       => 0,
-    'flatmask' 	       => 0,
-    }; 
-
-# Look for programs we need
-my $missing_tools;
-my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
-my $ppNormCalc = can_run('ppNormCalc') or (warn "Can't find ppNormCalc" and $missing_tools = 1);
-if ($missing_tools) { 
-    warn("Can't find required tools.");
-    exit($PS_EXIT_CONFIG_ERROR); 
-}
+    'flat'             => 1,
+    'domeflat'         => 1,
+    'skyflat'          => 1,
+    'fringe'           => 0,
+    'mask'             => 0,
+    'darkmask'         => 0,
+    'flatmask'         => 0,
+    };
 
 &my_die("Unrecognised detrend type: $detType", $det_id, $iter, $PS_EXIT_PROG_ERROR) unless exists NORMALIZE()->{lc($detType)};
@@ -89,5 +93,5 @@
 
 # Get the list of inputs
-my @files;			# The input files
+my @files;                      # The input files
 {
     my $command = "$dettool -processedimfile";
@@ -99,79 +103,79 @@
     print "Running [$command]...\n" if $verbose;
     if (not run(\@command, \$stdin, \$stdout, \$stderr)) {
-	&my_die("Unable to perform dettool -processedimfile on detrend $det_id/$iter: $?",
-		$det_id, $iter, $PS_EXIT_SYS_ERROR);
+        &my_die("Unable to perform dettool -processedimfile on detrend $det_id/$iter: $?",
+                $det_id, $iter, $PS_EXIT_SYS_ERROR);
     }
     print $stdout . "\n" if $verbose;
-    
+
     # Because of the length, need to split into individual metadatas --- it parses SO much quicker!
     my @whole = split /\n/, $stdout;
     my @single = ();
     while ( scalar @whole > 0 ) {
-	my $value = shift @whole;
-	push @single, $value;
-	if ($value =~ /^\s*END\s*$/) {
-	    push @single, "\n";
-
-	    my $list = parse_md_list( $mdcParser->parse( join( "\n", @single ) ) );
-	    &my_die("Unable to parse output from dettool", $det_id, $iter, $PS_EXIT_PROG_ERROR) unless
-		defined $list;
-	    push @files, @$list;
-	    @single = ();
-	}
-    }
-}
-
-my $norms;			# MDC with normalisations
+        my $value = shift @whole;
+        push @single, $value;
+        if ($value =~ /^\s*END\s*$/) {
+            push @single, "\n";
+
+            my $list = parse_md_list( $mdcParser->parse( join( "\n", @single ) ) );
+            &my_die("Unable to parse output from dettool", $det_id, $iter, $PS_EXIT_PROG_ERROR) unless
+                defined $list;
+            push @files, @$list;
+            @single = ();
+        }
+    }
+}
+
+my $norms;                      # MDC with normalisations
 if (NORMALIZE()->{lc($detType)} and not $no_op) {
 
     my %matrix; # Matrix of statistics as a function of exposures and classes
     foreach my $file (@files) {
-	my $exp_id = $file->{'exp_id'}; # Exposure ID
-	my $class_id = $file->{'class_id'}; # Class ID
-	my $stat = $file->{STATISTIC()}; # Statistic of interest
-	
-	# Create matrix elements
-	$matrix{$exp_id} = {} if not defined $matrix{$exp_id};
-	$matrix{$exp_id}->{$class_id} = $stat;
-    }
-    
+        my $exp_id = $file->{'exp_id'}; # Exposure ID
+        my $class_id = $file->{'class_id'}; # Class ID
+        my $stat = $file->{STATISTIC()}; # Statistic of interest
+
+        # Create matrix elements
+        $matrix{$exp_id} = {} if not defined $matrix{$exp_id};
+        $matrix{$exp_id}->{$class_id} = $stat;
+    }
+
     # Generate the input for ppNormCalc
-    my $normData;			# Normalisation data
+    my $normData;                       # Normalisation data
     foreach my $exp_id (keys %matrix) {
-	$normData .= "$exp_id\tMETADATA\n";
-	foreach my $class_id (keys %{$matrix{$exp_id}}) {
-	    $normData .= "\t" . $class_id . "\tF32\t" . $matrix{$exp_id}->{$class_id} . "\n";
-	}
-	$normData .= "END\n\n";
+        $normData .= "$exp_id\tMETADATA\n";
+        foreach my $class_id (keys %{$matrix{$exp_id}}) {
+            $normData .= "\t" . $class_id . "\tF32\t" . $matrix{$exp_id}->{$class_id} . "\n";
+        }
+        $normData .= "END\n\n";
     }
 
     # Run ppNormCalc
     {
-	my ( $stdout, $stderr ); # Buffers for running program
-	my @command = split /\s+/, $ppNormCalc;
-	print "Running [$ppNormCalc]...\n" if $verbose;
-	if (not run(\@command, \$normData, \$stdout, \$stderr)) {
-	    &my_die("Unable to perform ppNormCalc: $?", $det_id, $iter, $PS_EXIT_SYS_ERROR);
-	}
-	print $stdout . "\n" if $verbose;
-	
-	# Parse the output
-	$norms = $mdcParser->parse($stdout);
-	&my_die("Unable to parse metadata config doc", $det_id, $iter, $PS_EXIT_PROG_ERROR) unless $norms;
+        my ( $stdout, $stderr ); # Buffers for running program
+        my @command = split /\s+/, $ppNormCalc;
+        print "Running [$ppNormCalc]...\n" if $verbose;
+        if (not run(\@command, \$normData, \$stdout, \$stderr)) {
+            &my_die("Unable to perform ppNormCalc: $?", $det_id, $iter, $PS_EXIT_SYS_ERROR);
+        }
+        print $stdout . "\n" if $verbose;
+
+        # Parse the output
+        $norms = $mdcParser->parse($stdout);
+        &my_die("Unable to parse metadata config doc", $det_id, $iter, $PS_EXIT_PROG_ERROR) unless $norms;
     }
 
 } else {
     # It's something that doesn't need normalisation --- just push in a normalisation of 1
-    my %classes;		# List of unique classes
+    my %classes;                # List of unique classes
     foreach my $file (@files) {
-	my $class_id = $file->{'class_id'}; # Class Id
-	$classes{$class_id} = 1;
-    }
-    
+        my $class_id = $file->{'class_id'}; # Class Id
+        $classes{$class_id} = 1;
+    }
+
     foreach my $class_id (keys %classes) {
-	my %mdValue;	# Metadata value for this class id
-	$mdValue{name} = $class_id;
-	$mdValue{value} = 1.0;
-	push @$norms, \%mdValue;
+        my %mdValue;    # Metadata value for this class id
+        $mdValue{name} = $class_id;
+        $mdValue{value} = 1.0;
+        push @$norms, \%mdValue;
     }
 }
@@ -186,25 +190,25 @@
     foreach my $normItem (@$norms) {
 
-	my $className = $normItem->{name}; # Name of component
-	my $normalisation = $normItem->{value}; # Normalisation for component
-
-	if ($normalisation == 0.0 or lc($normalisation) eq 'nan') {
-	    warn("Class $className has bad normalisation: $normalisation");
-	    exit($PS_EXIT_SYS_ERROR);
-	}
-
-	my $command = $commandBase;
-	$command .= " -class_id $className";
-	$command .= " -norm $normalisation";
-
-	my @command = split /\s+/, $command;
-
-	my ( $stdin, $stdout, $stderr ); # Buffers for running program
-	print "Running [$command]...\n" if $verbose;
-	if (not run \@command, \$stdin, \$stdout, \$stderr) {
-	    warn("Unable to perform dettool -addnormstat for $className: $?");
-	    exit($PS_EXIT_SYS_ERROR);
-	}
-	print $stdout . "\n" if $verbose;
+        my $className = $normItem->{name}; # Name of component
+        my $normalisation = $normItem->{value}; # Normalisation for component
+
+        if ($normalisation == 0.0 or lc($normalisation) eq 'nan') {
+            warn("Class $className has bad normalisation: $normalisation");
+            exit($PS_EXIT_SYS_ERROR);
+        }
+
+        my $command = $commandBase;
+        $command .= " -class_id $className";
+        $command .= " -norm $normalisation";
+
+        my @command = split /\s+/, $command;
+
+        my ( $stdin, $stdout, $stderr ); # Buffers for running program
+        print "Running [$command]...\n" if $verbose;
+        if (not run \@command, \$stdin, \$stdout, \$stderr) {
+            warn("Unable to perform dettool -addnormstat for $className: $?");
+            exit($PS_EXIT_SYS_ERROR);
+        }
+        print $stdout . "\n" if $verbose;
     }
 } else {
@@ -212,12 +216,12 @@
     foreach my $normItem (@$norms) {
 
-	my $className = $normItem->{name}; # Name of component
-	my $normalisation = $normItem->{value}; # Normalisation for component
-
-	if ($normalisation == 0.0 or lc($normalisation) eq 'nan') {
-	    warn("Class $className has bad normalisation: $normalisation");
-	    exit($PS_EXIT_SYS_ERROR);
-	}
-	print "$className : $normalisation\n";
+        my $className = $normItem->{name}; # Name of component
+        my $normalisation = $normItem->{value}; # Normalisation for component
+
+        if ($normalisation == 0.0 or lc($normalisation) eq 'nan') {
+            warn("Class $className has bad normalisation: $normalisation");
+            exit($PS_EXIT_SYS_ERROR);
+        }
+        print "$className : $normalisation\n";
     }
 }
@@ -225,17 +229,17 @@
 sub my_die
 {
-    my $msg = shift;		# Warning message on die
-    my $det_id = shift;		# Detrend identifier
-    my $iter = shift;		# Iteration
-    my $exit_code = shift;	# Exit code to add
+    my $msg = shift;            # Warning message on die
+    my $det_id = shift;         # Detrend identifier
+    my $iter = shift;           # Iteration
+    my $exit_code = shift;      # Exit code to add
 
     carp($msg);
     if (defined $det_id and defined $iter and not $no_update) {
-	my $command = "$dettool -addnormalizedstat";
-	$command .= " -det_id $det_id";
-	$command .= " -iteration $iter";
-	# XXX EAM : we should add this to the db : $command .= " -path_base $outroot";
-	$command .= " -code $exit_code";
-	$command .= " -dbname $dbname" if defined $dbname;
+        my $command = "$dettool -addnormalizedstat";
+        $command .= " -det_id $det_id";
+        $command .= " -iteration $iter";
+        # XXX EAM : we should add this to the db : $command .= " -path_base $outroot";
+        $command .= " -code $exit_code";
+        $command .= " -dbname $dbname" if defined $dbname;
         system ($command);
     }
Index: /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/detrend_norm_exp.pl
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/detrend_norm_exp.pl	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/detrend_norm_exp.pl	(revision 23197)
@@ -24,4 +24,14 @@
 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
 use Pod::Usage qw( pod2usage );
+
+# Look for programs we need
+my $missing_tools;
+my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
+my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1);
+my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
+if ($missing_tools) {
+    warn("Can't find required tools.");
+    exit($PS_EXIT_CONFIG_ERROR);
+}
 
 my ($det_id, $iter, $det_type, $camera, $outroot, $dbname, $reduction, $verbose, $no_update, $no_op, $redirect, $save_temps);
@@ -50,4 +60,8 @@
     defined $outroot;
 
+# Unhandled exceptions should be passed on to my_die so they get pushed into the database
+$SIG{__DIE__} = sub { die @_ if $^S;
+                      my_die( $_[0], $det_id, $iter, $PS_EXIT_UNKNOWN_ERROR ); };
+
 my $logfile = $outroot . ".log";
 
@@ -60,14 +74,4 @@
 my $recipe = $ipprc->reduction($reduction, uc($det_type) . '_JPEG_IMAGE');
 &my_die("Unrecognised detrend type: $det_type", $det_id, $iter, $PS_EXIT_PROG_ERROR) unless defined $recipe;
-
-# Look for programs we need
-my $missing_tools;
-my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
-my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1);
-my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
-if ($missing_tools) {
-    warn("Can't find required tools.");
-    exit($PS_EXIT_CONFIG_ERROR);
-}
 
 # Get list of component files
Index: /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/detrend_process_exp.pl
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/detrend_process_exp.pl	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/detrend_process_exp.pl	(revision 23197)
@@ -24,4 +24,14 @@
 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
 use Pod::Usage qw( pod2usage );
+
+# Look for programs we need
+my $missing_tools;
+my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
+my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1);
+my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
+if ($missing_tools) {
+    warn("Can't find required tools.");
+    exit($PS_EXIT_CONFIG_ERROR);
+}
 
 my ( $det_id, $exp_id, $det_type, $exp_tag, $camera, $outroot, $dbname, $reduction, $verbose, $no_update,
@@ -53,4 +63,8 @@
     defined $outroot;
 
+# Unhandled exceptions should be passed on to my_die so they get pushed into the database
+$SIG{__DIE__} = sub { die @_ if $^S;
+                      my_die( $_[0], $det_id, $exp_id, $PS_EXIT_UNKNOWN_ERROR ); };
+
 $ipprc->define_camera($camera);
 
@@ -66,14 +80,4 @@
 my $recipe = $ipprc->reduction($reduction, uc($det_type) . '_JPEG_IMAGE'); # Recipe to use
 &my_die("Unrecognised detrend type: $det_type", $det_id, $exp_id, $PS_EXIT_PROG_ERROR) unless defined $recipe;
-
-# Look for programs we need
-my $missing_tools;
-my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
-my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1);
-my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
-if ($missing_tools) {
-    warn("Can't find required tools.");
-    exit($PS_EXIT_CONFIG_ERROR);
-}
 
 my $cmdflags;
Index: /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/detrend_process_imfile.pl
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/detrend_process_imfile.pl	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/detrend_process_imfile.pl	(revision 23197)
@@ -22,4 +22,14 @@
 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
 use Pod::Usage qw( pod2usage );
+
+# Look for programs we need
+my $missing_tools;
+my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
+my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1);
+my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
+if ($missing_tools) {
+    warn("Can't find required tools.");
+    exit($PS_EXIT_CONFIG_ERROR);
+}
 
 my ( $det_id, $exp_id, $class_id, $det_type, $exp_tag, $input_uri, $camera, $outroot, $dbname, $reduction,
@@ -55,4 +65,8 @@
     defined $outroot;
 
+# Unhandled exceptions should be passed on to my_die so they get pushed into the database
+$SIG{__DIE__} = sub { die @_ if $^S;
+                      my_die( $_[0], $det_id, $exp_id, $class_id, $PS_EXIT_UNKNOWN_ERROR ); };
+
 # XXX this exits with status = 0 on failure
 $ipprc->define_camera($camera);
@@ -66,14 +80,4 @@
 my $ppimage_recipe = $ipprc->reduction($reduction, uc($det_type) . '_PROCESS'); # Recipe name for ppImage
 my $jpeg_recipe = $ipprc->reduction($reduction, uc($det_type) . '_JPEG_IMAGE'); # Recipe name for JPEG
-
-# Look for programs we need
-my $missing_tools;
-my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
-my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1);
-my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
-if ($missing_tools) {
-    warn("Can't find required tools.");
-    exit($PS_EXIT_CONFIG_ERROR);
-}
 
 &my_die("Couldn't find input file: $input_uri\n", $det_id, $exp_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($input_uri);
@@ -128,5 +132,5 @@
     }
     foreach my $line (@$stdout_buf) {
-	$cmdflags .= " $line";
+        $cmdflags .= " $line";
     }
     chomp $cmdflags;
Index: /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/detrend_reject_exp.pl
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/detrend_reject_exp.pl	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/detrend_reject_exp.pl	(revision 23197)
@@ -27,4 +27,12 @@
 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
 use Pod::Usage qw( pod2usage );
+
+# Look for programs we need
+my $missing_tools;
+my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
+if ($missing_tools) {
+    warn("Can't find required tools.");
+    exit($PS_EXIT_CONFIG_ERROR);
+}
 
 my ($det_id, $iter, $det_type, $camera, $outroot, $filter, $dbname, $verbose, $no_update, $no_op, $redirect);
@@ -52,4 +60,8 @@
     defined $outroot;
 
+# Unhandled exceptions should be passed on to my_die so they get pushed into the database
+$SIG{__DIE__} = sub { die @_ if $^S;
+                      my_die( $_[0], $det_id, $iter, $PS_EXIT_UNKNOWN_ERROR ); };
+
 # check for existing directory, generate if needed
 $ipprc->outroot_prepare($outroot);
@@ -89,12 +101,4 @@
 my $rejstats = PS::IPP::Metadata::Stats->new($REJSTATS); # Stats parser
 
-# Look for programs we need
-my $missing_tools;
-my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
-if ($missing_tools) {
-    warn("Can't find required tools.");
-    exit($PS_EXIT_CONFIG_ERROR);
-}
-
 # Get list of component files
 my ($exposures, $command, $success, $error_code, $full_buf, $stdout_buf, $stderr_buf);
@@ -345,5 +349,5 @@
         $command .= " -det_id $det_id";
         $command .= " -iteration $iter";
-	# XXX EAM : we should add this to the db : $command .= " -path_base $outroot";
+        # XXX EAM : we should add this to the db : $command .= " -path_base $outroot";
         $command .= " -code $exit_code";
         $command .= " -dbname $dbname" if defined $dbname;
Index: /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/detrend_resid_exp.pl
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/detrend_resid_exp.pl	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/detrend_resid_exp.pl	(revision 23197)
@@ -35,4 +35,14 @@
 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt ); # option parsing
 use Pod::Usage qw( pod2usage );
+
+# Look for programs we need
+my $missing_tools;
+my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
+my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1);
+my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
+if ($missing_tools) {
+    warn("Can't find required tools.");
+    exit($PS_EXIT_CONFIG_ERROR);
+}
 
 # parse the command-line options
@@ -69,4 +79,8 @@
     defined $outroot;
 
+# Unhandled exceptions should be passed on to my_die so they get pushed into the database
+$SIG{__DIE__} = sub { die @_ if $^S;
+                      my_die( $_[0], $det_id, $iter, $exp_id, $PS_EXIT_UNKNOWN_ERROR ); };
+
 # load IPP config information for the specified camera
 $ipprc->define_camera($camera);
@@ -81,14 +95,4 @@
 my $recipe = $ipprc->reduction($reduction, uc($det_type) . '_JPEG_RESID'); # Recipe to use
 &my_die("Unrecognised detrend type: $det_type", $det_id, $iter, $PS_EXIT_PROG_ERROR) unless defined $recipe;
-
-# Look for programs we need
-my $missing_tools;
-my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
-my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1);
-my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
-if ($missing_tools) {
-    warn("Can't find required tools.");
-    exit($PS_EXIT_CONFIG_ERROR);
-}
 
 # Get list of imfile files
Index: /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/detrend_resid_imfile.pl
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/detrend_resid_imfile.pl	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/detrend_resid_imfile.pl	(revision 23197)
@@ -22,4 +22,15 @@
 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
 use Pod::Usage qw( pod2usage );
+
+# Look for programs we need
+my $missing_tools;
+my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
+my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1);
+my $ppStats = can_run('ppStats') or (warn "Can't find ppStats" and $missing_tools = 1);
+my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
+if ($missing_tools) {
+    warn("Can't find required tools.");
+    exit($PS_EXIT_CONFIG_ERROR);
+}
 
 my ( $det_id, $iter, $ref_det_id, $ref_iter, $exp_id, $exp_tag, $class_id, $det_type, $detrend, $input_uri, $camera, $mode, $outroot,
@@ -65,4 +76,8 @@
     defined $detrend;
 
+# Unhandled exceptions should be passed on to my_die so they get pushed into the database
+$SIG{__DIE__} = sub { die @_ if $^S;
+                      my_die( $_[0], $det_id, $iter, $exp_id, $class_id, $PS_EXIT_UNKNOWN_ERROR ); };
+
 $ipprc->define_camera($camera);
 my $logDest     = $ipprc->filename("LOG.IMFILE", $outroot, $class_id);
@@ -109,15 +124,4 @@
 };
 
-# Look for programs we need
-my $missing_tools;
-my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
-my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1);
-my $ppStats = can_run('ppStats') or (warn "Can't find ppStats" and $missing_tools = 1);
-my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
-if ($missing_tools) {
-    warn("Can't find required tools.");
-    exit($PS_EXIT_CONFIG_ERROR);
-}
-
 # outroot examples (HOST components must be set)
 # file://data/ipp004.0/gpc1/20080130
@@ -179,5 +183,5 @@
     }
     foreach my $line (@$stdout_buf) {
-	$cmdflags .= " $line";
+        $cmdflags .= " $line";
     }
     chomp $cmdflags;
@@ -192,5 +196,5 @@
     }
     foreach my $line (@$stdout_buf) {
-	$cmdflags .= " $line";
+        $cmdflags .= " $line";
     }
     chomp $cmdflags;
Index: /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/detrend_stack.pl
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/detrend_stack.pl	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/detrend_stack.pl	(revision 23197)
@@ -23,4 +23,14 @@
 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
 use Pod::Usage qw( pod2usage );
+
+# Look for programs we need
+my $missing_tools;
+my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
+my $ppMerge = can_run('ppMerge') or (warn "Can't find ppMerge" and $missing_tools = 1);
+my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
+if ($missing_tools) {
+    warn("Can't find required tools.");
+    exit($PS_EXIT_CONFIG_ERROR);
+}
 
 my ( $det_id, $iter, $class_id, $det_type, $camera, $outroot, $dbname, $reduction, $threads, $verbose, $save_temps,
@@ -59,4 +69,8 @@
     or &my_die("Missing entry in file rules", $det_id, $iter, $class_id, $PS_EXIT_CONFIG_ERROR);
 
+# Unhandled exceptions should be passed on to my_die so they get pushed into the database
+$SIG{__DIE__} = sub { die @_ if $^S;
+                      my_die( $_[0], $det_id, $iter, $class_id, $PS_EXIT_UNKNOWN_ERROR ); };
+
 # optionally redirect the outputs from this script to LOG.IMFILE
 $ipprc->redirect_output($logDest) if $redirect;
@@ -65,14 +79,4 @@
 $reduction = "DETREND" unless defined $reduction;
 my $recipe = $ipprc->reduction($reduction, $det_type . '_STACK'); # Recipe name to use
-
-# Look for programs we need
-my $missing_tools;
-my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
-my $ppMerge = can_run('ppMerge') or (warn "Can't find ppMerge" and $missing_tools = 1);
-my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
-if ($missing_tools) {
-    warn("Can't find required tools.");
-    exit($PS_EXIT_CONFIG_ERROR);
-}
 
 # The output file rule name depends on the detrend type
@@ -219,5 +223,5 @@
     }
     foreach my $line (@$stdout_buf) {
-	$cmdflags .= " $line";
+        $cmdflags .= " $line";
     }
     chomp $cmdflags;
@@ -261,5 +265,5 @@
         $command .= " -iteration $iter";
         $command .= " -class_id $class_id";
-	# XXX EAM : we should add this to the db : $command .= " -path_base $outroot";
+        # XXX EAM : we should add this to the db : $command .= " -path_base $outroot";
         $command .= " -code $exit_code";
         $command .= " -dbname $dbname" if defined $dbname;
Index: /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/diff_skycell.pl
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/diff_skycell.pl	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/diff_skycell.pl	(revision 23197)
@@ -27,9 +27,19 @@
 use Pod::Usage qw( pod2usage );
 
+# Look for programs we need
+my $missing_tools;
+my $difftool = can_run('difftool') or (warn "Can't find difftool" and $missing_tools = 1);
+my $ppSub = can_run('ppSub') or (warn "Can't find ppSub" and $missing_tools = 1);
+my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
+if ($missing_tools) {
+    warn("Can't find required tools.");
+    exit($PS_EXIT_CONFIG_ERROR);
+}
+
 my ($diff_id, $dbname, $threads, $outroot, $reduction, $verbose, $no_update, $no_op, $redirect);
 my ($skycell_id, $diff_skyfile_id);
 GetOptions(
     'diff_id=s'         => \$diff_id, # Diff identifier
-    'skycell_id=s'      => \$skycell_id, # Diff identifier
+    'skycell_id=s'      => \$skycell_id, # Skycell identifier
     'diff_skyfile_id=s' => \$diff_skyfile_id, # Diff identifier
     'dbname|d=s'        => \$dbname, # Database name
@@ -52,21 +62,14 @@
     and defined $outroot;
 
+# Unhandled exceptions should be passed on to my_die so they get pushed into the database
+$SIG{__DIE__} = sub { die @_ if $^S;
+                      my_die( $_[0], $diff_id, $skycell_id, $PS_EXIT_UNKNOWN_ERROR ); };
+
 # XXX camera is not known here; cannot use filerules...
 # my $logDest = $ipprc->filename("LOG.EXP", $outroot);
-
 my $logDest = "$outroot.log";
 $ipprc->redirect_output($logDest) if $redirect;
 
 my $source_id = $ipprc->source_id($dbname, $PS_TABLE_ID_DIFF);
-
-# Look for programs we need
-my $missing_tools;
-my $difftool = can_run('difftool') or (warn "Can't find difftool" and $missing_tools = 1);
-my $ppSub = can_run('ppSub') or (warn "Can't find ppSub" and $missing_tools = 1);
-my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
-if ($missing_tools) {
-    warn("Can't find required tools.");
-    exit($PS_EXIT_CONFIG_ERROR);
-}
 
 # Get list of components for subtraction
@@ -80,15 +83,14 @@
     unless ($success) {
         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-        &my_die("Unable to perform difftool -inputskyfile: $error_code", $diff_id, $error_code);
+        &my_die("Unable to perform difftool -inputskyfile: $error_code", $diff_id, $skycell_id, $error_code);
     }
 
     my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
-        &my_die("Unable to parse metadata config doc", $diff_id, $PS_EXIT_PROG_ERROR);
+        &my_die("Unable to parse metadata config doc", $diff_id, $skycell_id, $PS_EXIT_PROG_ERROR);
     $files = parse_md_list($metadata) or
-        &my_die("Unable to parse metadata list", $diff_id, $PS_EXIT_PROG_ERROR);
-}
-
-&my_die("Subtraction list does not contain exactly two elements", $diff_id, $PS_EXIT_SYS_ERROR) unless
-    scalar @$files == 2;
+        &my_die("Unable to parse metadata list", $diff_id, $skycell_id, $PS_EXIT_PROG_ERROR);
+}
+
+&my_die("Subtraction list does not contain exactly two elements", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless scalar @$files == 2;
 
 # Identify the input and the template
@@ -123,5 +125,5 @@
     }
     if (defined $tess_id) {
-        &my_die("Tesselation identifiers don't match", $diff_id, $PS_EXIT_SYS_ERROR) unless
+        &my_die("Tesselation identifiers don't match", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless
             $file->{tess_id} eq $tess_id;
     } else {
@@ -129,5 +131,5 @@
     }
     if (defined $skycell_id) {
-        &my_die("Skycell identifiers don't match", $diff_id, $PS_EXIT_SYS_ERROR) unless
+        &my_die("Skycell identifiers don't match", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless
             $file->{skycell_id} eq $skycell_id;
     } else {
@@ -135,5 +137,5 @@
     }
     if (defined $camera) {
-        &my_die("Cameras don't match", $diff_id, $PS_EXIT_SYS_ERROR) unless $file->{camera} eq $camera;
+        &my_die("Cameras don't match", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $file->{camera} eq $camera;
     } else {
         $camera = $file->{camera};
@@ -142,7 +144,7 @@
 }
 
-&my_die("Unable to identify template", $diff_id, $PS_EXIT_SYS_ERROR) unless defined $template;
-&my_die("Unable to identify input", $diff_id, $PS_EXIT_SYS_ERROR) unless defined $input;
-&my_die("Unable to identify camera", $diff_id, $PS_EXIT_SYS_ERROR) unless defined $camera;
+&my_die("Unable to identify template", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless defined $template;
+&my_die("Unable to identify input", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless defined $input;
+&my_die("Unable to identify camera", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless defined $camera;
 $ipprc->define_camera($camera);
 
@@ -152,5 +154,5 @@
 my $recipe_psphot  = $ipprc->reduction($reduction, 'DIFF_PSPHOT'); # Recipe to use for psphot
 unless ($recipe_ppSub and $recipe_psphot) {
-    &my_die("Couldn't find selected reduction for DIFF_PPSUB and DIFF_PSPHOT: $reduction\n", $diff_id, $PS_EXIT_CONFIG_ERROR);
+    &my_die("Couldn't find selected reduction for DIFF_PPSUB and DIFF_PSPHOT: $reduction\n", $diff_id, $skycell_id, $PS_EXIT_CONFIG_ERROR);
 }
 
@@ -177,11 +179,11 @@
 print "templateSources: $templateSources\n";
 
-&my_die("Couldn't find input: $template", $diff_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($template);
-&my_die("Couldn't find input: $templateMask", $diff_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($templateMask);
-&my_die("Couldn't find input: $templateVariance", $diff_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($templateVariance);
-&my_die("Couldn't find input: $input", $diff_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($input);
-&my_die("Couldn't find input: $inputMask", $diff_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inputMask);
-&my_die("Couldn't find input: $inputVariance", $diff_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inputVariance);
-&my_die("Couldn't find input: $templateSources", $diff_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($templateSources);
+&my_die("Couldn't find input: $template", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($template);
+&my_die("Couldn't find input: $templateMask", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($templateMask);
+&my_die("Couldn't find input: $templateVariance", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($templateVariance);
+&my_die("Couldn't find input: $input", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($input);
+&my_die("Couldn't find input: $inputMask", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inputMask);
+&my_die("Couldn't find input: $inputVariance", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inputVariance);
+&my_die("Couldn't find input: $templateSources", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($templateSources);
 
 # Get the output filenames
@@ -210,5 +212,7 @@
     $command .= " -recipe PSPHOT $recipe_psphot";
     $command .= " -recipe PPSTATS WARPSTATS";
+    $command .= " -F PSPHOT.PSF.SAVE PSPHOT.PSF.SKY.SAVE";
     $command .= " -F PSPHOT.OUTPUT PSPHOT.OUT.CMF.MEF";
+    $command .= " -F PSPHOT.BACKMDL PSPHOT.BACKMDL.MEF";
     $command .= " -sources $templateSources";
     $command .= " -photometry";
@@ -223,15 +227,15 @@
     unless ($success) {
         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-        &my_die("Unable to perform ppSub: $error_code", $diff_id, $error_code);
-    }
-    &my_die("Couldn't find expected output file: $outputName", $diff_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputName);
-    &my_die("Couldn't find expected output file: $outputMask", $diff_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputMask);
-    &my_die("Couldn't find expected output file: $outputVariance", $diff_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputVariance);
-#    &my_die("Couldn't find expected output file: $outputSources", $diff_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputSources);
-#    &my_die("Couldn't find expected output file: $bin1Name",    $diff_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($bin1Name);
-#    &my_die("Couldn't find expected output file: $bin2Name",    $diff_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($bin2Name);
+        &my_die("Unable to perform ppSub: $error_code", $diff_id, $skycell_id, $error_code);
+    }
+    &my_die("Couldn't find expected output file: $outputName", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputName);
+    &my_die("Couldn't find expected output file: $outputMask", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputMask);
+    &my_die("Couldn't find expected output file: $outputVariance", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputVariance);
+#    &my_die("Couldn't find expected output file: $outputSources", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputSources);
+#    &my_die("Couldn't find expected output file: $bin1Name",    $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($bin1Name);
+#    &my_die("Couldn't find expected output file: $bin2Name",    $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($bin2Name);
 
     my $outputStatsReal = $ipprc->file_resolve($outputStats);
-    &my_die("Couldn't find expected output file: $outputStats", $diff_id, $PS_EXIT_SYS_ERROR) unless -f $outputStatsReal;
+    &my_die("Couldn't find expected output file: $outputStats", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless -f $outputStatsReal;
 
     # measure chip stats
@@ -241,5 +245,5 @@
     unless ($success) {
         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-        &my_die("Unable to perform ppStatsFromMetadata: $error_code", $diff_id, $error_code);
+        &my_die("Unable to perform ppStatsFromMetadata: $error_code", $diff_id, $skycell_id, $error_code);
     }
     foreach my $line (@$stdout_buf) {
@@ -263,5 +267,5 @@
         unless ($success) {
             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-            &my_die("Unable to perform difftool -adddiffskyfile: $error_code", $diff_id, $error_code);
+            &my_die("Unable to perform difftool -adddiffskyfile: $error_code", $diff_id, $skycell_id, $error_code);
         }
     }
@@ -273,8 +277,9 @@
     my $msg = shift;            # Warning message on die
     my $diff_id = shift;        # Diff identifier
+    my $skycell_id = shift;     # Skycell identifier
     my $exit_code = shift;      # Exit code to add
 
     warn($msg);
-    if (defined $diff_id and not $no_update) {
+    if (defined $diff_id and defined $skycell_id and not $no_update) {
         my $command = "$difftool -adddiffskyfile -diff_id $diff_id -skycell_id $skycell_id -code $exit_code";
         $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
Index: /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/fake_imfile.pl
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/fake_imfile.pl	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/fake_imfile.pl	(revision 23197)
@@ -41,4 +41,14 @@
 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
 use Pod::Usage qw( pod2usage );
+
+# Look for programs we need
+my $missing_tools;
+my $faketool = can_run('faketool') or (warn "Can't find faketool" and $missing_tools = 1);
+my $ppSim = can_run('ppSim') or (warn "Can't find ppSim" and $missing_tools = 1);
+my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
+if ($missing_tools) {
+    warn("Can't find required tools.");
+    exit($PS_EXIT_CONFIG_ERROR);
+}
 
 # Parse the command-line arguments
@@ -72,4 +82,8 @@
     defined $outroot;
 
+# Unhandled exceptions should be passed on to my_die so they get pushed into the database
+$SIG{__DIE__} = sub { die @_ if $^S;
+                      my_die( $_[0], $exp_id, $fake_id, $class_id, $PS_EXIT_UNKNOWN_ERROR ); };
+
 $ipprc->define_camera($camera);
 
@@ -83,14 +97,4 @@
 unless ($recipe) {
     &my_die("Couldn't find selected reduction for FAKE: $reduction\n", $exp_id, $fake_id, $class_id, $PS_EXIT_CONFIG_ERROR);
-}
-
-# Look for programs we need
-my $missing_tools;
-my $faketool = can_run('faketool') or (warn "Can't find faketool" and $missing_tools = 1);
-my $ppSim = can_run('ppSim') or (warn "Can't find ppSim" and $missing_tools = 1);
-my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
-if ($missing_tools) {
-    warn("Can't find required tools.");
-    exit($PS_EXIT_CONFIG_ERROR);
 }
 
Index: /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/ipp_image_path.pl
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/ipp_image_path.pl	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/ipp_image_path.pl	(revision 23197)
@@ -2,6 +2,4 @@
 
 # ipp_image_path.pl print out the unix path name(s) for rawImage files for an exposure
-# Note this program should really be called gpc1_image_path since the camera is
-# hardcoded to gpc1 and the telescope is gpc1
 #
 
@@ -10,6 +8,7 @@
 
 # get images that are on ipp008 from alternative location until the
-# dataase is updated
-my $use_008_workaround  = 1;
+# database is updated
+my $use_008_workaround  = 0;
+my $use_017_workaround  = 0;
 
 use vars qw( $VERSION );
@@ -41,8 +40,4 @@
 my $ota_num;
 if ($class_id) {
-    # we accept class_id in 3 formats (all we care about is the number)
-    # xy23
-    # ota23
-    # 23
     $class_id = lc($class_id);
     my $extra;
@@ -74,10 +69,8 @@
     if ($from_registered) {
         $query = "SELECT exp_id, class_id, uri FROM rawImfile"
-                . " WHERE exp_name = \'$exp_name\'"
-                . " AND camera = \'gpc1\' AND telescope = \'ps1\'";
+                . " WHERE exp_name = \'$exp_name\'";
         $query .= " AND class_id = \'xy$ota_num\'" if ($ota_num);
     } else {
-        $query = "SELECT exp_id FROM newExp WHERE tmp_exp_name = ?"
-                . " AND tmp_camera = \'gpc1\' AND tmp_telescope = \'ps1\'";
+        $query = "SELECT exp_id FROM newExp WHERE tmp_exp_name = ?";
         my $stmt = $dbh->prepare($query);
         $stmt->execute($exp_name);
@@ -105,4 +98,7 @@
             if ($use_008_workaround && ($uri =~ /ipp008/)) {
                 $path = resolve_ipp008_file($uri);
+            } elsif ($use_017_workaround && ($uri =~ /4683/) &&
+                    ($uri =~ /ipp017/)) {
+                $path = resolve_ipp017_file($uri);
             } else {
                 $path = $ipprc->file_resolve($uri);
@@ -169,2 +165,22 @@
     return $path;
 }
+
+sub resolve_ipp017_file {
+    my $uri = shift;
+
+    # uri's look like neb://ipp008.0/gpc1/20080625/o4642g0400o/o4642g0400o.ota24.fits
+    
+    my ($left, $middle, $ota, $fits) = split '\.', $uri;
+    
+    my $node = "ipp015";
+
+    die "can't find node for $ota: $uri" if (!$node);
+
+    my $path =  $uri;
+    
+    $path =~  s%neb://ipp017.0%/data/${node}.0/recover17%;
+
+    die "sorry backup image for $uri not found\n" if (!-e $path);
+
+    return $path;
+}
Index: /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/magic_destreak.pl
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/magic_destreak.pl	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/magic_destreak.pl	(revision 23197)
@@ -26,4 +26,13 @@
 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
 use Pod::Usage qw( pod2usage );
+
+# Look for programs we need
+my $missing_tools;
+my $magicdstool   = can_run('magicdstool') or (warn "Can't find magicdstool" and $missing_tools = 1);
+my $streaksremove = can_run('streaksremove') or (warn "Can't find streaksremove" and $missing_tools = 1);
+if ($missing_tools) {
+    warn("Can't find required tools.");
+    exit($PS_EXIT_CONFIG_ERROR);
+}
 
 # Parse the command-line arguments
@@ -66,5 +75,9 @@
     defined $component and
     defined $outroot;
-    
+
+# Unhandled exceptions should be passed on to my_die so they get pushed into the database
+$SIG{__DIE__} = sub { die @_ if $^S;
+                      my_die( $_[0], $magic_ds_id, $component, $PS_EXIT_UNKNOWN_ERROR ); };
+
 
 my ($skycell_args, $class_id, $skycell_id);
@@ -87,13 +100,4 @@
 
 
-# Look for programs we need
-my $missing_tools;
-my $magicdstool   = can_run('magicdstool') or (warn "Can't find magicdstool" and $missing_tools = 1);
-my $streaksremove = can_run('streaksremove') or (warn "Can't find streaksremove" and $missing_tools = 1);
-if ($missing_tools) {
-    warn("Can't find required tools.");
-    exit($PS_EXIT_CONFIG_ERROR);
-}
-
 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
 
@@ -128,5 +132,5 @@
     if (! -e $outroot ) {
         my $code = system "mkdir -p $outroot";
-        &my_die("cannot create output directory $outroot", $magic_ds_id, $component, 
+        &my_die("cannot create output directory $outroot", $magic_ds_id, $component,
                 $code >> 8) if $code;
     }
@@ -143,5 +147,5 @@
         if (! -e $recoveryroot ) {
             my $code = system "mkdir -p $recoveryroot";
-            &my_die("cannot create output directory $outroot", $magic_ds_id, $component, 
+            &my_die("cannot create output directory $outroot", $magic_ds_id, $component,
                     $code >> 8) if $code;
         }
@@ -151,5 +155,5 @@
 
 # get skycell list if needed
-my ($sfh, $skycell_list);          
+my ($sfh, $skycell_list);
 if ($skycell_args) {
     my $command = "$magicdstool -magic_ds_id $magic_ds_id -getskycells $skycell_args";
Index: /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/magic_mask.pl
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/magic_mask.pl	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/magic_mask.pl	(revision 23197)
@@ -28,4 +28,13 @@
 use Pod::Usage qw( pod2usage );
 
+# Look for programs we need
+my $missing_tools;
+my $magictool = can_run('magictool') or (warn "Can't find magictool" and $missing_tools = 1);
+my $streaksremove = can_run('streaksremove') or (warn "Can't find streaksremove" and $missing_tools = 1);
+if ($missing_tools) {
+    warn("Can't find required tools.");
+    exit($PS_EXIT_CONFIG_ERROR);
+}
+
 # Parse the command-line arguments
 my ($magic_id, $camera, $dbname, $outroot, $save_temps, $verbose, $no_update, $no_op, $logfile);
@@ -49,16 +58,11 @@
     defined $outroot;
 
+# Unhandled exceptions should be passed on to my_die so they get pushed into the database
+$SIG{__DIE__} = sub { die @_ if $^S;
+                      my_die( $_[0], $magic_id, $PS_EXIT_UNKNOWN_ERROR ); };
+
 $ipprc->define_camera($camera);
 
 $ipprc->redirect_output($logfile) if $logfile;
-
-# Look for programs we need
-my $missing_tools;
-my $magictool = can_run('magictool') or (warn "Can't find magictool" and $missing_tools = 1);
-my $streaksremove = can_run('streaksremove') or (warn "Can't find streaksremove" and $missing_tools = 1);
-if ($missing_tools) {
-    warn("Can't find required tools.");
-    exit($PS_EXIT_CONFIG_ERROR);
-}
 
 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
@@ -85,5 +89,5 @@
 ### Do the heavy lifting
 {
-    my $command = "$streaks --streaks"; # Command to execute
+    my $command = "$streaksremove --streaks"; # Command to execute
     my @basenames;              # List of base names
 
Index: /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/magic_process.pl
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/magic_process.pl	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/magic_process.pl	(revision 23197)
@@ -28,4 +28,13 @@
 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
 use Pod::Usage qw( pod2usage );
+
+# Look for programs we need
+my $missing_tools;
+my $magictool      = can_run('magictool') or (warn "Can't find magictool" and $missing_tools = 1);
+my $removestreaks = can_run('RemoveStreaks') or (warn "Can't find RemoveStreaks" and $missing_tools = 1);
+if ($missing_tools) {
+    warn("Can't find required tools.");
+    exit($PS_EXIT_CONFIG_ERROR);
+}
 
 # Parse the command-line arguments
@@ -53,4 +62,8 @@
     defined $outroot;
 
+# Unhandled exceptions should be passed on to my_die so they get pushed into the database
+$SIG{__DIE__} = sub { die @_ if $^S;
+                      my_die( $_[0], $magic_id, $node, $PS_EXIT_UNKNOWN_ERROR ); };
+
 $ipprc->define_camera($camera);
 
@@ -66,15 +79,6 @@
 # resolve any path:// or file:// in outroot
 $outroot = $ipprc->file_resolve($outroot);
-    
+
 $ipprc->redirect_output($logfile) if $logfile;
-
-# Look for programs we need
-my $missing_tools;
-my $magictool      = can_run('magictool') or (warn "Can't find magictool" and $missing_tools = 1);
-my $removestreaks = can_run('RemoveStreaks') or (warn "Can't find RemoveStreaks" and $missing_tools = 1);
-if ($missing_tools) {
-    warn("Can't find required tools.");
-    exit($PS_EXIT_CONFIG_ERROR);
-}
 
 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
@@ -145,5 +149,5 @@
         # this causes major file pollution, but avoids multi-level queries
         # at higher level nodes.
-        
+
         my ($in_fh, $input_list)  = open_list_file($outroot, "input.list");
         print $in_fh "$outroot\n";
@@ -252,5 +256,5 @@
 
     my $fh;
-    open $fh, "<$resolved" or 
+    open $fh, "<$resolved" or
         &my_die("failed to open streaks file $streaks_file", $magic_id, $node, $PS_EXIT_UNKNOWN_ERROR);
     # the first line in the streaks file contains the number of streaks found
@@ -259,5 +263,5 @@
     close $fh;
     print "$num_streaks streaks found on magicRun $magic_id\n" if $verbose;
-    
+
     my $command = "$magictool -addmask";
     $command   .= " -magic_id $magic_id";
Index: /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/magic_tree.pl
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/magic_tree.pl	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/magic_tree.pl	(revision 23197)
@@ -31,4 +31,13 @@
 
 use constant MAX_FIELDS => 4;   # Maximum number of fields to be in a node
+
+# Look for programs we need
+my $missing_tools;
+my $magictool = can_run('magictool') or (warn "Can't find magictool" and $missing_tools = 1);
+my $warptool = can_run('warptool') or (warn "Can't find warptool" and $missing_tools = 1);
+if ($missing_tools) {
+    warn("Can't find required tools.");
+    exit($PS_EXIT_CONFIG_ERROR);
+}
 
 # Parse the command-line arguments
@@ -61,16 +70,11 @@
     defined $outroot;
 
+# Unhandled exceptions should be passed on to my_die so they get pushed into the database
+$SIG{__DIE__} = sub { die @_ if $^S;
+                      my_die( $_[0], $magic_id, $PS_EXIT_UNKNOWN_ERROR ); };
+
 $ipprc->define_camera($camera);
 
 $ipprc->redirect_output($logfile) if $logfile;
-
-# Look for programs we need
-my $missing_tools;
-my $magictool = can_run('magictool') or (warn "Can't find magictool" and $missing_tools = 1);
-my $warptool = can_run('warptool') 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 $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
@@ -96,5 +100,5 @@
         &my_die("Unable to parse metadata list", $magic_id, $PS_EXIT_PROG_ERROR);
 
-    # make a hash indexed by skycell_id 
+    # make a hash indexed by skycell_id
     foreach my $warp ( @$warps ) {
         my $skycell_id = $warp->{skycell_id};
@@ -156,9 +160,9 @@
 
     my ($header, $status) = (undef, 0);
-    my $fits =  Astro::FITS::CFITSIO::open_file( $skyfileResolved, READONLY, $status ); 
+    my $fits =  Astro::FITS::CFITSIO::open_file( $skyfileResolved, READONLY, $status );
     &my_die("failed to open skycell file: $skyfileResolved: $status", $magic_id, $PS_EXIT_SYS_ERROR) if $status;
 
     ($header, $status) = Astro::FITS::CFITSIO::fits_read_header( $fits );
-    
+
     &my_die("Unable to read skycell header: $status", $magic_id, $PS_EXIT_SYS_ERROR) if $status;
 
@@ -171,5 +175,5 @@
         $naxis2 = $$header{'NAXIS2'} or &my_die("Can't find NAXIS2", $magic_id, $PS_EXIT_SYS_ERROR);
     } else {
-        # if the skyfile is compressed then the WCS won't be in the primary header, move to the 
+        # if the skyfile is compressed then the WCS won't be in the primary header, move to the
         # extension
         my $hdutype;
@@ -257,5 +261,5 @@
     my $node = shift @tasks;
     divide_node($node, \@tasks);
-} 
+}
 
 ### Format tree for magictool
Index: /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/register_exp.pl
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/register_exp.pl	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/register_exp.pl	(revision 23197)
@@ -27,4 +27,13 @@
 my $ipprc = PS::IPP::Config->new();
 
+# Look for commands we need
+my $missing_tools;
+my $regtool = can_run('regtool') or (warn "can't find regtool" and $missing_tools = 1);
+my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
+if ($missing_tools) {
+    warn ("Can't find required tools");
+    exit($PS_EXIT_CONFIG_ERROR);
+}
+
 my ($cache, $exp_id, $exp_tag, $label, $dvodb, $end_stage, $tess_id, $dbname, $verbose, $no_update, $no_op, $save_temps, $logfile);
 GetOptions(
@@ -33,8 +42,8 @@
     'exp_tag|t=s'   => \$exp_tag,
     'dbname|d=s'    => \$dbname, # Database name
-    'label=s'       => \$label,   
-    'dvodb=s'       => \$dvodb,   
-    'end_stage=s'   => \$end_stage, 
-    'tess_id=s'     => \$tess_id,   
+    'label=s'       => \$label,
+    'dvodb=s'       => \$dvodb,
+    'end_stage=s'   => \$end_stage,
+    'tess_id=s'     => \$tess_id,
     'verbose'       => \$verbose,   # Print to stdout
     'no-update'     => \$no_update,
@@ -44,4 +53,8 @@
 ) or pod2usage( 2 );
 
+# Unhandled exceptions should be passed on to my_die so they get pushed into the database
+$SIG{__DIE__} = sub { die @_ if $^S;
+                      my_die( $_[0], $exp_id, $PS_EXIT_UNKNOWN_ERROR ); };
+
 $ipprc->redirect_output($logfile) if $logfile;
 
@@ -55,14 +68,4 @@
 my @SCIENCE = ( "object", "science", "light" ); # Observation types to NOT mark as detrend
 my $DETREND_FLAG = "-end_stage reg"; # Flag to use to mark detrend exposure
-
-# Look for commands we need
-my $missing_tools;
-my $regtool = can_run('regtool') or (warn "can't find regtool" and $missing_tools = 1);
-my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
-
-if ($missing_tools) {
-    warn ("Can't find required tools");
-    exit($PS_EXIT_CONFIG_ERROR);
-}
 
 # setup cache interface
@@ -123,7 +126,7 @@
 $command .= " -exp_tag $exp_tag";
 $command .= " -hostname  $host"      if defined $host;
-$command .= " -dbname 	 $dbname"    if defined $dbname;
-$command .= " -label  	 $label"     if defined $label;
-$command .= " -dvodb  	 $dvodb"     if defined $dvodb;
+$command .= " -dbname    $dbname"    if defined $dbname;
+$command .= " -label     $label"     if defined $label;
+$command .= " -dvodb     $dvodb"     if defined $dvodb;
 $command .= " -end_stage $end_stage" if defined $end_stage;
 $command .= " -tess_id   $tess_id"   if defined $tess_id;
Index: /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/register_imfile.pl
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/register_imfile.pl	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/register_imfile.pl	(revision 23197)
@@ -17,5 +17,6 @@
 use Storable qw(freeze thaw);
 use File::Basename qw( basename);
-use IPC::Run qw( harness run );
+use IPC::Run;
+use IPC::Cmd 0.36 qw( can_run );
 use PS::IPP::Config 1.01 qw( :standard );
 use PS::IPP::Metadata::Config;
@@ -27,4 +28,10 @@
 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
 use Pod::Usage qw( pod2usage );
+
+# Look for programs we need
+my $missing_tools;
+my $regtool = can_run( 'regtool' ) or (warn "Can't find regtool" and $missing_tools = 1);
+my $ppStats = can_run( 'ppStats' ) or (warn "Can't find ppStats" and $missing_tools = 1);
+my $ppStatsFromMetadata = can_run( 'ppStatsFromMetadata' ) or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
 
 my ($cache, $exp_id, $tmp_class_id, $tmp_exp_name, $uri, $dbname, $verbose, $no_update, $no_op, $logfile);
@@ -42,4 +49,8 @@
 ) or pod2usage( 2 );
 
+# Unhandled exceptions should be passed on to my_die so they get pushed into the database
+$SIG{__DIE__} = sub { die @_ if $^S;
+                      my_die( $_[0], $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_UNKNOWN_ERROR ); };
+
 $ipprc->redirect_output($logfile) if $logfile;
 
@@ -55,14 +66,4 @@
 my $RECIPE = "REGISTER"; # Recipe to use for ppStats
 
-# Look for programs we need
-my $missing_tools;
-my $regtool = `which regtool` or (warn "Can't find regtool" and $missing_tools = 1);
-my $ppStats = `which ppStats` or (warn "Can't find ppStats" and $missing_tools = 1);
-my $ppStatsFromMetadata = `which ppStatsFromMetadata` or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
-chomp $regtool;
-chomp $ppStats;
-chomp $ppStatsFromMetadata;
-
-
 if ($missing_tools) {
     warn ("Can't find required tools");
@@ -92,18 +93,18 @@
     # Run ppStats
     my ($in1, $out1, $err1);    # Buffers for ppStats
-    my $h1 = harness \@command1, \$in1, \$out1, \$err1;
+    my $h1 = IPC::Run::harness \@command1, \$in1, \$out1, \$err1;
     print "[Running $command1]\n";
-    my $result1 = run $h1;
-    print $out1;
-    print $err1;
+    my $result1 = IPC::Run::run $h1;
+    print "STDOUT:\n$out1";
+    print "STDERR:\n$err1";
     &my_die("Unable to perform ppStats on exposure id $exp_id: " . $h1->result(), $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $h1->result() ) unless $result1;
 
     print "[Running " . join(' ', @command2) . "]\n";
     my ($out2, $err2);          # Buffers for ppStatsFromMetadata
-    my $h2 = harness \@command2, \$out1, \$out2, \$err2;
+    my $h2 = IPC::Run::harness \@command2, \$out1, \$out2, \$err2;
     print "[Running $command2]\n";
-    my $result2 = run $h2;
-    print $out2;
-    print $err2;
+    my $result2 = IPC::Run::run $h2;
+    print "STDOUT:\n$out2";
+    print "STDERR:\n$err2";
     &my_die("Unable to perform ppStatsFromMetadata on exposure id $exp_id: " . $h2->result(), $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $h2->result() ) unless $result2;
     chomp $out2;
@@ -166,5 +167,5 @@
 unless ($no_update) {
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-        run(command => $command, verbose => $verbose);
+        IPC::Cmd::run(command => $command, verbose => $verbose);
     unless ($success) {
         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
@@ -187,5 +188,5 @@
         return @{thaw $cmd_output};
     } else {
-        my @output = run(%p);
+        my @output = IPC::Cmd::run(%p);
         $c->set($p{command}, freeze \@output) if $cache;
         return @output;
Index: /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/stack_skycell.pl
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/stack_skycell.pl	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/stack_skycell.pl	(revision 23197)
@@ -29,4 +29,15 @@
 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
 use Pod::Usage qw( pod2usage );
+
+# Look for programs we need
+my $missing_tools;
+my $stacktool = can_run('stacktool') or (warn "Can't find stacktool" and $missing_tools = 1);
+my $ppStack = can_run('ppStack') or (warn "Can't find ppStack" and $missing_tools = 1);
+my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
+my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
+if ($missing_tools) {
+    warn("Can't find required tools.");
+    exit($PS_EXIT_CONFIG_ERROR);
+}
 
 my ($stack_id, $dbname, $outroot, $debug, $run_state, $threads, $reduction, $verbose, $no_update, $no_op, $redirect, $save_temps);
@@ -55,7 +66,10 @@
     and defined $run_state;
 
+# Unhandled exceptions should be passed on to my_die so they get pushed into the database
+$SIG{__DIE__} = sub { die @_ if $^S;
+                      my_die( $_[0], $stack_id, $PS_EXIT_UNKNOWN_ERROR ); };
+
 # XXX camera is not known here; cannot use filerules...
 # my $logDest = $ipprc->filename("LOG.EXP", $outroot);
-
 my $logDest = "$outroot.log";
 
@@ -72,15 +86,4 @@
 my $image_id = $stack_id;
 my $source_id = $ipprc->source_id($dbname, $PS_TABLE_ID_STACK);
-
-# Look for programs we need
-my $missing_tools;
-my $stacktool = can_run('stacktool') or (warn "Can't find stacktool" and $missing_tools = 1);
-my $ppStack = can_run('ppStack') or (warn "Can't find ppStack" and $missing_tools = 1);
-my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
-my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
-if ($missing_tools) {
-    warn("Can't find required tools.");
-    exit($PS_EXIT_CONFIG_ERROR);
-}
 
 # Get list of components for stacking
@@ -300,6 +303,6 @@
 
     unless ($my_die_called) {
-	$my_die_called = 1;
-	delete_temps() unless ($save_temps);
+        $my_die_called = 1;
+        delete_temps() unless ($save_temps);
     }
 
@@ -324,6 +327,6 @@
 {
     unless ($temp_images_exist) {
-	print "No temporary images yet generated\n";
-	return 1;
+        print "No temporary images yet generated\n";
+        return 1;
     }
 
@@ -334,8 +337,8 @@
     unless ($success) {
         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-	&my_die("Unable to perform ppConfigDump: $error_code", $stack_id, $error_code);
+        &my_die("Unable to perform ppConfigDump: $error_code", $stack_id, $error_code);
     }
     my $md = $mdcParser->parse(join "", @$stdout_buf) or
-	&my_die("Unable to parse metadata config doc", $stack_id, $PS_EXIT_PROG_ERROR);
+        &my_die("Unable to parse metadata config doc", $stack_id, $PS_EXIT_PROG_ERROR);
 
     my $temp_delete = metadataLookupBool($md, 'TEMP.DELETE'); # Delete temporary files?
Index: /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/warp_overlap.pl
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/warp_overlap.pl	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/warp_overlap.pl	(revision 23197)
@@ -25,4 +25,14 @@
 
 my $ipprc = PS::IPP::Config->new(); # IPP configuration
+
+# Look for programs we need
+my $missing_tools;
+my $warptool = can_run('warptool') or (warn "Can't find warptool" and $missing_tools = 1);
+my $dvoImageOverlaps = can_run('dvoImageOverlaps') or (warn "Can't find dvoImageOverlaps" and $missing_tools = 1);
+my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
+if ($missing_tools) {
+    warn("Can't find required tools.");
+    exit($PS_EXIT_CONFIG_ERROR);
+}
 
 my ($warp_id, $camera, $tess_dir, $dbname, $verbose, $no_update, $no_op, $logfile, $save_temps);
@@ -49,15 +59,9 @@
     and defined $tess_dir;
 
+# Unhandled exceptions should be passed on to my_die so they get pushed into the database
+$SIG{__DIE__} = sub { die @_ if $^S;
+                      my_die( $_[0], $warp_id, $PS_EXIT_UNKNOWN_ERROR ); };
+
 $ipprc->define_camera($camera);
-
-# Look for programs we need
-my $missing_tools;
-my $warptool = can_run('warptool') or (warn "Can't find warptool" and $missing_tools = 1);
-my $dvoImageOverlaps = can_run('dvoImageOverlaps') or (warn "Can't find dvoImageOverlaps" and $missing_tools = 1);
-my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
-if ($missing_tools) {
-    warn("Can't find required tools.");
-    exit($PS_EXIT_CONFIG_ERROR);
-}
 
 &my_die("Tessellation identifier not provided: $tess_dir", $warp_id, $PS_EXIT_SYS_ERROR) unless $tess_dir ne "NULL";
Index: /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/warp_skycell.pl
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/warp_skycell.pl	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/ippScripts/scripts/warp_skycell.pl	(revision 23197)
@@ -26,4 +26,15 @@
 
 my $ipprc = PS::IPP::Config->new(); # IPP configuration
+
+# Look for programs we need
+my $missing_tools;
+my $warptool = can_run('warptool') or (warn "Can't find warptool" and $missing_tools = 1);
+my $pswarp = can_run('pswarp') or (warn "Can't find pswarp" and $missing_tools = 1);
+my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
+my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
+if ($missing_tools) {
+    warn("Can't find required tools.");
+    exit($PS_EXIT_CONFIG_ERROR);
+}
 
 my ($warp_id, $skycell_id, $warp_skyfile_id, $tess_dir, $camera, $dbname, $outroot, $threads, $run_state, $verbose, $no_update, $no_op, $redirect, $save_temps);
@@ -57,4 +68,8 @@
     and defined $run_state;
 
+# Unhandled exceptions should be passed on to my_die so they get pushed into the database
+$SIG{__DIE__} = sub { die @_ if $^S;
+                      my_die( $_[0], $warp_id, $skycell_id, $tess_dir, $PS_EXIT_UNKNOWN_ERROR ); };
+
 $ipprc->define_camera($camera);
 
@@ -65,15 +80,4 @@
 
 my $source_id = $ipprc->source_id($dbname, $PS_TABLE_ID_WARP);
-
-# Look for programs we need
-my $missing_tools;
-my $warptool = can_run('warptool') or (warn "Can't find warptool" and $missing_tools = 1);
-my $pswarp = can_run('pswarp') or (warn "Can't find pswarp" and $missing_tools = 1);
-my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
-my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
-if ($missing_tools) {
-    warn("Can't find required tools.");
-    exit($PS_EXIT_CONFIG_ERROR);
-}
 
 # Get list of component imfiles for exposure
Index: anches/cnb_branches/cnb_branch_20090215/ippTasks/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippTasks/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,9 +1,0 @@
-Makefile
-Makefile.in
-aclocal.m4
-autom4te.cache
-config.log
-config.status
-configure
-install-sh
-missing
Index: /branches/cnb_branches/cnb_branch_20090215/ippTasks/pantasks.pro
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippTasks/pantasks.pro	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/ippTasks/pantasks.pro	(revision 23197)
@@ -351,7 +351,7 @@
 
   if ("$template" == "NULL")
-    $varname = $workdir_template
+    $$varname = $workdir_template
     echo "WARNING: WORKDIR template not set.  Defaulting to $workdir_template"
-    break
+    return
   end
 
@@ -379,7 +379,7 @@
 
   if ("$template" == "NULL")
-    $varname = $workdir_template
+    $$varname = $workdir_template
     echo "WARNING: WORKDIR template not set.  Defaulting to $workdir_template"
-    break
+    return
   end
 
Index: anches/cnb_branches/cnb_branch_20090215/ippTools/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippTools/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,16 +1,0 @@
-Makefile
-Makefile.in
-aclocal.m4
-autom4te.cache
-compile
-config.guess
-config.log
-config.status
-config.sub
-configure
-depcomp
-install-sh
-libtool
-ltmain.sh
-missing
-pxtools.pc
Index: anches/cnb_branches/cnb_branch_20090215/ippTools/m4/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippTools/m4/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,5 +1,0 @@
-libtool.m4
-ltoptions.m4
-ltsugar.m4
-ltversion.m4
-lt~obsolete.m4
Index: anches/cnb_branches/cnb_branch_20090215/ippTools/scripts/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippTools/scripts/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-Makefile
-Makefile.in
Index: anches/cnb_branches/cnb_branch_20090215/ippTools/share/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippTools/share/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-Makefile.in
-Makefile
Index: anches/cnb_branches/cnb_branch_20090215/ippTools/src/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippTools/src/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,33 +1,0 @@
-.deps
-.gdb_history
-.libs
-Makefile
-Makefile.in
-config.h
-config.h.in
-stamp-h1
-*.la
-*.lo
-pxtoolsErrorCodes.c
-pxtoolsErrorCodes.h
-pxadmin
-pxinject
-pztool
-pzgetexp
-pzgetimfiles
-regtool
-guidetool
-chiptool
-camtool
-warptool
-difftool
-stacktool
-faketool
-dettool
-detselect
-pxdata.c
-magictool
-magicdstool
-caltool
-flatcorr
-pstamptool
Index: anches/cnb_branches/cnb_branch_20090215/ippconfig/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippconfig/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,14 +1,0 @@
-Makefile
-Makefile.in
-aclocal.m4
-autom4te.cache
-config.log
-config.status
-configure
-dvo.site
-install-sh
-ippconfig-0.0.1.tar.bz2
-ippconfig-0.0.1.tar.gz
-missing
-ipprc.config
-site.config
Index: anches/cnb_branches/cnb_branch_20090215/ippconfig/cfh12k/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippconfig/cfh12k/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-Makefile
-Makefile.in
Index: anches/cnb_branches/cnb_branch_20090215/ippconfig/esowfi/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippconfig/esowfi/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-Makefile
-Makefile.in
Index: anches/cnb_branches/cnb_branch_20090215/ippconfig/gpc1/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippconfig/gpc1/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-Makefile
-Makefile.in
Index: /branches/cnb_branches/cnb_branch_20090215/ippconfig/gpc1/Makefile.am
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippconfig/gpc1/Makefile.am	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/ippconfig/gpc1/Makefile.am	(revision 23197)
@@ -11,4 +11,5 @@
 	format_20081011.config \
 	format_20090120.config \
+	format_20090220.config \
 	format_mef.config \
 	format_relphot.config \
Index: /branches/cnb_branches/cnb_branch_20090215/ippconfig/gpc1/camera.config
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippconfig/gpc1/camera.config	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/ippconfig/gpc1/camera.config	(revision 23197)
@@ -5,4 +5,5 @@
 	MEF		STR	gpc1/format_mef.config
 	RELPHOT		STR	gpc1/format_relphot.config
+	RAW_20090220	STR	gpc1/format_20090220.config
 	RAW_20090120	STR	gpc1/format_20090120.config
 	RAW_20081011	STR	gpc1/format_20081011.config
Index: /branches/cnb_branches/cnb_branch_20090215/ippconfig/gpc1/format_20090220.config
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippconfig/gpc1/format_20090220.config	(revision 23197)
+++ /branches/cnb_branches/cnb_branch_20090215/ippconfig/gpc1/format_20090220.config	(revision 23197)
@@ -0,0 +1,519 @@
+# Refurbished GPC1
+# Change effective from 20 February 2009 fix for XY03 chip name
+
+# How to identify this type
+RULE    METADATA
+	ORIGIN		STR	PS1
+        TELESCOP        STR     PS1
+	INSTRUME	STR	gpc1
+        CONTROLR        STR     STARGRASP
+        NAMPS           S32     64
+	MJD-OBS		F64	54883.00559		# OP: >=
+END
+
+# How to read this data
+FILE    METADATA
+        PHU             STR     CHIP       # The FITS file represents a single chip
+        EXTENSIONS      STR     CELL       # The extensions represent cells
+        FPA.OBS         STR     CONTROLR   # A PHU keyword for unique identifier within the hierarchy level
+        CONTENT         STR     DETECTOR   # How to determine content of FITS file
+        CONTENT.RULE    STR     {CHIP.ID}  # How to derive the CONTENT when writing
+END
+
+# What's in the FITS file?
+CONTENTS        METADATA
+        # CONTENT      =    chip name : type
+        CCID58-2-15a1  STR  XY01:GPCChip  # chip 00
+        CCID58-2-18a1  STR  XY02:GPCChip  # chip 01
+        CCID58-2-04a2  STR  XY03:GPCChip  # chip 02
+        CCID58-1-01b1  STR  XY04:GPCChip  # chip 03
+        CCID58-1-09b1  STR  XY05:GPCChip  # chip 04
+        CCID58-2-09b1  STR  XY06:GPCChip  # chip 05
+        CCID58-2-22a1  STR  XY10:GPCChip  # chip 06
+        CCID58-2-01a1  STR  XY11:GPCChip  # chip 07
+        CCID58-3-11a1  STR  XY12:GPCChip  # chip 08
+        CCID58-3-06a1  STR  XY13:GPCChip  # chip 09
+        CCID58-3-05b1  STR  XY14:GPCChip  # chip 10
+        CCID58-3-08b1  STR  XY15:GPCChip  # chip 11
+        CCID58-1-02b1  STR  XY16:GPCChip  # chip 12
+        CCID58-2-07b2  STR  XY17:GPCChip  # chip 13
+        CCID58-1-19a1  STR  XY20:GPCChip  # chip 14
+        CCID58-1-04a1  STR  XY21:GPCChip  # chip 15
+        CCID58-2-09a2  STR  XY22:GPCChip  # chip 16
+        CCID58-1-02a1  STR  XY23:GPCChip  # chip 17
+        CCID58-3-10b1  STR  XY24:GPCChip  # chip 18
+        CCID58-3-05b2  STR  XY25:GPCChip  # chip 19
+        CCID58-3-04b1  STR  XY26:GPCChip  # chip 20
+        CCID58-1-18b1  STR  XY27:GPCChip  # chip 21
+        CCID58-3-13a2  STR  XY30:GPCChip  # chip 22
+        CCID58-3-05a1  STR  XY31:GPCChip  # chip 23
+        CCID58-2-01a2  STR  XY32:GPCChip  # chip 24
+        CCID58-1-02a2  STR  XY33:GPCChip  # chip 25
+        CCID58-3-03b1  STR  XY34:GPCChip  # chip 26
+        CCID58-1-01b2  STR  XY35:GPCChip  # chip 27
+        CCID58-3-14b1  STR  XY36:GPCChip  # chip 28
+        CCID58-2-23b2  STR  XY37:GPCChip  # chip 29
+        CCID58-3-02b1  STR  XY40:GPCChip  # chip 30
+        CCID58-1-03b2  STR  XY41:GPCChip  # chip 31
+        CCID58-1-07b1  STR  XY42:GPCChip  # chip 32
+        CCID58-2-11b2  STR  XY43:GPCChip  # chip 33
+        CCID58-2-09a1  STR  XY44:GPCChip  # chip 34
+        CCID58-3-04a2  STR  XY45:GPCChip  # chip 35
+        CCID58-3-02a1  STR  XY46:GPCChip  # chip 36
+        CCID58-3-14a1  STR  XY47:GPCChip  # chip 37
+        CCID58-1-17b1  STR  XY50:GPCChip  # chip 38
+        CCID58-2-09b2  STR  XY51:GPCChip  # chip 39
+        CCID58-1-04b1  STR  XY52:GPCChip  # chip 40
+        CCID58-1-05b2  STR  XY53:GPCChip  # chip 41
+        CCID58-3-05a2  STR  XY54:GPCChip  # chip 42
+        CCID58-3-03a2  STR  XY55:GPCChip  # chip 43
+        CCID58-3-02a2  STR  XY56:GPCChip  # chip 44
+        CCID58-3-11a2  STR  XY57:GPCChip  # chip 45
+        CCID58-2-16b1  STR  XY60:GPCChip  # chip 46
+        CCID58-1-03b1  STR  XY61:GPCChip  # chip 47
+        CCID58-3-03b2  STR  XY62:GPCChip  # chip 48
+        CCID58-1-02b2  STR  XY63:GPCChip  # chip 49
+        CCID58-1-07a1  STR  XY64:GPCChip  # chip 50
+        CCID58-2-04a1  STR  XY65:GPCChip  # chip 51
+        CCID58-3-10a1  STR  XY66:GPCChip  # chip 52
+        CCID58-1-09a1  STR  XY67:GPCChip  # chip 53
+        CCID58-2-13b1  STR  XY71:GPCChip  # chip 54
+        CCID58-1-14b1  STR  XY72:GPCChip  # chip 55
+        CCID58-3-11b2  STR  XY73:GPCChip  # chip 56
+        CCID58-1-05a2  STR  XY74:GPCChip  # chip 57
+        CCID58-1-21a1  STR  XY75:GPCChip  # chip 58
+        CCID58-2-05a1  STR  XY76:GPCChip  # chip 59
+END
+
+CHIPS   METADATA
+        GPCChip         METADATA
+                # Extension name, cellName:cellType
+                xy00   STR  xy00:GPCCell
+                xy10   STR  xy10:GPCCell
+                xy20   STR  xy20:GPCCell
+                xy30   STR  xy30:GPCCell
+                xy40   STR  xy40:GPCCell
+                xy50   STR  xy50:GPCCell
+                xy60   STR  xy60:GPCCell
+                xy70   STR  xy70:GPCCell
+                xy01   STR  xy01:GPCCell
+                xy11   STR  xy11:GPCCell
+                xy21   STR  xy21:GPCCell
+                xy31   STR  xy31:GPCCell
+                xy41   STR  xy41:GPCCell
+                xy51   STR  xy51:GPCCell
+                xy61   STR  xy61:GPCCell
+                xy71   STR  xy71:GPCCell
+                xy02   STR  xy02:GPCCell
+                xy12   STR  xy12:GPCCell
+                xy22   STR  xy22:GPCCell
+                xy32   STR  xy32:GPCCell
+                xy42   STR  xy42:GPCCell
+                xy52   STR  xy52:GPCCell
+                xy62   STR  xy62:GPCCell
+                xy72   STR  xy72:GPCCell
+                xy03   STR  xy03:GPCCell
+                xy13   STR  xy13:GPCCell
+                xy23   STR  xy23:GPCCell
+                xy33   STR  xy33:GPCCell
+                xy43   STR  xy43:GPCCell
+                xy53   STR  xy53:GPCCell
+                xy63   STR  xy63:GPCCell
+                xy73   STR  xy73:GPCCell
+                xy04   STR  xy04:GPCCell
+                xy14   STR  xy14:GPCCell
+                xy24   STR  xy24:GPCCell
+                xy34   STR  xy34:GPCCell
+                xy44   STR  xy44:GPCCell
+                xy54   STR  xy54:GPCCell
+                xy64   STR  xy64:GPCCell
+                xy74   STR  xy74:GPCCell
+                xy05   STR  xy05:GPCCell
+                xy15   STR  xy15:GPCCell
+                xy25   STR  xy25:GPCCell
+                xy35   STR  xy35:GPCCell
+                xy45   STR  xy45:GPCCell
+                xy55   STR  xy55:GPCCell
+                xy65   STR  xy65:GPCCell
+                xy75   STR  xy75:GPCCell
+                xy06   STR  xy06:GPCCell
+                xy16   STR  xy16:GPCCell
+                xy26   STR  xy26:GPCCell
+                xy36   STR  xy36:GPCCell
+                xy46   STR  xy46:GPCCell
+                xy56   STR  xy56:GPCCell
+                xy66   STR  xy66:GPCCell
+                xy76   STR  xy76:GPCCell
+                xy07   STR  xy07:GPCCell
+                xy17   STR  xy17:GPCCell
+                xy27   STR  xy27:GPCCell
+                xy37   STR  xy37:GPCCell
+                xy47   STR  xy47:GPCCell
+                xy57   STR  xy57:GPCCell
+                xy67   STR  xy67:GPCCell
+                xy77   STR  xy77:GPCCell
+        END
+END
+
+# Specify the cell data
+CELLS   METADATA
+        GPCCell         METADATA
+                CELL.TRIMSEC.SOURCE     STR     HEADER
+                CELL.TRIMSEC            STR     DATASEC
+                CELL.BIASSEC.SOURCE     STR     HEADER
+                CELL.BIASSEC            STR     BIASSEC
+        END
+END
+
+
+# How to translate PS concepts into FITS headers
+TRANSLATION     METADATA
+        FPA.FILTERID    STR     FILTERID
+        FPA.FILTER      STR     FILTERID
+        FPA.RA          STR     RA
+        FPA.DEC         STR     DEC
+        FPA.RADECSYS    STR     RADECSYS
+        FPA.OBSTYPE     STR     OBSTYPE
+        FPA.OBJECT      STR     OBJECT
+        FPA.OBS.MODE    STR     OBS_MODE
+        FPA.COMMENT     STR     CMMTOBS
+        FPA.AIRMASS     STR     AIRMASS
+        FPA.POSANGLE    STR     POSANGLE
+	FPA.ROTANGLE	STR	ROT
+        FPA.FOCUS       STR     M2Z
+        FPA.TIME        STR     SHUTOUTC
+        FPA.ALT         STR     ALT
+        FPA.AZ          STR     AZ
+        FPA.TEMP        STR     DETTEM
+        FPA.M1X         STR     M1X
+        FPA.M1Y         STR     M1Y   
+        FPA.M1Z         STR     M1Z   
+        FPA.M1TIP       STR     M1TIP 
+        FPA.M1TILT      STR     M1TILT
+        FPA.M2X         STR     M2X
+        FPA.M2Y         STR     M2Y   
+        FPA.M2Z         STR     M2Z   
+        FPA.M2TIP       STR     M2TIP 
+        FPA.M2TILT      STR     M2TILT
+        FPA.ENV.TEMP    STR     ENVTEM
+        FPA.ENV.HUMID   STR     ENVHUM
+        FPA.ENV.WIND    STR     ENVWIN
+        FPA.ENV.DIR     STR     ENVDIR
+
+        FPA.TELTEMP.M1     STR  TELTEMM1 # Primary mirror temps (C) 
+        FPA.TELTEMP.M1CELL STR  TELTEMMS # Primary mirror support temps (C)   
+        FPA.TELTEMP.M2     STR  TELTEMM2 # Secondary mirror temps (C
+        FPA.TELTEMP.SPIDER STR  TELTEMSP # Spider temperatures (C)  
+        FPA.TELTEMP.TRUSS  STR  TELTEMTR # Mid truss temperatures (C
+        FPA.TELTEMP.EXTRA  STR  TELTEMEX # Miscellaneous temperatures (C)     
+
+        FPA.PON.TIME    STR     PONTIME
+
+        CHIP.ID         STR     DETECTOR
+        CELL.XBIN       STR     CCDSUM
+        CELL.YBIN       STR     CCDSUM
+        CELL.X0         STR     IMNPIX1
+        CELL.Y0         STR     IMNPIX2
+        CELL.XPARITY    STR     ATM1_1
+        CELL.YPARITY    STR     ATM2_2
+	CHIP.TEMP	STR	DETTEM
+        FPA.EXPOSURE    STR     EXPREQ          # Requested exposure time, presumably camera exposure time
+        CELL.EXPOSURE   STR     EXPTIME         # Exposure time measured by shutter
+        CELL.DARKTIME   STR     DARKTIME        # Exposure time for camera
+        CELL.TIME       STR     SHUTOUTC	# Observation time
+        CELL.GAIN       STR     GAIN		# Cell gain (e/ADU)
+        CELL.READNOISE  STR     RDNOISE		# Cell read noise (ADU)
+        CELL.SATURATION STR     MAXLIN		# Saturation point (ADU)
+END
+
+# Default PS concepts that may be specified by value
+DEFAULTS        METADATA
+        FPA.TELESCOPE   STR     PS1
+        FPA.INSTRUMENT  STR     GPC1
+        FPA.LONGITUDE   STR     10:25:01.417 # West Longitude in Hours 10.4170608521
+        FPA.LATITUDE    STR     20:42:25.558 # North Latitude in Degrees 20.7070999146
+        FPA.ELEVATION   F32     3048.0 # altitude in meters
+        FPA.DETECTOR    STR     GPC1
+        FPA.TIMESYS     STR     UTC
+	CHIP.XSIZE	S32	4846
+	CHIP.YSIZE	S32	4868
+        CHIP.XPARITY    S32     1
+        CHIP.YPARITY    S32     1
+        CHIP.X0.DEPEND          STR     CHIP.NAME
+        CHIP.X0         METADATA
+          XY01  S32     4971
+          XY02  S32     4971
+          XY03  S32     4971
+          XY04  S32     4971
+          XY05  S32     4971
+          XY06  S32     4971
+          XY10  S32     9942
+          XY11  S32     9942
+          XY12  S32     9942
+          XY13  S32     9942
+          XY14  S32     9942
+          XY15  S32     9942
+          XY16  S32     9942
+          XY17  S32     9942
+          XY20  S32     14913
+          XY21  S32     14913
+          XY22  S32     14913
+          XY23  S32     14913
+          XY24  S32     14913
+          XY25  S32     14913
+          XY26  S32     14913
+          XY27  S32     14913
+          XY30  S32     19884
+          XY31  S32     19884
+          XY32  S32     19884
+          XY33  S32     19884
+          XY34  S32     19884
+          XY35  S32     19884
+          XY36  S32     19884
+          XY37  S32     19884
+          XY40  S32     20041
+          XY41  S32     20041
+          XY42  S32     20041
+          XY43  S32     20041
+          XY44  S32     20041
+          XY45  S32     20041
+          XY46  S32     20041
+          XY47  S32     20041
+          XY50  S32     25012
+          XY51  S32     25012
+          XY52  S32     25012
+          XY53  S32     25012
+          XY54  S32     25012
+          XY55  S32     25012
+          XY56  S32     25012
+          XY57  S32     25012
+          XY60  S32     29983
+          XY61  S32     29983
+          XY62  S32     29983
+          XY63  S32     29983
+          XY64  S32     29983
+          XY65  S32     29983
+          XY66  S32     29983
+          XY67  S32     29983
+          XY71  S32     34954
+          XY72  S32     34954
+          XY73  S32     34954
+          XY74  S32     34954
+          XY75  S32     34954
+          XY76  S32     34954
+        END
+        CHIP.Y0.DEPEND          STR     CHIP.NAME
+        CHIP.Y0         METADATA
+          XY01  S32     10286
+          XY02  S32     15429
+          XY03  S32     20572
+          XY04  S32     25715
+          XY05  S32     30858
+          XY06  S32     36001
+          XY10  S32     5143
+          XY11  S32     10286
+          XY12  S32     15429
+          XY13  S32     20572
+          XY14  S32     25715
+          XY15  S32     30858
+          XY16  S32     36001
+          XY17  S32     41144
+          XY20  S32     5143
+          XY21  S32     10286
+          XY22  S32     15429
+          XY23  S32     20572
+          XY24  S32     25715
+          XY25  S32     30858
+          XY26  S32     36001
+          XY27  S32     41144
+          XY30  S32     5143
+          XY31  S32     10286
+          XY32  S32     15429
+          XY33  S32     20572
+          XY34  S32     25715
+          XY35  S32     30858
+          XY36  S32     36001
+          XY37  S32     41144
+          XY40  S32     306
+          XY41  S32     5449
+          XY42  S32     10592
+          XY43  S32     15735
+          XY44  S32     20878
+          XY45  S32     26021
+          XY46  S32     31164
+          XY47  S32     36307
+          XY50  S32     306
+          XY51  S32     5449
+          XY52  S32     10592
+          XY53  S32     15735
+          XY54  S32     20878
+          XY55  S32     26021
+          XY56  S32     31164
+          XY57  S32     36307
+          XY60  S32     306
+          XY61  S32     5449
+          XY62  S32     10592
+          XY63  S32     15735
+          XY64  S32     20878
+          XY65  S32     26021
+          XY66  S32     31164
+          XY67  S32     36307
+          XY71  S32     5449
+          XY72  S32     10592
+          XY73  S32     15735
+          XY74  S32     20878
+          XY75  S32     26021
+          XY76  S32     31164
+        END
+        CHIP.XPARITY.DEPEND     STR     CHIP.NAME
+        CHIP.XPARITY    METADATA
+          XY01  S32     -1
+          XY02  S32     -1
+          XY03  S32     -1
+          XY04  S32     -1
+          XY05  S32     -1
+          XY06  S32     -1
+          XY10  S32     -1
+          XY11  S32     -1
+          XY12  S32     -1
+          XY13  S32     -1
+          XY14  S32     -1
+          XY15  S32     -1
+          XY16  S32     -1
+          XY17  S32     -1
+          XY20  S32     -1
+          XY21  S32     -1
+          XY22  S32     -1
+          XY23  S32     -1
+          XY24  S32     -1
+          XY25  S32     -1
+          XY26  S32     -1
+          XY27  S32     -1
+          XY30  S32     -1
+          XY31  S32     -1
+          XY32  S32     -1
+          XY33  S32     -1
+          XY34  S32     -1
+          XY35  S32     -1
+          XY36  S32     -1
+          XY37  S32     -1
+          XY40  S32     1
+          XY41  S32     1
+          XY42  S32     1
+          XY43  S32     1
+          XY44  S32     1
+          XY45  S32     1
+          XY46  S32     1
+          XY47  S32     1
+          XY50  S32     1
+          XY51  S32     1
+          XY52  S32     1
+          XY53  S32     1
+          XY54  S32     1
+          XY55  S32     1
+          XY56  S32     1
+          XY57  S32     1
+          XY60  S32     1
+          XY61  S32     1
+          XY62  S32     1
+          XY63  S32     1
+          XY64  S32     1
+          XY65  S32     1
+          XY66  S32     1
+          XY67  S32     1
+          XY71  S32     1
+          XY72  S32     1
+          XY73  S32     1
+          XY74  S32     1
+          XY75  S32     1
+          XY76  S32     1
+        END
+        CHIP.YPARITY.DEPEND     STR     CHIP.NAME
+        CHIP.YPARITY    METADATA
+          XY01  S32     -1
+          XY02  S32     -1
+          XY03  S32     -1
+          XY04  S32     -1
+          XY05  S32     -1
+          XY06  S32     -1
+          XY10  S32     -1
+          XY11  S32     -1
+          XY12  S32     -1
+          XY13  S32     -1
+          XY14  S32     -1
+          XY15  S32     -1
+          XY16  S32     -1
+          XY17  S32     -1
+          XY20  S32     -1
+          XY21  S32     -1
+          XY22  S32     -1
+          XY23  S32     -1
+          XY24  S32     -1
+          XY25  S32     -1
+          XY26  S32     -1
+          XY27  S32     -1
+          XY30  S32     -1
+          XY31  S32     -1
+          XY32  S32     -1
+          XY33  S32     -1
+          XY34  S32     -1
+          XY35  S32     -1
+          XY36  S32     -1
+          XY37  S32     -1
+          XY40  S32     1
+          XY41  S32     1
+          XY42  S32     1
+          XY43  S32     1
+          XY44  S32     1
+          XY45  S32     1
+          XY46  S32     1
+          XY47  S32     1
+          XY50  S32     1
+          XY51  S32     1
+          XY52  S32     1
+          XY53  S32     1
+          XY54  S32     1
+          XY55  S32     1
+          XY56  S32     1
+          XY57  S32     1
+          XY60  S32     1
+          XY61  S32     1
+          XY62  S32     1
+          XY63  S32     1
+          XY64  S32     1
+          XY65  S32     1
+          XY66  S32     1
+          XY67  S32     1
+          XY71  S32     1
+          XY72  S32     1
+          XY73  S32     1
+          XY74  S32     1
+          XY75  S32     1
+          XY76  S32     1
+        END
+        CELL.READDIR    S32     1
+        CELL.BAD        S32     -100
+	CELL.XSIZE	S32	590
+	CELL.YSIZE	S32	598
+        CELL.TIMESYS    STR     UTC
+END
+
+# How to translation PS concepts into database lookups
+DATABASE        METADATA
+END
+
+
+# Where there might be some ambiguity, specify the format
+FORMATS         METADATA
+        FPA.RA          STR     DEGREES
+        FPA.DEC         STR     DEGREES
+	FPA.LONGITUDE	STR	HOURS
+	FPA.LATITUDE	STR	DEGREES
+        FPA.TIME        STR     YEAR.FIRST
+        CELL.TIME       STR     YEAR.FIRST
+        CELL.BINNING    STR     TOGETHER
+        # CELL.X0         STR     FORTRAN
+        # CELL.Y0         STR     FORTRAN
+	CELL.READNOISE	STR	ADU
+END
+ 
Index: /branches/cnb_branches/cnb_branch_20090215/ippconfig/gpc1/format_mef.config
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippconfig/gpc1/format_mef.config	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/ippconfig/gpc1/format_mef.config	(revision 23197)
@@ -197,8 +197,8 @@
 	FPA.INSTRUMENT	STR	GPC1
 	FPA.DETECTOR	STR	GPC1
-	FPA.OBS	S32	12345
-	FPA.TIMESYS	STR	UTC
-	CHIP.XSIZE		S32	4846
-	CHIP.YSIZE		S32	4868
+	FPA.OBS		S32	12345
+	FPA.TIMESYS	STR	TAI
+	CHIP.XSIZE	S32	4846
+	CHIP.YSIZE	S32	4868
 	CHIP.XPARITY	S32	1
 	CHIP.YPARITY	S32	1
@@ -461,6 +461,6 @@
 	CELL.XSIZE	S32	590
 	CELL.YSIZE	S32	598
-#	CELL.TIME	STR	MJD-OBS
-#	CELL.TIMESYS	STR	TIMESYS
+	CELL.TIME	STR	MJD-OBS
+	CELL.TIMESYS	STR	TAI
 #	CELL.SATURATION	STR	60000
 END
Index: /branches/cnb_branches/cnb_branch_20090215/ippconfig/ipprc.config.in
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippconfig/ipprc.config.in	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/ippconfig/ipprc.config.in	(revision 23197)
@@ -4,5 +4,5 @@
 # Note: do not include $HOME in the distributed copy used by ippMonitor
 # PATH            STR     @pkgdatadir@:$HOME/.ipp:.
-PATH              STR     @pkgdatadir@:.
+PATH              STR     $HOME/ippconfig/:$PSCONFDIR/$PSCONFIG/share/ippconfig/
 
 # load the site-specific information from here
Index: anches/cnb_branches/cnb_branch_20090215/ippconfig/isp/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippconfig/isp/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-Makefile
-Makefile.in
Index: anches/cnb_branches/cnb_branch_20090215/ippconfig/lbc_red/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippconfig/lbc_red/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-Makefile
-Makefile.in
Index: anches/cnb_branches/cnb_branch_20090215/ippconfig/lulin/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippconfig/lulin/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-Makefile
-Makefile.in
Index: anches/cnb_branches/cnb_branch_20090215/ippconfig/megacam/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippconfig/megacam/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-Makefile
-Makefile.in
Index: anches/cnb_branches/cnb_branch_20090215/ippconfig/mosaic2/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippconfig/mosaic2/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-Makefile
-Makefile.in
Index: anches/cnb_branches/cnb_branch_20090215/ippconfig/recipes/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippconfig/recipes/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-Makefile
-Makefile.in
Index: anches/cnb_branches/cnb_branch_20090215/ippconfig/sdss/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippconfig/sdss/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-Makefile
-Makefile.in
Index: anches/cnb_branches/cnb_branch_20090215/ippconfig/sdssmosaic/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippconfig/sdssmosaic/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-Makefile
-Makefile.in
Index: anches/cnb_branches/cnb_branch_20090215/ippconfig/simmosaic/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippconfig/simmosaic/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-Makefile
-Makefile.in
Index: anches/cnb_branches/cnb_branch_20090215/ippconfig/simple/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippconfig/simple/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-Makefile
-Makefile.in
Index: anches/cnb_branches/cnb_branch_20090215/ippconfig/simtest/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippconfig/simtest/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-Makefile.in
-Makefile
Index: anches/cnb_branches/cnb_branch_20090215/ippconfig/skycell/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippconfig/skycell/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-Makefile
-Makefile.in
Index: anches/cnb_branches/cnb_branch_20090215/ippconfig/tc3/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippconfig/tc3/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-Makefile
-Makefile.in
Index: anches/cnb_branches/cnb_branch_20090215/ippconfig/uh8k/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippconfig/uh8k/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-Makefile
-Makefile.in
Index: anches/cnb_branches/cnb_branch_20090215/ippconfig/vysos5/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippconfig/vysos5/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-Makefile
-Makefile.in
Index: anches/cnb_branches/cnb_branch_20090215/ippdb/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippdb/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,21 +1,0 @@
-Doxyfile
-Makefile
-Makefile.in
-aclocal.m4
-autom4te.cache
-compile
-config.guess
-config.h
-config.h.in
-config.log
-config.status
-config.sub
-configure
-depcomp
-install-sh
-ippdb.pc
-libtool
-ltmain.sh
-missing
-stamp-h1
-docs
Index: anches/cnb_branches/cnb_branch_20090215/ippdb/src/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippdb/src/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,6 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-libippdb.la
-libippdb_la-ippdb.lo
Index: anches/cnb_branches/cnb_branch_20090215/ippdb/tests/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ippdb/tests/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,25 +1,0 @@
-.deps
-Makefile
-Makefile.in
-atconfig
-.libs
-alloc
-cleanup
-createtable
-dbcleanup
-dbsetup
-droptable
-init
-insert
-insertfits
-insertobject
-metadatafromobject
-objectfrommetadata
-package.m4
-pop
-popfits
-popobject
-selectrowsfits
-testsuite
-testsuite.dir
-testsuite.log
Index: anches/cnb_branches/cnb_branch_20090215/magic/remove/src/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/magic/remove/src/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,4 +1,0 @@
-streaksremove
-streaksreplace
-streakscompare
-streaksrelease
Index: /branches/cnb_branches/cnb_branch_20090215/operations/ippconfig/ipprc.config
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/operations/ippconfig/ipprc.config	(revision 23197)
+++ /branches/cnb_branches/cnb_branch_20090215/operations/ippconfig/ipprc.config	(revision 23197)
@@ -0,0 +1,25 @@
+# IPP Configuration file
+
+# Default search path for configuration files (add $HOME if desired)
+PATH            STR     /home/panstarrs/ipp/ippconfig/:$PSCONFDIR/$PSCONFIG/share/ippconfig/
+
+# load the site-specific information from here
+SITE            STR     site.config
+
+# load the system configuration information from here
+SYSTEM          STR     system.config
+
+# logging verbosity levels
+LOGLEVEL	S32	9			# Logging level; 3=INFO
+LOGFORMAT	STR	M			# Log format
+# LOGFORMAT	STR	THLNM			# Log format
+
+LOGDEST		STR	STDERR			# Log destination
+TRACEDEST	STR	STDERR			# Trace destination
+
+TRACE		METADATA			# Trace levels
+# place default trace lines here
+# example: 
+#psLib.db S32	10
+err S32 5
+END
Index: /branches/cnb_branches/cnb_branch_20090215/operations/ippconfig/site.config
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/operations/ippconfig/site.config	(revision 23197)
+++ /branches/cnb_branches/cnb_branch_20090215/operations/ippconfig/site.config	(revision 23197)
@@ -0,0 +1,39 @@
+## Site Configuration : use this as an example for your installation
+## Supply locations of interest
+
+# place your data directories here and refer to as path://PATH/remainder
+DATAPATH	METADATA
+        GPC1    STR     /data/ipp004.0/gpc1/
+END
+
+# List of tessellations, and their DVO CATDIR
+TESSELLATIONS	METADATA
+	FIXNS   STR     path://GPC1/scitest.200807/FIXNS/
+END
+
+# dvo databases used for output
+DVO.CATDIRS     METADATA
+END
+
+# dvo databases used for psastro reference
+PSASTRO.CATDIRS METADATA
+	2MASS		STR	/data/ipp004.0/ipp/ippRefs/catdir.2mass
+	SYNTH.GRIZY	STR	/data/ipp004.0/ipp/ippRefs/catdir.synth.grizy
+	SYNTH.BRIGHT	STR	/data/ipp004.0/ipp/ippRefs/catdir.synth.bright
+	SYNTH.SIMTEST	STR	/data/ipp004.0/ipp/ippRefs/catdir.synth.grizy
+END
+
+# nebulous server
+NEB_SERVER	STR	http://ipp004:80/nebulous	# Nebulous server
+
+# Database configuration
+DBSERVER	STR	ipp004			# Database host name (for psDBInit)
+DBNAME		STR	NONE			# Database name (for psDBInit)
+DBUSER		STR	ipp			# Database user name (for psDBInit)
+DBPASSWORD	STR	ipp			# Database password (for psDBInit)
+DBPORT          S32     0                       # Database port (for psDBInit); 0 = default
+
+# other basic values:
+# XXX is TIME still needed / used?
+# XXX use autoconf to put this in a known location?
+# TIME		STR	psTime.config	# Time configuration file
Index: /branches/cnb_branches/cnb_branch_20090215/operations/registration/input
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/operations/registration/input	(revision 23197)
+++ /branches/cnb_branches/cnb_branch_20090215/operations/registration/input	(revision 23197)
@@ -0,0 +1,136 @@
+macro setup
+    module pantasks.pro
+    module register.pro
+
+    $POLLLIMIT = 128
+    $RUNEXEC = 0.1
+    $RUNPOLL = 0.1
+    $LOADEXEC = 5
+    # $VERBOSE = 4 
+
+    $default_host = ipp023
+    $workdir_template = neb://anyhost/default.register/
+    queueload tmp -x "cat $MODULES:0/ipphosts.mhpcc.config"
+    ipptool2book tmp ipphosts -key camera
+    add.database gpc1
+    wave1_nothreads
+    wave2_nothreads
+    wave2_nothreads
+end
+
+
+macro change_polllimit
+    $POLLLIMIT = $1
+end
+
+macro change_runexec
+    $RUNEXEC = $1
+end
+
+macro change_runpoll
+    $RUNPOLL = $1
+end
+
+macro print_polllimit
+    echo $POLLLIMIT
+end
+
+macro print_runexec
+    echo $RUNEXEC
+end
+
+macro print_runpoll
+    echo $RUNPOLL
+end
+
+macro change_loadexec
+    $LOADEXEC = $1
+end
+
+macro change_loadpoll
+    $LOADPOLL = $1
+end
+
+macro print_loadexec
+    echo $LOADEXEC
+end
+
+macro print_loadpoll
+    echo $LOADPOLL
+end
+
+macro wave1
+# ipp004 is home
+# ipp005 is flaky
+    controller host add ipp006 -threads $1
+    controller host add ipp007 -threads $1
+# ipp008 is flaky
+    controller host add ipp009 -threads $1
+    controller host add ipp010 -threads $1
+    controller host add ipp011 -threads $1
+    controller host add ipp012 -threads $1
+    controller host add ipp013 -threads $1
+    controller host add ipp014 -threads $1
+    controller host add ipp016 -threads $1
+    controller host add ipp018 -threads $1
+# ipp019 is Nebulous
+    controller host add ipp020 -threads $1
+    controller host add ipp021 -threads $1
+# ipp025 is flaky
+end
+
+macro wave2
+    controller host add ipp015 -threads $1
+    controller host add ipp017 -threads $1
+    controller host add ipp023 -threads $1
+    controller host add ipp024 -threads $1
+    controller host add ipp026 -threads $1
+    controller host add ipp027 -threads $1
+    controller host add ipp028 -threads $1
+    controller host add ipp029 -threads $1
+    controller host add ipp030 -threads $1
+    controller host add ipp031 -threads $1
+    controller host add ipp032 -threads $1
+    controller host add ipp033 -threads $1
+    controller host add ipp034 -threads $1
+    controller host add ipp035 -threads $1
+    controller host add ipp036 -threads $1
+end
+
+macro wave1_nothreads
+# ipp004 is home
+# ipp005 is flaky
+    controller host add ipp006
+    controller host add ipp007
+# ipp008 is flaky
+    controller host add ipp009
+    controller host add ipp010
+    controller host add ipp011
+    controller host add ipp012
+    controller host add ipp013
+    controller host add ipp016
+    controller host add ipp018
+# ipp019 is Nebulous
+    controller host add ipp020
+    controller host add ipp021
+# ipp025 is flaky
+end
+
+macro wave2_nothreads
+    controller host add ipp015
+    controller host add ipp017
+    controller host add ipp023
+    controller host add ipp024
+    controller host add ipp026
+    controller host add ipp027
+    controller host add ipp028
+    controller host add ipp029
+    controller host add ipp030
+    controller host add ipp031
+    controller host add ipp032
+    controller host add ipp033
+    controller host add ipp034
+    controller host add ipp035
+    controller host add ipp036
+end
+
Index: /branches/cnb_branches/cnb_branch_20090215/operations/registration/ptolemy.rc
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/operations/registration/ptolemy.rc	(revision 23197)
+++ /branches/cnb_branches/cnb_branch_20090215/operations/registration/ptolemy.rc	(revision 23197)
@@ -0,0 +1,6 @@
+
+PANTASKS_SERVER_STDOUT  pantasks.stdout.log
+PANTASKS_SERVER_STDERR  pantasks.stderr.log
+PANTASKS_SERVER         ipp008
+PASSWORD                foobar
+
Index: /branches/cnb_branches/cnb_branch_20090215/operations/summitcopy/input
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/operations/summitcopy/input	(revision 23197)
+++ /branches/cnb_branches/cnb_branch_20090215/operations/summitcopy/input	(revision 23197)
@@ -0,0 +1,8 @@
+
+macro setup
+  module pantasks.pro
+  module summit.copy.pro
+  module site.mhpcc.pro
+  init.site
+  add.database gpc1
+end
Index: /branches/cnb_branches/cnb_branch_20090215/operations/summitcopy/ptolemy.rc
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/operations/summitcopy/ptolemy.rc	(revision 23197)
+++ /branches/cnb_branches/cnb_branch_20090215/operations/summitcopy/ptolemy.rc	(revision 23197)
@@ -0,0 +1,6 @@
+
+PANTASKS_SERVER_STDOUT  pantasks.stdout.log
+PANTASKS_SERVER_STDERR  pantasks.stderr.log
+PANTASKS_SERVER         ipp007
+PASSWORD                foobar
+
Index: anches/cnb_branches/cnb_branch_20090215/pedestal/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/pedestal/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,15 +1,0 @@
-Makefile
-Makefile.in
-aclocal.m4
-autom4te.cache
-compile
-config.guess
-config.log
-config.status
-config.sub
-configure
-depcomp
-install-sh
-ltmain.sh
-missing
-test
Index: anches/cnb_branches/cnb_branch_20090215/pedestal/src/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/pedestal/src/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,7 +1,0 @@
-.deps
-Makefile
-Makefile.in
-config.h
-config.h.in
-pedestal
-stamp-h1
Index: anches/cnb_branches/cnb_branch_20090215/pois/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/pois/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,7 +1,0 @@
-Makefile Makefile.in
-aclocal.m4 autom4te.cache
-config.* configure
-depcomp install-sh libtool ltmain.sh missing mkinstalldirs compile stamp-h*
-pois.pc
-pois-*.tar.bz2
-pois-*.tar.gz
Index: anches/cnb_branches/cnb_branch_20090215/pois/python/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/pois/python/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-Makefile Makefile.in
-*.pyc
Index: anches/cnb_branches/cnb_branch_20090215/pois/src/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/pois/src/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,8 +1,0 @@
-Makefile Makefile.in
-.deps .libs
-errorCodes.c poisErrorCodes.h
-*.la *.lo
-pois
-config.h
-config.h.in
-stamp-h1
Index: anches/cnb_branches/cnb_branch_20090215/pois/swig/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/pois/swig/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,9 +1,0 @@
-Makefile Makefile.in
-*.pm *.pyc
-*_wrap.c
-poisSwig.py psLibSwig.py xpaSwig.py
-swigrun.py
-xpa.py
-.Makefile.depend
-*.la *.lo
-.deps .libs
Index: anches/cnb_branches/cnb_branch_20090215/ppArith/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ppArith/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,18 +1,0 @@
-Makefile
-Makefile.in
-aclocal.m4
-autom4te.cache
-compile
-config.log
-config.status
-configure
-depcomp
-install-sh
-missing
-config.guess
-libtool
-ltmain.sh
-stamp-h1
-config.sub
-test
-Doxyfile
Index: anches/cnb_branches/cnb_branch_20090215/ppArith/src/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ppArith/src/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,8 +1,0 @@
-config.h
-config.h.in
-Makefile
-Makefile.in
-stamp-h1
-.deps
-.libs
-ppArith
Index: anches/cnb_branches/cnb_branch_20090215/ppConfigDump/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ppConfigDump/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,16 +1,0 @@
-aclocal.m4
-autom4te.cache
-compile
-config.guess
-config.log
-config.status
-config.sub
-configure
-depcomp
-install-sh
-ltmain.sh
-Makefile
-Makefile.in
-missing
-libtool
-Doxyfile
Index: anches/cnb_branches/cnb_branch_20090215/ppConfigDump/src/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ppConfigDump/src/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,8 +1,0 @@
-.libs
-config.h
-config.h.in
-Makefile
-Makefile.in
-ppConfigDump
-stamp-h1
-.deps
Index: anches/cnb_branches/cnb_branch_20090215/ppImage/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ppImage/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,18 +1,0 @@
-bin
-aclocal.m4
-autom4te.cache
-compile
-config.log
-config.status
-configure
-depcomp
-install-sh
-Makefile.in
-missing
-Makefile
-config.cache
-config.guess
-config.sub
-ltmain.sh
-libtool
-Doxyfile
Index: anches/cnb_branches/cnb_branch_20090215/ppImage/src/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ppImage/src/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,10 +1,0 @@
-ppImage
-ppTest
-Makefile
-Makefile.in
-.deps
-ppFocus
-config.h
-config.h.in
-stamp-h1
-.libs
Index: anches/cnb_branches/cnb_branch_20090215/ppImage/test/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ppImage/test/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,1 +1,0 @@
-*
Index: anches/cnb_branches/cnb_branch_20090215/ppMerge/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ppMerge/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,17 +1,0 @@
-Makefile
-Makefile.in
-aclocal.m4
-autom4te.cache
-compile
-config.log
-config.status
-configure
-depcomp
-install-sh
-missing
-test
-config.guess
-config.sub
-libtool
-ltmain.sh
-Doxyfile
Index: anches/cnb_branches/cnb_branch_20090215/ppMerge/src/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ppMerge/src/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,8 +1,0 @@
-.deps
-Makefile
-Makefile.in
-ppMerge
-config.h
-config.h.in
-stamp-h1
-.libs
Index: anches/cnb_branches/cnb_branch_20090215/ppNorm/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ppNorm/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,16 +1,0 @@
-Makefile
-Makefile.in
-aclocal.m4
-autom4te.cache
-compile
-config.log
-config.status
-configure
-depcomp
-install-sh
-missing
-test
-config.guess
-config.sub
-libtool
-ltmain.sh
Index: anches/cnb_branches/cnb_branch_20090215/ppNorm/src/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ppNorm/src/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,8 +1,0 @@
-Makefile
-Makefile.in
-ppNormCalc
-.deps
-config.h
-config.h.in
-stamp-h1
-.libs
Index: anches/cnb_branches/cnb_branch_20090215/ppSim/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ppSim/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,15 +1,0 @@
-aclocal.m4
-autom4te.cache
-config.guess
-config.log
-config.status
-config.sub
-configure
-depcomp
-install-sh
-libtool
-ltmain.sh
-Makefile
-Makefile.in
-missing
-test
Index: anches/cnb_branches/cnb_branch_20090215/ppSim/src/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ppSim/src/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,9 +1,0 @@
-config.h
-config.h.in
-Makefile
-Makefile.in
-ppSim
-stamp-h1
-.deps
-.libs
-ppSimSequence
Index: anches/cnb_branches/cnb_branch_20090215/ppStack/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ppStack/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,18 +1,0 @@
-aclocal.m4
-compile
-config.guess
-config.log
-config.status
-config.sub
-configure
-depcomp
-install-sh
-libtool
-ltmain.sh
-Makefile
-Makefile.in
-missing
-ppStac.pc
-test
-autom4te.cache
-Doxyfile
Index: anches/cnb_branches/cnb_branch_20090215/ppStack/src/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ppStack/src/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,10 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-*.lo
-*.la
-ppStack
-config.h
-config.h.in
-stamp-h1
Index: anches/cnb_branches/cnb_branch_20090215/ppStats/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ppStats/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,16 +1,0 @@
-Makefile
-Makefile.in
-aclocal.m4
-autom4te.cache
-compile
-config.log
-config.status
-configure
-depcomp
-install-sh
-missing
-config.guess
-config.sub
-libtool
-ltmain.sh
-ppStats.pc
Index: anches/cnb_branches/cnb_branch_20090215/ppStats/src/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ppStats/src/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-*.lo
-*.la
-ppStats
-ppStatsFromMetadata
-config.h
-config.h.in
-stamp-h1
Index: anches/cnb_branches/cnb_branch_20090215/ppSub/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ppSub/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,18 +1,0 @@
-Makefile
-Makefile.in
-aclocal.m4
-autom4te.cache
-compile
-config.log
-config.status
-configure
-depcomp
-install-sh
-missing
-config.guess
-libtool
-ltmain.sh
-stamp-h1
-config.sub
-test
-Doxyfile
Index: anches/cnb_branches/cnb_branch_20090215/ppSub/src/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ppSub/src/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-*.o
-*.lo
-.libs
-.deps
-Makefile
-Makefile.in
-ppSub
-config.h
-config.h.in
-stamp-h1
-ppSubKernel
Index: /branches/cnb_branches/cnb_branch_20090215/ppSub/src/ppSub.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ppSub/src/ppSub.c	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/ppSub/src/ppSub.c	(revision 23197)
@@ -6,6 +6,6 @@
  *
  *  @author IfA
- *  @version $Revision: 1.11.2.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2009-02-19 17:59:49 $
+ *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-02-18 00:31:20 $
  *  Copyright 2009 Institute for Astronomy, University of Hawaii
  */
Index: /branches/cnb_branches/cnb_branch_20090215/ppSub/src/ppSub.h
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ppSub/src/ppSub.h	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/ppSub/src/ppSub.h	(revision 23197)
@@ -6,11 +6,6 @@
  *
  *  @author IfA
-<<<<<<< .working
- *  @version $Revision: 1.6.2.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2009-02-19 17:59:49 $
-=======
  *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
  *  @date $Date: 2009-02-18 00:31:20 $
->>>>>>> .merge-right.r22214
  *  Copyright 2009 Institute for Astronomy, University of Hawaii
  */
Index: /branches/cnb_branches/cnb_branch_20090215/ppSub/src/ppSubArguments.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ppSub/src/ppSubArguments.c	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/ppSub/src/ppSubArguments.c	(revision 23197)
@@ -6,11 +6,6 @@
  *
  *  @author IfA
-<<<<<<< .working
- *  @version $Revision: 1.58.2.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2009-02-19 17:59:49 $
-=======
  *  @version $Revision: 1.59 $ $Name: not supported by cvs2svn $
  *  @date $Date: 2009-02-18 00:31:20 $
->>>>>>> .merge-right.r22214
  *  Copyright 2009 Institute for Astronomy, University of Hawaii
  */
@@ -196,5 +191,5 @@
 bool ppSubArgumentsSetup(int argc, char *argv[], pmConfig *config)
 {
-    int argnum;                         // Argument Number
+    //    int argnum;                         // Argument Number
     assert(config);
 
Index: /branches/cnb_branches/cnb_branch_20090215/ppSub/src/ppSubBackground.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ppSub/src/ppSubBackground.c	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/ppSub/src/ppSubBackground.c	(revision 23197)
@@ -6,6 +6,6 @@
  *
  *  @author IfA
- *  @version $Revision: 1.6.2.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2009-02-19 17:59:49 $
+ *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-02-18 00:31:20 $
  *  Copyright 2009 Institute for Astronomy, University of Hawaii
  */
Index: /branches/cnb_branches/cnb_branch_20090215/ppSub/src/ppSubDefineOutput.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ppSub/src/ppSubDefineOutput.c	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/ppSub/src/ppSubDefineOutput.c	(revision 23197)
@@ -6,6 +6,6 @@
  *
  *  @author IfA
- *  @version $Revision: 1.2.4.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2009-02-19 17:59:49 $
+ *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-02-18 00:31:20 $
  *  Copyright 2009 Institute for Astronomy, University of Hawaii
  */
Index: /branches/cnb_branches/cnb_branch_20090215/ppSub/src/ppSubMakePSF.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ppSub/src/ppSubMakePSF.c	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/ppSub/src/ppSubMakePSF.c	(revision 23197)
@@ -6,11 +6,6 @@
  *
  *  @author IfA
-<<<<<<< .working
- *  @version $Revision: 1.2.4.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2009-02-19 17:59:49 $
-=======
  *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
  *  @date $Date: 2009-02-18 00:31:20 $
->>>>>>> .merge-right.r22214
  *  Copyright 2009 Institute for Astronomy, University of Hawaii
  */
Index: /branches/cnb_branches/cnb_branch_20090215/ppSub/src/ppSubReadoutPhotometry.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ppSub/src/ppSubReadoutPhotometry.c	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/ppSub/src/ppSubReadoutPhotometry.c	(revision 23197)
@@ -6,11 +6,6 @@
  *
  *  @author IfA
-<<<<<<< .working
- *  @version $Revision: 1.3.4.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2009-02-19 17:59:49 $
-=======
  *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
  *  @date $Date: 2009-02-18 00:31:20 $
->>>>>>> .merge-right.r22214
  *  Copyright 2009 Institute for Astronomy, University of Hawaii
  */
Index: /branches/cnb_branches/cnb_branch_20090215/ppSub/src/ppSubReadoutSubtract.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ppSub/src/ppSubReadoutSubtract.c	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/ppSub/src/ppSubReadoutSubtract.c	(revision 23197)
@@ -88,5 +88,5 @@
     pmFPAfile *outFile = psMetadataLookupPtr(&mdok, config->files, "PPSUB.OUTPUT"); // Output file
     pmFPA *outFPA = outFile->fpa;       // Output FPA
-    if (!pmFPACopyConcepts(outFPA, inFPA)) {
+    if (!pmConceptsCopyFPA(outFPA, inFPA, true, true)) {
         psError(PS_ERR_UNKNOWN, false, "Unable to copy concepts from input to output.");
         psFree(outRO);
Index: anches/cnb_branches/cnb_branch_20090215/ppSub/test/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/ppSub/test/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,1 +1,0 @@
-*
Index: anches/cnb_branches/cnb_branch_20090215/psLib/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,35 +1,0 @@
-DoxygenLog
-Doxyfile
-ChangeLog
-bin
-lib
-include
-man
-include
-pslib.kdevelop.*
-docs
-Makefile.in
-aclocal.m4
-autom4te.cache
-configure
-Makefile
-config.log
-config.status
-libtool
-pslib-config
-pslib.pc
-pslib-*.tar.gz
-pslib-*.tar.bz2
-compile
-config.guess
-config.sub
-depcomp
-install-sh
-ltmain.sh
-missing
-pslib.kdevses
-.deps
-.libs
-*.bb
-*.bbg
-*.da
Index: anches/cnb_branches/cnb_branch_20090215/psLib/etc/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/etc/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,6 +1,0 @@
-Makefile
-Makefile.in
-*.bb
-*.bbg
-*.da
-pslib.config
Index: anches/cnb_branches/cnb_branch_20090215/psLib/m4/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/m4/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,7 +1,0 @@
-libtool.m4
-ltoptions.m4
-ltsugar.m4
-ltversion.m4
-lt~obsolete.m4
-Makefile
-Makefile.in
Index: anches/cnb_branches/cnb_branch_20090215/psLib/share/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/share/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,9 +1,0 @@
-Makefile
-Makefile.in
-.libs
-.deps
-psTime.config
-psTime.xml
-*.bb
-*.bbg
-*.da
Index: /branches/cnb_branches/cnb_branch_20090215/psLib/share/tai_utc.dat
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/share/tai_utc.dat	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psLib/share/tai_utc.dat	(revision 23197)
@@ -49,2 +49,4 @@
         2450630.5     31.0000000    41317.0     0.0000000
         2451179.5     32.0000000    41317.0     0.0000000
+	2453736.5     33.0000000    41317.0     0.0000000
+	2454832.5     34.0000000    41317.0     0.0000000
Index: /branches/cnb_branches/cnb_branch_20090215/psLib/share/tai_utc.raw
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/share/tai_utc.raw	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psLib/share/tai_utc.raw	(revision 23197)
@@ -35,2 +35,4 @@
  1997 JUL  1 =JD 2450630.5  TAI-UTC=  31.0       S + (MJD - 41317.) X 0.0      S
  1999 JAN  1 =JD 2451179.5  TAI-UTC=  32.0       S + (MJD - 41317.) X 0.0      S
+ 2006 JAN  1 =JD 2453736.5  TAI-UTC=  33.0       S + (MJD - 41317.) X 0.0      S
+ 2009 JAN  1 =JD 2454832.5  TAI-UTC=  34.0       S + (MJD - 41317.) X 0.0      S
Index: anches/cnb_branches/cnb_branch_20090215/psLib/src/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/src/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,14 +1,0 @@
-DoxygenLog
-Makefile.in
-.deps
-.libs
-Makefile
-config.h
-*.la
-*.lo
-stamp-h1
-libpslib.la.temp
-config.h.in
-*.bb
-*.bbg
-*.da
Index: anches/cnb_branches/cnb_branch_20090215/psLib/src/astro/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/src/astro/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,10 +1,0 @@
-.deps
-.libs
-Makefile
-Makefile.in
-*.la
-*.lo
-*.loT
-*.bb
-*.bbg
-*.da
Index: /branches/cnb_branches/cnb_branch_20090215/psLib/src/astro/psEarthOrientation.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/src/astro/psEarthOrientation.c	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psLib/src/astro/psEarthOrientation.c	(revision 23197)
@@ -767,5 +767,5 @@
     psTime *in = psTimeCopy(time);
     if (in->type != PS_TIME_UT1) {
-        in = psTimeConvert(in, PS_TIME_UT1);
+        psTimeConvert(in, PS_TIME_UT1);
     }
     //Check if tidal corrections should be included.
Index: /branches/cnb_branches/cnb_branch_20090215/psLib/src/astro/psTime.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/src/astro/psTime.c	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psLib/src/astro/psTime.c	(revision 23197)
@@ -9,13 +9,11 @@
  *
  *  @author Ross Harman, MHPCC
+ *  @author Paul Price, IfA
  *
- *  @version $Revision: 1.117 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-11-09 00:30:07 $
- *
- *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
+ *  Copyright 2004-2009 Institute for Astronomy, University of Hawaii
  */
 
 #ifdef HAVE_CONFIG_H
-# include "config.h"
+#include "config.h"
 #endif
 
@@ -39,85 +37,58 @@
 #include "psAssert.h"
 
-#define MAX_STRING_LENGTH 256
-
-/** Sidereal angular conversion from seconds to radians for GMST in seconds (i.e. pi/(180*240)) */
-#define S2R (7.272205216643039903848711535369e-5)
-
-/** Two times pi with double precision accuracy */
-#define TWOPI (2.0*M_PI)
-
-/** Conversion from radians to degrees */
-#define R2DEG = (180.0/M_PI)
-
-/** Maximum length of time string */
-#define MAX_TIME_STRING_LENGTH 256
-
-/** Seconds per minute */
-#define  SEC_PER_MINUTE 60.0
-
-/** Seconds per hour */
-#define  SEC_PER_HOUR (60.0*SEC_PER_MINUTE)
-
-/** Seconds per day */
-#define  SEC_PER_DAY (24.0*SEC_PER_HOUR)
-
-/** Seconds per year */
-#define  SEC_PER_YEAR (365.0*SEC_PER_DAY)
-
-/** Microseconds per day */
-#define NSEC_PER_DAY 86400000000000.0
-
-// Time config file path
-static char *timeConfig = NULL;
-
-/** Time metadata read from config file */
-static psMetadata *timeMetadata = NULL;
-
-// Offset to convert terrestrial time(TT) to international atomic time(TAI)
-#define  TAI_TT_OFFSET_SECONDS        32
-#define  TAI_TT_OFFSET_NANOSECONDS    184000000
-
-// Offset from converting to MJD
-#define  MJD_EPOCH_OFFSET             40587.0
-
-// Offset for converting to JD
-#define  JD_EPOCH_OFFSET              2440587.5
-
-// Offset of year 0000 from epoch
-#define YEAR_0000_SEC                 -62125920000
-
-// Offset of year 9999 from epoch
-#define YEAR_9999_SEC                 253202544000
+
+#define S2R (M_PI / (180.0 * 240.0))    /// Sidereal conversion: GMST in seconds to radians
+#define R2DEG = (180.0/M_PI)            /// Conversion from radians to degrees
+#define MAX_STRING_LENGTH 256           /// Maximum length of string
+#define MAX_TIME_STRING_LENGTH 30       /// Maximum length of time string: 1234-67-90T23:56:89.123456789
+#define SEC_PER_MINUTE 60.0             /// Seconds per minute
+#define SEC_PER_HOUR (60.0*SEC_PER_MINUTE) /// Seconds per hour
+#define SEC_PER_DAY (24.0*SEC_PER_HOUR) /// Seconds per day
+#define SEC_PER_YEAR (365.0*SEC_PER_DAY) /// Seconds per year
+#define NSEC_PER_DAY (SEC_PER_DAY * 1000000000.0) /// Nanoseconds per day
+
+#define MJD_EPOCH_OFFSET 40587.0        // Offset from converting to MJD
+#define JD_EPOCH_OFFSET 2440587.5       // Offset for converting to JD
+#define YEAR_0000_SEC -62125920000      // Offset of year 0000 from epoch
+#define YEAR_9999_SEC 253202544000      // Offset of year 9999 from epoch
+
+// Offset to convert terrestrial time (TT) to international atomic time (TAI)
+#define TAI_TT_OFFSET_SECONDS        32
+#define TAI_TT_OFFSET_NANOSECONDS    184000000
+
+
+// Static global variables
+static char *timeConfig = NULL;         // Time config file path
+static psMetadata *timeMetadata = NULL; // Time metadata read from config file
+static int isoDecimals = 6;             // Number of decimals to use in a string by psTimeToISO
+
 
 /** Static function prototypes */
 static char *cleanString(char *inString, int sLen);
 static char* getToken(char **inString, char *delimiter, psParseErrorType *status);
-static psTime* convertTimeTAIUTC(psTime* time);
-static psTime* convertTimeUTCTAI(psTime* time);
-static psTime* convertTimeTAITT(psTime* time);
-static psTime* convertTimeTTTAI(psTime* time);
-static psTime* convertTimeUTCUT1(psTime* time);
-
-static bool p_psTimeInit(const char *fileName);
+static bool convertTimeTAIUTC(psTime* time);
+static bool convertTimeUTCTAI(psTime* time);
+static bool convertTimeTAITT(psTime* time);
+static bool convertTimeTTTAI(psTime* time);
+static bool convertTimeUTCUT1(psTime* time);
+
+static bool timeInit(const char *fileName);
 
 /** Removes leading and trailing whitespace and # characters from a string. The cleaned string is a new null
  *  terminated copy of the original input string. */
-static char *cleanString(char *inString,
-                         int sLen)
-{
-    char *ptrB = NULL;
-    char *ptrE = NULL;
-    char *cleaned = NULL;
-
-    ptrB = inString;
+static char *cleanString(char *inString,// Input string
+                         int sLen       // Length of string
+                         )
+{
+    char *ptrB = inString;              // Pointer to start
 
     // Skip over leading # or whitespace
-    while (isspace(*ptrB) || *ptrB=='#') {
+    while (isspace(*ptrB) || *ptrB == '#') {
         ptrB++;
     }
 
     // Skip over trailing whitespace, null terminators, and # characters
-    ptrE = inString + sLen - 1;
-    while(isspace(*ptrE) || *ptrE=='\0' || *ptrE=='#') {
+    char *ptrE = inString + sLen - 1;   // Pointer to end
+    while (isspace(*ptrE) || *ptrE == '\0' || *ptrE == '#') {
         ptrE--;
     }
@@ -127,39 +98,31 @@
 
     // Adds '\0' to end of string and +1 to sLen
-    cleaned = psStringNCopy(ptrB, sLen);
-
-    return cleaned;
+    return psStringNCopy(ptrB, sLen);
 }
 
 /** Returns cleaned token based on delimiter, but not including delimiter. Also changes the pointer location
  * the beginning of the string. Tokens are newly allocated null terminated strings. */
-static char* getToken(char **inString,
-                      char *delimiter,
-                      psParseErrorType *status)
-{
-    char *cleanToken = NULL;
-    int sLen = 0;
-
+static char* getToken(char **inString,  // Input string
+                      char *delimiter,  // Delimiter
+                      psParseErrorType *status // Parsing status, returned
+                      )
+{
     // Skip over leading whitespace
-    while(isspace(**inString)) {
+    while (isspace(**inString)) {
         (*inString)++;
     }
 
-    // Length of token, not including delimiter
-    sLen = strcspn(*inString, delimiter);
-
-    if(sLen) {
-
+    int sLen = strcspn(*inString, delimiter); // Length of token, not including delimiter
+    char *cleanToken = NULL;            // Token, cleaned of delimiters
+    if (sLen) {
         // Create new, cleaned, and null terminated token
         cleanToken = cleanString(*inString, sLen);
 
         // Move to end of token
-        //        (*inString) += (sLen+1);
         (*inString) += sLen;
         if (**inString != '\0' ) {
             (*inString)++;
         }
-
-    } else if(**inString!='\0' && sLen==0) {
+    } else if (**inString != '\0' && sLen == 0) {
         *status = PS_PARSE_ERROR_GENERAL;
     }
@@ -210,5 +173,5 @@
 
     // Check if psTime tables are already loaded
-    if(!p_psTimeInit(p_psTimeConfigFilename(NULL))) {
+    if (!timeInit(p_psTimeConfigFilename(NULL))) {
         *status = PS_LOOKUP_ERROR;
         return NAN;
@@ -225,5 +188,5 @@
 
         // Check if table not a metadata item
-        if(tableMetadataItem == NULL) {
+        if (tableMetadataItem == NULL) {
             psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Failed find '%s' in time metadata."),
                     tableName);
@@ -239,10 +202,10 @@
 
         // Check if index within to/from range
-        if(index >= table->validFrom ) {
-            if(index <= table->validTo) {
+        if (index >= table->validFrom ) {
+            if (index <= table->validTo) {
                 // Attempt to interpolate table
                 result = psLookupTableInterpolate(table, index, column);
                 *status = PS_LOOKUP_SUCCESS;
-                if(!isnan(result)) {
+                if (!isnan(result)) {
                     break;
                 }
@@ -258,5 +221,5 @@
 }
 
-bool p_psTimeInit(const char *fileName)
+static bool timeInit(const char *fileName)
 {
     psS32 numLines = 0;
@@ -270,7 +233,4 @@
     char *tableName = NULL;
     char *tableFormat = NULL;
-    char *fullTableName = NULL;
-    psS32 i = 0;
-    psS32 j = 0;
     psS32 numTables = 0;
     psU32 nFail = 0;
@@ -283,18 +243,21 @@
     char metadataTableNames[4][MAX_STRING_LENGTH] = {"daily", "eopc",  "finals", "tai"};
 
-    // Check if the p_psTimeInit has already been ran
-    if (timeMetadata != NULL) {
+    // Check if the timeInit has already been run
+    if (timeMetadata) {
         return true;
     }
 
+    // All memory allocated below is "persistent"
     // XXX this is not thread safe as the persistence setting is global
-    const bool initialPersistence =
-        p_psMemAllocatePersistent(true); // All memory allocated below is "persistent"
+    const bool initialPersistence = p_psMemAllocatePersistent(true); // Initial setting of persistence
 
     // Read config file
     timeMetadata = psMetadataConfigRead(timeMetadata, &nFail, fileName, true);
-    if(timeMetadata == NULL) {
+    if (!timeMetadata) {
+        psError(PS_ERR_IO, false, "Unable to read time configuration file %s", fileName);
         return false;
-    } else if(nFail != 0) {
+    } else if (nFail != 0) {
+        psError(PS_ERR_IO, false, "Failed to parse %d lines reading time configuration file %s",
+                nFail, fileName);
         return false;
     }
@@ -302,5 +265,5 @@
     // Get number of tables
     metadataItem = psMetadataLookup(timeMetadata, "psLib.time.tables.n");
-    if(metadataItem == NULL) {
+    if (metadataItem == NULL) {
         p_psMemAllocatePersistent(initialPersistence);
         psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Failed find '%s' in time metadata."),
@@ -312,5 +275,5 @@
     // Get lower range of tables
     metadataItem = psMetadataLookup(timeMetadata, "psLib.time.tables.from");
-    if(metadataItem == NULL) {
+    if (metadataItem == NULL) {
         p_psMemAllocatePersistent(initialPersistence);
         psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Failed find '%s' in time metadata."),
@@ -319,5 +282,5 @@
     }
     tablesFrom = psVectorCopy(tablesFrom, metadataItem->data.V, PS_TYPE_F64);
-    if(tablesFrom->n != numTables) {
+    if (tablesFrom->n != numTables) {
         p_psMemAllocatePersistent(initialPersistence);
         psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Incorrect vector size. Size: %ld, Expected %d."), tablesFrom->n, numTables);
@@ -328,5 +291,5 @@
     // Get upper range of tables
     metadataItem = psMetadataLookup(timeMetadata, "psLib.time.tables.to");
-    if(metadataItem == NULL) {
+    if (metadataItem == NULL) {
         p_psMemAllocatePersistent(initialPersistence);
         psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Failed find '%s' in time metadata."),
@@ -336,5 +299,5 @@
     }
     tablesTo = psVectorCopy(tablesTo, metadataItem->data.V, PS_TYPE_F64);
-    if(tablesTo->n != numTables) {
+    if (tablesTo->n != numTables) {
         p_psMemAllocatePersistent(initialPersistence);
         psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Incorrect vector size. Size: %ld, Expected %d."), tablesTo->n, numTables);
@@ -346,5 +309,5 @@
     // Get index columns for the tables
     metadataItem = psMetadataLookup(timeMetadata, "psLib.time.tables.index");
-    if(metadataItem == NULL) {
+    if (metadataItem == NULL) {
         p_psMemAllocatePersistent(initialPersistence);
         psError(PS_ERR_BAD_PARAMETER_VALUE,true,_("Failed find '%s' in time metadata."),
@@ -355,5 +318,5 @@
     }
     tablesIndex = psVectorCopy(tablesIndex, metadataItem->data.V, PS_TYPE_S32);
-    if(tablesIndex->n != numTables) {
+    if (tablesIndex->n != numTables) {
         p_psMemAllocatePersistent(initialPersistence);
         psError(PS_ERR_BAD_PARAMETER_VALUE,true,_("Incorrect vector size. Size: %ld, Expected %d."),tablesIndex->n,numTables);
@@ -366,5 +329,5 @@
     // Get path to time data files
     metadataItem = psMetadataLookup(timeMetadata, "psLib.time.tables.dir");
-    if(metadataItem == NULL) {
+    if (metadataItem == NULL) {
         p_psMemAllocatePersistent(initialPersistence);
         psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Failed find '%s' in time metadata."),
@@ -379,5 +342,5 @@
     // Table file names
     metadataItem = psMetadataLookup(timeMetadata, "psLib.time.tables.files");
-    if(metadataItem == NULL) {
+    if (metadataItem == NULL) {
         p_psMemAllocatePersistent(initialPersistence);
         psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Failed find '%s' in time metadata."),
@@ -394,5 +357,5 @@
     // Get table format strings
     metadataItem = psMetadataLookup(timeMetadata, "psLib.time.tables.format");
-    if(metadataItem == NULL) {
+    if (metadataItem == NULL) {
         p_psMemAllocatePersistent(initialPersistence);
         psError(PS_ERR_BAD_PARAMETER_VALUE,true, _("Failed find '%s' in time metadata."),
@@ -411,20 +374,13 @@
     bool no_problem = true;  // True if we've detected no errors
     namesPtr = tableNames;
-    while((tableName=getToken(&namesPtr, " ", &status)) != NULL) {
-
-        // Form path with table name, adding one to length for last '/' that may not occur
-        // in string in cong file
-        fullTableName = (char*)psAlloc(strlen(tableDir)+strlen(tableName)+1+1);
-
-        // Old strings may come back from psAlloc(), so set initial position to EOL
-        fullTableName[0]='\0';
-        strcat(fullTableName, tableDir);
-        strcat(fullTableName, "/");
-        strcat(fullTableName, tableName);
+    int i;                              // Iterator
+    for (i = 0; (tableName = getToken(&namesPtr, " ", &status)) != NULL; i++) {
+        psString fullTableName = NULL;  // Full path for table
+        psStringAppend(&fullTableName, "%s/%s", tableDir, tableName);
 
         // Get table format
-        tableFormat = getToken(&formatPtr,",",&status);
-        if(tableFormat == NULL) {
-            psError(PS_ERR_BAD_PARAMETER_VALUE,no_problem,_("Failed find '%s' in time metadata."),
+        tableFormat = getToken(&formatPtr, ",", &status);
+        if (!tableFormat) {
+            psError(PS_ERR_BAD_PARAMETER_VALUE, no_problem, _("Failed find '%s' in time metadata."),
                     "psLib.time.tables.format");
             no_problem = false;
@@ -432,10 +388,10 @@
 
         // Create and read table
-        if(i < numTables) {
+        if (i < numTables) {
             table = psLookupTableAlloc(fullTableName, (const char*)tableFormat, tablesIndex->data.S32[i]);
             numLines = psLookupTableRead(table);
         } else {
             psError(PS_ERR_BAD_PARAMETER_VALUE, no_problem,
-                    _("Incorrect number of table files entered. Found: %d. Expected: %d."), i+1, numTables);
+                    _("Incorrect number of table files entered. Found: %d. Expected: %d."), i + 1, numTables);
             no_problem = false;
         }
@@ -443,11 +399,11 @@
         // Place tables into metadata slightly altered names as keys to create consistent naming conventions
         foundTable = false;
-        for(j=0; j<numTables; j++) {
+        for (int j = 0; j < numTables; j++) {
             metadataNamesPtr = strstr(tableName, metadataTableNames[j]);
-            if(metadataNamesPtr != NULL) {
+            if (metadataNamesPtr != NULL) {
                 psMetadataAdd(timeMetadata, PS_LIST_TAIL, strcat(metadataTableNames[j], "Table"),
                               PS_DATA_LOOKUPTABLE, NULL, table);
                 foundTable = true;
-            } else if(foundTable==false && j==numTables-1) {
+            } else if (foundTable == false && j == numTables - 1) {
                 psError(PS_ERR_BAD_PARAMETER_VALUE, no_problem,
                         _("Incorrect number of table files entered. Found: %d. Expected: %d."), j, numTables);
@@ -460,11 +416,12 @@
         psFree(tableFormat);
         psFree(table);
-        i++;
     }
 
     p_psMemAllocatePersistent(initialPersistence);
 
-    if(numTables != i) {
-        psError(PS_ERR_BAD_PARAMETER_VALUE, no_problem, _("Incorrect number of table files entered. Found: %d. Expected: %d."), i, numTables);
+    if (numTables != i) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, no_problem,
+                _("Incorrect number of table files entered. Found: %d. Expected: %d."),
+                i, numTables);
     }
 
@@ -481,5 +438,5 @@
 bool p_psTimeFinalize(void)
 {
-    if(timeMetadata != NULL) {
+    if (timeMetadata != NULL) {
         psFree(timeMetadata);
         timeMetadata = NULL;
@@ -496,18 +453,21 @@
 psTime* psTimeAlloc(psTimeType type)
 {
-    psTime *outTime = NULL;
-
     // Error checks
-    if(type!=PS_TIME_TAI && type!=PS_TIME_UTC && type!=PS_TIME_UT1 &&
-            type!=PS_TIME_TT) {
-        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
-                _("Specified type, %d, is not supported."),
-                type);
-        return NULL;
+    switch (type) {
+      case PS_TIME_TAI:
+      case PS_TIME_UTC:
+      case PS_TIME_UT1:
+      case PS_TIME_TT:
+        // No action
+        break;
+      default:
+        // Since we can never return NULL from an allocator
+        psAbort("Specified type, %d, is not supported.", type);
     }
 
     // Allocate memory for structure
-    outTime = (psTime*)psAlloc(sizeof(psTime));
+    psTime *outTime = psAlloc(sizeof(psTime));
     psMemSetDeallocator(outTime, (psFreeFunc)timeFree);
+
     // Initialize members
     outTime->sec = 0;
@@ -522,5 +482,5 @@
 bool psMemCheckTime(psPtr ptr)
 {
-    return ( psMemGetDeallocator(ptr) == (psFreeFunc)timeFree );
+    return (psMemGetDeallocator(ptr) == (psFreeFunc)timeFree);
 }
 
@@ -528,17 +488,6 @@
 psTime* psTimeGetNow(psTimeType type)
 {
-    struct timeval now;
-    psTime *time = NULL;
-
-    // Allocate psTime struct
-    time = psTimeAlloc(type);
-
-    // Verify time structure allocated
-    if(time == NULL) {
-        return NULL;
-    }
-
     // Get the system time
-    //    if (gettimeofday(&now, (struct timezone *)0) == -1) {
+    struct timeval now;                 // Current time
     if (gettimeofday(&now, 0) == -1) {
         psError(PS_ERR_OS_CALL_FAILED, true,
@@ -547,10 +496,13 @@
     }
 
+    // Allocate psTime struct
+    psTime *time = psTimeAlloc(type);   // Container for current time
+
     // Convert timeval time to psTime
     time->sec = now.tv_sec;
-    time->nsec = now.tv_usec*1000;
+    time->nsec = now.tv_usec * 1000;
 
     // Add most leapseconds to UTC time to get TAI time if necessary
-    if(type == PS_TIME_TAI) {
+    if (type == PS_TIME_TAI) {
         time->sec += p_psTimeGetTAIDelta(time);
     }
@@ -559,5 +511,5 @@
 }
 
-static psTime* convertTimeTAIUTC(psTime* time)
+static bool convertTimeTAIUTC(psTime* time)
 {
     psF64  deltaTAI     = 0.0;
@@ -575,5 +527,5 @@
 
     // Check for underflow in nsec
-    if(deltaNsec > time->nsec) {
+    if (deltaNsec > time->nsec) {
         // Borrow second
         time->nsec += 1e9;
@@ -585,5 +537,5 @@
 
     // Check for overflow in nsec
-    if(time->nsec >= 1e9) {
+    if (time->nsec >= 1e9) {
         time->nsec -= 1e9;
         time->sec++;
@@ -595,12 +547,12 @@
     // Check if leapsecond present in delta
     deltaUTC = p_psTimeGetTAIDelta(time);
-    if(fabs(deltaTAI-deltaUTC) >= 1.0) {
+    if (fabs(deltaTAI-deltaUTC) >= 1.0) {
         time->sec++;
     }
 
-    return time;
-}
-
-static psTime* convertTimeUTCTAI(psTime* time)
+    return true;
+}
+
+static bool convertTimeUTCTAI(psTime* time)
 {
     psF64  delta     = 0.0;
@@ -621,5 +573,5 @@
 
     // Check for overflow in nsec
-    if(time->nsec >= 1e9) {
+    if (time->nsec >= 1e9) {
         time->nsec -= 1e9;
         time->sec++;
@@ -629,10 +581,8 @@
     time->type = PS_TIME_TAI;
 
-    //XXX: Set leapseconds to TRUE
-    //    time->leapsecond = true;
-    return time;
-}
-
-static psTime* convertTimeTAITT(psTime* time)
+    return true;
+}
+
+static bool convertTimeTAITT(psTime* time)
 {
     // Add TT offset
@@ -641,5 +591,5 @@
 
     // Check for overflow in nsec
-    if(time->nsec >= 1e9) {
+    if (time->nsec >= 1e9) {
         time->nsec -= 1e9;
         time->sec++;
@@ -649,8 +599,8 @@
     time->type = PS_TIME_TT;
 
-    return time;
-}
-
-static psTime* convertTimeTTTAI(psTime* time)
+    return true;
+}
+
+static bool convertTimeTTTAI(psTime* time)
 {
     // Subtract TT offset
@@ -658,5 +608,5 @@
 
     // Check for nsec underflow
-    if(TAI_TT_OFFSET_NANOSECONDS > time->nsec) {
+    if (TAI_TT_OFFSET_NANOSECONDS > time->nsec) {
         // Borrow second
         time->sec--;
@@ -666,5 +616,5 @@
 
     // Check for overflow in nsec
-    if(time->nsec >= 1e9) {
+    if (time->nsec >= 1e9) {
         time->nsec -= 1e9;
         time->sec++;
@@ -674,8 +624,8 @@
     time->type = PS_TIME_TAI;
 
-    return time;
-}
-
-static psTime* convertTimeUTCUT1(psTime* time)
+    return true;
+}
+
+static bool convertTimeUTCUT1(psTime* time)
 {
     psS64   ut1utc  = 0;
@@ -685,8 +635,8 @@
 
     // Since UTC is within 0.9 sec of UT1 then nsec member is the member affected
-    if((ut1utc < 0) && (abs(ut1utc) > time->nsec)) {
+    if ((ut1utc < 0) && (abs(ut1utc) > time->nsec)) {
         // Borrow from sec
         time->sec--;
-        if(time->leapsecond) {
+        if (time->leapsecond) {
             time->leapsecond = false;
         } else {
@@ -699,8 +649,8 @@
 
     // Check for overflow in nsec
-    if(time->nsec >= 1e9) {
+    if (time->nsec >= 1e9) {
         time->nsec -= 1e9;
         time->sec++;
-        if(time->leapsecond) {
+        if (time->leapsecond) {
             time->leapsecond = false;
             time->sec--;
@@ -713,95 +663,74 @@
     time->type = PS_TIME_UT1;
 
-    return time;
-}
-
-psTime* psTimeConvert(psTime *time,
-                      psTimeType type)
+    return true;
+}
+
+bool psTimeConvert(psTime *time, psTimeType type)
 {
     // Error checks
-    PS_ASSERT_PTR_NON_NULL(time,NULL);
-    PS_ASSERT_INT_WITHIN_RANGE(time->nsec,0,(psU32)((1e9)-1), NULL);
-
-    // If the input type is UT1 then return time and generate error message
-    if(time->type == PS_TIME_UT1) {
-        psError(PS_ERR_BAD_PARAMETER_VALUE,true,"Cannot convert from UT1 time type");
-        return NULL;
-    }
-
-    // If the time to convert to is the same as psTime the return time
+    PS_ASSERT_PTR_NON_NULL(time, false);
+    PS_ASSERT_INT_WITHIN_RANGE(time->nsec, 0, (psU32)((1e9)-1), false);
+
+    if (time->type == PS_TIME_UT1) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Cannot convert from UT1 time type");
+        return false;
+    }
     if (time->type == type) {
-        return time;
-    }
-
-    // Convert from TAI to UTC, TT, UT1
-    if(time->type == PS_TIME_TAI) {
-        // Convert from TAI to UTC
-        if(type == PS_TIME_UTC) {
-            time = convertTimeTAIUTC(time);
-            // Convert from TAI to TT
-        } else if(type == PS_TIME_TT) {
-            time = convertTimeTAITT(time);
-            // Convert from TAI to UT1
-        } else if(type == PS_TIME_UT1) {
-            // Convert to UTC first
-            time = convertTimeTAIUTC(time);
-            // Convert UTC to UT1
-            time = convertTimeUTCUT1(time);
-            // Convert from TAI to unknown time type
-        } else {
+        // No action required
+        return true;
+    }
+
+    switch (time->type) {
+      case PS_TIME_TAI:
+        switch (type) {
+          case PS_TIME_UTC:
+            return convertTimeTAIUTC(time);
+          case PS_TIME_TT:
+            return convertTimeTAITT(time);
+          case PS_TIME_UT1:
+            convertTimeTAIUTC(time);
+            return convertTimeUTCUT1(time);
+          default:
+            psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Specified type, %d, is not supported."), type);
+            return false;
+        }
+        break;
+      case PS_TIME_TT:
+        switch (type) {
+          case PS_TIME_UTC:
+            convertTimeTTTAI(time);
+            return convertTimeTAIUTC(time);
+          case PS_TIME_TAI:
+            return convertTimeTTTAI(time);
+          case PS_TIME_UT1:
+            convertTimeTTTAI(time);
+            convertTimeTAIUTC(time);
+            return convertTimeUTCUT1(time);
+          default:
             psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Specified type, %d, is not supported."), type);
             return NULL;
         }
-        // Convert from TT to TAI, UTC, UT1
-    } else if(time->type == PS_TIME_TT) {
-        // Convert from TT to UTC
-        if(type == PS_TIME_UTC) {
-            // Convert to TAI time first
-            time = convertTimeTTTAI(time);
-            // Convert from TAI to UTC
-            time = convertTimeTAIUTC(time);
-            // Convert from TT to TAI
-        } else if(type == PS_TIME_TAI) {
-            time = convertTimeTTTAI(time);
-            // Convert from TT to UT1
-        } else if(type == PS_TIME_UT1) {
-            // Convert to UTC first
-            // Convert to TAI time first
-            time = convertTimeTTTAI(time);
-            // Convert from TAI to UTC
-            time = convertTimeTAIUTC(time);
-            // Convert from UTC to UT1
-            time = convertTimeUTCUT1(time);
-            // Convert from TT to unknown time type
-        } else {
+        break;
+      case PS_TIME_UTC:
+        switch (type) {
+          case PS_TIME_TAI:
+            return convertTimeUTCTAI(time);
+          case PS_TIME_TT:
+            convertTimeUTCTAI(time);
+            return convertTimeTAITT(time);
+          case PS_TIME_UT1:
+            return convertTimeUTCUT1(time);
+          default:
             psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Specified type, %d, is not supported."), type);
             return NULL;
         }
-        // Convert from UTC to TAI, TT, UT1
-    } else if(time->type == PS_TIME_UTC) {
-        // Convert UTC to TAI
-        if(type == PS_TIME_TAI) {
-            time = convertTimeUTCTAI(time);
-            // Convert UTC to TT
-        } else if(type == PS_TIME_TT) {
-            // Convert to TAI time first
-            time = convertTimeUTCTAI(time);
-            // Convert TAI to TT
-            time = convertTimeTAITT(time);
-            // Convert UTC to UT1
-        } else if(type == PS_TIME_UT1) {
-            time = convertTimeUTCUT1(time);
-            // Convert UTC to unknown time type
-        } else {
-            psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Specified type, %d, is not supported."), type);
-            return NULL;
-        }
-        // Convert unknown time type
-    } else {
+        break;
+      default:
         psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Specified type, %d, is not supported."), time->type);
         return NULL;
     }
 
-    return time;
+    psAbort("Should never reach here.");
+    return false;
 }
 
@@ -831,5 +760,5 @@
 
     // Verify input time is not in UT1 seconds
-    if(time->type == PS_TIME_UT1) {
+    if (time->type == PS_TIME_UT1) {
         psError(PS_ERR_BAD_PARAMETER_VALUE,true,_("Specified type, %d, is incorrect."),time->type);
         return NAN;
@@ -841,5 +770,5 @@
     tdtTime->nsec = time->nsec;
     tdtTime->leapsecond = time->leapsecond;
-    tdtTime = psTimeConvert(tdtTime,PS_TIME_TT);
+    psTimeConvert(tdtTime,PS_TIME_TT);
 
     // Determine time reference to UT1
@@ -848,5 +777,5 @@
     ut1Time->nsec = time->nsec;
     ut1Time->leapsecond = time->leapsecond;
-    ut1Time = psTimeConvert(ut1Time,PS_TIME_UT1);
+    psTimeConvert(ut1Time,PS_TIME_UT1);
 
     // Calculate UT1 as Julian Centuries since J2000.0
@@ -864,9 +793,9 @@
     // Calculate Greenwich Mean Sidereal Time (GMST) in radians.
     // Equation set up to minimize multiplications.
-    gmstRad = fracDays*TWOPI
-              + (const1+const2*tu+t*(const3+t*(const4+t*(const5+const6*t))))*S2R;
+    gmstRad = fracDays * 2 * M_PI +
+        (const1 + const2 * tu + t * (const3 + t * (const4 + t * (const5 + const6 * t)))) * S2R;
 
     // Place GMST between 0 and 2*pi
-    gmstRad = fmod(gmstRad, TWOPI);
+    gmstRad = fmod(gmstRad, 2 * M_PI);
 
     // Calculate Local Mean Sidereal Time (LMST) in radians
@@ -899,5 +828,5 @@
 
     // Check for invalid bulletin specified
-    if((bulletin != PS_IERS_A) && (bulletin != PS_IERS_B)) {
+    if ((bulletin != PS_IERS_A) && (bulletin != PS_IERS_B)) {
         psError(PS_ERR_BAD_PARAMETER_VALUE,true,"Invalid bulletin specified %d",bulletin);
         return NAN;
@@ -905,5 +834,5 @@
 
     // Check if psTime tables are already loaded
-    if(!p_psTimeInit(p_psTimeConfigFilename(NULL))) {
+    if (!timeInit(p_psTimeConfigFilename(NULL))) {
         psError(PS_ERR_UNKNOWN, true, "failed to init time tables.");
         return NAN;
@@ -911,5 +840,5 @@
 
     // Set lookup table column based on Bullentin
-    if(bulletin == PS_IERS_A) {
+    if (bulletin == PS_IERS_A) {
         tableColumn = 3;
     } else {
@@ -922,5 +851,5 @@
 
     // Value could not be found through table lookup and interpolation
-    if(status == PS_LOOKUP_PAST_TOP) {
+    if (status == PS_LOOKUP_PAST_TOP) {
 
         // Date too early for tables. Get default time delta value from metadata, and issue warning.
@@ -929,5 +858,5 @@
         // Lookup value from time metadata loaded from pslib.config
         tableMetadataItem = psMetadataLookup(timeMetadata, "psLib.time.before.dut");
-        if(tableMetadataItem == NULL) {
+        if (tableMetadataItem == NULL) {
             psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Failed find '%s' in time metadata."),
                     "psLib.time.before.dut");
@@ -936,5 +865,5 @@
         result = tableMetadataItem->data.F64;
 
-    } else if(status == PS_LOOKUP_PAST_BOTTOM) {
+    } else if (status == PS_LOOKUP_PAST_BOTTOM) {
         /* Date too late for tables. Issue warning and use following formulae for predicting
            ahead of the most recent available table entry.
@@ -949,5 +878,5 @@
         // Lookup values to calculate prediction
         tableMetadataItem = psMetadataLookup(timeMetadata, "psLib.time.predict.dut");
-        if(tableMetadataItem == NULL) {
+        if (tableMetadataItem == NULL) {
             psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Failed find '%s' in time metadata."),
                     "psLib.time.predict.dut");
@@ -958,9 +887,10 @@
 
         // Calculate predication of future UT1-UTC
-        t = 2000.0 + (mjd - 51544.03)/365.2422;
-        dut2ut1 = 0.022*sin(TWOPI*t) - 0.012*cos(TWOPI*t) - 0.006*sin(4.0*M_PI*t) + 0.007*cos(4.0*M_PI*t);
-        result = dut->data.F64[0] + dut->data.F64[1]*(mjd - dut->data.F64[2]) - dut2ut1;
-
-    } else if(status != PS_LOOKUP_SUCCESS) {
+        t = 2000.0 + (mjd - 51544.03) / 365.2422;
+        dut2ut1 = 0.022 * sin(2 * M_PI * t) - 0.012 * cos(2 * M_PI * t) -
+            0.006 * sin(4.0 * M_PI * t) + 0.007 * cos(4.0 * M_PI * t);
+        result = dut->data.F64[0] + dut->data.F64[1] * (mjd - dut->data.F64[2]) - dut2ut1;
+
+    } else if (status != PS_LOOKUP_SUCCESS) {
         psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Failed time table interpolation."));
         return NAN;
@@ -1044,5 +974,5 @@
     *out = *time;
     if (out->type != PS_TIME_UT1) {
-        out = psTimeConvert(out, PS_TIME_UT1);
+        psTimeConvert(out, PS_TIME_UT1);
     }
     //see if corrections include seconds or just nano-seconds
@@ -1086,5 +1016,5 @@
     PS_ASSERT_INT_WITHIN_RANGE(time->nsec,0,(psU32)((1e9)-1),NULL);
 
-    if(time->type != PS_TIME_TAI) {
+    if (time->type != PS_TIME_TAI) {
         psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Specified type, %d, is incorrect."), time->type);
         return NULL;
@@ -1092,5 +1022,5 @@
 
     // Check if psTime tables are already loaded
-    if(!p_psTimeInit(p_psTimeConfigFilename(NULL))) {
+    if (!timeInit(p_psTimeConfigFilename(NULL))) {
         psError(PS_ERR_UNKNOWN, true, "failed to init time tables.");
         return NULL;
@@ -1105,5 +1035,5 @@
 
     // Value could not be found through table lookup and interpolation
-    if(xStatus==PS_LOOKUP_PAST_TOP && yStatus==PS_LOOKUP_PAST_TOP) {
+    if (xStatus==PS_LOOKUP_PAST_TOP && yStatus==PS_LOOKUP_PAST_TOP) {
 
         // Date too earlier for tables. Get default polar coodinate values from metadata, and issue warning.
@@ -1117,5 +1047,5 @@
 
         tableMetadataItem = psMetadataLookup(timeMetadata, "psLib.time.before.xp");
-        if(tableMetadataItem == NULL) {
+        if (tableMetadataItem == NULL) {
             psError(PS_ERR_BAD_PARAMETER_VALUE, true,
                     _("Failed find '%s' in time metadata."), "psLib.time.before.xp");
@@ -1125,5 +1055,5 @@
 
         tableMetadataItem = psMetadataLookup(timeMetadata, "psLib.time.before.yp");
-        if(tableMetadataItem == NULL) {
+        if (tableMetadataItem == NULL) {
             psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Failed find '%s' in time metadata."), "psLib.time.before.yp");
             return NULL;
@@ -1131,5 +1061,5 @@
         y = tableMetadataItem->data.F64;
 
-    } else if(xStatus==PS_LOOKUP_PAST_BOTTOM && yStatus==PS_LOOKUP_PAST_BOTTOM) {
+    } else if (xStatus==PS_LOOKUP_PAST_BOTTOM && yStatus==PS_LOOKUP_PAST_BOTTOM) {
 
         /* Date too late for tables. Issue warning and use following formulae for predicting
@@ -1154,5 +1084,5 @@
         // Get predicted MJD
         tableMetadataItem = psMetadataLookup(timeMetadata, "psLib.time.predict.mjd");
-        if(tableMetadataItem == NULL) {
+        if (tableMetadataItem == NULL) {
             psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Failed find '%s' in time metadata."),
                     "psLib.time.predict.mjd");
@@ -1163,5 +1093,5 @@
         // Get xp
         tableMetadataItem = psMetadataLookup(timeMetadata, "psLib.time.predict.xp");
-        if(tableMetadataItem == NULL) {
+        if (tableMetadataItem == NULL) {
             psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Failed find '%s' in time metadata."), "psLib.time.predict.xp");
             return NULL;
@@ -1172,5 +1102,5 @@
         // Get yp
         tableMetadataItem = psMetadataLookup(timeMetadata, "psLib.time.predict.yp");
-        if(tableMetadataItem == NULL) {
+        if (tableMetadataItem == NULL) {
             psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Failed find '%s' in time metadata."), "psLib.time.predict.yp");
             return NULL;
@@ -1180,6 +1110,6 @@
 
         // Calculate "a" and "c" constants
-        a = TWOPI*(mjd - mjdPred)/365.25;
-        c = TWOPI*(mjd - mjdPred)/435.0;
+        a = 2 * M_PI * (mjd - mjdPred) / 365.25;
+        c = 2 * M_PI * (mjd - mjdPred) / 435.0;
 
         // Calculate x and y polar coordinates
@@ -1196,5 +1126,5 @@
             yp->data.F64[4]*sin(c);
 
-    } else if(xStatus!=PS_LOOKUP_SUCCESS || yStatus!=PS_LOOKUP_SUCCESS) {
+    } else if (xStatus!=PS_LOOKUP_SUCCESS || yStatus!=PS_LOOKUP_SUCCESS) {
         psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Failed time table interpolation."));
         return NULL;
@@ -1226,5 +1156,5 @@
 
     // Check if psTime tables are loaded/loadable
-    if (!p_psTimeInit(p_psTimeConfigFilename(NULL))) {
+    if (!timeInit(p_psTimeConfigFilename(NULL))) {
         psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Failed to open file %s."),
                 p_psTimeConfigFilename(NULL));
@@ -1234,5 +1164,5 @@
     // Get table from metadata
     tableMetadataItem = psMetadataLookup(timeMetadata, "taiTable");
-    if(tableMetadataItem == NULL) {
+    if (tableMetadataItem == NULL) {
         psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Failed find '%s' in time metadata."), "taiTable");
         return NAN;
@@ -1242,5 +1172,5 @@
 
     // Determine Julian and modified Julian dates used in table lookup and time delta calculation
-    if(time->sec < 0) {
+    if (time->sec < 0) {
         // psTime earlier than epoch
         jd = time->sec / SEC_PER_DAY - time->nsec / NSEC_PER_DAY + JD_EPOCH_OFFSET;
@@ -1253,5 +1183,5 @@
 
     // Set ceiling of the julian date to the last entry in the lookup table
-    if(table->validTo < jd) {
+    if (table->validTo < jd) {
         jd = table->validTo;
     }
@@ -1261,5 +1191,5 @@
 
     // Check for successful interpolation
-    if(results == NULL) {
+    if (results == NULL) {
         psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Failed time table interpolation."));
         return NAN;
@@ -1272,5 +1202,5 @@
 
     // If const3 not equal to zero solve for difference else floor of const1
-    if(fabs(const3-0.0) > FLT_EPSILON) {
+    if (fabs(const3-0.0) > FLT_EPSILON) {
         out = const1 + (mjd - const2) * const3;
     } else {
@@ -1306,5 +1236,5 @@
 
     // Verify time is UTC type
-    if(utc->type != PS_TIME_UTC) {
+    if (utc->type != PS_TIME_UTC) {
         psError(PS_ERR_BAD_PARAMETER_VALUE,true,_("Specified type, %d, is incorrect."),utc->type);
         return false;
@@ -1316,5 +1246,5 @@
 
     // Check the absolute difference between the two times for leapsecond
-    if(psTimeLeapSecondDelta(utc,prevUtc) >= 1.0) {
+    if (psTimeLeapSecondDelta(utc,prevUtc) >= 1.0) {
         returnValue = true;
     } else {
@@ -1330,18 +1260,14 @@
 double psTimeToJD(const psTime *time)
 {
-    psF64 jd = NAN;
-
     // Error checks
     PS_ASSERT_PTR_NON_NULL(time,NAN);
     PS_ASSERT_INT_WITHIN_RANGE(time->nsec,0,(psU32)((1e9)-1),NAN);
 
+    // ADD says that this formula works only for PS_TIME_TAI, so adding the following:
     psTime *time2 = psTimeCopy(time);
-    //XXX: ADD says that this formula works only for PS_TIME_TAI, so adding the following:
-    if (time->type == PS_TIME_UTC || time->type == PS_TIME_TT) {
-        time2 = psTimeConvert(time2, PS_TIME_TAI);
-    }
-
-    // Julian date conversion
-    if(time2->sec < 0) {
+    psTimeConvert(time2, PS_TIME_TAI);
+
+    double jd;                          // Julian date, to return
+    if (time2->sec < 0) {
         // psTime earlier than epoch
         jd = time2->sec / SEC_PER_DAY - time2->nsec / NSEC_PER_DAY + JD_EPOCH_OFFSET;
@@ -1350,6 +1276,6 @@
         jd = time2->sec / SEC_PER_DAY + time2->nsec / NSEC_PER_DAY + JD_EPOCH_OFFSET;
     }
-
     psFree(time2);
+
     return jd;
 }
@@ -1357,17 +1283,14 @@
 double psTimeToMJD(const psTime *time)
 {
-    psF64 mjd = NAN;
-
     // Error checks
     PS_ASSERT_PTR_NON_NULL(time,NAN);
     PS_ASSERT_INT_WITHIN_RANGE(time->nsec,0,(psU32)((1e9)-1),NAN);
+
+    // ADD says that this formula works only for PS_TIME_TAI, so adding the following:
     psTime *time2 = psTimeCopy(time);
-    //XXX: ADD says that this formula works only for PS_TIME_TAI, so adding the following:
-    if (time->type == PS_TIME_UTC || time->type == PS_TIME_TT) {
-        time2 = psTimeConvert(time2, PS_TIME_TAI);
-    }
-
-    // Modified Julian date conversion
-    if(time2->sec < 0) {
+    psTimeConvert(time2, PS_TIME_TAI);
+
+    double mjd;                         // Modified Julian Date, to return
+    if (time2->sec < 0) {
         // psTime earlier than epoch
         mjd = time2->sec / SEC_PER_DAY - time2->nsec / NSEC_PER_DAY + MJD_EPOCH_OFFSET;
@@ -1377,37 +1300,29 @@
     }
     psFree(time2);
+
     return mjd;
 }
 
-psString psTimeToISO(const psTime *time)
-{
-    psS32 ds = 0;
-    char *timeString = NULL;
-    char *tempString = NULL;
-
+
+// Format a time as a string, allowing for a specified number of decimals for the seconds field
+static psString timeToString(const psTime *time, // Time to format as string
+                             int decimals // Number of decimals to permit for seconds
+                             )
+{
     // Error checks
-    PS_ASSERT_PTR_NON_NULL(time,NULL);
-    PS_ASSERT_INT_WITHIN_RANGE(time->nsec,0,(psU32)((1e9)-1),NULL);
-
-    // Check valid year range
-    if ((time->sec) < ((psS64)YEAR_0000_SEC) || (time->sec) > ((psS64)YEAR_9999_SEC)) {
-      psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Error: %s, %" PRId64 ", is out of range.  Must be between %" PRId64 " and %" PRId64 ".", "time->sec", time->sec, ((psS64)YEAR_0000_SEC), ((psS64)YEAR_9999_SEC));
-      return NULL;
-    }
-
-    PS_ASSERT_S64_WITHIN_RANGE(time->sec, (psS64)YEAR_0000_SEC, (psS64)YEAR_9999_SEC, NULL);
-
-    // Allocate temp strings
-    tempString = psAlloc(MAX_TIME_STRING_LENGTH);
-    timeString = psAlloc(MAX_TIME_STRING_LENGTH);
-
-    // Convert nanoseconds to decaseconds
-    ds = time->nsec / 100000000;
-
-    // tmTime variable is statically allocated, no need to free
-    struct tm *tmTime = psTimeToTM(time);
-
-    // Converts psTime to YYYY-MM-DDThh:mm:ss.sss in string form
-    if (!strftime(tempString, MAX_TIME_STRING_LENGTH, "%Y-%m-%dT%H:%M:%S", tmTime)) {
+    PS_ASSERT_PTR_NON_NULL(time, NULL);
+    PS_ASSERT_INT_WITHIN_RANGE(time->nsec, 0, (psU32)((1e9)-1), NULL);
+    if (time->sec < YEAR_0000_SEC || time->sec > YEAR_9999_SEC) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+                "Time (%" PRId64 " sec) is not between year 0000 or 9999.\n", time->sec);
+        return NULL;
+    }
+    PS_ASSERT_INT_WITHIN_RANGE(decimals, 0, 9, NULL);
+
+    struct tm *tmTime = psTimeToTM(time); // Unix time structure
+
+    // Convert psTime to YYYY-MM-DDThh:mm:ss in string form
+    psString string = psStringAlloc(MAX_TIME_STRING_LENGTH); // Time string
+    if (!strftime(string, MAX_TIME_STRING_LENGTH, "%Y-%m-%dT%H:%M:%S", tmTime)) {
         psError(PS_ERR_OS_CALL_FAILED, true, _("Failed to convert a time via strftime function."));
         return NULL;
@@ -1416,18 +1331,43 @@
 
     // Check if time is UTC and leapsecond
-    if(((time->type==PS_TIME_UTC)||(time->type==PS_TIME_UT1)) && (time->leapsecond)) {
+    if ((time->type == PS_TIME_UTC || time->type == PS_TIME_UT1) && time->leapsecond) {
         // Modify second to be 60
-        tempString[17] = '6';
-        tempString[18] = '0';
-    }
-
-    // Create string with milliseconds
-    if (snprintf(timeString, MAX_TIME_STRING_LENGTH, "%s.%1d", tempString, ds) < 0) {
-        psError(PS_ERR_OS_CALL_FAILED, true, _("Failed to append millisecond to time string with snprintf function."));
-        return NULL;
-    }
-    psFree(tempString);
-
-    return timeString;
+        string[17] = '6';
+        string[18] = '0';
+    }
+
+    // Add in the nanoseconds
+    if (decimals > 0) {
+        int partial = round((double)time->nsec / pow(10.0, 9 - decimals)); // Partial part
+        psString format = NULL;             // Format for printing partial part
+        psStringAppend(&format, ".%%0%dd", decimals);
+        psStringAppend(&string, format, partial);
+        psFree(format);
+    }
+
+    return string;
+}
+
+psString psTimeToString(const psTime *time, int decimals)
+{
+    return timeToString(time, decimals);
+}
+
+
+int psTimeSetISODecimals(int num)
+{
+    int temp = isoDecimals;          // Current value, to return
+    isoDecimals = num;
+    return temp;
+}
+
+int psTimeGetISODecimals(void)
+{
+    return isoDecimals;
+}
+
+psString psTimeToISO(const psTime *time)
+{
+    return timeToString(time, isoDecimals);
 }
 
@@ -1487,5 +1427,5 @@
     days = jd - 2440587.5;
     seconds = days * SEC_PER_DAY;
-    if(seconds < 0.0) {
+    if (seconds < 0.0) {
         outTime->nsec = (seconds - (psS64)seconds) * -1000000000.0;  // psTime earlier than epoch
     } else {
@@ -1513,5 +1453,5 @@
     seconds = days * SEC_PER_DAY;
 
-    if(seconds < 0.0) {
+    if (seconds < 0.0) {
         outTime->nsec = (seconds - (psS64)seconds) * -1000000000.0;  // psTime earlier than epoch
     } else {
@@ -1701,5 +1641,5 @@
 
     // Make month in range 3..14 (treat Jan & Feb as months 13..14 of prev year)
-    if( month <= 2 )
+    if ( month <= 2 )
     {
         temp = (14 - month) / 12;
@@ -1707,5 +1647,5 @@
         year -= temp;
         month += 12 * temp;
-    } else if(month > 14)
+    } else if (month > 14)
     {
         temp = (month - 3) / 12;
@@ -1775,5 +1715,5 @@
     }
 
-    time->nsec += fractionalSeconds * 1e9;
+    time->nsec += fractionalSeconds * 1.0e9L;
     return time;
 }
@@ -1812,9 +1752,9 @@
 
     // Convert time to TAI if necessary, but without changing input arguments
-    if(time->type == PS_TIME_UTC) {
+    if (time->type == PS_TIME_UTC) {
         tempTime = psTimeAlloc(PS_TIME_UTC);
         tempTime->sec = time->sec;
         tempTime->nsec = time->nsec;
-        tempTime = psTimeConvert(tempTime, PS_TIME_TAI);
+        psTimeConvert(tempTime, PS_TIME_TAI);
         outTime = psTimeAlloc(PS_TIME_TAI);
     } else {
@@ -1833,6 +1773,6 @@
 
     // Convert result to same time type as input
-    if(time->type == PS_TIME_UTC) {
-        outTime = psTimeConvert(outTime, PS_TIME_UTC);
+    if (time->type == PS_TIME_UTC) {
+        psTimeConvert(outTime, PS_TIME_UTC);
     }
 
@@ -1858,5 +1798,5 @@
 
     // Verify both times of the same type
-    if(time1->type != time2->type) {
+    if (time1->type != time2->type) {
         psError(PS_ERR_BAD_PARAMETER_VALUE,true,_("Specified type, %d, is incorrect."),time1->type);
         return NAN;
@@ -1864,17 +1804,17 @@
 
     // Convert time to TAI if necessary, but without changing input arguments
-    if(time1->type == PS_TIME_UTC) {
+    if (time1->type == PS_TIME_UTC) {
         tempTime1 = psTimeAlloc(PS_TIME_UTC);
         tempTime1->sec = time1->sec;
         tempTime1->nsec = time1->nsec;
-        tempTime1 = psTimeConvert(tempTime1, PS_TIME_TAI);
+        psTimeConvert(tempTime1, PS_TIME_TAI);
     } else {
         tempTime1 = psMemIncrRefCounter((psTime*)time1);
     }
-    if(time2->type == PS_TIME_UTC) {
+    if (time2->type == PS_TIME_UTC) {
         tempTime2 = psTimeAlloc(PS_TIME_UTC);
         tempTime2->sec = time2->sec;
         tempTime2->nsec = time2->nsec;
-        tempTime2 = psTimeConvert(tempTime2, PS_TIME_TAI);
+        psTimeConvert(tempTime2, PS_TIME_TAI);
     } else {
         tempTime2 = psMemIncrRefCounter((psTime*)time2);
Index: /branches/cnb_branches/cnb_branch_20090215/psLib/src/astro/psTime.h
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/src/astro/psTime.h	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psLib/src/astro/psTime.h	(revision 23197)
@@ -135,9 +135,9 @@
 /** Convert psTime to UTC, TAI, UT1, or TT time.
  *
- *  Converts psTime to UTC, TAI, UT1, or TT time based on the psTimeType argument.
- *
- *  @return psTime*:    Pointer to psTime.
- */
-psTime* psTimeConvert(
+ *  Converts psTime in-place to UTC, TAI, UT1, or TT time based on the psTimeType argument.
+ *
+ *  @return bool: Successful conversion?
+ */
+bool psTimeConvert(
     psTime *time,                      ///< Time to be converted.
     psTimeType type                    ///< Type to be converted to.
@@ -241,5 +241,5 @@
 /** Convert psTime to ISO8601 formatted string.
  *
- *  Converts psTime to a null terminated string in the form of YYYY-MM-DDThh:mm:ss.sss.
+ *  Converts psTime to a null terminated string in the form of YYYY-MM-DDThh:mm:ss.ssssss
  *  This function does not add or subtract leapseconds.
  *
@@ -249,4 +249,32 @@
     const psTime* time                  ///< Input time to be converted.
 );
+
+/** Set number of decimals printed by psTimeToISO
+ *
+ * @return int: Previous setting
+ */
+int psTimeSetISODecimals(
+    int num                             ///< Number of decimals to print
+    );
+
+/** Get number of decimals printed by psTimeToISO
+ *
+ * @return int: Current setting
+ */
+int psTimeGetISODecimals(void);
+
+/** Convert psTime to ISO8601 formatted string with limited decimal places
+ *
+ *  Converts psTime to a null terminated string in the form of YYYY-MM-DDThh:mm:ss.s, with as
+ *  many decimal places as specified.
+ *  This function does not add or subtract leapseconds.
+ *
+ *  @return psString:     Pointer null terminated array of chars in ISO time.
+ */
+psString psTimeToString(
+    const psTime *time,                 ///< Input time to be converted
+    int decimals                        ///< Number of decimals to use
+    );
+
 
 /** Convert psTime to struct tm time.
@@ -474,6 +502,10 @@
 );
 
-// used by p_psEOCInit()
-const char *p_psTimeConfigFilename(const char *filename);
+/// Return the name of the configuration file used for time
+///
+/// The name is derived first from the environment variable PS_CONFIG_FILE if set; next from a previously used
+/// configuration file if available; finally from the default which is set at install time.
+const char *p_psTimeConfigFilename(const char *filename // Filename to use, or NULL
+    );
 
 /// @}
Index: anches/cnb_branches/cnb_branch_20090215/psLib/src/db/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/src/db/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,10 +1,0 @@
-.deps
-.libs
-Makefile
-Makefile.in
-*.la
-*.lo
-*.loT
-*.bb
-*.bbg
-*.da
Index: /branches/cnb_branches/cnb_branch_20090215/psLib/src/db/psDB.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/src/db/psDB.c	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psLib/src/db/psDB.c	(revision 23197)
@@ -866,5 +866,5 @@
                             const psArray *rowSet,
                             const char *query
-    )                            
+    )
 {
     PS_ASSERT_PTR_NON_NULL(dbh, -1);
@@ -1040,175 +1040,175 @@
 
       for (i = 0; i < fieldCount; i++) {
-	// lookup MySQL column type
-	pType = psDBMySQLToPType(field[i].type, field[i].flags);
-	if (!pType) {
-	  psError(PS_ERR_UNKNOWN, false, "Failed to lookup type.");
-	  psFree(md);
-	  mysql_free_result(result);
-	  psFree(resultSet);
-	  return NULL;
-	}
-
-	len = fieldLength[i];
-	if (len) {
-	  // copy the data out of the result set struct
-	  data = psAlloc(len + 1);
-	  memcpy(data, row[i], len);
-	  ((char*)data)[len] = '\0';
-	} else {
-	  // if len is zero then the value is NULL
-	  psTrace("psLib.db", PS_LOG_INFO, "database field name %s contains a NULL", field[i].name);
-	  data = psDBGetPTypeNaN(pType);
-
-	  // the NULL case must be handled for each type differently
-	  switch (pType) {
-	    case PS_DATA_STRING:
-	      if (!psMetadataAddStr(md, PS_LIST_TAIL, field[i].name, 0, "", data)) {
-		psError(PS_ERR_UNKNOWN, false, "Failed to add item %s", field[i].name);
-		psFree(data);
-		psFree(md);
-		mysql_free_result(result);
-		psFree(resultSet);
-		return NULL;
-	      }
-	      break;
-	    case PS_DATA_U8:
-	      if (!psMetadataAddU8(md, PS_LIST_TAIL, field[i].name, 0, "",*(psU8 *)data)) {
-		psError(PS_ERR_UNKNOWN, false, "Failed to add item %s", field[i].name);
-		psFree(data);
-		psFree(md);
-		mysql_free_result(result);
-		psFree(resultSet);
-		return NULL;
-	      }
-	      break;
-	    case PS_DATA_U16:
-	      if (!psMetadataAddU16(md, PS_LIST_TAIL, field[i].name, 0, "",*(psU16 *)data)) {
-		psError(PS_ERR_UNKNOWN, false, "Failed to add item %s", field[i].name);
-		psFree(data);
-		psFree(md);
-		mysql_free_result(result);
-		psFree(resultSet);
-		return NULL;
-	      }
-	      break;
-	    case PS_DATA_U32:
-	      if (!psMetadataAddU32(md, PS_LIST_TAIL, field[i].name, 0, "",*(psU32 *)data)) {
-		psError(PS_ERR_UNKNOWN, false, "Failed to add item %s", field[i].name);
-		psFree(data);
-		psFree(md);
-		mysql_free_result(result);
-		psFree(resultSet);
-		return NULL;
-	      }
-	      break;
-	    case PS_DATA_U64:
-	      if (!psMetadataAddU64(md, PS_LIST_TAIL, field[i].name, 0, "",*(psU64 *)data)) {
-		psError(PS_ERR_UNKNOWN, false, "Failed to add item %s", field[i].name);
-		psFree(data);
-		psFree(md);
-		mysql_free_result(result);
-		psFree(resultSet);
-		return NULL;
-	      }
-	      break;
-	    case PS_DATA_S8:
-	      if (!psMetadataAddS8(md, PS_LIST_TAIL, field[i].name, 0, "", *(psS8 *)data)) {
-		psError(PS_ERR_UNKNOWN, false, "Failed to add item %s", field[i].name);
-		psFree(data);
-		psFree(md);
-		mysql_free_result(result);
-		psFree(resultSet);
-		return NULL;
-	      }
-	      break;
-	    case PS_DATA_S16:
-	      if (!psMetadataAddS16(md, PS_LIST_TAIL, field[i].name, 0, "", *(psS16 *)data)) {
-		psError(PS_ERR_UNKNOWN, false, "Failed to add item %s", field[i].name);
-		psFree(data);
-		psFree(md);
-		mysql_free_result(result);
-		psFree(resultSet);
-		return NULL;
-	      }
-	      break;
-	    case PS_DATA_S32:
-	      if (!psMetadataAddS32(md, PS_LIST_TAIL, field[i].name, 0, "", *(psS32 *)data)) {
-		psError(PS_ERR_UNKNOWN, false, "Failed to add item %s", field[i].name);
-		psFree(data);
-		psFree(md);
-		mysql_free_result(result);
-		psFree(resultSet);
-		return NULL;
-	      }
-	      break;
-	    case PS_DATA_S64:
-	      if (!psMetadataAddS64(md, PS_LIST_TAIL, field[i].name, 0, "", *(psS64 *)data)) {
-		psError(PS_ERR_UNKNOWN, false, "Failed to add item %s", field[i].name);
-		psFree(data);
-		psFree(md);
-		mysql_free_result(result);
-		psFree(resultSet);
-		return NULL;
-	      }
-	      break;
-	    case PS_DATA_F32:
-	      if (!psMetadataAddF32(md, PS_LIST_TAIL, field[i].name, 0, "", *(psF32 *)data)) {
-		psError(PS_ERR_UNKNOWN, false, "Failed to add item %s", field[i].name);
-		psFree(data);
-		psFree(md);
-		mysql_free_result(result);
-		psFree(resultSet);
-		return NULL;
-	      }
-	      break;
-	    case PS_DATA_F64:
-	      if (!psMetadataAddF64(md, PS_LIST_TAIL, field[i].name, 0, "", *(psF64 *)data)) {
-		psError(PS_ERR_UNKNOWN, false, "Failed to add item %s", field[i].name);
-		psFree(data);
-		psFree(md);
-		mysql_free_result(result);
-		psFree(resultSet);
-		return NULL;
-	      }
-	      break;
-	    case PS_DATA_BOOL:
-	      if (!psMetadataAddBool(md, PS_LIST_TAIL, field[i].name, 0, "", *(bool *)data)) {
-		psError(PS_ERR_UNKNOWN, false, "Failed to add item %s", field[i].name);
-		psFree(data);
-		psFree(md);
-		mysql_free_result(result);
-		psFree(resultSet);
-		return NULL;
-	      }
-	      break;
-	    case PS_DATA_TIME:
-	      // just pass NULL values through as there is currently no
-	      // concept of a psTime with a NULL value
-	      if (!psMetadataAddTime(md, PS_LIST_TAIL, field[i].name, 0, "", NULL)) {
-		psError(PS_ERR_UNKNOWN, false, "Failed to add item %s", field[i].name);
-		psFree(data);
-		psFree(md);
-		mysql_free_result(result);
-		psFree(resultSet);
-		return NULL;
-	      }
-	      break;
-
-	    default:
-	      // just pass NULL values for all other types
-	      if (!psMetadataAddUnknown(md, PS_LIST_TAIL, field[i].name, 0, "", NULL)) {
-		psError(PS_ERR_UNKNOWN, false, "Failed to add item %s", field[i].name);
-		psFree(data);
-		psFree(md);
-		mysql_free_result(result);
-		psFree(resultSet);
-		return NULL;
-	      }
-	      break;
-	  }
-	  psFree(data);
-	  continue;
-	}
+        // lookup MySQL column type
+        pType = psDBMySQLToPType(field[i].type, field[i].flags);
+        if (!pType) {
+          psError(PS_ERR_UNKNOWN, false, "Failed to lookup type.");
+          psFree(md);
+          mysql_free_result(result);
+          psFree(resultSet);
+          return NULL;
+        }
+
+        len = fieldLength[i];
+        if (len) {
+          // copy the data out of the result set struct
+          data = psAlloc(len + 1);
+          memcpy(data, row[i], len);
+          ((char*)data)[len] = '\0';
+        } else {
+          // if len is zero then the value is NULL
+          psTrace("psLib.db", PS_LOG_INFO, "database field name %s contains a NULL", field[i].name);
+          data = psDBGetPTypeNaN(pType);
+
+          // the NULL case must be handled for each type differently
+          switch (pType) {
+            case PS_DATA_STRING:
+              if (!psMetadataAddStr(md, PS_LIST_TAIL, field[i].name, 0, "", data)) {
+                psError(PS_ERR_UNKNOWN, false, "Failed to add item %s", field[i].name);
+                psFree(data);
+                psFree(md);
+                mysql_free_result(result);
+                psFree(resultSet);
+                return NULL;
+              }
+              break;
+            case PS_DATA_U8:
+              if (!psMetadataAddU8(md, PS_LIST_TAIL, field[i].name, 0, "",*(psU8 *)data)) {
+                psError(PS_ERR_UNKNOWN, false, "Failed to add item %s", field[i].name);
+                psFree(data);
+                psFree(md);
+                mysql_free_result(result);
+                psFree(resultSet);
+                return NULL;
+              }
+              break;
+            case PS_DATA_U16:
+              if (!psMetadataAddU16(md, PS_LIST_TAIL, field[i].name, 0, "",*(psU16 *)data)) {
+                psError(PS_ERR_UNKNOWN, false, "Failed to add item %s", field[i].name);
+                psFree(data);
+                psFree(md);
+                mysql_free_result(result);
+                psFree(resultSet);
+                return NULL;
+              }
+              break;
+            case PS_DATA_U32:
+              if (!psMetadataAddU32(md, PS_LIST_TAIL, field[i].name, 0, "",*(psU32 *)data)) {
+                psError(PS_ERR_UNKNOWN, false, "Failed to add item %s", field[i].name);
+                psFree(data);
+                psFree(md);
+                mysql_free_result(result);
+                psFree(resultSet);
+                return NULL;
+              }
+              break;
+            case PS_DATA_U64:
+              if (!psMetadataAddU64(md, PS_LIST_TAIL, field[i].name, 0, "",*(psU64 *)data)) {
+                psError(PS_ERR_UNKNOWN, false, "Failed to add item %s", field[i].name);
+                psFree(data);
+                psFree(md);
+                mysql_free_result(result);
+                psFree(resultSet);
+                return NULL;
+              }
+              break;
+            case PS_DATA_S8:
+              if (!psMetadataAddS8(md, PS_LIST_TAIL, field[i].name, 0, "", *(psS8 *)data)) {
+                psError(PS_ERR_UNKNOWN, false, "Failed to add item %s", field[i].name);
+                psFree(data);
+                psFree(md);
+                mysql_free_result(result);
+                psFree(resultSet);
+                return NULL;
+              }
+              break;
+            case PS_DATA_S16:
+              if (!psMetadataAddS16(md, PS_LIST_TAIL, field[i].name, 0, "", *(psS16 *)data)) {
+                psError(PS_ERR_UNKNOWN, false, "Failed to add item %s", field[i].name);
+                psFree(data);
+                psFree(md);
+                mysql_free_result(result);
+                psFree(resultSet);
+                return NULL;
+              }
+              break;
+            case PS_DATA_S32:
+              if (!psMetadataAddS32(md, PS_LIST_TAIL, field[i].name, 0, "", *(psS32 *)data)) {
+                psError(PS_ERR_UNKNOWN, false, "Failed to add item %s", field[i].name);
+                psFree(data);
+                psFree(md);
+                mysql_free_result(result);
+                psFree(resultSet);
+                return NULL;
+              }
+              break;
+            case PS_DATA_S64:
+              if (!psMetadataAddS64(md, PS_LIST_TAIL, field[i].name, 0, "", *(psS64 *)data)) {
+                psError(PS_ERR_UNKNOWN, false, "Failed to add item %s", field[i].name);
+                psFree(data);
+                psFree(md);
+                mysql_free_result(result);
+                psFree(resultSet);
+                return NULL;
+              }
+              break;
+            case PS_DATA_F32:
+              if (!psMetadataAddF32(md, PS_LIST_TAIL, field[i].name, 0, "", *(psF32 *)data)) {
+                psError(PS_ERR_UNKNOWN, false, "Failed to add item %s", field[i].name);
+                psFree(data);
+                psFree(md);
+                mysql_free_result(result);
+                psFree(resultSet);
+                return NULL;
+              }
+              break;
+            case PS_DATA_F64:
+              if (!psMetadataAddF64(md, PS_LIST_TAIL, field[i].name, 0, "", *(psF64 *)data)) {
+                psError(PS_ERR_UNKNOWN, false, "Failed to add item %s", field[i].name);
+                psFree(data);
+                psFree(md);
+                mysql_free_result(result);
+                psFree(resultSet);
+                return NULL;
+              }
+              break;
+            case PS_DATA_BOOL:
+              if (!psMetadataAddBool(md, PS_LIST_TAIL, field[i].name, 0, "", *(bool *)data)) {
+                psError(PS_ERR_UNKNOWN, false, "Failed to add item %s", field[i].name);
+                psFree(data);
+                psFree(md);
+                mysql_free_result(result);
+                psFree(resultSet);
+                return NULL;
+              }
+              break;
+            case PS_DATA_TIME:
+              // just pass NULL values through as there is currently no
+              // concept of a psTime with a NULL value
+              if (!psMetadataAddTime(md, PS_LIST_TAIL, field[i].name, 0, "", NULL)) {
+                psError(PS_ERR_UNKNOWN, false, "Failed to add item %s", field[i].name);
+                psFree(data);
+                psFree(md);
+                mysql_free_result(result);
+                psFree(resultSet);
+                return NULL;
+              }
+              break;
+
+            default:
+              // just pass NULL values for all other types
+              if (!psMetadataAddUnknown(md, PS_LIST_TAIL, field[i].name, 0, "", NULL)) {
+                psError(PS_ERR_UNKNOWN, false, "Failed to add item %s", field[i].name);
+                psFree(data);
+                psFree(md);
+                mysql_free_result(result);
+                psFree(resultSet);
+                return NULL;
+              }
+              break;
+          }
+          psFree(data);
+          continue;
+        }
 
             switch (pType) {
@@ -2423,5 +2423,5 @@
     case PS_DATA_TIME: {
             if (item->data.V) {
-                psString timeStr = psTimeToISO(item->data.V);
+                psString timeStr = psTimeToString(item->data.V, 6); // MySQL only handles microseconds
                 psStringAppend(&query, "%s %s '%s'", itemName, opStr, timeStr);
                 psFree(timeStr);
Index: anches/cnb_branches/cnb_branch_20090215/psLib/src/fft/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/src/fft/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,10 +1,0 @@
-.deps
-.libs
-Makefile
-Makefile.in
-*.la
-*.lo
-*.loT
-*.bb
-*.bbg
-*.da
Index: anches/cnb_branches/cnb_branch_20090215/psLib/src/fits/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/src/fits/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,10 +1,0 @@
-.deps
-.libs
-Makefile
-Makefile.in
-*.la
-*.lo
-*.loT
-*.bb
-*.bbg
-*.da
Index: /branches/cnb_branches/cnb_branch_20090215/psLib/src/fits/psFitsHeader.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/src/fits/psFitsHeader.c	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psLib/src/fits/psFitsHeader.c	(revision 23197)
@@ -666,7 +666,8 @@
                 break;
               default:  // all other META types are ignored
-                psWarning("Attempt to write metadata %s of type %x to FITS header ignored.\n",
-item->name, item->type);
-                break;
+                psError(PS_ERR_IO, true,
+                        "Unable to write metadata item %s of type %x to FITS header",
+                        item->name, item->type);
+                return false;
             }
         }
@@ -675,5 +676,7 @@
             char fitsErr[MAX_STRING_LENGTH];
             (void)fits_get_errstatus(status, fitsErr);
-            psError(PS_ERR_IO, true, _("Could not write data to file. CFITSIO Error: %s"), fitsErr);
+            psError(PS_ERR_IO, true,
+                    _("Could not write metadata item %s of type %x to FITS header.\nCFITSIO Error: %s"),
+                    item->name, item->type, fitsErr);
             return false;
         }
Index: /branches/cnb_branches/cnb_branch_20090215/psLib/src/fits/psFitsImage.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/src/fits/psFitsImage.c	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psLib/src/fits/psFitsImage.c	(revision 23197)
@@ -7,6 +7,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.41 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2009-01-27 06:39:37 $
+ *  @version $Revision: 1.42 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-02-19 03:15:40 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -266,5 +266,23 @@
     *floatType = PS_FITS_FLOAT_NONE;
 
-    psFitsOptions *options = fits->options;
+    psFitsOptions *options = fits->options; // Options for FITS writing
+
+    // Can't PLIO compress U16,U32,U64 directly, so convert them
+    if (psFitsCompressionGetType(fits) == PS_FITS_COMPRESS_PLIO && (!options || options->bitpix == 0)) {
+        switch (image->type.type) {
+          case PS_TYPE_U16:
+            return psImageCopy(NULL, image, PS_TYPE_S32);
+          case PS_TYPE_U32:
+            return psImageCopy(NULL, image, PS_TYPE_S64);
+          case PS_TYPE_U64:
+            // Conversion would result in numerical overflow
+            psError(PS_ERR_IO, true, "Unable to compress U64 images");
+            return NULL;
+          default:
+            // No action
+            ;
+        }
+    }
+
     if (!options) {
         return psMemIncrRefCounter((psImage*)image); // Casting away const
Index: anches/cnb_branches/cnb_branch_20090215/psLib/src/imageops/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/src/imageops/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,10 +1,0 @@
-.deps
-.libs
-Makefile
-Makefile.in
-*.la
-*.lo
-*.loT
-*.bb
-*.bbg
-*.da
Index: anches/cnb_branches/cnb_branch_20090215/psLib/src/jpeg/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/src/jpeg/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,10 +1,0 @@
-.deps
-.libs
-Makefile
-Makefile.in
-*.la
-*.lo
-*.loT
-*.bb
-*.bbg
-*.da
Index: /branches/cnb_branches/cnb_branch_20090215/psLib/src/jpeg/psImageJpeg.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/src/jpeg/psImageJpeg.c	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psLib/src/jpeg/psImageJpeg.c	(revision 23197)
@@ -140,4 +140,5 @@
     PS_ASSERT_PTR_NON_NULL(map, false);
     PS_ASSERT_IMAGE_NON_NULL(image, false);
+    PS_ASSERT_IMAGE_TYPE(image, PS_TYPE_F32, false);
     PS_ASSERT_VECTOR_NON_NULL(map->red, false);
     PS_ASSERT_VECTOR_NON_NULL(map->green, false);
Index: anches/cnb_branches/cnb_branch_20090215/psLib/src/math/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/src/math/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,10 +1,0 @@
-.deps
-.libs
-Makefile
-Makefile.in
-*.la
-*.lo
-*.loT
-*.bb
-*.bbg
-*.da
Index: anches/cnb_branches/cnb_branch_20090215/psLib/src/mathtypes/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/src/mathtypes/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,10 +1,0 @@
-.deps
-.libs
-Makefile
-Makefile.in
-*.la
-*.lo
-*.loT
-*.bb
-*.bbg
-*.da
Index: anches/cnb_branches/cnb_branch_20090215/psLib/src/sys/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/src/sys/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,12 +1,0 @@
-.deps
-.libs
-Makefile
-Makefile.in
-*.la
-*.lo
-psErrorCodes.c
-psErrorCodes.h
-*.loT
-*.bb
-*.bbg
-*.da
Index: anches/cnb_branches/cnb_branch_20090215/psLib/src/types/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/src/types/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,10 +1,0 @@
-.deps
-.libs
-Makefile
-Makefile.in
-*.la
-*.lo
-*.loT
-*.bb
-*.bbg
-*.da
Index: /branches/cnb_branches/cnb_branch_20090215/psLib/src/types/psMetadataConfig.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/src/types/psMetadataConfig.c	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psLib/src/types/psMetadataConfig.c	(revision 23197)
@@ -821,26 +821,26 @@
         status = 0;
         strValue = getToken (&linePtr, "#", &status, true);
-       
+
         if (!status && strValue) {
-	    // found a directive, what does it say?
-	    if (strcasecmp (strValue, "UPDATE") && strcasecmp (strValue, "RESET")) {
-		psError(PS_ERR_IO, true, _("Invalid directive %s for METADATA or MULTI."), strValue);
-		psFree(strType);
-		psFree(strValue);
-		return false;
-	    }
-
-	    // found a directive, what does it say?
-	    if (!strcasecmp (strValue, "UPDATE")) {
-		// this folder or group is merged with an existing one of the same name
-		flags |= PS_META_UPDATE_FOLDER;
-	    }
-	    if (!strcasecmp (strValue, "RESET")) {
-		// this folder or group replaces an existing one of the same name
-		flags |= PS_META_REPLACE;
-	    }
-	    psFree(strValue);
-	    strValue = NULL;
-	}
+            // found a directive, what does it say?
+            if (strcasecmp (strValue, "UPDATE") && strcasecmp (strValue, "RESET")) {
+                psError(PS_ERR_IO, true, _("Invalid directive %s for METADATA or MULTI."), strValue);
+                psFree(strType);
+                psFree(strValue);
+                return false;
+            }
+
+            // found a directive, what does it say?
+            if (!strcasecmp (strValue, "UPDATE")) {
+                // this folder or group is merged with an existing one of the same name
+                flags |= PS_META_UPDATE_FOLDER;
+            }
+            if (!strcasecmp (strValue, "RESET")) {
+                // this folder or group replaces an existing one of the same name
+                flags |= PS_META_REPLACE;
+            }
+            psFree(strValue);
+            strValue = NULL;
+        }
 
         // Not all lines will have comments, so NULL is ok.
@@ -887,5 +887,5 @@
             return false;
         }
-    } 
+    }
 
 #define PARSE_ADD_CASE(NAME, TYPE, PARSEFUNC) \
@@ -1241,5 +1241,5 @@
         psError(PS_ERR_IO, true, _("failed to parse file '%s'"), filename);
         psFree(md);
-	psFree(file);
+        psFree(file);
         return NULL;
     }
@@ -1516,10 +1516,6 @@
             }
             psString timeStr = psTimeToISO(time);
-            psString timeOutput;
-            timeOutput = psStringNCopy(timeStr, 19);
-            psStringAppend(&content, "%s", timeOutput);
-            psStringAppend(&content, "Z");
+            psStringAppend(&content, "%s", timeStr);
             psFree(timeStr);
-            psFree(timeOutput);
         } else {
             // psTime is a NULL pointer
Index: anches/cnb_branches/cnb_branch_20090215/psLib/src/xml/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/src/xml/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,10 +1,0 @@
-.deps
-.libs
-Makefile
-Makefile.in
-*.la
-*.lo
-*.loT
-*.bb
-*.bbg
-*.da
Index: anches/cnb_branches/cnb_branch_20090215/psLib/swig/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/swig/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,6 +1,0 @@
-psLibModule
-Makefile
-Makefile.in
-*.bb
-*.bbg
-*.da
Index: anches/cnb_branches/cnb_branch_20090215/psLib/test/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/test/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,7 +1,0 @@
-temp
-Makefile
-Makefile.in
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/psLib/test/astro/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/test/astro/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,33 +1,0 @@
-.deps
-.libs
-Makefile
-Makefile.in
-pslib.config
-temp
-test.psTime.config1
-test.psTime.config2
-test.psTime.config3
-test.psTime.config4
-test.ser7.dat
-tst_psCoord
-tst_psCoord01
-tst_psSphereOps
-tst_psTime_01
-tst_psTime_02
-tst_psTime_03
-tst_psTime_04
-tst_psEarthOrientation
-tst_psCoord02
-*.bb
-*.bbg
-*.da
-gmon.out
-tap_psEarthOrientation_corrections
-tap_psEarthOrientation_motion
-tap_psSphereOps_all
-tap_psCoord
-tap_psCoord02
-tap_psTime_01
-tap_psTime_02
-tap_psTime_03
-tap_psTime_04
Index: anches/cnb_branches/cnb_branch_20090215/psLib/test/db/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/test/db/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-temp
-.deps
-.libs
-Makefile
-Makefile.in
-tst_psDB
-*.bb
-*.bbg
-*.da
-gmon.out
-tap_psDB
Index: anches/cnb_branches/cnb_branch_20090215/psLib/test/fft/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/test/fft/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,15 +1,0 @@
-temp
-.deps
-.libs
-Makefile
-Makefile.in
-tst_psImageFFT
-tst_psVectorFFT
-*.bb
-*.bbg
-*.da
-gmon.out
-tap_psImageFFT2
-tap_psVectorFFT2
-tap_psImageFFT
-tap_psVectorFFT
Index: anches/cnb_branches/cnb_branch_20090215/psLib/test/fits/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/test/fits/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,15 +1,0 @@
-temp
-.deps
-.libs
-Makefile
-Makefile.in
-multi.fits
-table.fits
-tmpImages
-tap_psFitsBlank_00
-*.bb
-*.bbg
-*.da
-gmon.out
-tap_psFits
-tap_psFitsImage
Index: anches/cnb_branches/cnb_branch_20090215/psLib/test/imageops/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/test/imageops/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,38 +1,0 @@
-temp
-.deps
-.libs
-Makefile
-Makefile.in
-tst_psImageConvolve
-tst_psImageGeomManip
-tst_psImageInterpolate
-tst_psImagePixelExtract
-tst_psImagePixelManip
-tst_psImageStats
-tst_psImageStructManip
-fBiOut.fits
-fOut.fits
-sBiOut.fits
-sOut.fits
-tst_psImageMaskOps
-tst_psImageSmooth
-*.bb
-*.bbg
-*.da
-gmon.out
-tap_psImageShift
-tap_psImageShiftKernel
-tap_psImageConvolve
-tap_psImageConvolve2
-convolutionBench
-tap_psImageInterpolate2
-tap_psImageGeomManip
-tap_psImageMaskOps
-tap_psImagePixelExtract
-tap_psImagePixelManip
-tap_psImageSmooth
-tap_psImageStructManip
-tap_psImageMap
-
-tap_psImageMapFit
-tap_psImageMapFit2
Index: anches/cnb_branches/cnb_branch_20090215/psLib/test/jpeg/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/test/jpeg/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,9 +1,0 @@
-temp
-.deps
-.libs
-Makefile
-Makefile.in
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/psLib/test/math/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/test/math/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,54 +1,0 @@
-temp
-.deps
-.libs
-Makefile
-Makefile.in
-seed_msglog1.txt
-seed_msglog2.txt
-*.bb
-*.bbg
-*.da
-gmon.out
-
-tap_psHist00
-tap_psHist01
-tap_psHist02
-tap_psHist03
-tap_psMD5
-tap_psMatrix01
-tap_psMatrix02
-tap_psMatrix03
-tap_psMatrix04
-tap_psMatrix05
-tap_psMatrix06
-tap_psMatrix07
-tap_psPolyFit1D
-tap_psPolyFit2D
-tap_psPolyFit3D
-tap_psPolyFit4D
-tap_psPolynomial
-tap_psPolynomialEval1D
-tap_psPolynomialEval2D
-tap_psPolynomialEval3D
-tap_psPolynomialEval4D
-tap_psPolynomialUtils_Derivatives
-tap_psSparse
-tap_psStats00
-tap_psStats01
-tap_psStats02
-tap_psStats03
-tap_psStats05
-tap_psStats06
-tap_psStats07
-tap_psStats08
-tap_psStats09
-tap_psStatsTiming
-tap_psStats_Sample_01
-tap_psFunc01
-tap_psHistogram
-tap_psMatrixVectorArithmetic01
-tap_psMatrixVectorArithmetic04
-tap_psMinimizePowell
-tap_psRandom
-tap_psSpline1D
-tap_psPolynomialMD
Index: anches/cnb_branches/cnb_branch_20090215/psLib/test/mathtypes/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/test/mathtypes/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,23 +1,0 @@
-temp
-.deps
-.libs
-Makefile
-Makefile.in
-tst_psImage
-tst_psScalar
-tst_psVector
-tst_psVectorSort_01
-tst_psVectorSort_02
-tst_psVectorSort_03
-tst_psVectorSort_04
-tap_psVector
-*.bb
-*.bbg
-*.da
-gmon.out
-tap_psImageInterpolate
-tap_psImage
-tap_psScalar
-tap_psVectorSort
-tap_psVectorSortIndex
-tap_psVectorSelect
Index: anches/cnb_branches/cnb_branch_20090215/psLib/test/pstap/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/test/pstap/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,3 +1,0 @@
-Makefile
-Makefile.in
-.deps
Index: anches/cnb_branches/cnb_branch_20090215/psLib/test/pstap/src/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/test/pstap/src/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,6 +1,0 @@
-Makefile
-Makefile.in
-.deps
-.libs
-libpstap.la
-pstap.lo
Index: anches/cnb_branches/cnb_branch_20090215/psLib/test/sys/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/test/sys/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,30 +1,0 @@
-temp
-.deps
-.libs
-Makefile
-Makefile.in
-log.txt
-log2.txt
-tst_psAbort
-tst_psConfigure
-tst_psError
-tst_psLogMsg
-tst_psMemory
-tst_psString
-tst_psTrace
-tst_psTrace02_OUT
-test.fits
-core
-core.*
-tap_psStringSubstitute
-tst_psLine
-*.bb
-*.bbg
-*.da
-gmon.out
-tap_psConfigure
-tap_psError
-tap_psLine
-tap_psMemory
-tap_psString
-tap_psTrace
Index: anches/cnb_branches/cnb_branch_20090215/psLib/test/tap/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/test/tap/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,13 +1,0 @@
-.in
-Makefile
-Makefile.in
-aclocal.m4
-autom4te.cache
-config.log
-config.status
-configure
-libtool
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/psLib/test/tap/src/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/test/tap/src/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,13 +1,0 @@
-.deps
-.libs
-Makefile
-Makefile.in
-libtap.la
-tap.lo
-config.h
-config.h.in
-stamp-h1
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/psLib/test/tap/tests/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/test/tap/tests/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,6 +1,0 @@
-Makefile
-Makefile.in
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/psLib/test/tap/tests/diag/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/test/tap/tests/diag/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/psLib/test/tap/tests/fail/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/test/tap/tests/fail/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,15 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/psLib/test/tap/tests/ok/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/test/tap/tests/ok/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,6 +1,0 @@
-Makefile
-Makefile.in
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/psLib/test/tap/tests/ok/ok-hash/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/test/tap/tests/ok/ok-hash/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/psLib/test/tap/tests/ok/ok-numeric/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/test/tap/tests/ok/ok-numeric/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/psLib/test/tap/tests/ok/ok/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/test/tap/tests/ok/ok/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/psLib/test/tap/tests/pass/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/test/tap/tests/pass/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/psLib/test/tap/tests/plan/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/test/tap/tests/plan/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,6 +1,0 @@
-Makefile
-Makefile.in
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/psLib/test/tap/tests/plan/no-tests/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/test/tap/tests/plan/no-tests/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/psLib/test/tap/tests/plan/no_plan/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/test/tap/tests/plan/no_plan/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/psLib/test/tap/tests/plan/not-enough-tests/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/test/tap/tests/plan/not-enough-tests/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/psLib/test/tap/tests/plan/sane/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/test/tap/tests/plan/sane/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/psLib/test/tap/tests/plan/skip_all/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/test/tap/tests/plan/skip_all/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/psLib/test/tap/tests/plan/too-many-plans/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/test/tap/tests/plan/too-many-plans/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/psLib/test/tap/tests/plan/too-many-tests/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/test/tap/tests/plan/too-many-tests/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/psLib/test/tap/tests/skip/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/test/tap/tests/skip/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/psLib/test/tap/tests/todo/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/test/tap/tests/todo/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/psLib/test/types/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/test/types/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,79 +1,0 @@
-temp
-.deps
-.libs
-Makefile
-Makefile.in
-header_1.fits
-header_2.fits
-mdcfgwrt.out
-table10.dat
-table2.dat
-table3.dat
-tableF32.dat
-tableS32.dat
-tableU8.dat
-test.config
-test1.config
-test2.config
-test3.config
-test4.config
-test5.config
-tst_psArray
-tst_psBitSet
-tst_psHash00
-tst_psHash01
-tst_psHash02
-tst_psHash03
-tst_psHash04
-tst_psHash05
-tst_psList
-tst_psLookupTable_01
-tst_psMetadataIO
-tst_psMetadata_01
-tst_psMetadata_02
-tst_psMetadata_03
-tst_psMetadata_04
-tst_psMetadata_05
-tst_psMetadata_06
-tst_psMetadata_07
-tst_psPixels
-MDCopy.in
-MDCopy.out
-tst_psArguments
-mdcfgwrt.verified
-
-tap_psListIterator
-tap_psMetadataIterator
-tap_psMetadataConfigParse
-tap_psMetadataConfigParse.config
-*.bb
-*.bbg
-*.da
-gmon.out
-
-tap_psArguments_all
-tap_psArray_all
-tap_psBitSet_all
-tap_psHash_845
-tap_psHash_all
-tap_psList_all
-tap_psLookupTable_all
-tap_psMetadataConfigFormat
-tap_psMetadataConfigParse_time
-tap_psMetadataConfigPrint
-tap_psMetadataConfigRead
-tap_psMetadataConfigWrite
-tap_psMetadataConfig_input
-tap_psMetadataConfig_output
-tap_psMetadataItemCompare
-tap_psMetadataItemParse
-tap_psMetadata_copying
-tap_psMetadata_creating
-tap_psMetadata_manip
-tap_psMetadata_polynomials
-tap_psMetadata_printing
-tap_psPixels_all
-
-tap_psMetadataUpdate
-tap_psMetadataOverlay
-tap_psTree
Index: anches/cnb_branches/cnb_branch_20090215/psLib/test/xml/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/test/xml/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,15 +1,0 @@
-temp
-.deps
-.libs
-Makefile
-Makefile.in
-psTest.xml
-psTest2.xml
-psTest3.xml
-psTest4.xml
-psTest5.xml
-tst_psXML
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/psLib/utils/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psLib/utils/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,5 +1,0 @@
-Makefile
-Makefile.in
-.deps
-.libs
-psTableParse
Index: anches/cnb_branches/cnb_branch_20090215/psModules/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,29 +1,0 @@
-autom4te.cache
-Makefile
-config.log
-config.status
-libtool
-Makefile.in
-aclocal.m4
-configure
-Doxyfile
-DoxygenLog
-docs
-man
-psmodules-config
-psmodules.pc
-bin
-include
-lib
-config.guess
-config.sub
-depcomp
-install-sh
-ltmain.sh
-missing
-psmodule.kdevelop.pcs
-psmodule-*.tar.gz
-psmodule-*.tar.bz2
-compile
-ChangeLog
-psmodules-*.tar.*
Index: anches/cnb_branches/cnb_branch_20090215/psModules/src/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,9 +1,0 @@
-.deps
-.libs
-Makefile
-config.h
-stamp-h1
-Makefile.in
-config.h.in
-*.la
-*.lo
Index: anches/cnb_branches/cnb_branch_20090215/psModules/src/astrom/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/astrom/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,6 +1,0 @@
-.deps
-.libs
-Makefile
-Makefile.in
-*.la
-*.lo
Index: anches/cnb_branches/cnb_branch_20090215/psModules/src/camera/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/camera/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,6 +1,0 @@
-.deps
-.libs
-Makefile
-Makefile.in
-*.la
-*.lo
Index: /branches/cnb_branches/cnb_branch_20090215/psModules/src/camera/pmFPAConstruct.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/camera/pmFPAConstruct.c	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psModules/src/camera/pmFPAConstruct.c	(revision 23197)
@@ -14,5 +14,5 @@
 #include "pmFPAview.h"
 #include "pmFPAFlags.h"
-#include "pmConcepts.h"
+#include "pmConceptsRead.h"
 #include "pmFPAConstruct.h"
 #include "pmFPAUtils.h"
Index: /branches/cnb_branches/cnb_branch_20090215/psModules/src/camera/pmFPACopy.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/camera/pmFPACopy.c	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psModules/src/camera/pmFPACopy.c	(revision 23197)
@@ -13,4 +13,5 @@
 #include "pmFPAUtils.h"
 #include "pmHDUUtils.h"
+#include "pmConceptsCopy.h"
 #include "pmFPACopy.h"
 
@@ -452,8 +453,8 @@
     // Update the concepts
     psMetadataItem *chipName = psMemIncrRefCounter(psMetadataLookup(target->concepts, "CHIP.NAME"));
-    psMetadataCopy(target->concepts, source->concepts);
+    pmConceptsCopyChip(target, source, false);
     psMetadataAddItem(target->concepts, chipName, PS_LIST_TAIL, PS_META_REPLACE);
     psFree(chipName);
-    psMetadataCopy(target->parent->concepts, source->parent->concepts);
+    pmConceptsCopyFPA(target->parent, source->parent, false, false);
 
     // Update the astrometric parameters
@@ -467,19 +468,19 @@
 
     if (targetFPA && sourceFPA) {
-	if (targetFPA->toSky) {
-	    psAssert (targetFPA->toSky == sourceFPA->toSky, "chips within FPA have inconsistent astrometry references");
-	} else {
-	    targetFPA->toSky = psMemIncrRefCounter (sourceFPA->toSky);
-	}
-	if (targetFPA->toTPA) {
-	    psAssert (targetFPA->toTPA == sourceFPA->toTPA, "chips within FPA have inconsistent astrometry references");
-	} else {
-	    targetFPA->toTPA = psMemIncrRefCounter (sourceFPA->toTPA);
-	}
-	if (targetFPA->fromTPA) {
-	    psAssert (targetFPA->fromTPA == sourceFPA->fromTPA, "chips within FPA have inconsistent astrometry references");
-	} else {
-	    targetFPA->fromTPA = psMemIncrRefCounter (sourceFPA->fromTPA);
-	}
+        if (targetFPA->toSky) {
+            psAssert (targetFPA->toSky == sourceFPA->toSky, "chips within FPA have inconsistent astrometry references");
+        } else {
+            targetFPA->toSky = psMemIncrRefCounter (sourceFPA->toSky);
+        }
+        if (targetFPA->toTPA) {
+            psAssert (targetFPA->toTPA == sourceFPA->toTPA, "chips within FPA have inconsistent astrometry references");
+        } else {
+            targetFPA->toTPA = psMemIncrRefCounter (sourceFPA->toTPA);
+        }
+        if (targetFPA->fromTPA) {
+            psAssert (targetFPA->fromTPA == sourceFPA->fromTPA, "chips within FPA have inconsistent astrometry references");
+        } else {
+            targetFPA->fromTPA = psMemIncrRefCounter (sourceFPA->fromTPA);
+        }
     }
 
@@ -525,5 +526,5 @@
 
     // Update the concepts
-    psMetadataCopy(targetChip->concepts, sourceChip->concepts);
+    pmConceptsCopyChip(targetChip, sourceChip, false);
 
     // update the attributes
@@ -572,5 +573,5 @@
 
     // Update the concepts
-    psMetadataCopy(target->concepts, source->concepts);
+    pmConceptsCopyFPA(target, source, false, false);
 
     return status;
Index: /branches/cnb_branches/cnb_branch_20090215/psModules/src/camera/pmFPAHeader.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/camera/pmFPAHeader.c	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psModules/src/camera/pmFPAHeader.c	(revision 23197)
@@ -10,5 +10,5 @@
 #include "pmFPA.h"
 #include "pmFPALevel.h"
-#include "pmConcepts.h"
+#include "pmConceptsRead.h"
 #include "pmFPAHeader.h"
 
Index: /branches/cnb_branches/cnb_branch_20090215/psModules/src/camera/pmFPARead.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/camera/pmFPARead.c	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psModules/src/camera/pmFPARead.c	(revision 23197)
@@ -17,5 +17,5 @@
 #include "pmFPAFlags.h"
 #include "pmHDUUtils.h"
-#include "pmConcepts.h"
+#include "pmConceptsRead.h"
 #include "pmFPAHeader.h"
 
Index: /branches/cnb_branches/cnb_branch_20090215/psModules/src/camera/pmFPAWrite.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/camera/pmFPAWrite.c	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psModules/src/camera/pmFPAWrite.c	(revision 23197)
@@ -18,5 +18,5 @@
 #include "pmHDUUtils.h"
 #include "pmHDUGenerate.h"
-#include "pmConcepts.h"
+#include "pmConceptsWrite.h"
 
 #include "pmFPAWrite.h"
Index: /branches/cnb_branches/cnb_branch_20090215/psModules/src/camera/pmFPAfile.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/camera/pmFPAfile.c	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psModules/src/camera/pmFPAfile.c	(revision 23197)
@@ -18,5 +18,5 @@
 #include "pmFPAfile.h"
 #include "pmFPACopy.h"
-#include "pmConcepts.h"
+#include "pmConceptsCopy.h"
 
 static void pmFPAfileFree(pmFPAfile *file)
@@ -409,5 +409,5 @@
     // XXX this should be smarter (ie, only copy concepts from the current chips)
     // but such a call is needed, so re-copy stuff rather than no copy
-    pmFPACopyConcepts (out, in);
+    pmConceptsCopyFPA(out, in, true, true);
 
     // pmFPAWrite takes care of all PHUs as needed
Index: /branches/cnb_branches/cnb_branch_20090215/psModules/src/camera/pmFPAfileDefine.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/camera/pmFPAfileDefine.c	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psModules/src/camera/pmFPAfileDefine.c	(revision 23197)
@@ -21,5 +21,5 @@
 #include "pmFPAConstruct.h"
 
-#include "pmConcepts.h"
+#include "pmConceptsCopy.h"
 
 # define FPA_TEST_ASSERT(A){ \
@@ -1024,8 +1024,8 @@
         }
 
-	// XXX A TEST: this is a provisional fpa until we read the first header for this pmFPAfile
-	// we are going to replace it when we determine the true file.  blow this away here...
-	psFree (file->fpa);
-	file->fpa = NULL;
+        // XXX A TEST: this is a provisional fpa until we read the first header for this pmFPAfile
+        // we are going to replace it when we determine the true file.  blow this away here...
+        psFree (file->fpa);
+        file->fpa = NULL;
     }
 
@@ -1184,5 +1184,5 @@
 
     // inherit the concepts from the src fpa:
-    pmFPACopyConcepts(file->fpa, file->src);
+    pmConceptsCopyFPA(file->fpa, file->src, true, true);
 
     return file;
Index: /branches/cnb_branches/cnb_branch_20090215/psModules/src/camera/pmFPAfileFitsIO.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/camera/pmFPAfileFitsIO.c	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psModules/src/camera/pmFPAfileFitsIO.c	(revision 23197)
@@ -22,5 +22,5 @@
 #include "pmFPAConstruct.h"
 #include "pmDark.h"
-#include "pmConcepts.h"
+#include "pmConceptsWrite.h"
 
 // Get a suitable FPA for the file; generate it if necessary
Index: /branches/cnb_branches/cnb_branch_20090215/psModules/src/camera/pmHDUUtils.h
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/camera/pmHDUUtils.h	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psModules/src/camera/pmHDUUtils.h	(revision 23197)
@@ -11,4 +11,7 @@
 #ifndef PM_HDU_UTILS_H
 #define PM_HDU_UTILS_H
+
+#include <pmHDU.h>
+#include <pmFPA.h>
 
 /// @addtogroup Camera Camera Layout
Index: anches/cnb_branches/cnb_branch_20090215/psModules/src/concepts/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/concepts/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,6 +1,0 @@
-.deps
-.libs
-Makefile
-Makefile.in
-*.la
-*.lo
Index: /branches/cnb_branches/cnb_branch_20090215/psModules/src/concepts/Makefile.am
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/concepts/Makefile.am	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psModules/src/concepts/Makefile.am	(revision 23197)
@@ -8,4 +8,5 @@
 	pmConceptsRead.c \
 	pmConceptsWrite.c \
+	pmConceptsCopy.c \
 	pmConceptsStandard.c \
 	pmConceptsPhotcode.c \
@@ -17,4 +18,5 @@
 	pmConceptsRead.h \
 	pmConceptsWrite.h \
+	pmConceptsCopy.h \
 	pmConceptsStandard.h \
 	pmConceptsPhotcode.h \
Index: /branches/cnb_branches/cnb_branch_20090215/psModules/src/concepts/pmConcepts.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/concepts/pmConcepts.c	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psModules/src/concepts/pmConcepts.c	(revision 23197)
@@ -19,5 +19,4 @@
 #include "pmConceptsWrite.h"
 #include "pmConceptsStandard.h"
-#include "pmConceptsUpdate.h"
 
 static bool conceptsInitialised = false;// Have concepts been read?
@@ -49,5 +48,6 @@
 
 pmConceptSpec *pmConceptSpecAlloc(psMetadataItem *blank, pmConceptParseFunc parse,
-                                  pmConceptFormatFunc format, bool required)
+                                  pmConceptFormatFunc format, pmConceptCopyFunc copy,
+                                  bool required)
 {
     pmConceptSpec *spec = psAlloc(sizeof(pmConceptSpec));
@@ -57,4 +57,5 @@
     spec->parse = parse;
     spec->format = format;
+    spec->copy = copy;
     spec->required = required;
 
@@ -86,4 +87,20 @@
 }
 
+psMetadata *pmConceptsSpecs(pmFPALevel level)
+{
+    if (!conceptsInitialised) {
+        pmConceptsInit();
+    }
+
+    // Get the appropriate concepts
+    psMetadata *concepts = conceptsFromLevel(level); // Metadata of concepts specs
+    if (!concepts) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Invalid concept level provided: %d\n", level);
+        return NULL;
+    }
+
+    return concepts;
+}
+
 bool pmConceptGetRequired(const char *name, pmFPALevel level)
 {
@@ -129,5 +146,6 @@
 
 bool pmConceptRegister(psMetadataItem *blank, pmConceptParseFunc parse,
-                        pmConceptFormatFunc format, bool required, pmFPALevel level)
+                       pmConceptFormatFunc format, pmConceptCopyFunc copy,
+                       bool required, pmFPALevel level)
 {
     PS_ASSERT_PTR_NON_NULL(blank, false);
@@ -144,5 +162,5 @@
     }
 
-    pmConceptSpec *spec = pmConceptSpecAlloc(blank, parse, format, required); // The concept specification
+    pmConceptSpec *spec = pmConceptSpecAlloc(blank, parse, format, copy, required); // Concept specification
     psMetadataAdd(target, PS_LIST_TAIL, blank->name, PS_DATA_UNKNOWN | PS_META_REPLACE,
                   "Concepts specification", spec);
@@ -188,154 +206,4 @@
 
 
-
-// Read all registered concepts for the specified level
-static bool conceptsRead(psMetadata **specs, // One of the concepts specifications
-                         pmFPA *fpa,    // The FPA
-                         pmChip *chip,  // The chip
-                         pmCell *cell, // The cell
-                         unsigned int *read,     // What's already been read
-                         pmConceptSource source, // The source of the concepts to read
-                         pmConfig *config, // Configuration
-                         psMetadata *target // Place into which to read the concepts
-                        )
-{
-    assert(specs);
-    assert(read);
-    assert(target);
-
-    if (!conceptsInitialised) {
-        pmConceptsInit();
-    }
-
-    // At least one HDU is required for the reading functions
-    pmHDU *hduLow = pmHDUGetLowest(fpa, chip, cell); // Lowest HDU.
-    if (!hduLow) {
-        // Can't do anything --- don't record any success, but don't return an error either
-        return true;
-    }
-    pmHDU *hduHigh = pmHDUGetHighest(fpa, chip, cell); // Highest HDU
-
-    if (cell && (cell->conceptsRead == PM_CONCEPT_SOURCE_NONE)) {
-        pmConceptsBlankCell(cell);
-        cell->conceptsRead = PM_CONCEPT_SOURCE_BLANK;
-    }
-    if (chip && (chip->conceptsRead == PM_CONCEPT_SOURCE_NONE)) {
-        pmConceptsBlankChip(chip);
-        chip->conceptsRead = PM_CONCEPT_SOURCE_BLANK;
-    }
-    if (fpa && (fpa->conceptsRead == PM_CONCEPT_SOURCE_NONE)) {
-        pmConceptsBlankFPA(fpa);
-        fpa->conceptsRead = PM_CONCEPT_SOURCE_BLANK;
-    }
-
-    bool success = true;                // Success in reading concepts?
-    if (source & PM_CONCEPT_SOURCE_CELLS && !(*read & PM_CONCEPT_SOURCE_CELLS) && cell) {
-        if (p_pmConceptsReadFromCells(target, *specs, cell)) {
-            *read |= PM_CONCEPT_SOURCE_CELLS;
-        } else {
-            psError(PS_ERR_UNKNOWN, false, "Error reading concepts from camera configuration.\n");
-            success = false;
-        }
-    }
-
-    if (source & PM_CONCEPT_SOURCE_DEFAULTS && !(*read & PM_CONCEPT_SOURCE_DEFAULTS)) {
-        if (p_pmConceptsReadFromDefaults(target, *specs, fpa, chip, cell)) {
-            *read |= PM_CONCEPT_SOURCE_DEFAULTS;
-        } else {
-            psError(PS_ERR_UNKNOWN, false, "Error reading concepts from defaults.\n");
-            success = false;
-        }
-    }
-
-    if (source & PM_CONCEPT_SOURCE_PHU && !(*read & PM_CONCEPT_SOURCE_PHU) && hduHigh->header) {
-        if (p_pmConceptsReadFromHeader(target, *specs, fpa, chip, cell)) {
-            *read |= PM_CONCEPT_SOURCE_PHU;
-        } else {
-            psError(PS_ERR_UNKNOWN, false, "Error reading concepts from PHU.\n");
-            success = false;
-        }
-    }
-
-    // If there are multiple HDUs, then it may be that one of them hasn't been read yet (hdu->header not set)
-    if (source & PM_CONCEPT_SOURCE_HEADER && !(*read & PM_CONCEPT_SOURCE_HEADER) &&
-        hduLow != hduHigh && hduLow->header) {
-        if (p_pmConceptsReadFromHeader(target, *specs, fpa, chip, cell)) {
-            *read |= PM_CONCEPT_SOURCE_HEADER;
-        } else {
-            psError(PS_ERR_UNKNOWN, false, "Error reading concepts from header.\n");
-            success = false;
-        }
-    }
-
-    #ifdef HAVE_PSDB
-    if (source & PM_CONCEPT_SOURCE_DATABASE && !(*read & PM_CONCEPT_SOURCE_DATABASE)) {
-        if (p_pmConceptsReadFromDatabase(target, *specs, fpa, chip, cell, config)) {
-            *read |= PM_CONCEPT_SOURCE_DATABASE;
-        } else {
-            psError(PS_ERR_UNKNOWN, false, "Error reading concepts from database.\n");
-            success = false;
-        }
-    }
-    #endif
-
-    pmConceptsUpdate(fpa, chip, cell);
-
-    return success;
-}
-
-// Write all registered concepts for the specified level
-static bool conceptsWrite(psMetadata **specs, // One of the concepts specifications
-                          const pmFPA *fpa,   // The FPA
-                          const pmChip *chip, // The chip
-                          const pmCell *cell, // The cell
-                          pmConceptSource source, // The source of the concepts to write
-                          pmConfig *config, // Configuration
-                          const psMetadata *concepts // The concepts to write out
-                         )
-{
-    assert(specs);
-    assert(concepts);
-
-    if (!conceptsInitialised) {
-        pmConceptsInit();
-    }
-
-    psTrace("psModules.concepts", 3, "Writing concepts (%p %p %p): %d\n", fpa, chip, cell, source);
-
-    if (source & PM_CONCEPT_SOURCE_CELLS) {
-        p_pmConceptsWriteToCells(*specs, cell, concepts);
-    }
-    if (source & PM_CONCEPT_SOURCE_DEFAULTS) {
-        p_pmConceptsWriteToDefaults(*specs, fpa, chip, cell, concepts);
-    }
-    if (source & (PM_CONCEPT_SOURCE_PHU | PM_CONCEPT_SOURCE_HEADER)) {
-        p_pmConceptsWriteToHeader(*specs, fpa, chip, cell, concepts);
-    }
-    if (source & PM_CONCEPT_SOURCE_DATABASE) {
-        p_pmConceptsWriteToDatabase(*specs, fpa, chip, cell, config, concepts);
-    }
-
-    return true;
-}
-
-
-bool pmConceptsRead(pmFPA *fpa, pmChip *chip, pmCell *cell, pmConceptSource source, pmConfig *config)
-{
-    PS_ASSERT_PTR_NON_NULL(fpa, false);
-    bool success = conceptsRead(&conceptsFPA, fpa, chip, cell, &fpa->conceptsRead, source,
-                                config, fpa->concepts);
-    if (chip) {
-        success &= conceptsRead(&conceptsChip, fpa, chip, cell, &chip->conceptsRead, source,
-                                config, chip->concepts);
-    }
-    if (cell) {
-        success &= conceptsRead(&conceptsCell, fpa, chip, cell, &cell->conceptsRead, source,
-                                config, cell->concepts);
-    }
-
-    return success;
-}
-
-
 bool pmConceptsBlankFPA(pmFPA *fpa)
 {
@@ -345,41 +213,4 @@
 }
 
-
-bool pmConceptsReadFPA(pmFPA *fpa, pmConceptSource source, bool propagateDown, pmConfig *config)
-{
-    PS_ASSERT_PTR_NON_NULL(fpa, false);
-    psTrace("psModules.concepts", 5, "Reading FPA concepts: %p %p\n", conceptsFPA, fpa->concepts);
-    bool success = conceptsRead(&conceptsFPA, fpa, NULL, NULL, &fpa->conceptsRead, source,
-                                config, fpa->concepts);
-    if (propagateDown) {
-        psArray *chips = fpa->chips;    // Array of chips
-        for (long i = 0; i < chips->n; i++) {
-            pmChip *chip = chips->data[i]; // Chip of interest
-            if (chip) {
-                success &= pmConceptsReadChip(chip, source, false, true, config);
-            }
-        }
-    }
-
-    return success;
-}
-
-bool pmConceptsWriteFPA(const pmFPA *fpa, pmConceptSource source, bool propagateDown, pmConfig *config)
-{
-    PS_ASSERT_PTR_NON_NULL(fpa, false);
-    psTrace("psModules.concepts", 5, "Writing FPA concepts: %p %p\n", conceptsFPA, fpa->concepts);
-    bool success = conceptsWrite(&conceptsFPA, fpa, NULL, NULL, source, config, fpa->concepts);
-    if (propagateDown) {
-        psArray *chips = fpa->chips;        // Array of chips
-        for (long i = 0; i < chips->n; i++) {
-            pmChip *chip = chips->data[i];  // Chip of interest
-            if (chip && !chip->hdu) {
-                success &= pmConceptsWriteChip(chip, source, false, true, config);
-            }
-        }
-    }
-    return success;
-}
-
 bool pmConceptsBlankChip(pmChip *chip)
 {
@@ -389,50 +220,4 @@
 }
 
-bool pmConceptsReadChip(pmChip *chip, pmConceptSource source, bool propagateUp,
-                        bool propagateDown, pmConfig *config)
-{
-    PS_ASSERT_PTR_NON_NULL(chip, false);
-    psTrace("psModules.concepts", 5, "Reading chip concepts: %p %p\n", conceptsChip, chip->concepts);
-    pmFPA *fpa = chip->parent;          // FPA to which the chip belongs
-    bool success = conceptsRead(&conceptsChip, fpa, chip, NULL, &chip->conceptsRead, source, config,
-                                chip->concepts);
-    if (propagateUp) {
-        success &= conceptsRead(&conceptsFPA, fpa, chip, NULL, &fpa->conceptsRead, source,
-                                config, fpa->concepts);
-    }
-    if (propagateDown) {
-        psArray *cells = chip->cells;        // Array of cells
-        for (long i = 0; i < cells->n; i++) {
-            pmCell *cell = cells->data[i];  // Cell of interest
-            if (cell) {
-                success &= pmConceptsReadCell(cell, source, false, config);
-            }
-        }
-    }
-    return success;
-}
-
-bool pmConceptsWriteChip(const pmChip *chip, pmConceptSource source, bool propagateUp,
-                         bool propagateDown, pmConfig *config)
-{
-    PS_ASSERT_PTR_NON_NULL(chip, false);
-    psTrace("psModules.concepts", 5, "Writing chip concepts: %p %p\n", conceptsChip, chip->concepts);
-    pmFPA *fpa = chip->parent;          // FPA to which the chip belongs
-    bool success = conceptsWrite(&conceptsChip, fpa, chip, NULL, source, config, chip->concepts);
-    if (propagateUp && !fpa->hdu) {
-        success &= conceptsWrite(&conceptsFPA, fpa, chip, NULL, source, config, fpa->concepts);
-    }
-    if (propagateDown) {
-        psArray *cells = chip->cells;        // Array of cells
-        for (long i = 0; i < cells->n; i++) {
-            pmCell *cell = cells->data[i];  // Cell of interest
-            if (cell && !cell->hdu) {
-                success &= pmConceptsWriteCell(cell, source, false, config);
-            }
-        }
-    }
-    return success;
-}
-
 bool pmConceptsBlankCell(pmCell *cell)
 {
@@ -440,43 +225,4 @@
     psTrace("psModules.concepts", 5, "Blanking cell concepts: %p %p\n", conceptsCell, cell->concepts);
     return conceptsBlank(&conceptsCell, cell->concepts);
-}
-
-bool pmConceptsReadCell(pmCell *cell, pmConceptSource source, bool propagateUp, pmConfig *config)
-{
-    PS_ASSERT_PTR_NON_NULL(cell, false);
-    psTrace("psModules.concepts", 5, "Reading cell concepts: %p %p\n", conceptsCell, cell->concepts);
-    pmChip *chip = cell->parent;        // Chip to which the cell belongs
-    pmFPA *fpa = chip->parent;          // FPA to which the chip belongs
-
-    bool success = conceptsRead(&conceptsCell, fpa, chip, cell, &cell->conceptsRead, source, config,
-                                cell->concepts);
-    if (propagateUp) {
-        success &= conceptsRead(&conceptsChip, fpa, chip, cell, &chip->conceptsRead, source, config,
-                                chip->concepts);
-        success &= conceptsRead(&conceptsFPA, fpa, chip, cell, &fpa->conceptsRead, source, config,
-                                fpa->concepts);
-    }
-
-    return success;
-}
-
-bool pmConceptsWriteCell(const pmCell *cell, pmConceptSource source, bool propagateUp, pmConfig *config)
-{
-    PS_ASSERT_PTR_NON_NULL(cell, false);
-    psTrace("psModules.concepts", 5, "Writing cell concepts: %p %p\n", conceptsCell, cell->concepts);
-    pmChip *chip = cell->parent;        // Chip to which the cell belongs
-    pmFPA *fpa = chip->parent;          // FPA to which the chip belongs
-
-    bool success = conceptsWrite(&conceptsCell, fpa, chip, cell, source, config, cell->concepts);
-    if (propagateUp) {
-        if (!chip->hdu) {
-            success &= conceptsWrite(&conceptsChip, fpa, chip, cell, source, config, chip->concepts);
-            if (!fpa->hdu) {
-                success &= conceptsWrite(&conceptsFPA, fpa, chip, cell, source, config, fpa->concepts);
-            }
-        }
-    }
-
-    return success;
 }
 
@@ -485,6 +231,7 @@
 static void conceptRegister##SUFFIX(const char *name, /* Name of concept */ \
                                     const char *comment, /* Comment for concept */ \
-                                    pmConceptParseFunc parse, /* Parsing function */ \
-                                    pmConceptFormatFunc format, /* Formatting function */ \
+                                    pmConceptParseFunc parse, /* Parsing function, or NULL */ \
+                                    pmConceptFormatFunc format, /* Formatting function, or NULL */ \
+                                    pmConceptCopyFunc copy, /* Copying function, or NULL */ \
                                     bool required, /* Required concept? */ \
                                     pmFPALevel level /* Level at which concept applies */ \
@@ -492,5 +239,5 @@
 { \
     psMetadataItem *item = psMetadataItemAlloc##TYPENAME(name, comment, DEFAULT); /* Item to add */ \
-    pmConceptRegister(item, parse, format, required, level); \
+    pmConceptRegister(item, parse, format, copy, required, level); \
     psFree(item); \
     return; \
@@ -515,5 +262,5 @@
     psMetadataItem *item = psMetadataItemAlloc(name, PS_DATA_TIME, comment, time);
     psFree(time);
-    pmConceptRegister(item, p_pmConceptParse_TIME, p_pmConceptFormat_TIME, required, level);
+    pmConceptRegister(item, p_pmConceptParse_TIME, p_pmConceptFormat_TIME, NULL, required, level);
     psFree(item);
 }
@@ -521,4 +268,8 @@
 bool pmConceptsInit(void)
 {
+    if (conceptsInitialised) {
+        return true;
+    }
+
     conceptsInitialised = true;
 
@@ -527,84 +278,84 @@
     bool init = false;                  // Did we initialise anything?
 
-    if (! conceptsFPA) {
+    if (!conceptsFPA) {
         conceptsFPA = psMetadataAlloc();
         init = true;
 
         // Install the standard concepts
-        conceptRegisterStr("FPA.TELESCOPE", "Telescope of origin", NULL, NULL, false, PM_FPA_LEVEL_FPA);
-        conceptRegisterStr("FPA.INSTRUMENT", "Instrument name (according to the instrument)", NULL, NULL, false, PM_FPA_LEVEL_FPA);
-        conceptRegisterStr("FPA.DETECTOR", "Detector name", NULL, NULL, false, PM_FPA_LEVEL_FPA);
-        conceptRegisterStr("FPA.COMMENT", "Observation comment", NULL, NULL, false, PM_FPA_LEVEL_FPA);
-        conceptRegisterStr("FPA.OBS.MODE", "Observation mode (eg, survey id)", NULL, NULL, false, PM_FPA_LEVEL_FPA);
-        conceptRegisterStr("FPA.OBS.GROUP", "Observation group (eg, associated images)", NULL, NULL, false, PM_FPA_LEVEL_FPA);
-        conceptRegisterF32("FPA.FOCUS", "Telescope focus", NULL, NULL, false, PM_FPA_LEVEL_FPA);
-        conceptRegisterF32("FPA.AIRMASS", "Airmass at boresight", NULL, NULL, false, PM_FPA_LEVEL_FPA);
-        conceptRegisterStr("FPA.FILTERID", "Filter used (parsed, abstract name)", p_pmConceptParse_FPA_FILTER, p_pmConceptFormat_FPA_FILTER, false, PM_FPA_LEVEL_FPA);
-        conceptRegisterStr("FPA.FILTER", "Filter used (instrument name)", false, NULL, NULL, PM_FPA_LEVEL_FPA);
-        conceptRegisterF32("FPA.POSANGLE", "Position angle of instrument", NULL, NULL, false, PM_FPA_LEVEL_FPA);
-        conceptRegisterF32("FPA.ROTANGLE", "Rotator angle of instrument", NULL, NULL, false, PM_FPA_LEVEL_FPA);
-        conceptRegisterStr("FPA.RADECSYS", "Celestial coordinate system", NULL, NULL, false, PM_FPA_LEVEL_FPA);
-        conceptRegisterF64("FPA.RA", "Right Ascension of boresight", p_pmConceptParse_FPA_Coords, p_pmConceptFormat_FPA_Coords, false, PM_FPA_LEVEL_FPA);
-        conceptRegisterF64("FPA.DEC", "Declination of boresight", p_pmConceptParse_FPA_Coords, p_pmConceptFormat_FPA_Coords, false, PM_FPA_LEVEL_FPA);
-        conceptRegisterF64("FPA.LONGITUDE", "West longitude of observatory", p_pmConceptParse_FPA_Coords, p_pmConceptFormat_FPA_Coords, false, PM_FPA_LEVEL_FPA);
-        conceptRegisterF64("FPA.LATITUDE", "Latitude of observatory", p_pmConceptParse_FPA_Coords, p_pmConceptFormat_FPA_Coords, false, PM_FPA_LEVEL_FPA);
-        conceptRegisterF32("FPA.ELEVATION", "Elevation of observatory (metres)", NULL, NULL, false, PM_FPA_LEVEL_FPA);
-        conceptRegisterStr("FPA.OBSTYPE", "Type of observation", NULL, NULL, false, PM_FPA_LEVEL_FPA);
-        conceptRegisterStr("FPA.OBJECT", "Object of observation", NULL, NULL, false, PM_FPA_LEVEL_FPA);
-        conceptRegisterF64("FPA.ALT", "Altitude of boresight", NULL, NULL, false, PM_FPA_LEVEL_FPA);
-        conceptRegisterF64("FPA.AZ", "Azimuth of boresight", NULL, NULL, false, PM_FPA_LEVEL_FPA);
-        conceptRegisterEnum("FPA.TIMESYS", "Time system", p_pmConceptParse_TIMESYS, p_pmConceptFormat_TIMESYS, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterStr("FPA.TELESCOPE", "Telescope of origin", NULL, NULL, NULL, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterStr("FPA.INSTRUMENT", "Instrument name (according to the instrument)", NULL, NULL, NULL, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterStr("FPA.DETECTOR", "Detector name", NULL, NULL, NULL, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterStr("FPA.COMMENT", "Observation comment", NULL, NULL, NULL, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterStr("FPA.OBS.MODE", "Observation mode (eg, survey id)", NULL, NULL, NULL, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterStr("FPA.OBS.GROUP", "Observation group (eg, associated images)", NULL, NULL, NULL, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterF32("FPA.FOCUS", "Telescope focus", NULL, NULL, NULL, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterF32("FPA.AIRMASS", "Airmass at boresight", NULL, NULL, NULL, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterStr("FPA.FILTERID", "Filter used (parsed, abstract name)", p_pmConceptParse_FPA_FILTER, p_pmConceptFormat_FPA_FILTER, NULL, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterStr("FPA.FILTER", "Filter used (instrument name)", NULL, NULL, NULL, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterF32("FPA.POSANGLE", "Position angle of instrument", NULL, NULL, NULL, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterF32("FPA.ROTANGLE", "Rotator angle of instrument", NULL, NULL, NULL, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterStr("FPA.RADECSYS", "Celestial coordinate system", NULL, NULL, NULL, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterF64("FPA.RA", "Right Ascension of boresight", p_pmConceptParse_FPA_Coords, p_pmConceptFormat_FPA_Coords, NULL, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterF64("FPA.DEC", "Declination of boresight", p_pmConceptParse_FPA_Coords, p_pmConceptFormat_FPA_Coords, NULL, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterF64("FPA.LONGITUDE", "West longitude of observatory", p_pmConceptParse_FPA_Coords, p_pmConceptFormat_FPA_Coords, NULL, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterF64("FPA.LATITUDE", "Latitude of observatory", p_pmConceptParse_FPA_Coords, p_pmConceptFormat_FPA_Coords, NULL, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterF32("FPA.ELEVATION", "Elevation of observatory (metres)", NULL, NULL, NULL, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterStr("FPA.OBSTYPE", "Type of observation", NULL, NULL, NULL, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterStr("FPA.OBJECT", "Object of observation", NULL, NULL, NULL, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterF64("FPA.ALT", "Altitude of boresight", NULL, NULL, NULL, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterF64("FPA.AZ", "Azimuth of boresight", NULL, NULL, NULL, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterEnum("FPA.TIMESYS", "Time system", p_pmConceptParse_TIMESYS, p_pmConceptFormat_TIMESYS, p_pmConceptCopy_TIMESYS, false, PM_FPA_LEVEL_FPA);
         conceptRegisterTime("FPA.TIME", "Time of exposure", false, PM_FPA_LEVEL_FPA);
-        conceptRegisterF32("FPA.TEMP", "Temperature of focal plane", NULL, NULL, false, PM_FPA_LEVEL_FPA);
-        conceptRegisterF32("FPA.M1X", "Primary Mirror X Position", NULL, NULL, false, PM_FPA_LEVEL_FPA);
-        conceptRegisterF32("FPA.M1Y", "Primary Mirror Y Position", NULL, NULL, false, PM_FPA_LEVEL_FPA);
-        conceptRegisterF32("FPA.M1Z", "Primary Mirror Z Position", NULL, NULL, false, PM_FPA_LEVEL_FPA);
-        conceptRegisterF32("FPA.M1TIP", "Primary Mirror TIP", NULL, NULL, false, PM_FPA_LEVEL_FPA);
-        conceptRegisterF32("FPA.M1TILT", "Primary Mirror TILT", NULL, NULL, false, PM_FPA_LEVEL_FPA);
-        conceptRegisterF32("FPA.M2X", "Primary Mirror X Position", NULL, NULL, false, PM_FPA_LEVEL_FPA);
-        conceptRegisterF32("FPA.M2Y", "Primary Mirror Y Position", NULL, NULL, false, PM_FPA_LEVEL_FPA);
-        conceptRegisterF32("FPA.M2Z", "Primary Mirror Z Position", NULL, NULL, false, PM_FPA_LEVEL_FPA);
-        conceptRegisterF32("FPA.M2TIP", "Primary Mirror TIP", NULL, NULL, false, PM_FPA_LEVEL_FPA);
-        conceptRegisterF32("FPA.M2TILT", "Primary Mirror TILT", NULL, NULL, false, PM_FPA_LEVEL_FPA);
-        conceptRegisterF32("FPA.ENV.TEMP", "Environment: Temperature", NULL, NULL, false, PM_FPA_LEVEL_FPA);
-        conceptRegisterF32("FPA.ENV.HUMID", "Environment: Humidity", NULL, NULL, false, PM_FPA_LEVEL_FPA);
-        conceptRegisterF32("FPA.ENV.WIND", "Environment: Wind speed", NULL, NULL, false, PM_FPA_LEVEL_FPA);
-        conceptRegisterF32("FPA.ENV.DIR", "Environment: Wind direction", NULL, NULL, false, PM_FPA_LEVEL_FPA);
-        conceptRegisterF32("FPA.TELTEMP.M1", "Telescope Temperatures: M1", p_pmConceptParse_TELTEMPS, NULL, false, PM_FPA_LEVEL_FPA);
-        conceptRegisterF32("FPA.TELTEMP.M1CELL", "Telescope Temperatures: M1 cell", p_pmConceptParse_TELTEMPS, NULL, false, PM_FPA_LEVEL_FPA);
-        conceptRegisterF32("FPA.TELTEMP.M2", "Telescope Temperatures: M2", p_pmConceptParse_TELTEMPS, NULL, false, PM_FPA_LEVEL_FPA);
-        conceptRegisterF32("FPA.TELTEMP.SPIDER", "Telescope Temperatures: spider", p_pmConceptParse_TELTEMPS, NULL, false, PM_FPA_LEVEL_FPA);
-        conceptRegisterF32("FPA.TELTEMP.TRUSS", "Telescope Temperatures: truss", p_pmConceptParse_TELTEMPS, NULL, false, PM_FPA_LEVEL_FPA);
-        conceptRegisterF32("FPA.TELTEMP.EXTRA", "Telescope Temperatures: extra", p_pmConceptParse_TELTEMPS, NULL, false, PM_FPA_LEVEL_FPA);
-        conceptRegisterF32("FPA.PON.TIME", "Power On Time", NULL, NULL, false, PM_FPA_LEVEL_FPA);
-        conceptRegisterF32("FPA.EXPOSURE", "Exposure time (sec)", NULL, NULL, false, PM_FPA_LEVEL_FPA);
-    }
-    if (! conceptsChip) {
+        conceptRegisterF32("FPA.TEMP", "Temperature of focal plane", NULL, NULL, NULL, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterF32("FPA.M1X", "Primary Mirror X Position", NULL, NULL, NULL, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterF32("FPA.M1Y", "Primary Mirror Y Position", NULL, NULL, NULL, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterF32("FPA.M1Z", "Primary Mirror Z Position", NULL, NULL, NULL, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterF32("FPA.M1TIP", "Primary Mirror TIP", NULL, NULL, NULL, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterF32("FPA.M1TILT", "Primary Mirror TILT", NULL, NULL, NULL, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterF32("FPA.M2X", "Primary Mirror X Position", NULL, NULL, NULL, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterF32("FPA.M2Y", "Primary Mirror Y Position", NULL, NULL, NULL, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterF32("FPA.M2Z", "Primary Mirror Z Position", NULL, NULL, NULL, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterF32("FPA.M2TIP", "Primary Mirror TIP", NULL, NULL, NULL, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterF32("FPA.M2TILT", "Primary Mirror TILT", NULL, NULL, NULL, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterF32("FPA.ENV.TEMP", "Environment: Temperature", NULL, NULL, NULL, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterF32("FPA.ENV.HUMID", "Environment: Humidity", NULL, NULL, NULL, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterF32("FPA.ENV.WIND", "Environment: Wind speed", NULL, NULL, NULL, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterF32("FPA.ENV.DIR", "Environment: Wind direction", NULL, NULL, NULL, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterF32("FPA.TELTEMP.M1", "Telescope Temperatures: M1", p_pmConceptParse_TELTEMPS, NULL, NULL, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterF32("FPA.TELTEMP.M1CELL", "Telescope Temperatures: M1 cell", p_pmConceptParse_TELTEMPS, NULL, NULL, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterF32("FPA.TELTEMP.M2", "Telescope Temperatures: M2", p_pmConceptParse_TELTEMPS, NULL, NULL, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterF32("FPA.TELTEMP.SPIDER", "Telescope Temperatures: spider", p_pmConceptParse_TELTEMPS, NULL, NULL, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterF32("FPA.TELTEMP.TRUSS", "Telescope Temperatures: truss", p_pmConceptParse_TELTEMPS, NULL, NULL, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterF32("FPA.TELTEMP.EXTRA", "Telescope Temperatures: extra", p_pmConceptParse_TELTEMPS, NULL, NULL, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterF32("FPA.PON.TIME", "Power On Time", NULL, NULL, NULL, false, PM_FPA_LEVEL_FPA);
+        conceptRegisterF32("FPA.EXPOSURE", "Exposure time (sec)", NULL, NULL, NULL, false, PM_FPA_LEVEL_FPA);
+    }
+    if (!conceptsChip) {
         conceptsChip = psMetadataAlloc();
         init = true;
 
         // Install the standard concepts
-        conceptRegisterS32("CHIP.XPARITY", "Orientation in x compared to the rest of the FPA", NULL, NULL, true, PM_FPA_LEVEL_CHIP);
-        conceptRegisterS32("CHIP.YPARITY", "Orientation in y compared to the rest of the FPA", NULL, NULL, true, PM_FPA_LEVEL_CHIP);
-        conceptRegisterS32("CHIP.X0", "Position of (0,0) on the FPA",p_pmConceptParse_Positions,p_pmConceptFormat_Positions, true, PM_FPA_LEVEL_CHIP);
-        conceptRegisterS32("CHIP.Y0", "Position of (0,0) on the FPA",p_pmConceptParse_Positions,p_pmConceptFormat_Positions, true, PM_FPA_LEVEL_CHIP);
-        conceptRegisterS32("CHIP.XSIZE", "Size of chip (pixels)", NULL, NULL, true, PM_FPA_LEVEL_CHIP);
-        conceptRegisterS32("CHIP.YSIZE", "Size of chip (pixels)", NULL, NULL, true, PM_FPA_LEVEL_CHIP);
-        conceptRegisterF32("CHIP.TEMP", "Temperature of chip", NULL, NULL, false, PM_FPA_LEVEL_CHIP);
-        conceptRegisterStr("CHIP.ID", "Chip identifier", NULL, NULL, false, PM_FPA_LEVEL_CHIP);
-    }
-
-    if (! conceptsCell) {
+        conceptRegisterS32("CHIP.XPARITY", "Orientation in x compared to the rest of the FPA", NULL, NULL, NULL, true, PM_FPA_LEVEL_CHIP);
+        conceptRegisterS32("CHIP.YPARITY", "Orientation in y compared to the rest of the FPA", NULL, NULL, NULL, true, PM_FPA_LEVEL_CHIP);
+        conceptRegisterS32("CHIP.X0", "Position of (0,0) on the FPA",p_pmConceptParse_Positions,p_pmConceptFormat_Positions, NULL, true, PM_FPA_LEVEL_CHIP);
+        conceptRegisterS32("CHIP.Y0", "Position of (0,0) on the FPA",p_pmConceptParse_Positions,p_pmConceptFormat_Positions, NULL, true, PM_FPA_LEVEL_CHIP);
+        conceptRegisterS32("CHIP.XSIZE", "Size of chip (pixels)", NULL, NULL, NULL, true, PM_FPA_LEVEL_CHIP);
+        conceptRegisterS32("CHIP.YSIZE", "Size of chip (pixels)", NULL, NULL, NULL, true, PM_FPA_LEVEL_CHIP);
+        conceptRegisterF32("CHIP.TEMP", "Temperature of chip", NULL, NULL, NULL, false, PM_FPA_LEVEL_CHIP);
+        conceptRegisterStr("CHIP.ID", "Chip identifier", NULL, NULL, NULL, false, PM_FPA_LEVEL_CHIP);
+    }
+
+    if (!conceptsCell) {
         conceptsCell = psMetadataAlloc();
         init = true;
 
         // Install the standard concepts
-        conceptRegisterF32("CELL.GAIN", "CCD gain (e/count)", NULL, NULL, true, PM_FPA_LEVEL_CELL);
-        conceptRegisterF32("CELL.READNOISE", "CCD read noise (e)", p_pmConceptParse_CELL_READNOISE, p_pmConceptFormat_CELL_READNOISE, true, PM_FPA_LEVEL_CELL);
-        conceptRegisterF32("CELL.SATURATION", "Saturation level (counts)", NULL, NULL, true, PM_FPA_LEVEL_CELL);
-        conceptRegisterF32("CELL.BAD", "Bad level (counts)", NULL, NULL, true, PM_FPA_LEVEL_CELL);
-        conceptRegisterS32("CELL.XPARITY", "Orientation in x compared to the rest of the chip", NULL, NULL, true, PM_FPA_LEVEL_CELL);
-        conceptRegisterS32("CELL.YPARITY", "Orientation in y compared to the rest of the chip", NULL, NULL, true, PM_FPA_LEVEL_CELL);
-        conceptRegisterS32("CELL.READDIR", "Read direction, rows=1, cols=2", NULL, NULL, true, PM_FPA_LEVEL_CELL);
+        conceptRegisterF32("CELL.GAIN", "CCD gain (e/count)", NULL, NULL, NULL, true, PM_FPA_LEVEL_CELL);
+        conceptRegisterF32("CELL.READNOISE", "CCD read noise (e)", p_pmConceptParse_CELL_READNOISE, p_pmConceptFormat_CELL_READNOISE, NULL, true, PM_FPA_LEVEL_CELL);
+        conceptRegisterF32("CELL.SATURATION", "Saturation level (counts)", NULL, NULL, NULL, true, PM_FPA_LEVEL_CELL);
+        conceptRegisterF32("CELL.BAD", "Bad level (counts)", NULL, NULL, NULL, true, PM_FPA_LEVEL_CELL);
+        conceptRegisterS32("CELL.XPARITY", "Orientation in x compared to the rest of the chip", NULL, NULL, NULL, true, PM_FPA_LEVEL_CELL);
+        conceptRegisterS32("CELL.YPARITY", "Orientation in y compared to the rest of the chip", NULL, NULL, NULL, true, PM_FPA_LEVEL_CELL);
+        conceptRegisterS32("CELL.READDIR", "Read direction, rows=1, cols=2", NULL, NULL, NULL, true, PM_FPA_LEVEL_CELL);
 
         // These (CELL.EXPOSURE and CELL.DARKTIME) used to be READOUT.EXPOSURE and READOUT.DARKTIME, but that
@@ -613,18 +364,18 @@
         // readout is a plane in a 3D image.  We'll have to dream up some additional suffix to specify these,
         // but for now....
-        conceptRegisterF32("CELL.EXPOSURE", "Exposure time (sec)", NULL, NULL, false, PM_FPA_LEVEL_CELL);
-        conceptRegisterF32("CELL.DARKTIME", "Time since flush (sec)", NULL, NULL, false, PM_FPA_LEVEL_CELL);
-
-        conceptRegisterS32("CELL.XBIN", "Binning in x", p_pmConceptParse_CELL_Binning,p_pmConceptFormat_CELL_XBIN, true, PM_FPA_LEVEL_CELL);
-        conceptRegisterS32("CELL.YBIN", "Binning in y",p_pmConceptParse_CELL_Binning,p_pmConceptFormat_CELL_YBIN, true, PM_FPA_LEVEL_CELL);
-        conceptRegisterEnum("CELL.TIMESYS", "Time system", p_pmConceptParse_TIMESYS,p_pmConceptFormat_TIMESYS, false, PM_FPA_LEVEL_CELL);
+        conceptRegisterF32("CELL.EXPOSURE", "Exposure time (sec)", NULL, NULL, NULL, false, PM_FPA_LEVEL_CELL);
+        conceptRegisterF32("CELL.DARKTIME", "Time since flush (sec)", NULL, NULL, NULL, false, PM_FPA_LEVEL_CELL);
+
+        conceptRegisterS32("CELL.XBIN", "Binning in x", p_pmConceptParse_CELL_Binning,p_pmConceptFormat_CELL_XBIN, NULL, true, PM_FPA_LEVEL_CELL);
+        conceptRegisterS32("CELL.YBIN", "Binning in y",p_pmConceptParse_CELL_Binning,p_pmConceptFormat_CELL_YBIN, NULL, true, PM_FPA_LEVEL_CELL);
+        conceptRegisterEnum("CELL.TIMESYS", "Time system", p_pmConceptParse_TIMESYS,p_pmConceptFormat_TIMESYS, p_pmConceptCopy_TIMESYS, false, PM_FPA_LEVEL_CELL);
         conceptRegisterTime("CELL.TIME", "Time of exposure", false, PM_FPA_LEVEL_CELL);
-        conceptRegisterS32("CELL.X0", "Position of (0,0) on the chip",p_pmConceptParse_Positions,p_pmConceptFormat_Positions, true, PM_FPA_LEVEL_CELL);
-        conceptRegisterS32("CELL.Y0", "Position of (0,0) on the chip",p_pmConceptParse_Positions,p_pmConceptFormat_Positions, true, PM_FPA_LEVEL_CELL);
-        conceptRegisterS32("CELL.XSIZE", "Size of cell (pixels)", NULL, NULL, true, PM_FPA_LEVEL_CELL);
-        conceptRegisterS32("CELL.YSIZE", "Size of cell (pixels)", NULL, NULL, true, PM_FPA_LEVEL_CELL);
-        conceptRegisterS32("CELL.XWINDOW", "Start of cell window (pixels)",p_pmConceptParse_Positions,p_pmConceptFormat_Positions, true, PM_FPA_LEVEL_CELL);
-        conceptRegisterS32("CELL.YWINDOW", "Start of cell window (pixels)",p_pmConceptParse_Positions,p_pmConceptFormat_Positions, true, PM_FPA_LEVEL_CELL);
-        conceptRegisterF32("CELL.VARFACTOR", "Variance factor for conversion from large to small scales", NULL, NULL, true, PM_FPA_LEVEL_CELL);
+        conceptRegisterS32("CELL.X0", "Position of (0,0) on the chip",p_pmConceptParse_Positions,p_pmConceptFormat_Positions, NULL, true, PM_FPA_LEVEL_CELL);
+        conceptRegisterS32("CELL.Y0", "Position of (0,0) on the chip",p_pmConceptParse_Positions,p_pmConceptFormat_Positions, NULL, true, PM_FPA_LEVEL_CELL);
+        conceptRegisterS32("CELL.XSIZE", "Size of cell (pixels)", NULL, NULL, NULL, true, PM_FPA_LEVEL_CELL);
+        conceptRegisterS32("CELL.YSIZE", "Size of cell (pixels)", NULL, NULL, NULL, true, PM_FPA_LEVEL_CELL);
+        conceptRegisterS32("CELL.XWINDOW", "Start of cell window (pixels)",p_pmConceptParse_Positions,p_pmConceptFormat_Positions, NULL, true, PM_FPA_LEVEL_CELL);
+        conceptRegisterS32("CELL.YWINDOW", "Start of cell window (pixels)",p_pmConceptParse_Positions,p_pmConceptFormat_Positions, NULL, true, PM_FPA_LEVEL_CELL);
+        conceptRegisterF32("CELL.VARFACTOR", "Variance factor for conversion from large to small scales", NULL, NULL, NULL, true, PM_FPA_LEVEL_CELL);
 
         // CELL.TRIMSEC
@@ -635,5 +386,5 @@
                                           "Trim section", trimsec);
             psFree(trimsec);
-            pmConceptRegister(cellTrimsec, p_pmConceptParse_CELL_TRIMSEC,p_pmConceptFormat_CELL_TRIMSEC, true, PM_FPA_LEVEL_CELL);
+            pmConceptRegister(cellTrimsec, p_pmConceptParse_CELL_TRIMSEC,p_pmConceptFormat_CELL_TRIMSEC, NULL, true, PM_FPA_LEVEL_CELL);
             psFree(cellTrimsec);
         }
@@ -645,5 +396,5 @@
                                           "Bias sections", biassecs);
             psFree(biassecs);
-            pmConceptRegister(cellBiassec, p_pmConceptParse_CELL_BIASSEC, p_pmConceptFormat_CELL_BIASSEC, true, PM_FPA_LEVEL_CELL);
+            pmConceptRegister(cellBiassec, p_pmConceptParse_CELL_BIASSEC, p_pmConceptFormat_CELL_BIASSEC, NULL, true, PM_FPA_LEVEL_CELL);
             psFree(cellBiassec);
         }
@@ -666,169 +417,4 @@
 
     conceptsInitialised = false;
-}
-
-
-// List of concepts not to copy, for each level.
-// Must be NULL-terminated
-static const char *dontCopyConceptsFPA[] = { "FPA.OBS", "FPA.NAME", "FPA.CAMERA", 0 };
-static const char *dontCopyConceptsChip[] = { "CHIP.NAME", 0 };
-static const char *dontCopyConceptsCell[] = { "CELL.NAME", "CELL.TRIMSEC", "CELL.BIASSEC", 0 };
-
-// Copy concepts from a source container to a target container, avoiding certain entries
-static void copyConcepts(psMetadata *target, // Target metadata container
-                         psMetadata *source, // Source metadata container
-                         const char *dontCopyConcepts[] // Don't copy these concepts
-                         )
-{
-    assert(target);
-    assert(source);
-    assert(dontCopyConcepts);
-
-    psMetadataIterator *iter = psMetadataIteratorAlloc(source, PS_LIST_HEAD, NULL);
-    psMetadataItem *item;               // Item from iteration
-    while ((item = psMetadataGetAndIncrement(iter))) {
-        const char *name = item->name;  // Name of concept
-        bool copyOK = true;            // OK to copy
-        for (int i = 0; dontCopyConcepts[i] && copyOK; i++) {
-            if (!strcmp(name, dontCopyConcepts[i])) {
-                copyOK = false;
-            }
-        }
-        if (!copyOK) {
-            continue;
-        }
-        psMetadataItem *new = psMetadataItemCopy(item); // New item, a copy of the old
-        psMetadataAddItem(target, new, PS_LIST_TAIL, PS_META_REPLACE);
-        psFree(new);                    // Drop reference
-    }
-    psFree(iter);
-
-    return;
-}
-
-
-bool pmFPACopyConcepts(pmFPA *target, const pmFPA *source)
-{
-    PS_ASSERT_PTR_NON_NULL(target, false);
-    PS_ASSERT_PTR_NON_NULL(source, false);
-
-    // Copy FPA concepts
-    copyConcepts(target->concepts, source->concepts, dontCopyConceptsFPA);
-
-    // Copy chip concepts
-    psArray *targetChips = target->chips; // Chips in target
-    psArray *sourceChips = source->chips; // Chips in source
-    if (targetChips->n != sourceChips->n) {
-        psError(PS_ERR_IO, true, "Number of chips in target (%ld) and source (%ld) differ --- unable to copy "
-                "concepts.\n", targetChips->n, sourceChips->n);
-        return false;
-    }
-    for (int i = 0; i < targetChips->n; i++) {
-        pmChip *targetChip = targetChips->data[i]; // Target chip of interest
-        pmChip *sourceChip = sourceChips->data[i]; // Source chip of interest
-        if (! targetChip || ! sourceChip) {
-            continue;
-        }
-
-        copyConcepts(targetChip->concepts, sourceChip->concepts, dontCopyConceptsChip);
-
-        // Copy cell concepts
-        psArray *targetCells = targetChip->cells; // Cells in target
-        psArray *sourceCells = sourceChip->cells; // Cells in source
-        if (targetCells->n != sourceCells->n) {
-            psError(PS_ERR_IO, true, "Number of cells in target (%ld) and source (%ld) differ for chip %d ---"
-                    " unable to copy concepts.\n", targetCells->n, sourceCells->n, i);
-            return false;
-        }
-        for (int j = 0; j < targetCells->n; j++) {
-            pmCell *targetCell = targetCells->data[j]; // Target chip of interest
-            pmCell *sourceCell = sourceCells->data[j]; // Source chip of interest
-            if (! targetCell || ! sourceCell) {
-                continue;
-            }
-
-            copyConcepts(targetCell->concepts, sourceCell->concepts, dontCopyConceptsCell);
-        }
-    }
-
-    return true;
-}
-
-
-bool pmConceptsCopyFPA(pmFPA *target, const pmFPA *source, bool chips, bool cells)
-{
-    PS_ASSERT_PTR_NON_NULL(target, false);
-    PS_ASSERT_PTR_NON_NULL(source, false);
-
-    // Copy FPA concepts
-    copyConcepts(target->concepts, source->concepts, dontCopyConceptsFPA);
-
-    // Copy chip concepts
-    bool status = true;                 // Status of chips
-    if (chips) {
-        psArray *targetChips = target->chips; // Chips in target
-        psArray *sourceChips = source->chips; // Chips in source
-        if (targetChips->n != sourceChips->n) {
-            psError(PS_ERR_IO, true,
-                    "Number of chips in target (%ld) and source (%ld) differ --- unable to copy concepts.",
-                    targetChips->n, sourceChips->n);
-            return false;
-        }
-        for (int i = 0; i < targetChips->n; i++) {
-            pmChip *targetChip = targetChips->data[i]; // Target chip of interest
-            pmChip *sourceChip = sourceChips->data[i]; // Source chip of interest
-            if (! targetChip || ! sourceChip) {
-                continue;
-            }
-
-            status &= pmConceptsCopyChip(targetChip, sourceChip, cells);
-        }
-    }
-
-    return status;
-}
-
-bool pmConceptsCopyChip(pmChip *target, const pmChip *source, bool cells)
-{
-    PS_ASSERT_PTR_NON_NULL(target, false);
-    PS_ASSERT_PTR_NON_NULL(source, false);
-
-    // Copy chip concepts
-    copyConcepts(target->concepts, source->concepts, dontCopyConceptsChip);
-
-    // Copy cell concepts
-    bool status = true;                 // Status of cells
-    if (cells) {
-        psArray *targetCells = target->cells; // Cells in target
-        psArray *sourceCells = source->cells; // Cells in source
-        if (targetCells->n != sourceCells->n) {
-            psError(PS_ERR_IO, true,
-                    "Number of cells in target (%ld) and source (%ld) differ --- unable to copy concepts.",
-                    targetCells->n, sourceCells->n);
-            return false;
-        }
-        for (int j = 0; j < targetCells->n; j++) {
-            pmCell *targetCell = targetCells->data[j]; // Target chip of interest
-            pmCell *sourceCell = sourceCells->data[j]; // Source chip of interest
-            if (! targetCell || ! sourceCell) {
-                continue;
-            }
-
-            status &= pmConceptsCopyCell(targetCell, sourceCell);
-        }
-    }
-
-    return status;
-}
-
-
-bool pmConceptsCopyCell(pmCell *target, const pmCell *source)
-{
-    PS_ASSERT_PTR_NON_NULL(target, false);
-    PS_ASSERT_PTR_NON_NULL(source, false);
-
-    copyConcepts(target->concepts, source->concepts, dontCopyConceptsCell);
-
-    return true;
 }
 
Index: /branches/cnb_branches/cnb_branch_20090215/psModules/src/concepts/pmConcepts.h
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/concepts/pmConcepts.h	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psModules/src/concepts/pmConcepts.h	(revision 23197)
@@ -12,4 +12,7 @@
 #define PM_CONCEPTS_H
 
+#include <pslib.h>
+#include <pmFPALevel.h>
+#include <pmFPA.h>
 #include <pmConfig.h>
 
@@ -34,21 +37,34 @@
 
 /// Function to call to parse a concept once it has been read
-typedef psMetadataItem* (*pmConceptParseFunc)(const psMetadataItem *concept, ///< Concept to parse
-        const psMetadataItem *pattern, ///< Pattern for parsing
-                                              pmConceptSource source, ///< Source of concept
-        const psMetadata *cameraFormat, ///< Camera format definition
-        const pmFPA *fpa, ///< FPA for concept, or NULL
-        const pmChip *chip, ///< Chip for concept, or NULL
-        const pmCell *cell ///< Cell for concept, or NULL
-                                             );
+typedef psMetadataItem* (*pmConceptParseFunc)(
+    const psMetadataItem *concept, ///< Concept to parse
+    const psMetadataItem *pattern, ///< Pattern for parsing
+    pmConceptSource source, ///< Source of concept
+    const psMetadata *cameraFormat, ///< Camera format definition
+    const pmFPA *fpa, ///< FPA for concept, or NULL
+    const pmChip *chip, ///< Chip for concept, or NULL
+    const pmCell *cell ///< Cell for concept, or NULL
+    );
 
 /// Function to call to format a concept for writing
-typedef psMetadataItem* (*pmConceptFormatFunc)(const psMetadataItem *concept, ///< Concept to format
-                                               pmConceptSource source, ///< Source of concept
-        const psMetadata *cameraFormat, ///< Camera format definition
-        const pmFPA *fpa, ///< FPA for concept, or NULL
-        const pmChip *chip, ///< Chip for concept, or NULL
-        const pmCell *cell ///< Cell for concept, or NULL
-                                              );
+typedef psMetadataItem* (*pmConceptFormatFunc)(
+    const psMetadataItem *concept, ///< Concept to format
+    pmConceptSource source, ///< Source of concept
+    const psMetadata *cameraFormat, ///< Camera format definition
+    const pmFPA *fpa, ///< FPA for concept, or NULL
+    const pmChip *chip, ///< Chip for concept, or NULL
+    const pmCell *cell ///< Cell for concept, or NULL
+    );
+
+/// Function to call to copy a concept
+typedef psMetadataItem* (*pmConceptCopyFunc)(
+    const psMetadataItem *target,       ///< Target concept
+    const psMetadataItem *source,       ///< Source concept
+    const psMetadata *cameraFormat,     ///< Camera format definition
+    const pmFPA *fpa,                   ///< Source FPA for concept, or NULL
+    const pmChip *chip,                 ///< Source chip for concept, or NULL
+    const pmCell *cell                  ///< Source cell for concept, or NULL
+    );
+
 
 /// A "concept" specification
@@ -56,9 +72,9 @@
 /// Defines the name, default comment, blank value, and functions to parse (after reading) and format (before
 /// writing) the concept.
-typedef struct
-{
+typedef struct {
     psMetadataItem *blank;              ///< Blank value of concept; also contains the name and comment
-    pmConceptParseFunc parse;           ///< Function to call to read the concept
-    pmConceptFormatFunc format;         ///< Function to call to write the concept
+    pmConceptParseFunc parse;           ///< Function to call to read the concept, or NULL
+    pmConceptFormatFunc format;         ///< Function to call to write the concept, or NULL
+    pmConceptCopyFunc copy;             ///< Function to call to copy the concept, or NULL
     bool required;                      ///< Is concept required (throw an error on problems)?
 }
@@ -67,6 +83,7 @@
 /// Allocator for pmConceptSpec
 pmConceptSpec *pmConceptSpecAlloc(psMetadataItem *blank, ///< Blank value; contains the name
-                                  pmConceptParseFunc parse, ///< Function to call to parse the concept
-                                  pmConceptFormatFunc format, ///< Function to call to format the concept
+                                  pmConceptParseFunc parse, ///< Function to call to parse the concept/NULL
+                                  pmConceptFormatFunc format, ///< Function to call to format the concept/NULL
+                                  pmConceptCopyFunc copy, ///< Function to call to copy the concept, or NULL
                                   bool required ///< Is concept required?
                                  );
@@ -92,46 +109,15 @@
                        pmConceptParseFunc parse, ///< Function to call to parse the concept, or NULL
                        pmConceptFormatFunc format, ///< Function to call to format the concept, or NULL
+                       pmConceptCopyFunc copy, ///< Function to call to copy the concept, or NULL
                        bool required,   ///< Is concept required?
                        pmFPALevel level ///< Level at which to store concept in the FPA hierarchy
                       );
 
-/// Get a list of defined concepts for a particular level.
-psList *pmConceptsList(pmFPALevel level);
+/// Get the specifications for defined concepts of a particular level
+psMetadata *pmConceptsSpecs(pmFPALevel level);
 
-/// Read the concepts for the given set of fpa, chip, cell
-///
-/// Attempts to read as many concepts as possible from the specified source for the specified FPA, chip and
-/// cell.  That is, it will read chip- and cell-level concepts in addition to fpa-level concepts, if the chip
-/// and cell are provided.
-bool pmConceptsRead(pmFPA *fpa,         ///< FPA for which to read concepts
-                    pmChip *chip,       ///< Chip for which to read concepts, or NULL
-                    pmCell *cell,       ///< Cell for which to read concepts, or NULL
-                    pmConceptSource source, ///< The source of the concepts to read
-                    pmConfig *config    ///< Configuration
-                   );
 
 /// Set the concepts within the FPA to the blank value
 bool pmConceptsBlankFPA(pmFPA *fpa      ///< FPA for which to set blank concepts
-                       );
-
-/// Read concepts for an FPA; optionally, read concepts at all lower levels.
-///
-/// Once concepts should be available for reading at the FPA-level, this function attempts to read the
-/// concepts from the specified source.  It also allows concepts to be read at lower levels by iterating over
-/// the components.
-bool pmConceptsReadFPA(pmFPA *fpa,      ///< FPA for which to read concepts
-                       pmConceptSource source, ///< Source for concepts
-                       bool propagateDown, ///< Propagate to lower levels?
-                       pmConfig *config         ///< Configuration
-                      );
-
-/// Write concepts for an FPA; optionally, write concepts at all lower levels.
-///
-/// This function writes all concepts for the FPA to the specified "source".  It also allows concepts to be
-/// written for all lower levels by iterating over the components.
-bool pmConceptsWriteFPA(const pmFPA *fpa,     ///< FPA for which to write concepts
-                        pmConceptSource source, ///< Source for concepts
-                        bool propagateDown, ///< Propagate to lower levels?
-                        pmConfig *config        ///< Configuration
                        );
 
@@ -140,51 +126,6 @@
                         );
 
-/// Read concepts for a chip; optionally, read concepts at the FPA and cell levels.
-///
-/// Once concepts should be available for reading at the FPA-level, this function attempts to read the
-/// concepts from the specified source.  It also allows concepts to be read at the fpa level (through the
-/// parent), and the cell level by iterating over the components.
-bool pmConceptsReadChip(pmChip *chip,   ///< Chip for which to read concepts
-                        pmConceptSource source, ///< Source for concepts
-                        bool propagateUp, ///< Propagate to higher levels?
-                        bool propagateDown, ///< Propagate to lower levels?
-                        pmConfig *config        ///< Configuration
-                       );
-
-/// Write concepts for a chip; optionally, write concepts at the FPA and cell levels.
-///
-/// This function writes all concepts for the chip to the specified "source".  It also allows concepts to be
-/// written for the FPA, and the cell level by iterating over the components.
-bool pmConceptsWriteChip(const pmChip *chip,  ///< Chip for which to write concepts
-                         pmConceptSource source, ///< Source for concepts
-                         bool propagateUp,///< Propagate to higher levels?
-                         bool propagateDown, ///< Propagate to lower levels?
-                         pmConfig *config       ///< Configuration
-                        );
-
 /// Set the concepts within the cell to the blank value
 bool pmConceptsBlankCell(pmCell *cell   ///< Cell for which to set blank concepts
-                        );
-
-/// Read concepts for a cell; optionally, read concepts for the parents.
-///
-/// Once concepts should be available for reading at the FPA-level, this function attempts to read the
-/// concepts from the specified source.  It also allows concepts to be read at upper levels through the
-/// parents (note, it would not read concepts for all chips, but only the parent of this cell).
-bool pmConceptsReadCell(pmCell *cell,   ///< Cell for which to read concepts
-                        pmConceptSource source, ///< Source for concepts
-                        bool propagateUp, ///< Propagate to higher levels?
-                        pmConfig *config        ///< Configuration
-                       );
-
-/// Write concepts for a cell; optionally, write concepts for the parents.
-///
-/// This function writes all concepts for the chip to the specified "source".  It also allows concepts to be
-/// written for the upper levels through the parents (note, it would not write concepts for all chips, but
-/// only the parent of this cell).
-bool pmConceptsWriteCell(const pmCell *cell,  ///< FPA for which to write concepts
-                         pmConceptSource source, ///< Source for concepts
-                         bool propagateUp, ///< Propagate to higher levels?
-                         pmConfig *config ///< Configuration
                         );
 
@@ -199,29 +140,4 @@
 /// Frees the registered concepts so there is no memory leak when the user checks "persistent" memory.
 void pmConceptsDone(void);
-
-/// Copy all the concepts within an FPA to another FPA
-///
-/// Iterates over all components of the FPA, and copies the concepts metadata from the source to the target.
-bool pmFPACopyConcepts(pmFPA *target,   ///< The target FPA
-                       const pmFPA *source    ///< The source FPA
-                      );
-
-/// Copy the concepts within an FPA to another FPA; optionally recurse to lower levels
-bool pmConceptsCopyFPA(pmFPA *target,   ///< Target FPA
-                       const pmFPA *source, ///< Source FPA
-                       bool chips,      ///< Recurse to chips level?
-                       bool cells       ///< Recurse to cells level?
-    );
-
-/// Copy the concepts within a chip to another chip; optionally recurse to lower level
-bool pmConceptsCopyChip(pmChip *target, ///< Target chip
-                        const pmChip *source, ///< Source chip
-                        bool cells      ///< Recurse to cells level?
-    );
-
-/// Copy the concepts within a cell to another cell
-bool pmConceptsCopyCell(pmCell *target, ///< Target cell
-                        const pmCell *source ///< Source cell
-    );
 
 /// Interpolate a concept name to the actual value
Index: /branches/cnb_branches/cnb_branch_20090215/psModules/src/concepts/pmConceptsAverage.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/concepts/pmConceptsAverage.c	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psModules/src/concepts/pmConceptsAverage.c	(revision 23197)
@@ -61,4 +61,5 @@
 
         psTime *fpaTime = psMetadataLookupPtr(NULL, fpa->concepts, "FPA.TIME");
+        psTimeConvert(fpaTime, PS_TIME_TAI);
         time       += psTimeToMJD(fpaTime);
         if (num == 1) {
@@ -96,5 +97,7 @@
         psMetadataItem *timeItem = psMetadataLookup(target->concepts, "FPA.TIME");
         psFree(timeItem->data.V);
-        timeItem->data.V = psTimeFromMJD(time);
+        psTime *new = psTimeFromMJD(time);
+        psTimeConvert(new, timeSys);
+        timeItem->data.V = new;
     }
 
@@ -115,7 +118,7 @@
         }
 
-	float value = psMetadataLookupF32(&status, cell->concepts, name);
-	if (!status) continue;
-	if (!isfinite(value)) continue;
+        float value = psMetadataLookupF32(&status, cell->concepts, name);
+        if (!status) continue;
+        if (!isfinite(value)) continue;
 
         sum += value;
@@ -246,5 +249,7 @@
         psMetadataItem *timeItem = psMetadataLookup(target->concepts, "CELL.TIME");
         psFree(timeItem->data.V);
-        timeItem->data.V = psTimeFromMJD(time);
+        psTime *new = psTimeFromMJD(time);
+        psTimeConvert(new, timeSys);
+        timeItem->data.V = new;
     }
 
Index: /branches/cnb_branches/cnb_branch_20090215/psModules/src/concepts/pmConceptsCopy.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/concepts/pmConceptsCopy.c	(revision 23197)
+++ /branches/cnb_branches/cnb_branch_20090215/psModules/src/concepts/pmConceptsCopy.c	(revision 23197)
@@ -0,0 +1,169 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <pslib.h>
+
+#include "pmHDU.h"
+#include "pmHDUUtils.h"
+#include "pmFPA.h"
+#include "pmConcepts.h"
+
+#include "pmConceptsCopy.h"
+
+
+
+// List of concepts not to copy, for each level.
+// Must be NULL-terminated
+static const char *dontCopyConceptsFPA[] = { "FPA.OBS", "FPA.NAME", "FPA.CAMERA", 0 };
+static const char *dontCopyConceptsChip[] = { "CHIP.NAME", 0 };
+static const char *dontCopyConceptsCell[] = { "CELL.NAME", 0 };
+
+// Copy concepts from a source container to a target container, avoiding certain entries
+static bool copyConcepts(psMetadata *target, // Target metadata container
+                         psMetadata *source, // Source metadata container
+                         psMetadata *specs, // Concept specifications
+                         psMetadata *cameraFormat, // Camera format configuration
+                         const pmFPA *fpa,    // FPA of interest
+                         const pmChip *chip,  // Chip of interest, or NULL
+                         const pmCell *cell,  // Cell of interest, or NULL
+                         const char *dontCopyConcepts[] // Don't copy these concepts
+                         )
+{
+    assert(target);
+    assert(source);
+    assert(specs);
+    assert(dontCopyConcepts);
+
+    psMetadataIterator *iter = psMetadataIteratorAlloc(source, PS_LIST_HEAD, NULL);
+    psMetadataItem *sourceItem;         // Item from iteration
+    while ((sourceItem = psMetadataGetAndIncrement(iter))) {
+        const char *name = sourceItem->name;  // Name of concept
+        bool copyOK = true;            // OK to copy
+        for (int i = 0; dontCopyConcepts[i] && copyOK; i++) {
+            if (!strcmp(name, dontCopyConcepts[i])) {
+                copyOK = false;
+            }
+        }
+        if (!copyOK) {
+            continue;
+        }
+
+        bool mdok;                      // Status of MD lookup
+        pmConceptSpec *spec = psMetadataLookupPtr(&mdok, specs, name); // Specification for concept
+        psMetadataItem *copy = NULL;    // Copy of source item
+        if (mdok && spec && spec->copy) {
+            psMetadataItem *targetItem = psMetadataLookup(target, name); // Corresponding item from target
+            copy = spec->copy(targetItem, sourceItem, cameraFormat, fpa, chip, cell);
+            if (!copy) {
+                psError(PS_ERR_UNKNOWN, false, "Unable to copy concept %s", name);
+                return false;
+            }
+        } else {
+            copy = psMetadataItemCopy(sourceItem);
+        }
+        psMetadataAddItem(target, copy, PS_LIST_TAIL, PS_META_REPLACE);
+        psFree(copy);                    // Drop reference
+    }
+    psFree(iter);
+
+    return true;
+}
+
+
+bool pmConceptsCopyFPA(pmFPA *target, const pmFPA *source, bool chips, bool cells)
+{
+    PS_ASSERT_PTR_NON_NULL(target, false);
+    PS_ASSERT_PTR_NON_NULL(source, false);
+
+    psMetadata *specs = pmConceptsSpecs(PM_FPA_LEVEL_FPA); // Concept specifications
+
+    pmHDU *hdu = target->hdu;           // Header data unit
+    psMetadata *format = hdu ? hdu->format : NULL; // Camera format
+
+    // Copy FPA concepts
+    if (!copyConcepts(target->concepts, source->concepts, specs, format,
+                      source, NULL, NULL, dontCopyConceptsFPA)) {
+        return false;
+    }
+
+    // Copy chip concepts
+    bool status = true;                 // Status of chips
+    if (chips) {
+        psArray *targetChips = target->chips; // Chips in target
+        psArray *sourceChips = source->chips; // Chips in source
+        if (targetChips->n != sourceChips->n) {
+            psError(PS_ERR_IO, true,
+                    "Number of chips in target (%ld) and source (%ld) differ --- unable to copy concepts.",
+                    targetChips->n, sourceChips->n);
+            return false;
+        }
+        for (int i = 0; i < targetChips->n; i++) {
+            pmChip *targetChip = targetChips->data[i]; // Target chip of interest
+            pmChip *sourceChip = sourceChips->data[i]; // Source chip of interest
+            if (!targetChip || !sourceChip) {
+                continue;
+            }
+
+            status &= pmConceptsCopyChip(targetChip, sourceChip, cells);
+        }
+    }
+
+    return status;
+}
+
+bool pmConceptsCopyChip(pmChip *target, const pmChip *source, bool cells)
+{
+    PS_ASSERT_PTR_NON_NULL(target, false);
+    PS_ASSERT_PTR_NON_NULL(source, false);
+
+    psMetadata *specs = pmConceptsSpecs(PM_FPA_LEVEL_CHIP); // Concept specifications
+    pmHDU *hdu = pmHDUFromChip(target); // Header data unit
+    psMetadata *format = hdu ? hdu->format : NULL; // Camera format
+
+    // Copy chip concepts
+    if (!copyConcepts(target->concepts, source->concepts, specs, format,
+                      source->parent, source, NULL, dontCopyConceptsChip)) {
+        return false;
+    }
+
+    // Copy cell concepts
+    bool status = true;                 // Status of cells
+    if (cells) {
+        psArray *targetCells = target->cells; // Cells in target
+        psArray *sourceCells = source->cells; // Cells in source
+        if (targetCells->n != sourceCells->n) {
+            psError(PS_ERR_IO, true,
+                    "Number of cells in target (%ld) and source (%ld) differ --- unable to copy concepts.",
+                    targetCells->n, sourceCells->n);
+            return false;
+        }
+        for (int j = 0; j < targetCells->n; j++) {
+            pmCell *targetCell = targetCells->data[j]; // Target chip of interest
+            pmCell *sourceCell = sourceCells->data[j]; // Source chip of interest
+            if (! targetCell || ! sourceCell) {
+                continue;
+            }
+
+            status &= pmConceptsCopyCell(targetCell, sourceCell);
+        }
+    }
+
+    return status;
+}
+
+
+bool pmConceptsCopyCell(pmCell *target, const pmCell *source)
+{
+    PS_ASSERT_PTR_NON_NULL(target, false);
+    PS_ASSERT_PTR_NON_NULL(source, false);
+
+    psMetadata *specs = pmConceptsSpecs(PM_FPA_LEVEL_CHIP); // Concept specifications
+    pmHDU *hdu = pmHDUFromCell(target); // Header data unit
+    psMetadata *format = hdu ? hdu->format : NULL; // Camera format
+
+    return copyConcepts(target->concepts, source->concepts, specs, format,
+                        source->parent->parent, source->parent, source, dontCopyConceptsCell);
+}
Index: /branches/cnb_branches/cnb_branch_20090215/psModules/src/concepts/pmConceptsCopy.h
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/concepts/pmConceptsCopy.h	(revision 23197)
+++ /branches/cnb_branches/cnb_branch_20090215/psModules/src/concepts/pmConceptsCopy.h	(revision 23197)
@@ -0,0 +1,31 @@
+#ifndef PM_CONCEPTS_COPY_H
+#define PM_CONCEPTS_COPY_H
+
+#include <pmFPA.h>
+
+/// Copy all the concepts within an FPA to another FPA
+///
+/// Iterates over all components of the FPA, and copies the concepts metadata from the source to the target.
+bool pmFPACopyConcepts(pmFPA *target,   ///< The target FPA
+                       const pmFPA *source    ///< The source FPA
+                      );
+
+/// Copy the concepts within an FPA to another FPA; optionally recurse to lower levels
+bool pmConceptsCopyFPA(pmFPA *target,   ///< Target FPA
+                       const pmFPA *source, ///< Source FPA
+                       bool chips,      ///< Recurse to chips level?
+                       bool cells       ///< Recurse to cells level?
+    );
+
+/// Copy the concepts within a chip to another chip; optionally recurse to lower level
+bool pmConceptsCopyChip(pmChip *target, ///< Target chip
+                        const pmChip *source, ///< Source chip
+                        bool cells      ///< Recurse to cells level?
+    );
+
+/// Copy the concepts within a cell to another cell
+bool pmConceptsCopyCell(pmCell *target, ///< Target cell
+                        const pmCell *source ///< Source cell
+    );
+
+#endif
Index: /branches/cnb_branches/cnb_branch_20090215/psModules/src/concepts/pmConceptsRead.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/concepts/pmConceptsRead.c	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psModules/src/concepts/pmConceptsRead.c	(revision 23197)
@@ -15,4 +15,6 @@
 #include "pmHDUUtils.h"
 #include "pmConcepts.h"
+#include "pmConceptsUpdate.h"
+
 #include "pmConceptsRead.h"
 
@@ -483,2 +485,193 @@
 }
 
+
+
+// Read all registered concepts for the specified level
+static bool conceptsRead(psMetadata **specs, // One of the concepts specifications
+                         pmFPA *fpa,    // The FPA
+                         pmChip *chip,  // The chip
+                         pmCell *cell, // The cell
+                         unsigned int *read,     // What's already been read
+                         pmConceptSource source, // The source of the concepts to read
+                         pmConfig *config, // Configuration
+                         psMetadata *target // Place into which to read the concepts
+                        )
+{
+    assert(specs);
+    assert(read);
+    assert(target);
+
+    pmConceptsInit();
+
+    // At least one HDU is required for the reading functions
+    pmHDU *hduLow = pmHDUGetLowest(fpa, chip, cell); // Lowest HDU.
+    if (!hduLow) {
+        // Can't do anything --- don't record any success, but don't return an error either
+        return true;
+    }
+    pmHDU *hduHigh = pmHDUGetHighest(fpa, chip, cell); // Highest HDU
+
+    if (cell && (cell->conceptsRead == PM_CONCEPT_SOURCE_NONE)) {
+        pmConceptsBlankCell(cell);
+        cell->conceptsRead = PM_CONCEPT_SOURCE_BLANK;
+    }
+    if (chip && (chip->conceptsRead == PM_CONCEPT_SOURCE_NONE)) {
+        pmConceptsBlankChip(chip);
+        chip->conceptsRead = PM_CONCEPT_SOURCE_BLANK;
+    }
+    if (fpa && (fpa->conceptsRead == PM_CONCEPT_SOURCE_NONE)) {
+        pmConceptsBlankFPA(fpa);
+        fpa->conceptsRead = PM_CONCEPT_SOURCE_BLANK;
+    }
+
+    bool success = true;                // Success in reading concepts?
+    if (source & PM_CONCEPT_SOURCE_CELLS && !(*read & PM_CONCEPT_SOURCE_CELLS) && cell) {
+        if (p_pmConceptsReadFromCells(target, *specs, cell)) {
+            *read |= PM_CONCEPT_SOURCE_CELLS;
+        } else {
+            psError(PS_ERR_UNKNOWN, false, "Error reading concepts from camera configuration.\n");
+            success = false;
+        }
+    }
+
+    if (source & PM_CONCEPT_SOURCE_DEFAULTS && !(*read & PM_CONCEPT_SOURCE_DEFAULTS)) {
+        if (p_pmConceptsReadFromDefaults(target, *specs, fpa, chip, cell)) {
+            *read |= PM_CONCEPT_SOURCE_DEFAULTS;
+        } else {
+            psError(PS_ERR_UNKNOWN, false, "Error reading concepts from defaults.\n");
+            success = false;
+        }
+    }
+
+    if (source & PM_CONCEPT_SOURCE_PHU && !(*read & PM_CONCEPT_SOURCE_PHU) && hduHigh->header) {
+        if (p_pmConceptsReadFromHeader(target, *specs, fpa, chip, cell)) {
+            *read |= PM_CONCEPT_SOURCE_PHU;
+        } else {
+            psError(PS_ERR_UNKNOWN, false, "Error reading concepts from PHU.\n");
+            success = false;
+        }
+    }
+
+    // If there are multiple HDUs, then it may be that one of them hasn't been read yet (hdu->header not set)
+    if (source & PM_CONCEPT_SOURCE_HEADER && !(*read & PM_CONCEPT_SOURCE_HEADER) &&
+        hduLow != hduHigh && hduLow->header) {
+        if (p_pmConceptsReadFromHeader(target, *specs, fpa, chip, cell)) {
+            *read |= PM_CONCEPT_SOURCE_HEADER;
+        } else {
+            psError(PS_ERR_UNKNOWN, false, "Error reading concepts from header.\n");
+            success = false;
+        }
+    }
+
+#ifdef HAVE_PSDB
+    if (source & PM_CONCEPT_SOURCE_DATABASE && !(*read & PM_CONCEPT_SOURCE_DATABASE)) {
+        if (p_pmConceptsReadFromDatabase(target, *specs, fpa, chip, cell, config)) {
+            *read |= PM_CONCEPT_SOURCE_DATABASE;
+        } else {
+            psError(PS_ERR_UNKNOWN, false, "Error reading concepts from database.\n");
+            success = false;
+        }
+    }
+#endif
+
+    pmConceptsUpdate(fpa, chip, cell);
+
+    return success;
+}
+
+
+
+
+bool pmConceptsRead(pmFPA *fpa, pmChip *chip, pmCell *cell, pmConceptSource source, pmConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(fpa, false);
+    psMetadata *conceptsFPA = pmConceptsSpecs(PM_FPA_LEVEL_FPA); // Concept specifications
+    bool success = conceptsRead(&conceptsFPA, fpa, chip, cell, &fpa->conceptsRead, source,
+                                config, fpa->concepts);
+    if (chip) {
+        psMetadata *conceptsChip = pmConceptsSpecs(PM_FPA_LEVEL_CHIP); // Concept specifications
+        success &= conceptsRead(&conceptsChip, fpa, chip, cell, &chip->conceptsRead, source,
+                                config, chip->concepts);
+    }
+    if (cell) {
+        psMetadata *conceptsCell = pmConceptsSpecs(PM_FPA_LEVEL_CELL); // Concept specifications
+        success &= conceptsRead(&conceptsCell, fpa, chip, cell, &cell->conceptsRead, source,
+                                config, cell->concepts);
+    }
+
+    return success;
+}
+
+
+
+bool pmConceptsReadFPA(pmFPA *fpa, pmConceptSource source, bool propagateDown, pmConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(fpa, false);
+    psMetadata *conceptsFPA = pmConceptsSpecs(PM_FPA_LEVEL_FPA); // Concept specifications
+    psTrace("psModules.concepts", 5, "Reading FPA concepts: %p %p\n", conceptsFPA, fpa->concepts);
+    bool success = conceptsRead(&conceptsFPA, fpa, NULL, NULL, &fpa->conceptsRead, source,
+                                config, fpa->concepts);
+    if (propagateDown) {
+        psArray *chips = fpa->chips;    // Array of chips
+        for (long i = 0; i < chips->n; i++) {
+            pmChip *chip = chips->data[i]; // Chip of interest
+            if (chip) {
+                success &= pmConceptsReadChip(chip, source, false, true, config);
+            }
+        }
+    }
+
+    return success;
+}
+
+
+
+bool pmConceptsReadChip(pmChip *chip, pmConceptSource source, bool propagateUp,
+                        bool propagateDown, pmConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(chip, false);
+    psMetadata *conceptsChip = pmConceptsSpecs(PM_FPA_LEVEL_CHIP); // Concept specifications
+    psTrace("psModules.concepts", 5, "Reading chip concepts: %p %p\n", conceptsChip, chip->concepts);
+    pmFPA *fpa = chip->parent;          // FPA to which the chip belongs
+    bool success = conceptsRead(&conceptsChip, fpa, chip, NULL, &chip->conceptsRead, source, config,
+                                chip->concepts);
+    if (propagateUp) {
+        psMetadata *conceptsFPA = pmConceptsSpecs(PM_FPA_LEVEL_FPA); // Concept specifications
+        success &= conceptsRead(&conceptsFPA, fpa, chip, NULL, &fpa->conceptsRead, source,
+                                config, fpa->concepts);
+    }
+    if (propagateDown) {
+        psArray *cells = chip->cells;        // Array of cells
+        for (long i = 0; i < cells->n; i++) {
+            pmCell *cell = cells->data[i];  // Cell of interest
+            if (cell) {
+                success &= pmConceptsReadCell(cell, source, false, config);
+            }
+        }
+    }
+    return success;
+}
+
+
+bool pmConceptsReadCell(pmCell *cell, pmConceptSource source, bool propagateUp, pmConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(cell, false);
+    psMetadata *conceptsCell = pmConceptsSpecs(PM_FPA_LEVEL_CELL); // Concept specifications
+    psTrace("psModules.concepts", 5, "Reading cell concepts: %p %p\n", conceptsCell, cell->concepts);
+    pmChip *chip = cell->parent;        // Chip to which the cell belongs
+    pmFPA *fpa = chip->parent;          // FPA to which the chip belongs
+
+    bool success = conceptsRead(&conceptsCell, fpa, chip, cell, &cell->conceptsRead, source, config,
+                                cell->concepts);
+    if (propagateUp) {
+        psMetadata *conceptsChip = pmConceptsSpecs(PM_FPA_LEVEL_CHIP); // Concept specifications
+        success &= conceptsRead(&conceptsChip, fpa, chip, cell, &chip->conceptsRead, source, config,
+                                chip->concepts);
+        psMetadata *conceptsFPA = pmConceptsSpecs(PM_FPA_LEVEL_FPA); // Concept specifications
+
+        success &= conceptsRead(&conceptsFPA, fpa, chip, cell, &fpa->conceptsRead, source, config,
+                                fpa->concepts);
+    }
+
+    return success;
+}
Index: /branches/cnb_branches/cnb_branch_20090215/psModules/src/concepts/pmConceptsRead.h
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/concepts/pmConceptsRead.h	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psModules/src/concepts/pmConceptsRead.h	(revision 23197)
@@ -11,4 +11,9 @@
 #ifndef PM_CONCEPTS_READ_H
 #define PM_CONCEPTS_READ_H
+
+#include <pslib.h>
+#include <pmFPA.h>
+#include <pmConfig.h>
+#include <pmConcepts.h>
 
 /// Read concepts from the camera format file's CELLS.
@@ -79,4 +84,51 @@
                                   pmConfig *config // Configuration
                                  );
+
+/// Read the concepts for the given set of fpa, chip, cell
+///
+/// Attempts to read as many concepts as possible from the specified source for the specified FPA, chip and
+/// cell.  That is, it will read chip- and cell-level concepts in addition to fpa-level concepts, if the chip
+/// and cell are provided.
+bool pmConceptsRead(pmFPA *fpa,         ///< FPA for which to read concepts
+                    pmChip *chip,       ///< Chip for which to read concepts, or NULL
+                    pmCell *cell,       ///< Cell for which to read concepts, or NULL
+                    pmConceptSource source, ///< The source of the concepts to read
+                    pmConfig *config    ///< Configuration
+                   );
+
+/// Read concepts for an FPA; optionally, read concepts at all lower levels.
+///
+/// Once concepts should be available for reading at the FPA-level, this function attempts to read the
+/// concepts from the specified source.  It also allows concepts to be read at lower levels by iterating over
+/// the components.
+bool pmConceptsReadFPA(pmFPA *fpa,      ///< FPA for which to read concepts
+                       pmConceptSource source, ///< Source for concepts
+                       bool propagateDown, ///< Propagate to lower levels?
+                       pmConfig *config         ///< Configuration
+                      );
+
+/// Read concepts for a chip; optionally, read concepts at the FPA and cell levels.
+///
+/// Once concepts should be available for reading at the FPA-level, this function attempts to read the
+/// concepts from the specified source.  It also allows concepts to be read at the fpa level (through the
+/// parent), and the cell level by iterating over the components.
+bool pmConceptsReadChip(pmChip *chip,   ///< Chip for which to read concepts
+                        pmConceptSource source, ///< Source for concepts
+                        bool propagateUp, ///< Propagate to higher levels?
+                        bool propagateDown, ///< Propagate to lower levels?
+                        pmConfig *config        ///< Configuration
+                       );
+
+/// Read concepts for a cell; optionally, read concepts for the parents.
+///
+/// Once concepts should be available for reading at the FPA-level, this function attempts to read the
+/// concepts from the specified source.  It also allows concepts to be read at upper levels through the
+/// parents (note, it would not read concepts for all chips, but only the parent of this cell).
+bool pmConceptsReadCell(pmCell *cell,   ///< Cell for which to read concepts
+                        pmConceptSource source, ///< Source for concepts
+                        bool propagateUp, ///< Propagate to higher levels?
+                        pmConfig *config        ///< Configuration
+                       );
+
 /// @}
 #endif
Index: /branches/cnb_branches/cnb_branch_20090215/psModules/src/concepts/pmConceptsStandard.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/concepts/pmConceptsStandard.c	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psModules/src/concepts/pmConceptsStandard.c	(revision 23197)
@@ -116,5 +116,5 @@
                         if (!isfinite(gain)) {
                             psWarning("CELL.READNOISE is supposed to be in ADU, but CELL.GAIN isn't set -- forcing to 1.0");
-			    gain = 1.0;
+                            gain = 1.0;
                         }
                         rn /= gain;
@@ -639,4 +639,36 @@
 }
 
+// Determine the corresponding TIMESYS for one of the TIME concepts
+static psTimeType conceptGetTimesysForTime(const char *name, // Concept name ("CELL.TIME" or "FPA.TIME")
+                                           const pmFPA *fpa, // FPA of interest
+                                           const pmChip *chip, // Chip of interest, or NULL
+                                           const pmCell *cell // Cell of interest, or NULL
+                                           )
+{
+    assert(name);
+
+    psString timesysName = psStringCopy(name); // e.g., "CELL.TIME" --> "CELL.TIMESYS"
+    psStringSubstitute(&timesysName, "TIMESYS", "TIME");
+    bool mdok = false;                  // Result of MD lookup
+    psTimeType timeSys = 0xFFFFFFFF;    // The time system
+    if (cell) {
+        timeSys = psMetadataLookupS32(&mdok, cell->concepts, timesysName);
+    }
+    if (!mdok && chip) {
+        timeSys = psMetadataLookupS32(&mdok, chip->concepts, timesysName);
+    }
+    if (!mdok && fpa) {
+        timeSys = psMetadataLookupS32(&mdok, fpa->concepts, timesysName);
+    }
+    if (!mdok || (timeSys == 0xFFFFFFFF)) {
+        psWarning("Unable to find %s in concepts when parsing %s --- assuming UTC.\n",
+                  timesysName, name);
+        timeSys = PS_TIME_UTC;
+    }
+    psFree(timesysName);
+
+    return timeSys;
+}
+
 psMetadataItem *p_pmConceptParse_TIME(const psMetadataItem *concept,
                                       const psMetadataItem *pattern,
@@ -650,24 +682,5 @@
     assert(cameraFormat);
 
-    // Need TIMESYS first
-    psString timesysName = psStringCopy(pattern->name); // e.g., "CELL.TIME" --> "CELL.TIMESYS"
-    psStringSubstitute(&timesysName, "TIMESYS", "TIME");
-    bool mdok = false;                  // Result of MD lookup
-    psTimeType timeSys = PS_TIME_UTC; // The time system
-    if (cell) {
-        timeSys = psMetadataLookupS32(&mdok, cell->concepts, timesysName);
-    }
-    if (!mdok && chip) {
-        timeSys = psMetadataLookupS32(&mdok, chip->concepts, timesysName);
-    }
-    if (!mdok && fpa) {
-        timeSys = psMetadataLookupS32(&mdok, fpa->concepts, timesysName);
-    }
-    if (!mdok || (timeSys == 0xffffffff)) {
-        psWarning("Unable to find %s in concepts when parsing %s --- assuming UTC.\n",
-                  timesysName, pattern->name);
-        timeSys = PS_TIME_UTC;
-    }
-    psFree(timesysName);
+    psTimeType timeSys = conceptGetTimesysForTime(pattern->name, fpa, chip, cell); // Time system
 
     // Work out how the time is represented
@@ -681,4 +694,5 @@
 
     // Get format
+    bool mdok;                          // Status of MD lookup
     psMetadata *formats = psMetadataLookupMetadata(&mdok, cameraFormat, "FORMATS");
     if (!mdok || !formats) {
@@ -877,4 +891,6 @@
     }
 
+    time->type = timeSys;
+
     psMetadataItem *item = psMetadataItemAllocPtr(pattern->name, PS_DATA_TIME, pattern->comment, time);
     psFree(time);                       // Drop reference
@@ -1132,4 +1148,7 @@
 {
     psTime *time = concept->data.V;     // The time
+
+    psTimeType timeSys = conceptGetTimesysForTime(concept->name, fpa, chip, cell); // Time system
+    psTimeConvert(time, timeSys);
 
     // Work out the format
@@ -1331,2 +1350,16 @@
 
 
+psMetadataItem *p_pmConceptCopy_TIMESYS(const psMetadataItem *target,
+                                        const psMetadataItem *source,
+                                        const psMetadata *cameraFormat,
+                                        const pmFPA *fpa,
+                                        const pmChip *chip,
+                                        const pmCell *cell)
+{
+    if (!target || target->data.S32 == -1) {
+        // Replace
+        return psMetadataItemCopy(source);
+    }
+    // Keep what we've got --- it's been mandated by use of the DEFAULTS
+    return psMemIncrRefCounter((psMetadataItem*)target);
+}
Index: /branches/cnb_branches/cnb_branch_20090215/psModules/src/concepts/pmConceptsStandard.h
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/concepts/pmConceptsStandard.h	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psModules/src/concepts/pmConceptsStandard.h	(revision 23197)
@@ -20,189 +20,223 @@
 
 /// Parse the CELL.READNOISE concept to do ADU->e correction if required
-psMetadataItem *p_pmConceptParse_CELL_READNOISE(const psMetadataItem *concept,
-                                                const psMetadataItem *pattern,
-                                                pmConceptSource source,
-                                                const psMetadata *cameraFormat,
-                                                const pmFPA *fpa,
-                                                const pmChip *chip,
-                                                const pmCell *cell);
+psMetadataItem *p_pmConceptParse_CELL_READNOISE(
+    const psMetadataItem *concept,
+    const psMetadataItem *pattern,
+    pmConceptSource source,
+    const psMetadata *cameraFormat,
+    const pmFPA *fpa,
+    const pmChip *chip,
+    const pmCell *cell
+);
 
 /// Format the CELL.READNOISE concept to do e->ADU correction if required
-psMetadataItem *p_pmConceptFormat_CELL_READNOISE(const psMetadataItem *concept,
-                                                 pmConceptSource source,
-                                                 const psMetadata *cameraFormat,
-                                                 const pmFPA *fpa,
-                                                 const pmChip *chip,
-                                                 const pmCell *cell);
+psMetadataItem *p_pmConceptFormat_CELL_READNOISE(
+    const psMetadataItem *concept,
+    pmConceptSource source,
+    const psMetadata *cameraFormat,
+    const pmFPA *fpa,
+    const pmChip *chip,
+    const pmCell *cell
+    );
 
 // Parse the TELTEMPS concept : parse a list of the form 'X1 X2 X3 X4 X5 ...' : for now use median
-psMetadataItem *p_pmConceptParse_TELTEMPS(const psMetadataItem *concept,
-                                          const psMetadataItem *pattern,
-                                          pmConceptSource source,
-                                          const psMetadata *cameraFormat,
-                                          const pmFPA *fpa,
-                                          const pmChip *chip,
-                                          const pmCell *cell);
+psMetadataItem *p_pmConceptParse_TELTEMPS(
+    const psMetadataItem *concept,
+    const psMetadataItem *pattern,
+    pmConceptSource source,
+    const psMetadata *cameraFormat,
+    const pmFPA *fpa,
+    const pmChip *chip,
+    const pmCell *cell
+    );
 
 /// Parse the FPA.FILTER concept to apply a lookup table
-psMetadataItem *p_pmConceptParse_FPA_FILTER(const psMetadataItem *concept, ///< Concept to parse
-        const psMetadataItem *pattern, ///< Pattern to use in parsing
-                                            pmConceptSource source, ///< Source for concept
-        const psMetadata *cameraFormat, ///< Camera format definition
-        const pmFPA *fpa, ///< FPA for concept, or NULL
-        const pmChip *chip, ///< Chip for concept, or NULL
-        const pmCell *cell ///< Cell for concept, or NULL
-                                           );
+psMetadataItem *p_pmConceptParse_FPA_FILTER(
+    const psMetadataItem *concept, ///< Concept to parse
+    const psMetadataItem *pattern, ///< Pattern to use in parsing
+    pmConceptSource source, ///< Source for concept
+    const psMetadata *cameraFormat, ///< Camera format definition
+    const pmFPA *fpa, ///< FPA for concept, or NULL
+    const pmChip *chip, ///< Chip for concept, or NULL
+    const pmCell *cell ///< Cell for concept, or NULL
+    );
 
 /// Format the FPA.FILTER concept to (reverse-)apply a lookup table
-psMetadataItem *p_pmConceptFormat_FPA_FILTER(const psMetadataItem *concept, ///< Concept to format
-                                            pmConceptSource source, ///< Source for concept
-        const psMetadata *cameraFormat, ///< Camera format definition
-        const pmFPA *fpa, ///< FPA for concept, or NULL
-        const pmChip *chip, ///< Chip for concept, or NULL
-        const pmCell *cell ///< Cell for concept, or NULL
-                                            );
+psMetadataItem *p_pmConceptFormat_FPA_FILTER(
+    const psMetadataItem *concept, ///< Concept to format
+    pmConceptSource source, ///< Source for concept
+    const psMetadata *cameraFormat, ///< Camera format definition
+    const pmFPA *fpa, ///< FPA for concept, or NULL
+    const pmChip *chip, ///< Chip for concept, or NULL
+    const pmCell *cell ///< Cell for concept, or NULL
+    );
 
 /// Parse the coordinates concepts: FPA.RA and FPA.DEC
-psMetadataItem *p_pmConceptParse_FPA_Coords(const psMetadataItem *concept, ///< Concept to parse
-        const psMetadataItem *pattern, ///< Pattern to use in parsing
-                                            pmConceptSource source, ///< Source for concept
-        const psMetadata *cameraFormat, ///< Camera format definition
-        const pmFPA *fpa, ///< FPA for concept, or NULL
-        const pmChip *chip, ///< Chip for concept, or NULL
-        const pmCell *cell ///< Cell for concept, or NULL
-                                           );
+psMetadataItem *p_pmConceptParse_FPA_Coords(
+    const psMetadataItem *concept, ///< Concept to parse
+    const psMetadataItem *pattern, ///< Pattern to use in parsing
+    pmConceptSource source, ///< Source for concept
+    const psMetadata *cameraFormat, ///< Camera format definition
+    const pmFPA *fpa, ///< FPA for concept, or NULL
+    const pmChip *chip, ///< Chip for concept, or NULL
+    const pmCell *cell ///< Cell for concept, or NULL
+    );
 
 /// Format the coordinates concepts: FPA.RA and FPA.DEC
-psMetadataItem *p_pmConceptFormat_FPA_Coords(const psMetadataItem *concept, ///< Concept to format
-                                            pmConceptSource source, ///< Source for concept
-        const psMetadata *cameraFormat, ///< Camera format definition
-        const pmFPA *fpa, ///< FPA for concept, or NULL
-        const pmChip *chip, ///< Chip for concept, or NULL
-        const pmCell *cell ///< Cell for concept, or NULL
-                                            );
+psMetadataItem *p_pmConceptFormat_FPA_Coords(
+    const psMetadataItem *concept, ///< Concept to format
+    pmConceptSource source, ///< Source for concept
+    const psMetadata *cameraFormat, ///< Camera format definition
+    const pmFPA *fpa, ///< FPA for concept, or NULL
+    const pmChip *chip, ///< Chip for concept, or NULL
+    const pmCell *cell ///< Cell for concept, or NULL
+    );
 
 /// Parse the CELL.TRIMSEC concept
-psMetadataItem *p_pmConceptParse_CELL_TRIMSEC(const psMetadataItem *concept, ///< Concept to parse
-        const psMetadataItem *pattern, ///< Pattern to use in parsing
-                                            pmConceptSource source, ///< Source for concept
-        const psMetadata *cameraFormat, ///< Camera format definition
-        const pmFPA *fpa, ///< FPA for concept, or NULL
-        const pmChip *chip, ///< Chip for concept, or NULL
-        const pmCell *cell ///< Cell for concept, or NULL
-                                             );
+psMetadataItem *p_pmConceptParse_CELL_TRIMSEC(
+    const psMetadataItem *concept, ///< Concept to parse
+    const psMetadataItem *pattern, ///< Pattern to use in parsing
+    pmConceptSource source, ///< Source for concept
+    const psMetadata *cameraFormat, ///< Camera format definition
+    const pmFPA *fpa, ///< FPA for concept, or NULL
+    const pmChip *chip, ///< Chip for concept, or NULL
+    const pmCell *cell ///< Cell for concept, or NULL
+    );
 
 /// Parse the CELL.BIASSEC concept
-psMetadataItem *p_pmConceptParse_CELL_BIASSEC(const psMetadataItem *concept, ///< Concept to parse
-        const psMetadataItem *pattern, ///< Pattern to use in parsing
-                                            pmConceptSource source, ///< Source for concept
-        const psMetadata *cameraFormat, ///< Camera format definition
-        const pmFPA *fpa, ///< FPA for concept, or NULL
-        const pmChip *chip, ///< Chip for concept, or NULL
-        const pmCell *cell ///< Cell for concept, or NULL
-                                             );
+psMetadataItem *p_pmConceptParse_CELL_BIASSEC(
+    const psMetadataItem *concept, ///< Concept to parse
+    const psMetadataItem *pattern, ///< Pattern to use in parsing
+    pmConceptSource source, ///< Source for concept
+    const psMetadata *cameraFormat, ///< Camera format definition
+    const pmFPA *fpa, ///< FPA for concept, or NULL
+    const pmChip *chip, ///< Chip for concept, or NULL
+    const pmCell *cell ///< Cell for concept, or NULL
+    );
 
 /// Parse the cell binning concepts: CELL.XBIN, CELL.YBIN
-psMetadataItem *p_pmConceptParse_CELL_Binning(const psMetadataItem *concept, ///< Concept to parse
-        const psMetadataItem *pattern, ///< Pattern to use in parsing
-                                            pmConceptSource source, ///< Source for concept
-        const psMetadata *cameraFormat, ///< Camera format definition
-        const pmFPA *fpa, ///< FPA for concept, or NULL
-        const pmChip *chip, ///< Chip for concept, or NULL
-        const pmCell *cell ///< Cell for concept, or NULL
-                                             );
+psMetadataItem *p_pmConceptParse_CELL_Binning(
+    const psMetadataItem *concept, ///< Concept to parse
+    const psMetadataItem *pattern, ///< Pattern to use in parsing
+    pmConceptSource source, ///< Source for concept
+    const psMetadata *cameraFormat, ///< Camera format definition
+    const pmFPA *fpa, ///< FPA for concept, or NULL
+    const pmChip *chip, ///< Chip for concept, or NULL
+    const pmCell *cell ///< Cell for concept, or NULL
+    );
 
 /// Parse the time system concepts: FPA.TIMESYS and CELL.TIMESYS
-psMetadataItem *p_pmConceptParse_TIMESYS(const psMetadataItem *concept, ///< Concept to parse
-        const psMetadataItem *pattern, ///< Pattern to use in parsing
-                                            pmConceptSource source, ///< Source for concept
-        const psMetadata *cameraFormat, ///< Camera format definition
-        const pmFPA *fpa, ///< FPA for concept, or NULL
-        const pmChip *chip, ///< Chip for concept, or NULL
-        const pmCell *cell ///< Cell for concept, or NULL
-                                        );
+psMetadataItem *p_pmConceptParse_TIMESYS(
+    const psMetadataItem *concept, ///< Concept to parse
+    const psMetadataItem *pattern, ///< Pattern to use in parsing
+    pmConceptSource source, ///< Source for concept
+    const psMetadata *cameraFormat, ///< Camera format definition
+    const pmFPA *fpa, ///< FPA for concept, or NULL
+    const pmChip *chip, ///< Chip for concept, or NULL
+    const pmCell *cell ///< Cell for concept, or NULL
+    );
 
 /// Parse the time concepts: FPA.TIME and CELL.TIME
-psMetadataItem *p_pmConceptParse_TIME(const psMetadataItem *concept, ///< Concept to parse
-                                      const psMetadataItem *pattern, ///< Pattern to use in parsing
-                                            pmConceptSource source, ///< Source for concept
-                                      const psMetadata *cameraFormat, ///< Camera format definition
-                                      const pmFPA *fpa, ///< FPA for concept, or NULL
-                                      const pmChip *chip, ///< Chip for concept, or NULL
-                                      const pmCell *cell ///< Cell for concept, or NULL
-                                     );
+psMetadataItem *p_pmConceptParse_TIME(
+    const psMetadataItem *concept, ///< Concept to parse
+    const psMetadataItem *pattern, ///< Pattern to use in parsing
+    pmConceptSource source, ///< Source for concept
+    const psMetadata *cameraFormat, ///< Camera format definition
+    const pmFPA *fpa, ///< FPA for concept, or NULL
+    const pmChip *chip, ///< Chip for concept, or NULL
+    const pmCell *cell ///< Cell for concept, or NULL
+    );
 
 /// Parse a cell position concept, e.g., CELL.X0
-psMetadataItem *p_pmConceptParse_Positions(const psMetadataItem *concept, ///< Concept to parse
-        const psMetadataItem *pattern, ///< Pattern to use in parsing
-                                            pmConceptSource source, ///< Source for concept
-       const psMetadata *cameraFormat, ///< Camera format definition
-        const pmFPA *fpa, ///< FPA for concept, or NULL
-        const pmChip *chip, ///< Chip for concept, or NULL
-        const pmCell *cell ///< Cell for concept, or NULL
-                                          );
+psMetadataItem *p_pmConceptParse_Positions(
+    const psMetadataItem *concept, ///< Concept to parse
+    const psMetadataItem *pattern, ///< Pattern to use in parsing
+    pmConceptSource source, ///< Source for concept
+    const psMetadata *cameraFormat, ///< Camera format definition
+    const pmFPA *fpa, ///< FPA for concept, or NULL
+    const pmChip *chip, ///< Chip for concept, or NULL
+    const pmCell *cell ///< Cell for concept, or NULL
+    );
 
 /// Format the CELL.TRIMSEC concept
-psMetadataItem *p_pmConceptFormat_CELL_TRIMSEC(const psMetadataItem *concept, ///< Concept to format
-                                            pmConceptSource source, ///< Source for concept
-        const psMetadata *cameraFormat, ///< Camera format definition
-        const pmFPA *fpa, ///< FPA for concept, or NULL
-        const pmChip *chip, ///< Chip for concept, or NULL
-        const pmCell *cell ///< Cell for concept, or NULL
-                                              );
+psMetadataItem *p_pmConceptFormat_CELL_TRIMSEC(
+    const psMetadataItem *concept, ///< Concept to format
+    pmConceptSource source, ///< Source for concept
+    const psMetadata *cameraFormat, ///< Camera format definition
+    const pmFPA *fpa, ///< FPA for concept, or NULL
+    const pmChip *chip, ///< Chip for concept, or NULL
+    const pmCell *cell ///< Cell for concept, or NULL
+    );
 
 /// Format the CELL.BIASSEC concept
-psMetadataItem *p_pmConceptFormat_CELL_BIASSEC(const psMetadataItem *concept, ///< Concept to format
-                                            pmConceptSource source, ///< Source for concept
-        const psMetadata *cameraFormat, ///< Camera format definition
-        const pmFPA *fpa, ///< FPA for concept, or NULL
-        const pmChip *chip, ///< Chip for concept, or NULL
-        const pmCell *cell ///< Cell for concept, or NULL
-                                              );
+psMetadataItem *p_pmConceptFormat_CELL_BIASSEC(
+    const psMetadataItem *concept, ///< Concept to format
+    pmConceptSource source, ///< Source for concept
+    const psMetadata *cameraFormat, ///< Camera format definition
+    const pmFPA *fpa, ///< FPA for concept, or NULL
+    const pmChip *chip, ///< Chip for concept, or NULL
+    const pmCell *cell ///< Cell for concept, or NULL
+    );
 
 /// Format the CELL.XBIN concept
-psMetadataItem *p_pmConceptFormat_CELL_XBIN(const psMetadataItem *concept, ///< Concept to format
-                                            pmConceptSource source, ///< Source for concept
-        const psMetadata *cameraFormat, ///< Camera format definition
-        const pmFPA *fpa, ///< FPA for concept, or NULL
-        const pmChip *chip, ///< Chip for concept, or NULL
-        const pmCell *cell ///< Cell for concept, or NULL
-                                           );
+psMetadataItem *p_pmConceptFormat_CELL_XBIN(
+    const psMetadataItem *concept, ///< Concept to format
+    pmConceptSource source, ///< Source for concept
+    const psMetadata *cameraFormat, ///< Camera format definition
+    const pmFPA *fpa, ///< FPA for concept, or NULL
+    const pmChip *chip, ///< Chip for concept, or NULL
+    const pmCell *cell ///< Cell for concept, or NULL
+    );
 
 /// Format the CELL.YBIN concept
-psMetadataItem *p_pmConceptFormat_CELL_YBIN(const psMetadataItem *concept, ///< Concept to format
-                                            pmConceptSource source, ///< Source for concept
-        const psMetadata *cameraFormat, ///< Camera format definition
-        const pmFPA *fpa, ///< FPA for concept, or NULL
-        const pmChip *chip, ///< Chip for concept, or NULL
-        const pmCell *cell ///< Cell for concept, or NULL
-                                           );
+psMetadataItem *p_pmConceptFormat_CELL_YBIN(
+    const psMetadataItem *concept, ///< Concept to format
+    pmConceptSource source, ///< Source for concept
+    const psMetadata *cameraFormat, ///< Camera format definition
+    const pmFPA *fpa, ///< FPA for concept, or NULL
+    const pmChip *chip, ///< Chip for concept, or NULL
+    const pmCell *cell ///< Cell for concept, or NULL
+    );
 
 /// Format the time system concepts: FPA.TIMESYS and CELL.TIMESYS
-psMetadataItem *p_pmConceptFormat_TIMESYS(const psMetadataItem *concept, ///< Concept to format
-                                            pmConceptSource source, ///< Source for concept
-        const psMetadata *cameraFormat, ///< Camera format definition
-        const pmFPA *fpa, ///< FPA for concept, or NULL
-        const pmChip *chip, ///< Chip for concept, or NULL
-        const pmCell *cell ///< Cell for concept, or NULL
-                                         );
+psMetadataItem *p_pmConceptFormat_TIMESYS(
+    const psMetadataItem *concept, ///< Concept to format
+    pmConceptSource source, ///< Source for concept
+    const psMetadata *cameraFormat, ///< Camera format definition
+    const pmFPA *fpa, ///< FPA for concept, or NULL
+    const pmChip *chip, ///< Chip for concept, or NULL
+    const pmCell *cell ///< Cell for concept, or NULL
+    );
 
 /// Format the time concepts: FPA.TIME and CELL.TIME
-psMetadataItem *p_pmConceptFormat_TIME(const psMetadataItem *concept, ///< Concept to format
-                                            pmConceptSource source, ///< Source for concept
-                                       const psMetadata *cameraFormat, ///< Camera format definition
-                                       const pmFPA *fpa, ///< FPA for concept, or NULL
-                                       const pmChip *chip, ///< Chip for concept, or NULL
-                                       const pmCell *cell ///< Cell for concept, or NULL
-                                      );
+psMetadataItem *p_pmConceptFormat_TIME(
+    const psMetadataItem *concept, ///< Concept to format
+    pmConceptSource source, ///< Source for concept
+    const psMetadata *cameraFormat, ///< Camera format definition
+    const pmFPA *fpa, ///< FPA for concept, or NULL
+    const pmChip *chip, ///< Chip for concept, or NULL
+    const pmCell *cell ///< Cell for concept, or NULL
+    );
 
 /// Format a cell position concept, e.g., CELL.X0
-psMetadataItem *p_pmConceptFormat_Positions(const psMetadataItem *concept, ///< Concept to format
-                                            pmConceptSource source, ///< Source for concept
-        const psMetadata *cameraFormat, ///< Camera format definition
-        const pmFPA *fpa, ///< FPA for concept, or NULL
-        const pmChip *chip, ///< Chip for concept, or NULL
-        const pmCell *cell ///< Cell for concept, or NULL
-                                           );
+psMetadataItem *p_pmConceptFormat_Positions(
+    const psMetadataItem *concept, ///< Concept to format
+    pmConceptSource source, ///< Source for concept
+    const psMetadata *cameraFormat, ///< Camera format definition
+    const pmFPA *fpa, ///< FPA for concept, or NULL
+    const pmChip *chip, ///< Chip for concept, or NULL
+    const pmCell *cell ///< Cell for concept, or NULL
+    );
+
+/// Copy the time system only if not already set
+psMetadataItem *p_pmConceptCopy_TIMESYS(
+    const psMetadataItem *target,
+    const psMetadataItem *source,
+    const psMetadata *cameraFormat,
+    const pmFPA *fpa,
+    const pmChip *chip,
+    const pmCell *cell
+    );
+
 /// @}
 #endif
Index: /branches/cnb_branches/cnb_branch_20090215/psModules/src/concepts/pmConceptsWrite.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/concepts/pmConceptsWrite.c	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psModules/src/concepts/pmConceptsWrite.c	(revision 23197)
@@ -16,4 +16,6 @@
 #include "pmConcepts.h"
 #include "pmConceptsRead.h"
+
+#include "pmConceptsWrite.h"
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -320,5 +322,5 @@
 
 bool p_pmConceptsWriteToDefaults(const psMetadata *specs, const pmFPA *fpa, const pmChip *chip,
-                                 const pmCell *cell, psMetadata *concepts)
+                                 const pmCell *cell, const psMetadata *concepts)
 {
     PS_ASSERT_PTR_NON_NULL(specs, false);
@@ -486,2 +488,107 @@
     #endif
 }
+
+
+
+
+
+// Write all registered concepts for the specified level
+static bool conceptsWrite(psMetadata **specs, // One of the concepts specifications
+                          const pmFPA *fpa,   // The FPA
+                          const pmChip *chip, // The chip
+                          const pmCell *cell, // The cell
+                          pmConceptSource source, // The source of the concepts to write
+                          pmConfig *config, // Configuration
+                          psMetadata *concepts // The concepts to write out
+                         )
+{
+    assert(specs);
+    assert(concepts);
+
+    pmConceptsInit();
+
+    psTrace("psModules.concepts", 3, "Writing concepts (%p %p %p): %d\n", fpa, chip, cell, source);
+
+    if (source & PM_CONCEPT_SOURCE_CELLS) {
+        p_pmConceptsWriteToCells(*specs, cell, concepts);
+    }
+    if (source & PM_CONCEPT_SOURCE_DEFAULTS) {
+        p_pmConceptsWriteToDefaults(*specs, fpa, chip, cell, concepts);
+    }
+    if (source & (PM_CONCEPT_SOURCE_PHU | PM_CONCEPT_SOURCE_HEADER)) {
+        p_pmConceptsWriteToHeader(*specs, fpa, chip, cell, concepts);
+    }
+    if (source & PM_CONCEPT_SOURCE_DATABASE) {
+        p_pmConceptsWriteToDatabase(*specs, fpa, chip, cell, config, concepts);
+    }
+
+    return true;
+}
+
+
+bool pmConceptsWriteFPA(const pmFPA *fpa, pmConceptSource source, bool propagateDown, pmConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(fpa, false);
+    psMetadata *conceptsFPA = pmConceptsSpecs(PM_FPA_LEVEL_FPA); // Concept specifications
+    psTrace("psModules.concepts", 5, "Writing FPA concepts: %p %p\n", conceptsFPA, fpa->concepts);
+    bool success = conceptsWrite(&conceptsFPA, fpa, NULL, NULL, source, config, fpa->concepts);
+    if (propagateDown) {
+        psArray *chips = fpa->chips;        // Array of chips
+        for (long i = 0; i < chips->n; i++) {
+            pmChip *chip = chips->data[i];  // Chip of interest
+            if (chip && !chip->hdu) {
+                success &= pmConceptsWriteChip(chip, source, false, true, config);
+            }
+        }
+    }
+    return success;
+}
+
+
+bool pmConceptsWriteChip(const pmChip *chip, pmConceptSource source, bool propagateUp,
+                         bool propagateDown, pmConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(chip, false);
+    psMetadata *conceptsChip = pmConceptsSpecs(PM_FPA_LEVEL_CHIP); // Concept specifications
+    psTrace("psModules.concepts", 5, "Writing chip concepts: %p %p\n", conceptsChip, chip->concepts);
+    pmFPA *fpa = chip->parent;          // FPA to which the chip belongs
+    bool success = conceptsWrite(&conceptsChip, fpa, chip, NULL, source, config, chip->concepts);
+    if (propagateUp && !fpa->hdu) {
+        psMetadata *conceptsFPA = pmConceptsSpecs(PM_FPA_LEVEL_FPA); // Concept specifications
+        success &= conceptsWrite(&conceptsFPA, fpa, chip, NULL, source, config, fpa->concepts);
+    }
+    if (propagateDown) {
+        psArray *cells = chip->cells;        // Array of cells
+        for (long i = 0; i < cells->n; i++) {
+            pmCell *cell = cells->data[i];  // Cell of interest
+            if (cell && !cell->hdu) {
+                success &= pmConceptsWriteCell(cell, source, false, config);
+            }
+        }
+    }
+    return success;
+}
+
+
+bool pmConceptsWriteCell(const pmCell *cell, pmConceptSource source, bool propagateUp, pmConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(cell, false);
+    psMetadata *conceptsCell = pmConceptsSpecs(PM_FPA_LEVEL_CELL); // Concept specifications
+    psTrace("psModules.concepts", 5, "Writing cell concepts: %p %p\n", conceptsCell, cell->concepts);
+    pmChip *chip = cell->parent;        // Chip to which the cell belongs
+    pmFPA *fpa = chip->parent;          // FPA to which the chip belongs
+
+    bool success = conceptsWrite(&conceptsCell, fpa, chip, cell, source, config, cell->concepts);
+    if (propagateUp) {
+        if (!chip->hdu) {
+            psMetadata *conceptsChip = pmConceptsSpecs(PM_FPA_LEVEL_CHIP); // Concept specifications
+            success &= conceptsWrite(&conceptsChip, fpa, chip, cell, source, config, chip->concepts);
+            if (!fpa->hdu) {
+                psMetadata *conceptsFPA = pmConceptsSpecs(PM_FPA_LEVEL_FPA); // Concept specifications
+                success &= conceptsWrite(&conceptsFPA, fpa, chip, cell, source, config, fpa->concepts);
+            }
+        }
+    }
+
+    return success;
+}
Index: /branches/cnb_branches/cnb_branch_20090215/psModules/src/concepts/pmConceptsWrite.h
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/concepts/pmConceptsWrite.h	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psModules/src/concepts/pmConceptsWrite.h	(revision 23197)
@@ -11,4 +11,9 @@
 #ifndef PM_CONCEPTS_WRITE_H
 #define PM_CONCEPTS_WRITE_H
+
+#include <pslib.h>
+#include <pmFPA.h>
+#include <pmConfig.h>
+#include <pmConcepts.h>
 
 /// @addtogroup Concepts Data Abstraction Concepts
@@ -58,4 +63,38 @@
                                  const psMetadata *concepts ///< The concepts
                                 );
+
+
+/// Write concepts for an FPA; optionally, write concepts at all lower levels.
+///
+/// This function writes all concepts for the FPA to the specified "source".  It also allows concepts to be
+/// written for all lower levels by iterating over the components.
+bool pmConceptsWriteFPA(const pmFPA *fpa,     ///< FPA for which to write concepts
+                        pmConceptSource source, ///< Source for concepts
+                        bool propagateDown, ///< Propagate to lower levels?
+                        pmConfig *config        ///< Configuration
+                       );
+
+/// Write concepts for a chip; optionally, write concepts at the FPA and cell levels.
+///
+/// This function writes all concepts for the chip to the specified "source".  It also allows concepts to be
+/// written for the FPA, and the cell level by iterating over the components.
+bool pmConceptsWriteChip(const pmChip *chip,  ///< Chip for which to write concepts
+                         pmConceptSource source, ///< Source for concepts
+                         bool propagateUp,///< Propagate to higher levels?
+                         bool propagateDown, ///< Propagate to lower levels?
+                         pmConfig *config       ///< Configuration
+                        );
+
+/// Write concepts for a cell; optionally, write concepts for the parents.
+///
+/// This function writes all concepts for the chip to the specified "source".  It also allows concepts to be
+/// written for the upper levels through the parents (note, it would not write concepts for all chips, but
+/// only the parent of this cell).
+bool pmConceptsWriteCell(const pmCell *cell,  ///< FPA for which to write concepts
+                         pmConceptSource source, ///< Source for concepts
+                         bool propagateUp, ///< Propagate to higher levels?
+                         pmConfig *config ///< Configuration
+                        );
+
 /// @}
 #endif
Index: anches/cnb_branches/cnb_branch_20090215/psModules/src/config/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/config/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,8 +1,0 @@
-.deps
-.libs
-Makefile
-Makefile.in
-*.la
-*.lo
-pmErrorCodes.c
-pmErrorCodes.h
Index: /branches/cnb_branches/cnb_branch_20090215/psModules/src/config/pmConfigCamera.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/config/pmConfigCamera.c	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psModules/src/config/pmConfigCamera.c	(revision 23197)
@@ -280,40 +280,37 @@
         psMetadata *translation = psMetadataAlloc(); // The TRANSLATION --- how to read the FITS headers
 
-        psList *concepts;               // List of concepts for each level
-        psListIterator *iter;           // Iterator for concepts
-        psString name;                  // Concept name, from iteration
-
-        concepts = pmConceptsList(PM_FPA_LEVEL_FPA); // FPA-level concepts
-        iter = psListIteratorAlloc(concepts, PS_LIST_HEAD, false);
-        while ((name = psListGetAndIncrement(iter))) {
-            const char *new = skycellConceptName(name, skycellConceptsFPA, system); // Name for skycell
+        psMetadata *concepts;           // List of concepts for each level
+        psMetadataIterator *iter;       // Iterator for concepts
+        psMetadataItem *item;           // Concept specification item, from iteration
+
+        concepts = pmConceptsSpecs(PM_FPA_LEVEL_FPA); // FPA-level concepts
+        iter = psMetadataIteratorAlloc(concepts, PS_LIST_HEAD, NULL);
+        while ((item = psMetadataGetAndIncrement(iter))) {
+            const char *new = skycellConceptName(item->name, skycellConceptsFPA, system); // Name for skycell
             if (new) {
-                psMetadataAddStr(translation, PS_LIST_TAIL, name, 0, NULL, new);
+                psMetadataAddStr(translation, PS_LIST_TAIL, item->name, 0, NULL, new);
             }
         }
         psFree(iter);
-        psFree(concepts);
-
-        concepts = pmConceptsList(PM_FPA_LEVEL_CHIP);
-        iter = psListIteratorAlloc(concepts, PS_LIST_HEAD, false);
-        while ((name = psListGetAndIncrement(iter))) {
-            const char *new = skycellConceptName(name, skycellConceptsChip, system); // Name for skycell
+
+        concepts = pmConceptsSpecs(PM_FPA_LEVEL_CHIP);
+        iter = psMetadataIteratorAlloc(concepts, PS_LIST_HEAD, NULL);
+        while ((item = psMetadataGetAndIncrement(iter))) {
+            const char *new = skycellConceptName(item->name, skycellConceptsChip, system); // Name for skycell
             if (new) {
-                psMetadataAddStr(translation, PS_LIST_TAIL, name, 0, NULL, new);
+                psMetadataAddStr(translation, PS_LIST_TAIL, item->name, 0, NULL, new);
             }
         }
         psFree(iter);
-        psFree(concepts);
-
-        concepts = pmConceptsList(PM_FPA_LEVEL_CELL);
-        iter = psListIteratorAlloc(concepts, PS_LIST_HEAD, false);
-        while ((name = psListGetAndIncrement(iter))) {
-            const char *new = skycellConceptName(name, skycellConceptsCell, system); // Name for skycell
+
+        concepts = pmConceptsSpecs(PM_FPA_LEVEL_CELL);
+        iter = psMetadataIteratorAlloc(concepts, PS_LIST_HEAD, false);
+        while ((item = psMetadataGetAndIncrement(iter))) {
+            const char *new = skycellConceptName(item->name, skycellConceptsCell, system); // Name for skycell
             if (new) {
-                psMetadataAddStr(translation, PS_LIST_TAIL, name, 0, NULL, new);
+                psMetadataAddStr(translation, PS_LIST_TAIL, item->name, 0, NULL, new);
             }
         }
         psFree(iter);
-        psFree(concepts);
 
         psMetadataAddMetadata(format, PS_LIST_TAIL, "TRANSLATION", 0, "How to translate the FITS headers",
Index: anches/cnb_branches/cnb_branch_20090215/psModules/src/detrend/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/detrend/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,6 +1,0 @@
-.deps
-.libs
-Makefile
-Makefile.in
-*.la
-*.lo
Index: /branches/cnb_branches/cnb_branch_20090215/psModules/src/detrend/pmFlatField.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/detrend/pmFlatField.c	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psModules/src/detrend/pmFlatField.c	(revision 23197)
@@ -43,5 +43,5 @@
 
     // Using i,j for image; x,y for flat.
-    for (int j = rowStart, y = yOffset; j < rowStop; j++, y++) {
+    for (int j = rowStart, y = rowStart + yOffset; j < rowStop; j++, y++) {
         for (int i = 0, x = xOffset; i < numCols; i++, x++) {
             float flatValue = 1.0 / flatImage->data.F32[y][x];
Index: /branches/cnb_branches/cnb_branch_20090215/psModules/src/detrend/pmShutterCorrection.h
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/detrend/pmShutterCorrection.h	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psModules/src/detrend/pmShutterCorrection.h	(revision 23197)
@@ -5,6 +5,6 @@
  * @author Paul Price, IfA
  *
- * @version $Revision: 1.23.2.1 $ $Name: not supported by cvs2svn $
- * @date $Date: 2009-02-19 17:59:50 $
+ * @version $Revision: 1.24 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-02-16 22:27:49 $
  * Copyright 2006 Institute for Astronomy, University of Hawaii
  */
Index: anches/cnb_branches/cnb_branch_20090215/psModules/src/extras/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/extras/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,6 +1,0 @@
-.deps
-.libs
-Makefile
-Makefile.in
-*.la
-*.lo
Index: anches/cnb_branches/cnb_branch_20090215/psModules/src/imcombine/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/imcombine/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,6 +1,0 @@
-.deps
-.libs
-Makefile
-Makefile.in
-*.la
-*.lo
Index: /branches/cnb_branches/cnb_branch_20090215/psModules/src/imcombine/pmSubtractionIO.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/imcombine/pmSubtractionIO.c	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psModules/src/imcombine/pmSubtractionIO.c	(revision 23197)
@@ -8,5 +8,5 @@
 #include "pmFPAfile.h"
 #include "pmFPAfileFitsIO.h"
-#include "pmConcepts.h"
+#include "pmConceptsRead.h"
 
 #include "pmSubtraction.h"
Index: anches/cnb_branches/cnb_branch_20090215/psModules/src/objects/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/objects/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,6 +1,0 @@
-.deps
-.libs
-Makefile
-Makefile.in
-*.la
-*.lo
Index: /branches/cnb_branches/cnb_branch_20090215/psModules/src/objects/pmModel.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/objects/pmModel.c	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psModules/src/objects/pmModel.c	(revision 23197)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.27.4.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2009-02-19 17:59:50 $
+ *  @version $Revision: 1.28 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-02-16 22:30:26 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -235,14 +235,14 @@
 
     if (model->residuals) {
-        DX = xBin*(image->col0 - xCenter - dx) + model->residuals->xCenter + 0.5;
-        DY = yBin*(image->row0 - yCenter - dy) + model->residuals->yCenter + 0.5;
-        Ro = (model->residuals->Ro)   ? model->residuals->Ro->data.F32 : NULL;
-        Rx = (model->residuals->Rx)   ? model->residuals->Rx->data.F32 : NULL;
-        Ry = (model->residuals->Ry)   ? model->residuals->Ry->data.F32 : NULL;
-        Rm = (model->residuals->mask) ? model->residuals->mask->data.PS_TYPE_IMAGE_MASK_DATA : NULL;
-        if (Ro) {
-            NX = model->residuals->Ro->numCols;
-            NY = model->residuals->Ro->numRows;
-        }
+	DX = xBin*(image->col0 - xCenter - dx) + model->residuals->xCenter + 0.5;
+	DY = yBin*(image->row0 - yCenter - dy) + model->residuals->yCenter + 0.5;
+	Ro = (model->residuals->Ro)   ? model->residuals->Ro->data.F32 : NULL;
+	Rx = (model->residuals->Rx)   ? model->residuals->Rx->data.F32 : NULL;
+	Ry = (model->residuals->Ry)   ? model->residuals->Ry->data.F32 : NULL;
+	Rm = (model->residuals->mask) ? model->residuals->mask->data.PS_TYPE_IMAGE_MASK_DATA : NULL;
+	if (Ro) {
+	    NX = model->residuals->Ro->numCols;
+	    NY = model->residuals->Ro->numRows;
+	}	    
     }
 
@@ -256,5 +256,5 @@
 
             // XXX should we use using 0.5 pixel offset?
-            // Convert to coordinate in parent image, with offset (dx,dy)
+	    // Convert to coordinate in parent image, with offset (dx,dy)
             imageCol = ix + image->col0 - dx;
             imageRow = iy + image->row0 - dy;
@@ -276,56 +276,56 @@
                 float rx = xBin*ix + DX;
 
-                int rx0 = rx - 0.5;
-                int rx1 = rx + 0.5;
-                int ry0 = ry - 0.5;
-                int ry1 = ry + 0.5;
-
-                if (rx0 < 0) goto skip;
-                if (ry0 < 0) goto skip;
-                if (rx1 >= NX) goto skip;
-                if (ry1 >= NY) goto skip;
-
-                // these go from 0.0 to 1.0 between the centers of the pixels
-                float fx = rx - 0.5 - rx0;
-                float Fx = 1.0 - fx;
-                float fy = ry - 0.5 - ry0;
-                float Fy = 1.0 - fy;
-
-                // check the residual image mask (if set). give up if any of the 4 pixels are masked.
-                if (Rm) {
-                    if (Rm[ry0][rx0]) goto skip;
-                    if (Rm[ry0][rx1]) goto skip;
-                    if (Rm[ry1][rx0]) goto skip;
-                    if (Rm[ry1][rx1]) goto skip;
-                }
-
-                // a possible further optimization if we re-use these values
-                // XXX allow for masked pixels, and add pixel weights
-                float V0 = (Ro[ry0][rx0]*Fx + Ro[ry0][rx1]*fx);
-                float V1 = (Ro[ry1][rx0]*Fx + Ro[ry1][rx1]*fx);
-                float Vo = V0*Fy + V1*fy;
-                if (!isfinite(Vo)) goto skip;
-
-                float Vx = 0.0;
-                float Vy = 0.0;
-
-                // skip Rx,Ry if Ro is masked
-                if (Rx && Ry && (mode & PM_MODEL_OP_RES1)) {
-                    V0 = (Rx[ry0][rx0]*Fx + Rx[ry0][rx1]*fx);
-                    V1 = (Rx[ry1][rx0]*Fx + Rx[ry1][rx1]*fx);
-                    Vx = V0*Fy + V1*fy;
-
-                    V0 = (Ry[ry0][rx0]*Fx + Ry[ry0][rx1]*fx);
-                    V1 = (Ry[ry1][rx0]*Fx + Ry[ry1][rx1]*fx);
-                    Vy = V0*Fy + V1*fy;
-                }
-                if (!isfinite(Vx)) goto skip;
-                if (!isfinite(Vy)) goto skip;
-
-                // 2D residual variations are set for the true source position
-                pixelValue += Io*(Vo + XoSave*Vx + XoSave*Vy);
+		int rx0 = rx - 0.5;
+		int rx1 = rx + 0.5;
+		int ry0 = ry - 0.5;
+		int ry1 = ry + 0.5;
+
+		if (rx0 < 0) goto skip;
+		if (ry0 < 0) goto skip;
+		if (rx1 >= NX) goto skip;
+		if (ry1 >= NY) goto skip;
+
+		// these go from 0.0 to 1.0 between the centers of the pixels 
+		float fx = rx - 0.5 - rx0;
+		float Fx = 1.0 - fx;
+		float fy = ry - 0.5 - ry0;
+		float Fy = 1.0 - fy;
+
+		// check the residual image mask (if set). give up if any of the 4 pixels are masked.
+		if (Rm) {
+		    if (Rm[ry0][rx0]) goto skip;
+		    if (Rm[ry0][rx1]) goto skip;
+		    if (Rm[ry1][rx0]) goto skip;
+		    if (Rm[ry1][rx1]) goto skip;
+		}
+
+		// a possible further optimization if we re-use these values
+		// XXX allow for masked pixels, and add pixel weights
+		float V0 = (Ro[ry0][rx0]*Fx + Ro[ry0][rx1]*fx);
+		float V1 = (Ro[ry1][rx0]*Fx + Ro[ry1][rx1]*fx);
+		float Vo = V0*Fy + V1*fy;
+		if (!isfinite(Vo)) goto skip;
+
+		float Vx = 0.0;
+		float Vy = 0.0;
+
+		// skip Rx,Ry if Ro is masked
+		if (Rx && Ry && (mode & PM_MODEL_OP_RES1)) {
+		    V0 = (Rx[ry0][rx0]*Fx + Rx[ry0][rx1]*fx);
+		    V1 = (Rx[ry1][rx0]*Fx + Rx[ry1][rx1]*fx);
+		    Vx = V0*Fy + V1*fy;
+
+		    V0 = (Ry[ry0][rx0]*Fx + Ry[ry0][rx1]*fx);
+		    V1 = (Ry[ry1][rx0]*Fx + Ry[ry1][rx1]*fx);
+		    Vy = V0*Fy + V1*fy;
+		}
+		if (!isfinite(Vx)) goto skip;
+		if (!isfinite(Vy)) goto skip;
+
+		// 2D residual variations are set for the true source position
+		pixelValue += Io*(Vo + XoSave*Vx + XoSave*Vy);
             }
 
-        skip:
+	skip:
             // add or subtract the value
             if (add) {
Index: /branches/cnb_branches/cnb_branch_20090215/psModules/src/objects/pmModel.h
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/objects/pmModel.h	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psModules/src/objects/pmModel.h	(revision 23197)
@@ -5,6 +5,6 @@
  * @author EAM, IfA
  *
- * @version $Revision: 1.18.8.1 $ $Name: not supported by cvs2svn $
- * @date $Date: 2009-02-19 17:59:50 $
+ * @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-02-16 22:30:50 $
  *
  * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -151,5 +151,5 @@
     pmModel *model,                     ///< The input pmModel
     pmModelOpMode mode,                 ///< mode to control how the model is added into the image
-    psImageMaskType maskVal             ///< Value to mask
+    psImageMaskType maskVal		///< Value to mask
 );
 
@@ -169,5 +169,5 @@
     pmModel *model,                     ///< The input pmModel
     pmModelOpMode mode,                 ///< mode to control how the model is added into the image
-    psImageMaskType maskVal             ///< Value to mask
+    psImageMaskType maskVal		///< Value to mask
 );
 
Index: /branches/cnb_branches/cnb_branch_20090215/psModules/src/objects/pmPeaks.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/objects/pmPeaks.c	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psModules/src/objects/pmPeaks.c	(revision 23197)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA: significant modifications.
  *
- *  @version $Revision: 1.25.14.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2009-02-19 17:59:50 $
+ *  @version $Revision: 1.26 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-02-16 22:30:14 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -28,5 +28,5 @@
 AddPeak(): A private function which allocates a psArray, if the peaks
 argument is NULL, otherwise it adds the peak to that array.
-XXX EAM : row,col now refer to image coords, NOT parent (since this is private)
+XXX EAM : row,col now refer to image coords, NOT parent (since this is private) 
 XXX EAM : now also calculates fractional peak positions from 3x3 bicube region
 *****************************************************************************/
@@ -64,17 +64,17 @@
         peak->yf = min.y + iy + image->row0;
 
-        // These errors are fractional errors, and should be scaled by the
-        // error on the peak pixel (see, eg, psphotFindPeaks)
-        peak->dx = min.xErr;
-        peak->dy = min.yErr;
-
-        // xf,yf must land on image with 0 pixel border
-        peak->xf = PS_MAX (PS_MIN (peak->xf, image->numCols - 1), image->col0);
-        peak->yf = PS_MAX (PS_MIN (peak->yf, image->numRows - 1), image->row0);
+	// These errors are fractional errors, and should be scaled by the 
+	// error on the peak pixel (see, eg, psphotFindPeaks)
+	peak->dx = min.xErr;
+	peak->dy = min.yErr;
+	
+	// xf,yf must land on image with 0 pixel border
+	peak->xf = PS_MAX (PS_MIN (peak->xf, image->numCols - 1), image->col0);
+	peak->yf = PS_MAX (PS_MIN (peak->yf, image->numRows - 1), image->row0);
     } else {
         peak->xf = ix;
         peak->yf = iy;
-        peak->dx = NAN;
-        peak->dy = NAN;
+	peak->dx = NAN;
+	peak->dy = NAN;
     }
 
@@ -89,5 +89,5 @@
 getRowVectorFromImage(): a private function which simply returns a
 psVector containing the specified row of data from the psImage.
-
+ 
 XXX: Is there a better way to do this?
 XXX EAM: does this really need to alloc a new vector???
@@ -248,7 +248,7 @@
 above the given threshold.  Returns a vector of type PS_TYPE_U32 containing
 the location (x value) of all peaks.
-
+ 
 XXX: What types should be supported?  Only F32 is implemented.
-
+ 
 XXX: We currently step through the input vector twice; once to determine the
 size of the output vector, then to set the values of the output vector.
@@ -256,5 +256,5 @@
 *****************************************************************************/
 psVector *pmPeaksInVector(const psVector *vector,
-                         psF32 threshold)
+			 psF32 threshold)
 {
     psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
@@ -350,12 +350,12 @@
 above the given threshold.  Returns a psArray containing location (x/y value)
 of all peaks.
-
+ 
 XXX: I'm not convinced the peak type definition in the SDRS is mutually
 exclusive.  Some peaks can have multiple types.  Edges for sure.  Also, a
 digonal line with the same value at each point will have a peak for every
 point on that line.
-
+ 
 XXX: This does not work if image has either a single row, or a single column.
-
+ 
 The peak is returned in the image parent coordinates
 
Index: /branches/cnb_branches/cnb_branch_20090215/psModules/src/objects/pmSource.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/objects/pmSource.c	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psModules/src/objects/pmSource.c	(revision 23197)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA: significant modifications.
  *
- *  @version $Revision: 1.69.4.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2009-02-19 17:59:50 $
+ *  @version $Revision: 1.70 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-02-16 22:29:59 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -543,12 +543,12 @@
         pmSource *source = (pmSource *) sources->data[i];
 
-        // psf clumps are found for image subregions:
-        // skip sources not in this region
+	// psf clumps are found for image subregions:
+	// skip sources not in this region 
         if (source->peak->x <  region->x0) continue;
         if (source->peak->x >= region->x1) continue;
         if (source->peak->y <  region->y0) continue;
-        if (source->peak->y >= region->y1) continue;
-
-        // should be set by pmSourceAlloc
+	if (source->peak->y >= region->y1) continue;
+
+	// should be set by pmSourceAlloc
         psAssert (source->type == PM_SOURCE_TYPE_UNKNOWN, "source type was not init-ed?");
 
@@ -556,5 +556,5 @@
         if (!source->moments) {
             source->type = PM_SOURCE_TYPE_STAR;
-            psAssert (source->mode & noMoments, "why is this source missing moments?");
+	    psAssert (source->mode & noMoments, "why is this source missing moments?");
             Nstar++;
             continue;
Index: /branches/cnb_branches/cnb_branch_20090215/psModules/src/objects/pmSource.h
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/objects/pmSource.h	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psModules/src/objects/pmSource.h	(revision 23197)
@@ -3,6 +3,6 @@
  * @author EAM, IfA; GLG, MHPCC
  *
- * @version $Revision: 1.28.4.1 $ $Name: not supported by cvs2svn $
- * @date $Date: 2009-02-19 17:59:50 $
+ * @version $Revision: 1.29 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-02-16 22:30:50 $
  * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  */
@@ -37,20 +37,20 @@
 // bit flags to distinguish analysis results
 typedef enum {
-    PM_SOURCE_MODE_DEFAULT          = 0x00000000, ///< Initial value: resets all bits
-    PM_SOURCE_MODE_PSFMODEL         = 0x00000001, ///< Source fitted with a psf model (linear or non-linear)
-    PM_SOURCE_MODE_EXTMODEL         = 0x00000002, ///< Source fitted with an extended-source model
-    PM_SOURCE_MODE_FITTED           = 0x00000004, ///< Source fitted with non-linear model (PSF or EXT; good or bad)
-    PM_SOURCE_MODE_FAIL             = 0x00000008, ///< Fit (non-linear) failed (non-converge, off-edge, run to zero)
-    PM_SOURCE_MODE_POOR             = 0x00000010, ///< Fit succeeds, but low-SN, high-Chisq, or large (for PSF -- drop?)
-    PM_SOURCE_MODE_PAIR             = 0x00000020, ///< Source fitted with a double psf
-    PM_SOURCE_MODE_PSFSTAR          = 0x00000040, ///< Source used to define PSF model
-    PM_SOURCE_MODE_SATSTAR          = 0x00000080, ///< Source model peak is above saturation
-    PM_SOURCE_MODE_BLEND            = 0x00000100, ///< Source is a blend with other sourcers
-    PM_SOURCE_MODE_EXTERNAL         = 0x00000200, ///< Source based on supplied input position
-    PM_SOURCE_MODE_BADPSF           = 0x00000400, ///< Failed to get good estimate of object's PSF
-    PM_SOURCE_MODE_DEFECT           = 0x00000800, ///< Source is thought to be a defect
-    PM_SOURCE_MODE_SATURATED        = 0x00001000, ///< Source is thought to be saturated pixels (bleed trail)
-    PM_SOURCE_MODE_CR_LIMIT         = 0x00002000, ///< Source has crNsigma above limit
-    PM_SOURCE_MODE_EXT_LIMIT        = 0x00004000, ///< Source has extNsigma above limit
+    PM_SOURCE_MODE_DEFAULT    	    = 0x00000000, ///< Initial value: resets all bits
+    PM_SOURCE_MODE_PSFMODEL   	    = 0x00000001, ///< Source fitted with a psf model (linear or non-linear)
+    PM_SOURCE_MODE_EXTMODEL   	    = 0x00000002, ///< Source fitted with an extended-source model
+    PM_SOURCE_MODE_FITTED     	    = 0x00000004, ///< Source fitted with non-linear model (PSF or EXT; good or bad)
+    PM_SOURCE_MODE_FAIL       	    = 0x00000008, ///< Fit (non-linear) failed (non-converge, off-edge, run to zero)
+    PM_SOURCE_MODE_POOR       	    = 0x00000010, ///< Fit succeeds, but low-SN, high-Chisq, or large (for PSF -- drop?)
+    PM_SOURCE_MODE_PAIR       	    = 0x00000020, ///< Source fitted with a double psf
+    PM_SOURCE_MODE_PSFSTAR    	    = 0x00000040, ///< Source used to define PSF model
+    PM_SOURCE_MODE_SATSTAR    	    = 0x00000080, ///< Source model peak is above saturation
+    PM_SOURCE_MODE_BLEND      	    = 0x00000100, ///< Source is a blend with other sourcers
+    PM_SOURCE_MODE_EXTERNAL   	    = 0x00000200, ///< Source based on supplied input position
+    PM_SOURCE_MODE_BADPSF     	    = 0x00000400, ///< Failed to get good estimate of object's PSF
+    PM_SOURCE_MODE_DEFECT     	    = 0x00000800, ///< Source is thought to be a defect
+    PM_SOURCE_MODE_SATURATED  	    = 0x00001000, ///< Source is thought to be saturated pixels (bleed trail)
+    PM_SOURCE_MODE_CR_LIMIT   	    = 0x00002000, ///< Source has crNsigma above limit
+    PM_SOURCE_MODE_EXT_LIMIT  	    = 0x00004000, ///< Source has extNsigma above limit
     PM_SOURCE_MODE_MOMENTS_FAILURE  = 0x00008000, ///< could not measure the moments
     PM_SOURCE_MODE_SKY_FAILURE      = 0x00010000, ///< could not measure the local sky
@@ -101,5 +101,5 @@
     pmSourceType type;                  ///< Best identification of object.
     pmSourceMode mode;                  ///< analysis flags set for object.
-    pmSourceTmpF tmpFlags;              ///< internal-only flags
+    pmSourceTmpF tmpFlags;		///< internal-only flags
     psArray *blends;                    ///< collection of sources thought to be confused with object
     float psfMag;                       ///< calculated from flux in modelPSF
Index: /branches/cnb_branches/cnb_branch_20090215/psModules/src/objects/pmSourceFitModel.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/objects/pmSourceFitModel.c	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psModules/src/objects/pmSourceFitModel.c	(revision 23197)
@@ -6,6 +6,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.30.4.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2009-02-19 17:59:50 $
+ *  @version $Revision: 1.31 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-02-16 22:29:09 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
Index: /branches/cnb_branches/cnb_branch_20090215/psModules/src/objects/pmSourceIO.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/objects/pmSourceIO.c	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psModules/src/objects/pmSourceIO.c	(revision 23197)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.69.14.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2009-02-19 17:59:50 $
+ *  @version $Revision: 1.70 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-02-16 22:30:50 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -29,5 +29,5 @@
 #include "pmFPAfile.h"
 #include "pmFPAfileFitsIO.h"
-#include "pmConcepts.h"
+#include "pmConceptsRead.h"
 
 #include "pmSpan.h"
Index: /branches/cnb_branches/cnb_branch_20090215/psModules/src/objects/pmSourceIO.h
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/objects/pmSourceIO.h	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psModules/src/objects/pmSourceIO.h	(revision 23197)
@@ -4,6 +4,6 @@
  * @author EAM, IfA; GLG, MHPCC
  *
- * @version $Revision: 1.19.16.1 $ $Name: not supported by cvs2svn $
- * @date $Date: 2009-02-19 17:59:50 $
+ * @version $Revision: 1.20 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-02-16 22:30:50 $
  * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  *
Index: /branches/cnb_branches/cnb_branch_20090215/psModules/src/objects/pmSourceIO_CMF_PS1_V1.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/objects/pmSourceIO_CMF_PS1_V1.c	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psModules/src/objects/pmSourceIO_CMF_PS1_V1.c	(revision 23197)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.3.2.2 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2009-02-19 17:59:50 $
+ *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-02-18 02:44:19 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -45,6 +45,6 @@
 // followed by a zero-size matrix, followed by the table data
 
-bool pmSourcesWrite_CMF_PS1_V1 (psFits *fits, pmReadout *readout, psArray *sources, 
-				psMetadata *imageHeader, psMetadata *tableHeader, char *extname)
+bool pmSourcesWrite_CMF_PS1_V1 (psFits *fits, pmReadout *readout, psArray *sources,
+                                psMetadata *imageHeader, psMetadata *tableHeader, char *extname)
 {
     PS_ASSERT_PTR_NON_NULL(fits, false);
@@ -72,5 +72,5 @@
     float zeroptErr = psMetadataLookupF32 (&status2, imageHeader, "ZPT_ERR");
     if (status1 && status2 && (exptime > 0.0)) {
-	magOffset = zeropt + 2.5*log10(exptime);
+        magOffset = zeropt + 2.5*log10(exptime);
     }
 
@@ -79,10 +79,10 @@
     if (sources->n > 0) {
         pmSource *source = (pmSource *) sources->data[0];
-	if (source->seq == -1) {
-	  // let's write these out in S/N order
-	  sources = psArraySort (sources, pmSourceSortBySN);
-	} else {
-	  sources = psArraySort (sources, pmSourceSortBySeq);
-	}
+        if (source->seq == -1) {
+          // let's write these out in S/N order
+          sources = psArraySort (sources, pmSourceSortBySN);
+        } else {
+          sources = psArraySort (sources, pmSourceSortBySeq);
+        }
     }
 
@@ -94,11 +94,11 @@
         pmSource *source = (pmSource *) sources->data[i];
 
-	// If source->seq is -1, source was generated in this analysis.  If source->seq is
-	// not -1, source was read from elsewhere: in the latter case, preserve the source
-	// ID.  source.seq is used instead of source.id since the latter is a const
-	// generated on Alloc, and would thus be wrong for read in sources.
-	if (source->seq == -1) {
-	  source->seq = i;
-	}
+        // If source->seq is -1, source was generated in this analysis.  If source->seq is
+        // not -1, source was read from elsewhere: in the latter case, preserve the source
+        // ID.  source.seq is used instead of source.id since the latter is a const
+        // generated on Alloc, and would thus be wrong for read in sources.
+        if (source->seq == -1) {
+          source->seq = i;
+        }
 
         // no difference between PSF and non-PSF model
@@ -110,24 +110,24 @@
             xPos = PAR[PM_PAR_XPOS];
             yPos = PAR[PM_PAR_YPOS];
-	    if (source->mode & PM_SOURCE_MODE_NONLINEAR_FIT) {
-	      xErr = dPAR[PM_PAR_XPOS];
-	      yErr = dPAR[PM_PAR_YPOS];
-	    } else {
-	      // in linear-fit mode, there is no error on the centroid
-	      xErr = source->peak->dx;
-	      yErr = source->peak->dy;
-	    }	      
-	    if (isfinite(PAR[PM_PAR_SXX]) && isfinite(PAR[PM_PAR_SXX]) && isfinite(PAR[PM_PAR_SXX])) {
-		axes = pmPSF_ModelToAxes (PAR, 20.0);
-	    } else {
-		axes.major = NAN;
-		axes.minor = NAN;
-		axes.theta = NAN;
-	    }
-	    chisq = model->chisq;
-	    nDOF = model->nDOF;
-	    nPix = model->nPix;
-	    apRadius = model->radiusFit; // XXX should we really use the fitRadius for aperture Radius?
-	    errMag = model->dparams->data.F32[PM_PAR_I0] / model->params->data.F32[PM_PAR_I0];
+            if (source->mode & PM_SOURCE_MODE_NONLINEAR_FIT) {
+              xErr = dPAR[PM_PAR_XPOS];
+              yErr = dPAR[PM_PAR_YPOS];
+            } else {
+              // in linear-fit mode, there is no error on the centroid
+              xErr = source->peak->dx;
+              yErr = source->peak->dy;
+            }
+            if (isfinite(PAR[PM_PAR_SXX]) && isfinite(PAR[PM_PAR_SXX]) && isfinite(PAR[PM_PAR_SXX])) {
+                axes = pmPSF_ModelToAxes (PAR, 20.0);
+            } else {
+                axes.major = NAN;
+                axes.minor = NAN;
+                axes.theta = NAN;
+            }
+            chisq = model->chisq;
+            nDOF = model->nDOF;
+            nPix = model->nPix;
+            apRadius = model->radiusFit; // XXX should we really use the fitRadius for aperture Radius?
+            errMag = model->dparams->data.F32[PM_PAR_I0] / model->params->data.F32[PM_PAR_I0];
         } else {
             xPos = source->peak->xf;
@@ -138,19 +138,19 @@
             axes.minor = NAN;
             axes.theta = NAN;
-	    chisq = NAN;
-	    nDOF = 0;
-	    nPix = 0;
-	    apRadius = NAN;
-	    errMag = NAN;
-        }
-
-	float calMag = isfinite(magOffset) ? source->psfMag + magOffset : NAN;
+            chisq = NAN;
+            nDOF = 0;
+            nPix = 0;
+            apRadius = NAN;
+            errMag = NAN;
+        }
+
+        float calMag = isfinite(magOffset) ? source->psfMag + magOffset : NAN;
         float peakMag = (source->peak->flux > 0) ? -2.5*log10(source->peak->flux) : NAN;
         psS16 nImageOverlap = 1;
 
-	psSphere ptSky = {0.0, 0.0, 0.0, 0.0};
-	float posAngle = 0.0;
-	float pltScale = 0.0;
-	pmSourceLocalAstrometry (&ptSky, &posAngle, &pltScale, chip, xPos, yPos);
+        psSphere ptSky = {0.0, 0.0, 0.0, 0.0};
+        float posAngle = 0.0;
+        float pltScale = 0.0;
+        pmSourceLocalAstrometry (&ptSky, &posAngle, &pltScale, chip, xPos, yPos);
 
         row = psMetadataAlloc ();
@@ -185,8 +185,11 @@
         psMetadataAdd (row, PS_LIST_TAIL, "PSF_NPIX",         PS_DATA_S32, "number of pixels in fit",                    nPix);
 
-	// distinguish moments measure from window vs S/N > XX ??
-        psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_XX",       PS_DATA_F32, "second moments (X^2)",                      source->moments->Mxx);
-        psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_XY",       PS_DATA_F32, "second moments (X*Y)",                      source->moments->Mxy);
-        psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_YY",       PS_DATA_F32, "second moments (Y*Y)",                      source->moments->Myy);
+        // distinguish moments measure from window vs S/N > XX ??
+        float mxx = source->moments ? source->moments->Mxx : NAN;
+        float mxy = source->moments ? source->moments->Mxy : NAN;
+        float myy = source->moments ? source->moments->Myy : NAN;
+        psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_XX",       PS_DATA_F32, "second moments (X^2)",                      mxx);
+        psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_XY",       PS_DATA_F32, "second moments (X*Y)",                      mxy);
+        psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_YY",       PS_DATA_F32, "second moments (Y*Y)",                      myy);
 
         psMetadataAdd (row, PS_LIST_TAIL, "FLAGS",            PS_DATA_U32, "psphot analysis flags",                      source->mode);
@@ -199,9 +202,9 @@
         psFree (row);
 
-	// EXT_NSIGMA will be NAN if: 1) contour ellipse is imaginary; 2) source is not
-	// subtracted
-
-	// CR_NSIGMA will be NAN if: 1) source is not subtracted; 2) source is on the image
-	// edge; 3) any pixels in the 3x3 peak region are masked; 
+        // EXT_NSIGMA will be NAN if: 1) contour ellipse is imaginary; 2) source is not
+        // subtracted
+
+        // CR_NSIGMA will be NAN if: 1) source is not subtracted; 2) source is on the image
+        // edge; 3) any pixels in the 3x3 peak region are masked;
     }
 
@@ -281,7 +284,7 @@
         source->apMag     = psMetadataLookupF32 (&status, row, "AP_MAG");
 
-	// XXX this scaling is incorrect: does not include the 2 \pi AREA factor 
-	PAR[PM_PAR_I0]    = (isfinite(source->psfMag)) ? pow(10.0, -0.4*source->psfMag) : NAN;
-	dPAR[PM_PAR_I0]   = (isfinite(source->psfMag)) ? PAR[PM_PAR_I0] * source->errMag : NAN;
+        // XXX this scaling is incorrect: does not include the 2 \pi AREA factor
+        PAR[PM_PAR_I0]    = (isfinite(source->psfMag)) ? pow(10.0, -0.4*source->psfMag) : NAN;
+        dPAR[PM_PAR_I0]   = (isfinite(source->psfMag)) ? PAR[PM_PAR_I0] * source->errMag : NAN;
 
         pmPSF_AxesToModel (PAR, axes);
@@ -290,5 +293,5 @@
         float peakFlux    = (isfinite(peakMag)) ? pow(10.0, -0.4*peakMag) : NAN;
 
-	// recreate the peak to match (xPos, yPos) +/- (xErr, yErr)
+        // recreate the peak to match (xPos, yPos) +/- (xErr, yErr)
         source->peak = pmPeakAlloc(PAR[PM_PAR_XPOS], PAR[PM_PAR_YPOS], peakFlux, PM_PEAK_LONE);
         source->peak->flux = peakFlux;
@@ -300,11 +303,11 @@
         source->extNsigma = psMetadataLookupF32 (&status, row, "EXT_NSIGMA");
 
-	// note that some older versions used PSF_PROBABILITY: this was not well defined.
-        model->chisq 	  = psMetadataLookupF32 (&status, row, "PSF_CHISQ");
-        model->nDOF  	  = psMetadataLookupS32 (&status, row, "PSF_NDOF");
-        model->nPix  	  = psMetadataLookupS32 (&status, row, "PSF_NPIX");
+        // note that some older versions used PSF_PROBABILITY: this was not well defined.
+        model->chisq      = psMetadataLookupF32 (&status, row, "PSF_CHISQ");
+        model->nDOF       = psMetadataLookupS32 (&status, row, "PSF_NDOF");
+        model->nPix       = psMetadataLookupS32 (&status, row, "PSF_NPIX");
         model->radiusFit  = psMetadataLookupS32 (&status, row, "AP_MAG_RADIUS");
 
-	source->moments = pmMomentsAlloc ();
+        source->moments = pmMomentsAlloc ();
         source->moments->Mxx = psMetadataLookupF32 (&status, row, "MOMENTS_XX");
         source->moments->Mxy = psMetadataLookupF32 (&status, row, "MOMENTS_XY");
@@ -321,5 +324,5 @@
 }
 
-// XXX this layout is still the same as PS1_DEV_1 
+// XXX this layout is still the same as PS1_DEV_1
 bool pmSourcesWrite_CMF_PS1_V1_XSRC (psFits *fits, psArray *sources, char *extname, psMetadata *recipe)
 {
@@ -355,26 +358,26 @@
     // we write out all sources, regardless of quality.  the source flags tell us the state
     for (int i = 0; i < sources->n; i++) {
-	// skip source if it is not a ext sourc
-	// XXX we have two places that extended source parameters are measured:
-	// psphotExtendedSources, which measures the aperture-like parameters and (potentially) the psf-convolved extended source models,
-	// psphotFitEXT, which does the simple extended source model fit (not psf-convolved)
-	// should we require both?
-
-	pmSource *source = sources->data[i];
-
-	// skip sources without measurements
-	if (source->extpars == NULL) continue;
-
-	// we require a PSF model fit (ignore the real crud)
-	pmModel *model = source->modelPSF;
-	if (model == NULL) continue;
-
-	// XXX I need to split the extended models from the extended aperture measurements
-	PAR = model->params->data.F32;
-	dPAR = model->dparams->data.F32;
-	xPos = PAR[PM_PAR_XPOS];
-	yPos = PAR[PM_PAR_YPOS];
-	xErr = dPAR[PM_PAR_XPOS];
-	yErr = dPAR[PM_PAR_YPOS];
+        // skip source if it is not a ext sourc
+        // XXX we have two places that extended source parameters are measured:
+        // psphotExtendedSources, which measures the aperture-like parameters and (potentially) the psf-convolved extended source models,
+        // psphotFitEXT, which does the simple extended source model fit (not psf-convolved)
+        // should we require both?
+
+        pmSource *source = sources->data[i];
+
+        // skip sources without measurements
+        if (source->extpars == NULL) continue;
+
+        // we require a PSF model fit (ignore the real crud)
+        pmModel *model = source->modelPSF;
+        if (model == NULL) continue;
+
+        // XXX I need to split the extended models from the extended aperture measurements
+        PAR = model->params->data.F32;
+        dPAR = model->dparams->data.F32;
+        xPos = PAR[PM_PAR_XPOS];
+        yPos = PAR[PM_PAR_YPOS];
+        xErr = dPAR[PM_PAR_XPOS];
+        yErr = dPAR[PM_PAR_YPOS];
 
         row = psMetadataAlloc ();
@@ -387,101 +390,101 @@
         psMetadataAdd (row, PS_LIST_TAIL, "Y_EXT_SIG",        PS_DATA_F32, "Sigma in EXT y coordinate",                  yErr);
 
-	// Petrosian measurements
-	// XXX insert header data: petrosian ref radius, flux ratio
-	if (doPetrosian) {
-	    pmSourcePetrosianValues *petrosian = source->extpars->petrosian;
-	    if (petrosian) {
-		psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG",        PS_DATA_F32, "Petrosian Magnitude",       petrosian->mag);
-		psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG_ERR",    PS_DATA_F32, "Petrosian Magnitude Error", petrosian->magErr);
-		psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS",     PS_DATA_F32, "Petrosian Radius",          petrosian->rad);
-		psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS_ERR", PS_DATA_F32, "Petrosian Radius Error",    petrosian->radErr);
-	    } else {
-		psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG",        PS_DATA_F32, "Petrosian Magnitude",       NAN);
-		psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG_ERR",    PS_DATA_F32, "Petrosian Magnitude Error", NAN);
-		psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS",     PS_DATA_F32, "Petrosian Radius",          NAN);
-		psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS_ERR", PS_DATA_F32, "Petrosian Radius Error",    NAN);
-	    }
-	} 
-
-	// Kron measurements
-	if (doKron) {
-	    pmSourceKronValues *kron = source->extpars->kron;
-	    if (kron) {
-		psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG",        PS_DATA_F32, "Kron Magnitude",       kron->mag);
-		psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG_ERR",    PS_DATA_F32, "Kron Magnitude Error", kron->magErr);
-		psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS",     PS_DATA_F32, "Kron Radius",          kron->rad);
-		psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS_ERR", PS_DATA_F32, "Kron Radius Error",    kron->radErr);
-	    } else {
-		psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG",        PS_DATA_F32, "Kron Magnitude",       NAN);
-		psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG_ERR",    PS_DATA_F32, "Kron Magnitude Error", NAN);
-		psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS",     PS_DATA_F32, "Kron Radius",          NAN);
-		psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS_ERR", PS_DATA_F32, "Kron Radius Error",    NAN);
-	    }
-	}
-
-	// Isophot measurements
-	// XXX insert header data: isophotal level
-	if (doIsophotal) {
-	    pmSourceIsophotalValues *isophot = source->extpars->isophot;
-	    if (isophot) {
-		psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG",        PS_DATA_F32, "Isophot Magnitude",       isophot->mag);
-		psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG_ERR",    PS_DATA_F32, "Isophot Magnitude Error", isophot->magErr);
-		psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS",     PS_DATA_F32, "Isophot Radius",          isophot->rad);
-		psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS_ERR", PS_DATA_F32, "Isophot Radius Error",    isophot->radErr);
-	    } else {
-		psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG",        PS_DATA_F32, "Isophot Magnitude",       NAN);
-		psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG_ERR",    PS_DATA_F32, "Isophot Magnitude Error", NAN);
-		psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS",     PS_DATA_F32, "Isophot Radius",          NAN);
-		psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS_ERR", PS_DATA_F32, "Isophot Radius Error",    NAN);
-	    }
-	}
-
-	// Flux Annuli
-	if (doAnnuli) {
-	    pmSourceAnnuli *annuli = source->extpars->annuli;
-	    if (annuli) {
-		psVector *fluxVal = annuli->flux;
-		psVector *fluxErr = annuli->fluxErr;
-		psVector *fluxVar = annuli->fluxVar;
-
-		for (int j = 0; j < fluxVal->n; j++) {
-		    char name[32];
-		    sprintf (name, "FLUX_VAL_R_%02d", j);
-		    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux value in annulus", fluxVal->data.F32[j]);
-		    sprintf (name, "FLUX_ERR_R_%02d", j);
-		    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux error in annulus", fluxErr->data.F32[j]);
-		    sprintf (name, "FLUX_VAR_R_%02d", j);
-		    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux stdev in annulus", fluxVar->data.F32[j]);
-		} 
-	    } else {
-		for (int j = 0; j < radialBinsLower->n; j++) {
-		    char name[32];
-		    sprintf (name, "FLUX_VAL_R_%02d", j);
-		    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux value in annulus", NAN);
-		    sprintf (name, "FLUX_ERR_R_%02d", j);
-		    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux error in annulus", NAN);
-		    sprintf (name, "FLUX_VAR_R_%02d", j);
-		    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux stdev in annulus", NAN);
-		} 
-	    }
-	}
-
-	psArrayAdd (table, 100, row);
-	psFree (row);
+        // Petrosian measurements
+        // XXX insert header data: petrosian ref radius, flux ratio
+        if (doPetrosian) {
+            pmSourcePetrosianValues *petrosian = source->extpars->petrosian;
+            if (petrosian) {
+                psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG",        PS_DATA_F32, "Petrosian Magnitude",       petrosian->mag);
+                psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG_ERR",    PS_DATA_F32, "Petrosian Magnitude Error", petrosian->magErr);
+                psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS",     PS_DATA_F32, "Petrosian Radius",          petrosian->rad);
+                psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS_ERR", PS_DATA_F32, "Petrosian Radius Error",    petrosian->radErr);
+            } else {
+                psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG",        PS_DATA_F32, "Petrosian Magnitude",       NAN);
+                psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG_ERR",    PS_DATA_F32, "Petrosian Magnitude Error", NAN);
+                psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS",     PS_DATA_F32, "Petrosian Radius",          NAN);
+                psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS_ERR", PS_DATA_F32, "Petrosian Radius Error",    NAN);
+            }
+        }
+
+        // Kron measurements
+        if (doKron) {
+            pmSourceKronValues *kron = source->extpars->kron;
+            if (kron) {
+                psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG",        PS_DATA_F32, "Kron Magnitude",       kron->mag);
+                psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG_ERR",    PS_DATA_F32, "Kron Magnitude Error", kron->magErr);
+                psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS",     PS_DATA_F32, "Kron Radius",          kron->rad);
+                psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS_ERR", PS_DATA_F32, "Kron Radius Error",    kron->radErr);
+            } else {
+                psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG",        PS_DATA_F32, "Kron Magnitude",       NAN);
+                psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG_ERR",    PS_DATA_F32, "Kron Magnitude Error", NAN);
+                psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS",     PS_DATA_F32, "Kron Radius",          NAN);
+                psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS_ERR", PS_DATA_F32, "Kron Radius Error",    NAN);
+            }
+        }
+
+        // Isophot measurements
+        // XXX insert header data: isophotal level
+        if (doIsophotal) {
+            pmSourceIsophotalValues *isophot = source->extpars->isophot;
+            if (isophot) {
+                psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG",        PS_DATA_F32, "Isophot Magnitude",       isophot->mag);
+                psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG_ERR",    PS_DATA_F32, "Isophot Magnitude Error", isophot->magErr);
+                psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS",     PS_DATA_F32, "Isophot Radius",          isophot->rad);
+                psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS_ERR", PS_DATA_F32, "Isophot Radius Error",    isophot->radErr);
+            } else {
+                psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG",        PS_DATA_F32, "Isophot Magnitude",       NAN);
+                psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG_ERR",    PS_DATA_F32, "Isophot Magnitude Error", NAN);
+                psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS",     PS_DATA_F32, "Isophot Radius",          NAN);
+                psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS_ERR", PS_DATA_F32, "Isophot Radius Error",    NAN);
+            }
+        }
+
+        // Flux Annuli
+        if (doAnnuli) {
+            pmSourceAnnuli *annuli = source->extpars->annuli;
+            if (annuli) {
+                psVector *fluxVal = annuli->flux;
+                psVector *fluxErr = annuli->fluxErr;
+                psVector *fluxVar = annuli->fluxVar;
+
+                for (int j = 0; j < fluxVal->n; j++) {
+                    char name[32];
+                    sprintf (name, "FLUX_VAL_R_%02d", j);
+                    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux value in annulus", fluxVal->data.F32[j]);
+                    sprintf (name, "FLUX_ERR_R_%02d", j);
+                    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux error in annulus", fluxErr->data.F32[j]);
+                    sprintf (name, "FLUX_VAR_R_%02d", j);
+                    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux stdev in annulus", fluxVar->data.F32[j]);
+                }
+            } else {
+                for (int j = 0; j < radialBinsLower->n; j++) {
+                    char name[32];
+                    sprintf (name, "FLUX_VAL_R_%02d", j);
+                    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux value in annulus", NAN);
+                    sprintf (name, "FLUX_ERR_R_%02d", j);
+                    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux error in annulus", NAN);
+                    sprintf (name, "FLUX_VAR_R_%02d", j);
+                    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux stdev in annulus", NAN);
+                }
+            }
+        }
+
+        psArrayAdd (table, 100, row);
+        psFree (row);
     }
 
     if (table->n == 0) {
-	psFitsWriteBlank (fits, outhead, extname);
-	psFree (outhead);
-	psFree (table);
-	return true;
+        psFitsWriteBlank (fits, outhead, extname);
+        psFree (outhead);
+        psFree (table);
+        return true;
     }
 
     psTrace ("pmFPAfile", 5, "writing ext data %s\n", extname);
     if (!psFitsWriteTable (fits, outhead, table, extname)) {
-	psError(PS_ERR_IO, false, "writing ext data %s\n", extname);
-	psFree (outhead);
-	psFree(table);
-	return false;
+        psError(PS_ERR_IO, false, "writing ext data %s\n", extname);
+        psFree (outhead);
+        psFree(table);
+        return false;
     }
     psFree (outhead);
@@ -491,5 +494,5 @@
 }
 
-// XXX this layout is still the same as PS1_DEV_1 
+// XXX this layout is still the same as PS1_DEV_1
 bool pmSourcesWrite_CMF_PS1_V1_XFIT (psFits *fits, psArray *sources, char *extname)
 {
@@ -515,11 +518,11 @@
     int nParamMax = 0;
     for (int i = 0; i < sources->n; i++) {
-	pmSource *source = sources->data[i];
-	if (source->modelFits == NULL) continue;
-	for (int j = 0; j < source->modelFits->n; j++) {
-	    pmModel *model = source->modelFits->data[j];
-	    assert (model);
-	    nParamMax = PS_MAX (nParamMax, model->params->n);
-	}
+        pmSource *source = sources->data[i];
+        if (source->modelFits == NULL) continue;
+        for (int j = 0; j < source->modelFits->n; j++) {
+            pmModel *model = source->modelFits->data[j];
+            assert (model);
+            nParamMax = PS_MAX (nParamMax, model->params->n);
+        }
     }
 
@@ -529,85 +532,85 @@
     for (int i = 0; i < sources->n; i++) {
 
-	pmSource *source = sources->data[i];
-
-	// XXX if no model fits are saved, write out modelEXT?
-	if (source->modelFits == NULL) continue;
-
-	// We have multiple sources : need to flag the one used to subtract the light (the 'best' model)
-	for (int j = 0; j < source->modelFits->n; j++) {
-
-	    // choose the convolved EXT model, if available, otherwise the simple one
-	    pmModel *model = source->modelFits->data[j];
-	    assert (model);
-
-	    PAR = model->params->data.F32;
-	    dPAR = model->dparams->data.F32;
-	    xPos = PAR[PM_PAR_XPOS];
-	    yPos = PAR[PM_PAR_YPOS];
-	    xErr = dPAR[PM_PAR_XPOS];
-	    yErr = dPAR[PM_PAR_YPOS];
-
-	    axes = pmPSF_ModelToAxes (PAR, 20.0);
-
-	    row = psMetadataAlloc ();
-
-	    // XXX we are not writing out the mode (flags) or the type (psf, ext, etc)
-	    psMetadataAddU32 (row, PS_LIST_TAIL, "IPP_IDET",         0, "IPP detection identifier index",             source->seq);
-	    psMetadataAddF32 (row, PS_LIST_TAIL, "X_EXT",            0, "EXT model x coordinate",                     xPos);
-	    psMetadataAddF32 (row, PS_LIST_TAIL, "Y_EXT",            0, "EXT model y coordinate",                     yPos);
-	    psMetadataAddF32 (row, PS_LIST_TAIL, "X_EXT_SIG",        0, "Sigma in EXT x coordinate",                  xErr);
-	    psMetadataAddF32 (row, PS_LIST_TAIL, "Y_EXT_SIG",        0, "Sigma in EXT y coordinate",                  yErr);
-	    psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_INST_MAG",     0, "EXT fit instrumental magnitude",             model->mag);
-	    psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_INST_MAG_SIG", 0, "Sigma of PSF instrumental magnitude",        model->magErr);
-
-	    psMetadataAddF32 (row, PS_LIST_TAIL, "NPARAMS",          0, "number of model parameters",                 model->params->n);
-	    psMetadataAddStr (row, PS_LIST_TAIL, "MODEL_TYPE",       0, "name of model",                              pmModelClassGetName (model->type));
-
-	    // XXX these should be major and minor, not 'x' and 'y'
-	    psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_WIDTH_MAJ",    0, "EXT width in x coordinate",                  axes.major);
-	    psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_WIDTH_MIN",    0, "EXT width in y coordinate",                  axes.minor);
-	    psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_THETA",        0, "EXT orientation angle",                      axes.theta);
-
-	    // write out the other generic parameters
-	    for (int k = 0; k < nParamMax; k++) {
-		if (k == PM_PAR_I0) continue;
-		if (k == PM_PAR_SKY) continue;
-		if (k == PM_PAR_XPOS) continue;
-		if (k == PM_PAR_YPOS) continue;
-		if (k == PM_PAR_SXX) continue;
-		if (k == PM_PAR_SXY) continue;
-		if (k == PM_PAR_SYY) continue;
-
-		snprintf (name, 64, "EXT_PAR_%02d", k);
-
-		if (k < model->params->n) {
-		    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "", model->params->data.F32[k]);
-		} else {
-		    psMetadataAddF32 (row, PS_LIST_TAIL, name, PS_DATA_F32, "", NAN);
-		}
-	    }
-
-	    // XXX other parameters which may be set.
-	    // XXX flag / value to define the model
-	    // XXX write out the model type, fit status flags
-
-	    psArrayAdd (table, 100, row);
-	    psFree (row);
-	}
+        pmSource *source = sources->data[i];
+
+        // XXX if no model fits are saved, write out modelEXT?
+        if (source->modelFits == NULL) continue;
+
+        // We have multiple sources : need to flag the one used to subtract the light (the 'best' model)
+        for (int j = 0; j < source->modelFits->n; j++) {
+
+            // choose the convolved EXT model, if available, otherwise the simple one
+            pmModel *model = source->modelFits->data[j];
+            assert (model);
+
+            PAR = model->params->data.F32;
+            dPAR = model->dparams->data.F32;
+            xPos = PAR[PM_PAR_XPOS];
+            yPos = PAR[PM_PAR_YPOS];
+            xErr = dPAR[PM_PAR_XPOS];
+            yErr = dPAR[PM_PAR_YPOS];
+
+            axes = pmPSF_ModelToAxes (PAR, 20.0);
+
+            row = psMetadataAlloc ();
+
+            // XXX we are not writing out the mode (flags) or the type (psf, ext, etc)
+            psMetadataAddU32 (row, PS_LIST_TAIL, "IPP_IDET",         0, "IPP detection identifier index",             source->seq);
+            psMetadataAddF32 (row, PS_LIST_TAIL, "X_EXT",            0, "EXT model x coordinate",                     xPos);
+            psMetadataAddF32 (row, PS_LIST_TAIL, "Y_EXT",            0, "EXT model y coordinate",                     yPos);
+            psMetadataAddF32 (row, PS_LIST_TAIL, "X_EXT_SIG",        0, "Sigma in EXT x coordinate",                  xErr);
+            psMetadataAddF32 (row, PS_LIST_TAIL, "Y_EXT_SIG",        0, "Sigma in EXT y coordinate",                  yErr);
+            psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_INST_MAG",     0, "EXT fit instrumental magnitude",             model->mag);
+            psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_INST_MAG_SIG", 0, "Sigma of PSF instrumental magnitude",        model->magErr);
+
+            psMetadataAddF32 (row, PS_LIST_TAIL, "NPARAMS",          0, "number of model parameters",                 model->params->n);
+            psMetadataAddStr (row, PS_LIST_TAIL, "MODEL_TYPE",       0, "name of model",                              pmModelClassGetName (model->type));
+
+            // XXX these should be major and minor, not 'x' and 'y'
+            psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_WIDTH_MAJ",    0, "EXT width in x coordinate",                  axes.major);
+            psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_WIDTH_MIN",    0, "EXT width in y coordinate",                  axes.minor);
+            psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_THETA",        0, "EXT orientation angle",                      axes.theta);
+
+            // write out the other generic parameters
+            for (int k = 0; k < nParamMax; k++) {
+                if (k == PM_PAR_I0) continue;
+                if (k == PM_PAR_SKY) continue;
+                if (k == PM_PAR_XPOS) continue;
+                if (k == PM_PAR_YPOS) continue;
+                if (k == PM_PAR_SXX) continue;
+                if (k == PM_PAR_SXY) continue;
+                if (k == PM_PAR_SYY) continue;
+
+                snprintf (name, 64, "EXT_PAR_%02d", k);
+
+                if (k < model->params->n) {
+                    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "", model->params->data.F32[k]);
+                } else {
+                    psMetadataAddF32 (row, PS_LIST_TAIL, name, PS_DATA_F32, "", NAN);
+                }
+            }
+
+            // XXX other parameters which may be set.
+            // XXX flag / value to define the model
+            // XXX write out the model type, fit status flags
+
+            psArrayAdd (table, 100, row);
+            psFree (row);
+        }
     }
 
     if (table->n == 0) {
-	psFitsWriteBlank (fits, outhead, extname);
-	psFree (outhead);
-	psFree (table);
-	return true;
+        psFitsWriteBlank (fits, outhead, extname);
+        psFree (outhead);
+        psFree (table);
+        return true;
     }
 
     psTrace ("pmFPAfile", 5, "writing ext data %s\n", extname);
     if (!psFitsWriteTable (fits, outhead, table, extname)) {
-	psError(PS_ERR_IO, false, "writing ext data %s\n", extname);
-	psFree (outhead);
-	psFree(table);
-	return false;
+        psError(PS_ERR_IO, false, "writing ext data %s\n", extname);
+        psFree (outhead);
+        psFree(table);
+        return false;
     }
     psFree (outhead);
@@ -645,5 +648,5 @@
     psPlaneTransformApply (&ptFP, chip->toFPA, &ptCH);
     psPlaneTransformApply (&ptTP_y, fpa->toTPA, &ptFP);
-    
+
     // the resulting Tangent Plane coordinates are in TP pixels; convert to local Tangent Plane
     // degrees
@@ -671,5 +674,5 @@
     *posAngle = NAN;
     *pltScale = NAN;
-    
+
     return false;
 }
Index: /branches/cnb_branches/cnb_branch_20090215/psModules/src/objects/pmSourceIO_PS1_CAL_0.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/objects/pmSourceIO_PS1_CAL_0.c	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psModules/src/objects/pmSourceIO_PS1_CAL_0.c	(revision 23197)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.2.14.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2009-02-19 17:59:50 $
+ *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-02-16 22:30:50 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -49,6 +49,6 @@
 // XXX how do I generate the source tables which I need to send to PSPS?
 
-bool pmSourcesWrite_PS1_CAL_0 (psFits *fits, pmReadout *readout, psArray *sources,
-                               psMetadata *imageHeader, psMetadata *tableHeader, char *extname)
+bool pmSourcesWrite_PS1_CAL_0 (psFits *fits, pmReadout *readout, psArray *sources, 
+			       psMetadata *imageHeader, psMetadata *tableHeader, char *extname)
 {
     PS_ASSERT_PTR_NON_NULL(fits, false);
@@ -68,5 +68,5 @@
     pmFPA  *fpa  = chip->parent;
     if (!chip->toFPA || !fpa->toTPA || !fpa->toSky) {
-        psWarning ("astrometry calibration is missing, no calibrated coords");
+	psWarning ("astrometry calibration is missing, no calibrated coords");
     }
 
@@ -77,7 +77,7 @@
     float zeropt  = psMetadataLookupF32 (&status2, imageHeader, "ZPT_OBS");
     if (!status1 || !status2 || (exptime == 0.0)) {
-        psWarning ("exposure time or measured zero point not found for a readout, no calibrated mags");
+	psWarning ("exposure time or measured zero point not found for a readout, no calibrated mags");
     } else {
-        magOffset = zeropt + 2.5*log10(exptime);
+	magOffset = zeropt + 2.5*log10(exptime);
     }
 
@@ -90,7 +90,7 @@
     for (i = 0; i < sources->n; i++) {
         pmSource *source = (pmSource *) sources->data[i];
-        if (source->seq == -1) {
-            source->seq = i;
-        }
+	if (source->seq == -1) {
+	    source->seq = i;
+	}
 
         // no difference between PSF and non-PSF model
@@ -104,15 +104,15 @@
             xErr = dPAR[PM_PAR_XPOS];
             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, 20.0);
-            } else {
-                axes.major = NAN;
-                axes.minor = NAN;
-                axes.theta = NAN;
-            }
-            chisq = model->chisq;
-
-            // need to determine the PSF photometry error: source->errMag is the error on the 'best' model mag.
-            errMag = model->dparams->data.F32[PM_PAR_I0] / model->params->data.F32[PM_PAR_I0];
+	    if (isfinite(PAR[PM_PAR_SXX]) && isfinite(PAR[PM_PAR_SXX]) && isfinite(PAR[PM_PAR_SXX])) {
+		axes = pmPSF_ModelToAxes (PAR, 20.0);
+	    } else {
+		axes.major = NAN;
+		axes.minor = NAN;
+		axes.theta = NAN;
+	    }
+	    chisq = model->chisq;
+
+	    // need to determine the PSF photometry error: source->errMag is the error on the 'best' model mag.
+	    errMag = model->dparams->data.F32[PM_PAR_I0] / model->params->data.F32[PM_PAR_I0];
         } else {
             xPos = source->peak->xf;
@@ -123,26 +123,26 @@
             axes.minor = NAN;
             axes.theta = NAN;
-            chisq = NAN;
-            errMag = NAN;
+	    chisq = NAN;
+	    errMag = NAN;
         }
 
-        float calMag = source->psfMag + magOffset;
+	float calMag = source->psfMag + magOffset;
         float peakMag = (source->peak->flux > 0) ? -2.5*log10(source->peak->flux) : NAN;
         psS16 nImageOverlap = 1;
 
-        // generate RA,DEC
-        psPlane ptCH, ptFP, ptTP;
-        psSphere ptSky;
-
-        ptCH.x = xPos;
-        ptCH.y = yPos;
-        if (chip->toFPA && fpa->toTPA && fpa->toSky) {
-            psPlaneTransformApply (&ptFP, chip->toFPA, &ptCH);
-            psPlaneTransformApply (&ptTP, fpa->toTPA, &ptFP);
-            psDeproject (&ptSky, &ptTP, fpa->toSky);
-        } else {
-            ptSky.r = NAN;
-            ptSky.d = NAN;
-        }
+	// generate RA,DEC
+	psPlane ptCH, ptFP, ptTP;
+	psSphere ptSky;
+
+	ptCH.x = xPos;
+	ptCH.y = yPos;
+	if (chip->toFPA && fpa->toTPA && fpa->toSky) {
+	    psPlaneTransformApply (&ptFP, chip->toFPA, &ptCH);
+	    psPlaneTransformApply (&ptTP, fpa->toTPA, &ptFP);
+	    psDeproject (&ptSky, &ptTP, fpa->toSky);
+	} else {
+	    ptSky.r = NAN;
+	    ptSky.d = NAN;
+	}
 
         row = psMetadataAlloc ();
@@ -150,5 +150,5 @@
         psMetadataAdd (row, PS_LIST_TAIL, "RA_PSF",           PS_DATA_F32, "PSF RA coordinate (degrees)",                ptSky.r*PS_DEG_RAD);
         psMetadataAdd (row, PS_LIST_TAIL, "DEC_PSF",          PS_DATA_F32, "PSF DEC coordinate (degrees)",               ptSky.d*PS_DEG_RAD);
-        // XXX need to do the error propagation correctly..
+	// XXX need to do the error propagation correctly..
         // psMetadataAdd (row, PS_LIST_TAIL, "RA_PSF_SIG",       PS_DATA_F32, "Sigma of PSF fit RA",                     dRA);
         // psMetadataAdd (row, PS_LIST_TAIL, "DEC_PSF_SIG",      PS_DATA_F32, "Sigma of PSF fit DEC",                    dDEC);
@@ -170,9 +170,9 @@
         psMetadataAdd (row, PS_LIST_TAIL, "EXT_NSIGMA",       PS_DATA_F32,  "Nsigma deviations from PSF to EXT",         source->extNsigma);
 
-        // EXT_NSIGMA will be NAN if: 1) contour ellipse is imaginary; 2) source is not
-        // subtracted
-
-        // CR_NSIGMA will be NAN if: 1) source is not subtracted; 2) source is on the image
-        // edge; 3) any pixels in the 3x3 peak region are masked;
+	// EXT_NSIGMA will be NAN if: 1) contour ellipse is imaginary; 2) source is not
+	// subtracted
+
+	// CR_NSIGMA will be NAN if: 1) source is not subtracted; 2) source is on the image
+	// edge; 3) any pixels in the 3x3 peak region are masked; 
 
         // XXX these should be major and minor, not 'x' and 'y'
@@ -277,6 +277,6 @@
         source->psfMag    = psMetadataLookupF32 (&status, row, "PSF_INST_MAG");
         source->errMag    = psMetadataLookupF32 (&status, row, "PSF_INST_MAG_SIG");
-        PAR[PM_PAR_I0]    = (isfinite(source->psfMag)) ? pow(10.0, -0.4*source->psfMag) : NAN;
-        dPAR[PM_PAR_I0]   = (isfinite(source->psfMag)) ? PAR[PM_PAR_I0] * source->errMag : NAN;
+	PAR[PM_PAR_I0]    = (isfinite(source->psfMag)) ? pow(10.0, -0.4*source->psfMag) : NAN;
+	dPAR[PM_PAR_I0]   = (isfinite(source->psfMag)) ? PAR[PM_PAR_I0] * source->errMag : NAN;
 
         pmPSF_AxesToModel (PAR, axes);
@@ -289,5 +289,5 @@
         source->pixWeight = psMetadataLookupF32 (&status, row, "PSF_QF");
 
-        // note that some older versions used PSF_PROBABILITY: this was not well defined.
+	// note that some older versions used PSF_PROBABILITY: this was not well defined.
         model->chisq      = psMetadataLookupF32 (&status, row, "PSF_CHISQ");
         source->crNsigma  = psMetadataLookupF32 (&status, row, "CR_NSIGMA");
@@ -321,5 +321,5 @@
     pmFPA  *fpa  = chip->parent;
     if (!chip->toFPA || !fpa->toTPA || !fpa->toSky) {
-        psWarning ("astrometry calibration is missing, no calibrated coords");
+	psWarning ("astrometry calibration is missing, no calibrated coords");
     }
 
@@ -331,8 +331,8 @@
     float zeropt  = psMetadataLookupF32 (&status2, imageHeader, "ZPT_OBS");
     if (!status1 || !status2 || (exptime == 0.0)) {
-        psWarning ("exposure time or measured zero point not found for a readout, no calibrated mags");
+	psWarning ("exposure time or measured zero point not found for a readout, no calibrated mags");
     } else {
-        magOffset = zeropt + 2.5*log10(exptime);
-        calMags = true;
+	magOffset = zeropt + 2.5*log10(exptime);
+	calMags = true;
     }
 
@@ -360,41 +360,41 @@
     // we write out all sources, regardless of quality.  the source flags tell us the state
     for (int i = 0; i < sources->n; i++) {
-        // skip source if it is not a ext sourc
-        // XXX we have two places that extended source parameters are measured:
-        // psphotExtendedSources, which measures the aperture-like parameters and (potentially) the psf-convolved extended source models,
-        // psphotFitEXT, which does the simple extended source model fit (not psf-convolved)
-        // should we require both?
-
-        pmSource *source = sources->data[i];
-
-        // skip sources without measurements
-        if (source->extpars == NULL) continue;
-
-        // we require a PSF model fit (ignore the real crud)
-        pmModel *model = source->modelPSF;
-        if (model == NULL) continue;
-
-        // XXX I need to split the extended models from the extended aperture measurements
-        PAR = model->params->data.F32;
-        dPAR = model->dparams->data.F32;
-        xPos = PAR[PM_PAR_XPOS];
-        yPos = PAR[PM_PAR_YPOS];
-        xErr = dPAR[PM_PAR_XPOS];
-        yErr = dPAR[PM_PAR_YPOS];
-
-        // generate RA,DEC
-        psPlane ptCH, ptFP, ptTP;
-        psSphere ptSky;
-
-        ptCH.x = xPos;
-        ptCH.y = yPos;
-        if (chip->toFPA && fpa->toTPA && fpa->toSky) {
-            psPlaneTransformApply (&ptFP, chip->toFPA, &ptCH);
-            psPlaneTransformApply (&ptTP, fpa->toTPA, &ptFP);
-            psDeproject (&ptSky, &ptTP, fpa->toSky);
-        } else {
-            ptSky.r = NAN;
-            ptSky.d = NAN;
-        }
+	// skip source if it is not a ext sourc
+	// XXX we have two places that extended source parameters are measured:
+	// psphotExtendedSources, which measures the aperture-like parameters and (potentially) the psf-convolved extended source models,
+	// psphotFitEXT, which does the simple extended source model fit (not psf-convolved)
+	// should we require both?
+
+	pmSource *source = sources->data[i];
+
+	// skip sources without measurements
+	if (source->extpars == NULL) continue;
+
+	// we require a PSF model fit (ignore the real crud)
+	pmModel *model = source->modelPSF;
+	if (model == NULL) continue;
+
+	// XXX I need to split the extended models from the extended aperture measurements
+	PAR = model->params->data.F32;
+	dPAR = model->dparams->data.F32;
+	xPos = PAR[PM_PAR_XPOS];
+	yPos = PAR[PM_PAR_YPOS];
+	xErr = dPAR[PM_PAR_XPOS];
+	yErr = dPAR[PM_PAR_YPOS];
+
+	// generate RA,DEC
+	psPlane ptCH, ptFP, ptTP;
+	psSphere ptSky;
+
+	ptCH.x = xPos;
+	ptCH.y = yPos;
+	if (chip->toFPA && fpa->toTPA && fpa->toSky) {
+	    psPlaneTransformApply (&ptFP, chip->toFPA, &ptCH);
+	    psPlaneTransformApply (&ptTP, fpa->toTPA, &ptFP);
+	    psDeproject (&ptSky, &ptTP, fpa->toSky);
+	} else {
+	    ptSky.r = NAN;
+	    ptSky.d = NAN;
+	}
 
         row = psMetadataAlloc ();
@@ -410,113 +410,113 @@
         psMetadataAdd (row, PS_LIST_TAIL, "Y_EXT_SIG",        PS_DATA_F32, "Sigma in EXT y coordinate",                  yErr);
 
-        // Petrosian measurements
-        // XXX insert header data: petrosian ref radius, flux ratio
-        if (doPetrosian) {
-            pmSourcePetrosianValues *petrosian = source->extpars->petrosian;
-            if (petrosian) {
-                if (calMags) {
-                    psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG_CAL",    PS_DATA_F32, "Petrosian Magnitude (calibrated)", petrosian->mag + magOffset);
-                } else {
-                    psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG_INST",   PS_DATA_F32, "Petrosian Magnitude (instrumental)", petrosian->mag);
-                }
-                psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG_ERR",    PS_DATA_F32, "Petrosian Magnitude Error", petrosian->magErr);
-                psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS",     PS_DATA_F32, "Petrosian Radius",          petrosian->rad);
-                psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS_ERR", PS_DATA_F32, "Petrosian Radius Error",    petrosian->radErr);
-            } else {
-                psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG",        PS_DATA_F32, "Petrosian Magnitude",       NAN);
-                psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG_ERR",    PS_DATA_F32, "Petrosian Magnitude Error", NAN);
-                psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS",     PS_DATA_F32, "Petrosian Radius",          NAN);
-                psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS_ERR", PS_DATA_F32, "Petrosian Radius Error",    NAN);
-            }
-        }
-
-        // Kron measurements
-        if (doKron) {
-            pmSourceKronValues *kron = source->extpars->kron;
-            if (kron) {
-                if (calMags) {
-                    psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG_CAL",  PS_DATA_F32, "Kron Magnitude",     kron->mag + magOffset);
-                } else {
-                    psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG_INST", PS_DATA_F32, "Kron Magnitude",     kron->mag);
-                }
-                psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG_ERR",    PS_DATA_F32, "Kron Magnitude Error", kron->magErr);
-                psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS",     PS_DATA_F32, "Kron Radius",          kron->rad);
-                psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS_ERR", PS_DATA_F32, "Kron Radius Error",    kron->radErr);
-            } else {
-                psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG",        PS_DATA_F32, "Kron Magnitude",       NAN);
-                psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG_ERR",    PS_DATA_F32, "Kron Magnitude Error", NAN);
-                psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS",     PS_DATA_F32, "Kron Radius",          NAN);
-                psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS_ERR", PS_DATA_F32, "Kron Radius Error",    NAN);
-            }
-        }
-
-        // Isophot measurements
-        // XXX insert header data: isophotal level
-        if (doIsophotal) {
-            pmSourceIsophotalValues *isophot = source->extpars->isophot;
-            if (isophot) {
-                if (calMags) {
-                    psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG_CAL",    PS_DATA_F32, "Isophot Magnitude (calibrated)",   isophot->mag + magOffset);
-                } else {
-                    psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG_INST",   PS_DATA_F32, "Isophot Magnitude (uncalibrated)", isophot->mag);
-                }
-                psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG_ERR",    PS_DATA_F32, "Isophot Magnitude Error", isophot->magErr);
-                psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS",     PS_DATA_F32, "Isophot Radius",          isophot->rad);
-                psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS_ERR", PS_DATA_F32, "Isophot Radius Error",    isophot->radErr);
-            } else {
-                psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG",        PS_DATA_F32, "Isophot Magnitude",       NAN);
-                psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG_ERR",    PS_DATA_F32, "Isophot Magnitude Error", NAN);
-                psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS",     PS_DATA_F32, "Isophot Radius",          NAN);
-                psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS_ERR", PS_DATA_F32, "Isophot Radius Error",    NAN);
-            }
-        }
-
-        // Flux Annuli
-        if (doAnnuli) {
-            pmSourceAnnuli *annuli = source->extpars->annuli;
-            if (annuli) {
-                psVector *fluxVal = annuli->flux;
-                psVector *fluxErr = annuli->fluxErr;
-                psVector *fluxVar = annuli->fluxVar;
-
-                for (int j = 0; j < fluxVal->n; j++) {
-                    char name[32];
-                    sprintf (name, "FLUX_VAL_R_%02d", j);
-                    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux value in annulus", fluxVal->data.F32[j]);
-                    sprintf (name, "FLUX_ERR_R_%02d", j);
-                    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux error in annulus", fluxErr->data.F32[j]);
-                    sprintf (name, "FLUX_VAR_R_%02d", j);
-                    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux stdev in annulus", fluxVar->data.F32[j]);
-                }
-            } else {
-                for (int j = 0; j < radialBinsLower->n; j++) {
-                    char name[32];
-                    sprintf (name, "FLUX_VAL_R_%02d", j);
-                    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux value in annulus", NAN);
-                    sprintf (name, "FLUX_ERR_R_%02d", j);
-                    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux error in annulus", NAN);
-                    sprintf (name, "FLUX_VAR_R_%02d", j);
-                    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux stdev in annulus", NAN);
-                }
-            }
-        }
-
-        psArrayAdd (table, 100, row);
-        psFree (row);
+	// Petrosian measurements
+	// XXX insert header data: petrosian ref radius, flux ratio
+	if (doPetrosian) {
+	    pmSourcePetrosianValues *petrosian = source->extpars->petrosian;
+	    if (petrosian) {
+		if (calMags) {
+		    psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG_CAL",    PS_DATA_F32, "Petrosian Magnitude (calibrated)", petrosian->mag + magOffset);
+		} else {
+		    psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG_INST",   PS_DATA_F32, "Petrosian Magnitude (instrumental)", petrosian->mag);
+		}
+		psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG_ERR",    PS_DATA_F32, "Petrosian Magnitude Error", petrosian->magErr);
+		psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS",     PS_DATA_F32, "Petrosian Radius",          petrosian->rad);
+		psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS_ERR", PS_DATA_F32, "Petrosian Radius Error",    petrosian->radErr);
+	    } else {
+		psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG",        PS_DATA_F32, "Petrosian Magnitude",       NAN);
+		psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG_ERR",    PS_DATA_F32, "Petrosian Magnitude Error", NAN);
+		psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS",     PS_DATA_F32, "Petrosian Radius",          NAN);
+		psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS_ERR", PS_DATA_F32, "Petrosian Radius Error",    NAN);
+	    }
+	} 
+
+	// Kron measurements
+	if (doKron) {
+	    pmSourceKronValues *kron = source->extpars->kron;
+	    if (kron) {
+		if (calMags) {
+		    psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG_CAL",  PS_DATA_F32, "Kron Magnitude",     kron->mag + magOffset);
+		} else {
+		    psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG_INST", PS_DATA_F32, "Kron Magnitude",     kron->mag);
+		}
+		psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG_ERR",    PS_DATA_F32, "Kron Magnitude Error", kron->magErr);
+		psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS",     PS_DATA_F32, "Kron Radius",          kron->rad);
+		psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS_ERR", PS_DATA_F32, "Kron Radius Error",    kron->radErr);
+	    } else {
+		psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG",        PS_DATA_F32, "Kron Magnitude",       NAN);
+		psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG_ERR",    PS_DATA_F32, "Kron Magnitude Error", NAN);
+		psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS",     PS_DATA_F32, "Kron Radius",          NAN);
+		psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS_ERR", PS_DATA_F32, "Kron Radius Error",    NAN);
+	    }
+	}
+
+	// Isophot measurements
+	// XXX insert header data: isophotal level
+	if (doIsophotal) {
+	    pmSourceIsophotalValues *isophot = source->extpars->isophot;
+	    if (isophot) {
+		if (calMags) {
+		    psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG_CAL",    PS_DATA_F32, "Isophot Magnitude (calibrated)",   isophot->mag + magOffset);
+		} else {
+		    psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG_INST",   PS_DATA_F32, "Isophot Magnitude (uncalibrated)", isophot->mag);
+		}
+		psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG_ERR",    PS_DATA_F32, "Isophot Magnitude Error", isophot->magErr);
+		psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS",     PS_DATA_F32, "Isophot Radius",          isophot->rad);
+		psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS_ERR", PS_DATA_F32, "Isophot Radius Error",    isophot->radErr);
+	    } else {
+		psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG",        PS_DATA_F32, "Isophot Magnitude",       NAN);
+		psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG_ERR",    PS_DATA_F32, "Isophot Magnitude Error", NAN);
+		psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS",     PS_DATA_F32, "Isophot Radius",          NAN);
+		psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS_ERR", PS_DATA_F32, "Isophot Radius Error",    NAN);
+	    }
+	}
+
+	// Flux Annuli
+	if (doAnnuli) {
+	    pmSourceAnnuli *annuli = source->extpars->annuli;
+	    if (annuli) {
+		psVector *fluxVal = annuli->flux;
+		psVector *fluxErr = annuli->fluxErr;
+		psVector *fluxVar = annuli->fluxVar;
+
+		for (int j = 0; j < fluxVal->n; j++) {
+		    char name[32];
+		    sprintf (name, "FLUX_VAL_R_%02d", j);
+		    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux value in annulus", fluxVal->data.F32[j]);
+		    sprintf (name, "FLUX_ERR_R_%02d", j);
+		    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux error in annulus", fluxErr->data.F32[j]);
+		    sprintf (name, "FLUX_VAR_R_%02d", j);
+		    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux stdev in annulus", fluxVar->data.F32[j]);
+		} 
+	    } else {
+		for (int j = 0; j < radialBinsLower->n; j++) {
+		    char name[32];
+		    sprintf (name, "FLUX_VAL_R_%02d", j);
+		    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux value in annulus", NAN);
+		    sprintf (name, "FLUX_ERR_R_%02d", j);
+		    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux error in annulus", NAN);
+		    sprintf (name, "FLUX_VAR_R_%02d", j);
+		    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux stdev in annulus", NAN);
+		} 
+	    }
+	}
+
+	psArrayAdd (table, 100, row);
+	psFree (row);
     }
 
     if (table->n == 0) {
-        psFitsWriteBlank (fits, outhead, extname);
-        psFree (outhead);
-        psFree (table);
-        return true;
+	psFitsWriteBlank (fits, outhead, extname);
+	psFree (outhead);
+	psFree (table);
+	return true;
     }
 
     psTrace ("pmFPAfile", 5, "writing ext data %s\n", extname);
     if (!psFitsWriteTable (fits, outhead, table, extname)) {
-        psError(PS_ERR_IO, false, "writing ext data %s\n", extname);
-        psFree (outhead);
-        psFree(table);
-        return false;
+	psError(PS_ERR_IO, false, "writing ext data %s\n", extname);
+	psFree (outhead);
+	psFree(table);
+	return false;
     }
     psFree (outhead);
@@ -540,5 +540,5 @@
     pmFPA  *fpa  = chip->parent;
     if (!chip->toFPA || !fpa->toTPA || !fpa->toSky) {
-        psWarning ("astrometry calibration is missing, no calibrated coords");
+	psWarning ("astrometry calibration is missing, no calibrated coords");
     }
 
@@ -549,7 +549,7 @@
     float zeropt  = psMetadataLookupF32 (&status2, imageHeader, "ZPT_OBS");
     if (!status1 || !status2 || (exptime == 0.0)) {
-        psWarning ("exposure time or measured zero point not found for a readout, no calibrated mags");
+	psWarning ("exposure time or measured zero point not found for a readout, no calibrated mags");
     } else {
-        magOffset = zeropt + 2.5*log10(exptime);
+	magOffset = zeropt + 2.5*log10(exptime);
     }
 
@@ -566,11 +566,11 @@
     int nParamMax = 0;
     for (int i = 0; i < sources->n; i++) {
-        pmSource *source = sources->data[i];
-        if (source->modelFits == NULL) continue;
-        for (int j = 0; j < source->modelFits->n; j++) {
-            pmModel *model = source->modelFits->data[j];
-            assert (model);
-            nParamMax = PS_MAX (nParamMax, model->params->n);
-        }
+	pmSource *source = sources->data[i];
+	if (source->modelFits == NULL) continue;
+	for (int j = 0; j < source->modelFits->n; j++) {
+	    pmModel *model = source->modelFits->data[j];
+	    assert (model);
+	    nParamMax = PS_MAX (nParamMax, model->params->n);
+	}
     }
 
@@ -580,103 +580,103 @@
     for (int i = 0; i < sources->n; i++) {
 
-        pmSource *source = sources->data[i];
-
-        // XXX if no model fits are saved, write out modelEXT?
-        if (source->modelFits == NULL) continue;
-
-        // We have multiple sources : need to flag the one used to subtract the light (the 'best' model)
-        for (int j = 0; j < source->modelFits->n; j++) {
-
-            // choose the convolved EXT model, if available, otherwise the simple one
-            pmModel *model = source->modelFits->data[j];
-            assert (model);
-
-            PAR = model->params->data.F32;
-            dPAR = model->dparams->data.F32;
-            xPos = PAR[PM_PAR_XPOS];
-            yPos = PAR[PM_PAR_YPOS];
-            xErr = dPAR[PM_PAR_XPOS];
-            yErr = dPAR[PM_PAR_YPOS];
-
-            axes = pmPSF_ModelToAxes (PAR, 20.0);
-
-            // generate RA,DEC
-            psPlane ptCH, ptFP, ptTP;
-            psSphere ptSky;
-
-            ptCH.x = xPos;
-            ptCH.y = yPos;
-            if (chip->toFPA && fpa->toTPA && fpa->toSky) {
-                psPlaneTransformApply (&ptFP, chip->toFPA, &ptCH);
-                psPlaneTransformApply (&ptTP, fpa->toTPA, &ptFP);
-                psDeproject (&ptSky, &ptTP, fpa->toSky);
-            } else {
-                ptSky.r = NAN;
-                ptSky.d = NAN;
-            }
-
-            row = psMetadataAlloc ();
-
-            // XXX we are not writing out the mode (flags) or the type (psf, ext, etc)
-            psMetadataAddU32 (row, PS_LIST_TAIL, "IPP_IDET",         0, "IPP detection identifier index",             source->seq);
-            psMetadataAddF32 (row, PS_LIST_TAIL, "RA_EXT",           0, "EXT model RA (degrees)",                     ptSky.r);
-            psMetadataAddF32 (row, PS_LIST_TAIL, "DEC_EXT",          0, "EXT model DEC (degrees)",                    ptSky.d);
-            psMetadataAddF32 (row, PS_LIST_TAIL, "X_EXT",            0, "EXT model x coordinate",                     xPos);
-            psMetadataAddF32 (row, PS_LIST_TAIL, "Y_EXT",            0, "EXT model y coordinate",                     yPos);
-            psMetadataAddF32 (row, PS_LIST_TAIL, "X_EXT_SIG",        0, "Sigma in EXT x coordinate",                  xErr);
-            psMetadataAddF32 (row, PS_LIST_TAIL, "Y_EXT_SIG",        0, "Sigma in EXT y coordinate",                  yErr);
-            psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_CAL_MAG",      0, "EXT fit calibrated magnitude",               model->mag + magOffset);
-            psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_INST_MAG",     0, "EXT fit instrumental magnitude",             model->mag);
-            psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_INST_MAG_SIG", 0, "Sigma of PSF instrumental magnitude",        model->magErr);
-
-            psMetadataAddF32 (row, PS_LIST_TAIL, "NPARAMS",          0, "number of model parameters",                 model->params->n);
-            psMetadataAddStr (row, PS_LIST_TAIL, "MODEL_TYPE",       0, "name of model",                              pmModelClassGetName (model->type));
-
-            // XXX these should be major and minor, not 'x' and 'y'
-            psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_WIDTH_MAJ",    0, "EXT width in x coordinate",                  axes.major);
-            psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_WIDTH_MIN",    0, "EXT width in y coordinate",                  axes.minor);
-            psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_THETA",        0, "EXT orientation angle",                      axes.theta);
-
-            // write out the other generic parameters
-            for (int k = 0; k < nParamMax; k++) {
-                if (k == PM_PAR_I0) continue;
-                if (k == PM_PAR_SKY) continue;
-                if (k == PM_PAR_XPOS) continue;
-                if (k == PM_PAR_YPOS) continue;
-                if (k == PM_PAR_SXX) continue;
-                if (k == PM_PAR_SXY) continue;
-                if (k == PM_PAR_SYY) continue;
-
-                snprintf (name, 64, "EXT_PAR_%02d", k);
-
-                if (k < model->params->n) {
-                    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "", model->params->data.F32[k]);
-                } else {
-                    psMetadataAddF32 (row, PS_LIST_TAIL, name, PS_DATA_F32, "", NAN);
-                }
-            }
-
-            // XXX other parameters which may be set.
-            // XXX flag / value to define the model
-            // XXX write out the model type, fit status flags
-
-            psArrayAdd (table, 100, row);
-            psFree (row);
-        }
+	pmSource *source = sources->data[i];
+
+	// XXX if no model fits are saved, write out modelEXT?
+	if (source->modelFits == NULL) continue;
+
+	// We have multiple sources : need to flag the one used to subtract the light (the 'best' model)
+	for (int j = 0; j < source->modelFits->n; j++) {
+
+	    // choose the convolved EXT model, if available, otherwise the simple one
+	    pmModel *model = source->modelFits->data[j];
+	    assert (model);
+
+	    PAR = model->params->data.F32;
+	    dPAR = model->dparams->data.F32;
+	    xPos = PAR[PM_PAR_XPOS];
+	    yPos = PAR[PM_PAR_YPOS];
+	    xErr = dPAR[PM_PAR_XPOS];
+	    yErr = dPAR[PM_PAR_YPOS];
+
+	    axes = pmPSF_ModelToAxes (PAR, 20.0);
+
+	    // generate RA,DEC
+	    psPlane ptCH, ptFP, ptTP;
+	    psSphere ptSky;
+
+	    ptCH.x = xPos;
+	    ptCH.y = yPos;
+	    if (chip->toFPA && fpa->toTPA && fpa->toSky) {
+		psPlaneTransformApply (&ptFP, chip->toFPA, &ptCH);
+		psPlaneTransformApply (&ptTP, fpa->toTPA, &ptFP);
+		psDeproject (&ptSky, &ptTP, fpa->toSky);
+	    } else {
+		ptSky.r = NAN;
+		ptSky.d = NAN;
+	    }
+
+	    row = psMetadataAlloc ();
+
+	    // XXX we are not writing out the mode (flags) or the type (psf, ext, etc)
+	    psMetadataAddU32 (row, PS_LIST_TAIL, "IPP_IDET",         0, "IPP detection identifier index",             source->seq);
+	    psMetadataAddF32 (row, PS_LIST_TAIL, "RA_EXT",           0, "EXT model RA (degrees)",                     ptSky.r);
+	    psMetadataAddF32 (row, PS_LIST_TAIL, "DEC_EXT",          0, "EXT model DEC (degrees)",                    ptSky.d);
+	    psMetadataAddF32 (row, PS_LIST_TAIL, "X_EXT",            0, "EXT model x coordinate",                     xPos);
+	    psMetadataAddF32 (row, PS_LIST_TAIL, "Y_EXT",            0, "EXT model y coordinate",                     yPos);
+	    psMetadataAddF32 (row, PS_LIST_TAIL, "X_EXT_SIG",        0, "Sigma in EXT x coordinate",                  xErr);
+	    psMetadataAddF32 (row, PS_LIST_TAIL, "Y_EXT_SIG",        0, "Sigma in EXT y coordinate",                  yErr);
+	    psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_CAL_MAG",      0, "EXT fit calibrated magnitude",               model->mag + magOffset);
+	    psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_INST_MAG",     0, "EXT fit instrumental magnitude",             model->mag);
+	    psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_INST_MAG_SIG", 0, "Sigma of PSF instrumental magnitude",        model->magErr);
+
+	    psMetadataAddF32 (row, PS_LIST_TAIL, "NPARAMS",          0, "number of model parameters",                 model->params->n);
+	    psMetadataAddStr (row, PS_LIST_TAIL, "MODEL_TYPE",       0, "name of model",                              pmModelClassGetName (model->type));
+
+	    // XXX these should be major and minor, not 'x' and 'y'
+	    psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_WIDTH_MAJ",    0, "EXT width in x coordinate",                  axes.major);
+	    psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_WIDTH_MIN",    0, "EXT width in y coordinate",                  axes.minor);
+	    psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_THETA",        0, "EXT orientation angle",                      axes.theta);
+
+	    // write out the other generic parameters
+	    for (int k = 0; k < nParamMax; k++) {
+		if (k == PM_PAR_I0) continue;
+		if (k == PM_PAR_SKY) continue;
+		if (k == PM_PAR_XPOS) continue;
+		if (k == PM_PAR_YPOS) continue;
+		if (k == PM_PAR_SXX) continue;
+		if (k == PM_PAR_SXY) continue;
+		if (k == PM_PAR_SYY) continue;
+
+		snprintf (name, 64, "EXT_PAR_%02d", k);
+
+		if (k < model->params->n) {
+		    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "", model->params->data.F32[k]);
+		} else {
+		    psMetadataAddF32 (row, PS_LIST_TAIL, name, PS_DATA_F32, "", NAN);
+		}
+	    }
+
+	    // XXX other parameters which may be set.
+	    // XXX flag / value to define the model
+	    // XXX write out the model type, fit status flags
+
+	    psArrayAdd (table, 100, row);
+	    psFree (row);
+	}
     }
 
     if (table->n == 0) {
-        psFitsWriteBlank (fits, outhead, extname);
-        psFree (outhead);
-        psFree (table);
-        return true;
+	psFitsWriteBlank (fits, outhead, extname);
+	psFree (outhead);
+	psFree (table);
+	return true;
     }
 
     psTrace ("pmFPAfile", 5, "writing ext data %s\n", extname);
     if (!psFitsWriteTable (fits, outhead, table, extname)) {
-        psError(PS_ERR_IO, false, "writing ext data %s\n", extname);
-        psFree (outhead);
-        psFree(table);
-        return false;
+	psError(PS_ERR_IO, false, "writing ext data %s\n", extname);
+	psFree (outhead);
+	psFree(table);
+	return false;
     }
     psFree (outhead);
Index: /branches/cnb_branches/cnb_branch_20090215/psModules/src/objects/pmSourceIO_PS1_DEV_1.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/objects/pmSourceIO_PS1_DEV_1.c	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psModules/src/objects/pmSourceIO_PS1_DEV_1.c	(revision 23197)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.14.14.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2009-02-19 17:59:50 $
+ *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-02-16 22:30:50 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -49,6 +49,6 @@
 // XXX how do I generate the source tables which I need to send to PSPS?
 
-bool pmSourcesWrite_PS1_DEV_1 (psFits *fits, psArray *sources,
-                               psMetadata *imageHeader, psMetadata *tableHeader, char *extname)
+bool pmSourcesWrite_PS1_DEV_1 (psFits *fits, psArray *sources, 
+			       psMetadata *imageHeader, psMetadata *tableHeader, char *extname)
 {
     PS_ASSERT_PTR_NON_NULL(fits, false);
@@ -73,7 +73,7 @@
     for (i = 0; i < sources->n; i++) {
         pmSource *source = (pmSource *) sources->data[i];
-        if (source->seq == -1) {
-            source->seq = i;
-        }
+	if (source->seq == -1) {
+	    source->seq = i;
+	}
 
         // no difference between PSF and non-PSF model
@@ -87,15 +87,15 @@
             xErr = dPAR[PM_PAR_XPOS];
             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, 20.0);
-            } else {
-                axes.major = NAN;
-                axes.minor = NAN;
-                axes.theta = NAN;
-            }
-            chisq = model->chisq;
-
-            // need to determine the PSF photometry error: source->errMag is the error on the 'best' model mag.
-            errMag = model->dparams->data.F32[PM_PAR_I0] / model->params->data.F32[PM_PAR_I0];
+	    if (isfinite(PAR[PM_PAR_SXX]) && isfinite(PAR[PM_PAR_SXX]) && isfinite(PAR[PM_PAR_SXX])) {
+		axes = pmPSF_ModelToAxes (PAR, 20.0);
+	    } else {
+		axes.major = NAN;
+		axes.minor = NAN;
+		axes.theta = NAN;
+	    }
+	    chisq = model->chisq;
+
+	    // need to determine the PSF photometry error: source->errMag is the error on the 'best' model mag.
+	    errMag = model->dparams->data.F32[PM_PAR_I0] / model->params->data.F32[PM_PAR_I0];
         } else {
             xPos = source->peak->xf;
@@ -106,6 +106,6 @@
             axes.minor = NAN;
             axes.theta = NAN;
-            chisq = NAN;
-            errMag = NAN;
+	    chisq = NAN;
+	    errMag = NAN;
         }
 
@@ -130,11 +130,11 @@
         psMetadataAdd (row, PS_LIST_TAIL, "EXT_NSIGMA",       PS_DATA_F32,  "Nsigma deviations from PSF to EXT",         source->extNsigma);
 
-        // EXT_NSIGMA will be NAN if: 1) contour ellipse is imaginary; 2) source is not
-        // subtracted
-
-        // CR_NSIGMA will be NAN if: 1) source is not subtracted; 2) source is on the image
-        // edge; 3) any pixels in the 3x3 peak region are masked;
-
-        // CR_NSIGMA and
+	// EXT_NSIGMA will be NAN if: 1) contour ellipse is imaginary; 2) source is not
+	// subtracted
+
+	// CR_NSIGMA will be NAN if: 1) source is not subtracted; 2) source is on the image
+	// edge; 3) any pixels in the 3x3 peak region are masked; 
+
+	// CR_NSIGMA and 
 
         // XXX these should be major and minor, not 'x' and 'y'
@@ -247,6 +247,6 @@
         source->psfMag    = psMetadataLookupF32 (&status, row, "PSF_INST_MAG");
         source->errMag    = psMetadataLookupF32 (&status, row, "PSF_INST_MAG_SIG");
-        PAR[PM_PAR_I0]    = (isfinite(source->psfMag)) ? pow(10.0, -0.4*source->psfMag) : NAN;
-        dPAR[PM_PAR_I0]   = (isfinite(source->psfMag)) ? PAR[PM_PAR_I0] * source->errMag : NAN;
+	PAR[PM_PAR_I0]    = (isfinite(source->psfMag)) ? pow(10.0, -0.4*source->psfMag) : NAN;
+	dPAR[PM_PAR_I0]   = (isfinite(source->psfMag)) ? PAR[PM_PAR_I0] * source->errMag : NAN;
 
         pmPSF_AxesToModel (PAR, axes);
@@ -259,5 +259,5 @@
         source->pixWeight = psMetadataLookupF32 (&status, row, "PSF_QF");
 
-        // note that some older versions used PSF_PROBABILITY: this was not well defined.
+	// note that some older versions used PSF_PROBABILITY: this was not well defined.
         model->chisq      = psMetadataLookupF32 (&status, row, "PSF_CHISQ");
         source->crNsigma  = psMetadataLookupF32 (&status, row, "CR_NSIGMA");
@@ -311,26 +311,26 @@
     // we write out all sources, regardless of quality.  the source flags tell us the state
     for (int i = 0; i < sources->n; i++) {
-        // skip source if it is not a ext sourc
-        // XXX we have two places that extended source parameters are measured:
-        // psphotExtendedSources, which measures the aperture-like parameters and (potentially) the psf-convolved extended source models,
-        // psphotFitEXT, which does the simple extended source model fit (not psf-convolved)
-        // should we require both?
-
-        pmSource *source = sources->data[i];
-
-        // skip sources without measurements
-        if (source->extpars == NULL) continue;
-
-        // we require a PSF model fit (ignore the real crud)
-        pmModel *model = source->modelPSF;
-        if (model == NULL) continue;
-
-        // XXX I need to split the extended models from the extended aperture measurements
-        PAR = model->params->data.F32;
-        dPAR = model->dparams->data.F32;
-        xPos = PAR[PM_PAR_XPOS];
-        yPos = PAR[PM_PAR_YPOS];
-        xErr = dPAR[PM_PAR_XPOS];
-        yErr = dPAR[PM_PAR_YPOS];
+	// skip source if it is not a ext sourc
+	// XXX we have two places that extended source parameters are measured:
+	// psphotExtendedSources, which measures the aperture-like parameters and (potentially) the psf-convolved extended source models,
+	// psphotFitEXT, which does the simple extended source model fit (not psf-convolved)
+	// should we require both?
+
+	pmSource *source = sources->data[i];
+
+	// skip sources without measurements
+	if (source->extpars == NULL) continue;
+
+	// we require a PSF model fit (ignore the real crud)
+	pmModel *model = source->modelPSF;
+	if (model == NULL) continue;
+
+	// XXX I need to split the extended models from the extended aperture measurements
+	PAR = model->params->data.F32;
+	dPAR = model->dparams->data.F32;
+	xPos = PAR[PM_PAR_XPOS];
+	yPos = PAR[PM_PAR_YPOS];
+	xErr = dPAR[PM_PAR_XPOS];
+	yErr = dPAR[PM_PAR_YPOS];
 
         row = psMetadataAlloc ();
@@ -343,101 +343,101 @@
         psMetadataAdd (row, PS_LIST_TAIL, "Y_EXT_SIG",        PS_DATA_F32, "Sigma in EXT y coordinate",                  yErr);
 
-        // Petrosian measurements
-        // XXX insert header data: petrosian ref radius, flux ratio
-        if (doPetrosian) {
-            pmSourcePetrosianValues *petrosian = source->extpars->petrosian;
-            if (petrosian) {
-                psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG",        PS_DATA_F32, "Petrosian Magnitude",       petrosian->mag);
-                psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG_ERR",    PS_DATA_F32, "Petrosian Magnitude Error", petrosian->magErr);
-                psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS",     PS_DATA_F32, "Petrosian Radius",          petrosian->rad);
-                psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS_ERR", PS_DATA_F32, "Petrosian Radius Error",    petrosian->radErr);
-            } else {
-                psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG",        PS_DATA_F32, "Petrosian Magnitude",       NAN);
-                psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG_ERR",    PS_DATA_F32, "Petrosian Magnitude Error", NAN);
-                psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS",     PS_DATA_F32, "Petrosian Radius",          NAN);
-                psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS_ERR", PS_DATA_F32, "Petrosian Radius Error",    NAN);
-            }
-        }
-
-        // Kron measurements
-        if (doKron) {
-            pmSourceKronValues *kron = source->extpars->kron;
-            if (kron) {
-                psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG",        PS_DATA_F32, "Kron Magnitude",       kron->mag);
-                psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG_ERR",    PS_DATA_F32, "Kron Magnitude Error", kron->magErr);
-                psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS",     PS_DATA_F32, "Kron Radius",          kron->rad);
-                psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS_ERR", PS_DATA_F32, "Kron Radius Error",    kron->radErr);
-            } else {
-                psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG",        PS_DATA_F32, "Kron Magnitude",       NAN);
-                psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG_ERR",    PS_DATA_F32, "Kron Magnitude Error", NAN);
-                psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS",     PS_DATA_F32, "Kron Radius",          NAN);
-                psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS_ERR", PS_DATA_F32, "Kron Radius Error",    NAN);
-            }
-        }
-
-        // Isophot measurements
-        // XXX insert header data: isophotal level
-        if (doIsophotal) {
-            pmSourceIsophotalValues *isophot = source->extpars->isophot;
-            if (isophot) {
-                psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG",        PS_DATA_F32, "Isophot Magnitude",       isophot->mag);
-                psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG_ERR",    PS_DATA_F32, "Isophot Magnitude Error", isophot->magErr);
-                psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS",     PS_DATA_F32, "Isophot Radius",          isophot->rad);
-                psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS_ERR", PS_DATA_F32, "Isophot Radius Error",    isophot->radErr);
-            } else {
-                psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG",        PS_DATA_F32, "Isophot Magnitude",       NAN);
-                psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG_ERR",    PS_DATA_F32, "Isophot Magnitude Error", NAN);
-                psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS",     PS_DATA_F32, "Isophot Radius",          NAN);
-                psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS_ERR", PS_DATA_F32, "Isophot Radius Error",    NAN);
-            }
-        }
-
-        // Flux Annuli
-        if (doAnnuli) {
-            pmSourceAnnuli *annuli = source->extpars->annuli;
-            if (annuli) {
-                psVector *fluxVal = annuli->flux;
-                psVector *fluxErr = annuli->fluxErr;
-                psVector *fluxVar = annuli->fluxVar;
-
-                for (int j = 0; j < fluxVal->n; j++) {
-                    char name[32];
-                    sprintf (name, "FLUX_VAL_R_%02d", j);
-                    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux value in annulus", fluxVal->data.F32[j]);
-                    sprintf (name, "FLUX_ERR_R_%02d", j);
-                    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux error in annulus", fluxErr->data.F32[j]);
-                    sprintf (name, "FLUX_VAR_R_%02d", j);
-                    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux stdev in annulus", fluxVar->data.F32[j]);
-                }
-            } else {
-                for (int j = 0; j < radialBinsLower->n; j++) {
-                    char name[32];
-                    sprintf (name, "FLUX_VAL_R_%02d", j);
-                    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux value in annulus", NAN);
-                    sprintf (name, "FLUX_ERR_R_%02d", j);
-                    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux error in annulus", NAN);
-                    sprintf (name, "FLUX_VAR_R_%02d", j);
-                    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux stdev in annulus", NAN);
-                }
-            }
-        }
-
-        psArrayAdd (table, 100, row);
-        psFree (row);
+	// Petrosian measurements
+	// XXX insert header data: petrosian ref radius, flux ratio
+	if (doPetrosian) {
+	    pmSourcePetrosianValues *petrosian = source->extpars->petrosian;
+	    if (petrosian) {
+		psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG",        PS_DATA_F32, "Petrosian Magnitude",       petrosian->mag);
+		psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG_ERR",    PS_DATA_F32, "Petrosian Magnitude Error", petrosian->magErr);
+		psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS",     PS_DATA_F32, "Petrosian Radius",          petrosian->rad);
+		psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS_ERR", PS_DATA_F32, "Petrosian Radius Error",    petrosian->radErr);
+	    } else {
+		psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG",        PS_DATA_F32, "Petrosian Magnitude",       NAN);
+		psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG_ERR",    PS_DATA_F32, "Petrosian Magnitude Error", NAN);
+		psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS",     PS_DATA_F32, "Petrosian Radius",          NAN);
+		psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS_ERR", PS_DATA_F32, "Petrosian Radius Error",    NAN);
+	    }
+	} 
+
+	// Kron measurements
+	if (doKron) {
+	    pmSourceKronValues *kron = source->extpars->kron;
+	    if (kron) {
+		psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG",        PS_DATA_F32, "Kron Magnitude",       kron->mag);
+		psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG_ERR",    PS_DATA_F32, "Kron Magnitude Error", kron->magErr);
+		psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS",     PS_DATA_F32, "Kron Radius",          kron->rad);
+		psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS_ERR", PS_DATA_F32, "Kron Radius Error",    kron->radErr);
+	    } else {
+		psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG",        PS_DATA_F32, "Kron Magnitude",       NAN);
+		psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG_ERR",    PS_DATA_F32, "Kron Magnitude Error", NAN);
+		psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS",     PS_DATA_F32, "Kron Radius",          NAN);
+		psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS_ERR", PS_DATA_F32, "Kron Radius Error",    NAN);
+	    }
+	}
+
+	// Isophot measurements
+	// XXX insert header data: isophotal level
+	if (doIsophotal) {
+	    pmSourceIsophotalValues *isophot = source->extpars->isophot;
+	    if (isophot) {
+		psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG",        PS_DATA_F32, "Isophot Magnitude",       isophot->mag);
+		psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG_ERR",    PS_DATA_F32, "Isophot Magnitude Error", isophot->magErr);
+		psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS",     PS_DATA_F32, "Isophot Radius",          isophot->rad);
+		psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS_ERR", PS_DATA_F32, "Isophot Radius Error",    isophot->radErr);
+	    } else {
+		psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG",        PS_DATA_F32, "Isophot Magnitude",       NAN);
+		psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG_ERR",    PS_DATA_F32, "Isophot Magnitude Error", NAN);
+		psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS",     PS_DATA_F32, "Isophot Radius",          NAN);
+		psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS_ERR", PS_DATA_F32, "Isophot Radius Error",    NAN);
+	    }
+	}
+
+	// Flux Annuli
+	if (doAnnuli) {
+	    pmSourceAnnuli *annuli = source->extpars->annuli;
+	    if (annuli) {
+		psVector *fluxVal = annuli->flux;
+		psVector *fluxErr = annuli->fluxErr;
+		psVector *fluxVar = annuli->fluxVar;
+
+		for (int j = 0; j < fluxVal->n; j++) {
+		    char name[32];
+		    sprintf (name, "FLUX_VAL_R_%02d", j);
+		    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux value in annulus", fluxVal->data.F32[j]);
+		    sprintf (name, "FLUX_ERR_R_%02d", j);
+		    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux error in annulus", fluxErr->data.F32[j]);
+		    sprintf (name, "FLUX_VAR_R_%02d", j);
+		    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux stdev in annulus", fluxVar->data.F32[j]);
+		} 
+	    } else {
+		for (int j = 0; j < radialBinsLower->n; j++) {
+		    char name[32];
+		    sprintf (name, "FLUX_VAL_R_%02d", j);
+		    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux value in annulus", NAN);
+		    sprintf (name, "FLUX_ERR_R_%02d", j);
+		    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux error in annulus", NAN);
+		    sprintf (name, "FLUX_VAR_R_%02d", j);
+		    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux stdev in annulus", NAN);
+		} 
+	    }
+	}
+
+	psArrayAdd (table, 100, row);
+	psFree (row);
     }
 
     if (table->n == 0) {
-        psFitsWriteBlank (fits, outhead, extname);
-        psFree (outhead);
-        psFree (table);
-        return true;
+	psFitsWriteBlank (fits, outhead, extname);
+	psFree (outhead);
+	psFree (table);
+	return true;
     }
 
     psTrace ("pmFPAfile", 5, "writing ext data %s\n", extname);
     if (!psFitsWriteTable (fits, outhead, table, extname)) {
-        psError(PS_ERR_IO, false, "writing ext data %s\n", extname);
-        psFree (outhead);
-        psFree(table);
-        return false;
+	psError(PS_ERR_IO, false, "writing ext data %s\n", extname);
+	psFree (outhead);
+	psFree(table);
+	return false;
     }
     psFree (outhead);
@@ -470,11 +470,11 @@
     int nParamMax = 0;
     for (int i = 0; i < sources->n; i++) {
-        pmSource *source = sources->data[i];
-        if (source->modelFits == NULL) continue;
-        for (int j = 0; j < source->modelFits->n; j++) {
-            pmModel *model = source->modelFits->data[j];
-            assert (model);
-            nParamMax = PS_MAX (nParamMax, model->params->n);
-        }
+	pmSource *source = sources->data[i];
+	if (source->modelFits == NULL) continue;
+	for (int j = 0; j < source->modelFits->n; j++) {
+	    pmModel *model = source->modelFits->data[j];
+	    assert (model);
+	    nParamMax = PS_MAX (nParamMax, model->params->n);
+	}
     }
 
@@ -484,85 +484,85 @@
     for (int i = 0; i < sources->n; i++) {
 
-        pmSource *source = sources->data[i];
-
-        // XXX if no model fits are saved, write out modelEXT?
-        if (source->modelFits == NULL) continue;
-
-        // We have multiple sources : need to flag the one used to subtract the light (the 'best' model)
-        for (int j = 0; j < source->modelFits->n; j++) {
-
-            // choose the convolved EXT model, if available, otherwise the simple one
-            pmModel *model = source->modelFits->data[j];
-            assert (model);
-
-            PAR = model->params->data.F32;
-            dPAR = model->dparams->data.F32;
-            xPos = PAR[PM_PAR_XPOS];
-            yPos = PAR[PM_PAR_YPOS];
-            xErr = dPAR[PM_PAR_XPOS];
-            yErr = dPAR[PM_PAR_YPOS];
-
-            axes = pmPSF_ModelToAxes (PAR, 20.0);
-
-            row = psMetadataAlloc ();
-
-            // XXX we are not writing out the mode (flags) or the type (psf, ext, etc)
-            psMetadataAddU32 (row, PS_LIST_TAIL, "IPP_IDET",         0, "IPP detection identifier index",             source->seq);
-            psMetadataAddF32 (row, PS_LIST_TAIL, "X_EXT",            0, "EXT model x coordinate",                     xPos);
-            psMetadataAddF32 (row, PS_LIST_TAIL, "Y_EXT",            0, "EXT model y coordinate",                     yPos);
-            psMetadataAddF32 (row, PS_LIST_TAIL, "X_EXT_SIG",        0, "Sigma in EXT x coordinate",                  xErr);
-            psMetadataAddF32 (row, PS_LIST_TAIL, "Y_EXT_SIG",        0, "Sigma in EXT y coordinate",                  yErr);
-            psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_INST_MAG",     0, "EXT fit instrumental magnitude",             model->mag);
-            psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_INST_MAG_SIG", 0, "Sigma of PSF instrumental magnitude",        model->magErr);
-
-            psMetadataAddF32 (row, PS_LIST_TAIL, "NPARAMS",          0, "number of model parameters",                 model->params->n);
-            psMetadataAddStr (row, PS_LIST_TAIL, "MODEL_TYPE",       0, "name of model",                              pmModelClassGetName (model->type));
-
-            // XXX these should be major and minor, not 'x' and 'y'
-            psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_WIDTH_MAJ",    0, "EXT width in x coordinate",                  axes.major);
-            psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_WIDTH_MIN",    0, "EXT width in y coordinate",                  axes.minor);
-            psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_THETA",        0, "EXT orientation angle",                      axes.theta);
-
-            // write out the other generic parameters
-            for (int k = 0; k < nParamMax; k++) {
-                if (k == PM_PAR_I0) continue;
-                if (k == PM_PAR_SKY) continue;
-                if (k == PM_PAR_XPOS) continue;
-                if (k == PM_PAR_YPOS) continue;
-                if (k == PM_PAR_SXX) continue;
-                if (k == PM_PAR_SXY) continue;
-                if (k == PM_PAR_SYY) continue;
-
-                snprintf (name, 64, "EXT_PAR_%02d", k);
-
-                if (k < model->params->n) {
-                    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "", model->params->data.F32[k]);
-                } else {
-                    psMetadataAddF32 (row, PS_LIST_TAIL, name, PS_DATA_F32, "", NAN);
-                }
-            }
-
-            // XXX other parameters which may be set.
-            // XXX flag / value to define the model
-            // XXX write out the model type, fit status flags
-
-            psArrayAdd (table, 100, row);
-            psFree (row);
-        }
+	pmSource *source = sources->data[i];
+
+	// XXX if no model fits are saved, write out modelEXT?
+	if (source->modelFits == NULL) continue;
+
+	// We have multiple sources : need to flag the one used to subtract the light (the 'best' model)
+	for (int j = 0; j < source->modelFits->n; j++) {
+
+	    // choose the convolved EXT model, if available, otherwise the simple one
+	    pmModel *model = source->modelFits->data[j];
+	    assert (model);
+
+	    PAR = model->params->data.F32;
+	    dPAR = model->dparams->data.F32;
+	    xPos = PAR[PM_PAR_XPOS];
+	    yPos = PAR[PM_PAR_YPOS];
+	    xErr = dPAR[PM_PAR_XPOS];
+	    yErr = dPAR[PM_PAR_YPOS];
+
+	    axes = pmPSF_ModelToAxes (PAR, 20.0);
+
+	    row = psMetadataAlloc ();
+
+	    // XXX we are not writing out the mode (flags) or the type (psf, ext, etc)
+	    psMetadataAddU32 (row, PS_LIST_TAIL, "IPP_IDET",         0, "IPP detection identifier index",             source->seq);
+	    psMetadataAddF32 (row, PS_LIST_TAIL, "X_EXT",            0, "EXT model x coordinate",                     xPos);
+	    psMetadataAddF32 (row, PS_LIST_TAIL, "Y_EXT",            0, "EXT model y coordinate",                     yPos);
+	    psMetadataAddF32 (row, PS_LIST_TAIL, "X_EXT_SIG",        0, "Sigma in EXT x coordinate",                  xErr);
+	    psMetadataAddF32 (row, PS_LIST_TAIL, "Y_EXT_SIG",        0, "Sigma in EXT y coordinate",                  yErr);
+	    psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_INST_MAG",     0, "EXT fit instrumental magnitude",             model->mag);
+	    psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_INST_MAG_SIG", 0, "Sigma of PSF instrumental magnitude",        model->magErr);
+
+	    psMetadataAddF32 (row, PS_LIST_TAIL, "NPARAMS",          0, "number of model parameters",                 model->params->n);
+	    psMetadataAddStr (row, PS_LIST_TAIL, "MODEL_TYPE",       0, "name of model",                              pmModelClassGetName (model->type));
+
+	    // XXX these should be major and minor, not 'x' and 'y'
+	    psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_WIDTH_MAJ",    0, "EXT width in x coordinate",                  axes.major);
+	    psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_WIDTH_MIN",    0, "EXT width in y coordinate",                  axes.minor);
+	    psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_THETA",        0, "EXT orientation angle",                      axes.theta);
+
+	    // write out the other generic parameters
+	    for (int k = 0; k < nParamMax; k++) {
+		if (k == PM_PAR_I0) continue;
+		if (k == PM_PAR_SKY) continue;
+		if (k == PM_PAR_XPOS) continue;
+		if (k == PM_PAR_YPOS) continue;
+		if (k == PM_PAR_SXX) continue;
+		if (k == PM_PAR_SXY) continue;
+		if (k == PM_PAR_SYY) continue;
+
+		snprintf (name, 64, "EXT_PAR_%02d", k);
+
+		if (k < model->params->n) {
+		    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "", model->params->data.F32[k]);
+		} else {
+		    psMetadataAddF32 (row, PS_LIST_TAIL, name, PS_DATA_F32, "", NAN);
+		}
+	    }
+
+	    // XXX other parameters which may be set.
+	    // XXX flag / value to define the model
+	    // XXX write out the model type, fit status flags
+
+	    psArrayAdd (table, 100, row);
+	    psFree (row);
+	}
     }
 
     if (table->n == 0) {
-        psFitsWriteBlank (fits, outhead, extname);
-        psFree (outhead);
-        psFree (table);
-        return true;
+	psFitsWriteBlank (fits, outhead, extname);
+	psFree (outhead);
+	psFree (table);
+	return true;
     }
 
     psTrace ("pmFPAfile", 5, "writing ext data %s\n", extname);
     if (!psFitsWriteTable (fits, outhead, table, extname)) {
-        psError(PS_ERR_IO, false, "writing ext data %s\n", extname);
-        psFree (outhead);
-        psFree(table);
-        return false;
+	psError(PS_ERR_IO, false, "writing ext data %s\n", extname);
+	psFree (outhead);
+	psFree(table);
+	return false;
     }
     psFree (outhead);
Index: /branches/cnb_branches/cnb_branch_20090215/psModules/src/objects/pmSourcePhotometry.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/objects/pmSourcePhotometry.c	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psModules/src/objects/pmSourcePhotometry.c	(revision 23197)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA; GLG, MHPCC
  *
- *  @version $Revision: 1.49.4.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2009-02-19 17:59:50 $
+ *  @version $Revision: 1.50 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-02-16 22:28:54 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -578,5 +578,5 @@
         }
     }
-    model->nPix = Npix;
+    model->nPix = Npix; 
     model->nDOF = Npix - 1;
     model->chisq = dC;
@@ -768,50 +768,50 @@
 // measure centroid of unshifted gaussian (should be 16.0,16.0)
         {
-          psImage *image = source->pixels;
-          float xo = 0.0;
-          float yo = 0.0;
-          float xo2 = 0.0;
-          float yo2 = 0.0;
-          float no = 0.0;
-          for (int j = 0; j < image->numRows; j++)
-          {
-            for (int i = 0; i < image->numCols; i++) {
-              xo += i*image->data.F32[j][i];
-              yo += j*image->data.F32[j][i];
-              xo2 += i*i*image->data.F32[j][i];
-              yo2 += j*j*image->data.F32[j][i];
-              no += image->data.F32[j][i];
-            }
-          }
-          xo /= no;
-          yo /= no;
-          xo2 = sqrt (xo2/no - xo*xo);
-          yo2 = sqrt (yo2/no - yo*yo);
-          fprintf (stderr, "pre-shift centroid: %f,%f, sigma: %f,%f: flux: %f\n", xo, yo, xo2, yo2, no);
+	  psImage *image = source->pixels;
+	  float xo = 0.0;
+	  float yo = 0.0;
+	  float xo2 = 0.0;
+	  float yo2 = 0.0;
+	  float no = 0.0;
+	  for (int j = 0; j < image->numRows; j++)
+	  {
+	    for (int i = 0; i < image->numCols; i++) {
+	      xo += i*image->data.F32[j][i];
+	      yo += j*image->data.F32[j][i];
+	      xo2 += i*i*image->data.F32[j][i];
+	      yo2 += j*j*image->data.F32[j][i];
+	      no += image->data.F32[j][i];
+	    }
+	  }
+	  xo /= no;
+	  yo /= no;
+	  xo2 = sqrt (xo2/no - xo*xo);
+	  yo2 = sqrt (yo2/no - yo*yo);
+	  fprintf (stderr, "pre-shift centroid: %f,%f, sigma: %f,%f: flux: %f\n", xo, yo, xo2, yo2, no);
         }
 
 // measure centroid of unshifted gaussian (should be 16.0,16.0)
         {
-          psImage *image = flux;
-          float xo = 0.0;
-          float yo = 0.0;
-          float xo2 = 0.0;
-          float yo2 = 0.0;
-          float no = 0.0;
-          for (int j = 0; j < image->numRows; j++)
-          {
-            for (int i = 0; i < image->numCols; i++) {
-              xo += i*image->data.F32[j][i];
-              yo += j*image->data.F32[j][i];
-              xo2 += i*i*image->data.F32[j][i];
-              yo2 += j*j*image->data.F32[j][i];
-              no += image->data.F32[j][i];
-            }
-          }
-          xo /= no;
-          yo /= no;
-          xo2 = sqrt (xo2/no - xo*xo);
-          yo2 = sqrt (yo2/no - yo*yo);
-          fprintf (stderr, "pre-shift centroid: %f,%f, sigma: %f,%f: flux: %f\n", xo, yo, xo2, yo2, no);
+	  psImage *image = flux;
+	  float xo = 0.0;
+	  float yo = 0.0;
+	  float xo2 = 0.0;
+	  float yo2 = 0.0;
+	  float no = 0.0;
+	  for (int j = 0; j < image->numRows; j++)
+	  {
+	    for (int i = 0; i < image->numCols; i++) {
+	      xo += i*image->data.F32[j][i];
+	      yo += j*image->data.F32[j][i];
+	      xo2 += i*i*image->data.F32[j][i];
+	      yo2 += j*j*image->data.F32[j][i];
+	      no += image->data.F32[j][i];
+	    }
+	  }
+	  xo /= no;
+	  yo /= no;
+	  xo2 = sqrt (xo2/no - xo*xo);
+	  yo2 = sqrt (yo2/no - yo*yo);
+	  fprintf (stderr, "pre-shift centroid: %f,%f, sigma: %f,%f: flux: %f\n", xo, yo, xo2, yo2, no);
         }
 # endif
Index: /branches/cnb_branches/cnb_branch_20090215/psModules/src/objects/pmSourcePhotometry.h
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/objects/pmSourcePhotometry.h	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psModules/src/objects/pmSourcePhotometry.h	(revision 23197)
@@ -4,6 +4,6 @@
  * @author EAM, IfA; GLG, MHPCC
  *
- * @version $Revision: 1.12.8.1 $ $Name: not supported by cvs2svn $
- * @date $Date: 2009-02-19 17:59:50 $
+ * @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-02-16 22:28:54 $
  * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  */
@@ -46,5 +46,5 @@
     psImage *image,                     ///< image pixels to be used
     psImage *mask,                      ///< mask of pixels to ignore
-    psImageMaskType maskVal             ///< Value to mask
+    psImageMaskType maskVal		///< Value to mask
 );
 
Index: /branches/cnb_branches/cnb_branch_20090215/psModules/src/psmodules.h
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/src/psmodules.h	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psModules/src/psmodules.h	(revision 23197)
@@ -32,7 +32,8 @@
 // the following headers are from psModule:concepts
 #include <pmConcepts.h>
+#include <pmConceptsStandard.h>
 #include <pmConceptsRead.h>
-#include <pmConceptsStandard.h>
 #include <pmConceptsWrite.h>
+#include <pmConceptsCopy.h>
 #include <pmConceptsPhotcode.h>
 #include <pmConceptsAverage.h>
Index: anches/cnb_branches/cnb_branch_20090215/psModules/test/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/test/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,15 +1,0 @@
-.deps
-.libs
-Makefile
-tst_pmFlatField
-tst_pmMaskBadPixels
-tst_pmNonLinear
-tst_pmSubtractBias
-temp
-Makefile.in
-tst_pmObjects01
-tst_pmReadoutCombine
-tst_pmSubtractSky
-tst_pmImageSubtract
-tst_pmImageCombine
-tst_pmAstrometry
Index: anches/cnb_branches/cnb_branch_20090215/psModules/test/astrom/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/test/astrom/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,12 +1,0 @@
-.deps
-.libs
-Makefile
-Makefile.in
-temp
-tst_pmAstrometry
-tst_pmAstrometry01
-tap_pmAstrometryWCS
-tap_pmAstrometryWCS_DVO
-tap_pmAstrometryWCS_DVO2
-tap_pmAstrometryWCS_DVO3
-tap_pmAstrometryWCS_DVO4
Index: anches/cnb_branches/cnb_branch_20090215/psModules/test/camera/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/test/camera/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,6 +1,0 @@
-.deps
-.libs
-Makefile
-Makefile.in
-temp
-tst_pmAstrometry
Index: anches/cnb_branches/cnb_branch_20090215/psModules/test/concepts/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/test/concepts/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,4 +1,0 @@
-.deps
-.libs
-Makefile
-Makefile.in
Index: anches/cnb_branches/cnb_branch_20090215/psModules/test/config/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/test/config/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,7 +1,0 @@
-.deps
-.libs
-Makefile
-Makefile.in
-temp
-tst_pmConfig
-SampleIPPConfig
Index: anches/cnb_branches/cnb_branch_20090215/psModules/test/detrend/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/test/detrend/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,9 +1,0 @@
-.deps
-.libs
-Makefile
-Makefile.in
-temp
-tst_pmFlatField
-tst_pmMaskBadPixels
-tst_pmNonLinear
-.tmp_tst_pmNonLinearLookupFile
Index: anches/cnb_branches/cnb_branch_20090215/psModules/test/extras/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/test/extras/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-Makefile
-Makefile.in
Index: anches/cnb_branches/cnb_branch_20090215/psModules/test/imcombine/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/test/imcombine/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,8 +1,0 @@
-.deps
-.libs
-Makefile
-Makefile.in
-temp
-tst_pmImageCombine
-tst_pmReadoutCombine
-tap_pmImageCombine
Index: anches/cnb_branches/cnb_branch_20090215/psModules/test/objects/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/test/objects/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,9 +1,0 @@
-.deps
-.libs
-Makefile
-Makefile.in
-temp
-tap_pmGrowthCurve
-tap_pmSourceFitModel
-tap_pmSourceFitModel_Delta
-tap_pmSourcePhotometry
Index: anches/cnb_branches/cnb_branch_20090215/psModules/test/pstap/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/test/pstap/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-Makefile
-Makefile.in
Index: anches/cnb_branches/cnb_branch_20090215/psModules/test/pstap/src/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/test/pstap/src/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,6 +1,0 @@
-Makefile
-Makefile.in
-libpstap.la
-pstap.lo
-.deps
-.libs
Index: anches/cnb_branches/cnb_branch_20090215/psModules/test/tap/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/test/tap/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,13 +1,0 @@
-.in
-Makefile
-Makefile.in
-aclocal.m4
-autom4te.cache
-config.log
-config.status
-configure
-libtool
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/psModules/test/tap/src/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/test/tap/src/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,13 +1,0 @@
-.deps
-.libs
-Makefile
-Makefile.in
-libtap.la
-tap.lo
-config.h
-config.h.in
-stamp-h1
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/psModules/test/tap/tests/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/test/tap/tests/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,6 +1,0 @@
-Makefile
-Makefile.in
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/psModules/test/tap/tests/diag/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/test/tap/tests/diag/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/psModules/test/tap/tests/fail/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/test/tap/tests/fail/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,15 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/psModules/test/tap/tests/ok/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/test/tap/tests/ok/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,6 +1,0 @@
-Makefile
-Makefile.in
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/psModules/test/tap/tests/ok/ok-hash/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/test/tap/tests/ok/ok-hash/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/psModules/test/tap/tests/ok/ok-numeric/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/test/tap/tests/ok/ok-numeric/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/psModules/test/tap/tests/ok/ok/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/test/tap/tests/ok/ok/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/psModules/test/tap/tests/pass/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/test/tap/tests/pass/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/psModules/test/tap/tests/plan/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/test/tap/tests/plan/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,6 +1,0 @@
-Makefile
-Makefile.in
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/psModules/test/tap/tests/plan/no-tests/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/test/tap/tests/plan/no-tests/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/psModules/test/tap/tests/plan/no_plan/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/test/tap/tests/plan/no_plan/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/psModules/test/tap/tests/plan/not-enough-tests/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/test/tap/tests/plan/not-enough-tests/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/psModules/test/tap/tests/plan/sane/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/test/tap/tests/plan/sane/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/psModules/test/tap/tests/plan/skip_all/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/test/tap/tests/plan/skip_all/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/psModules/test/tap/tests/plan/too-many-plans/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/test/tap/tests/plan/too-many-plans/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/psModules/test/tap/tests/plan/too-many-tests/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/test/tap/tests/plan/too-many-tests/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/psModules/test/tap/tests/skip/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/test/tap/tests/skip/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/psModules/test/tap/tests/todo/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psModules/test/tap/tests/todo/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-test
-test.c.out
-test.pl.out
-*.bb
-*.bbg
-*.da
-gmon.out
Index: anches/cnb_branches/cnb_branch_20090215/psconfig/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psconfig/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,3 +1,0 @@
-tarballs
-psconfig.csh
-psconfig.bash
Index: /branches/cnb_branches/cnb_branch_20090215/psconfig/psbuild
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psconfig/psbuild	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psconfig/psbuild	(revision 23197)
@@ -283,13 +283,17 @@
         if (! -e "Makefile") { &failure($module[$i], "missing makefile: do you need to run the -dev developer build?"); }
 
+        my $makeopts = $ENV{'PSCONFIG_MAKEOPTS'}; # Options for make
+        my $make = "make";      # Command for "make"
+        $make .= " $makeopts" if defined $makeopts;
+
         if ($clean) {
-            vsystem ("make clean");
+            vsystem ("$make clean");
             if ($?) { &failure($module[$i], "failure in make clean"); }
         }
 
-        vsystem ("make");
+        vsystem ("$make");
         if ($?) { &failure($module[$i], "failure in make"); }
 
-        vsystem ("make install");
+        vsystem ("$make install");
         if ($?) { &failure($module[$i], "failure in make install"); }
 
Index: /branches/cnb_branches/cnb_branch_20090215/psconfig/pschecklibs
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psconfig/pschecklibs	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psconfig/pschecklibs	(revision 23197)
@@ -11,5 +11,6 @@
 $version = "";
 $build = 0;
-%force;
+my %force;
+my %done;                       # Tarballs that have been processed
 @tARGV = ();
 for (; @ARGV > 0; ) {
@@ -132,8 +133,10 @@
 
 
-    if ((defined $force{lc($name)} or defined $force{'all'}) and lc($tarball) ne "none") {
+    if ((defined $force{lc($name)} or defined $force{'all'}) and
+        not defined $done{$tarball} and lc($tarball) ne "none") {
         # remove it for the list so we can check for -force for a library
         # not in the list
         &buildlib ($name, $tarball, $tardir, $configure_opts, $make_opts, $install_opts);
+        $done{$tarball} = 1;
         delete($force{lc($name)});
         next;
@@ -157,14 +160,14 @@
 
     if ($auto_force eq "Y") {
-	print "$name will be built\n";
+        print "$name will be built\n";
     }
 
     if ($found) {
-	if ($found eq "runtime-only") {
-	    print "runtime $name ($found)\n";
-	    push @faillibs, "$name";
-	} else {
-	    print "pass $name ($found)\n";
-	}
+        if ($found eq "runtime-only") {
+            print "runtime $name ($found)\n";
+            push @faillibs, "$name";
+        } else {
+            print "pass $name ($found)\n";
+        }
         next;
     } else {
@@ -174,5 +177,5 @@
 
     if ($auto_force eq "Y") {
-	print "$name will be built\n";
+        print "$name will be built\n";
     }
 
@@ -187,4 +190,5 @@
 my $bad_force;
 foreach $k (keys %force) {
+    next if lc($k) eq 'all';
     print STDERR "\nERROR: -force $k requested but $k isn't in the list of libraries\n";
     $bad_force = 1;
@@ -254,17 +258,20 @@
     if ($?) { &failure($name, "failure in configure"); }
 
+    my $make = "make";          # Command for make
+    $make .= ' ' . $ENV{'PSCONFIG_MAKEOPTS'} if defined $ENV{'PSCONFIG_MAKEOPTS'};
+
     if ($make_opts eq "NONE") {
-        vsystem ("make");
+        vsystem ($make);
     } else {
         $make_opts = join (' ', split (',', $make_opts));
-        vsystem ("make $make_opts");
+        vsystem ("$make $make_opts");
     }
     if ($?) { &failure($name, "failure in make"); }
 
     if ($install_opts eq "NONE") {
-        vsystem ("make install");
+        vsystem ("$make install");
     } else {
         $install_opts = join (' ', split (',', $install_opts));
-        vsystem ("make install $install_opts");
+        vsystem ("$make install $install_opts");
     }
     if ($?) { &failure($name, "failure in make install"); }
@@ -315,29 +322,29 @@
         # versions libraries if we find only a .so.N without a matching
         # .so, we link this in the installed libdir
-	# XXX this was probably a mistake to allow some systems to build without supplied libs
-	if (1) {
-	    foreach $topdir ( @libpath ) {
-		foreach $subdir ( @subdirs ) {
-		    if ($subdir eq ".") {
-			$path = $topdir;
-		    } else {
-			$path = "$topdir/$subdir";
-		    }
-		    if (! -e $path) { next; }
-		    @libnames = <$path/$tryname.$dlltype*>;
-		    if (@libnames > 0) {
-			$libname = @libnames[-1];
-			$needdev = 1;
-			# print " *** need developer version of $name\n";
-			return "runtime-only";
-
-			# XXX old option: link in existing library
-			# symlink $libname, "$libdir/$f.$dlltype";
-			# if ($?) { exit 1; }
-			# return $libname;
-		    }
-		}
-	    }
-	}
+        # XXX this was probably a mistake to allow some systems to build without supplied libs
+        if (1) {
+            foreach $topdir ( @libpath ) {
+                foreach $subdir ( @subdirs ) {
+                    if ($subdir eq ".") {
+                        $path = $topdir;
+                    } else {
+                        $path = "$topdir/$subdir";
+                    }
+                    if (! -e $path) { next; }
+                    @libnames = <$path/$tryname.$dlltype*>;
+                    if (@libnames > 0) {
+                        $libname = @libnames[-1];
+                        $needdev = 1;
+                        # print " *** need developer version of $name\n";
+                        return "runtime-only";
+
+                        # XXX old option: link in existing library
+                        # symlink $libname, "$libdir/$f.$dlltype";
+                        # if ($?) { exit 1; }
+                        # return $libname;
+                    }
+                }
+            }
+        }
     }
     return 0;
Index: /branches/cnb_branches/cnb_branch_20090215/psconfig/tagsets/ipp-2.7.libs
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psconfig/tagsets/ipp-2.7.libs	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/psconfig/tagsets/ipp-2.7.libs	(revision 23197)
@@ -25,5 +25,5 @@
 lib libz                 NONE           NONE   zlib-1.2.3.tar.gz        zlib-1.2.3       N --shared NONE NONE
 lib libpng               NONE           NONE   libpng-1.2.15.tar.gz     libpng-1.2.15    N NONE NONE NONE
-lib libjpeg              NONE           jpeg   jpegsrc.v6b-p1.tgz       jpeg-6b          N --enable-shared NONE install-lib
+lib libjpeg              NONE           jpeg   jpegsrc.v6b-p1.tar.gz    jpeg-6b          N --enable-shared NONE install-lib
 lib libcfitsio           NONE           NONE   cfitsio3100-pap.tar.gz   cfitsio3100-pap  N --enable-shared shared NONE
 #lib libmysqlclient      NONE           mysql  mysql-5.0.27.tar.gz      mysql-5.0.27     N NONE NONE NONE
Index: anches/cnb_branches/cnb_branch_20090215/psdemo/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psdemo/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,1 +1,0 @@
-bin
Index: anches/cnb_branches/cnb_branch_20090215/psphot/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psphot/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,20 +1,0 @@
-bin
-Makefile
-Makefile.in
-aclocal.m4
-autom4te.cache
-compile
-config.log
-config.status
-configure
-depcomp
-install-sh
-missing
-config.guess
-libtool
-ltmain.sh
-stamp-h1
-config.sub
-psphot.pc
-psphot-config
-Doxyfile
Index: anches/cnb_branches/cnb_branch_20090215/psphot/src/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/psphot/src/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,18 +1,0 @@
-*.o
-*.lo
-.libs
-.deps
-Makefile
-Makefile.in
-libpsphot.la
-psphot
-psphotTest
-psphot.loT
-psphotErrorCodes.h
-psphotErrorCodes.c
-config.h
-config.h.in
-stamp-h1
-
-polyfitTest
-growthTest
Index: anches/cnb_branches/cnb_branch_20090215/pstamp/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/pstamp/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,17 +1,0 @@
-bin
-aclocal.m4
-autom4te.cache
-compile
-config.log
-config.status
-configure
-depcomp
-install-sh
-Makefile.in
-missing
-Makefile
-config.cache
-config.guess
-config.sub
-ltmain.sh
-libtool
Index: anches/cnb_branches/cnb_branch_20090215/pstamp/scripts/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/pstamp/scripts/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,2 +1,0 @@
-Makefile.in
-Makefile
Index: anches/cnb_branches/cnb_branch_20090215/pstamp/src/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/pstamp/src/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,14 +1,0 @@
-ppstamp
-locateimages
-pstamprequest
-pstampfinish
-pstampdump
-Makefile
-Makefile.in
-.deps
-config.h
-config.h.in
-stamp-h1
-pstampErrorCodes.c
-pstampErrorCodes.h
-.libs
Index: anches/cnb_branches/cnb_branch_20090215/pstest/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/pstest/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,1 +1,0 @@
-bin
Index: anches/cnb_branches/cnb_branch_20090215/pswarp/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/pswarp/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,19 +1,0 @@
-bin
-Makefile
-Makefile.in
-aclocal.m4
-autom4te.cache
-compile
-config.log
-config.status
-configure
-depcomp
-install-sh
-missing
-config.guess
-libtool
-ltmain.sh
-stamp-h1
-config.sub
-pswarp.pc
-Doxyfile
Index: anches/cnb_branches/cnb_branch_20090215/pswarp/src/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/pswarp/src/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,14 +1,0 @@
-*.o
-*.lo
-.libs
-.deps
-Makefile
-Makefile.in
-pswarp
-pswarp.loT
-pswarpErrorCodes.h
-pswarpErrorCodes.c
-libpswarp.la
-config.h
-config.h.in
-stamp-h1
Index: /branches/cnb_branches/cnb_branch_20090215/pswarp/src/pswarpTransformReadout.c
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/pswarp/src/pswarpTransformReadout.c	(revision 23196)
+++ /branches/cnb_branches/cnb_branch_20090215/pswarp/src/pswarpTransformReadout.c	(revision 23197)
@@ -6,6 +6,6 @@
  *
  *  @author IfA
- *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2009-02-06 03:10:36 $
+ *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-02-18 02:58:59 $
  *  Copyright 2009 Institute for Astronomy, University of Hawaii
  */
@@ -146,4 +146,5 @@
         psMetadataAddList(output->analysis, PS_LIST_TAIL, PSWARP_ANALYSIS_COVARIANCES, 0,
                           "Collection of covariance matrices", covariances);
+        psFree(covariances);            // Drop reference; still have the copy on the analysis metadata
     }
     while ((job = psThreadJobGetDone()) != NULL) {
Index: anches/cnb_branches/cnb_branch_20090215/pswarp/test/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/pswarp/test/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,1 +1,0 @@
-*
Index: anches/cnb_branches/cnb_branch_20090215/simtest/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/simtest/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,9 +1,0 @@
-Makefile
-Makefile.in
-aclocal.m4
-autom4te.cache
-config.log
-config.status
-configure
-install-sh
-missing
Index: anches/cnb_branches/cnb_branch_20090215/stac/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/stac/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,11 +1,0 @@
-Makefile
-Makefile.in
-aclocal.m4
-autom4te.cache
-compile
-config.log
-config.status
-configure
-depcomp
-install-sh
-missing
Index: anches/cnb_branches/cnb_branch_20090215/stac/src/.cvsignore
===================================================================
--- /branches/cnb_branches/cnb_branch_20090215/stac/src/.cvsignore	(revision 23196)
+++ 	(revision )
@@ -1,12 +1,0 @@
-.deps
-Makefile
-Makefile.in
-calcGradient
-combine
-shift
-shiftSize
-stac
-sum
-config.h
-config.h.in
-stamp-h1
