Changeset 12996 for trunk/Mars/mcore/fits.h
- Timestamp:
- 03/07/12 14:08:49 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Mars/mcore/fits.h
r12845 r12996 41 41 #endif 42 42 43 #include "checksum.h" 44 43 45 namespace std 44 46 { … … 88 90 Columns cols; 89 91 Keys keys; 92 93 int64_t datasum; 90 94 91 95 string Trim(const string &str, char c=' ') const … … 218 222 num_rows = Get<size_t>("NAXIS2"); 219 223 num_cols = Get<size_t>("TFIELDS"); 224 datasum = Get<int64_t>("DATASUM", -1); 220 225 221 226 size_t bytes = 0; … … 382 387 // Values of keys are always signed 383 388 template<typename T> 384 T Get(const string &key, const string&deflt) const389 T Get(const string &key, const T &deflt) const 385 390 { 386 391 const map<string,Entry>::const_iterator it = keys.find(key); … … 416 421 417 422 size_t fRow; 423 424 Checksum fChkHeader; 425 Checksum fChkData; 418 426 419 427 bool ReadBlock(vector<string> &vec) … … 428 436 break; 429 437 438 fChkHeader.add(c, 80); 439 430 440 // if (c[0]==0) 431 441 // return vector<string>(); … … 527 537 528 538 if (block[0].substr(0, 9)=="SIMPLE =") 539 { 540 fChkHeader.reset(); 529 541 continue; 542 } 530 543 531 544 if (block[0].substr(0, 9)=="XTENSION=") … … 544 557 } 545 558 546 fBufferRow.resize(fTable.bytes_per_row );559 fBufferRow.resize(fTable.bytes_per_row + 4-fTable.bytes_per_row%4); 547 560 fBufferDat.resize(fTable.bytes_per_row); 548 561 … … 565 578 } 566 579 567 voidReadRow(size_t row)580 uint8_t ReadRow(size_t row) 568 581 { 569 582 // if (row!=fRow+1) // Fast seeking is ensured by izstream 570 583 seekg(fTable.offset+row*fTable.bytes_per_row); 571 584 585 // For the checksum we need everything to be correctly aligned 586 const uint8_t offset = (row*fTable.bytes_per_row)%4; 587 588 auto ib = fBufferRow.begin(); 589 auto ie = fBufferRow.end(); 590 *ib++ = 0; 591 *ib++ = 0; 592 *ib++ = 0; 593 *ib = 0; 594 595 *--ie = 0; 596 *--ie = 0; 597 *--ie = 0; 598 *--ie = 0; 599 600 fBufferRow.assign(fBufferRow.size(), 0); 601 602 read(fBufferRow.data()+offset, fTable.bytes_per_row); 603 //fin.clear(fin.rdstate()&~ios::eofbit); 604 605 if (row==fRow+1) 606 fChkData.add(fBufferRow); 607 572 608 fRow = row; 573 609 574 read(fBufferRow.data(), fBufferRow.size()); 575 //fin.clear(fin.rdstate()&~ios::eofbit); 610 return offset; 576 611 } 577 612 … … 586 621 bool GetRow(size_t row) 587 622 { 588 ReadRow(row);623 const uint8_t offset = ReadRow(row); 589 624 if (!good()) 590 625 return good(); 591 626 627 const char *ptr = fBufferRow.data() + offset; 628 592 629 for (Addresses::const_iterator it=fAddresses.begin(); it!=fAddresses.end(); it++) 593 630 { 594 631 const Table::Column &c = it->second; 595 632 596 const char *src = fBufferRow.data()+ c.offset;633 const char *src = ptr + c.offset; 597 634 char *dest = reinterpret_cast<char*>(it->first); 598 635 … … 782 819 void PrintKeys() const { fTable.PrintKeys(); } 783 820 void PrintColumns() const { fTable.PrintColumns(); } 821 822 bool IsHeaderOk() const { return fTable.datasum<0?false:(fChkHeader+Checksum(fTable.datasum)).valid(); } 823 bool IsFileOk() const { return (fChkHeader+fChkData).valid(); } 824 784 825 }; 785 826
Note:
See TracChangeset
for help on using the changeset viewer.