Index: trunk/Mars/mcore/zofits.h
===================================================================
--- trunk/Mars/mcore/zofits.h	(revision 17221)
+++ trunk/Mars/mcore/zofits.h	(revision 17225)
@@ -7,14 +7,11 @@
 
 #include "ofits.h"
+#include "zfits.h"
 #include "Queue.h"
 #include "MemoryManager.h"
 
-#include "FITS.h"
-
 #ifdef USE_BOOST_THREADS
 #include <boost/thread.hpp>
 #endif
-
-using namespace FITS;
 
 #ifndef __MARS__
@@ -24,4 +21,5 @@
 using namespace std;
 #endif
+
 
 class zofits : public ofits
@@ -61,5 +59,5 @@
         {
             InitMemberVariables(numTiles, rowPerTile, maxUsableMem);
-            SetNumWorkingThreads(fNumQueues);
+            SetNumThreads(fgNumQueues);
         }
 
@@ -72,5 +70,5 @@
         {
             InitMemberVariables(numTiles, rowPerTile, maxUsableMem);
-            SetNumWorkingThreads(fNumQueues);
+            SetNumThreads(fgNumQueues);
         }
 
@@ -206,5 +204,5 @@
         }
 
-        bool WriteRow(const void* ptr, size_t cnt, bool byte_swap=true)
+        bool WriteRow(const void* ptr, size_t cnt, bool = true)
         {
             if (cnt != fRealRowWidth)
@@ -497,14 +495,8 @@
         bool AddColumn(uint32_t cnt, char typechar, const string& name, const string& unit, const string& comment="", bool addHeaderKeys=true)
         {
-            BlockHeaderWriter head;
-            return AddColumn(cnt, typechar, name, unit, head, comment, addHeaderKeys);
-        }
-
-        bool AddColumn(const string& compressionScheme, uint32_t cnt, char typechar, const string& name, const string& unit,  const string& comment="", bool addHeaderKeys=true)
-        {
-            BlockHeaderWriter head(compressionScheme);
-            return AddColumn(cnt, typechar, name, unit, head, comment, addHeaderKeys);
-        }
-        bool AddColumn(uint32_t cnt, char typechar, const string& name, const string& unit, const BlockHeaderWriter& header, const string& comment="", bool addHeaderKeys=true)
+            return AddColumn(kFactRaw, cnt, typechar, name, unit, comment, addHeaderKeys);
+        }
+
+        bool AddColumn(const FITS::Compression &comp, uint32_t cnt, char typechar, const string& name, const string& unit, const string& comment="", bool addHeaderKeys=true)
         {
             if (!ofits::AddColumn(1, 'Q', name, unit, comment, addHeaderKeys))
@@ -522,5 +514,5 @@
             fRealRowWidth += size*cnt;
 
-            fRealColumns.emplace_back(CompressedColumn(col, header));
+            fRealColumns.emplace_back(CompressedColumn(col, comp));
 
             ostringstream strKey, strVal, strCom;
@@ -541,26 +533,9 @@
         }
 
-        bool AddColumnShort(const string& compressionScheme, uint32_t cnt, const string &name, const string &unit="", const string &comment="")
-        { return AddColumn(compressionScheme, cnt, 'I', name, unit, comment); }
-        bool AddColumnInt(const string& compressionScheme, uint32_t cnt, const string &name, const string &unit="", const string &comment="")
-        { return AddColumn(compressionScheme, cnt, 'J', name, unit, comment); }
-        bool AddColumnLong(const string& compressionScheme, uint32_t cnt, const string &name, const string &unit="", const string &comment="")
-        { return AddColumn(compressionScheme, cnt, 'K', name, unit, comment); }
-        bool AddColumnFloat(const string& compressionScheme, uint32_t cnt, const string &name, const string &unit="", const string &comment="")
-        { return AddColumn(compressionScheme, cnt, 'E', name, unit, comment); }
-        bool AddColumnDouble(const string& compressionScheme, uint32_t cnt, const string &name, const string &unit="", const string &comment="")
-        { return AddColumn(compressionScheme, cnt, 'D', name, unit, comment); }
-        bool AddColumnChar(const string& compressionScheme, uint32_t cnt, const string &name, const string &unit="", const string &comment="")
-        { return AddColumn(compressionScheme, cnt, 'A', name, unit, comment); }
-        bool AddColumnByte(const string& compressionScheme, uint32_t cnt, const string &name, const string &unit="", const string &comment="")
-        { return AddColumn(compressionScheme, cnt, 'B', name, unit, comment); }
-        bool AddColumnBool(const string& compressionScheme, uint32_t cnt, const string &name, const string &unit="", const string &comment="")
-        { return AddColumn(compressionScheme, cnt, 'L', name, unit, comment); }
-
-        static void SetNumThreads(int32_t num) { fNumQueues = num;}
-        static int32_t GetNumThreads() { return fNumQueues;}
-    protected:
-
-        bool SetNumWorkingThreads(int32_t num)
+        static void SetDefaultNumThreads(int32_t num) { fgNumQueues = num;}
+        static int32_t GetDefaultNumThreads() { return fgNumQueues;}
+
+        int32_t GetNumThreads() { return fNumQueues;}
+        bool SetNumThreads(int32_t num)
         {
             if (is_open())
@@ -619,4 +594,6 @@
             return true;
         }
