Index: trunk/ippScripts/scripts/camera_exp.pl
===================================================================
--- trunk/ippScripts/scripts/camera_exp.pl	(revision 17671)
+++ trunk/ippScripts/scripts/camera_exp.pl	(revision 17803)
@@ -29,23 +29,23 @@
      $no_op, $save_temps );
 GetOptions(
-	   'exp_tag=s'          => \$exp_tag, # Exposure identifier
-	   'cam_id=s'          => \$cam_id, # Camtool identifier
-	   'recipe=s'          => \$recipe, # Recipe to use
-	   'camera|c=s'        => \$camera, # Camera
-	   'dbname|d=s'        => \$dbname, # Database name
-	   'outroot|w=s'       => \$outroot, # output file base name
-	   'reduction=s'       => \$reduction, # Reduction class		       
-	   'dvodb|w=s'         => \$dvodb,  # output DVO database
-	   'verbose'           => \$verbose,   # Print to stdout
-	   'no-update'         => \$no_update, # Update the database?
-	   'no-op'             => \$no_op, # Don't do any operations?
-	   'save-temps'        => \$save_temps, # Save temporary files?
-	   ) or pod2usage( 2 );
+           'exp_tag=s'          => \$exp_tag, # Exposure identifier
+           'cam_id=s'          => \$cam_id, # Camtool identifier
+           'recipe=s'          => \$recipe, # Recipe to use
+           'camera|c=s'        => \$camera, # Camera
+           'dbname|d=s'        => \$dbname, # Database name
+           'outroot|w=s'       => \$outroot, # output file base name
+           'reduction=s'       => \$reduction, # Reduction class
+           'dvodb|w=s'         => \$dvodb,  # output DVO database
+           'verbose'           => \$verbose,   # Print to stdout
+           'no-update'         => \$no_update, # Update the database?
+           'no-op'             => \$no_op, # Don't do any operations?
+           'save-temps'        => \$save_temps, # Save temporary files?
+           ) or pod2usage( 2 );
 
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
 pod2usage(
-	  -msg => "Required options: --exp_tag --cam_id --camera --outroot",
-	  -exitval => 3,
-	  ) unless 
+          -msg => "Required options: --exp_tag --cam_id --camera --outroot",
+          -exitval => 3,
+          ) unless
     defined $exp_tag and
     defined $cam_id and
@@ -66,34 +66,34 @@
 # values to extract from output metadata and the stats to calculate
 # these should be coming from the psastro results
