Index: trunk/ippScripts/scripts/warp_skycell.pl
===================================================================
--- trunk/ippScripts/scripts/warp_skycell.pl	(revision 16723)
+++ trunk/ippScripts/scripts/warp_skycell.pl	(revision 16728)
@@ -33,9 +33,8 @@
 		       caturi
 		       );
-use PS::IPP::Operations qw( skycell_file );
 
 my $ipprc = PS::IPP::Config->new(); # IPP configuration
 
-my ($warp_id, $skycell_id, $tess_id, $camera, $dbname, $workdir, $verbose, $no_update, $no_op, $save_temps);
+my ($warp_id, $skycell_id, $tess_id, $camera, $dbname, $outroot, $verbose, $no_update, $no_op, $save_temps);
 GetOptions(
     'warp_id|i=s'       => \$warp_id, # Warp identifier
@@ -44,5 +43,5 @@
     'camera|c=s'        => \$camera, # Camera name
     'dbname|d=s'        => \$dbname, # Database name
-    'workdir|w=s'       => \$workdir, # Working directory, for output files
+    'outroot=s'         => \$outroot, # Output root name
     'verbose'           => \$verbose,   # Print to stdout
     'no-update'         => \$no_update,	# Don't update the database?
@@ -116,31 +115,24 @@
 }
 
-my $skyFile = skycell_file($tess_id, $skycell_id, $workdir) or 
-    &my_die("Unable to get name of skycell file", $warp_id, $skycell_id, $tess_id, $PS_EXIT_SYS_ERROR);
-&my_die("Unable to find skycell file: $skyFile", $warp_id, $skycell_id, $tess_id, $PS_EXIT_SYS_ERROR) unless
-    $ipprc->file_exists( $skyFile );
-
-$workdir = caturi( $workdir, "tess_" . $tess_id, "sky_" . $skycell_id ) if defined $workdir;
-my $outputRoot = $ipprc->file_prepare( "$tess_id.$skycell_id.wrp$warp_id", $workdir, $$imfiles[0]->{uri} );
-my $outputImage = $ipprc->filename("PSWARP.OUTPUT", $outputRoot, $skycell_id );
-my $outputMask = $ipprc->filename("PSWARP.OUTPUT.MASK", $outputRoot, $skycell_id);
-my $outputWeight = $ipprc->filename("PSWARP.OUTPUT.WEIGHT", $outputRoot, $skycell_id);
-my $outputSources = $ipprc->filename("PSWARP.OUTPUT.SOURCES", $outputRoot, $skycell_id);
-my $outputPSF = $ipprc->filename("PSPHOT.PSF.SAVE", $outputRoot, $skycell_id);
-my $outputBin1 = $ipprc->filename("PSWARP.BIN1", $outputRoot, $skycell_id );
-my $outputBin2 = $ipprc->filename("PSWARP.BIN2", $outputRoot, $skycell_id );
-my $outputStats = $outputRoot . '.stats';
-
-my $traceDest = 'file:' . $ipprc->file_resolve($outputRoot) . ".trace"; # Trace messages
-my $logDest = 'file:' . $ipprc->file_resolve($outputRoot) . ".log"; # Log messages
+my $outputImage = $ipprc->filename("PSWARP.OUTPUT", $outroot, $skycell_id );
+my $outputMask = $ipprc->filename("PSWARP.OUTPUT.MASK", $outroot, $skycell_id);
+my $outputWeight = $ipprc->filename("PSWARP.OUTPUT.WEIGHT", $outroot, $skycell_id);
+my $outputSources = $ipprc->filename("PSWARP.OUTPUT.SOURCES", $outroot, $skycell_id);
+my $outputPSF = $ipprc->filename("PSPHOT.PSF.SAVE", $outroot, $skycell_id);
+my $outputBin1 = $ipprc->filename("PSWARP.BIN1", $outroot, $skycell_id );
+my $outputBin2 = $ipprc->filename("PSWARP.BIN2", $outroot, $skycell_id );
+my $outputStats = $ipprc->filename("SKYCELL.STATS", $outroot, $skycell_id );
+my $traceDest = $ipprc->filename("TRACE.EXP", $outroot, $skycell_id);
+my $logDest = $ipprc->filename("TRACE.IMFILE", $outroot, $skycell_id);
+
+my $skyFile = $ipprc->filename("SKYCELL.TEMPLATE", $outroot, $skycell_id );
+$ipprc->skycell_file( $tess_id, $skycell_id, $skyFile, $verbose ) or &my_die("Unable to generate template skycell", $warp_id, $skycell_id, $tess_id, $PS_EXIT_SYS_ERROR);
 
 # Get list of filenames
