Index: trunk/ippToPsps/scripts/ippToPsps_run.pl
===================================================================
--- trunk/ippToPsps/scripts/ippToPsps_run.pl	(revision 28528)
+++ trunk/ippToPsps/scripts/ippToPsps_run.pl	(revision 28529)
@@ -10,4 +10,5 @@
 use constant DB_SOCKET => '/var/run/mysqld/mysqld.sock';
 use File::Temp qw(tempfile);
+use XML::LibXML;
 
 # globals
@@ -73,5 +74,5 @@
 
 # make a temporary file for saving results
-my ($resultsFile, $resultsFileName) = tempfile( "/tmp/ippToPsps_results.XXXX", UNLINK => !$save_temps);
+my ($resultsFile, $resultsFilePath) = tempfile( "/tmp/ippToPsps_results.XXXX", UNLINK => !$save_temps);
 
 process();
@@ -118,5 +119,4 @@
 }
 
-
 #######################################################################################
 # 
@@ -160,4 +160,5 @@
             AND chipRun.exp_id = rawExp.exp_id 
             AND camRun.dist_group = '$survey'   
+            AND rawExp.dateobs >= '2010-02-20'
             GROUP BY  rawExp.exp_id 
             ORDER BY rawExp.exp_id ASC;
@@ -457,22 +458,9 @@
 
     # read results
-    open (MYFILE, $resultsFileName);
-    my $i = 0;
-
-    # detection results
-    my $minObjId;
-    my $maxObjId;
-    my $filename;
-    if($batchType eq 'det') {
-
-        while (<MYFILE>) {
-            chomp;
-            if ($i == 0) { $filename = $_; }
-            if ($i == 1) { $minObjId = $_; }
-            if ($i == 2) { $maxObjId = $_; }
-            $i++;
-        }
-    }
-    close (MYFILE);
+    my $parser = XML::LibXML->new;
+    my $doc = $parser->parse_file($resultsFilePath);
+    my $filename = $doc->findvalue('//filename');
+    my $minObjId = $doc->findvalue('//minObjID');
+    my $maxObjId = $doc->findvalue('//maxObjID');
 
     # create XML file
@@ -794,5 +782,5 @@
     $command .= " -survey $surveyType";
     $command .= " -batch $batchType";
-    $command .= " -results $resultsFileName";
+    $command .= " -results $resultsFilePath";
 
     # run command
Index: trunk/ippToPsps/src/ippToPsps.c
===================================================================
--- trunk/ippToPsps/src/ippToPsps.c	(revision 28528)
+++ trunk/ippToPsps/src/ippToPsps.c	(revision 28529)
@@ -53,4 +53,14 @@
     }
 
+    // save XML document for results
+    if (this->resultsXmlDoc) {
+    
+        xmlSaveFormatFileEnc(this->resultsPath, this->resultsXmlDoc, "UTF-8", 1);
+
+        xmlFreeDoc(this->resultsXmlDoc);
+        xmlCleanupParser();
+        xmlMemoryDump();
+    }
+
     psFree(this->fitsInPath);
     psFree(this->resultsPath);
@@ -59,5 +69,4 @@
     psFree(this->pmconfig);
 
-    if (this->resultsFile) fclose(this->resultsFile);
 
     for(uint32_t i=0; i<this->numOfInputFiles; i++)
@@ -246,5 +255,5 @@
     this->fitsInPath = NULL;
     this->resultsPath = NULL;
-    this->resultsFile = NULL;
+    this->resultsXmlDoc = NULL;
     this->numOfInputFiles = 0;
     this->inputFiles = NULL;
@@ -304,4 +313,5 @@
     }
 
+    // create a config object
     this->config = ippToPspsConfig_Constructor(this->configsDir);
     if (this->config == NULL) {
@@ -311,18 +321,11 @@
     }
 
