- Timestamp:
- 02/09/12 18:43:38 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/fitsdump.cc
r12884 r12885 132 132 } 133 133 134 void FitsDumper::ListKeywords(ostream & out)134 void FitsDumper::ListKeywords(ostream &fout) 135 135 { 136 136 const fits::Table::Keys &fKeyMap = GetKeys(); 137 137 138 138 for (auto it=fKeyMap.begin(); it != fKeyMap.end(); it++) { 139 out << "## " << setw(8) << it->first << " = " << setw(10);140 out << "'" << it->second.value << "'" << " / " << it->second.comment << endl;139 fout << "## " << setw(8) << it->first << " = " << setw(10); 140 fout << "'" << it->second.value << "'" << " / " << it->second.comment << endl; 141 141 } 142 142 } … … 144 144 void FitsDumper::ListHeader(const string& filename) 145 145 { 146 ofstream out(filename=="-"?"/dev/stdout":filename);147 if (! out)146 ofstream fout(filename=="-"?"/dev/stdout":filename); 147 if (!fout) 148 148 { 149 149 cerr << "Cannot open file " << filename << ": " << strerror(errno) << endl; … … 153 153 const fits::Table::Keys &fKeyMap = GetKeys(); 154 154 155 out << "\nTable: " << fKeyMap.find("EXTNAME")->second.value << " (rows=" << fKeyMap.find("NAXIS2")->second.value << ")\n";155 fout << "\nTable: " << fKeyMap.find("EXTNAME")->second.value << " (rows=" << fKeyMap.find("NAXIS2")->second.value << ")\n"; 156 156 if (fKeyMap.find("COMMENT") != fKeyMap.end()) 157 out << "Comment: \t" << fKeyMap.find("COMMENT")->second.value << "\n"; 158 159 ListKeywords(out); 160 out << endl; 161 157 fout << "Comment: \t" << fKeyMap.find("COMMENT")->second.value << "\n"; 158 159 ListKeywords(fout); 160 fout << endl; 162 161 } 163 162 … … 235 234 //! Perform the actual dump, based on the current parameters 236 235 // 237 void FitsDumper::Dump(ofstream & out, const vector<MyColumn> &cols, const string &filename)236 void FitsDumper::Dump(ofstream &fout, const vector<MyColumn> &cols, const string &filename) 238 237 { 239 238 const fits::Table::Keys &fKeyMap = GetKeys(); 240 239 241 out << "## --------------------------------------------------------------------------\n";242 out << "## Fits file:\t" << fFilename << '\n';240 fout << "## --------------------------------------------------------------------------\n"; 241 fout << "## Fits file:\t" << fFilename << '\n'; 243 242 if (filename!="-") 244 out << "## File: \t" << filename << '\n';245 out << "## Table: \t" << fKeyMap.find("EXTNAME")->second.value << '\n';246 out << "## NumRows: \t" << GetInt("NAXIS2") << '\n';247 out << "## Comment: \t" << ((fKeyMap.find("COMMENT") != fKeyMap.end()) ? fKeyMap.find("COMMENT")->second.value : "") << '\n';248 out << "## --------------------------------------------------------------------------\n";249 ListKeywords( out);250 out << "## --------------------------------------------------------------------------\n";251 out << "#\n";243 fout << "## File: \t" << filename << '\n'; 244 fout << "## Table: \t" << fKeyMap.find("EXTNAME")->second.value << '\n'; 245 fout << "## NumRows: \t" << GetInt("NAXIS2") << '\n'; 246 fout << "## Comment: \t" << ((fKeyMap.find("COMMENT") != fKeyMap.end()) ? fKeyMap.find("COMMENT")->second.value : "") << '\n'; 247 fout << "## --------------------------------------------------------------------------\n"; 248 ListKeywords(fout); 249 fout << "## --------------------------------------------------------------------------\n"; 250 fout << "#\n"; 252 251 253 252 for (auto it=cols.begin(); it!=cols.end(); it++) 254 253 { 255 out << "# " << it->name;254 fout << "# " << it->name; 256 255 257 256 if (it->first==it->last) 258 257 { 259 258 if (it->first!=0) 260 out << "[" << it->first << "]";259 fout << "[" << it->first << "]"; 261 260 } 262 261 else 263 out << "[" << it->first << ":" << it->last << "]";264 265 out << ": " << it->col.unit << '\n';266 } 267 out << "#" << endl;262 fout << "[" << it->first << ":" << it->last << "]"; 263 264 fout << ": " << it->col.unit << '\n'; 265 } 266 fout << "#" << endl; 268 267 269 268 // ----------------------------------------------------------------- … … 286 285 break; 287 286 case 'B': 288 out << (unsigned int)reinterpret_cast<const unsigned char*>(it->ptr)[i] << " ";287 fout << (unsigned int)reinterpret_cast<const unsigned char*>(it->ptr)[i] << " "; 289 288 break; 290 289 case 'L': 291 out << reinterpret_cast<const bool*>(it->ptr)[i] << " ";290 fout << reinterpret_cast<const bool*>(it->ptr)[i] << " "; 292 291 break; 293 292 case 'I': 294 out << reinterpret_cast<const int16_t*>(it->ptr)[i] << " ";293 fout << reinterpret_cast<const int16_t*>(it->ptr)[i] << " "; 295 294 break; 296 295 case 'J': 297 out << reinterpret_cast<const int32_t*>(it->ptr)[i] << " ";296 fout << reinterpret_cast<const int32_t*>(it->ptr)[i] << " "; 298 297 break; 299 298 case 'K': 300 out << reinterpret_cast<const int64_t*>(it->ptr)[i] << " ";299 fout << reinterpret_cast<const int64_t*>(it->ptr)[i] << " "; 301 300 break; 302 301 case 'E': 303 out << reinterpret_cast<const float*>(it->ptr)[i] << " ";302 fout << reinterpret_cast<const float*>(it->ptr)[i] << " "; 304 303 break; 305 304 case 'D': 306 out << reinterpret_cast<const double*>(it->ptr)[i] << " ";305 fout << reinterpret_cast<const double*>(it->ptr)[i] << " "; 307 306 break; 308 307 default: … … 312 311 313 312 if (it->col.type=='A') 314 out << "'" << msg << "' ";315 } 316 out << endl;317 } 318 } 319 320 void FitsDumper::DumpMinMax(ofstream & out, const vector<MyColumn> &cols, bool fNoZeroPlease)313 fout << "'" << msg << "' "; 314 } 315 fout << endl; 316 } 317 } 318 319 void FitsDumper::DumpMinMax(ofstream &fout, const vector<MyColumn> &cols, bool fNoZeroPlease) 321 320 { 322 321 vector<minMaxStruct> statData(cols.size()); … … 331 330 auto statsIt = statData.begin(); 332 331 333 for (auto i n=cols.begin(); in!=cols.end(); in++, statsIt++)334 { 335 if ((i n->name=="UnixTimeUTC" || in->name=="PCTime") && in->first==0 && in->last==1)332 for (auto it=cols.begin(); it!=cols.end(); it++, statsIt++) 333 { 334 if ((it->name=="UnixTimeUTC" || it->name=="PCTime") && it->first==0 && it->last==1) 336 335 { 337 const uint32_t *val = reinterpret_cast<const uint32_t*>(i n->ptr);336 const uint32_t *val = reinterpret_cast<const uint32_t*>(it->ptr); 338 337 if (fNoZeroPlease && val[0]==0 && val[1]==0) 339 338 continue; … … 343 342 } 344 343 345 for (uint32_t i=i n->first; i<=in->last; i++)344 for (uint32_t i=it->first; i<=it->last; i++) 346 345 { 347 346 double cValue = 0; 348 switch (i n->col.type)347 switch (it->col.type) 349 348 { 350 349 case 'L': 351 cValue = reinterpret_cast<const bool*>(i n->ptr)[i];350 cValue = reinterpret_cast<const bool*>(it->ptr)[i]; 352 351 break; 353 352 case 'B': 354 cValue = reinterpret_cast<const int8_t*>(i n->ptr)[i];353 cValue = reinterpret_cast<const int8_t*>(it->ptr)[i]; 355 354 break; 356 355 case 'I': 357 cValue = reinterpret_cast<const int16_t*>(i n->ptr)[i];356 cValue = reinterpret_cast<const int16_t*>(it->ptr)[i]; 358 357 break; 359 358 case 'J': 360 cValue = reinterpret_cast<const int32_t*>(i n->ptr)[i];359 cValue = reinterpret_cast<const int32_t*>(it->ptr)[i]; 361 360 break; 362 361 case 'K': 363 cValue = reinterpret_cast<const int64_t*>(i n->ptr)[i];362 cValue = reinterpret_cast<const int64_t*>(it->ptr)[i]; 364 363 break; 365 364 case 'E': 366 cValue = reinterpret_cast<const float*>(i n->ptr)[i];365 cValue = reinterpret_cast<const float*>(it->ptr)[i]; 367 366 break; 368 367 case 'D': 369 cValue = reinterpret_cast<const double*>(i n->ptr)[i];368 cValue = reinterpret_cast<const double*>(it->ptr)[i]; 370 369 break; 371 370 default: … … 387 386 for (auto it=cols.begin(); it!=cols.end(); it++, statsIt++) 388 387 { 389 cout << "\n[" << it->name << ':' << it->first;388 fout << "\n[" << it->name << ':' << it->first; 390 389 if (it->first!=it->last) 391 cout << ':' << it->last;392 cout << "]\n";390 fout << ':' << it->last; 391 fout << "]\n"; 393 392 394 393 if (statsIt->numValues == 0) 395 394 { 396 out << "Min: -\nMax: -\nAvg: -\nRms: -" << endl;395 fout << "Min: -\nMax: -\nAvg: -\nRms: -" << endl; 397 396 continue; 398 397 } … … 406 405 rms = sqrt(rms/num - avg*avg); 407 406 408 out << "Min: " << statsIt->min << '\n';409 out << "Max: " << statsIt->max << '\n';410 out << "Avg: " << avg << '\n';411 out << "Rms: " << rms << endl;407 fout << "Min: " << statsIt->min << '\n'; 408 fout << "Max: " << statsIt->max << '\n'; 409 fout << "Avg: " << avg << '\n'; 410 fout << "Rms: " << rms << endl; 412 411 } 413 412 } … … 454 453 } 455 454 456 void FitsDumper::DumpStats(ofstream & out, const vector<MyColumn> &cols)455 void FitsDumper::DumpStats(ofstream &fout, const vector<MyColumn> &cols) 457 456 { 458 457 // Loop over all columns in our list of requested columns 459 458 vector<vector<char>> statData; 460 459 461 for (auto i n=cols.begin(); in!=cols.end(); in++)462 statData.push_back(vector<char>(i n->col.size*GetNumRows()*(in->last-in->first+1)));460 for (auto it=cols.begin(); it!=cols.end(); it++) 461 statData.push_back(vector<char>(it->col.size*GetNumRows()*(it->last-it->first+1))); 463 462 464 463 while (GetNextRow()) … … 469 468 470 469 auto statsIt = statData.begin(); 471 for (auto i n=cols.begin(); in!=cols.end(); in++, statsIt++)472 { 473 const char *src = reinterpret_cast<const char*>(i n->ptr);474 const size_t sz = (i n->last-in->first+1)*in->col.size;475 memcpy(statsIt->data()+row*sz, src+i n->first*in->col.size, sz);470 for (auto it=cols.begin(); it!=cols.end(); it++, statsIt++) 471 { 472 const char *src = reinterpret_cast<const char*>(it->ptr); 473 const size_t sz = (it->last-it->first+1)*it->col.size; 474 memcpy(statsIt->data()+row*sz, src+it->first*it->col.size, sz); 476 475 } 477 476 } 478 477 479 478 auto statsIt = statData.begin(); 480 for (auto i n=cols.begin(); in!=cols.end(); in++, statsIt++)481 { 482 out << "\n[" << in->name << ':' << in->first;483 if (i n->last!=in->first)484 out << ':' << in->last;485 out << "]\n";486 487 switch (i n->col.type)479 for (auto it=cols.begin(); it!=cols.end(); it++, statsIt++) 480 { 481 fout << "\n[" << it->name << ':' << it->first; 482 if (it->last!=it->first) 483 fout << ':' << it->last; 484 fout << "]\n"; 485 486 switch (it->col.type) 488 487 { 489 488 case 'L': 490 displayStats<bool>(*statsIt, out);489 displayStats<bool>(*statsIt, fout); 491 490 break; 492 491 case 'B': 493 displayStats<char>(*statsIt, out);492 displayStats<char>(*statsIt, fout); 494 493 break; 495 494 case 'I': 496 displayStats<int16_t>(*statsIt, out);495 displayStats<int16_t>(*statsIt, fout); 497 496 break; 498 497 case 'J': 499 displayStats<int32_t>(*statsIt, out);498 displayStats<int32_t>(*statsIt, fout); 500 499 break; 501 500 case 'K': 502 displayStats<int64_t>(*statsIt, out);501 displayStats<int64_t>(*statsIt, fout); 503 502 break; 504 503 case 'E': 505 displayStats<float>(*statsIt, out);504 displayStats<float>(*statsIt, fout); 506 505 break; 507 506 case 'D': 508 displayStats<double>(*statsIt, out);507 displayStats<double>(*statsIt, fout); 509 508 break; 510 509 default: … … 555 554 const string filename = conf.Get<string>("outfile"); 556 555 557 ofstream out(filename=="-"?"/dev/stdout":filename);558 if (! out)556 ofstream fout(filename=="-"?"/dev/stdout":filename); 557 if (!fout) 559 558 { 560 559 cerr << "Cannot open file " << filename << ": " << strerror(errno) << endl; 561 560 return false; 562 561 } 563 out.precision(conf.Get<int>("precision"));562 fout.precision(conf.Get<int>("precision")); 564 563 565 564 const vector<MyColumn> cols = InitColumns(conf.Vec<string>("col")); … … 569 568 if (conf.Get<bool>("minmax")) 570 569 { 571 DumpMinMax( out, cols, conf.Get<bool>("nozero"));570 DumpMinMax(fout, cols, conf.Get<bool>("nozero")); 572 571 return 0; 573 572 } … … 575 574 if (conf.Get<bool>("stat")) 576 575 { 577 DumpStats( out, cols);576 DumpStats(fout, cols); 578 577 return 0; 579 578 } 580 579 581 Dump( out, cols, filename);580 Dump(fout, cols, filename); 582 581 583 582 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.