Index: trunk/FACT++/src/fitsdump.cc
===================================================================
--- trunk/FACT++/src/fitsdump.cc	(revision 12727)
+++ trunk/FACT++/src/fitsdump.cc	(revision 12729)
@@ -88,5 +88,5 @@
     /// Lists all columns of an open file
     void List();                          
-    void ListHeader();
+    void ListHeader(const string& filename);
     void ListKeywords(ostream &);
 
@@ -102,4 +102,5 @@
     int doMinMaxPlease(const string& filename, const vector<string>& list, int precision);
     int doStatsPlease(const string &filename, const vector<string>& list, int precision);
+//    void doTBoundary(conf.Get<string>("outfile"), conf.Get<int>("precision"), true);
     //    bool Plot(const vector<string> &list);
 
@@ -253,5 +254,5 @@
 }
 
-void FitsDumper::ListHeader()
+void FitsDumper::ListHeader(const string& filename)
 {
     if (!fFile)
@@ -260,11 +261,17 @@
         return;
     }
-
-    cout << "\nTable: " << fKeyMap.find("EXTNAME")->second.value << " (rows=" << fKeyMap.find("NAXIS2")->second.value << ")\n";
+    ofstream out(filename=="-"?"/dev/stdout":filename);
+    if (!out)
+    {
+        cerr << "Cannot open file " << filename << ": " << strerror(errno) << endl;
+        return;
+    }
+
+    out << "\nTable: " << fKeyMap.find("EXTNAME")->second.value << " (rows=" << fKeyMap.find("NAXIS2")->second.value << ")\n";
     if (fKeyMap.find("COMMENT") != fKeyMap.end())
-        cout << "Comment: \t" << fKeyMap.find("COMMENT")->second.value << "\n";
-
-    ListKeywords(cout);
-    cout << endl;
+        out << "Comment: \t" << fKeyMap.find("COMMENT")->second.value << "\n";
+
+    ListKeywords(out);
+    out << endl;
 
 }
@@ -479,17 +486,28 @@
         return -1;
     }
+
     if (conf.Get<bool>("nozero"))
     {
         fNoZeroPlease = true;
     }
+
+    if (conf.Has("tablename"))
+    {
+        if (!OpenTable(conf.Get<string>("tablename")))
+            return -1;
+    }
+
     if (conf.Get<bool>("list"))
         List();