-my $CHIPSTATS = 
-    [   
-	#          PPSTATS KEYWORD         STATISTIC          CHIPTOOL FLAG
-	{ name => "bg",             type => "mean",  flag => "-bg",            	dtype => "float" },
-	{ name => "bg_stdev",       type => "rms",   flag => "-bg_stdev",      	dtype => "float" },  
-	{ name => "bg_mean_stdev",  type => "stdev", flag => "-bg_mean_stdev", 	dtype => "float" },
-	{ name => "bias",           type => "mean",  flag => "-bias",      	dtype => "float" },  
-	{ name => "bias_stdev",     type => "rms",   flag => "-bias_stdev",   	dtype => "float" },  
-        { name => "fringe_0",       type => "mean",  flag => "-fringe_0",      	dtype => "float" },  
-        { name => "fringe_1",       type => "rms",   flag => "-fringe_1",      	dtype => "float" },  
-        { name => "fringe_0",       type => "stdev", flag => "-fringe_2",      	dtype => "float" },  
-	{ name => "sigma_ra",       type => "rms",   flag => "-sigma_ra",      	dtype => "float" },  
-	{ name => "sigma_dec",      type => "rms",   flag => "-sigma_dec",     	dtype => "float" },  
-	{ name => "ap_resid",       type => "mean",  flag => "-ap_resid",      	dtype => "float" },  
-	{ name => "ap_resid_stdev", type => "rms",   flag => "-ap_resid_stdev", dtype => "float" },  
-	{ name => "zp_mean",        type => "mean",  flag => "-zp_mean",      	dtype => "float" },  
-	{ name => "zp_stdev",       type => "rms",   flag => "-zp_stdev",       dtype => "float" },  
-	{ name => "fwhm_major",     type => "mean",  flag => "-fwhm_major",     dtype => "float" },  
-	{ name => "fwhm_minor",     type => "mean",  flag => "-fwhm_minor",     dtype => "float" },  
-	{ name => "dtime_detrend",  type => "sum",   flag => "-dtime_detrend",  dtype => "float" },  
-	{ name => "dtime_photom",   type => "sum",   flag => "-dtime_photom",   dtype => "float" },  
-	{ name => "dtime_astrom",   type => "sum",   flag => "-dtime_astrom",   dtype => "float" },  
-	{ name => "n_stars",        type => "sum",   flag => "-n_stars",       	dtype => "int"   },  
-	{ name => "n_extended",     type => "sum",   flag => "-n_extended",     dtype => "int"   },  
-	{ name => "n_cr",           type => "sum",   flag => "-n_cr",       	dtype => "int"   },  
-	{ name => "n_astrom",       type => "sum",   flag => "-n_astrom",      	dtype => "int"   },  
+my $CHIPSTATS =
+    [
+        #          PPSTATS KEYWORD         STATISTIC          CHIPTOOL FLAG
+        { name => "bg",             type => "mean",  flag => "-bg",             dtype => "float" },
+        { name => "bg_stdev",       type => "rms",   flag => "-bg_stdev",       dtype => "float" },
+        { name => "bg_mean_stdev",  type => "stdev", flag => "-bg_mean_stdev",  dtype => "float" },
+        { name => "bias",           type => "mean",  flag => "-bias",           dtype => "float" },
+        { name => "bias_stdev",     type => "rms",   flag => "-bias_stdev",     dtype => "float" },
+        { name => "fringe_0",       type => "mean",  flag => "-fringe_0",       dtype => "float" },
+        { name => "fringe_1",       type => "rms",   flag => "-fringe_1",       dtype => "float" },
+        { name => "fringe_0",       type => "stdev", flag => "-fringe_2",       dtype => "float" },
+        { name => "sigma_ra",       type => "rms",   flag => "-sigma_ra",       dtype => "float" },
+        { name => "sigma_dec",      type => "rms",   flag => "-sigma_dec",      dtype => "float" },
+        { name => "ap_resid",       type => "mean",  flag => "-ap_resid",       dtype => "float" },
+        { name => "ap_resid_stdev", type => "rms",   flag => "-ap_resid_stdev", dtype => "float" },
+        { name => "zp_mean",        type => "mean",  flag => "-zp_mean",        dtype => "float" },
+        { name => "zp_stdev",       type => "rms",   flag => "-zp_stdev",       dtype => "float" },
+        { name => "fwhm_major",     type => "mean",  flag => "-fwhm_major",     dtype => "float" },
+        { name => "fwhm_minor",     type => "mean",  flag => "-fwhm_minor",     dtype => "float" },
+        { name => "dtime_detrend",  type => "sum",   flag => "-dtime_detrend",  dtype => "float" },
+        { name => "dtime_photom",   type => "sum",   flag => "-dtime_photom",   dtype => "float" },
+        { name => "dtime_astrom",   type => "sum",   flag => "-dtime_astrom",   dtype => "float" },
+        { name => "n_stars",        type => "sum",   flag => "-n_stars",        dtype => "int"   },
+        { name => "n_extended",     type => "sum",   flag => "-n_extended",     dtype => "int"   },
+        { name => "n_cr",           type => "sum",   flag => "-n_cr",           dtype => "int"   },
+        { name => "n_astrom",       type => "sum",   flag => "-n_astrom",       dtype => "int"   },
 
 
 # these are not defined for the database table camProcessedExp
-	];
+        ];
 my $chipStats = PS::IPP::Metadata::Stats->new($CHIPSTATS); # Stats parser
 
