Index: branches/pap/tools/diff_outputs.pl
===================================================================
--- branches/pap/tools/diff_outputs.pl	(revision 23948)
+++ branches/pap/tools/diff_outputs.pl	(revision 25027)
@@ -12,4 +12,19 @@
 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
 
+# List of products
+use constant PRODUCTS => { 'REGULAR' => [ 'IMAGE', 'MASK', 'VARIANCE',
+                                          'SOURCES', 'JPEG1', 'JPEG2',
+                                          'KERNEL' ],
+                           'ALL' => [ 'IMAGE', 'MASK', 'VARIANCE',
+                                      'SOURCES', 'JPEG1', 'JPEG2',
+                                      'KERNEL', 'INVERSE.IMAGE',
+                                      'INVERSE.MASK', 'INVERSE.VARIANCE',
+                                      'INVERSE.SOURCES' ],
+                           'INVERSE' => [ 'INVERSE.IMAGE', 'INVERSE.MASK',
+                                          'INVERSE.VARIANCE',
+                                          'INVERSE.SOURCES' ],
+                       };
+
+# Extensions to add to path_base
 use constant EXTENSIONS => { 'IMAGE' => '.fits', # Image
                              'MASK' => '.mask.fits', # Mask
@@ -19,4 +34,8 @@
                              'JPEG2' => '.b2.jpg', # Binned JPEG
                              'KERNEL' => '.subkernel', # Convolution kernel
+                             'INVERSE.IMAGE' => '.inv.fits', # Image
+                             'INVERSE.MASK' => '.inv.mask.fits', # Mask
+                             'INVERSE.VARIANCE' => '.inv.wt.fits', # Variance
+                             'INVERSE.SOURCES' => '.inv.cmf', # Sources
                          };
 
@@ -50,23 +69,32 @@
                        ) or die "Unable to connect to database: $DBI::errstr";
 
+
 # Query to run
-my $sql = "SELECT path_base FROM diffSkyfile WHERE diff_id = $diff_id";
+my $sql = "SELECT path_base, bothways FROM diffSkyfile JOIN diffRun USING(diff_id) WHERE diff_id = $diff_id AND fault = 0 AND quality = 0";
 $sql .= " AND skycell_id = '$skycell_id'" if defined $skycell_id;
 
 # List of diffs
-my $diffs = $db->selectcol_arrayref( $sql,
-                                     { Columns => [1] }
+my $diffs = $db->selectall_arrayref( $sql, { Slice => {} }
                                      ) or die "Unable to execute SQL: $DBI::errstr";
 
 my @products;                   # Array of products
 if (defined $products) {
-    @products = split /,/, $products;
+  PRODUCT_SEARCH: foreach my $product ( split(/,/, $products) ) {
+      foreach my $key ( keys %{PRODUCTS()} ) {
+          if ($product eq $key) {
+              push @products, @{${PRODUCTS()}{$key}};
+              next PRODUCT_SEARCH;
+          }
+      }
+      push @products, $product;
+  }
 } else {
-    @products = keys %{EXTENSIONS()};
+    @products = @{${PRODUCTS()}{'ALL'}};
 }
 
 foreach my $diff ( @$diffs ) {
     foreach my $product ( @products ) {
-        copy_extension( $diff, ${EXTENSIONS()}{$product} );
+        next if (not defined $diff->{bothways} or $diff->{bothways} eq 'NULL' or not $diff->{bothways}) and $product =~ /INVERSE/;
+        copy_extension( $diff->{path_base}, ${EXTENSIONS()}{$product} );
     }
 }
