Index: trunk/Mars/mcore/factofits.h
===================================================================
--- trunk/Mars/mcore/factofits.h	(revision 17262)
+++ trunk/Mars/mcore/factofits.h	(revision 17263)
@@ -15,6 +15,4 @@
 namespace std
 {
-#else
-using namespace std;
 #endif
 
@@ -25,7 +23,7 @@
 
         /// constructors
-        factofits(uint32_t numTiles=1000,
-                  uint32_t rowPerTile=100,
-                  uint64_t maxUsableMem=0) : zofits(numTiles, rowPerTile, maxUsableMem)
+        factofits(uint32_t numTiles=DefaultMaxNumTiles(), uint32_t rowPerTile=DefaultNumRowsPerTile(),
+                  uint32_t maxMem=DefaultMaxMemory())
+            : zofits(numTiles, rowPerTile, maxMem)
         {
             fStartCellsOffset = -1;
@@ -33,8 +31,7 @@
         }
 
-        factofits(const char* fname,
-                  uint32_t numTiles=1000,
-                  uint32_t rowPerTile=100,
-                  uint64_t maxUsableMem=0) : zofits(fname, numTiles, rowPerTile, maxUsableMem)
+        factofits(const char *fname, uint32_t numTiles=DefaultMaxNumTiles(),
+                  uint32_t rowPerTile=DefaultNumRowsPerTile(), uint32_t maxMem=DefaultMaxMemory())
+            : zofits(fname, numTiles, rowPerTile, maxMem)
         {
             fStartCellsOffset = -1;
@@ -97,50 +94,50 @@
                 return false;
 
-            if (IsOffsetCalibration())
-            {//retrieve the column storing the start cell offsets, if required.
-
-                for (auto it=fRealColumns.begin(); it!=fRealColumns.end(); it++)//Table.cols.begin(); it!= fTable.cols.end(); it++)
+            if (!IsOffsetCalibration())
+                return true;
+
+            //retrieve the column storing the start cell offsets, if required.
+            for (auto it=fRealColumns.cbegin(); it!=fRealColumns.cend(); it++)
+            {
+                if (it->col.name == "StartCellData")
+                    fStartCellsOffset = it->col.offset;
+
+                if (it->col.name == "Data")
                 {
-                    if (it->col.name == "StartCellData")
-                        fStartCellsOffset = it->col.offset;
-
-                    if (it->col.name == "Data")
+                    fNumSlices  = it->col.num;
+                    fDataOffset = it->col.offset;
+                    if (fNumSlices % 1440 != 0)
                     {
-                        fNumSlices  = it->col.num;
-                        fDataOffset = it->col.offset;
-                        if (fNumSlices % 1440 != 0)
-                        {
 #ifdef __EXCEPTIONS
-                            throw runtime_error("Number of data samples not a multiple of 1440.");
+                        throw runtime_error("Number of data samples not a multiple of 1440.");
 #else
-                            gLog << ___err___ << "ERROR - Number of data samples not a multiple of 1440. Doing it uncalibrated." << endl;
-#endif
-                            fOffsetCalibration.resize(0);
-                        }
-                        fNumSlices /= 1440;
+                        gLog << ___warn___ << "WARNING - Number of data samples not a multiple of 1440. Doing it uncalibrated." << endl;
+#endif
+                        fOffsetCalibration.resize(0);
                     }
+                    fNumSlices /= 1440;
                 }
-
-                if (fStartCellsOffset < 0)
-                {
+            }
+
+            if (fStartCellsOffset < 0)
+            {
 #ifdef __EXCEPTIONS
-                    throw runtime_error("FACT Calibration requested, but \"StartCellData\" column not found.");
+                throw runtime_error("FACT Calibration requested, but \"StartCellData\" column not found.");
 #else
-                    gLog << ___err___ << "ERROR - FACT Calibration requested, but \"StartCellData\" column not found. Doing it uncalibrated." << endl;
+                gLog << ___warn___ << "WARNING - FACT Calibration requested, but \"StartCellData\" column not found. Doing it uncalibrated." << endl;
+#endif
+                //throw away the calibration data
+                fOffsetCalibration.resize(0);
+            }
+
+            if (fDataOffset < 0)
+            {
+#ifdef __EXCEPTIONS
+                throw runtime_error("FACT Calibration requested, but \"Data\" column not found.");
+#else
+                gLog << ___warn___ << "WARNING - FACT Calibration requested, but \"Data\" column not found. Doing it uncalibrated." << endl;
 #endif
                     //throw away the calibration data
-                    fOffsetCalibration.resize(0);
-                }
-
-                if (fDataOffset < 0)
-                {
-#ifdef __EXCEPTIONS
-                    throw runtime_error("FACT Calibration requested, but \"Data\" column not found.");
-#else
-                    gLog << ___err___ << "ERROR - FACT Calibration requested, but \"Data\" column not found. Doing it uncalibrated." << endl;
-#endif
-                    //throw away the calibration data
-                    fOffsetCalibration.resize(0);
-                }
+                fOffsetCalibration.resize(0);
             }
 
@@ -196,4 +193,5 @@
             return good();
         }*/
+
         ///Actually write the drs calibration table
         virtual bool WriteDrsOffsetsTable()
@@ -243,11 +241,9 @@
             Checksum rawsum;
             rawsum.add((char*)(fOffsetCalibration.data()), 1024*1440*sizeof(int16_t));
-            ostringstream sum_str;
-            sum_str << rawsum.val();
-            c.SetStr("RAWSUM", sum_str.str());
+            c.SetStr("RAWSUM", to_string(rawsum.val()));
 
             //compress data and calculate final, compressed size
-            const uint32_t compressed_header_size = sizeof(TileHeader) + sizeof(BlockHeader) + 1*sizeof(uint16_t);
-            vector<char> compressed_calib(1024*1440*2 + compressed_header_size + 8); //+8 for checksum;
+            const uint32_t compressed_header_size = sizeof(FITS::TileHeader) + sizeof(FITS::BlockHeader) + 1*sizeof(uint16_t);
+            std::vector<char> compressed_calib(1024*1440*2 + compressed_header_size + 8); //+8 for checksum;
             char* data_start = compressed_calib.data() + compressed_header_size;
             uint32_t compressed_size = compressHUFFMAN16(data_start, (char*)(fOffsetCalibration.data()), 1024*1440, 2, 1);;
@@ -255,12 +251,12 @@
 
             //Write tile header
-            TileHeader th;
-            vector<uint16_t> seq(1, kFactHuffman16);
-            Compression bh(seq, kOrderByRow);
+            FITS::TileHeader th;
+            std::vector<uint16_t> seq(1, FITS::kFactHuffman16);
+            FITS::Compression bh(seq, FITS::kOrderByRow);
             th.numRows = 1;
             th.size = compressed_size;
-            bh.SetBlockSize(compressed_size-sizeof(TileHeader));
-            memcpy(compressed_calib.data(), &(th), sizeof(TileHeader));
-            bh.Memcpy(compressed_calib.data()+sizeof(TileHeader));
+            bh.SetBlockSize(compressed_size-sizeof(FITS::TileHeader));
+            memcpy(compressed_calib.data(), &(th), sizeof(FITS::TileHeader));
+            bh.Memcpy(compressed_calib.data()+sizeof(FITS::TileHeader));
 
             //calculate resulting compressed datasum
@@ -272,9 +268,9 @@
             seekp(here_I_am);
 
-            vector<uint64_t> catalog(2,0);
-            catalog[0] = compressed_size-sizeof(TileHeader);
-            catalog[1] = sizeof(TileHeader);
-
-            vector<char> swappedCatalog(catalog_size);
+            std::vector<uint64_t> catalog(2,0);
+            catalog[0] = compressed_size-sizeof(FITS::TileHeader);
+            catalog[1] = sizeof(FITS::TileHeader);
+
+            std::vector<char> swappedCatalog(catalog_size);
             revcpy<sizeof(int64_t)>(swappedCatalog.data(), (char*)(catalog.data()), 2);//catalog_size);
             datasum.add(swappedCatalog.data(), catalog_size);
@@ -285,8 +281,5 @@
             c.SetFloat("ZRATIO", (float)(1024*1440*2)/(float)(compressed_size));
             c.SetInt("PCOUNT", compressed_size + catalog_size);
-
-            sum_str.str("");
-            sum_str << datasum.val();
-            c.SetStr("DATASUM", sum_str.str());
+            c.SetStr("DATASUM", to_string(datasum.val()));
 
             datasum += c.WriteHeader(*this);
@@ -307,33 +300,33 @@
         virtual void DrsOffsetCalibrate(char* target_location)
         {
-            if (IsOffsetCalibration())
+            if (!IsOffsetCalibration())
+                return;
+
+            const int16_t* startCell = reinterpret_cast<int16_t*>(target_location + fStartCellsOffset);
+            int16_t*       data      = reinterpret_cast<int16_t*>(target_location + fDataOffset);
+
+            for (uint32_t ch=0; ch<1440; ch++)
             {
-                const int16_t* startCell = reinterpret_cast<int16_t*>(target_location + fStartCellsOffset);
-                int16_t*       data      = reinterpret_cast<int16_t*>(target_location + fDataOffset);
-
-                for (uint32_t ch=0; ch<1440; ch++)
+                if (startCell[ch] < 0)
                 {
-                    if (startCell[ch] < 0)
-                    {
-                        data += fNumSlices;
-                        continue;
-                    }
-
-                    const int16_t modStart = startCell[ch]%1024;
-                    const int16_t *off     = fOffsetCalibration.data() + ch*1024;
-
-                    const int16_t* cal        = off+modStart;
-                    const int16_t* end_stride = data+fNumSlices;
-
-                    if (modStart+fNumSlices > 1024)
-                    {
-                        while (cal < off+1024)
-                            *data++ -= *cal++;
-                        cal = off;
-                    }
-
-                    while (data<end_stride)
+                    data += fNumSlices;
+                    continue;
+                }
+
+                const int16_t modStart = startCell[ch]%1024;
+                const int16_t *off     = fOffsetCalibration.data() + ch*1024;
+
+                const int16_t* cal        = off+modStart;
+                const int16_t* end_stride = data+fNumSlices;
+
+                if (modStart+fNumSlices > 1024)
+                {
+                    while (cal < off+1024)
                         *data++ -= *cal++;
+                    cal = off;
                 }
+
+                while (data<end_stride)
+                    *data++ -= *cal++;
             }
         }
@@ -341,23 +334,24 @@
 private:
         /// Checks if the size of the input calibration is ok
-        void VerifyCalibrationSize(uint32_t size)
-        {
-            if (size != 1440*1024)
-            {
-                ostringstream str;
-                str << "Cannot load calibration with anything else than 1440 pixels and 1024 samples per pixel. Got a total size of " << size;
+        bool VerifyCalibrationSize(uint32_t size)
+        {
+            if (size == 1440*1024)
+                return true;
+
+            ostringstream str;
+            str << "Cannot load calibration with anything else than 1440 pixels and 1024 samples per pixel. Got a total size of " << size;
 #ifdef __EXCEPTIONS
             throw runtime_error(str.str());
 #else
             gLog << ___err___ << "ERROR - " << str.str() << endl;
-#endif
-            }
+            return false;
+#endif
          }
 
         //Offsets calibration stuff.
-        vector<int16_t> fOffsetCalibration;    ///< The calibration itself
-        int32_t         fStartCellsOffset;    ///<  Offset in bytes for the startcell data
-        int32_t         fDataOffset;         ///<   Offset in bytes for the data
-        int32_t         fNumSlices;         ///<    Number of samples per pixel per event
+        vector<int16_t> fOffsetCalibration;  ///< The calibration itself
+        int32_t         fStartCellsOffset;   ///< Offset in bytes for the startcell data
+        int32_t         fDataOffset;         ///< Offset in bytes for the data
+        int32_t         fNumSlices;          ///< Number of samples per pixel per event
 
 }; //class factofits
Index: trunk/Mars/mcore/ofits.h
===================================================================
--- trunk/Mars/mcore/ofits.h	(revision 17262)
+++ trunk/Mars/mcore/ofits.h	(revision 17263)
@@ -36,6 +36,4 @@
 namespace std
 {
-#else
-using namespace std;
 #endif
 
@@ -50,9 +48,9 @@
     struct Key
     {
-        string key;
-        bool   delim;
-        string value;
-        string comment;
-        string fitsString;
+        std::string key;
+        bool        delim;
+        std::string value;
+        std::string comment;
+        std::string fitsString;
 
         off_t offset;   // offset in file
@@ -60,7 +58,7 @@
         bool changed;   // For closing the file
 
-        Key(const string &k="") : key(k), delim(false), fitsString(""), offset(0), changed(true) { }
-
-        string Trim(const string &str)
+        Key(const std::string &k="") : key(k), delim(false), fitsString(""), offset(0), changed(true) { }
+
+        std::string Trim(const std::string &str)
         {
             // Trim Both leading and trailing spaces
@@ -69,6 +67,6 @@
 
             // if all spaces or empty return an empty string
-            if (string::npos==first || string::npos==last)
-                return string();
+            if (std::string::npos==first || std::string::npos==last)
+                return std::string();
 
             return str.substr(first, last-first+1);
@@ -81,5 +79,5 @@
             {
 #ifdef __EXCEPTIONS
-                throw runtime_error("Key name empty.");
+                throw std::runtime_error("Key name empty.");
 #else
                 gLog << ___err___ << "ERROR - Key name empty." << endl;
@@ -89,8 +87,8 @@
             if (key.size()>8)
             {
-                ostringstream sout;
+                std::ostringstream sout;
                 sout << "Key '" << key << "' exceeds 8 bytes.";
 #ifdef __EXCEPTIONS
-                throw runtime_error(sout.str());
+                throw std::runtime_error(sout.str());
 #else
                 gLog << ___err___ << "ERROR - " << sout.str() << endl;
@@ -101,11 +99,11 @@
             //transform(key.begin(), key.end(), key.begin(), toupper);
 
-            for (string::const_iterator c=key.begin(); c<key.end(); c++)
+            for (std::string::const_iterator c=key.cbegin(); c<key.cend(); c++)
                 if ((*c<'A' || *c>'Z') && (*c<'0' || *c>'9') && *c!='-' && *c!='_')
                 {
-                    ostringstream sout;
+                    std::ostringstream sout;
                     sout << "Invalid character '" << *c << "' found in key '" << key << "'";
 #ifdef __EXCEPTIONS
-                    throw runtime_error(sout.str());
+                    throw std::runtime_error(sout.str());
 #else
                     gLog << ___err___ << "ERROR - " << sout.str() << endl;
@@ -121,11 +119,11 @@
             comment = Trim(comment);
 
-            for (string::const_iterator c=key.begin(); c<key.end(); c++)
+            for (std::string::const_iterator c=key.cbegin(); c<key.cend(); c++)
                 if (*c<32 || *c>126)
                 {
-                    ostringstream sout;
+                    std::ostringstream sout;
                     sout << "Invalid character '" << *c << "' [" << int(*c) << "] found in comment '" << comment << "'";
 #ifdef __EXCEPTIONS
-                    throw runtime_error(sout.str());
+                    throw std::runtime_error(sout.str());
 #else
                     gLog << ___err___ << "ERROR - " << sout.str() << endl;
@@ -151,8 +149,8 @@
             if (!trim)
             {
-                ostringstream sout;
+                std::ostringstream sout;
                 sout << "Size " << sz << " of entry for key '" << key << "' exceeds 80 characters.";
 #ifdef __EXCEPTIONS
-                throw runtime_error(sout.str());
+                throw std::runtime_error(sout.str());
 #else
                 gLog << ___err___ << "ERROR - " << sout.str() << endl;
@@ -169,5 +167,5 @@
             {
 #ifndef __EXCEPTIONS
-                ostringstream sout;
+                std::ostringstream sout;
                 sout << "Size " << sz << " of entry for key '" << key << "' exceeds 80 characters... removed comment.";
                 gLog << ___warn___ << "WARNING - " << sout.str() << endl;
@@ -176,8 +174,8 @@
             }
 
-            ostringstream sout;
+            std::ostringstream sout;
             sout << "Size " << sz << " of entry for key '" << key << "' exceeds 80 characters even without comment.";
 #ifdef __EXCEPTIONS
-            throw runtime_error(sout.str());
+            throw std::runtime_error(sout.str());
 #else
             gLog << ___err___ << "ERROR - " << sout.str() << endl;
@@ -194,5 +192,5 @@
         }
 
-        string Compile()
+        std::string Compile()
         {
 
@@ -200,5 +198,5 @@
                 return fitsString;
 
-            ostringstream sout;
+            std::ostringstream sout;
             sout << std::left << setw(8) << key;
 
@@ -226,5 +224,5 @@
                 return;
 
-            string str = Compile();
+            std::string str = Compile();
             str.insert(str.end(), 80-str.size(), ' ');
 
@@ -245,5 +243,5 @@
         void Out(ostream &out)
         {
-            string str = Compile();
+            std::string str = Compile();
 
             str.insert(str.end(), 80-str.size(), ' ');
@@ -255,7 +253,7 @@
 
 private:
-    vector<Key> fKeys;
-
-    vector<Key>::iterator findkey(const string &key)
+    std::vector<Key> fKeys;
+
+    std::vector<Key>::iterator findkey(const std::string &key)
     {
         for (auto it=fKeys.begin(); it!=fKeys.end(); it++)
@@ -266,5 +264,5 @@
     }
 
-    bool Set(const string &key="", bool delim=false, const string &value="", const string &comment="")
+    bool Set(const std::string &key="", bool delim=false, const std::string &value="", const std::string &comment="")
     {
         // If no delimit add the row no matter if it alread exists
@@ -283,8 +281,8 @@
         if (fTable.num_rows>0)
         {
-            ostringstream sout;
+            std::ostringstream sout;
             sout << "No new header key can be defined, rows were already written to the file... ignoring new key '" << key << "'";
 #ifdef __EXCEPTIONS
-                throw runtime_error(sout.str());
+                throw std::runtime_error(sout.str());
 #else
                 gLog << ___err___ << "ERROR - " << sout.str() << endl;
@@ -320,5 +318,5 @@
         struct Column
         {
-            string name;
+            std::string name;
             size_t offset;
             size_t num;
@@ -327,5 +325,5 @@
         };
 
-        vector<Column> cols;
+        std::vector<Column> cols;
 
         Table() : offset(0), bytes_per_row(0), num_rows(0), num_cols(0)
@@ -337,13 +335,13 @@
     Table fTable;
 
-    vector<char> fOutputBuffer;
-
-    vector<Table::Column>::iterator findcol(const string &name)
-    {
-        for (auto it=fTable.cols.begin(); it!=fTable.cols.end(); it++)
+    std::vector<char> fOutputBuffer;
+
+    std::vector<Table::Column>::const_iterator findcol(const std::string &name)
+    {
+        for (auto it=fTable.cols.cbegin(); it!=fTable.cols.cend(); it++)
             if (name==it->name)
                 return it;
 
-        return fTable.cols.end();
+        return fTable.cols.cend();
     }
 
@@ -398,5 +396,5 @@
     }
     //Etienne: required to enable 1 to 1 reconstruction of files
-    bool SetKeyComment(const string& key, const string& comment)
+    bool SetKeyComment(const std::string& key, const std::string& comment)
     {
         auto it = findkey(key);
@@ -407,15 +405,15 @@
         return true;
     }
-    bool SetKeyFromFitsString(const string& fitsString)
+    bool SetKeyFromFitsString(const std::string& fitsString)
     {
         if (fTable.num_rows>0)
         {
-            ostringstream sout;
+            std::ostringstream sout;
             sout << "No new header key can be defined, rows were already written to the file... ignoring new key '" << fitsString << "'";
 #ifdef __EXCEPTIONS
-                throw runtime_error(sout.str());
-#else
-                gLog << ___err___ << "ERROR - " << sout.str() << endl;
-                return false;
+            throw std::runtime_error(sout.str());
+#else
+            gLog << ___err___ << "ERROR - " << sout.str() << endl;
+            return false;
 #endif
         }
@@ -427,20 +425,20 @@
         return true;
     }
-    bool SetRaw(const string &key, const string &val, const string &comment)
+    bool SetRaw(const std::string &key, const std::string &val, const std::string &comment)
     {
         return Set(key, true, val, comment);
     }
 
-    bool SetBool(const string &key, bool b, const string &comment="")
+    bool SetBool(const std::string &key, bool b, const std::string &comment="")
     {
         return Set(key, true, b?"T":"F", comment);
     }
 
-    bool AddEmpty(const string &key, const string &comment="")
+    bool AddEmpty(const std::string &key, const std::string &comment="")
     {
         return Set(key, true, "", comment);
     }
 
-    bool SetStr(const string &key, string s, const string &comment="")
+    bool SetStr(const std::string &key, std::string s, const std::string &comment="")
     {
         for (uint i=0; i<s.length(); i++)
@@ -451,7 +449,7 @@
     }
 
-    bool SetInt(const string &key, int64_t i, const string &comment="")
-    {
-        ostringstream sout;
+    bool SetInt(const std::string &key, int64_t i, const std::string &comment="")
+    {
+        std::ostringstream sout;
         sout << i;
 
@@ -459,7 +457,7 @@
     }
 
-    bool SetFloat(const string &key, double f, int p, const string &comment="")
-    {
-        ostringstream sout;
+    bool SetFloat(const std::string &key, double f, int p, const std::string &comment="")
+    {
+        std::ostringstream sout;
 
         if (p<0)
@@ -472,9 +470,9 @@
         sout << f;
 
-        string str = sout.str();
+        std::string str = sout.str();
 
         replace(str.begin(), str.end(), 'e', 'E');
 
-        if (str.find_first_of('E')==string::npos && str.find_first_of('.')==string::npos)
+        if (str.find_first_of('E')==std::string::npos && str.find_first_of('.')==std::string::npos)
             str += ".";
 
@@ -482,22 +480,22 @@
     }
 
-    bool SetFloat(const string &key, double f, const string &comment="")
+    bool SetFloat(const std::string &key, double f, const std::string &comment="")
     {
         return SetFloat(key, f, 0, comment);
     }
 
-    bool SetHex(const string &key, uint64_t i, const string &comment="")
-    {
-        ostringstream sout;
+    bool SetHex(const std::string &key, uint64_t i, const std::string &comment="")
+    {
+        std::ostringstream sout;
         sout << std::hex << "0x" << i;
         return SetStr(key, sout.str(), comment);
     }
 
-    bool AddComment(const string &comment)
+    bool AddComment(const std::string &comment)
     {
         return Set("COMMENT", false, "", comment);
     }
 
-    bool AddHistory(const string &comment)
+    bool AddHistory(const std::string &comment)
     {
         return Set("HISTORY", false, "", comment);
@@ -511,19 +509,19 @@
     }
 
-    string CommentFromType(char type)
-    {
-        string comment;
+    std::string CommentFromType(char type)
+    {
+        std::string comment;
 
         switch (type)
         {
-        case 'L': comment = "1-byte BOOL]";  break;
-        case 'A': comment = "1-byte CHAR]";  break;
-        case 'B': comment = "1-byte BOOL]";  break;
-        case 'I': comment = "2-byte INT]";   break;
-        case 'J': comment = "4-byte INT]";   break;
-        case 'K': comment = "8-byte INT]";   break;
-        case 'E': comment = "4-byte FLOAT]"; break;
-        case 'D': comment = "8-byte FLOAT]"; break;
-        case 'Q': comment = "var. Length]"; break;
+        case 'L': comment = "[1-byte BOOL]";  break;
+        case 'A': comment = "[1-byte CHAR]";  break;
+        case 'B': comment = "[1-byte BOOL]";  break;
+        case 'I': comment = "[2-byte INT]";   break;
+        case 'J': comment = "[4-byte INT]";   break;
+        case 'K': comment = "[8-byte INT]";   break;
+        case 'E': comment = "[4-byte FLOAT]"; break;
+        case 'D': comment = "[8-byte FLOAT]"; break;
+        case 'Q': comment = "[var. Length]"; break;
         }
 
@@ -551,12 +549,12 @@
     }
     //ETIENNE to be able to restore the file 1 to 1, I must restore the header keys myself
-    virtual bool AddColumn(uint32_t cnt, char typechar, const string &name, const string &unit, const string &comment="", bool addHeaderKeys=true)
+    virtual bool AddColumn(uint32_t cnt, char typechar, const std::string &name, const std::string &unit, const std::string &comment="", bool addHeaderKeys=true)
     {
         if (tellp()<0)
         {
-            ostringstream sout;
+            std::ostringstream sout;
             sout << "File not open... ignoring column '" << name << "'";
 #ifdef __EXCEPTIONS
-            throw runtime_error(sout.str());
+            throw std::runtime_error(sout.str());
 #else
             gLog << ___err___ << "ERROR - " << sout.str() << endl;
@@ -567,8 +565,8 @@
         if (tellp()>0)
         {
-            ostringstream sout;
+            std::ostringstream sout;
             sout << "Header already written, no new column can be defined... ignoring column '" << name << "'";
 #ifdef __EXCEPTIONS
-            throw runtime_error(sout.str());
+            throw std::runtime_error(sout.str());
 #else
             gLog << ___err___ << "ERROR - " << sout.str() << endl;
@@ -577,10 +575,10 @@
         }
 
-        if (findcol(name)!=fTable.cols.end())
-        {
-            ostringstream sout;
+        if (findcol(name)!=fTable.cols.cend())
+        {
+            std::ostringstream sout;
             sout << "A column with the name '" << name << "' already exists.";
 #ifdef __EXCEPTIONS
-            throw runtime_error(sout.str());
+            throw std::runtime_error(sout.str());
 #else
             gLog << ___err___ << "ERROR - " << sout.str() << endl;
@@ -591,11 +589,11 @@
         typechar = toupper(typechar);
 
-        static const string allow("LABIJKEDQ");
-        if (std::find(allow.begin(), allow.end(), typechar)==allow.end())
-        {
-            ostringstream sout;
+        static const std::string allow("LABIJKEDQ");
+        if (std::find(allow.cbegin(), allow.cend(), typechar)==allow.end())
+        {
+            std::ostringstream sout;
             sout << "Column type '" << typechar << "' not supported.";
 #ifdef __EXCEPTIONS
-            throw runtime_error(sout.str());
+            throw std::runtime_error(sout.str());
 #else
             gLog << ___err___ << "ERROR - " << sout.str() << endl;
@@ -604,5 +602,5 @@
         }
 
-        ostringstream type;
+        std::ostringstream type;
         type << cnt;
         if (typechar=='Q')
@@ -613,20 +611,12 @@
         fTable.num_cols++;
 
-        ostringstream typekey, formkey, unitkey, unitcom, typecom;
-        typekey << "TTYPE" << fTable.num_cols;
-        formkey << "TFORM" << fTable.num_cols;
-        unitkey << "TUNIT" << fTable.num_cols;
-        unitcom << "unit of " << name;
-
-        typecom << "format of " << name << " [";
-
-        typecom << CommentFromType(typechar);
-
         if (addHeaderKeys)
         {
-            SetStr(formkey.str(), type.str(), typecom.str());
-            SetStr(typekey.str(), name,       comment);
+            const std::string nc = std::to_string(fTable.num_cols);
+
+            SetStr("TFORM"+nc, type.str(), "format of "+name+" "+CommentFromType(typechar));
+            SetStr("TTYPE"+nc, name, comment);
             if (!unit.empty())
-                SetStr(unitkey.str(), unit, unitcom.str());
+                SetStr("TUNIT"+nc, unit, "unit of "+name);
         }
         size_t size = SizeFromType(typechar);
@@ -650,84 +640,84 @@
     }
 
-    virtual bool AddColumn(const FITS::Compression&, uint32_t cnt, char typechar, const string& name, const string& unit,  const string& comment="", bool addHeaderKeys=true)
+    virtual bool AddColumn(const FITS::Compression&, uint32_t cnt, char typechar, const std::string& name, const std::string& unit,  const std::string& comment="", bool addHeaderKeys=true)
     {
         return AddColumn(cnt, typechar, name, unit, comment, addHeaderKeys);
     }
 
-    bool AddColumnShort(uint32_t cnt, const string &name, const string &unit="", const string &comment="")
+    bool AddColumnShort(uint32_t cnt, const std::string &name, const std::string &unit="", const std::string &comment="")
     { return AddColumn(cnt, 'I', name, unit, comment); }
-    bool AddColumnInt(uint32_t cnt, const string &name, const string &unit="", const string &comment="")
+    bool AddColumnInt(uint32_t cnt, const std::string &name, const std::string &unit="", const std::string &comment="")
     { return AddColumn(cnt, 'J', name, unit, comment); }
-    bool AddColumnLong(uint32_t cnt, const string &name, const string &unit="", const string &comment="")
+    bool AddColumnLong(uint32_t cnt, const std::string &name, const std::string &unit="", const std::string &comment="")
     { return AddColumn(cnt, 'K', name, unit, comment); }
-    bool AddColumnFloat(uint32_t cnt, const string &name, const string &unit="", const string &comment="")
+    bool AddColumnFloat(uint32_t cnt, const std::string &name, const std::string &unit="", const std::string &comment="")
     { return AddColumn(cnt, 'E', name, unit, comment); }
-    bool AddColumnDouble(uint32_t cnt, const string &name, const string &unit="", const string &comment="")
+    bool AddColumnDouble(uint32_t cnt, const std::string &name, const std::string &unit="", const std::string &comment="")
     { return AddColumn(cnt, 'D', name, unit, comment); }
-    bool AddColumnChar(uint32_t cnt, const string &name, const string &unit="", const string &comment="")
+    bool AddColumnChar(uint32_t cnt, const std::string &name, const std::string &unit="", const std::string &comment="")
     { return AddColumn(cnt, 'A', name, unit, comment); }
-    bool AddColumnByte(uint32_t cnt, const string &name, const string &unit="", const string &comment="")
+    bool AddColumnByte(uint32_t cnt, const std::string &name, const std::string &unit="", const std::string &comment="")
     { return AddColumn(cnt, 'B', name, unit, comment); }
-    bool AddColumnBool(uint32_t cnt, const string &name, const string &unit="", const string &comment="")
+    bool AddColumnBool(uint32_t cnt, const std::string &name, const std::string &unit="", const std::string &comment="")
     { return AddColumn(cnt, 'L', name, unit, comment); }
 
-    bool AddColumnShort(const string &name, const string &unit="", const string &comment="")
+    bool AddColumnShort(const std::string &name, const std::string &unit="", const std::string &comment="")
     { return AddColumn(1, 'I', name, unit, comment); }
-    bool AddColumnInt(const string &name, const string &unit="", const string &comment="")
+    bool AddColumnInt(const std::string &name, const std::string &unit="", const std::string &comment="")
     { return AddColumn(1, 'J', name, unit, comment); }
-    bool AddColumnLong(const string &name, const string &unit="", const string &comment="")
+    bool AddColumnLong(const std::string &name, const std::string &unit="", const std::string &comment="")
     { return AddColumn(1, 'K', name, unit, comment); }
-    bool AddColumnFloat(const string &name, const string &unit="", const string &comment="")
+    bool AddColumnFloat(const std::string &name, const std::string &unit="", const std::string &comment="")
     { return AddColumn(1, 'E', name, unit, comment); }
-    bool AddColumnDouble(const string &name, const string &unit="", const string &comment="")
+    bool AddColumnDouble(const std::string &name, const std::string &unit="", const std::string &comment="")
     { return AddColumn(1, 'D', name, unit, comment); }
-    bool AddColumnChar(const string &name, const string &unit="", const string &comment="")
+    bool AddColumnChar(const std::string &name, const std::string &unit="", const std::string &comment="")
     { return AddColumn(1, 'A', name, unit, comment); }
-    bool AddColumnByte(const string &name, const string &unit="", const string &comment="")
+    bool AddColumnByte(const std::string &name, const std::string &unit="", const std::string &comment="")
     { return AddColumn(1, 'B', name, unit, comment); }
-    bool AddColumnBool(const string &name, const string &unit="", const string &comment="")
+    bool AddColumnBool(const std::string &name, const std::string &unit="", const std::string &comment="")
     { return AddColumn(1, 'L', name, unit, comment); }
 
-    bool AddColumnShort(const FITS::Compression &comp, uint32_t cnt, const string &name, const string &unit="", const string &comment="")
+    bool AddColumnShort(const FITS::Compression &comp, uint32_t cnt, const std::string &name, const std::string &unit="", const std::string &comment="")
     { return AddColumn(comp, cnt, 'I', name, unit, comment); }
-    bool AddColumnInt(const FITS::Compression &comp, uint32_t cnt, const string &name, const string &unit="", const string &comment="")
+    bool AddColumnInt(const FITS::Compression &comp, uint32_t cnt, const std::string &name, const std::string &unit="", const std::string &comment="")
     { return AddColumn(comp, cnt, 'J', name, unit, comment); }
-    bool AddColumnLong(const FITS::Compression &comp, uint32_t cnt, const string &name, const string &unit="", const string &comment="")
+    bool AddColumnLong(const FITS::Compression &comp, uint32_t cnt, const std::string &name, const std::string &unit="", const std::string &comment="")
     { return AddColumn(comp, cnt, 'K', name, unit, comment); }
-    bool AddColumnFloat(const FITS::Compression &comp, uint32_t cnt, const string &name, const string &unit="", const string &comment="")
+    bool AddColumnFloat(const FITS::Compression &comp, uint32_t cnt, const std::string &name, const std::string &unit="", const std::string &comment="")
     { return AddColumn(comp, cnt, 'E', name, unit, comment); }
-    bool AddColumnDouble(const FITS::Compression &comp, uint32_t cnt, const string &name, const string &unit="", const string &comment="")
+    bool AddColumnDouble(const FITS::Compression &comp, uint32_t cnt, const std::string &name, const std::string &unit="", const std::string &comment="")
     { return AddColumn(comp, cnt, 'D', name, unit, comment); }
-    bool AddColumnChar(const FITS::Compression &comp, uint32_t cnt, const string &name, const string &unit="", const string &comment="")
+    bool AddColumnChar(const FITS::Compression &comp, uint32_t cnt, const std::string &name, const std::string &unit="", const std::string &comment="")
     { return AddColumn(comp, cnt, 'A', name, unit, comment); }
-    bool AddColumnByte(const FITS::Compression &comp, uint32_t cnt, const string &name, const string &unit="", const string &comment="")
+    bool AddColumnByte(const FITS::Compression &comp, uint32_t cnt, const std::string &name, const std::string &unit="", const std::string &comment="")
     { return AddColumn(comp, cnt, 'B', name, unit, comment); }
-    bool AddColumnBool(const FITS::Compression &comp, uint32_t cnt, const string &name, const string &unit="", const string &comment="")
+    bool AddColumnBool(const FITS::Compression &comp, uint32_t cnt, const std::string &name, const std::string &unit="", const std::string &comment="")
     { return AddColumn(comp, cnt, 'L', name, unit, comment); }
 
-    bool AddColumnShort(const FITS::Compression &comp, const string &name, const string &unit="", const string &comment="")
+    bool AddColumnShort(const FITS::Compression &comp, const std::string &name, const std::string &unit="", const std::string &comment="")
     { return AddColumn(comp, 1, 'I', name, unit, comment); }
-    bool AddColumnInt(const FITS::Compression &comp, const string &name, const string &unit="", const string &comment="")
+    bool AddColumnInt(const FITS::Compression &comp, const std::string &name, const std::string &unit="", const std::string &comment="")
     { return AddColumn(comp, 1, 'J', name, unit, comment); }
-    bool AddColumnLong(const FITS::Compression &comp, const string &name, const string &unit="", const string &comment="")
+    bool AddColumnLong(const FITS::Compression &comp, const std::string &name, const std::string &unit="", const std::string &comment="")
     { return AddColumn(comp, 1, 'K', name, unit, comment); }
-    bool AddColumnFloat(const FITS::Compression &comp, const string &name, const string &unit="", const string &comment="")
+    bool AddColumnFloat(const FITS::Compression &comp, const std::string &name, const std::string &unit="", const std::string &comment="")
     { return AddColumn(comp, 1, 'E', name, unit, comment); }
-    bool AddColumnDouble(const FITS::Compression &comp, const string &name, const string &unit="", const string &comment="")
+    bool AddColumnDouble(const FITS::Compression &comp, const std::string &name, const std::string &unit="", const std::string &comment="")
     { return AddColumn(comp, 1, 'D', name, unit, comment); }
-    bool AddColumnChar(const FITS::Compression &comp, const string &name, const string &unit="", const string &comment="")
+    bool AddColumnChar(const FITS::Compression &comp, const std::string &name, const std::string &unit="", const std::string &comment="")
     { return AddColumn(comp, 1, 'A', name, unit, comment); }
-    bool AddColumnByte(const FITS::Compression &comp, const string &name, const string &unit="", const string &comment="")
+    bool AddColumnByte(const FITS::Compression &comp, const std::string &name, const std::string &unit="", const std::string &comment="")
     { return AddColumn(comp, 1, 'B', name, unit, comment); }
-    bool AddColumnBool(const FITS::Compression &comp, const string &name, const string &unit="", const string &comment="")
+    bool AddColumnBool(const FITS::Compression &comp, const std::string &name, const std::string &unit="", const std::string &comment="")
     { return AddColumn(comp, 1, 'L', name, unit, comment); }
 
     /*
-    bool AddKey(string key, double d, const string &comment)
+    bool AddKey(string key, double d, const std::string &comment)
     {
         ostringstream out;
         out << d;
 
-        string s = out.str();
+        std::string s = out.str();
 
         replace(s.begin(), s.end(), "e", "E");
@@ -804,5 +794,5 @@
         {
 #ifdef __EXCEPTIONS
-            throw runtime_error("File not empty anymore.");
+            throw std::runtime_error("File not empty anymore.");
 #else
             gLog << ___err___ << "ERROR - File not empty anymore." << endl;
@@ -848,5 +838,5 @@
             sout << "WriteRow - Size " << cnt << " does not match expected size " << fTable.bytes_per_row;
 #ifdef __EXCEPTIONS
-            throw runtime_error(sout.str());
+            throw std::runtime_error(sout.str());
 #else
             gLog << ___err___ << "ERROR - " << sout.str() << endl;
@@ -876,5 +866,5 @@
         else
         {
-            for (auto it=fTable.cols.begin(); it!=fTable.cols.end(); it++)
+            for (auto it=fTable.cols.cbegin(); it!=fTable.cols.cend(); it++)
             {
                 const char *src  = reinterpret_cast<const char*>(ptr) + it->offset;
@@ -902,5 +892,5 @@
 
     template<typename N>
-    bool WriteRow(const vector<N> &vec)
+    bool WriteRow(const std::vector<N> &vec)
     {
         return WriteRow(vec.data(), vec.size()*sizeof(N));
@@ -920,5 +910,5 @@
         if (tellp()%(80*36)>0)
         {
-            vector<char> filler(80*36-tellp()%(80*36));
+            std::vector<char> filler(80*36-tellp()%(80*36));
             write(filler.data(), filler.size());
         }
@@ -961,5 +951,5 @@
         sout << "Checksum (" << std::hex << chk.val() << ") invalid.";
 #ifdef __EXCEPTIONS
-        throw runtime_error(sout.str());
+        throw std::runtime_error(sout.str());
 #else
         gLog << ___err___ << "ERROR - " << sout.str() << endl;
@@ -970,8 +960,8 @@
     pair<string, int> GetChecksumData()
     {
-        string datasum;
-        string checksum;
+        std::string datasum;
+        std::string checksum;
         //cannot directly use the Get methods, because they are only in fits.h
-        for (vector<Key>::const_iterator it=fKeys.begin(); it!= fKeys.end(); it++)
+        for (std::vector<Key>::const_iterator it=fKeys.cbegin(); it!= fKeys.cend(); it++)
         {
             if (it->key == "CHECKSUM") checksum = it->value;
@@ -1002,5 +992,5 @@
         const struct tm *tmp1 = gmtime(&t0);
 
-        string str(21, '\0');
+        std::string str(21, '\0');
         if (tmp1 && strftime(const_cast<char*>(str.data()), 20, "%Y-%m-%dT%H:%M:%S", tmp1))
             SetStr("DATE", str, "File creation date");
@@ -1061,5 +1051,5 @@
     fits f("delme.fits");
     if (!f)
-        throw runtime_error("xxx");
+        throw std::runtime_error("xxx");
 
     cout << "Header is valid: " << f.IsHeaderOk() << endl;
Index: trunk/Mars/mcore/zofits.h
===================================================================
--- trunk/Mars/mcore/zofits.h	(revision 17262)
+++ trunk/Mars/mcore/zofits.h	(revision 17263)
@@ -559,8 +559,5 @@
             fRealColumns.emplace_back(col, comp);
 
-            ostringstream str;
-            str << "format of " << name << " [" << CommentFromType(typechar);
-
-            SetStr("ZFORM"+to_string(fRealColumns.size()), to_string(cnt)+typechar, str.str());
+            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");
 
