Index: /trunk/Mars/mcore/fits.h
===================================================================
--- /trunk/Mars/mcore/fits.h	(revision 17259)
+++ /trunk/Mars/mcore/fits.h	(revision 17260)
@@ -48,6 +48,4 @@
 namespace std
 {
-#else
-using namespace std;
 #endif
 
@@ -65,8 +63,8 @@
     struct Entry
     {
-        char   type;
-        string value;
-        string comment;
-        string fitsString;
+        char        type;
+        std::string value;
+        std::string comment;
+        std::string fitsString;
 
         template<typename T>
@@ -75,5 +73,5 @@
             T t;
 
-            istringstream str(value);
+            std::istringstream str(value);
             str >> t;
 
@@ -88,5 +86,5 @@
         bool is_compressed;
 
-        string name;
+        std::string name;
         size_t bytes_per_row;
         size_t num_rows;
@@ -101,11 +99,11 @@
             size_t bytes;  // num*size
             char   type;
-            string unit;
+            std::string unit;
             Compression_t comp;
         };
 
-        typedef map<string, Entry>  Keys;
-        typedef map<string, Column> Columns;
-        typedef vector<Column> SortedColumns;
+        typedef std::map<std::string, Entry>  Keys;
+        typedef std::map<std::string, Column> Columns;
+        typedef std::vector<Column> SortedColumns;
 
         Columns cols;
@@ -115,5 +113,5 @@
         int64_t datasum;
 
-        string Trim(const string &str, char c=' ') const
+        std::string Trim(const std::string &str, char c=' ') const
         {
             // Trim Both leading and trailing spaces
@@ -122,19 +120,19 @@
 
             // if all spaces or empty return an empty string
-            if (string::npos==pstart || string::npos==pend)
-                return string();
+            if (std::string::npos==pstart || std::string::npos==pend)
+                return std::string();
 
             return str.substr(pstart, pend-pstart+1);
         }
 
-        bool Check(const string &key, char type, const string &value="") const
+        bool Check(const std::string &key, char type, const std::string &value="") const
         {
             const Keys::const_iterator it = keys.find(key);
             if (it==keys.end())
             {
-                ostringstream str;
+                std::ostringstream str;
                 str << "Key '" << key << "' not found.";
 #ifdef __EXCEPTIONS
-                throw runtime_error(str.str());
+                throw std::runtime_error(str.str());
 #else
                 gLog << ___err___ << "ERROR - " << str.str() << endl;
@@ -145,8 +143,8 @@
             if (it->second.type!=type)
             {
-                ostringstream str;
+                std::ostringstream str;
                 str << "Wrong type for key '" << key << "': expected " << type << ", found " << it->second.type << ".";
 #ifdef __EXCEPTIONS
-                throw runtime_error(str.str());
+                throw std::runtime_error(str.str());
 #else
                 gLog << ___err___ << "ERROR - " << str.str() << endl;
@@ -157,8 +155,8 @@
             if (!value.empty() && it->second.value!=value)
             {
-                ostringstream str;
+                std::ostringstream str;
                 str << "Wrong value for key '" << key << "': expected " << value << ", found " << it->second.value << ".";
 #ifdef __EXCEPTIONS
-                throw runtime_error(str.str());
+                throw std::runtime_error(str.str());
 #else
                 gLog << ___err___ << "ERROR - " << str.str() << endl;
@@ -170,11 +168,11 @@
         }
 
-        Keys ParseBlock(const vector<string> &vec) const
-        {
-            map<string,Entry> rc;
+        Keys ParseBlock(const std::vector<std::string> &vec) const
+        {
+            std::map<std::string,Entry> rc;
 
             for (unsigned int i=0; i<vec.size(); i++)
             {
-                const string key = Trim(vec[i].substr(0,8));
+                const std::string key = Trim(vec[i].substr(0,8));
                 // Keywords without a value, like COMMENT / HISTORY
                 if (vec[i].substr(8,2)!="= ")
@@ -183,6 +181,6 @@
                 char type = 0;
 
-                string com;
-                string val = Trim(vec[i].substr(10));
+                std::string com;
+                std::string val = Trim(vec[i].substr(10));
 
                 if (val[0]=='\'')
@@ -193,5 +191,5 @@
                     {
                         const size_t pp = val.find_first_of('\'', p);
-                        if (pp==string::npos)
+                        if (pp==std::string::npos)
                             break;
 
@@ -204,5 +202,5 @@
                     // Set value, comment and type
                     // comments could be just spaces. take care of this.
-                    if (ppp!=string::npos && val.size() != ppp+1)
+                    if (ppp!=std::string::npos && val.size() != ppp+1)
                         com = Trim(val.substr(ppp+1));
 
@@ -219,8 +217,8 @@
                     val = Trim(val.substr(0, p));
 
-                    if (val.empty() || val.find_first_of('T')!=string::npos || val.find_first_of('F')!=string::npos)
+                    if (val.empty() || val.find_first_of('T')!=std::string::npos || val.find_first_of('F')!=std::string::npos)
                         type = 'B';
                     else
-                        type = val.find_last_of('.')==string::npos ? 'I' : 'F';
+                        type = val.find_last_of('.')==std::string::npos ? 'I' : 'F';
                 }
 
@@ -234,5 +232,5 @@
 
         Table() : offset(0), is_compressed(false) { }
-        Table(const vector<string> &vec, off_t off) : offset(off),
+        Table(const std::vector<std::string> &vec, off_t off) : offset(off),
             keys(ParseBlock(vec))
         {
@@ -270,8 +268,8 @@
             size_t bytes = 0;
 
-            const string tFormName = is_compressed ? "ZFORM" : "TFORM";
+            const std::string tFormName = is_compressed ? "ZFORM" : "TFORM";
             for (long long unsigned int i=1; i<=num_cols; i++)
             {
-                const string num(to_string(i));
+                const std::string num(std::to_string(i));
 
                 if (!Check("TTYPE"+num, 'T') ||
@@ -279,8 +277,8 @@
                     return;
 
-                const string id   = Get<string>("TTYPE"+num);
-                const string fmt  = Get<string>(tFormName+num);
-                const string unit = Get<string>("TUNIT"+num, "");
-                const string comp = Get<string>("ZCTYP"+num, "");
+                const std::string id   = Get<std::string>("TTYPE"+num);
+                const std::string fmt  = Get<std::string>(tFormName+num);
+                const std::string unit = Get<std::string>("TUNIT"+num, "");
+                const std::string comp = Get<std::string>("ZCTYP"+num, "");
 
                 Compression_t compress = kCompUnknown;
@@ -288,5 +286,5 @@
                     compress = kCompFACT;
 
-                istringstream sin(fmt);
+                std::istringstream sin(fmt);
                 int n = 0;
                 sin >> n;
@@ -316,8 +314,8 @@
                 default:
                     {
-                        ostringstream str;
+                        std::ostringstream str;
                         str << "FITS format TFORM='" << fmt << "' not yet supported.";
 #ifdef __EXCEPTIONS
-                        throw runtime_error(str.str());
+                        throw std::runtime_error(str.str());
 #else
                         gLog << ___err___ << "ERROR - " << str.str() << endl;
@@ -337,5 +335,5 @@
             {
 #ifdef __EXCEPTIONS
-                throw runtime_error("Column size mismatch");
+                throw std::runtime_error("Column size mismatch");
 #else
                 gLog << ___err___ << "ERROR - Column size mismatch" << endl;
@@ -344,10 +342,10 @@
             }
 
-            name = Get<string>("EXTNAME");
+            name = Get<std::string>("EXTNAME");
         }
 
         void PrintKeys(bool display_all=false) const
         {
-            for (Keys::const_iterator it=keys.begin(); it!=keys.end(); it++)
+            for (Keys::const_iterator it=keys.cbegin(); it!=keys.cend(); it++)
             {
                 if (!display_all &&
@@ -369,12 +367,12 @@
         void PrintColumns() const
         {
-            typedef map<pair<size_t, string>, Column> Sorted;
+            typedef std::map<std::pair<size_t, std::string>, Column> Sorted;
 
             Sorted sorted;
 
-            for (Columns::const_iterator it=cols.begin(); it!=cols.end(); it++)
-                sorted[make_pair(it->second.offset, it->first)] = it->second;
-
-            for (Sorted::const_iterator it=sorted.begin(); it!=sorted.end(); it++)
+            for (Columns::const_iterator it=cols.cbegin(); it!=cols.cend(); it++)
+                sorted[std::make_pair(it->second.offset, it->first)] = it->second;
+
+            for (Sorted::const_iterator it=sorted.cbegin(); it!=sorted.cend(); it++)
             {
                 gLog << ___all___ << setw(6) << it->second.offset << "| ";
@@ -397,10 +395,10 @@
         operator bool() const { return !name.empty(); }
 
-        bool HasKey(const string &key) const
+        bool HasKey(const std::string &key) const
         {
             return keys.find(key)!=keys.end();
         }
 
-        bool HasColumn(const string& col) const
+        bool HasColumn(const std::string& col) const
         {
             return cols.find(col)!=cols.end();
@@ -419,13 +417,13 @@
         // Values of keys are always signed
         template<typename T>
-            T Get(const string &key) const
-        {
-            const map<string,Entry>::const_iterator it = keys.find(key);
+            T Get(const std::string &key) const
+        {
+            const std::map<std::string,Entry>::const_iterator it = keys.find(key);
             if (it==keys.end())
             {
-                ostringstream str;
-                str << "Key '" << key << "' not found." << endl;
-#ifdef __EXCEPTIONS
-                throw runtime_error(str.str());
+                std::ostringstream str;
+                str << "Key '" << key << "' not found.";
+#ifdef __EXCEPTIONS
+                throw std::runtime_error(str.str());
 #else
                 gLog << ___err___ << "ERROR - " << str.str() << endl;
@@ -438,11 +436,11 @@
         // Values of keys are always signed
         template<typename T>
-            T Get(const string &key, const T &deflt) const
-        {
-            const map<string,Entry>::const_iterator it = keys.find(key);
+            T Get(const std::string &key, const T &deflt) const
+        {
+            const std::map<std::string,Entry>::const_iterator it = keys.find(key);
             return it==keys.end() ? deflt :it->second.Get<T>();
         }
 
-        size_t GetN(const string &key) const
+        size_t GetN(const std::string &key) const
         {
             const Columns::const_iterator it = cols.find(key);
@@ -485,24 +483,24 @@
 
 protected:
-    ofstream fCopy;
+    std::ofstream fCopy;
 
     Table fTable;
 
-    typedef pair<void*, Table::Column> Address;
-    typedef vector<Address> Addresses;
+    typedef std::pair<void*, Table::Column> Address;
+    typedef std::vector<Address> Addresses;
     //map<void*, Table::Column> fAddresses;
     Addresses fAddresses;
 
 #if defined(__MARS__) || defined(__CINT__)
-    typedef map<string, void*> Pointers;
-#else
-    typedef unordered_map<string, void*> Pointers;
+    typedef std::map<std::string, void*> Pointers;
+#else
+    typedef std::unordered_map<std::string, void*> Pointers;
 #endif
     Pointers fPointers;
 
-    vector<vector<char>> fGarbage;
-
-    vector<char> fBufferRow;
-    vector<char> fBufferDat;
+    std::vector<std::vector<char>> fGarbage;
+
+    std::vector<char> fBufferRow;
+    std::vector<char> fBufferDat;
 
     size_t fRow;
@@ -511,5 +509,5 @@
     Checksum fChkData;
 
-    bool ReadBlock(vector<string> &vec)
+    bool ReadBlock(std::vector<std::string> &vec)
     {
         int endtag = 0;
@@ -527,5 +525,5 @@
 //                return vector<string>();
 
-            string str(c);
+            std::string str(c);
 
 //            if (!str.empty())
@@ -554,12 +552,7 @@
     }
 
-    string Compile(const string &key, int16_t i=-1) const
-    {
-        if (i<0)
-            return key;
-
-        ostringstream str;
-        str << key << i;
-        return str.str();
+    std::string Compile(const std::string &key, int16_t i=-1) const
+    {
+        return i<0 ? key : key+std::to_string(i);
     }
 
@@ -577,5 +570,5 @@
             clear(rdstate()|ios::badbit);
 #ifdef __EXCEPTIONS
-            throw runtime_error("File is not a FITS file.");
+            throw std::runtime_error("File is not a FITS file.");
 #else
             gLog << ___err___ << "ERROR - File is not a FITS file." << endl;
@@ -588,5 +581,5 @@
         while (good())
         {
-            vector<string> block;
+            std::vector<std::string> block;
             while (1)
             {
@@ -605,5 +598,5 @@
                     clear(rdstate()|ios::badbit);
 #ifdef __EXCEPTIONS
-                    throw runtime_error("FITS file corrupted.");
+                    throw std::runtime_error("FITS file corrupted.");
 #else
                     gLog << ___err___ << "ERROR - FITS file corrupted." << endl;
@@ -618,5 +611,5 @@
                         clear(rdstate()|ios::badbit);
 #ifdef __EXCEPTIONS
-                        throw runtime_error("END keyword missing in FITS header.");
+                        throw std::runtime_error("END keyword missing in FITS header.");
 #else
                         gLog << ___err___ << "ERROR - END keyword missing in FITS file... file might be corrupted." << endl;
@@ -691,5 +684,5 @@
             clear(rdstate()|ios::badbit);
 #ifdef __EXCEPTIONS
-            throw runtime_error("Could not open output file.");
+            throw std::runtime_error("Could not open output file.");
 #else
             gLog << ___err___ << "ERROR - Failed to open output file." << endl;
@@ -700,5 +693,5 @@
         seekg(0);
 
-        vector<char> buf(p);
+        std::vector<char> buf(p);
         read(buf.data(), p);
 
@@ -709,5 +702,5 @@
 
 public:
-    fits(const string &fname, const string& tableName="", bool force=false) : izstream(fname.c_str())
+    fits(const std::string &fname, const std::string& tableName="", bool force=false) : izstream(fname.c_str())
     {
         Constructor(fname, "", tableName, force);
@@ -716,5 +709,5 @@
         {
 #ifdef __EXCEPTIONS
-            throw runtime_error("You are trying to read a compressed fits with the base fits class. Please use factfits instead.");
+            throw std::runtime_error("You are trying to read a compressed fits with the base fits class. Please use factfits instead.");
 #else
             gLog << ___err___ << "ERROR - You are trying to read a compressed fits with the base fits class. Please use factfits instead." << endl;
@@ -724,5 +717,5 @@
     }
 
-    fits(const string &fname, const string &fout, const string& tableName, bool force=false) : izstream(fname.c_str())
+    fits(const std::string &fname, const std::string &fout, const std::string& tableName, bool force=false) : izstream(fname.c_str())
     {
         Constructor(fname, fout, tableName, force);
@@ -731,5 +724,5 @@
         {
 #ifdef __EXCEPTIONS
-            throw runtime_error("You are trying to read a compressed fits with the base fits class. Please use factfits instead.");
+            throw std::runtime_error("You are trying to read a compressed fits with the base fits class. Please use factfits instead.");
 #else
             gLog << ___err___ << "ERROR - You are trying to read a compressed fits with the base fits class. Please use factfits instead." << endl;
@@ -746,7 +739,7 @@
     ~fits()
     {
-        copy(istreambuf_iterator<char>(*this),
-             istreambuf_iterator<char>(),
-             ostreambuf_iterator<char>(fCopy));
+        std::copy(std::istreambuf_iterator<char>(*this),
+                  std::istreambuf_iterator<char>(),
+                  std::ostreambuf_iterator<char>(fCopy));
     }
 
@@ -776,5 +769,5 @@
     }
 
-    void ZeroBufferForChecksum(vector<char>& vec, const uint64_t extraZeros=0)
+    void ZeroBufferForChecksum(std::vector<char>& vec, const uint64_t extraZeros=0)
     {
         auto ib = vec.begin();
@@ -842,5 +835,5 @@
         const char *ptr = fBufferRow.data() + offset;
 
-        for (Addresses::const_iterator it=fAddresses.begin(); it!=fAddresses.end(); it++)
+        for (Addresses::const_iterator it=fAddresses.cbegin(); it!=fAddresses.cend(); it++)
         {
             const Table::Column &c = it->second;
@@ -876,17 +869,17 @@
 
     template<class T, class S>
-    const T &GetAs(const string &name)
+    const T &GetAs(const std::string &name)
     {
         return *reinterpret_cast<S*>(fPointers[name]);
     }
 
-    void *SetPtrAddress(const string &name)
+    void *SetPtrAddress(const std::string &name)
     {
         if (fTable.cols.count(name)==0)
         {
-            ostringstream str;
-            str << "SetPtrAddress('" << name << "') - Column not found." << endl;
-#ifdef __EXCEPTIONS
-            throw runtime_error(str.str());
+            std::ostringstream str;
+            str << "SetPtrAddress('" << name << "') - Column not found.";
+#ifdef __EXCEPTIONS
+            throw std::runtime_error(str.str());
 #else
             gLog << ___err___ << "ERROR - " << str.str() << endl;
@@ -910,12 +903,12 @@
 
     template<typename T>
-    bool SetPtrAddress(const string &name, T *ptr, size_t cnt)
+    bool SetPtrAddress(const std::string &name, T *ptr, size_t cnt)
     {
         if (fTable.cols.count(name)==0)
         {
-            ostringstream str;
-            str << "SetPtrAddress('" << name << "') - Column not found." << endl;
-#ifdef __EXCEPTIONS
-            throw runtime_error(str.str());
+            std::ostringstream str;
+            str << "SetPtrAddress('" << name << "') - Column not found.";
+#ifdef __EXCEPTIONS
+            throw std::runtime_error(str.str());
 #else
             gLog << ___err___ << "ERROR - " << str.str() << endl;
@@ -926,9 +919,9 @@
         if (sizeof(T)!=fTable.cols[name].size)
         {
-            ostringstream str;
+            std::ostringstream str;
             str << "SetPtrAddress('" << name << "') - Element size mismatch: expected "
-                << fTable.cols[name].size << " from header, got " << sizeof(T) << endl;
-#ifdef __EXCEPTIONS
-            throw runtime_error(str.str());
+                << fTable.cols[name].size << " from header, got " << sizeof(T);
+#ifdef __EXCEPTIONS
+            throw std::runtime_error(str.str());
 #else
             gLog << ___err___ << "ERROR - " << str.str() << endl;
@@ -939,9 +932,9 @@
         if (cnt!=fTable.cols[name].num)
         {
-            ostringstream str;
+            std::ostringstream str;
             str << "SetPtrAddress('" << name << "') - Element count mismatch: expected "
-                << fTable.cols[name].num << " from header, got " << cnt << endl;
-#ifdef __EXCEPTIONS
-            throw runtime_error(str.str());
+                << fTable.cols[name].num << " from header, got " << cnt;
+#ifdef __EXCEPTIONS
+            throw std::runtime_error(str.str());
 #else
             gLog << ___err___ << "ERROR - " << str.str() << endl;
@@ -961,5 +954,5 @@
 
     template<class T>
-    bool SetRefAddress(const string &name, T &ptr)
+    bool SetRefAddress(const std::string &name, T &ptr)
     {
         return SetPtrAddress(name, &ptr, sizeof(ptr)/sizeof(T));
@@ -967,5 +960,5 @@
 
     template<typename T>
-    bool SetVecAddress(const string &name, vector<T> &vec)
+    bool SetVecAddress(const std::string &name, std::vector<T> &vec)
     {
         return SetPtrAddress(name, vec.data(), vec.size());
@@ -973,5 +966,5 @@
 
     template<typename T>
-        T Get(const string &key) const
+        T Get(const std::string &key) const
     {
         return fTable.Get<T>(key);
@@ -979,17 +972,17 @@
 
     template<typename T>
-        T Get(const string &key, const string &deflt) const
+        T Get(const std::string &key, const std::string &deflt) const
     {
         return fTable.Get<T>(key, deflt);
     }
 
-    bool SetPtrAddress(const string &name, void *ptr, size_t cnt=0)
+    bool SetPtrAddress(const std::string &name, void *ptr, size_t cnt=0)
     {
         if (fTable.cols.count(name)==0)
         {
-            ostringstream str;
-            str <<"SetPtrAddress('" << name << "') - Column not found." << endl;
-#ifdef __EXCEPTIONS
-            throw runtime_error(str.str());
+            std::ostringstream str;
+            str <<"SetPtrAddress('" << name << "') - Column not found.";
+#ifdef __EXCEPTIONS
+            throw std::runtime_error(str.str());
 #else
             gLog << ___err___ << "ERROR - " << str.str() << endl;
@@ -1000,9 +993,9 @@
         if (cnt && cnt!=fTable.cols[name].num)
         {
-            ostringstream str;
+            std::ostringstream str;
             str << "SetPtrAddress('" << name << "') - Element count mismatch: expected "
-                << fTable.cols[name].num << " from header, got " << cnt << endl;
-#ifdef __EXCEPTIONS
-            throw runtime_error(str.str());
+                << fTable.cols[name].num << " from header, got " << cnt;
+#ifdef __EXCEPTIONS
+            throw std::runtime_error(str.str());
 #else
             gLog << ___err___ << "ERROR - " << str.str() << endl;
@@ -1021,16 +1014,16 @@
     }
 
-    bool     HasKey(const string &key) const { return fTable.HasKey(key); }
-    bool     HasColumn(const string& col) const { return fTable.HasColumn(col);}
+    bool     HasKey(const std::string &key) const { return fTable.HasKey(key); }
+    bool     HasColumn(const std::string& col) const { return fTable.HasColumn(col);}
     const Table::Columns &GetColumns() const { return fTable.GetColumns();}
     const Table::SortedColumns& GetSortedColumns() const { return fTable.sorted_cols;}
     const Table::Keys &GetKeys() const { return fTable.GetKeys();}
 
-    int64_t  GetInt(const string &key) const { return fTable.Get<int64_t>(key); }
-    uint64_t GetUInt(const string &key) const { return fTable.Get<uint64_t>(key); }
-    double   GetFloat(const string &key) const { return fTable.Get<double>(key); }
-    string   GetStr(const string &key) const { return fTable.Get<string>(key); }
-
-    size_t GetN(const string &key) const
+    int64_t     GetInt(const std::string &key) const { return fTable.Get<int64_t>(key); }
+    uint64_t    GetUInt(const std::string &key) const { return fTable.Get<uint64_t>(key); }
+    double      GetFloat(const std::string &key) const { return fTable.Get<double>(key); }
+    std::string GetStr(const std::string &key) const { return fTable.Get<std::string>(key); }
+
+    size_t GetN(const std::string &key) const
     {
         return fTable.GetN(key);
