Changeset 17393
- Timestamp:
- 11/26/13 19:16:38 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/fitsdump.cc
r17291 r17393 72 72 /// Lists all columns of an open file 73 73 void List(); 74 void ListFileContent( const string& filename);74 void ListFileContent() const; 75 75 void ListHeader(const string& filename); 76 76 void ListKeywords(ostream &); … … 166 166 } 167 167 168 void FitsDumper::ListFileContent(const string& filename) 169 { 170 ofstream fout(filename=="-"?"/dev/stdout":filename); 171 if (!fout) 172 { 173 cerr << "Cannot open file " << filename << ": " << strerror(errno) << endl; 174 return; 175 } 176 177 int table_id = 0; 178 179 vector<string> table_names; 180 vector<uint32_t> table_rows; 181 try 182 { 183 184 while (true) 185 { 186 clear(); 187 seekg(0); 188 fTable = Table(); 189 Constructor(fFilename, "", "", false, table_id); 190 191 table_names.push_back(fTable.Get<string>("EXTNAME")); 192 table_rows.push_back(GetNumRows()); 193 194 table_id++; 195 } 196 } 197 catch (runtime_error e) 198 { 199 //nothing to see here, just catching the error thrown by EOF 200 } 201 202 fout << "File " << fFilename << " has " << table_names.size() << " tables: " << endl; 203 for (uint32_t i=0; i<table_names.size(); i++) 204 { 205 fout << "#" << i << ": \"" << table_names[i]; 206 fout << "\" num. rows = " << table_rows[i] << endl; 207 } 208 } 168 void FitsDumper::ListFileContent() const 169 { 170 const std::vector<std::string> &tables = GetTables(); 171 172 cout << "File " << fFilename << " has " << tables.size() << " table(s): " << endl; 173 for (auto it=tables.begin(); it!=tables.end(); it++) 174 cout << " * " << *it << endl; 175 } 176 209 177 void FitsDumper::ListHeader(const string& filename) 210 178 { … … 607 575 break; 608 576 609 ostringstream id; 610 id << '[' << p << ']'; 611 612 it->replace(ibeg-it->begin()+what.position(1), what.length()-1, id.str()); 613 614 ibeg = what[0].first+3; 577 const string id = '['+to_string(p)+']'; 578 579 // Replace might reallocate the memory. Therefore, we cannot use what[0].first 580 // directly but have to store the offset 581 const size_t offset = what[0].first - it->begin(); 582 583 it->replace(ibeg-it->begin()+what.position(1), what.length()-1, id); 584 585 ibeg = it->begin() + offset + id.size(); 615 586 iend = it->end(); 616 587 … … 972 943 973 944 if (conf.Get<bool>("filecontent")) 974 ListFileContent( conf.Get<string>("outfile"));945 ListFileContent(); 975 946 976 947 if (conf.Get<bool>("header")) … … 1135 1106 po::options_description configs("Fitsdump options"); 1136 1107 configs.add_options() 1137 ("fitsfile,f", var<string>() 1108 ("filecontent", po_switch(), "List the number of tables in the file, along with their name") 1109 ("header,h", po_switch(), "Dump header of given table") 1110 ("list,l", po_switch(), "List all tables and columns in file") 1111 ("fitsfile", var<string>() 1138 1112 #if BOOST_VERSION >= 104200 1139 1113 ->required() 1140 1114 #endif 1141 1115 , "Name of FITS file") 1142 ("col,c", vars<string>(), "List of columns to dump\narg is a list of columns, separated by a space.\nAdditionnally, a list of sub-columns can be added\ne.g. Data[3] will dump sub-column 3 of column Data\nData[3:4] will dump sub-columns 3 and 4\nOmitting this argument dump the entire column\nnot a: all indices start at zero")1116 ("col,c", vars<string>(), "List of columns to dump\narg is a list of columns, separated by a space.\nAdditionnally, a list of sub-columns can be added\ne.g. Data[3] will dump sub-column 3 of column Data\nData[3:4] will dump sub-columns 3 and 4\nOmitting this argument dump the entire column\nnote: all indices start at zero") 1143 1117 ("outfile,o", var<string>("-"), "Name of output file (-:/dev/stdout)") 1144 1118 ("precision,p", var<int>(20), "Precision of ofstream") 1145 ("list,l", po_switch(), "List all tables and columns in file")1146 ("header,h", po_switch(), "Dump header of given table")1147 1119 ("stat,s", po_switch(), "Perform statistics instead of dump") 1148 1120 ("minmax,m", po_switch(), "Calculates min and max of data") … … 1155 1127 ("limit", var<size_t>(size_t(0)), "Limit for the maximum number of rows to read (0=unlimited)") 1156 1128 ("tablename,t", var<string>(""), "Name of the table to open. If not specified, first binary table is opened") 1157 ("filecontent", po_switch(), "List the number of tables in the file, along with their name")1158 1129 #ifdef HAVE_ROOT 1159 1130 ("root,r", po_switch(), "Enable root mode")
Note:
See TracChangeset
for help on using the changeset viewer.