Index: trunk/ippScripts/scripts/ipp_serial_inject.pl
===================================================================
--- trunk/ippScripts/scripts/ipp_serial_inject.pl	(revision 13751)
+++ trunk/ippScripts/scripts/ipp_serial_inject.pl	(revision 14021)
@@ -1,6 +1,13 @@
 #!/usr/bin/env perl
 
-# this program injects a list of single-file exposures into the db, taking the
-# filename (without .fits) as the exp_tag.
+# 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
+# for informational purposes only until the registration step can
+# determine the true telescope and instrument name from the image
+# headers.
+
+# this program should not fail because of the data format or the
+# configuration, except for the very basic database setup.
 
 use warnings;
@@ -8,11 +15,8 @@
 
 use IPC::Cmd 0.36 qw( can_run run );
-use PS::IPP::Metadata::Config;
-use PS::IPP::Metadata::List qw( parse_md_list );
 use File::Spec;
-# use File::Find::Rule;
 use PS::IPP::Config;
-my $ipprc = PS::IPP::Config->new();
-my $mdcParser = PS::IPP::Metadata::Config->new;	# Parser for metadata config files
+
+my $ipprc = PS::IPP::Config->new(); # this is used for PATH, NEB filename conversions
 
 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
@@ -20,14 +24,25 @@
 
 # Parse the command-line arguments
-my ($workdir, $dbname);
+my ($workdir, $dbname, $telescope, $instrument, $help);
 GetOptions(
-    'workdir|w=s'   => \$workdir,  # working directory for output files
-    'dbname|d=s'    => \$dbname    # Database name
+    '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
+    'help'           => \$help # give help listing
 ) or pod2usage( 2 );
 
-pod2usage( -msg => "Usage: $0 [--workdir path] [--dbname dbname] (files)", -exitval => 2 ) if scalar @ARGV == 0;
+pod2usage( -msg => "inject one or many files into the IPP pipeline database", -exitval => 2
+
+pod2usage( -msg => "Usage: $0 --telescope (name) --instrument (name) [--workdir path] [--dbname dbname] (files)", 
+	   -exitval => 2 ) if 
+	   scalar @ARGV == 0;
+
+pod2usage( -msg => "Required options: --telescope (name) --instrument (name)",
+	   -exitval => 3) unless
+	   defined $telescope and
+	   defined $instrument;
 
 my $pxinject = can_run('pxinject') or die "Can't find pxinject\n";
-my $ppStats = can_run('ppStats') or die "Can't find ppStats\n";
 
 # if workdir is not defined, assign the current path
@@ -40,5 +55,5 @@
 foreach my $file ( @ARGV ) {
     my $absfile = File::Spec->rel2abs( $file );
-    inject($absfile, $workdir, $dbname);
+    inject($absfile, $workdir, $dbname, $telescope, $instrument);
     $num ++;
 }
@@ -48,29 +63,16 @@
 sub inject
 {
-    my $absfile = shift;		# absolute path for this file
-    my $workdir  = shift;		# absolute path for output directory
-    my $dbname = shift;
+    my $absfile = shift;	# absolute path for this file
+    my $workdir  = shift;	# absolute path for output directory
+    my $dbname = shift;		# IPP database to use
+    my $telescope = shift;	# user-specified telescope
+    my $instrument = shift;	# user-specified instrument
 
     my ( $vol, $path, $name ) = File::Spec->splitpath( $absfile );
-    my ( $exp ) = $name =~ /(.*)\.fits/;
+    my ( $exp_name ) = $name =~ /(.*)\.fits/;
 
     my $relfile = $ipprc->convert_filename_relative( $absfile );
 
-    my $command_type = "$ppStats -recipe PPSTATS INJECT $absfile";
-
-    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command_type, verbose => 1);
-    die "Unable to perform ppStats: $error_code\n" if not $success;
-    my $metadata = $mdcParser->parse(join "", @$stdout_buf) 
-        or die "unable to parse metadata config doc";
-
-    my $type;
-    my $telescope;
-    my $instrument;
-    foreach my $row (@$metadata) {
-	if ($row->{name} eq "FPA.TELESCOPE")  { $telescope = $row->{value}; }
-	if ($row->{name} eq "FPA.INSTRUMENT") { $instrument = $row->{value}; } # this entry must return the camera in the ipp/config system which we load
-    }
-    
-    my $command_exp = "$pxinject -newExp -exp_id $exp -inst $instrument -telescope $telescope -imfiles 1 -workdir $workdir" ; # Command to run
+    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";
@@ -79,10 +81,11 @@
     my ( $success_exp, $error_code_exp, $full_buf_exp, $stdout_buf_exp, $stderr_buf_exp ) =
 	run( command => $command_exp, verbose => 1 );
-    die "Unable to inject $exp: $error_code_exp\n" if not $success_exp;
+    die "Unable to inject $exp_name: $error_code_exp\n" if not $success_exp;
     
     my @line = split(/\s+/, $$stdout_buf_exp[0]); # The output line, containing the exposure tag
-    my $exp_tag = $line[2];	# The exposure tag
+    my $exp_id = $line[2];	# The exposure tag
     
-    my $command_imfile = "$pxinject -newImfile -exp_tag $exp_tag -class fpa -class_id fpa -uri $relfile"; # Command to run
+    # 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";
@@ -90,5 +93,5 @@
     
     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 imfile: $error_code_imfile\n" if not $success_imfile;
+    die "Unable to inject $exp_name imfile: $error_code_imfile\n" if not $success_imfile;
 
     return 1;
