Index: trunk/ippScripts/scripts/fake_imfile.pl
===================================================================
--- trunk/ippScripts/scripts/fake_imfile.pl	(revision 18562)
+++ trunk/ippScripts/scripts/fake_imfile.pl	(revision 19932)
@@ -2,5 +2,5 @@
 
 ## this script is run on every imfile to perform the fake source
-## analysis and the forced photometry analysis.  
+## analysis and the forced photometry analysis.
 
 ## For the fake source analysis, we load the image, inject a number of
@@ -12,5 +12,5 @@
 
 ## For the forced photometry, we need to use the measured astrometry
-## to select the desired locations in pixel coord.  
+## to select the desired locations in pixel coord.
 
 # XXX : seeing needs to be determined from the input PSF (not currently done in ppSim)
@@ -27,4 +27,7 @@
 print "Starting script $0 on $host\n\n";
 
+use DateTime;
+my $mjd_start = DateTime->now->mjd;   # MJD of starting script
+
 use vars qw( $VERSION );
 $VERSION = '0.01';
@@ -41,19 +44,19 @@
 
 # Parse the command-line arguments
-my ( $exp_id, $fake_id, $class_id, $chiproot, $camroot, $camera, $outroot, 
+my ( $exp_id, $fake_id, $class_id, $chiproot, $camroot, $camera, $outroot,
      $dbname, $reduction, $verbose, $no_update, $no_op, $redirect  );
 GetOptions(
-    'exp_id=s'      	=> \$exp_id,    # Exposure identifier
-    'fake_id=s'     	=> \$fake_id,   # Chiptool identifier
-    'class_id=s'    	=> \$class_id,  # Class identifier
-    'chiproot=s'    	=> \$chiproot,  # Input Chip files (root)
-    'camroot=s'     	=> \$camroot,   # Input Camera files (root)
-    'camera|c=s'    	=> \$camera,	   # Camera
-    'outroot|w=s'   	=> \$outroot,   # output file base name
-    'dbname|d=s'    	=> \$dbname,    # Database name
-    'reduction=s'   	=> \$reduction, # Reduction class
-    'verbose'       	=> \$verbose,   # Print to stdout
-    'no-update'     	=> \$no_update, # Don't update the database?
-    'no-op'         	=> \$no_op,	   # Don't do any operations?
+    'exp_id=s'          => \$exp_id,    # Exposure identifier
+    'fake_id=s'         => \$fake_id,   # Chiptool identifier
+    'class_id=s'        => \$class_id,  # Class identifier
+    'chiproot=s'        => \$chiproot,  # Input Chip files (root)
+    'camroot=s'         => \$camroot,   # Input Camera files (root)
+    'camera|c=s'        => \$camera,       # Camera
+    'outroot|w=s'       => \$outroot,   # output file base name
+    'dbname|d=s'        => \$dbname,    # Database name
+    'reduction=s'       => \$reduction, # Reduction class
+    'verbose'           => \$verbose,   # Print to stdout
+    'no-update'         => \$no_update, # Don't update the database?
+    'no-op'             => \$no_op,        # Don't do any operations?
     'redirect-output'   => \$redirect,
     ) or pod2usage( 2 );
@@ -61,5 +64,5 @@
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
 pod2usage( -msg => "Required options: --exp_id --fake_id --class_id --chiproot --camroot --camera --outroot",
-	   -exitval => 3) unless
+           -exitval => 3) unless
     defined $exp_id and
     defined $fake_id and
@@ -104,5 +107,5 @@
 }
 
-my $mdcParser = PS::IPP::Metadata::Config->new;	# Parser for metadata config files
+my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
 
 # outroot examples (HOST components must be set)
@@ -120,5 +123,5 @@
 my $chipPSF       = $ipprc->filename("PSPHOT.PSF.SAVE",     $chiproot, $class_id) or &my_die("Missing entry from camera config", $exp_id, $fake_id, $class_id, $PS_EXIT_CONFIG_ERROR);
 my $cameraObjects = $ipprc->filename("PSASTRO.OUTPUT",      $camroot)             or &my_die("Missing entry from camera config", $exp_id, $fake_id, $class_id, $PS_EXIT_CONFIG_ERROR);
-my $traceDest     = $ipprc->filename("TRACE.IMFILE", 	    $outroot, $class_id)  or &my_die("Missing entry from camera config", $exp_id, $fake_id, $class_id, $PS_EXIT_CONFIG_ERROR);
+my $traceDest     = $ipprc->filename("TRACE.IMFILE",        $outroot, $class_id)  or &my_die("Missing entry from camera config", $exp_id, $fake_id, $class_id, $PS_EXIT_CONFIG_ERROR);
 
 # XXX check for existence of input data
