Index: trunk/Mars/mcore/zofits.h
===================================================================
--- trunk/Mars/mcore/zofits.h	(revision 17263)
+++ trunk/Mars/mcore/zofits.h	(revision 17264)
@@ -10,5 +10,5 @@
 
 #include "ofits.h"
-#include "zfits.h"
+#include "huffman.h"
 #include "Queue.h"
 #include "MemoryManager.h"
@@ -16,9 +16,4 @@
 #ifdef USE_BOOST_THREADS
 #include <boost/thread.hpp>
-#endif
-
-#ifndef __MARS__
-namespace std
-{
 #endif
 
@@ -39,11 +34,11 @@
         struct CatalogEntry
         {
-            CatalogEntry(int64_t f=0, int64_t s=0) : first(f), second(s) {};
+            CatalogEntry(int64_t f=0, int64_t s=0) : first(f), second(s) { }
             int64_t first;   ///< Size of this column in the tile
             int64_t second;  ///< offset of this column in the tile, from the start of the heap area
         } __attribute__((__packed__));
 
-        typedef vector<CatalogEntry> CatalogRow;
-        typedef list<CatalogRow>     CatalogType;
+        typedef std::vector<CatalogEntry> CatalogRow;
+        typedef std::list<CatalogRow>     CatalogType;
 
 
@@ -59,7 +54,7 @@
             WriteTarget(const WriteTarget &t, uint32_t sz) : tile_num(t.tile_num), size(sz), data(t.data) { }
 
-            uint32_t         tile_num; ///< Tile index of the data (to make sure that they are written in the correct order)
-            uint32_t         size;     ///< Size to write
-            shared_ptr<char> data;     ///< Memory block to write
+            uint32_t              tile_num; ///< Tile index of the data (to make sure that they are written in the correct order)
+            uint32_t              size;     ///< Size to write
+            std::shared_ptr<char> data;     ///< Memory block to write
         };
 
@@ -71,9 +66,9 @@
             {}
 
-            CatalogRow&      catalog_entry;   ///< Reference to the catalog entry to deal with
-            shared_ptr<char> src;             ///< Original data
-            shared_ptr<char> transposed_src;  ///< Transposed data
-            WriteTarget      target;          ///< Compressed data
-            uint32_t         num_rows;        ///< Number of rows to compress
+            CatalogRow&           catalog_entry;   ///< Reference to the catalog entry to deal with
+            std::shared_ptr<char> src;             ///< Original data
+            std::shared_ptr<char> transposed_src;  ///< Transposed data
+            WriteTarget           target;          ///< Compressed data
+            uint32_t              num_rows;        ///< Number of rows to compress
          };
 
@@ -92,6 +87,6 @@
                uint32_t rowPerTile  = DefaultNumRowsPerTile(),
                uint32_t maxUsableMem= DefaultMaxMemory()) : ofits(),
-                                                        fMemPool(0, maxUsableMem*1000),
-                                                        fWriteToDiskQueue(bind(&zofits::WriteBufferToDisk, this, placeholders::_1), false)
+            fMemPool(0, maxUsableMem*1000),
+            fWriteToDiskQueue(std::bind(&zofits::WriteBufferToDisk, this, std::placeholders::_1), false)
         {
             InitMemberVariables(numTiles, rowPerTile, maxUsableMem*1000);
@@ -107,6 +102,6 @@
                uint32_t rowPerTile  = DefaultNumRowsPerTile(),
                uint32_t maxUsableMem= DefaultMaxMemory()) : ofits(fname),
