Index: /trunk/ippScripts/scripts/flatcorr_proc.pl
===================================================================
--- /trunk/ippScripts/scripts/flatcorr_proc.pl	(revision 16808)
+++ /trunk/ippScripts/scripts/flatcorr_proc.pl	(revision 16809)
@@ -93,5 +93,5 @@
 my ($DECs, $DECe) = split (",", $coords[1]);
 
-# Run relphot (filter) for each filter
+# Run relphot (filter) for the specified region (need to clarify the options like imfreeze)
 {
     my $command = "$relphot $filter";
@@ -106,9 +106,10 @@
     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 relphot -grid on region $region: $error_code", $dvo_id, $region, "RELPHOT", $status, $dbname);
     }
 }
 
 # use one of the input raw images as a reference image
+# XXX I'm not sure how this works: do I run this once per imfile for a given exp?
 my ($reffile)
 {
@@ -120,22 +121,26 @@
     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_die ("Unable to perform flatcorr -flatcorrimfile: $error_code", $dvo_id, $region, "RELPHOT", $status, $dbname);
+    }
+
+    my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
+	&my_die("Unable to parse metadata config doc", $dvo_id, $region, "RELPHOT", $status, $dbname, $PS_EXIT_PROG_ERROR););
+
+    my $imfiles = parse_md_list($metadata) or 
+	&my_die("Unable to parse metadata list", $dvo_id, $region, "RELPHOT", $status, $dbname, $PS_EXIT_PROG_ERROR););
+
+    my $imfile = $imfiles->[0];
+    $reffile = $imfile->{uri};
 }
 
 {
     my $command = "$dvoMakeCorr -file $outgrid -ref $reffile $outcorr";
-    $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, "RELASTRO.OBJECTS", $status, $dbname);
+
+    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 dvoMakeCorr: $error_code", $dvo_id, $region, "RELASTRO.OBJECTS", $status, $dbname);
     }
 }
