Index: trunk/ippScripts/scripts/fake_exp.pl
===================================================================
--- trunk/ippScripts/scripts/fake_exp.pl	(revision 18786)
+++ trunk/ippScripts/scripts/fake_exp.pl	(revision 18786)
@@ -0,0 +1,129 @@
+#!/usr/bin/env perl
+
+use Carp;
+use warnings;
+use strict;
+
+## report the program and machine
+use Sys::Hostname;
+my $host = hostname();
+print "\n\n";
+print "Starting script $0 on $host\n\n";
+
+use vars qw( $VERSION );
+$VERSION = '0.01';
+
+use IPC::Cmd 0.36 qw( can_run run );
+use PS::IPP::Metadata::Config;
+use PS::IPP::Metadata::Stats;
+use PS::IPP::Config 1.01 qw( :standard );
+
+my $ipprc = PS::IPP::Config->new(); # IPP configuration
+
+use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
+use Pod::Usage qw( pod2usage );
+
+# Parse the command-line arguments
+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
+    '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 );
+
+pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
+pod2usage( -msg => "Required options: --exp_id --fake_id --camera --outroot",
+           -exitval => 3) unless
+    defined $exp_id and
+    defined $fake_id and
+    defined $camera and
+    defined $outroot;
+
+$ipprc->define_camera($camera);
+
+my $logDest = $ipprc->filename("LOG.EXP", $outroot, "exp") or &my_die("Missing entry from camera config", $exp_id, $fake_id, $PS_EXIT_CONFIG_ERROR);
+
+$ipprc->redirect_output($logDest) if $redirect;
+
+# Look for programs we need
+my $missing_tools;
+my $faketool = can_run('faketool') or (warn "Can't find faketool" and $missing_tools = 1);
+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
+
+# check for existing directory, generate if needed
+$ipprc->outroot_prepare($outroot);
+
+
+
+
+### Operations to perform go here
+
+
+
+
+### Update database
+{
+    my $command = "$faketool -addprocessedexp"; # Command to update database
+    $command   .= " -fake_id $fake_id";
+    $command   .= " -exp_id $exp_id";
+    $command   .= " -path_base $outroot";
+    $command   .= " -dbname $dbname" if defined $dbname;
+
+    # Add the processed file to the database
+    unless ($no_update) {
+        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);
+            warn("Unable to perform faketool -addprocessedexp: $error_code\n");
+            exit($error_code);
+        }
+    } else {
+        print "skipping command: $command\n";
+    }
+}
+
+### Pau.
+
+
+sub my_die
+{
+    my $msg = shift; # Warning message on die
+    my $exp_id = shift; # rawExp identifier
+    my $fake_id = shift; # fakeRun identifier
+    my $exit_code = shift; # Exit code to add
+
+    carp($msg);
+    if (defined $exp_id and defined $fake_id  and not $no_update) {
+        my $command = "$faketool -addprocessedexp";
+        $command .= " -fake_id $fake_id";
+        $command .= " -exp_id $exp_id";
+        $command .= " -path_base $outroot";
+        $command .= " -code $exit_code";
+        $command .= " -dbname $dbname" if defined $dbname;
+        system($command);
+    }
+    exit $exit_code;
+}
+
+END {
+    my $status = $?;
+    system("sync") == 0
+        or die "failed to execute sync: $!" ;
+    $? = $status;
+}
+
+__END__