-                                                        fMemPool(0, maxUsableMem*1000),
-                                                        fWriteToDiskQueue(bind(&zofits::WriteBufferToDisk, this, placeholders::_1), false)
+                   fMemPool(0, maxUsableMem*1000),
+                   fWriteToDiskQueue(std::bind(&zofits::WriteBufferToDisk, this, std::placeholders::_1), false)
         {
             InitMemberVariables(numTiles, rowPerTile, maxUsableMem*1000);
@@ -132,5 +127,5 @@
             fMaxUsableMem = maxUsableMem;
 #ifdef __EXCEPTIONS
-            fThreadsException = exception_ptr();
+            fThreadsException = std::exception_ptr();
 #endif
             fErrno = 0;
@@ -208,5 +203,5 @@
 
             // swap the catalog bytes before writing
-            vector<char> swapped_catalog(total_catalog_size);
+            std::vector<char> swapped_catalog(total_catalog_size);
 
             uint32_t shift = 0;
@@ -272,7 +267,7 @@
             {
 #ifdef __EXCEPTIONS
-                throw runtime_error("Wrong size of row given to WriteRow");
+                throw std::runtime_error("Wrong size of row given to WriteRow");
 #else
-                gLog << ___err___ << "ERROR - Wrong size of row given to WriteRow" << endl;
+                gLog << ___err___ << "ERROR - Wrong size of row given to WriteRow" << std::endl;
                 return false;
 #endif
@@ -282,6 +277,6 @@
             //check if something hapenned while the compression threads were working
             //if so, re-throw the exception that was generated
-            if (fThreadsException != exception_ptr())
-                rethrow_exception(fThreadsException);
+            if (fThreadsException != std::exception_ptr())
+                std::rethrow_exception(fThreadsException);
 #endif
             //copy current row to pool or rows waiting for compression
@@ -331,5 +326,5 @@
                 const WriteTarget write_target(compress_target.target, size_to_write);
                 if (!WriteBufferToDisk(write_target))
-                    throw runtime_error("Unexpected tile number mismatch in WriteBufferToDisk in the main thread.");
+                    throw std::runtime_error("Unexpected tile number mismatch in WriteBufferToDisk in the main thread.");
 
                 // The correct 'errno' is set, because it is the main thread.
@@ -339,5 +334,5 @@
             //if all queues are empty, use queue 0
             uint32_t min_index     = 0;
-            uint32_t min_size      = numeric_limits<uint32_t>::max();
+            uint32_t min_size      = std::numeric_limits<uint32_t>::max();
             uint32_t current_index = 0;
 
@@ -353,5 +348,5 @@
 
             if (!fCompressionQueues[min_index].emplace(compress_target))
-                throw runtime_error("The compression queues are not started. Did you close the file before writing this row?");
+                throw std::runtime_error("The compression queues are not started. Did you close the file before writing this row?");
 
             errno = fErrno;
@@ -448,6 +443,6 @@
             //check if something hapenned while the compression threads were working
             //if so, re-throw the exception that was generated
-            if (fThreadsException != exception_ptr())
-                rethrow_exception(fThreadsException);
+            if (fThreadsException != std::exception_ptr())
+                std::rethrow_exception(fThreadsException);
 #endif
 
@@ -467,5 +462,5 @@
                 const WriteTarget write_target(compress_target.target, size_to_write);
                 if (!WriteBufferToDisk(write_target))
-                    throw runtime_error("Tile number mismatch in WriteBufferToDisk writing the last tile.");
+                    throw std::runtime_error("Tile number mismatch in WriteBufferToDisk writing the last tile.");
             }
 
@@ -502,5 +497,5 @@
             SetInt("NAXIS1", total_catalog_width);
             SetInt("NAXIS2", total_num_tiles_written);
-            SetStr("RAWSUM", to_string(fRawSum.val()));
+            SetStr("RAWSUM", std::to_string(fRawSum.val()));
 
             const float compression_ratio = (float)(fRealRowWidth*fTable.num_rows)/(float)heap_size;
@@ -519,15 +514,15 @@
             const Checksum checksm = UpdateHeaderChecksum();
 
-            ofstream::close();
+            std::ofstream::close();
 
             if ((checksm+fDataSum).valid())
                 return true;
 
-            ostringstream sout;
+            std::ostringstream sout;
             sout << "Checksum (" << std::hex << checksm.val() << ") invalid.";
 #ifdef __EXCEPTIONS
-            throw runtime_error(sout.str());
+            throw std::runtime_error(sout.str());
 #else
-            gLog << ___err___ << "ERROR - " << sout.str() << endl;
+            gLog << ___err___ << "ERROR - " << sout.str() << std::endl;
             return false;
 #endif
@@ -535,5 +530,6 @@
 
         /// Overload of the ofits method. Just calls the zofits specific one with default, uncompressed options for this column
-        bool AddColumn(uint32_t cnt, char typechar, const string& name, const string& unit, const string& comment="", bool addHeaderKeys=true)
+        bool AddColumn(uint32_t cnt, char typechar, const std::string& name, const std::string& unit,
+                       const std::string& comment="", bool addHeaderKeys=true)
         {
             return AddColumn(FITS::kFactRaw, cnt, typechar, name, unit, comment, addHeaderKeys);
@@ -541,5 +537,6 @@
 
         /// Overload of the simplified compressed version
-        bool AddColumn(const FITS::Compression &comp, uint32_t cnt, char typechar, const string& name, const string& unit, const string& comment="", bool addHeaderKeys=true)
+        bool AddColumn(const FITS::Compression &comp, uint32_t cnt, char typechar, const std::string& name,
+                       const std::string& unit, const std::string& comment="", bool addHeaderKeys=true)
         {
             if (!ofits::AddColumn(1, 'Q', name, unit, comment, addHeaderKeys))
@@ -559,6 +556,6 @@
             fRealColumns.emplace_back(col, comp);
 
-            SetStr("ZFORM"+to_string(fRealColumns.size()), to_string(cnt)+typechar, "format of "+name+" "+CommentFromType(typechar));
-            SetStr("ZCTYP"+to_string(fRealColumns.size()), "FACT", "Compression type: FACT");
+            SetStr("ZFORM"+std::to_string(fRealColumns.size()), std::to_string(cnt)+typechar, "format of "+name+" "+CommentFromType(typechar));
+            SetStr("ZCTYP"+std::to_string(fRealColumns.size()), "FACT", "Compression type: FACT");
 
             return true;
@@ -572,7 +569,7 @@
             {
 #ifdef __EXCEPTIONS
-                throw runtime_error("File must be closed before changing the number of compression threads");
+                throw std::runtime_error("File must be closed before changing the number of compression threads");
 #else
-                gLog << ___err___ << "ERROR - File must be closed before changing the number of compression threads" << endl;
+                gLog << ___err___ << "ERROR - File must be closed before changing the number of compression threads" << std::endl;
 #endif
                 return false;
@@ -583,5 +580,5 @@
             unsigned int num_available_cores = boost::thread::hardware_concurrency();
 #else
-            unsigned int num_available_cores = thread::hardware_concurrency();
+            unsigned int num_available_cores = std::thread::hardware_concurrency();
 #endif
             // could not detect number of available cores from system properties...
@@ -595,5 +592,5 @@
             if (fCompressionQueues.size() != uint32_t(num))
             {
-                fCompressionQueues.resize(num, Queue<CompressionTarget>(bind(&zofits::CompressBuffer, this, placeholders::_1), false));
+                fCompressionQueues.resize(num, Queue<CompressionTarget>(std::bind(&zofits::CompressBuffer, this, std::placeholders::_1), false));
                 fNumQueues = num;
             }
@@ -664,5 +661,5 @@
 //            for (uint32_t i=0;i<thisRoundNumRows;i++)
 //            {
-//                char* target_location = target.src.get()->get() + fRealRowWidth*i;
+//                char* target_location = target.src.get() + fRealRowWidth*i;
 //                cout << "Target Location there...." << hex << static_cast<void*>(target_location) << endl;
 //                DrsOffsetCalibrate(target_location);
@@ -682,7 +679,7 @@
             catch (...)
             {
-                fThreadsException = current_exception();
+                fThreadsException = std::current_exception();
                 if (fNumQueues == 0)
-                    rethrow_exception(fThreadsException);
+                    std::rethrow_exception(fThreadsException);
             }
 #endif
@@ -720,7 +717,7 @@
             catch (...)
             {
-                fThreadsException = current_exception();
+                fThreadsException = std::current_exception();
                 if (fNumQueues == 0)
-                    rethrow_exception(fThreadsException);
+                    std::rethrow_exception(fThreadsException);
             }
 #endif
@@ -871,5 +868,5 @@
         uint32_t compressHUFFMAN16(char* dest, const char* src, uint32_t numRows, uint32_t sizeOfElems, uint32_t numRowElems)
         {
-            string huffmanOutput;
+            std::string huffmanOutput;
             uint32_t previousHuffmanSize = 0;
 
@@ -881,7 +878,7 @@
             {
 #ifdef __EXCEPTIONS
-                throw runtime_error("HUFMANN16 can only encode columns with 16-bit or longer types");
+                throw std::runtime_error("HUFMANN16 can only encode columns with 16-bit or longer types");
 #else
-                gLog << ___err___ << "ERROR - HUFMANN16 can only encode columns with 16-bit or longer types" << endl;
+                gLog << ___err___ << "ERROR - HUFMANN16 can only encode columns with 16-bit or longer types" << std::endl;
                 return 0;
 #endif
@@ -942,5 +939,5 @@
         int32_t         fLatestWrittenTile; ///< Index of the last tile written to disk (for correct ordering while using several threads)
 
-        vector<Queue<CompressionTarget>>          fCompressionQueues;  ///< Processing queues (=threads)
+        std::vector<Queue<CompressionTarget>>          fCompressionQueues;  ///< Processing queues (=threads)
         Queue<WriteTarget, QueueMin<WriteTarget>> fWriteToDiskQueue;   ///< Writing queue (=thread)
 
@@ -967,20 +964,14 @@
             FITS::Compression block_head;  ///< the compression data associated with that column
         };
-        vector<CompressedColumn> fRealColumns;     ///< Vector hosting the columns of the file
-        uint32_t                 fRealRowWidth;    ///< Width in bytes of one uncompressed row
-        shared_ptr<char>         fSmartBuffer;     ///< Smart pointer to the buffer where the incoming rows are written
-        vector<char>             fRawSumBuffer;    ///< buffer used for checksuming the incoming data, before compression
-
-#ifdef __EXCEPTIONS
-        exception_ptr     fThreadsException; ///< exception pointer to store exceptions coming from the threads
-#endif
-        int               fErrno;            ///< propagate errno to main thread
-
-
+        std::vector<CompressedColumn> fRealColumns;     ///< Vector hosting the columns of the file
+        uint32_t                      fRealRowWidth;    ///< Width in bytes of one uncompressed row
+        std::shared_ptr<char>         fSmartBuffer;     ///< Smart pointer to the buffer where the incoming rows are written
+        std::vector<char>             fRawSumBuffer;    ///< buffer used for checksuming the incoming data, before compression
+
+#ifdef __EXCEPTIONS
+        std::exception_ptr fThreadsException; ///< exception pointer to store exceptions coming from the threads
+#endif
+        int                fErrno;            ///< propagate errno to main thread
 };
 
-#ifndef __MARS__
-}; //namespace std
-#endif
-
-#endif
+#endif
