Index: trunk/ippScripts/scripts/camera_exp.pl
===================================================================
--- trunk/ippScripts/scripts/camera_exp.pl	(revision 13090)
+++ trunk/ippScripts/scripts/camera_exp.pl	(revision 13275)
@@ -17,16 +17,16 @@
 use PS::IPP::Metadata::List qw( parse_md_list );
 use Statistics::Descriptive;
-
-use PS::IPP::Config qw(
-    $PS_EXIT_SUCCESS
-    $PS_EXIT_UNKNOWN_ERROR
-    $PS_EXIT_SYS_ERROR
-    $PS_EXIT_CONFIG_ERROR
-    $PS_EXIT_PROG_ERROR
-    $PS_EXIT_DATA_ERROR
-    $PS_EXIT_TIMEOUT_ERROR
-    );
+use File::Temp qw( tempfile );
+
+use PS::IPP::Config qw($PS_EXIT_SUCCESS
+		       $PS_EXIT_UNKNOWN_ERROR
+		       $PS_EXIT_SYS_ERROR
+		       $PS_EXIT_CONFIG_ERROR
+		       $PS_EXIT_PROG_ERROR
+		       $PS_EXIT_DATA_ERROR
+		       $PS_EXIT_TIMEOUT_ERROR
+		       caturi
+		       );
 my $ipprc = PS::IPP::Config->new(); # IPP configuration
-use File::Spec;
 
 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
@@ -125,41 +125,19 @@
 }
 
-# Set output directory
-if (defined $workdir) {
-    $workdir = $ipprc->convert_filename_absolute( $workdir );
-    $workdir = File::Spec->catdir( $workdir, $exp_id );
-} else {
-    my $example = $ipprc->convert_filename_absolute( ${$files}[0]->{path_base}) ; # Example original name
-    my ($vol, $dir, $file) = File::Spec->splitpath( $example );
-    $workdir = $dir;
-}
-system "mkdir -p $workdir" unless -d $workdir;
-
-# Generate the file list, and get the statistics
-my $outputFile =  "$exp_id.cam$cam_id";
-my $outputRoot = File::Spec->catfile( $workdir, $outputFile );
-
-my $list1Name = $outputRoot . '.b1.list'; # Name for the input file list for binning 1
-my $list2Name = $outputRoot . '.b2.list'; # Name for the input file list for binning 2
-my $list3Name = $outputRoot . '.b3.list'; # Name for the input file list for chip astrometry
+my ($list1File, $list1Name) = tempfile( "$exp_id.cam$cam_id.b1.list.XXXX", UNLINK => 1 ); # For binning 1
+my ($list2File, $list2Name) = tempfile( "$exp_id.cam$cam_id.b2.list.XXXX", UNLINK => 1 ); # For binning 2
+my ($list3File, $list3Name) = tempfile( "$exp_id.cam$cam_id.b3.list.XXXX", UNLINK => 1 ); # For astrometry
 
 my @means;			# Array of means
 my @stdevs;			# Array of stdevs
-open my $list1File, '>' . $list1Name;
-open my $list2File, '>' . $list2Name;
-open my $list3File, '>' . $list3Name;
-
-print "$list1Name $list2Name $list3Name\n";
-
 my $chipObjects; 
 foreach my $file (@$files) {
     # use the path_base as OUTPUT root and convert the filenames with ipprc->filename:
     my $class_id = $file->{class_id};
-    my $origRoot = $ipprc->convert_filename_absolute( $file->{path_base} ); # Original root name
-
-    # if there is only one chip, we use this name for the input to addstar
-    $chipObjects = $ipprc->filename("PSASTRO.OUTPUT", $origRoot, $class_id);
-    print $list1File $ipprc->filename("PPIMAGE.BIN1", $origRoot, $class_id);
-    print $list2File $ipprc->filename("PPIMAGE.BIN2", $origRoot, $class_id);
+
+    # If there is only one chip, we use this name for the input to addstar
+    $chipObjects = $ipprc->filename("PSASTRO.OUTPUT", $file->{path_base}, $class_id);
+    print $list1File $ipprc->filename("PPIMAGE.BIN1", $file->{path_base}, $class_id);
+    print $list2File $ipprc->filename("PPIMAGE.BIN2", $file->{path_base}, $class_id);
     print $list3File $chipObjects;
     push @means, $file->{bg};
@@ -170,9 +148,10 @@
 close $list3File;
 
-# Output products --- need to synch with the camera configuration!
+# Output products
+$workdir = caturi( $workdir, $exp_id ) if defined $workdir;
+my $outputRoot = $ipprc->file_prepare( "$exp_id.cam$cam_id", $workdir, ${$files}[0]->{path_base} );
 my $jpeg1 = $ipprc->filename("PPIMAGE.JPEG1", $outputRoot); # Binned JPEG #1
 my $jpeg2 = $ipprc->filename("PPIMAGE.JPEG2", $outputRoot); # Binned JPEG #2
 my $fpaObjects = $ipprc->filename("PSASTRO.OUTPUT", $outputRoot); # MEF psastro output
-# my $dvo_camera = $ipprc->dvocamera();
 
 unless ($no_op) {
@@ -188,8 +167,8 @@
 	    &my_die("Unable to perform psastro: $error_code", $cam_id, $error_code);
 	}
-	&my_die("Unable to find expected output file: $fpaObjects", $cam_id, $PS_EXIT_PROG_ERROR) unless -f $fpaObjects;
     } else {
-	system "cp $chipObjects $fpaObjects";
-    }
+	$ipprc->file_copy($chipObjects, $fpaObjects);
+    }
+    &my_die("Unable to find expected output file: $fpaObjects", $cam_id, $PS_EXIT_PROG_ERROR) unless -f $ipprc->file_resolve($fpaObjects);
 
     # run addstar on either the single chip output or the single fpa output
@@ -197,5 +176,5 @@
     # XXX which in turn points at ippconfig/dvo.site
     {
-	my $command = "addstar -D CAMERA $camera $fpaObjects";
+	my $command = "addstar -D CAMERA $camera " . $ipprc->file_resolve($fpaObjects);
 	my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 	    run(command => $command, verbose => 1);
@@ -215,5 +194,5 @@
 	    &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 $jpeg1;
+	&my_die("Unable to find expected output file: $jpeg1", $cam_id, $PS_EXIT_PROG_ERROR) unless -f $ipprc->file_resolve($jpeg1);
     }
 
@@ -227,12 +206,9 @@
 	    &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 $jpeg2;
-    }
-}
-
-# XXX keep the same outroot as the input
+	&my_die("Unable to find expected output file: $jpeg2", $cam_id, $PS_EXIT_PROG_ERROR) unless -f $ipprc->file_resolve($jpeg2);
+    }
+}
+
 # Add the result into the database
-$outputRoot = $ipprc->convert_filename_relative( $outputRoot );
-
 unless ($no_update) {
     my $command = "$camtool -addprocessedexp -cam_id $cam_id -uri UNKNOWN -path_base $outputRoot " .
@@ -247,7 +223,4 @@
 	exit($error_code);
     }
-
-    unlink $list1Name;
-    unlink $list2Name;
 }
 
