Index: trunk/ippToPsps/src/Fits.c
===================================================================
--- trunk/ippToPsps/src/Fits.c	(revision 31009)
+++ trunk/ippToPsps/src/Fits.c	(revision 31010)
@@ -19,11 +19,52 @@
     if (fits_close_file(this->file, &status)) {
 
-        psError(PS_ERR_IO, false, "Unable to close FITS file");
+        psError(PS_ERR_IO, false, "* Fits: Unable to close FITS file");
         fits_report_error(stderr, status);
     }
-
-printf("destroyed...\n");
-
-    return;
+    else 
+        psLogMsg("ippToPsps", PS_LOG_INFO, "* Fits: Closed '%s'", this->path);
+}
+
+/**
+  Gets a header key value
+  */
+static bool getHeaderKeyValue(Fits* this, int type, char* name, void* value) {
+
+    int status = 0;
+    fits_read_key(this->file, type, name, value, NULL, &status);
+
+    if (status) {
+
+        psError(PS_ERR_IO, false, "* Fits: Could not get value for header key '%s'\n", name);
+        return false;
+    }
+
+    return true;
+}
+
+/*
+   Gets the contents of a column vector
+   */
+static bool getColumnVector(
+        Fits* this,
+        int col,
+        long row,
+        int type,
+        int repeat,
+        float* vector) {
+
+    int status = 0;
+    int anynull = 0;
+
+    // remember to add 1 to row number since cfitsio is the stupidest libary ever written
+    fits_read_col(this->file, type, col, row+1, 1, repeat, NULL, vector, &anynull, &status);
+
+    if (status) {
+
+        psError(PS_ERR_IO, false, "* Fits: Failed to read vector column %d row %ld", col, row);
+        return false;
+    }
+
+    return true;
 }
 
@@ -37,10 +78,40 @@
     if (status) {
 
-        psError(PS_ERR_IO, false, "Could not get column number for '%s'\n", name);
-        return false;
-    }
-
-    return true;
-}
+        psError(PS_ERR_IO, false, "* Fits: Could not get column number for '%s'\n", name);
+        return false;
+    }
+
+    return true;
+}
+
+/*
+   Gets metadata about a column 
+   */
+bool getColumnMeta(
+        Fits* this,
+        char* name,
+        int* colNum,
+        int* type,
+        long* repeat) {
+
+    int status = 0;
+    fits_get_colnum(this->file, CASESEN, name, colNum, &status);
+    if (status) {
+
+        psError(PS_ERR_IO, false, "* Fits: Unable to read col '%s'", name);
+        return false;
+    }
+
+    status = 0;
+    fits_get_eqcoltype(this->file, *colNum, type, repeat, NULL, &status);
+    if (status) {
+
+        psError(PS_ERR_IO, false, "* Fits: Unable to read type info for '%s'", name);
+        return false;
+    }
+
+    return true;
+}
+
 
 /**
@@ -52,5 +123,5 @@
     if (fits_movnam_hdu(this->file, type, name, 0, &status)) {
 
-        psError(PS_ERR_IO, false, "Can't move to table extension named '%s'\n", name);
+        psError(PS_ERR_IO, false, "* Fits: Can't move to table extension named '%s'\n", name);
     }
 
@@ -61,5 +132,5 @@
   Moves to a certain header extension
   */