@@ -108,32 +108,32 @@
 my $addstar = can_run('addstar') or (warn "Can't find addstar" and $missing_tools = 1);
 
-if ($missing_tools) { 
+if ($missing_tools) {
     warn("Can't find required tools.");
-    exit($PS_EXIT_CONFIG_ERROR); 
-}
-
-my $mdcParser = PS::IPP::Metadata::Config->new;	# Parser for metadata config files
+    exit($PS_EXIT_CONFIG_ERROR);
+}
+
+my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
 
 # Get list of component files
-my $files;			# Array of component files
+my $files;                      # Array of component files
 {
     my $command = "$camtool -pendingimfile -cam_id $cam_id"; # Command to run
     $command .= " -dbname $dbname" if defined $dbname;
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-	run(command => $command, verbose => $verbose);
+        run(command => $command, verbose => $verbose);
     unless ($success) {
-	$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-	&my_die("Unable to perform camtool: $error_code", $cam_id, $error_code);
+        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+        &my_die("Unable to perform camtool: $error_code", $cam_id, $error_code);
     }
     my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
-	&my_die("Unable to parse metadata config doc", $cam_id, $PS_EXIT_PROG_ERROR);
+        &my_die("Unable to parse metadata config doc", $cam_id, $PS_EXIT_PROG_ERROR);
 
     # extract the metadata for the files into a hash list
     $files = parse_md_list($metadata) or
-	&my_die("Unable to parse metadata list", $cam_id, $PS_EXIT_PROG_ERROR);
+        &my_die("Unable to parse metadata list", $cam_id, $PS_EXIT_PROG_ERROR);
 
     # extract the stats from the metadata
     unless ($chipStats->parse($metadata)) {
-	&my_die("Unable to find all values in statistics output.\n", $cam_id, $PS_EXIT_PROG_ERROR);
+        &my_die("Unable to find all values in statistics output.\n", $cam_id, $PS_EXIT_PROG_ERROR);
     }
 }
@@ -145,5 +145,5 @@
 
 # XXX we perform astrometry iff photometry output exists
-my $chipObjects; 
+my $chipObjects;
 my $chipObjectsExist = 0;
 foreach my $file (@$files) {
@@ -160,5 +160,5 @@
     # if any of the output chip photometry files exist, we can run psastro / addstar below
     if ($ipprc->file_exists($chipObjects)) {
-	$chipObjectsExist = 1;
+        $chipObjectsExist = 1;
     }
 }
@@ -171,9 +171,9 @@
 
 # the camera configurations should define the psastro output to be a single file (MEF), regardless of the inputs
-my $jpeg1      = $ipprc->filename("PPIMAGE.JPEG1", 	$outroot) or &my_die("Missing entry from camera config", $cam_id, $PS_EXIT_CONFIG_ERROR);
-my $jpeg2      = $ipprc->filename("PPIMAGE.JPEG2", 	$outroot) or &my_die("Missing entry from camera config", $cam_id, $PS_EXIT_CONFIG_ERROR);
+my $jpeg1      = $ipprc->filename("PPIMAGE.JPEG1",      $outroot) or &my_die("Missing entry from camera config", $cam_id, $PS_EXIT_CONFIG_ERROR);
+my $jpeg2      = $ipprc->filename("PPIMAGE.JPEG2",      $outroot) or &my_die("Missing entry from camera config", $cam_id, $PS_EXIT_CONFIG_ERROR);
 my $fpaObjects = $ipprc->filename("PSASTRO.OUTPUT",     $outroot) or &my_die("Missing entry from camera config", $cam_id, $PS_EXIT_CONFIG_ERROR);
 my $traceDest  = $ipprc->filename("TRACE.EXP",          $outroot) or &my_die("Missing entry from camera config", $cam_id, $PS_EXIT_CONFIG_ERROR);
