Index: trunk/ippScripts/scripts/ipp_serial_inject.pl
===================================================================
--- trunk/ippScripts/scripts/ipp_serial_inject.pl	(revision 14021)
+++ trunk/ippScripts/scripts/ipp_serial_inject.pl	(revision 14039)
@@ -3,7 +3,7 @@
 # this program injects a list of single-file exposures into the db,
 # taking the filename (without .fits) as the exp_tag.  the user
-# supplies a temporary telescope and instrument name.  these are used
+# supplies a temporary telescope and camera name.  these are used
 # for informational purposes only until the registration step can
-# determine the true telescope and instrument name from the image
+# determine the true telescope and camera name from the image
 # headers.
 
@@ -24,23 +24,25 @@
 
 # Parse the command-line arguments
-my ($workdir, $dbname, $telescope, $instrument, $help);
+my ($workdir, $dbname, $telescope, $camera, $help);
 GetOptions(
     'workdir|w=s'    => \$workdir, # working directory for output files
     'dbname|d=s'     => \$dbname, # Database name
     'telescope|t=s'  => \$telescope, # user-supplied telescope name
-    'instrument|i=s' => \$instrument, # user-supplied instrument name
+    'camera|i=s'     => \$camera, # user-supplied camera name
     'help'           => \$help # give help listing
 ) or pod2usage( 2 );
 
-pod2usage( -msg => "inject one or many files into the IPP pipeline database", -exitval => 2
+pod2usage( -msg => "inject one or many files into the IPP pipeline database", 
+	   -exitval => 2) if 
+    defined $help;
 
-pod2usage( -msg => "Usage: $0 --telescope (name) --instrument (name) [--workdir path] [--dbname dbname] (files)", 
+pod2usage( -msg => "Usage: $0 --telescope (name) --camera (name) [--workdir path] [--dbname dbname] (files)", 
 	   -exitval => 2 ) if 
-	   scalar @ARGV == 0;
+    scalar @ARGV == 0;
 
-pod2usage( -msg => "Required options: --telescope (name) --instrument (name)",
+pod2usage( -msg => "Required options: --telescope (name) --camera (name)",
 	   -exitval => 3) unless
-	   defined $telescope and
-	   defined $instrument;
+    defined $telescope and
+    defined $camera;
 
 my $pxinject = can_run('pxinject') or die "Can't find pxinject\n";
@@ -54,6 +56,8 @@
 my $num = 0;
 foreach my $file ( @ARGV ) {
+    # check for file existence
+    if (! -e $file) { die "file $file not found\n"; }
     my $absfile = File::Spec->rel2abs( $file );
-    inject($absfile, $workdir, $dbname, $telescope, $instrument);
+    inject($absfile, $workdir, $dbname, $telescope, $camera);
     $num ++;
 }
@@ -67,5 +71,5 @@
     my $dbname = shift;		# IPP database to use
     my $telescope = shift;	# user-specified telescope
-    my $instrument = shift;	# user-specified instrument
+    my $camera = shift;	# user-specified camera
 
     my ( $vol, $path, $name ) = File::Spec->splitpath( $absfile );
@@ -74,8 +78,11 @@
     my $relfile = $ipprc->convert_filename_relative( $absfile );
 
-    my $command_exp = "$pxinject -newExp -exp_name $exp_name -inst $instrument -telescope $telescope -imfiles 1 -workdir $workdir" ; # Command to run
-    if ($dbname) {
-	$command_exp = "$command_exp -dbname $dbname";
-    }
+    # the telescope, instrument, and exp_name used here are temporary : register replaces them with the true values
+    my $command_exp = "$pxinject -newExp";
+    $command_exp .= " -tmp_exp_name $exp_name";
+    $command_exp .= " -tmp_inst $camera";
+    $command_exp .= " -tmp_telescope $telescope";
+    $command_exp .= " -workdir $workdir";
+    $command_exp .= " -dbname $dbname" if defined $dbname;
 
     my ( $success_exp, $error_code_exp, $full_buf_exp, $stdout_buf_exp, $stderr_buf_exp ) =
@@ -86,12 +93,22 @@
     my $exp_id = $line[2];	# The exposure tag
     
-    # XXX the class_id used here should be temporary : register should replace it with the true class_id
-    my $command_imfile = "$pxinject -newImfile -exp_id $exp_id -exp_name $exp_name -class fpa -class_id fpa -uri $relfile"; # Command to run
-    if ($dbname) {
-	$command_imfile = "$command_imfile -dbname $dbname";
-    }
+    # the class_id used here is temporary : register replaces it with the true class_id
+    my $command_imfile = "$pxinject -newImfile";
+    $command_imfile .= " -exp_id $exp_id";
+    $command_imfile .= " -tmp_class_id fpa";
+    $command_imfile .= " -uri $relfile";
+    $command_imfile .= " -dbname $dbname" if defined ($dbname);
     
     my ( $success_imfile, $error_code_imfile, $full_buf_imfile, $stdout_buf_imfile, $stderr_buf_imfile ) = run( command => $command_imfile, verbose => 1 );
     die "Unable to inject $exp_name imfile: $error_code_imfile\n" if not $success_imfile;
+
+    # the class_id used here is temporary : register replaces it with the true class_id
+    my $command_update = "$pxinject -updatenewExp";
+    $command_update .= " -exp_id $exp_id";
+    $command_update .= " -state run";
+    $command_update .= " -dbname $dbname" if defined ($dbname);
+    
+    my ( $success_update, $error_code_update, $full_buf_update, $stdout_buf_update, $stderr_buf_update ) = run( command => $command_update, verbose => 1 );
+    die "Unable to update $exp_name: $error_code_update\n" if not $success_update;
 
     return 1;
