Index: /trunk/ippScripts/scripts/calibrate_dvo.pl
===================================================================
--- /trunk/ippScripts/scripts/calibrate_dvo.pl	(revision 16275)
+++ /trunk/ippScripts/scripts/calibrate_dvo.pl	(revision 16276)
@@ -36,8 +36,8 @@
 use Pod::Usage qw( pod2usage );
 
-my ($dvo_id, $catdir, $region, $dbname, $workdir, $no_update, $no_op);
+my ($cal_id, $dvodb, $region, $dbname, $workdir, $no_update, $no_op);
 GetOptions(
-    'dvo_id|i=s'       => \$dvo_id,
-    'catdir|c=s'       => \$catdir,
+    'cal_id|i=s'       => \$cal_id,
+    'dvodb|c=s'        => \$dvodb,
     'region|r=s'       => \$region,
     'dbname|d=s'       => \$dbname,# Database name
@@ -48,8 +48,8 @@
 
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
-pod2usage( -msg => "Required options: --dvo_id --catdir --region",
+pod2usage( -msg => "Required options: --cal_id --dvodb --region",
            -exitval => 3) unless
-    defined $dvo_id and
-    defined $catdir and
+    defined $cal_id and
+    defined $dvodb and
     defined $region;
 
@@ -78,5 +78,5 @@
 {
     my $command = "$addstar -resort";
-    $command .= "-D CATDIR $catdir";
+    $command .= "-D CATDIR $dvodb";
     $command .= "-region $RAs $RAe $DECs $DECe";
 
@@ -86,5 +86,5 @@
     unless ($success) { 
         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-        &my_die ("Unable to perform addstar -resort on region $region: $error_code", $dvo_id, $region, "RESORT", $status, $dbname);
+        &my_die ("Unable to perform addstar -resort on region $region: $error_code", $cal_id, $region, "RESORT", $status, $dbname);
     }
 }
@@ -94,5 +94,5 @@
     foreach my $filter (@filters) {
 	my $command = "$relphot $filter";
-	$command .= "-D CATDIR $catdir";
+	$command .= "-D CATDIR $dvodb";
 	$command .= "-region $RAs $RAe $DECs $DECe";
 
@@ -102,5 +102,5 @@
 	unless ($success) { 
 	    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-	    &my_die ("Unable to perform addstar -resort on region $region: $error_code", $dvo_id, $region, "RELPHOT", $status, $dbname);
+	    &my_die ("Unable to perform addstar -resort on region $region: $error_code", $cal_id, $region, "RELPHOT", $status, $dbname);
 	}
     }
@@ -112,5 +112,5 @@
     foreach my $filter (@filters) {
 	my $command = "$uniphot $filter";
-	$command .= "-D CATDIR $catdir";
+	$command .= "-D CATDIR $dvodb";
 	$command .= "-region $RAs $RAe $DECs $DECe";
 
@@ -120,5 +120,5 @@
 	unless ($success) { 
 	    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-	    &my_die ("Unable to perform addstar -resort on region $region: $error_code", $dvo_id, $region, "UNIPHOT", $status, $dbname);
+	    &my_die ("Unable to perform addstar -resort on region $region: $error_code", $cal_id, $region, "UNIPHOT", $status, $dbname);
 	}
     }
@@ -127,5 +127,5 @@
 {
     my $command = "$relastro -objects";
-    $command .= "-D CATDIR $catdir";
+    $command .= "-D CATDIR $dvodb";
     $command .= "-region $RAs $RAe $DECs $DECe";
 
@@ -135,5 +135,5 @@
     unless ($success) { 
 	$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-	&my_die ("Unable to perform addstar -resort on region $region: $error_code", $dvo_id, $region, "RELASTRO.OBJECTS", $status, $dbname);
+	&my_die ("Unable to perform addstar -resort on region $region: $error_code", $cal_id, $region, "RELASTRO.OBJECTS", $status, $dbname);
     }
 }
@@ -141,5 +141,5 @@
 {
     my $command = "$relastro -images";
-    $command .= "-D CATDIR $catdir";
+    $command .= "-D CATDIR $dvodb";
     $command .= "-region $RAs $RAe $DECs $DECe";
 
@@ -149,13 +149,13 @@
     unless ($success) { 
 	$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-	&my_die ("Unable to perform addstar -resort on region $region: $error_code", $dvo_id, $region, "RELASTRO.IMAGES", $status, $dbname);
-    }
-}
-
-my $command = "$caltool -addcalrun";
-$command .= " -dvo_id $dvo_id";
+	&my_die ("Unable to perform addstar -resort on region $region: $error_code", $cal_id, $region, "RELASTRO.IMAGES", $status, $dbname);
+    }
+}
+
+my $command = "$caltool -addrun";
+$command .= " -cal_id $cal_id";
 $command .= " -region $region";
 $command .= " -last_step RELASTRO.IMAGES";