-my $logDest    = $ipprc->filename("LOG.EXP", 	        $outroot) or &my_die("Missing entry from camera config", $cam_id, $PS_EXIT_CONFIG_ERROR);
+my $logDest    = $ipprc->filename("LOG.EXP",            $outroot) or &my_die("Missing entry from camera config", $cam_id, $PS_EXIT_CONFIG_ERROR);
 
 # convert supplied DVO database name to UNIX filename
@@ -190,70 +190,70 @@
     # Make the jpeg for binning 1
     {
-	my $command = "$ppImage -list $list1Name $outroot -recipe PPIMAGE $recipe1"; # Command to run
-	$command .= " -dbname $dbname" if defined $dbname;
-
-	my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-	    run(command => $command, verbose => $verbose);
-	unless ($success) {
-	    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-	    &my_die("Unable to perform ppImage: $error_code", $cam_id, $error_code);
-	}
-	&my_die("Unable to find expected output file: $jpeg1", $cam_id, $PS_EXIT_PROG_ERROR) unless -f $ipprc->file_resolve($jpeg1);
+        my $command = "$ppImage -list $list1Name $outroot -recipe PPIMAGE $recipe1"; # Command to run
+        $command .= " -dbname $dbname" if defined $dbname;
+
+        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+            run(command => $command, verbose => $verbose);
+        unless ($success) {
+            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+            &my_die("Unable to perform ppImage: $error_code", $cam_id, $error_code);
+        }
+        &my_die("Unable to find expected output file: $jpeg1", $cam_id, $PS_EXIT_PROG_ERROR) unless -f $ipprc->file_resolve($jpeg1);
     }
 
     # Make the jpeg for binning 2
     {
-	my $command = "$ppImage -list $list2Name $outroot -recipe PPIMAGE $recipe2"; # Command to run
-	$command .= " -dbname $dbname" if defined $dbname;
-
-	my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-	    run(command => $command, verbose => $verbose);
-	unless ($success) {
-	    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-	    &my_die("Unable to perform ppImage: $error_code", $cam_id, $error_code);
-	}
-	&my_die("Unable to find expected output file: $jpeg2", $cam_id, $PS_EXIT_PROG_ERROR) unless -f $ipprc->file_resolve($jpeg2);
+        my $command = "$ppImage -list $list2Name $outroot -recipe PPIMAGE $recipe2"; # Command to run
+        $command .= " -dbname $dbname" if defined $dbname;
+
+        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+            run(command => $command, verbose => $verbose);
+        unless ($success) {
+            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+            &my_die("Unable to perform ppImage: $error_code", $cam_id, $error_code);
+        }
+        &my_die("Unable to find expected output file: $jpeg2", $cam_id, $PS_EXIT_PROG_ERROR) unless -f $ipprc->file_resolve($jpeg2);
     }
 
     # only run psastro / addstar if any of the output chip astrometry files exist (should we test for successful astrometry?)
     if ($chipObjectsExist) {
-	# run psastro on the chipObjects, producing fpaObjects
-	# XXX add a ppStats call which will collect the astrometry stats
-	my $command;
-	$command  = "$psastro -list $list3Name $outroot";
-	$command .= " -tracedest $traceDest -log $logDest";
-	$command .= " -dbname $dbname" if defined $dbname;
-
-	my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-	    run(command => $command, verbose => $verbose);
-	unless ($success) {
-	    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-	    &my_die("Unable to perform psastro: $error_code", $cam_id, $error_code);
-	}
-	# XXX do we want to give an error if astrometry fails here?
-	&my_die("Unable to find expected output file: $fpaObjects", $cam_id, $PS_EXIT_PROG_ERROR) unless -f $ipprc->file_resolve($fpaObjects);
-	
-	# run addstar on the output fpaObjects (if a DVO database is defined)
-	if (defined $dvodbReal) {
-	    # XXX this construct requires the user to have a valid .ptolemyrc 
-	    # XXX which in turn points at ippconfig/dvo.site
-	    # require a defined output dvo database to run addstar (ie, refuse to use the .ptolemyrc default)
-	    # XXX this needs to be converted to addstar_client...
-
-	    my $camdir = $ipprc->dvo_cameradir(); # Camera directory for addstar
-	    my $command;
-	    $command  = "$addstar -D CAMERA $camdir -update";
-	    $command .= " -D CATDIR $dvodbReal";
-
-	    my $realFile = $ipprc->file_resolve($fpaObjects);
-	    $command .= " $realFile";
-
-	    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-		run(command => $command, verbose => $verbose);
-	    unless ($success) {
-		$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-		&my_die("Unable to perform addstar: $error_code", $cam_id, $error_code);
-	    }
-	}
+        # run psastro on the chipObjects, producing fpaObjects
+        # XXX add a ppStats call which will collect the astrometry stats
+        my $command;
+        $command  = "$psastro -list $list3Name $outroot";
+        $command .= " -tracedest $traceDest -log $logDest";
+        $command .= " -dbname $dbname" if defined $dbname;
+
+        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+            run(command => $command, verbose => $verbose);
+        unless ($success) {
+            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+            &my_die("Unable to perform psastro: $error_code", $cam_id, $error_code);
+        }
+        # XXX do we want to give an error if astrometry fails here?
+        &my_die("Unable to find expected output file: $fpaObjects", $cam_id, $PS_EXIT_PROG_ERROR) unless -f $ipprc->file_resolve($fpaObjects);
+
+        # run addstar on the output fpaObjects (if a DVO database is defined)
+        if (defined $dvodbReal) {
+            # XXX this construct requires the user to have a valid .ptolemyrc
+            # XXX which in turn points at ippconfig/dvo.site
+            # require a defined output dvo database to run addstar (ie, refuse to use the .ptolemyrc default)
+            # XXX this needs to be converted to addstar_client...
+
+            my $camdir = $ipprc->dvo_cameradir(); # Camera directory for addstar
+            my $command;
+            $command  = "$addstar -D CAMERA $camdir -update";
+            $command .= " -D CATDIR $dvodbReal";
+
+            my $realFile = $ipprc->file_resolve($fpaObjects);
+            $command .= " $realFile";
+
+            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+                run(command => $command, verbose => $verbose);
+            unless ($success) {
+                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+                &my_die("Unable to perform addstar: $error_code", $cam_id, $error_code);
+            }
+        }
     }
 }
