Changeset 15364
- Timestamp:
- 04/18/13 12:08:14 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Mars/mcore/fits.h
r15267 r15364 17 17 #include <map> 18 18 #include <string> 19 #include <fstream> 19 20 #include <sstream> 20 21 #include <algorithm> … … 420 421 421 422 private: 423 ofstream fCopy; 424 422 425 Table fTable; 423 426 … … 497 500 } 498 501 499 public: 500 fits(const string &fname, bool force=false) : izstream(fname.c_str()) 502 void Constructor(const string &fname, string fout, bool force) 501 503 { 502 504 char simple[10]; … … 595 597 } 596 598 } 599 600 if (fout.empty()) 601 return; 602 603 if (*fout.rbegin()=='/') 604 { 605 const size_t p = fname.find_last_of('/'); 606 fout.append(fname.substr(p+1)); 607 } 608 609 fCopy.open(fout); 610 if (!fCopy) 611 { 612 clear(rdstate()|ios::badbit); 613 #ifdef __EXCEPTIONS 614 throw runtime_error("Could not open output file."); 615 #else 616 gLog << ___err___ << "ERROR - Failed to open output file." << endl; 617 #endif 618 } 619 620 const streampos p = tellg(); 621 seekg(0); 622 623 vector<char> buf(p); 624 read(buf.data(), p); 625 626 fCopy.write(buf.data(), p); 627 if (!fCopy) 628 clear(rdstate()|ios::badbit); 629 } 630 631 public: 632 fits(const string &fname, bool force=false) : izstream(fname.c_str()) 633 { 634 Constructor(fname, "", force); 635 } 636 637 fits(const string &fname, const string &fout, bool force=false) : izstream(fname.c_str()) 638 { 639 Constructor(fname, fout, force); 640 } 641 642 ~fits() 643 { 644 copy(istreambuf_iterator<char>(*this), 645 istreambuf_iterator<char>(), 646 ostreambuf_iterator<char>(fCopy)); 597 647 } 598 648 … … 625 675 626 676 if (row==fRow+1) 677 { 627 678 fChkData.add(fBufferRow); 679 if (fCopy.is_open() && fCopy.good()) 680 fCopy.write(fBufferRow.data()+offset, fTable.bytes_per_row); 681 if (!fCopy) 682 clear(rdstate()|ios::badbit); 683 } 684 else 685 if (fCopy.is_open()) 686 clear(rdstate()|ios::badbit); 628 687 629 688 fRow = row;
Note:
See TracChangeset
for help on using the changeset viewer.