Changeset 17216 for trunk/Mars/mcore
- Timestamp:
- 10/11/13 17:11:13 (11 years ago)
- Location:
- trunk/Mars/mcore
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Mars/mcore/fits.h
r17206 r17216 267 267 num_cols = Get<size_t>("TFIELDS"); 268 268 datasum = is_compressed ? Get<int64_t>("ZDATASUM", -1) : Get<int64_t>("DATASUM", -1); 269 269 //cout << "IS COMPRESSED =-========= " << is_compressed << " " << Get<size_t>("NAXIS1") << endl; 270 270 size_t bytes = 0; 271 271 … … 456 456 streamoff GetHeapShift() const 457 457 { 458 if (!HasKey(" THEAP"))458 if (!HasKey("ZHEAPPTR")) 459 459 return 0; 460 460 461 const size_t shift = Get<size_t>(" THEAP");461 const size_t shift = Get<size_t>("ZHEAPPTR"); 462 462 return shift <= total_bytes ? 0 : shift - total_bytes; 463 463 } -
trunk/Mars/mcore/ofits.h
r17141 r17216 308 308 } 309 309 310 protected: 310 311 struct Table 311 312 { … … 363 364 this->open(fname); 364 365 } 365 ~ofits() { close(); }366 367 v oid open(const char * filename, bool addEXTNAMEKey=true)366 ~ofits() { if (is_open()) close(); } 367 368 virtual void open(const char * filename, bool addEXTNAMEKey=true) 368 369 { 369 370 fDataSum = 0; … … 509 510 } 510 511 512 string CommentFromType(char type) 513 { 514 string comment; 515 516 switch (type) 517 { 518 case 'L': comment = "1-byte BOOL]"; break; 519 case 'A': comment = "1-byte CHAR]"; break; 520 case 'B': comment = "1-byte BOOL]"; break; 521 case 'I': comment = "2-byte INT]"; break; 522 case 'J': comment = "4-byte INT]"; break; 523 case 'K': comment = "8-byte INT]"; break; 524 case 'E': comment = "4-byte FLOAT]"; break; 525 case 'D': comment = "8-byte FLOAT]"; break; 526 case 'Q': comment = "var. Length]"; break; 527 } 528 529 return comment; 530 } 531 532 uint32_t SizeFromType(char type) 533 { 534 size_t size = 0; 535 536 switch (type) 537 { 538 case 'L': size = 1; break; 539 case 'A': size = 1; break; 540 case 'B': size = 1; break; 541 case 'I': size = 2; break; 542 case 'J': size = 4; break; 543 case 'K': size = 8; break; 544 case 'E': size = 4; break; 545 case 'D': size = 8; break; 546 case 'Q': size = 16; break; 547 } 548 549 return size; 550 } 511 551 //ETIENNE to be able to restore the file 1 to 1, I must restore the header keys myself 512 bool AddColumn(uint32_t cnt, char typechar, const string &name, const string &unit, const string &comment="", bool addHeaderKeys=true)552 virtual bool AddColumn(uint32_t cnt, char typechar, const string &name, const string &unit, const string &comment="", bool addHeaderKeys=true) 513 553 { 514 554 if (tellp()<0) … … 550 590 typechar = toupper(typechar); 551 591 552 static const string allow("LABIJKED ");592 static const string allow("LABIJKEDQ"); 553 593 if (std::find(allow.begin(), allow.end(), typechar)==allow.end()) 554 594 { … … 564 604 565 605 ostringstream type; 566 type << cnt << typechar; 606 type << cnt; 607 if (typechar=='Q') 608 type << "QB"; 609 else 610 type << typechar; 567 611 568 612 fTable.num_cols++; … … 576 620 typecom << "format of " << name << " ["; 577 621 578 switch (typechar) 622 typecom << CommentFromType(typechar); 623 /* switch (typechar) 579 624 { 580 625 case 'L': typecom << "1-byte BOOL]"; break; … … 586 631 case 'E': typecom << "4-byte FLOAT]"; break; 587 632 case 'D': typecom << "8-byte FLOAT]"; break; 588 } 589 633 case 'Q': typecom << "var. Length]"; break; 634 } 635 */ 590 636 if (addHeaderKeys) 591 637 { … … 595 641 SetStr(unitkey.str(), unit, unitcom.str()); 596 642 } 597 size_t size = 0;598 599 switch (typechar)643 size_t size = SizeFromType(typechar); 644 645 /* switch (typechar) 600 646 { 601 647 case 'L': size = 1; break; … … 607 653 case 'E': size = 4; break; 608 654 case 'D': size = 8; break; 609 } 610 655 case 'Q': size = 16; break; 656 } 657 */ 611 658 Table::Column col; 612 659 … … 678 725 { 679 726 Checksum sum; 727 uint32_t count=0; 680 728 for (auto it=fKeys.begin(); it!=fKeys.end(); it++) 681 729 { 682 730 it->Out(fout); 683 731 sum += it->checksum; 732 count++; 684 733 } 685 734 fout.flush(); … … 725 774 } 726 775 727 bool WriteTableHeader(const char *name="DATA") 776 virtual bool WriteDrsOffsetsTable () 777 { 778 return true; 779 } 780 781 virtual bool WriteCatalog() 782 { 783 return true; 784 } 785 786 virtual bool WriteTableHeader(const char *name="DATA") 728 787 { 729 788 if (tellp()>0) … … 738 797 739 798 fHeaderSum = WriteFitsHeader(); 799 800 WriteDrsOffsetsTable(); 740 801 741 802 if (!fManualExtName) … … 748 809 WriteHeader(); 749 810 811 WriteCatalog(); 812 750 813 return good(); 751 814 } … … 759 822 } 760 823 761 uint32_t GetBytesPerRow() const { return fTable.bytes_per_row; }762 763 bool WriteRow(const void *ptr, size_t cnt, bool byte_swap=true)824 virtual uint32_t GetBytesPerRow() const { return fTable.bytes_per_row; } 825 826 virtual bool WriteRow(const void *ptr, size_t cnt, bool byte_swap=true) 764 827 { 765 828 // FIXME: Make sure that header was already written … … 830 893 831 894 // Flushes the number of rows to the header on disk 832 v oid FlushNumRows()895 virtual void FlushNumRows() 833 896 { 834 897 SetInt("NAXIS2", fTable.num_rows); … … 838 901 size_t GetNumRows() const { return fTable.num_rows; } 839 902 840 bool close() 841 { 842 if (tellp()<0) 843 return false; 844 903 void AlignTo2880Bytes() 904 { 845 905 if (tellp()%(80*36)>0) 846 906 { 847 constvector<char> filler(80*36-tellp()%(80*36));907 vector<char> filler(80*36-tellp()%(80*36)); 848 908 write(filler.data(), filler.size()); 849 909 } 850 851 // We don't have to jump back to the end of the file 852 SetInt("NAXIS2", fTable.num_rows); 910 } 911 912 Checksum UpdateHeaderChecksum() 913 { 853 914 854 915 ostringstream dataSumStr; … … 862 923 SetStr("CHECKSUM", (sum+fDataSum).str()); 863 924 864 const Checksum chk = WriteHeader(); 925 return WriteHeader(); 926 } 927 virtual bool close() 928 { 929 if (tellp()<0) 930 return false; 931 932 AlignTo2880Bytes(); 933 934 // We don't have to jump back to the end of the file 935 SetInt("NAXIS2", fTable.num_rows); 936 937 938 const Checksum chk = UpdateHeaderChecksum(); 865 939 866 940 ofstream::close();
Note:
See TracChangeset
for help on using the changeset viewer.