Index: trunk/ippScripts/scripts/magic_tree.pl
===================================================================
--- trunk/ippScripts/scripts/magic_tree.pl	(revision 20673)
+++ trunk/ippScripts/scripts/magic_tree.pl	(revision 20674)
@@ -52,8 +52,7 @@
 
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
-pod2usage( -msg => "Required options: --magic_id --warp_id --camera --tess_id --ra --dec --outroot",
+pod2usage( -msg => "Required options: --magic_id --camera --tess_id --ra --dec --outroot",
            -exitval => 3) unless
     defined $magic_id and
-    defined $warp_id and
     defined $tess_id and
     defined $ra0 and
@@ -78,6 +77,8 @@
 
 ### Get a list of warpSkyfiles
+### This is a workaround to allow processing with older diffSkyfiles that don't have
+### a wcs. If warp_id is provided, we get the wcs from there
 my %warpSkyfiles;                   # hash of warps
-{
+if ($warp_id) {
     my $command = "$warptool -warped -warp_id $warp_id"; # Command to run
     $command .= " -dbname $dbname" if defined $dbname;
@@ -121,5 +122,5 @@
 
     foreach my $input ( @$inputs ) {
-        push @skycells, $input->{node}; # NB: Storing the skycell_id in magicInputSkyfile.node
+        push @skycells, $input; # NB: Storing the skycell_id in magicInputSkyfile.node
     }
 }
@@ -127,5 +128,5 @@
 ### For each skycell, project centre of skycell onto tangent plane of boresight
 my @fields;
-foreach my $skycell_id ( @skycells ) {
+foreach my $input ( @skycells ) {
     # the filename method doesn't add the $skycell_id
 
@@ -137,14 +138,43 @@
 #    $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 $warp = $warpSkyfiles{$skycell_id};
-    die "warpSkyfile for $skycell_id not found" if !$warp;
-    my $skyfileBase = $warp->{path_base};
-    my $skyfile = $ipprc->filename("SKYCELL.TEMPLATE", $skyfileBase);
+    my $skyfile;
+    my $skycell_id = $input->{node};
+    if ($warp_id) {
+        # Applying the workaround
+        my $warp = $warpSkyfiles{$skycell_id};
+        die "warpSkyfile for $skycell_id not found" if !$warp;
+        my $skyfileBase = $warp->{path_base};
+        $skyfile = $ipprc->filename("SKYCELL.TEMPLATE", $skyfileBase);
+    } else {
+        # using the diffSkyfile
+        $skyfile = $input->{uri};
+    }
     my $skyfileResolved = $ipprc->file_resolve( $skyfile );
-    my ($header, $status) = Astro::FITS::CFITSIO::fits_read_header( $skyfileResolved );
+
+#    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;
+
+    my ($header, $status) = (undef, 0);
+    my $fits =  Astro::FITS::CFITSIO::open_file( $skyfileResolved, READONLY, $status ); 
+    &my_die("failed to open skycell file: $skyfileResolved: $status", $magic_id, $PS_EXIT_SYS_ERROR) if $status;
+
+    ($header, $status) = Astro::FITS::CFITSIO::fits_read_header( $fits );
+    
     &my_die("Unable to read skycell header: $status", $magic_id, $PS_EXIT_SYS_ERROR) if $status;
 
+
     # Get the useful header keywords
-    my $naxis1 = $$header{'NAXIS1'} or &my_die("Can't find NAXIS1", $magic_id, $PS_EXIT_SYS_ERROR);
+#    my $naxis1 = $$header{'NAXIS1'} or &my_die("Can't find NAXIS1", $magic_id, $PS_EXIT_SYS_ERROR);
+    my $naxis1 = $$header{'NAXIS1'};
+    if (!$naxis1) {
+        # XXX: if the skyfile is compressed then the WCS won't be in the primary header
+        my $hdutype;
+        $fits->movrel_hdu(1, $hdutype, $status);
+        &my_die("Unable to movrel_hdu: $status", $magic_id, $PS_EXIT_SYS_ERROR) if $status;
+
+        ($header, $status) = Astro::FITS::CFITSIO::fits_read_header( $fits );
+        &my_die("Unable to read extension header: $status", $magic_id, $PS_EXIT_SYS_ERROR) if $status;
+        $naxis1 = $$header{'NAXIS1'} or &my_die("Can't find NAXIS1", $magic_id, $PS_EXIT_SYS_ERROR);
+    }
     my $naxis2 = $$header{'NAXIS2'} or &my_die("Can't find NAXIS2", $magic_id, $PS_EXIT_SYS_ERROR);
     my $ctype1 = $$header{'CTYPE1'} or &my_die("Can't find CTYPE1", $magic_id, $PS_EXIT_SYS_ERROR);
