Index: /trunk/tools/releasecalib/scripts/calibudpateprocess.txt
===================================================================
--- /trunk/tools/releasecalib/scripts/calibudpateprocess.txt	(revision 35927)
+++ /trunk/tools/releasecalib/scripts/calibudpateprocess.txt	(revision 35927)
@@ -0,0 +1,26 @@
+Here are the steps used to put the 3PI.PV1 calibration info into the database on 2013-08-06
+
+# dump Images.dat
+ftlist columns=NAME,MCAL,DMCAL,SECZ,EXPTIME,TZERO,PHOTCO,FLAGS,UBERCAL_DIST /data/ipp060.0/gpc1/catdir/LAP.ThreePi.20120706.v2/Images.working.dat T > Images.working.txt
+
+
+# loop over entries and select values for each exposure from the up to 60 rows in the images table
+# Note this program has hardcoded values for the photcode information. A correct implementation would
+# get the values from there.
+perl extractinfo < Images.working.txt > 3pi.pv1.calibration.txt
+
+
+
+# read that file and update the relExp entries
+perl updatecalib 3pi.pv1.calibration.txt >& updatecalib.log
+
+
+Note that there are 224597 rows in relExp for 3PI.PV1 but only 211793 values extracted from DVO.
+12804 are currently missing.
+1253 of the relExps are for camRuns with bad quality so those are expected to be missing.
+11551 are missing
+
+Heather points out that the lower declination area in slice 18 has not been loaded into dvo yet.
+This accounts for 8104 of them.
+
+This leaves 3447 to track down. This will be easier once the updates are done
Index: /trunk/tools/releasecalib/scripts/extractinfo
===================================================================
--- /trunk/tools/releasecalib/scripts/extractinfo	(revision 35927)
+++ /trunk/tools/releasecalib/scripts/extractinfo	(revision 35927)
@@ -0,0 +1,100 @@
+#!/usr/bin/env perl
+
+# extract the calibration list from a partial ftlist of an Images.dat file
+
+use strict;
+use warnings;
+
+my $outcount = 0;
+
+my $log10 = log(10.);
+
+my $last_exp_id = 0;
+my $new_exp_id = 0;
+
+my $bad_flags = 0x62;   # ID_IMAGE_ASTROM_FAIL | ID_IMAGE_ASTROM_POOR | ID_IMAGE_PHOTOM_POOR
+                        # do the DVO flags actually add value other than PHOTOM_UBERCAL ?
+
+my @saved_vals;
+
+while (my $line = <STDIN>) {
+    chomp $line;
+    # skip empty lines
+    next if !$line;
+
+    my ($n, $name, $mcal, $dmcal, $secz, $exptime, $tzero, $photcode, $flags, $ubercal_dist) = split " ", $line;
+
+    # skip header lines
+    next unless defined $ubercal_dist;
+
+    #skip non gpc1 single frame photcodes (stacks)
+    next if ($photcode >= 11000 or $photcode < 10000);
+
+    # skip PHU images
+    next if $name =~ "PHU";
+
+    my $fcode = int($photcode / 100);
+
+    my ($filter, $clam, $k);
+    if ($fcode == 100) {
+        $filter = 'g';
+        $clam = 24.563;
+        $k = -0.147;
+    } elsif ($fcode == 101) {
+        $filter = 'r';
+        $clam = 24.750;
+        $k = -0.085;
+    } elsif ($fcode == 102) {
+        $filter = 'i';
+        $clam = 24.611;
+        $k = -0.044;
+    } elsif ($fcode == 103) {
+        $filter = 'z';
+        $clam = 24.250;
+        $k = -0.033;
+    } elsif ($fcode == 104) {
+        $filter = 'y';
+        $clam = 23.320;
+        $k = -0.073;
+    } else {
+        die "unexpected photcode: $photcode\n";
+    }
+
+    $dmcal = 0 if $dmcal eq 'NULL';
+
+    my $zpt = $clam - $mcal;
+
+    my ($exp_name, $exp_id, undef, $cam_id) = split '\.', $name;
+
+    # we take the values from the first chip
+    next if $exp_id eq $last_exp_id;
+    
+    if ($new_exp_id and $exp_id ne $new_exp_id) {
+        # exposure changed without getting a good one for previous exposure
+        # print last set of values
+        printexp(@saved_vals);
+        $new_exp_id = 0;
+        @saved_vals = ();
+    }
+
+    if ($flags & $bad_flags) {
+        $new_exp_id = $exp_id;
+        @saved_vals = ($exp_name, $exp_id, $cam_id, $zpt, $dmcal, $mcal, $filter, $flags, $ubercal_dist);
+        next;
+    }
+
+    $new_exp_id = 0;
+
+    $last_exp_id = $exp_id;
+    
+    printexp($exp_name, $exp_id, $cam_id, $zpt, $dmcal, $mcal, $filter, $flags, $ubercal_dist);
+
+}
+
+sub printexp {
+    if ($outcount % 100 == 0) {
+        print "#exp_name     exp_id  cam_id    zpcalib      zpcalerr        mcal     filter     flags   ubercal_dist\n";
+    }
+    $outcount++;
+    printf "%12s %7d %7d %12.8f %12.8f %12.8f %6s    0x%08x %6d\n", @_;
+}
Index: /trunk/tools/releasecalib/scripts/updatecalib
===================================================================
--- /trunk/tools/releasecalib/scripts/updatecalib	(revision 35927)
+++ /trunk/tools/releasecalib/scripts/updatecalib	(revision 35927)
@@ -0,0 +1,38 @@
+#!/usr/bin/env perl
+
+# program to read list of calibration data produced by extractinfo and update the corresponding
+# rows in gpc1 relExp table
+
+use strict;
+use warnings;
+
+my $input = shift;
+
+die "need input file name\n", unless defined $input;
+
+open IN, "<$input" or die "failed to open $input\n";
+
+my $release_name = '3PI.PV1';
+
+my $cmd = "releasetool -updaterelexp -release_name $release_name -set_state calibrated";
+
+while (my $line = <IN>) {
+    next if $line =~ /^#/;
+    chomp $line;
+
+    my ($exp_name, $exp_id, $cam_id, $zpt, $dmcal, $mcal, $filter, $flags, $ubercal_dist)
+        = split " ", $line;
+
+    die "failed to parse $line\n" unless defined $ubercal_dist;
+
+    my $command = "$cmd -exp_id $exp_id -set_zpt_obs $zpt -set_zpt_stdev $dmcal -set_flags $flags";
+    $command   .= " -set_mcal $mcal -set_ubercal_dist $ubercal_dist";
+
+    print STDERR "$command\n";
+
+    my $rc = system $command;
+    if ($rc) {
+        my $status = $rc >> 8;
+        die "$command failed with $rc $status\n";
+    }
+}
