Index: /trunk/ippToPsps/src/Batch.c
===================================================================
--- /trunk/ippToPsps/src/Batch.c	(revision 31014)
+++ /trunk/ippToPsps/src/Batch.c	(revision 31015)
@@ -87,5 +87,7 @@
     if (this->dvoConfig != NULL) dvoConfigFree(this->dvoConfig);
 
+    // destroy objects
     this->config->destroy(this->config);
+    this->initData->destroy(this->initData);
 
     pmConfigDone();
@@ -210,6 +212,5 @@
     }
 
-
-
+    // check we have some input paths
     if (haveFitsInPath && !readInputFilePaths(this)) {
 
@@ -218,5 +219,14 @@
     }
 
-    // create a config object
+    // create an InitData object and get survey ID
+    this->initData = new_InitData(configsBaseDir);
+    if (strlen(this->surveyType) > 0 && 
+            !this->initData->getSurveyId(this->initData, this->surveyType, &this->surveyID)) {
+
+        this->exitCode = PS_EXIT_CONFIG_ERROR;
+        return false;
+    }
+
+    // create a Config object
     strcat(configsBaseDir, configsDir);
     this->config = new_Config(configsBaseDir);
@@ -227,12 +237,6 @@
     }
 
-    // get survey ID using config object
-    if (strlen(this->surveyType) > 0 && !this->config->getSurveyId(this->config, this->surveyType, &this->surveyID)) {
-
-        this->exitCode = PS_EXIT_CONFIG_ERROR;
-        return false;
-    }
     // create full FITS out path
-    sprintf (fitsOutPath, "%s/%s", fitsOutPath, fitsOutFile);
+    sprintf(fitsOutPath, "%s/%s", fitsOutPath, fitsOutFile);
 
     // create an output FITS file
@@ -321,8 +325,5 @@
     // set up function pointers
     this->parseArguments = parseArguments;
-    //this->init = init;
     this->print = print;
-    this->destroy = destroy;
-
     this->gotResultsPath = gotResultsPath;
     this->gotFitsInPath = gotFitsInPath;
@@ -330,4 +331,5 @@
     this->gotConfig = gotConfig;
     this->gotSurveyType = gotSurveyType;
+    this->destroy = destroy;
 
     assert(this);
Index: /trunk/ippToPsps/src/Batch.h
===================================================================
--- /trunk/ippToPsps/src/Batch.h	(revision 31014)
+++ /trunk/ippToPsps/src/Batch.h	(revision 31015)
@@ -12,11 +12,13 @@
 #define IPPTOPSPS_BATCH_H
 
-#include <psmodules.h>
-#include <dvo_util.h>
-#include "Config.h"
 #include <libxml/parser.h>
 #include <libxml/tree.h>
 
+#include <psmodules.h>
+#include <dvo_util.h>
+
+#include "Config.h"
 #include "Fits.h"
+#include "InitData.h"
 
 /**
@@ -42,5 +44,6 @@
     pmConfig* pmconfig;         // pmConfig
     dvoConfig* dvoConfig;       // dvo database
-    Config* config;    // config structure
+    Config* config;             // Config object
+    InitData* initData;         // InitData object
     char todaysDate[20];        // today's date
     int exitCode;               // ps exit code
Index: /trunk/ippToPsps/src/Config.c
===================================================================
--- /trunk/ippToPsps/src/Config.c	(revision 31014)
+++ /trunk/ippToPsps/src/Config.c	(revision 31015)
@@ -15,5 +15,5 @@
 
 /**
-   Gets PS type from string
+   Gets PS type from string TODO FITS types? should be in Fits class
    */
 static int ippToPsps_GetDataType(char *typename) {
@@ -199,5 +199,4 @@
             default:
                 break;
-
         }
     }
@@ -230,39 +229,4 @@
 }
 