+
+protected:
 
         bool reallocateBuffers()
@@ -738,5 +715,5 @@
                 if (fRealColumns[i].col.num == 0) continue;
 
-                BlockHeaderWriter& head = fRealColumns[i].block_head;
+                Compression& head = fRealColumns[i].block_head;
 
                 //set the default byte telling if uncompressed the compressed Flag
@@ -744,9 +721,9 @@
 
                 //skip header data
-                compressedOffset += head.SizeOnDisk();
-
-                for (uint32_t j=0;j<head.NumProcs();j++)//sequence.size(); j++)
+                compressedOffset += head.getSizeOnDisk();
+
+                for (uint32_t j=0;j<head.getNumProcs();j++)//sequence.size(); j++)
                 {
-                    switch (head.Proc(j))
+                    switch (head.getProc(j))
                     {
                         case kFactRaw:
@@ -757,37 +734,30 @@
                         break;
                         case kFactHuffman16:
-                            if (head.Ordering() == kOrderByCol)
-                                compressedOffset += compressHUFFMAN(dest + compressedOffset, src  + offset, thisRoundNumRows, fRealColumns[i].col.size, fRealColumns[i].col.num);
+                            if (head.getOrdering() == kOrderByCol)
+                                compressedOffset += compressHUFFMAN16(dest + compressedOffset, src  + offset, thisRoundNumRows, fRealColumns[i].col.size, fRealColumns[i].col.num);
                             else
-                                compressedOffset += compressHUFFMAN(dest + compressedOffset, src  + offset, fRealColumns[i].col.num, fRealColumns[i].col.size, thisRoundNumRows);
+                                compressedOffset += compressHUFFMAN16(dest + compressedOffset, src  + offset, fRealColumns[i].col.num, fRealColumns[i].col.size, thisRoundNumRows);
                         break;
-                        default:
-                        {
-                            ostringstream str;
-                            str << "Unkown compression sequence entry: " << head.Proc(j);
-#ifdef __EXCEPTIONS
-                            throw runtime_error(str.str());
-#else
-                            gLog << ___err___ << "ERROR - " << str.str();
-                            return 0;
-#endif
-                        }
                     }
                 }
 
                //check if compressed size is larger than uncompressed
-                if ((head.Proc(0) != kFactRaw) && (compressedOffset - previousOffset > fRealColumns[i].col.size*fRealColumns[i].col.num*thisRoundNumRows+head.SizeOnDisk()))// && two)
+                if ((head.getProc(0) != kFactRaw) && (compressedOffset - previousOffset > fRealColumns[i].col.size*fRealColumns[i].col.num*thisRoundNumRows+head.getSizeOnDisk()))// && two)
                 {//if so set flag and redo it uncompressed
                     cout << "Redoing uncompressed ! " << endl;
                     //de-smooth !
-                    if (head.Proc(0) == kFactSmoothing)
+                    if (head.getProc(0) == kFactSmoothing)
                         UnApplySMOOTHING(src+offset, fRealColumns[i].col.num*thisRoundNumRows);
 
-                    BlockHeaderWriter he;
-                    compressedOffset = previousOffset + he.SizeOnDisk();
+                    Compression he;
+
+                    compressedOffset = previousOffset + he.getSizeOnDisk();
                     compressedOffset += compressUNCOMPRESSED(dest + compressedOffset, src + offset, thisRoundNumRows*fRealColumns[i].col.size*fRealColumns[i].col.num);
+
                     he.SetBlockSize(compressedOffset - previousOffset);
-                    he.Write(dest+previousOffset);
+                    he.Memcpy(dest+previousOffset);
+
                     offset += thisRoundNumRows*fRealColumns[i].col.size*fRealColumns[i].col.num;
+
                     fCatalog[currentCatalogRow][i].first = compressedOffset - fCatalog[currentCatalogRow][i].second;
                     continue;
@@ -795,5 +765,5 @@
 
                 head.SetBlockSize(compressedOffset - previousOffset);
-                head.Write(dest + previousOffset);
+                head.Memcpy(dest + previousOffset);
 
                 offset += thisRoundNumRows*fRealColumns[i].col.size*fRealColumns[i].col.num;
@@ -814,5 +784,5 @@
             for (uint32_t i=0;i<fRealColumns.size();i++)
             {
-                switch (fRealColumns[i].block_head.Ordering())
+                switch (fRealColumns[i].block_head.getOrdering())
                 {
                     case kOrderByRow:
@@ -832,15 +802,4 @@
                             }
                     break;
-                    default:
-                    {
-                            ostringstream str;
-                            str << "Unkown column ordering: " << fRealColumns[i].block_head.Ordering();
-#ifdef __EXCEPTIONS
-                            throw runtime_error(str.str());
-#else
-                            gLog << ___err___ << "ERROR - " << str.str();
-                            return;
-#endif
-                    }
                 };
             }