@@ -263,4 +263,5 @@
 $fpaCommand .= " -uri UNKNOWN";
 $fpaCommand .= " -path_base $outroot";
+$fpaCommand .= " -hostname $host" if defined $host;
 $fpaCommand .= " -dbname $dbname" if defined $dbname;
 $fpaCommand .= $chipStats->cmdflags();
@@ -269,9 +270,9 @@
 unless ($no_update) {
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-	run(command => $fpaCommand, verbose => $verbose);
+        run(command => $fpaCommand, verbose => $verbose);
     unless ($success) {
-	$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-	warn("Unable to add result to database: $error_code\n");
-	exit($error_code);
+        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+        warn("Unable to add result to database: $error_code\n");
+        exit($error_code);
     }
 } else {
@@ -288,6 +289,7 @@
     carp($msg);
     if (defined $cam_id and not $no_update) {
-	my $command = "$camtool -addprocessedexp -cam_id $cam_id -uri UNKNOWN -code $exit_code";
-	$command .= " -dbname $dbname" if defined $dbname;
+        my $command = "$camtool -addprocessedexp -cam_id $cam_id -uri UNKNOWN -code $exit_code";
+        $command .= " -hostname $host" if defined $host;
+        $command .= " -dbname $dbname" if defined $dbname;
         system ($command);
     }