-    // ready results file, if necessary
+    // create XML document for results 
     if (this->resultsPath) {
 
-        this->resultsFile = fopen (this->resultsPath, "w+");
-
-        if (this->resultsFile == NULL) {
-
-            psError(PS_ERR_UNKNOWN, false, "Unable to open results file at %s", this->resultsPath);
-            // not essential to write results, so don't bail out
-        }
-        else {
-            if (fprintf(this->resultsFile, "%s\n", outputName) < 1 )     
-                psError(PS_ERR_IO, false, "Unable to write FITS output filename to'%s'\n", this->resultsPath);
-        }
+        this->resultsXmlDoc = xmlNewDoc(BAD_CAST "1.0");
+        xmlNodePtr rootNode = xmlNewNode(NULL, BAD_CAST "ippToPsps_Results");
+        xmlDocSetRootElement(this->resultsXmlDoc, rootNode);
+        xmlNewChild(rootNode, NULL, BAD_CAST "filename", BAD_CAST outputName);
     }
 
Index: trunk/ippToPsps/src/ippToPsps.h
===================================================================
--- trunk/ippToPsps/src/ippToPsps.h	(revision 28528)
+++ trunk/ippToPsps/src/ippToPsps.h	(revision 28529)
@@ -20,20 +20,20 @@
 typedef struct {
 
-    uint32_t expId;            // the exposure ID to be used
-    psString expName;          // the exposure name
-    psString surveyType;       // the survey type, eg 3PI, MD01, STS, SSS
-    uint8_t batchType;         // PSPS batch type
-    psString fitsInPath;       // path to FITS input
-    psString resultsPath;      // path to results file
-    FILE* resultsFile;         // file for results  
-    uint16_t numOfInputFiles;  // number of input files
-    char** inputFiles;         // array of input file names
-    psString fitsOutPath;      // path to FITS output
-    fitsfile *fitsOut;         // output FITS file
-    psString configsDir;       // path to IPP/PSPS mapping file
-    pmConfig* pmconfig;        // pmConfig
-    dvoConfig* dvoConfig;      // dvo database
-    IppToPspsConfig* config;   // config structure
-    int exitCode;              // ps exit code
+    uint32_t expId;             // the exposure ID to be used
+    psString expName;           // the exposure name
+    psString surveyType;        // the survey type, eg 3PI, MD01, STS, SSS
+    uint8_t batchType;          // PSPS batch type
+    psString fitsInPath;        // path to FITS input
+    psString resultsPath;       // path to results file
+    xmlDocPtr resultsXmlDoc;    // pointer to XML document for results
+    uint16_t numOfInputFiles;   // number of input files
+    char** inputFiles;          // array of input file names
+    psString fitsOutPath;       // path to FITS output
+    fitsfile *fitsOut;          // output FITS file
+    psString configsDir;        // path to IPP/PSPS mapping file
+    pmConfig* pmconfig;         // pmConfig
+    dvoConfig* dvoConfig;       // dvo database
+    IppToPspsConfig* config;    // config structure
+    int exitCode;               // ps exit code
 
     int (*run)();
Index: trunk/ippToPsps/src/ippToPspsBatchDetection.c
===================================================================
--- trunk/ippToPsps/src/ippToPspsBatchDetection.c	(revision 28528)
+++ trunk/ippToPsps/src/ippToPspsBatchDetection.c	(revision 28529)
@@ -386,12 +386,14 @@
 
     // write results
-    if (this->resultsFile) {
-
-        if (fprintf(this->resultsFile, "%ld\n", minObjID) < 1 ) 
-            psError(PS_ERR_IO, false, "Unable to write min Object ID to'%s'\n", this->resultsPath);
-        if (fprintf(this->resultsFile, "%ld\n", maxObjID) < 1 ) 
-            psError(PS_ERR_IO, false, "Unable to write max Object ID to'%s'\n", this->resultsPath);
-        if (fprintf(this->resultsFile, "%ld\n", totalDetectionsOut) < 1 ) 
-            psError(PS_ERR_IO, false, "Unable to write totalDetectionsOut to'%s'\n", this->resultsPath);
+    if (this->resultsXmlDoc) {
+
+        xmlNodePtr rootNode = xmlDocGetRootElement(this->resultsXmlDoc);
+        char tmp[100];
+        sprintf(tmp, "%ld", minObjID);
+        xmlNewChild(rootNode, NULL, BAD_CAST "minObjID", BAD_CAST tmp);
+        sprintf(tmp, "%ld", maxObjID);
+        xmlNewChild(rootNode, NULL, BAD_CAST "maxObjID", BAD_CAST tmp);
+        sprintf(tmp, "%ld", totalDetectionsOut);
+        xmlNewChild(rootNode, NULL, BAD_CAST "totalDetections", BAD_CAST tmp);
     }
 
