Index: trunk/ippTools/src/difftool.c
===================================================================
--- trunk/ippTools/src/difftool.c	(revision 37900)
+++ trunk/ippTools/src/difftool.c	(revision 37938)
@@ -42,4 +42,5 @@
 static bool definepoprunMode(pxConfig *config);
 static bool definewarpstackMode(pxConfig *config);
+static bool definewarpstackOldMethodMode(pxConfig *config);
 static bool definewarpwarpMode(pxConfig *config);
 static bool definestackstackMode(pxConfig *config);
@@ -95,4 +96,5 @@
         MODECASE(DIFFTOOL_MODE_DEFINEPOPRUN,          definepoprunMode);
         MODECASE(DIFFTOOL_MODE_DEFINEWARPSTACK,       definewarpstackMode);
+	MODECASE(DIFFTOOL_MODE_DEFINEWARPSTACKOLDMETHOD,       definewarpstackOldMethodMode);
         MODECASE(DIFFTOOL_MODE_DEFINEWARPWARP,        definewarpwarpMode);
         MODECASE(DIFFTOOL_MODE_DEFINESTACKSTACK,      definestackstackMode);
@@ -1250,5 +1252,5 @@
   }
   
-  
+  PXOPT_LOOKUP_BOOL(available, config->args, "-available", false);
   PXOPT_LOOKUP_BOOL(bothways, config->args, "-bothways", false);
   
@@ -1334,4 +1336,68 @@
     return true;
   }
+
+  // Do a pass through the result list to determine which runs should be excluded.
+  // This exclusion should do two things:  If a skycell doesn't have a stack (as we do a LEFT JOIN) now,
+  // then that skycell needs to not be included in the diff.  However, if we have available off,
+  // then we need to flag the entire exposure as bad.
+  psS64 previous_exp_id = 0;
+  long  start_index     = 0;
+  bool  bad_exposure    = false;
+  long  Nskycells       = 0;
+  for (long i = 0; i < output->n; i++) {
+    psMetadata *row = output->data[i];
+    bool mdok;
+    psS64 exp_id = psMetadataLookupS64(&mdok, row, "exp_id");
+    if (!mdok) {
+	psError(PXTOOLS_ERR_PROG, false, "exp_id not found");
+	if (!psDBRollback(config->dbh)) {
+	  psError(PS_ERR_UNKNOWN, false, "database error");
+	}
+	return false;
+    }
+
+    if (exp_id != previous_exp_id) { // Save the position of the start of this exposure.
+      if (Nskycells == 0) {  // Ooops, we didn't find any good skycells for this exposure.  Don't make an empty run.
+	for (long j = start_index; j < i; j++) { // Clear all the previous entries for this exposure.
+	  psMetadata *old_row = output->data[j];
+	  psMetadataAddBool(old_row,PS_LIST_TAIL, "exclude", PS_META_REPLACE, "", true);  // No stack exists, so this row can't be diffed.
+	  psMetadataAddBool(old_row,PS_LIST_TAIL, "excludeExp", PS_META_REPLACE, "", true);  // No stack exists, so this row can't be diffed.
+	}
+      }      
+      previous_exp_id = exp_id;
+      start_index = i;
+      bad_exposure = false;
+      Nskycells = 0;
+    }
+
+    if (bad_exposure) { // We've flagged this exposure as bad.
+      psMetadataAddBool(row,PS_LIST_TAIL, "exclude", PS_META_REPLACE, "", true);
+      psMetadataAddBool(row,PS_LIST_TAIL, "excludeExp", PS_META_REPLACE, "", true);
+      continue;
+    }
+
+    psMetadataAddBool(row,PS_LIST_TAIL, "exclude", PS_META_REPLACE, "", false); // By default, this shouldn't be excluded.
+    psMetadataAddBool(row,PS_LIST_TAIL, "excludeExp", PS_META_REPLACE, "", false);
+    
+    psS64 stack_id = psMetadataLookupS64(&mdok, row, "stack_id");
+    if (stack_id == PS_MAX_S64) { // stack_id IS NULL, we cannot make this skycell-level diff
+      psMetadataAddBool(row,PS_LIST_TAIL, "exclude", PS_META_REPLACE, "", true);  // No stack exists, so this row can't be diffed.
+
+      if (!available) { // We want to be strict about everything, so cancel this entire exposure.
+	bad_exposure = true;  // New exposures with this exp_id will be flagged as bad.
+	for (long j = start_index; j < i; j++) { // Clear all the previous entries for this exposure.
+	  psMetadata *old_row = output->data[j];
+	  psMetadataAddBool(old_row,PS_LIST_TAIL, "exclude", PS_META_REPLACE, "", true);  // No stack exists, so this row can't be diffed.
+	  psMetadataAddBool(old_row,PS_LIST_TAIL, "excludeExp", PS_META_REPLACE, "", true);  // No stack exists, so this row can't be diffed.
+	}
+      }
+    }
+    else { // This looks fine.
+      Nskycells++;
+    }
+  }
+  
+
+  
   if (pretend) {
     // negative simple so the default is true
@@ -1385,4 +1451,17 @@
 	  return false;
 	}
+      }
+
+      // Do exposure level exclusion here.
+      bool excludeExp = psMetadataLookupBool(&mdok, row, "excludeExp");
+      if (!mdok) {
+	psError(PXTOOLS_ERR_PROG, false, "excludeExp not found");
+	if (!psDBRollback(config->dbh)) {
+	  psError(PS_ERR_UNKNOWN, false, "database error");
+	}
+	return false;
+      }
+      if (excludeExp) { // The pre-scan determined that no diff should be made for this exposure.
+	continue;
       }
       
@@ -1441,4 +1520,15 @@
     
     if (exp_id == last_exp_id) {
+      bool exclude = psMetadataLookupBool(&mdok, row, "exclude");
+      if (!mdok) {
+	psError(PXTOOLS_ERR_PROG, false, "exclude not found");
+	if (!psDBRollback(config->dbh)) {
+	  psError(PS_ERR_UNKNOWN, false, "database error");
+	}
+	return false;
+      }
+      if (exclude) { // skip this skycell, as we probably don't have a diff.
+	continue;
+      }
       psString skycell_id = psMetadataLookupStr(&mdok, row, "skycell_id");
       if (!mdok) {
@@ -1524,6 +1614,6 @@
 }  
 
-#if (0)
-static bool definewarpstackMode(pxConfig *config)
+
+static bool definewarpstackOldMethodMode(pxConfig *config)
 {
     PS_ASSERT_PTR_NON_NULL(config, false);
@@ -1806,4 +1896,6 @@
         }
 
+	// CZW force available off.  If we're using this very-expensive mode, we need to get the one thing it does correctly.
+	available = false;;
         if (!available && (num != skycell_count)) {
             psTrace("difftool", PS_LOG_INFO, "%" PRId64 " skyfiles with stack found for warp_id %" PRId64
@@ -1913,5 +2005,5 @@
     return true;
 }
-#endif
+
 
 static bool definewarpwarpMode(pxConfig *config)
