Index: trunk/ippToPsps/src/Batch.c
===================================================================
--- trunk/ippToPsps/src/Batch.c	(revision 30968)
+++ trunk/ippToPsps/src/Batch.c	(revision 31011)
@@ -18,4 +18,5 @@
 #include <pslib.h>
 #include <psmodules.h>
+
 #include "Batch.h"
 
@@ -62,22 +63,9 @@
         if (this->exitCode != PS_EXIT_SUCCESS) {
 
-            psError(PS_ERR_UNKNOWN, false, "Failed, so deleting %s", this->fitsOutPath);
-
-            // if process failed, we need to delete that FITS file
-            if (remove(this->fitsOutPath) == -1) {
-
-                psError(PS_ERR_UNKNOWN, false, "Unable to delete %s", this->fitsOutPath);
-            }
+            psError(PS_ERR_UNKNOWN, false, "Failed, so deleting fits file");
+            this->fitsOut->delete(this->fitsOut);
         }
-        // ...otherwise, close file
-        else {
-
-            int status = 0;
-            if (fits_close_file(this->fitsOut, &status)) {
-
-                psError(PS_ERR_IO, false, "Unable to close FITS file %s", this->fitsOutPath);
-                fits_report_error(stderr, status);
-            }
-        }
+
+        this->fitsOut->destroy(this->fitsOut);
     }
 
@@ -99,5 +87,5 @@
     if (this->dvoConfig != NULL) dvoConfigFree(this->dvoConfig);
 
-    ippToPspsConfig_Destructor(this->config);
+    this->config->destroy(this->config);
 
     pmConfigDone();
@@ -151,5 +139,5 @@
   Sets-up and reads command-line arguments
 */
-static bool parseArguments(Batch* this, int argc, char **argv) {
+static bool parseArguments(Batch* this, int argc, char **argv, char* configsDir, char* fitsOutFile) {
 
     // first deal with DVO database
@@ -178,4 +166,7 @@
     haveSurveyType = false;
 
+    char fitsOutPath[1000];
+    char configsBaseDir[1000];
+
     // decode arguments
     int32_t optind = 1;
@@ -193,5 +184,5 @@
             else if(strcmp(sw, "-output") == 0 ) {
                 optind++; if( optind > ( argc-1 ) ) break;
-                strcpy(this->fitsOutPath, argv[optind]);
+                strcpy(fitsOutPath, argv[optind]);
                 haveFitsOutPath = true;
             }
@@ -203,5 +194,5 @@
             else if(strcmp(sw, "-config") == 0 ) {
                 optind++; if( optind > ( argc-1 ) ) break;
-                strcpy(this->configsDir, argv[optind]);
+                strcpy(configsBaseDir, argv[optind]);
                 haveConfig = true;
             }
@@ -220,17 +211,4 @@
 
 
-    // setup command line arguments
-    //psMetadataAddStr(this->arguments, PS_LIST_TAIL, "-survey", 0, "Survey type", NULL);
-
-
-    // now check rest of arguments
-    //if (argc < 2 || !psArgumentParse(this->arguments, &argc, argv)) {
-
-      //  usage(this, argv[0]);
-        //this->exitCode = PS_EXIT_CONFIG_ERROR;
-        //return false;
-   // }
-
-    //this->surveyType = psMemIncrRefCounter(psMetadataLookupStr(NULL, this->arguments, "-survey"));
 
     if (haveFitsInPath && !readInputFilePaths(this)) {
@@ -240,14 +218,7 @@
     }
 
-    return true;
-}
-
-/**
-  Initialises file paths, creates FITS file etc
-  */
-bool init(Batch* this) {
-
     // create a config object
-    this->config = ippToPspsConfig_Constructor(this->configsDir);
+    strcat(configsBaseDir, configsDir);
+    this->config = new_Config(configsBaseDir);
     if (this->config == NULL) {
 
@@ -257,5 +228,5 @@
 
     // get survey ID using config object
-    if (strlen(this->surveyType) > 0 && !ippToPspsConfig_getSurveyId(this->config, this->surveyType, &this->surveyID)) {
+    if (strlen(this->surveyType) > 0 && !this->config->getSurveyId(this->config, this->surveyType, &this->surveyID)) {
 
         this->exitCode = PS_EXIT_CONFIG_ERROR;
@@ -263,15 +234,9 @@
     }
     // create full FITS out path
-    sprintf (this->fitsOutPath, "%s/%s", this->fitsOutPath, this->fitsOutFile);
+    sprintf (fitsOutPath, "%s/%s", fitsOutPath, fitsOutFile);
 
     // create an output FITS file
-    int status=0;
-    if (fits_create_file(&this->fitsOut, this->fitsOutPath, &status)) {
-        fits_report_error(stderr, status);
-        psError(PS_ERR_IO, false, "Unable to create file at: '%s'", this->fitsOutPath);
-        this->exitCode = PS_EXIT_SYS_ERROR;
-        this->fitsOut = NULL;
-        return false;
-    }
+    this->fitsOut = new_Fits(fitsOutPath);
+    if (this->fitsOut->getFilePtr(this->fitsOut) == NULL) return false;
 
     // create XML document for results 
@@ -281,5 +246,5 @@
         xmlNodePtr rootNode = xmlNewNode(NULL, BAD_CAST "ippToPsps_Results");
         xmlDocSetRootElement(this->resultsXmlDoc, rootNode);
-        xmlNewChild(rootNode, NULL, BAD_CAST "filename", BAD_CAST this->fitsOutFile);
+        xmlNewChild(rootNode, NULL, BAD_CAST "filename", BAD_CAST fitsOutFile);
     }
 
@@ -298,7 +263,4 @@
     printf("* numOfInputFiles : %d\n", this->numOfInputFiles);
     printf("* fitsInPath      : '%s'\n", this->fitsInPath);
-    printf("* fitsOutFile     : '%s'\n", this->fitsOutFile);
-    printf("* fitsOutPath     : '%s'\n", this->fitsOutPath);
-    printf("* configsDir      : '%s'\n", this->configsDir);
 }
 
@@ -359,5 +321,5 @@
     // set up function pointers
     this->parseArguments = parseArguments;
-    this->init = init;
+    //this->init = init;
     this->print = print;
     this->destroy = destroy;
