- Timestamp:
- 08/23/11 12:09:46 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/fitsdump.cc
r11578 r11910 14 14 15 15 using namespace std; 16 17 class MyColumn : public CCfits::Column 18 { 19 public: 20 const string &comment() const { return CCfits::Column::comment(); } 21 long width() const 22 {//the width() method seems to be buggy (or empty ?) as it always return 1... redo it ourselves. 23 string inter = format(); 24 inter = inter.substr(0, inter.size()-1); 25 return atoi(inter.c_str()); 26 } 27 }; 16 28 17 29 class FitsDumper … … 25 37 CCfits::FITS *fFile; /// FITS pointer 26 38 CCfits::Table *fTable; /// Table pointer 27 map<string, CCfits::Column*> fColMap; /// map between the column names and their CCfits objects39 map<string, MyColumn*> fColMap; /// map between the column names and their CCfits objects 28 40 29 41 // Convert CCfits::ValueType into a human readable string … … 43 55 44 56 /// Write a single row of the selected data 45 int WriteRow(ostream &, const vector< CCfits::Column*> &, const vector<int> &, unsigned char *) const;57 int WriteRow(ostream &, const vector<MyColumn*> &, const vector<int> &, unsigned char *, const vector<pair<int, int> >&) const; 46 58 47 59 bool OpenFile(const string &); /// Open a file … … 182 194 //! the memory were the row has been loaded by cfitsio 183 195 // 184 int FitsDumper::WriteRow(ostream &out, const vector< CCfits::Column*> &list, const vector<int> &offsets, unsigned char* fitsBuffer) const196 int FitsDumper::WriteRow(ostream &out, const vector<MyColumn*> &list, const vector<int> &offsets, unsigned char* fitsBuffer, const vector<pair<int, int> >& ranges) const 185 197 { 186 198 int cnt = 0; 187 199 188 for (vector<CCfits::Column*>::const_iterator it=list.begin(); it!=list.end(); it++) 189 { 190 const CCfits::Column *col = *it; 200 vector<pair<int, int> >::const_iterator jt = ranges.begin(); 201 for (vector<MyColumn*>::const_iterator it=list.begin(); it!=list.end(); it++, jt++) 202 { 203 const MyColumn *col = *it; 191 204 192 205 // CCfits starts counting at 1 not 0 … … 197 210 198 211 // Loop over all array entries 199 for (int width= 0; width<col->width(); width++)212 for (int width=jt->first; width<jt->second; width++) 200 213 { 201 214 switch (col->type()) … … 243 256 map<int,int> sizes; 244 257 245 for (map<string, CCfits::Column*>::const_iterator it=fColMap.begin();258 for (map<string, MyColumn*>::const_iterator it=fColMap.begin(); 246 259 it!=fColMap.end(); it++) 247 260 { … … 325 338 } 326 339 327 fColMap = fTable->column(); 340 map<string, CCfits::Column*>& tCols = fTable->column(); 341 for (map<string, CCfits::Column*>::const_iterator it = tCols.begin(); it != tCols.end(); it++) 342 { 343 fColMap.insert(make_pair(it->first, static_cast<MyColumn*>(it->second))); 344 } 345 // fColMap = fTable->column(); 328 346 329 347 fTable->makeThisCurrent(); … … 336 354 } 337 355 338 class MyColumn : public CCfits::Column339 {340 public:341 const string &comment() const { return CCfits::Column::comment(); }342 };343 356 344 357 void FitsDumper::List() … … 358 371 CCfits::Table *table = dynamic_cast<CCfits::Table*>(extMap.find(it->first)->second); 359 372 373 table->makeThisCurrent(); 374 table->readData(); 375 360 376 cout << " " << it->first << " [" << table->rows() << "]\n"; 361 377 362 378 const map<string, CCfits::Column*> &cols = table->column(); 379 380 // for (map<string, CCfits::Column*>::const_iterator id = cols.begin(); ib != cols.end(); ib++) 381 // { 382 // TFORM 383 // } 363 384 364 385 for (map<string, CCfits::Column*>::const_iterator ic=cols.begin(); … … 492 513 493 514 // Loop over all columns in our list of requested columns 494 vector<CCfits::Column*> columns; 515 vector<MyColumn*> columns; 516 vector<pair<int, int> > ranges; 495 517 for (vector<string>::const_iterator it=list.begin(); it!=list.end(); it++) 496 columns.push_back(fColMap.find(*it)->second); 497 518 { 519 MyColumn *cCol = static_cast<MyColumn*>(fColMap.find(*it)->second); 520 //CCfits::Column* cCol = fColMap.find(*it)->second; 521 columns.push_back(cCol); 522 int start, end; 523 if (cCol->width() != 1) 524 {//get the desired range of that column to output 525 cout << "Column " << *it << " has " << cCol->width() << " entries. Please tell us which of them should be outputted. " << endl; 526 cout << "Please enter the first value to dump (min 0, max " << cCol->width()-1 << "): "; 527 cin >> start; 528 while (start < 0 || start > cCol->width()-1) 529 { 530 cout << "value invalid. Please stick to the range 0-" << cCol->width()-1 << ": "; 531 cin >> start; 532 } 533 cout << "Please enter the last value to dump (min " << start << ", max " << cCol->width()-1 << "): "; 534 cin >> end; 535 while (end < start || end > cCol->width()-1) 536 { 537 cout << "value invalid. Please stick to the range " << start << "-" << cCol->width()-1 << ": "; 538 cin >> end; 539 } 540 end++; 541 ranges.push_back(make_pair(start, end)); 542 } 543 else 544 { 545 ranges.push_back(make_pair(0, cCol->width())); 546 } 547 } 498 548 499 549 const int size = offsets[offsets.size()-1]; … … 509 559 break; 510 560 } 511 if (WriteRow(out, columns, offsets, fitsBuffer )<0)561 if (WriteRow(out, columns, offsets, fitsBuffer, ranges)<0) 512 562 { 513 563 status=1; … … 623 673 if (conf.Has("outfile")) 624 674 { 675 if (!conf.Has("col")) 676 { 677 cout << "Please specify the columns that should be dumped as arguments. Aborting" << endl; 678 return 0; 679 } 625 680 if (!Dump(conf.Get<string>("outfile"), 626 681 conf.Get<vector<string>>("col"),
Note:
See TracChangeset
for help on using the changeset viewer.