-
-    if (conf.Has("tablename"))
-    {
-        if (!OpenTable(conf.Get<string>("tablename")))
-            return -1;
-    }
-
+    /*
+    if (conf.Get<bool>("tstart"))
+    {
+        doTBoundary(conf.Get<string>("outfile"), conf.Get<int>("precision"), true);
+    }
+    if (conf.Get<bool>("tstop"))
+    {
+        doTBoundary(conf.Get<string>("outfile"), conf.Get<int>("precision"), false);
+    }
+    */
     if (conf.Get<bool>("minmax"))
     {
@@ -531,5 +549,5 @@
 
     if (conf.Get<bool>("header"))
-        ListHeader();
+        ListHeader(conf.Get<string>("outfile"));
 
     if (conf.Get<bool>("header") || conf.Get<bool>("list"))
@@ -578,5 +596,4 @@
 int FitsDumper::doMinMaxPlease(const string& filename, const vector<string>& list, int precision)
 {
-
     //first of all, let's separate the columns from their ranges and check that the requested columns are indeed part of the file
     vector<pair<int, int> > ranges;
@@ -689,4 +706,119 @@
 }
 
+/*
+void FitsDumper::doTBoundary(const string& filename, int precision, bool tStop)
+{
+
+    //first of all, let's separate the columns from their ranges and check that the requested columns are indeed part of the file
+     vector<pair<int, int> > ranges;
+     vector<string> listNamesOnly;
+
+     if (!separateColumnsFromRanges(list, ranges, listNamesOnly))
+     {
+         cerr << "Something went wrong while extracting the columns names from parameters. Aborting" << endl;
+         return false;
+     }
+
+     ofstream out(filename=="-"?"/dev/stdout":filename);
+     if (!out)
+     {
+         cerr << "Cannot open file " << filename << ": " << strerror(errno) << endl;
+         return false;
+     }
+
+     out.precision(precision);
+
+     // Loop over all columns in our list of requested columns
+     vector<pair<char, char*> > columnsData;
+     vector<minMaxStruct> statData;
+     int numRows = fFile->GetInt("NAXIS2");
+     auto rangesIt = ranges.begin();
+     for (vector<string>::const_iterator it=listNamesOnly.begin(); it!=listNamesOnly.end(); it++, rangesIt++)
+     {
+         fits::Table::Column& cCol = fColMap.find(*it)->second;
+         columnsData.push_back(make_pair(cCol.type, new char[cCol.num*cCol.size]));
+ //        minMaxStuct initData;
+         statData.push_back(minMaxStruct());
+         fFile->SetPtrAddress(*it, columnsData[columnsData.size()-1].second);
+     }
+
+     int row = 0;
+     while (fFile->GetNextRow() && row < numRows)
+     {
+         rangesIt = ranges.begin();
+         auto statsIt = statData.begin();
+         for (auto it=columnsData.begin(); it != columnsData.end(); it++, rangesIt++, statsIt++)
+         {
+             double cValue = 0;
+             for (int i=rangesIt->first; i<rangesIt->second; i++)
+             {
+             switch (it->first) {
+                 case 'L':
+                         cValue = reinterpret_cast<bool*>(it->second)[i];
+                         break;
+                 case 'B':
+                         cValue = reinterpret_cast<bool*>(it->second)[i];
+                         break;
+                 case 'I':
+                         cValue = reinterpret_cast<int16_t*>(it->second)[i];
+                         break;
+                 case 'J':
+                         cValue = reinterpret_cast<int32_t*>(it->second)[i];
+                         break;
+                 case 'K':
+                         cValue = reinterpret_cast<int64_t*>(it->second)[i];
+                         break;
+                 case 'E':
+                         cValue = reinterpret_cast<float*>(it->second)[i];
+                         break;
+                 case 'D':
+                         cValue = reinterpret_cast<double*>(it->second)[i];
+                         break;
+                 default:
+                     ;
+             }
+             if (!fNoZeroPlease || cValue != 0)
+             {
+                 statsIt->average += cValue;
+                 if (cValue < statsIt->min)
+                     statsIt->min = cValue;
+                 if (cValue > statsIt->max)
+                     statsIt->max = cValue;
+                 statsIt->numValues++;
+             }
+             }
+         }
+         row++;
+     }
+     for (auto it = columnsData.begin(); it != columnsData.end(); it++)
+         delete[] it->second;
+
+     //okay. So now I've got ALL the data, loaded.
+     //let's do the summing and averaging in a safe way (i.e. avoid overflow of variables as much as possible)
+     rangesIt = ranges.begin();
+     auto statsIt = statData.begin();
+
+     auto nameIt = listNamesOnly.begin();
+     for (auto it=columnsData.begin(); it != columnsData.end(); it++, rangesIt++, statsIt++, nameIt++)
+     {
+         int span = rangesIt->second - rangesIt->first;
+         cout << *nameIt << ": " << endl;
+         if (statsIt->numValues != 0)
+         {
+             statsIt->average /= statsIt->numValues;
+             out << "min: " << statsIt->min << endl;
+             out << "max: " << statsIt->max << endl;
+             out << "mea: " << statsIt->average << endl;
+         }
+         else
+         {
+             out << "min: 0" << endl << "max: 0" << endl << "mea: " << endl;
+         }
+
+     }
+     return true;
+
+}
+*/
 template<typename T>
 void displayStats(char* array, int numElems, ofstream& out)
@@ -1114,4 +1246,6 @@
         ("minmax,m",    po_switch(),                "Calculates min and max of data")
         ("nozero,z",    po_switch(),                "skip 0 values for stats")
+        ("tstart,a",    po_switch(),                "Give the mjdStart from reading the file data")
+        ("tstop,b",     po_switch(),                "Give the mjdStop from reading the file data")
 #ifdef PLOTTING_PLEASE
         ("graph,g",     po_switch(),                "Plot the columns instead of dumping them")