@@ -128,11 +131,11 @@
 my $command = "$ppConfigDump -camera $camera -dump-recipe PPSIM -recipe PPSIM $recipe -";
 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 ppConfigDump: $error_code", $exp_id, $fake_id, $class_id, $PS_EXIT_SYS_ERROR);
+        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+        &my_die("Unable to perform ppConfigDump: $error_code", $exp_id, $fake_id, $class_id, $PS_EXIT_SYS_ERROR);
 }
 my $recipeData = $mdcParser->parse(join "", @$stdout_buf) or
-	&my_die("Unable to parse metadata config doc", $exp_id, $fake_id, $class_id, $PS_EXIT_SYS_ERROR);
+        &my_die("Unable to parse metadata config doc", $exp_id, $fake_id, $class_id, $PS_EXIT_SYS_ERROR);
 
 ## allow the output images to be optional, depending on the recipe / reduction class
@@ -156,8 +159,8 @@
 
     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 ppSim: $error_code", $exp_id, $fake_id, $class_id, $error_code);
+        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+        &my_die("Unable to perform ppSim: $error_code", $exp_id, $fake_id, $class_id, $error_code);
     }
 
@@ -167,19 +170,19 @@
     # XXX use this to parse the output metadata : eg, detection limits, Nfakes, Nforced
     # Get the statistics on the processed image
-    # my $statsFile;		# File handle
+    # my $statsFile;            # File handle
     # open $statsFile, $ipprc->file_resolve($outputStats) or &my_die("Can't open statistics file $outputStats: $!", $exp_id, $fake_id, $class_id, $PS_EXIT_SYS_ERROR);
     # my @contents = <$statsFile>; # Contents of file
     # close $statsFile;
-    # 
+    #
     # # parse the statistics MDC file
-    # my $mdcParser = PS::IPP::Metadata::Config->new();	# Parser for metadata config files
+    # my $mdcParser = PS::IPP::Metadata::Config->new(); # Parser for metadata config files
     # my $metadata = $mdcParser->parse(join "", @contents);
     # unless ($metadata) {
-    # 	&my_die("Unable to parse metadata config doc", $exp_id, $fake_id, $class_id, $PS_EXIT_PROG_ERROR);
+    #   &my_die("Unable to parse metadata config doc", $exp_id, $fake_id, $class_id, $PS_EXIT_PROG_ERROR);
     # }
-    # 
+    #
     # # extract the stats from the metadata
     # unless ($stats->parse($metadata)) {
-    # 	&my_die("Failure extracting metadata from the statistics output file.\n", $exp_id, $fake_id, $class_id, $PS_EXIT_PROG_ERROR);
+    #   &my_die("Failure extracting metadata from the statistics output file.\n", $exp_id, $fake_id, $class_id, $PS_EXIT_PROG_ERROR);
     # }
 } else {
@@ -194,4 +197,5 @@
 $command .= " -path_base $outroot";
 $command .= " -dbname $dbname" if defined $dbname;
+$command .= (" -dtime_script " . (($mjd_start - DateTime->now->mjd) * 86400));
 # XXX add this after defined
 # $command .= $stats->cmdflags();
@@ -200,9 +204,9 @@
 unless ($no_update) {
     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);
-	warn("Unable to perform faketool -addprocessedimfile: $error_code\n");
-	exit($error_code);
+        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+        warn("Unable to perform faketool -addprocessedimfile: $error_code\n");
+        exit($error_code);
     }
 } else {
@@ -220,11 +224,12 @@
     carp($msg);
     if (defined $exp_id and defined $fake_id and defined $class_id and not $no_update) {
-	my $command = "$faketool -addprocessedimfile";
-	$command .= " -fake_id $fake_id";
-	$command .= " -exp_id $exp_id";
-	$command .= " -class_id $class_id";
-	$command .= " -path_base $outroot";
-	$command .= " -code $exit_code";
-	$command .= " -dbname $dbname" if defined $dbname;
+        my $command = "$faketool -addprocessedimfile";
+        $command .= " -fake_id $fake_id";
+        $command .= " -exp_id $exp_id";
+        $command .= " -class_id $class_id";
+        $command .= " -path_base $outroot";
+        $command .= (" -dtime_script " . (($mjd_start - DateTime->now->mjd) * 86400));
+        $command .= " -code $exit_code";
+        $command .= " -dbname $dbname" if defined $dbname;
         system ($command);
     }