-my ($imageFile,  $imageName)  = tempfile( "$tess_id.$skycell_id.wrp$warp_id.image.list.XXXX",  UNLINK => !$save_temps);
-my ($maskFile,   $maskName)   = tempfile( "$tess_id.$skycell_id.wrp$warp_id.mask.list.XXXX",   UNLINK => !$save_temps);
-my ($weightFile, $weightName) = tempfile( "$tess_id.$skycell_id.wrp$warp_id.weight.list.XXXX", UNLINK => !$save_temps);
-my ($astromFile, $astromName) = tempfile( "$tess_id.$skycell_id.wrp$warp_id.astrom.list.XXXX", UNLINK => !$save_temps);
-
-# XXXX this is inconsistent: what is the goal of inputAstrom?
-my $inputAstrom = 0;
+my ($imageFile,  $imageName)  = tempfile( caturi($outroot, "$tess_id.$skycell_id.wrp$warp_id.image.list.XXXX"),  UNLINK => !$save_temps);
+my ($maskFile,   $maskName)   = tempfile( caturi($outroot, "$tess_id.$skycell_id.wrp$warp_id.mask.list.XXXX"),   UNLINK => !$save_temps);
+my ($weightFile, $weightName) = tempfile( caturi($outroot, "$tess_id.$skycell_id.wrp$warp_id.weight.list.XXXX"), UNLINK => !$save_temps);
+my ($astromFile, $astromName) = tempfile( caturi($outroot, "$tess_id.$skycell_id.wrp$warp_id.astrom.list.XXXX"), UNLINK => !$save_temps);
+
 foreach my $imfile (@$imfiles) {
     my $image = $imfile->{uri};	# Image name
@@ -154,20 +146,16 @@
     if ($astromSource eq 'PSASTRO.OUTPUT.MEF') {
 	$astrom = $ipprc->filename($astromSource, $imfile->{cam_path_base});
-	&my_die("Couldn't find input file: $astrom", $warp_id, $skycell_id, $tess_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($astrom);
-	$inputAstrom = 1;
-    }
-    if ($astromSource eq 'PSASTRO.OUTPUT') {
+    } elsif ($astromSource eq 'PSASTRO.OUTPUT') {
 	my $chipRoot = $imfile->{chip_path_base};
 	my $classID = $imfile->{class_id};
 	$astrom = $ipprc->filename($astromSource, $chipRoot, $classID); # Astrometry file
-	$inputAstrom = 1;
-    }
-
-    if ($inputAstrom) {
-	print $imageFile  "$image\n";
-	print $maskFile   "$mask\n";
-	print $weightFile "$weight\n";
-	print $astromFile "$astrom\n";
-    }
+    }
+
+    &my_die("Couldn't find input file: $astrom", $warp_id, $skycell_id, $tess_id, $PS_EXIT_SYS_ERROR) unless defined $astrom and $ipprc->file_exists($astrom);
+    
+    print $imageFile  "$image\n";
+    print $maskFile   "$mask\n";
+    print $weightFile "$weight\n";
+    print $astromFile "$astrom\n";
 }
 close $imageFile;
@@ -175,4 +163,5 @@
 close $weightFile;
 close $astromFile;
+
 
 # Run pswarp
@@ -183,6 +172,6 @@
     $command .= " -masklist $maskName";
     $command .= " -weightlist $weightName";
-    $command .= " -astromlist $astromName" if $inputAstrom;
-    $command .= " $outputRoot $skyFile";
+    $command .= " -astromlist $astromName";
+    $command .= " $outroot $skyFile";
     $command .= " -stats $outputStats";
     $command .= " -recipe PPSTATS WARPSTATS";
@@ -225,5 +214,5 @@
     my $command = "$warptool -addwarped -warp_id $warp_id -skycell_id $skycell_id -tess_id $tess_id";
     $command .= " -ignore" if not $accept; # Completed succesfully, but can't produce product
-    $command .= " -uri $outputImage -path_base $outputRoot" if $accept;
+    $command .= " -uri $outputImage -path_base $outroot" if $accept;
     $command .= $stats->cmdflags() if $accept;
     $command .= " -dbname $dbname" if defined $dbname;
