Index: /tags/ipp-20100823/ippconfig/recipes/filerules-mef.mdc
===================================================================
--- /tags/ipp-20100823/ippconfig/recipes/filerules-mef.mdc	(revision 29383)
+++ /tags/ipp-20100823/ippconfig/recipes/filerules-mef.mdc	(revision 29384)
@@ -295,4 +295,5 @@
                                                                                      
 PPSTAMP.OUTPUT          OUTPUT {OUTPUT}.fits                     IMAGE     COMP_IMG   FPA        TRUE      NONE
+PPSTAMP.OUTPUT.DIFF     OUTPUT {OUTPUT}.fits                     IMAGE     COMP_SUB   FPA        TRUE      NONE
 PPSTAMP.OUTPUT.MASK     OUTPUT {OUTPUT}.mk.fits                  MASK      COMP_MASK  FPA        TRUE      NONE
 PPSTAMP.OUTPUT.VARIANCE OUTPUT {OUTPUT}.wt.fits                  VARIANCE  COMP_WT    FPA        TRUE      NONE
Index: /tags/ipp-20100823/ippconfig/recipes/filerules-simple.mdc
===================================================================
--- /tags/ipp-20100823/ippconfig/recipes/filerules-simple.mdc	(revision 29383)
+++ /tags/ipp-20100823/ippconfig/recipes/filerules-simple.mdc	(revision 29384)
@@ -261,4 +261,5 @@
                                              
 PPSTAMP.OUTPUT               OUTPUT {OUTPUT}.fits                 IMAGE           COMP_IMG   FPA        TRUE      NONE
+PPSTAMP.OUTPUT.DIFF          OUTPUT {OUTPUT}.fits                 IMAGE           COMP_SUB   FPA        TRUE      NONE
 PPSTAMP.OUTPUT.MASK          OUTPUT {OUTPUT}.mk.fits              MASK            COMP_MASK  FPA        TRUE      NONE
 PPSTAMP.OUTPUT.VARIANCE      OUTPUT {OUTPUT}.wt.fits              VARIANCE        COMP_WT    FPA        TRUE      NONE
Index: /tags/ipp-20100823/ippconfig/recipes/filerules-split.mdc
===================================================================
--- /tags/ipp-20100823/ippconfig/recipes/filerules-split.mdc	(revision 29383)
+++ /tags/ipp-20100823/ippconfig/recipes/filerules-split.mdc	(revision 29384)
@@ -280,4 +280,5 @@
 
 PPSTAMP.OUTPUT               OUTPUT {OUTPUT}.fits                     IMAGE           COMP_IMG   FPA        TRUE      NONE
+PPSTAMP.OUTPUT.DIFF          OUTPUT {OUTPUT}.fits                     IMAGE           COMP_SUB   FPA        TRUE      NONE
 PPSTAMP.OUTPUT.MASK          OUTPUT {OUTPUT}.mk.fits                  MASK            COMP_MASK  FPA        TRUE      NONE
 PPSTAMP.OUTPUT.VARIANCE      OUTPUT {OUTPUT}.wt.fits                  VARIANCE        COMP_WT    FPA        TRUE      NONE
Index: /tags/ipp-20100823/pstamp/scripts/pstamp_job_run.pl
===================================================================
--- /tags/ipp-20100823/pstamp/scripts/pstamp_job_run.pl	(revision 29383)
+++ /tags/ipp-20100823/pstamp/scripts/pstamp_job_run.pl	(revision 29384)
@@ -118,4 +118,5 @@
     $command .= " -dbname $dbname" if $dbname;
     $command .= " -dbserver $dbserver" if $dbserver;
+    $command .= " -stage $params->{stage}" if $params->{stage};
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
         run(command => $command, verbose => $verbose);
Index: /tags/ipp-20100823/pstamp/scripts/pstamp_webrequest.pl
===================================================================
--- /tags/ipp-20100823/pstamp/scripts/pstamp_webrequest.pl	(revision 29383)
+++ /tags/ipp-20100823/pstamp/scripts/pstamp_webrequest.pl	(revision 29384)
@@ -26,12 +26,8 @@
 my $dbname;
 my $dbserver;
-my $project;
-my $job_type;
 
 GetOptions(
-    'job_type=s'    =>  \$job_type,
     'dbname=s'      =>  \$dbname,
     'dbserver=s'    =>  \$dbserver,
-#    'project=s'     => \$project,
     'verbose'       => \$verbose,
 );
@@ -42,11 +38,4 @@
     print "\n\n";
     print "Starting script $0 on $host\n\n";
-}
-
-my $listMode;
-if ($job_type and ($job_type eq 'list_uri')) {
-    $listMode=1;
-} else  {
-    $listMode=0;
 }
 
@@ -105,28 +94,4 @@
 }
 
-# ok at this point we have a request file add it to the database (unless we're in listMode)
-if ($listMode == 1 ) {
-    ###
-    ### In list mode just parse the file print the output and we're done
-    ###
-    my $command = "$pstampparse --mode list_uri --file $request_file";
-    $command .= " --dbname $dbname" if $dbname;
-    $command .= " --dbserver $dbserver" if $dbserver;
-    $command .= " --verbose" if $verbose;
-    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-        run(command => $command, verbose => $verbose);
-
-    if ($success) {
-        ### print "Matching Images:\n";
-        print @$stdout_buf;
-        exit 0;
-    } else {
-        # we send the output to STDOUT because that's where PHP finds it
-        print @$stdout_buf;
-        print @$stderr_buf;
-        exit 1;
-    }
-}
-
 # Queue the request
 my $req_id = 0;
