Changeset 12729
- Timestamp:
- 12/21/11 13:57:24 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/fitsdump.cc
r12727 r12729 88 88 /// Lists all columns of an open file 89 89 void List(); 90 void ListHeader( );90 void ListHeader(const string& filename); 91 91 void ListKeywords(ostream &); 92 92 … … 102 102 int doMinMaxPlease(const string& filename, const vector<string>& list, int precision); 103 103 int doStatsPlease(const string &filename, const vector<string>& list, int precision); 104 // void doTBoundary(conf.Get<string>("outfile"), conf.Get<int>("precision"), true); 104 105 // bool Plot(const vector<string> &list); 105 106 … … 253 254 } 254 255 255 void FitsDumper::ListHeader( )256 void FitsDumper::ListHeader(const string& filename) 256 257 { 257 258 if (!fFile) … … 260 261 return; 261 262 } 262 263 cout << "\nTable: " << fKeyMap.find("EXTNAME")->second.value << " (rows=" << fKeyMap.find("NAXIS2")->second.value << ")\n"; 263 ofstream out(filename=="-"?"/dev/stdout":filename); 264 if (!out) 265 { 266 cerr << "Cannot open file " << filename << ": " << strerror(errno) << endl; 267 return; 268 } 269 270 out << "\nTable: " << fKeyMap.find("EXTNAME")->second.value << " (rows=" << fKeyMap.find("NAXIS2")->second.value << ")\n"; 264 271 if (fKeyMap.find("COMMENT") != fKeyMap.end()) 265 cout << "Comment: \t" << fKeyMap.find("COMMENT")->second.value << "\n";266 267 ListKeywords( cout);268 cout << endl;272 out << "Comment: \t" << fKeyMap.find("COMMENT")->second.value << "\n"; 273 274 ListKeywords(out); 275 out << endl; 269 276 270 277 } … … 479 486 return -1; 480 487 } 488 481 489 if (conf.Get<bool>("nozero")) 482 490 { 483 491 fNoZeroPlease = true; 484 492 } 493 494 if (conf.Has("tablename")) 495 { 496 if (!OpenTable(conf.Get<string>("tablename"))) 497 return -1; 498 } 499 485 500 if (conf.Get<bool>("list")) 486 501 List(); 487 488 if (conf.Has("tablename")) 489 { 490 if (!OpenTable(conf.Get<string>("tablename"))) 491 return -1; 492 } 493 502 /* 503 if (conf.Get<bool>("tstart")) 504 { 505 doTBoundary(conf.Get<string>("outfile"), conf.Get<int>("precision"), true); 506 } 507 if (conf.Get<bool>("tstop")) 508 { 509 doTBoundary(conf.Get<string>("outfile"), conf.Get<int>("precision"), false); 510 } 511 */ 494 512 if (conf.Get<bool>("minmax")) 495 513 { … … 531 549 532 550 if (conf.Get<bool>("header")) 533 ListHeader( );551 ListHeader(conf.Get<string>("outfile")); 534 552 535 553 if (conf.Get<bool>("header") || conf.Get<bool>("list")) … … 578 596 int FitsDumper::doMinMaxPlease(const string& filename, const vector<string>& list, int precision) 579 597 { 580 581 598 //first of all, let's separate the columns from their ranges and check that the requested columns are indeed part of the file 582 599 vector<pair<int, int> > ranges; … … 689 706 } 690 707 708 /* 709 void FitsDumper::doTBoundary(const string& filename, int precision, bool tStop) 710 { 711 712 //first of all, let's separate the columns from their ranges and check that the requested columns are indeed part of the file 713 vector<pair<int, int> > ranges; 714 vector<string> listNamesOnly; 715 716 if (!separateColumnsFromRanges(list, ranges, listNamesOnly)) 717 { 718 cerr << "Something went wrong while extracting the columns names from parameters. Aborting" << endl; 719 return false; 720 } 721 722 ofstream out(filename=="-"?"/dev/stdout":filename); 723 if (!out) 724 { 725 cerr << "Cannot open file " << filename << ": " << strerror(errno) << endl; 726 return false; 727 } 728 729 out.precision(precision); 730 731 // Loop over all columns in our list of requested columns 732 vector<pair<char, char*> > columnsData; 733 vector<minMaxStruct> statData; 734 int numRows = fFile->GetInt("NAXIS2"); 735 auto rangesIt = ranges.begin(); 736 for (vector<string>::const_iterator it=listNamesOnly.begin(); it!=listNamesOnly.end(); it++, rangesIt++) 737 { 738 fits::Table::Column& cCol = fColMap.find(*it)->second; 739 columnsData.push_back(make_pair(cCol.type, new char[cCol.num*cCol.size])); 740 // minMaxStuct initData; 741 statData.push_back(minMaxStruct()); 742 fFile->SetPtrAddress(*it, columnsData[columnsData.size()-1].second); 743 } 744 745 int row = 0; 746 while (fFile->GetNextRow() && row < numRows) 747 { 748 rangesIt = ranges.begin(); 749 auto statsIt = statData.begin(); 750 for (auto it=columnsData.begin(); it != columnsData.end(); it++, rangesIt++, statsIt++) 751 { 752 double cValue = 0; 753 for (int i=rangesIt->first; i<rangesIt->second; i++) 754 { 755 switch (it->first) { 756 case 'L': 757 cValue = reinterpret_cast<bool*>(it->second)[i]; 758 break; 759 case 'B': 760 cValue = reinterpret_cast<bool*>(it->second)[i]; 761 break; 762 case 'I': 763 cValue = reinterpret_cast<int16_t*>(it->second)[i]; 764 break; 765 case 'J': 766 cValue = reinterpret_cast<int32_t*>(it->second)[i]; 767 break; 768 case 'K': 769 cValue = reinterpret_cast<int64_t*>(it->second)[i]; 770 break; 771 case 'E': 772 cValue = reinterpret_cast<float*>(it->second)[i]; 773 break; 774 case 'D': 775 cValue = reinterpret_cast<double*>(it->second)[i]; 776 break; 777 default: 778 ; 779 } 780 if (!fNoZeroPlease || cValue != 0) 781 { 782 statsIt->average += cValue; 783 if (cValue < statsIt->min) 784 statsIt->min = cValue; 785 if (cValue > statsIt->max) 786 statsIt->max = cValue; 787 statsIt->numValues++; 788 } 789 } 790 } 791 row++; 792 } 793 for (auto it = columnsData.begin(); it != columnsData.end(); it++) 794 delete[] it->second; 795 796 //okay. So now I've got ALL the data, loaded. 797 //let's do the summing and averaging in a safe way (i.e. avoid overflow of variables as much as possible) 798 rangesIt = ranges.begin(); 799 auto statsIt = statData.begin(); 800 801 auto nameIt = listNamesOnly.begin(); 802 for (auto it=columnsData.begin(); it != columnsData.end(); it++, rangesIt++, statsIt++, nameIt++) 803 { 804 int span = rangesIt->second - rangesIt->first; 805 cout << *nameIt << ": " << endl; 806 if (statsIt->numValues != 0) 807 { 808 statsIt->average /= statsIt->numValues; 809 out << "min: " << statsIt->min << endl; 810 out << "max: " << statsIt->max << endl; 811 out << "mea: " << statsIt->average << endl; 812 } 813 else 814 { 815 out << "min: 0" << endl << "max: 0" << endl << "mea: " << endl; 816 } 817 818 } 819 return true; 820 821 } 822 */ 691 823 template<typename T> 692 824 void displayStats(char* array, int numElems, ofstream& out) … … 1114 1246 ("minmax,m", po_switch(), "Calculates min and max of data") 1115 1247 ("nozero,z", po_switch(), "skip 0 values for stats") 1248 ("tstart,a", po_switch(), "Give the mjdStart from reading the file data") 1249 ("tstop,b", po_switch(), "Give the mjdStop from reading the file data") 1116 1250 #ifdef PLOTTING_PLEASE 1117 1251 ("graph,g", po_switch(), "Plot the columns instead of dumping them")
Note:
See TracChangeset
for help on using the changeset viewer.