-$command .= " -status SUCCESS";
+$command .= " -state 0";
 $command .= " -dbname $dbname" if defined $dbname;
 
@@ -176,5 +176,5 @@
 {
     my $msg = shift; # Warning message on die
-    my $dvo_id    = shift;
+    my $cal_id    = shift;
     my $region    = shift;
     my $last_step = shift;
@@ -183,10 +183,10 @@
 
     carp($msg);
-    if ($dvo_id && $region && $last_step && $status and not $no_update) {
+    if ($cal_id && $region && $last_step && $status and not $no_update) {
         my $command = "$caltool -addcalrun";
-	$command .= " -dvo_id $dvo_id";
+	$command .= " -cal_id $cal_id";
         $command .= " -region $region";
 	$command .= " -last_step $last_step";
-	$command .= " -status $status";
+	$command .= " -state $status";
         $command .= " -dbname $dbname" if defined $dbname;
         system ($command);
Index: /trunk/ippScripts/scripts/flatcorr_proc.pl
===================================================================
--- /trunk/ippScripts/scripts/flatcorr_proc.pl	(revision 16275)
+++ /trunk/ippScripts/scripts/flatcorr_proc.pl	(revision 16276)
@@ -8,6 +8,4 @@
 
 # relphot -D CATDIR $dvodb -grid (outgrid.fits) (filter) -region 0 360 -90 90 (other parameters?)
-
-# detselect flat?
 
 # dvoMakeCorr -file outgrid.fits -ref ref.fits outcorr
@@ -52,9 +50,10 @@
 use Pod::Usage qw( pod2usage );
 
-my ($dvo_id, $catdir, $region, $dbname, $workdir, $no_update, $no_op);
+my ($corr_id, $dvodb, $region, $filter, $dbname, $workdir, $no_update, $no_op);
 GetOptions(
-    'dvo_id|i=s'       => \$dvo_id,
-    'catdir|c=s'       => \$catdir,
+    'corr_id|i=s'      => \$corr_id,
+    'dvodb|c=s'        => \$dvodb,
     'region|r=s'       => \$region,
+    'filter|f=s'       => \$filter,
     'dbname|d=s'       => \$dbname,# Database name
     'workdir|w=s'      => \$workdir, # Working directory for output files
@@ -64,17 +63,18 @@
 
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
-pod2usage( -msg => "Required options: --dvo_id --catdir --region",
+pod2usage( -msg => "Required options: --corr_id --dvodb --region --filter",
            -exitval => 3) unless
-    defined $dvo_id and
-    defined $catdir and
-    defined $region;
+    defined $corr_id and
+    defined $dvodb and
+    defined $region and
+    defined $filter;
 
 # Look for programs we need
 my $missing_tools;
-my $addstar  = can_run('addstar')  or (warn "Can't find addstar"  and $missing_tools = 1);
-my $relphot  = can_run('relphot')  or (warn "Can't find relphot"  and $missing_tools = 1);
-my $uniphot  = can_run('uniphot')  or (warn "Can't find uniphot"  and $missing_tools = 1);
-my $relastro = can_run('relastro') or (warn "Can't find relastro" and $missing_tools = 1);
-my $caltool  = can_run('caltool')  or (warn "Can't find caltool"  and $missing_tools = 1);
+my $relphot     = can_run('relphot')      or (warn "Can't find relphot"      and $missing_tools = 1);
+my $dvoMakeCorr = can_run('dvoMakeCorr')  or (warn "Can't find dvoMakeCorr"  and $missing_tools = 1);
+my $detselect   = can_run('detselect') 	  or (warn "Can't find detselect"    and $missing_tools = 1);
+my $dettool     = can_run('dettool')   	  or (warn "Can't find dettool"      and $missing_tools = 1);
+my $flatcorr    = can_run('flatcorr')  	  or (warn "Can't find flatcorr"     and $missing_tools = 1);
 
 if ($missing_tools) { 
@@ -83,6 +83,8 @@
 }
 
-# select the primary filters from DVO query?
-my (@filters) = `photcodeList -average`;
+my($outgrid, $outcorr);
+
+$outgrid = "$workdir/grid.$corr_id.fits";
+$outcorr = "$workdir/corr.$corr_id.fits";
 
 # parse the region (RAs,RAe:DECs,DECe) : item = +/-NNN.NNNN
@@ -91,57 +93,41 @@
 my ($DECs, $DECe) = split (",", $coords[1]);
 
-# Run addstar -resort
-{
-    my $command = "$addstar -resort";
-    $command .= "-D CATDIR $catdir";
+# Run relphot (filter) for each filter
+{
+    my $command = "$relphot $filter";
+    $command .= "-D CATDIR $dvodb";
     $command .= "-region $RAs $RAe $DECs $DECe";
-
-    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-        cache_run(command => $command, verbose => 1);
-
-    unless ($success) { 
-        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-        &my_die ("Unable to perform addstar -resort on region $region: $error_code", $dvo_id, $region, "RESORT", $status, $dbname);
-    }
-}
-
-# Run relphot (filter) for each filter
-{
-    foreach my $filter (@filters) {
-	my $command = "$relphot $filter";
-	$command .= "-D CATDIR $catdir";
-	$command .= "-region $RAs $RAe $DECs $DECe";
-
-	my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-	    cache_run(command => $command, verbose => 1);
-
-	unless ($success) { 
-	    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-	    &my_die ("Unable to perform addstar -resort on region $region: $error_code", $dvo_id, $region, "RELPHOT", $status, $dbname);
-	}
-    }
-}
-
-# Run uniphot (filter) for each filter
-# XXX skip this one?  run less frequently?
-if (0) {
-    foreach my $filter (@filters) {
-	my $command = "$uniphot $filter";
-	$command .= "-D CATDIR $catdir";
-	$command .= "-region $RAs $RAe $DECs $DECe";
-
-	my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-	    cache_run(command => $command, verbose => 1);
-
-	unless ($success) { 
-	    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-	    &my_die ("Unable to perform addstar -resort on region $region: $error_code", $dvo_id, $region, "UNIPHOT", $status, $dbname);
-	}
-    }
-}
-
-{
-    my $command = "$relastro -objects";
-    $command .= "-D CATDIR $catdir";
+    $command .= "-grid $outgrid";
+    $command .= "-imfreeze?";
+
+    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+	cache_run(command => $command, verbose => 1);
+
+    unless ($success) { 
+	$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+	&my_die ("Unable to perform addstar -resort on region $region: $error_code", $dvo_id, $region, "RELPHOT", $status, $dbname);
+    }
+}
+
+# use one of the input raw images as a reference image
+my ($reffile)
+{
+    my $command = "$flatcoor -flatcorrimfile -limit 1";
+
+    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+	cache_run(command => $command, verbose => 1);
+
+    unless ($success) { 
+	$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+	&my_die ("Unable to perform addstar -resort on region $region: $error_code", $dvo_id, $region, "RELPHOT", $status, $dbname);
+    }
+
+    # parse the output metadata to get the refernece image filename
+    $reffile = "foobar";
+}
+
+{
+    my $command = "$dvoMakeCorr -file $outgrid -ref $reffile $outcorr";
+    $command .= "-D CATDIR $dvodb";
     $command .= "-region $RAs $RAe $DECs $DECe";
 
@@ -156,7 +142,11 @@
 
 {
-    my $command = "$relastro -images";
-    $command .= "-D CATDIR $catdir";
-    $command .= "-region $RAs $RAe $DECs $DECe";
+    my $command = "$dettool -register";
+    $command .= "-det_type FLATCORR";
+    $command .= "-file_level $fileLevel";
+    $command .= "-workdir $workdir";
+    $command .= "-inst $inst";
+    $command .= " -dbname $dbname" if defined $dbname;
+    ## XXX what else do we need, and where do we get it?
 
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
@@ -169,9 +159,7 @@
 }
 
-my $command = "$caltool -addcalrun";
-$command .= " -dvo_id $dvo_id";
-$command .= " -region $region";
-$command .= " -last_step RELASTRO.IMAGES";
-$command .= " -status SUCCESS";
+my $command = "$flatcorr -done";
+$command .= " -corr_id $corr_id";
+$command .= " -stats UNKNOWN";
 $command .= " -dbname $dbname" if defined $dbname;
 