-bool moveToHeader(Fits* this, char* name) {
+static bool moveToHeader(Fits* this, char* name) {
 
     return moveToExtension(this, name, IMAGE_HDU);
@@ -69,5 +140,5 @@
   Moves to a certain binary table extension
   */
-bool moveToBinaryTable(Fits* this, char* name) {
+static bool moveToBinaryTable(Fits* this, char* name) {
 
     return moveToExtension(this, name, BINARY_TBL);
@@ -75,4 +146,50 @@
 
 /**
+  Counts the rows in the current table extension
+  */
+static bool countRows(Fits* this, long* count) {
+
+    int status = 0;
+    if (fits_get_num_rows(this->file, count, &status)) {
+
+        psError(PS_ERR_IO, false, "* Fits: Count not count rows in this table\n");
+        return false;
+    }
+
+    return true;
+}
+
+/**
+  Moves to a certain binary table extension and counts rows within
+  */
+static bool moveToBinaryTableAndCountRows(Fits* this, char* name, long* count) {
+
+    if (!moveToExtension(this, name, BINARY_TBL)) return false;
+    return countRows(this, count);
+}
+
+/**
+  Deletes this file.
+  */
+static bool delete(Fits* this) {
+
+    if (remove(this->path) == -1) {
+
+        psError(PS_ERR_UNKNOWN, false, "* Fits: Unable to delete '%s'", this->path);
+        return false;
+    }
+
+    return true;
+}
+
+/**
+  Returns the file path.
+  */
+static char* getPath(Fits* this) {
+
+    return this->path;
+}
+
+/**
   Returns the file pointer.
   */
@@ -83,28 +200,222 @@
 
 /**
-  Constructor. Returns a new Fits object.
-  */
-Fits* new_Fits(char* path) {
-
-    Fits* this = (Fits*)calloc(1, sizeof(Fits));
-
-    int status = 0;
-    if (fits_open_file(&this->file, path, READONLY, &status)) {
-
-        psError(PS_ERR_IO, false, "Unable to open FITS file here %s\n", path);
-    }
+  Deletes a bunch of rows from the current binary table
+  */
+static bool deleteRows(Fits* this, long *rowlist, long nrows) {
+
+    int status = 0;
+    fits_delete_rowlist(this->file, rowlist, nrows, &status);
+    if (status) {
+
+        psError(PS_ERR_IO, false, "* Fits: Unable to delet rows using rowlist \n");
+        return false;
+    }
+
+    return true;
+}
+
+/**
+  Reads a column from the current binary table
+  */
+static bool readColumn(
+        Fits* this, 
+        int datatype, 
+        int colnum, 
+        LONGLONG firstrow, 
+        LONGLONG firstelem,
+        LONGLONG nelements, 
+        void* coldata)  {
+
+    int anynull = 0;
+    int status = 0;
+
+    if (datatype == TBYTE) {
+
+        int8_t nullval = -99;
+        fits_read_col(this->file, datatype, colnum, firstrow, firstelem, nelements, &nullval, coldata, &anynull, &status);
+    }
+    else if (datatype == TSHORT) {
+
+        int16_t nullval = -999;
+        fits_read_col(this->file, datatype, colnum, firstrow, firstelem, nelements, &nullval, coldata, &anynull, &status);
+    }
+    else if (datatype == TLONG || datatype == TLONGLONG) {
+
+        long nullval = -999;
+        fits_read_col(this->file, datatype, colnum, firstrow, firstelem, nelements, &nullval, coldata, &anynull, &status);
+    }
+    else if (datatype == TFLOAT) {
+
+        float nullval = -999.0;
+        fits_read_col(this->file, datatype, colnum, firstrow, firstelem, nelements, &nullval, coldata, &anynull, &status);
+    }
+    else if (datatype == TDOUBLE) {
+
+        double nullval = -999.0;
+        fits_read_col(this->file, datatype, colnum, firstrow, firstelem, nelements, &nullval, coldata, &anynull, &status);
+    }
+    else if (datatype == TSTRING) {
+
+        char nullval[20];
+        strcpy(nullval, "null");
+        fits_read_col(this->file, datatype, colnum, firstrow, firstelem, nelements, &nullval, coldata, &anynull, &status);
+    }
+    else {
+
+        psError(PS_ERR_IO, false, "* Fits: Don't support datatype '%d' yet\n", datatype);
+        return false;
+    }
+
+    if (status) {
+
+        psError(PS_ERR_IO, false, "* Fits: Unable to read column data from column %d\n", colnum);
+        return false;
+
+    }
+
+    return true;
+}
+
+/**
+  Reads a column from the current binary table providing column name
+  */
+static bool readColumnUsingName(
+        Fits* this,
+        int datatype, 
+        char* colname,
+        LONGLONG firstrow, 
+        LONGLONG firstelem,
+        LONGLONG nelements, 
+        void* coldata)  {
+
+    int colnum;
+    if (!getColumnNumber(this, colname, &colnum)) return false;
+
+    return  readColumn(this, datatype, colnum, firstrow, firstelem, nelements, coldata);
+}
+
+/**
+  Writes a column to the current binary table
+  */
+static bool writeColumn(
+        Fits* this, 
+        int datatype, 
+        int colnum, 
+        LONGLONG firstrow,
+        LONGLONG firstelem, 
+        LONGLONG nelements, 
+        void* coldata) { 
+
+    int status = 0;
+    fits_write_col(this->file, datatype, colnum, firstrow, firstelem, nelements, coldata, &status);
+    if (status) {
+
+        psError(PS_ERR_IO, false, "* Fits: Unable to write column data for column %d\n", colnum);
+        return false;
+
+    }
+
+    return true;
+}
+
+/**
+  Creates a new binary table
+  */
+static bool createBinaryTable(
+        Fits* this, 
+        LONGLONG nRows, 
+        int nCols, 
+        char *names[],
+        char *types[], 
+        char *name) {
+
+    int status = 0;
+    fits_create_tbl(this->file, BINARY_TBL, nRows, nCols, names, types, NULL, name, &status);
+
+    if (status) {
+
+        psError(PS_ERR_IO,"* Fits: Unable to create table: '%s'", name);
+        return false;
+    }
+
+
+    return true;
+}
+
+/**
+  Initilization common to all constructors
+  */
+static void init(Fits* this) {
 
     // method pointers
     this->getFilePtr = getFilePtr;
+    this->getPath = getPath;
+    this->countRows = countRows;
+    this->getColumnMeta = getColumnMeta;
     this->getColumnNumber = getColumnNumber;
+    this->getColumnVector = getColumnVector;
+    this->readColumn = readColumn;
+    this->readColumnUsingName = readColumnUsingName;
+    this->getHeaderKeyValue = getHeaderKeyValue;
     this->moveToExtension = moveToExtension;
     this->moveToHeader = moveToHeader;
     this->moveToBinaryTable = moveToBinaryTable;
+    this->moveToBinaryTableAndCountRows = moveToBinaryTableAndCountRows;
+    this->deleteRows = deleteRows;
+    this->createBinaryTable = createBinaryTable;
+    this->writeColumn = writeColumn;
+    this->delete = delete;
     this->destroy = destroy;
 
     assert(this);
 
+}
+
+/**
+  Constructor.
+
+  Returns a new Fits object representing an existing FITS file.
+
+*/
+Fits* existing_Fits(char* path) {
+
+    Fits* this = (Fits*)calloc(1, sizeof(Fits));
+
+    int status = 0;
+    strcpy(this->path, path);
+
+    if (fits_open_file(&this->file, this->path, READONLY, &status)) {
+
+        psError(PS_ERR_IO, false, "* Fits: Unable to open FITS file here %s\n", path);
+        this->file = NULL;
+    }
+
+    init(this);
+
     return this;
 }
 
-
+/**
+  Constructor. 
+
+  Returns a new Fits object representing a new FITS file.
+  */
+Fits* new_Fits(char* path) {
+
+    Fits* this = (Fits*)calloc(1, sizeof(Fits));
+
+    int status = 0;
+    strcpy(this->path, path);
+
+    if (fits_create_file(&this->file, this->path, &status)) {
+
+        psError(PS_ERR_IO, false, "* Fits: Unable to create file here '%s'", path);
+        this->file = NULL;
+    }
+
+    init(this);
+
+    return this;
+}
+
+
Index: trunk/ippToPsps/src/Fits.h
===================================================================
--- trunk/ippToPsps/src/Fits.h	(revision 31009)
+++ trunk/ippToPsps/src/Fits.h	(revision 31010)
@@ -15,4 +15,5 @@
 
 /**
+
   Class that encapsulates a FITS file, making an OO interface to the dreaded cfitsio
 
@@ -21,16 +22,35 @@
 
     // fields
-    fitsfile* file;
+    fitsfile* file;             // cfitsio file pointer
+    char path[1000];            // FITS path
 
-    // methods
+    // accessor methods
     fitsfile* (*getFilePtr)();
+    char* (*getPath)();
+    bool (*countRows)();
+    bool (*getColumnMeta)();
     bool (*getColumnNumber)();
+    bool (*getColumnVector)();
+    bool (*readColumn)();
+    bool (*readColumnUsingName)();
+    bool (*getHeaderKeyValue)();
+
+    // mutators
     bool (*moveToExtension)();
     bool (*moveToHeader)();
     bool (*moveToBinaryTable)();
+    bool (*moveToBinaryTableAndCountRows)();
+    bool (*createBinaryTable)();
+    bool (*writeColumn)();
+    bool (*deleteRows)();
+    bool (*delete)();
+
+    // destructor
     void (*destroy)();
 
 } Fits;
 
+// constructors
+Fits* existing_Fits(char* path);
 Fits* new_Fits(char* path);
 
Index: trunk/ippToPsps/src/Makefile.am
===================================================================
--- trunk/ippToPsps/src/Makefile.am	(revision 31009)
+++ trunk/ippToPsps/src/Makefile.am	(revision 31010)
@@ -31,4 +31,5 @@
         Batch.c \
 	Version.c \
+	Fits.c \
 	Config.c
 
@@ -40,4 +41,5 @@
         Batch.c \
 	Version.c \
+	Fits.c \
 	Config.c
 
@@ -49,4 +51,5 @@
         Batch.c \
 	Version.c \
+	Fits.c \
 	Config.c
 