-/**
-  Searches through this table and finds attribute value for a provided key
-  */
-static bool getRowAttribute(Config* this, xmlNode* tableNode, 
-        const char* keyName, const char* keyValue, 
-        const char* attName, char* attValue) {
-
-    xmlNode* node = NULL;
-
-    char buffer[100];
-
-    // loop round all available rows for this table
-    for (node = tableNode->children; node; node = node->next) {
-        if (node->type == XML_ELEMENT_NODE) {
-            //psLogMsg("ippToPsps", PS_LOG_INFO, "Node name '%s'",  (const char*)node->name );
-
-            if (strcmp((const char*)node->name, "row")==0) {
-                //psLogMsg("ippToPsps", PS_LOG_INFO, " Looking for key '%s'",  keyName );
-
-                if (!getAttribute(node, keyName, buffer)) continue;
-                //psLogMsg("ippToPsps", PS_LOG_INFO, "Found key '%s' value '%s'",  keyName, buffer );
-
-                if (strcmp(buffer, keyValue) != 0) continue;
-                getAttribute(node, attName, attValue);
-                //printf("FOUND %s %s %s %s \n", keyName, buffer, attName, attValue );
-                return true;
-
-            }
-        }
-    }
-
-    psLogMsg("ippToPsps", PS_LOG_INFO, "Could not find value for '%s' for '%s' with value '%s'", attName, keyName, keyValue );
-    return false;
-}
-
 /*
    opens an XML file and returns the document
@@ -283,90 +247,4 @@
     xmlCleanupParser();
 
-    return true;
-}
-
-/**
-  Gets a value from the 'init' data 
-  */
-static bool getInitValue(
-        Config* this, 
-        const char* tableName,
-        const char* keyName, const char* keyValue,
-        const char* attName, char* attValue) {
-
-    bool ret = true;
-
-    psString path = NULL;
-    psStringAppend(&path, "%s/../init/data.xml", this->configsPath); // TODO nasty
-
-    xmlDoc* doc = openXmlFile(path);
-
-    if (doc == NULL) {
-        psFree(path);
-        return false;
-    }
-    psFree(path);
-
-    xmlNode* rootElement = xmlDocGetRootElement(doc);
-
-    if (strcmp((const char*)rootElement->name, "tabledata")!=0) {
-        psError(PS_ERR_IO, false, "Root node of XML is not 'tabledata', as it should be");
-        return false;
-    }
-
-    xmlNode* node = NULL;
-    char tempStr[100];
-
-    // loop round all available tables
-    for (node = rootElement->children; node; node = node->next) {
-        if (node->type == XML_ELEMENT_NODE) {
-
-            if (strcmp((const char*)node->name, "table")!=0) continue;
-            if (!getAttribute(node, "name", tempStr)) continue;
-            if (strcmp(tempStr, tableName)!=0) continue;
-
-            ret = getRowAttribute(this, node, keyName, keyValue, attName, attValue);
-            break;
-        }
-
-    }
-
-    closeXmlFile(doc);
-
-    return ret;
-}
-
-/*
-   Gets survey ID from survey name
-   */
-static bool getSurveyId(Config* this, const char* surveyType, int8_t* surveyId) {
-
-    char buffer[10];
-    if (!getInitValue(this, "Survey", "name", surveyType, "surveyID", buffer)) {
-
-        *surveyId = -1;
-        return false;
-    }
-
-    *surveyId = atoi(buffer);
-    return true;
-}
-
-/*
-   Gets filter ID from filter type
-   */
-static bool getFilterId(Config* this, const char* filterType, int8_t* filterId) {
-
-    char tmp[2];
-    strncpy(tmp,filterType,1);
-    tmp[1] = '\0';
-    char buffer[10];
-    if (!getInitValue(this, "Filter", "filterType", tmp, "filterID", buffer)) {
-
-        *filterId = -1;
-        return false;
-    }
-
-    *filterId = atoi(buffer);
     return true;
 }
@@ -859,14 +737,13 @@
 static void destroy(Config* this) {
 
-    if (this != NULL ) {
-
-        // TODO check logic here
-        for (int i=0;i<this->numOfTables;i++)
-            free(this->tables[i].columns);
-
-        free(this->tables);
-        psFree(this->configsPath);
-        free(this);
-    }
+    if (this == NULL) return;
+
+    // TODO check logic here
+    for (int i=0;i<this->numOfTables;i++)
+        free(this->tables[i].columns);
+
+    free(this->tables);
+    psFree(this->configsPath);
+    free(this);
 }
 
@@ -882,6 +759,4 @@
 
     // method pointers
-    this->getFilterId = getFilterId;
-    this->getSurveyId = getSurveyId;
     this->createAndPopulateTable = createAndPopulateTable;
     this->populateFromFile = populateFromFile;
Index: /trunk/ippToPsps/src/Config.h
===================================================================
--- /trunk/ippToPsps/src/Config.h	(revision 31014)
+++ /trunk/ippToPsps/src/Config.h	(revision 31015)
@@ -51,6 +51,4 @@
 
     // methods