@@ -854,5 +813,5 @@
         }
 
-        uint32_t compressHUFFMAN(char* dest, const char* src, uint32_t numRows, uint32_t sizeOfElems, uint32_t numRowElems)
+        uint32_t compressHUFFMAN16(char* dest, const char* src, uint32_t numRows, uint32_t sizeOfElems, uint32_t numRowElems)
         {
             string huffmanOutput;
@@ -865,7 +824,7 @@
             {
 #ifdef __EXCEPTIONS
-                throw runtime_error("Fatal ERROR: HUFMANN can only encode short or longer types");
+                throw runtime_error("HUFMANN16 can only encode columns with 16-bit or longer types");
 #else
-                gLog << ___err___ << "ERROR - Fatal ERROR: HUFMANN can only encode short or longer types";
+                gLog << ___err___ << "ERROR - HUFMANN16 can only encode columns with 16-bit or longer types";
                 return 0;
 #endif
@@ -920,5 +879,6 @@
 
         //thread related stuff
-        static int32_t          fNumQueues;    ///< The number of threads that will be used to compress
+        static int32_t          fgNumQueues;    ///< The number of threads that will be used to compress
+        int32_t          fNumQueues;    ///< The number of threads that will be used to compress
 
         int32_t           fLatestWrittenTile;
@@ -949,9 +909,9 @@
         struct CompressedColumn
         {
-            CompressedColumn(const Table::Column& c, const BlockHeaderWriter& h) : col(c),
-                                                                                   block_head(h)
+            CompressedColumn(const Table::Column& c, const Compression& h) : col(c),
+                block_head(h)
             {}
             Table::Column     col;
-            BlockHeaderWriter block_head;
+            Compression block_head;
         };
         vector<CompressedColumn> fRealColumns;
@@ -959,36 +919,7 @@
 };
 
-int32_t zofits::fNumQueues = 0;
+int32_t zofits::fgNumQueues = 0;
 
 #ifndef __MARS__
 }; //namespace std
 #endif
-
-#ifdef crappy_example_usage
-zofits zofitsfile(123456, 100);
-zofitsfile.SetNumWorkingThreads(numThreads);
-zofitsfile.open((fileNameOut).c_str());
-std::zofits::BlockHeader zoheader(0, kOrderByRow, 2);
-vector<uint16_t> smoothmanProcessings(2);
-smoothmanProcessings[0] = kFactSmoothing;
-smoothmanProcessings[1] = kFactHuffman16;
-
-zofitsfile.AddColumn(sortedColumns[i].num,
-                     sortedColumns[i].type,
-                     colName,
-                     "");
-
-zofitsfile.AddColumn(sortedColumns[i].num,
-                     sortedColumns[i].type,
-                     colName,
-                     "",
-                     zoheader,
-                     smoothmanProcessings);
-
-zofitsfile.SetStr("ZCHKSUM", i->second.value, i->second.comment);
-zofitsfile.SetDrsCalibration(drsCalibFloat);
-zofitsfile.WriteTableHeader(tableName.c_str());
-zofitsfile.WriteRow(buffer, rowWidth);
-zofitsfile.close();
-
-#endif