Index: /tags/ipp-20100823/pstamp/src/ppstamp.c
===================================================================
--- /tags/ipp-20100823/pstamp/src/ppstamp.c	(revision 29383)
+++ /tags/ipp-20100823/pstamp/src/ppstamp.c	(revision 29384)
@@ -22,5 +22,5 @@
 
     // define the active I/O files
-    if (!ppstampParseCamera(config)) {
+    if (!ppstampParseCamera(config, options)) {
         psErrorStackPrint(stderr, "Unable to parse camera.");
         ppstampCleanup(config, options);
Index: /tags/ipp-20100823/pstamp/src/ppstamp.h
===================================================================
--- /tags/ipp-20100823/pstamp/src/ppstamp.h	(revision 29383)
+++ /tags/ipp-20100823/pstamp/src/ppstamp.h	(revision 29384)
@@ -18,5 +18,5 @@
 
 // Determine what type of camera, and initialise
-bool ppstampParseCamera(pmConfig *config);
+bool ppstampParseCamera(pmConfig *config, ppstampOptions *options);
 
 int ppstampMakeStamp(pmConfig *config, ppstampOptions *);
Index: /tags/ipp-20100823/pstamp/src/ppstampArguments.c
===================================================================
--- /tags/ipp-20100823/pstamp/src/ppstampArguments.c	(revision 29383)
+++ /tags/ipp-20100823/pstamp/src/ppstampArguments.c	(revision 29384)
@@ -78,4 +78,9 @@
         psArgumentRemove(argnum, &argc, argv);
     }
+    if ((argnum = psArgumentGet(argc, argv, "-stage"))) {
+        psArgumentRemove(argnum, &argc, argv);
+        options->stage = psStringCopy(argv[argnum]);
+        psArgumentRemove(argnum, &argc, argv);
+    }
 
     pmConfigFileSetsMD(config->arguments, &argc, argv, "ASTROM", "-astrom", "-astromlist");
Index: /tags/ipp-20100823/pstamp/src/ppstampMakeStamp.c
===================================================================
--- /tags/ipp-20100823/pstamp/src/ppstampMakeStamp.c	(revision 29383)
+++ /tags/ipp-20100823/pstamp/src/ppstampMakeStamp.c	(revision 29384)
@@ -233,5 +233,10 @@
     int status = false;
 
-    pmFPAfile *output = psMetadataLookupPtr(NULL, config->files, "PPSTAMP.OUTPUT");
+    pmFPAfile *output;
+    if (!options->stage || (strcmp(options->stage, "diff") != 0)) {
+        output = psMetadataLookupPtr(NULL, config->files, "PPSTAMP.OUTPUT");
+    } else {
+        output = psMetadataLookupPtr(NULL, config->files, "PPSTAMP.OUTPUT.DIFF");
+    }
     if (!output) {
         psError(PS_ERR_UNKNOWN, false, "Can't find output data\n");
Index: /tags/ipp-20100823/pstamp/src/ppstampOptions.h
===================================================================
--- /tags/ipp-20100823/pstamp/src/ppstampOptions.h	(revision 29383)
+++ /tags/ipp-20100823/pstamp/src/ppstampOptions.h	(revision 29384)
@@ -10,4 +10,5 @@
     psString    chipName;
     psString    cellName;
+    psString    stage;
     //
     // Calculated Values
Index: /tags/ipp-20100823/pstamp/src/ppstampParseCamera.c
===================================================================
--- /tags/ipp-20100823/pstamp/src/ppstampParseCamera.c	(revision 29383)
+++ /tags/ipp-20100823/pstamp/src/ppstampParseCamera.c	(revision 29384)
@@ -8,7 +8,19 @@
 
 // Set up the ppstamp output Image file
-bool setupOutput(pmConfig *config, pmFPAfile *input, bool doMask, bool doWeight)
+bool setupOutput(pmConfig *config, pmFPAfile *input, psString stage, bool doMask, bool doWeight)
 {
-    pmFPAfile *output = pmFPAfileDefineSkycell(config, NULL, "PPSTAMP.OUTPUT");
+    pmFPAfile *output;
+    
+    if (!stage || (strcmp(stage, "diff") != 0)) {
+        output = pmFPAfileDefineSkycell(config, NULL, "PPSTAMP.OUTPUT");
+    } else {
+        // need special filerule for diff stage image to allow for negative values
+        output = pmFPAfileDefineSkycell(config, NULL, "PPSTAMP.OUTPUT.DIFF");
+    }
+    if (!output) {
+        psError(PS_ERR_UNKNOWN, false, "Unable to setup output.");
+        return false;
+    }
+
     output->save = true;
 
@@ -29,5 +41,5 @@
 // something else that I'm missing?
 
-bool ppstampParseCamera(pmConfig *config)
+bool ppstampParseCamera(pmConfig *config, ppstampOptions *options)
 {
     bool status = false;
@@ -83,5 +95,5 @@
 
     // Set up the output target
-    if (!setupOutput(config, input, doMask, doWeight)) {
+    if (!setupOutput(config, input, options->stage, doMask, doWeight)) {
         psError(PS_ERR_UNKNOWN, false, "Unable to setup output.");
         return false;