-    bool (*getFilterId)();
-    bool (*getSurveyId)();
     bool (*createAndPopulateTable)();
     bool (*populateFromFile)();
Index: /trunk/ippToPsps/src/DetectionBatch.c
===================================================================
--- /trunk/ippToPsps/src/DetectionBatch.c	(revision 31014)
+++ /trunk/ippToPsps/src/DetectionBatch.c	(revision 31015)
@@ -63,5 +63,5 @@
     // FrameMeta values
     int8_t filterID = -1;
-    if (!this->base.config->getFilterId(this->base.config, filterType, &filterID)) {
+    if (!this->base.initData->getFilterId(this->base.initData, filterType, &filterID)) {
     
         this->base.exitCode = PS_EXIT_DATA_ERROR;
Index: /trunk/ippToPsps/src/InitData.c
===================================================================
--- /trunk/ippToPsps/src/InitData.c	(revision 31015)
+++ /trunk/ippToPsps/src/InitData.c	(revision 31015)
@@ -0,0 +1,183 @@
+/** @file InitData.c
+ *
+ *  @ingroup ippToPsps
+ *
+ *  @author IfA
+ *  Copyright 2011 Institute for Astronomy, University of Hawaii
+ */
+
+#include "InitData.h"
+#include "Fits.h"
+
+
+/**
+  Gets an attribute value from XML node
+  */
+static bool getAttribute(xmlNode* node, const char* attName, char* _value) {
+
+    xmlChar* value = xmlGetProp(node, (const xmlChar*)attName);
+    if (!value) return false;
+    sprintf(_value, "%s", value);
+    xmlFree(value);
+
+    return true;
+}
+
+/**
+  Searches through this table and finds attribute value for a provided key
+  */
+static bool getRowAttribute(
+        xmlNode* tableNode,
+        const char* keyName, 
+        const char* keyValue,
+        const char* attName, 
+        char* attValue) {
+
+    xmlNode* node = NULL;
+
+    char buffer[100];
+
+    // loop round all available rows for this table
+    for (node = tableNode->children; node; node = node->next) {
+        if (node->type == XML_ELEMENT_NODE) {
+            //psLogMsg("ippToPsps", PS_LOG_INFO, "Node name '%s'",  (const char*)node->name );
+
+            if (strcmp((const char*)node->name, "row")==0) {
+                //psLogMsg("ippToPsps", PS_LOG_INFO, " Looking for key '%s'",  keyName );
+
+                if (!getAttribute(node, keyName, buffer)) continue;
+                //psLogMsg("ippToPsps", PS_LOG_INFO, "Found key '%s' value '%s'",  keyName, buffer );
+
+                if (strcmp(buffer, keyValue) != 0) continue;
+                getAttribute(node, attName, attValue);
+                //printf("FOUND %s %s %s %s \n", keyName, buffer, attName, attValue );
+                return true;
+
+            }
+        }
+    }
+
+    psError(PS_ERR_UNKNOWN, 
+            false, 
+            "* InitData: Could not find value for '%s' for '%s' with value '%s'", 
+            attName, keyName, keyValue);
+
+    return false;
+}
+
+
+/**
+  Gets a value from the 'init' data 
+  */
+static bool getInitValue(
+        InitData* this, 
+        const char* tableName,
+        const char* keyName, 
+        const char* keyValue,
+        const char* attName, 
+        char* attValue) {
+
+    bool ret = true;
+
+    xmlNode* rootElement = xmlDocGetRootElement(this->doc);
+
+    if (strcmp((const char*)rootElement->name, "tabledata")!=0) {
+        psError(PS_ERR_IO, false, "* InitData: Root node of XML is not 'tabledata', as it should be");
+        return false;
+    }
+
+    xmlNode* node = NULL;
+    char tempStr[100];
+
+    // loop round all available tables
+    for (node = rootElement->children; node; node = node->next) {
+        if (node->type == XML_ELEMENT_NODE) {
+
+            if (strcmp((const char*)node->name, "table")!=0) continue;
+            if (!getAttribute(node, "name", tempStr)) continue;
+            if (strcmp(tempStr, tableName)!=0) continue;
+
+            ret = getRowAttribute(node, keyName, keyValue, attName, attValue);
+            break;
+        }
+
+    }
+
+    return ret;
+}
+
+/*
+   Gets survey ID from survey name
+   */
+static bool getSurveyId(InitData* this, const char* surveyType, int8_t* surveyId) {
+
+    char buffer[10];
+    if (!getInitValue(this, "Survey", "name", surveyType, "surveyID", buffer)) {
+
+        *surveyId = -1;
+        return false;
+    }
+
+    *surveyId = atoi(buffer);
+    return true;
+}
+
+/*
+   Gets filter ID from filter type
+   */
+static bool getFilterId(InitData* this, const char* filterType, int8_t* filterId) {
+
+    char tmp[2];
+    strncpy(tmp,filterType,1);
+    tmp[1] = '\0';
+    char buffer[10];
+    if (!getInitValue(this, "Filter", "filterType", tmp, "filterID", buffer)) {
+
+        *filterId = -1;
+        return false;
+    }
+
+    *filterId = atoi(buffer);
+    return true;
+}
+
+/**
+  Destructor.
+  */
+static void destroy(InitData* this) {
+
+    if (this == NULL) return;
+
+    if (this->doc != NULL) {
+
+        xmlFreeDoc(this->doc);
+        xmlCleanupParser();
+    }
+
+    psLogMsg("ippToPsps", PS_LOG_INFO, "* InitData: destructor");
+
+    free(this);
+}
+
+/**
+  Constructor.
+  */
+InitData* new_InitData(const char* path) {
+
+    psLogMsg("ippToPsps", PS_LOG_INFO, "* InitData: constructor");
+
+    InitData* this = (InitData*)calloc(1, sizeof(InitData));
+
+    sprintf(this->path, "%s/init/data.xml", path);
+
+    this->doc = xmlReadFile(this->path, NULL, 0);
+    if (this->doc == NULL) psError(PS_ERR_IO, false, "* InitData: Unable to open XML file at %s", this->path);
+
+    // method pointers
+    this->getFilterId = getFilterId;
+    this->getSurveyId = getSurveyId;
+    this->destroy = destroy;
+
+    return this;
+}
+
Index: /trunk/ippToPsps/src/InitData.h
===================================================================
--- /trunk/ippToPsps/src/InitData.h	(revision 31015)
+++ /trunk/ippToPsps/src/InitData.h	(revision 31015)
@@ -0,0 +1,43 @@
+/** @file InitData.h
+ *
+ *  @brief ippToPsps
+ *
+ *  @ingroup ippToPsps
+ *
+ *  @author IfA
+ *  Copyright 2011 Institute for Astronomy, University of Hawaii
+ */
+
+#ifndef IPPTOPSPS_INITDATA_H
+#define IPPTOPSPS_INITDATA_H
+
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+
+#include <psmodules.h>
+
+/**
+
+  Class encapsulating the initialization data
+
+*/
+typedef struct InitData {
+
+    // fields
+    char path[1000];
+    xmlDoc* doc;
+
+    // methods
+    bool (*getFilterId)();
+    bool (*getSurveyId)();
+
+    // destructor
+    void (*destroy)();
+
+} InitData; 
+
+// constructor
+InitData* new_InitData(const char* path);
+
+#endif // IPPTOPSPS_INITDATA_H
+
Index: /trunk/ippToPsps/src/Makefile.am
===================================================================
--- /trunk/ippToPsps/src/Makefile.am	(revision 31014)
+++ /trunk/ippToPsps/src/Makefile.am	(revision 31015)
@@ -32,4 +32,5 @@
 	Version.c \
 	Fits.c \
+	InitData.c \
 	Config.c
 
@@ -42,4 +43,5 @@
 	Version.c \
 	Fits.c \
+	InitData.c \
 	Config.c
 
@@ -52,4 +54,5 @@
 	Version.c \
 	Fits.c \
+	InitData.c \
 	Config.c
 
Index: /trunk/ippToPsps/src/StackBatch.c
===================================================================
--- /trunk/ippToPsps/src/StackBatch.c	(revision 31014)
+++ /trunk/ippToPsps/src/StackBatch.c	(revision 31015)
@@ -323,5 +323,5 @@
 
     int8_t filterID = -1;
-    if (!this->base.config->getFilterId(this->base.config, filterType, &filterID)) {
+    if (!this->base.initData->getFilterId(this->base.initData, filterType, &filterID)) {
 
         //        this->base.exitCode = PS_EXIT_DATA_ERROR;
