Index: /trunk/ippScripts/scripts/magic_tree.pl
===================================================================
--- /trunk/ippScripts/scripts/magic_tree.pl	(revision 16736)
+++ /trunk/ippScripts/scripts/magic_tree.pl	(revision 16737)
@@ -17,7 +17,4 @@
 use PS::IPP::Metadata::Config;
 use PS::IPP::Metadata::List qw( parse_md_list );
-use PS::IPP::Operations qw( skycell_file
-			    generate_skycells
-			    );
 
 use Astro::FITS::CFITSIO qw( :constants );
@@ -44,5 +41,5 @@
 
 # Parse the command-line arguments
-my ($magic_id, $tess_id, $camera, $ra0, $dec0, $dbname, $workdir, $save_temps, $verbose, $no_update, $no_op);
+my ($magic_id, $tess_id, $camera, $ra0, $dec0, $dbname, $outroot, $save_temps, $verbose, $no_update, $no_op);
 GetOptions(
 	   'magic_id=s'    => \$magic_id,   # Magic identifier
@@ -52,5 +49,5 @@
 	   'dec=f'         => \$dec0,       # Boresight declination, radians
 	   'dbname=s'      => \$dbname,     # Database name
-	   'workdir=s'     => \$workdir,    # Working directory, for output files
+	   'outroot=s'     => \$outroot,    # Output root name
 	   'save-temps'    => \$save_temps, # Save temporary files?
 	   'verbose'       => \$verbose,    # Print stuff?
@@ -60,5 +57,5 @@
 
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
-pod2usage( -msg => "Required options: --magic_id --camera --workdir",
+pod2usage( -msg => "Required options: --magic_id --camera --outroot",
 	   -exitval => 3) unless
     defined $magic_id and
@@ -67,5 +64,5 @@
     defined $dec0 and
     defined $camera and
-    defined $workdir;
+    defined $outroot;
 
 $ipprc->define_camera($camera);
@@ -106,16 +103,11 @@
 }
 
-generate_skycells($ipprc, $tess_id, \@skycells, $workdir, $verbose) or
-    &my_die("Unable to generate skycells", $magic_id, $PS_EXIT_PROG_ERROR);
-
 ### For each skycell, project centre of skycell onto tangent plane of boresight
 my @fields;
 foreach my $skycell_id ( @skycells ) {
-    my $skyfile = skycell_file($tess_id, $skycell_id, $workdir) or 
-	&my_die("Unable to get name of skycell file", $magic_id, $PS_EXIT_PROG_ERROR);
-    &my_die("Unable to find skycell file", $magic_id, $PS_EXIT_SYS_ERROR) unless
-	$ipprc->file_exists( $skyfile );
-
-    my ($header, $status) = Astro::FITS::CFITSIO::fits_read_header( $skyfile );
+    my $skyfile = $ipprc->filename("SKYCELL.TEMPLATE", $outroot, $skycell_id );
+    $ipprc->skycell_file($tess_id, $skycell_id, $skyFile, $verbose) or &my_die("Unable to generate skycells $skycell_id", $magic_id, $PS_EXIT_PROG_ERROR);
+    my $skyfileResolved = $ipprc->file_resolve( $skyfile );
+    my ($header, $status) = Astro::FITS::CFITSIO::fits_read_header( $skyfileResolved );
     &my_die("Unable to read skycell header: $status", $magic_id, $PS_EXIT_SYS_ERROR) if $status;
     
