Changeset 17751
- Timestamp:
- 05/01/14 18:51:14 (11 years ago)
- Location:
- trunk/Mars/mcore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Mars/mcore/ofits.h
r17559 r17751 42 42 // units: m kg s rad sr K A mol cd Hz J W V N Pa C Ohm S F Wb T Hlm lx 43 43 44 class ofits : public std::o fstream44 class ofits : public std::ostream 45 45 { 46 protected: 47 std::filebuf fFilebuf; 48 46 49 public: 47 50 struct Key … … 225 228 Checksum checksum; 226 229 227 void Out(std::o fstream &fout)230 void Out(std::ostream &fout) 228 231 { 229 232 if (!changed) … … 359 362 360 363 public: 361 ofits() : fCommentTrimming(false), 362 fManualExtName(false) 363 { 364 } 365 ofits(const char *fname) : std::ofstream(), 366 fCommentTrimming(false), 367 fManualExtName(false) 368 { 369 this->open(fname); 370 } 371 virtual ~ofits() { if (is_open()) close(); } 372 373 virtual void open(const char * filename, bool addEXTNAMEKey=true) 364 ofits() 365 : std::ostream(), fFilebuf(), fCommentTrimming(false), fManualExtName(false) 366 { 367 init(&fFilebuf); 368 } 369 370 ofits(const char *fname) 371 : std::ostream(), fFilebuf(), fCommentTrimming(false), fManualExtName(false) 372 { 373 init(&fFilebuf); 374 open(fname); 375 } 376 377 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 378 ofits(const std::string &fname) 379 : std::ostream(), fCommentTrimming(false), fManualExtName(false) 380 { 381 init(&fFilebuf); 382 open(fname); 383 } 384 #endif 385 386 virtual ~ofits() 387 { 388 if (is_open()) 389 close(); 390 } 391 /* 392 filebuf *rdbuf() const 393 { 394 return const_cast<filebuf*>(&fFilebuf); 395 } 396 */ 397 bool is_open() 398 { 399 return fFilebuf.is_open(); 400 } 401 402 bool is_open() const 403 { 404 return fFilebuf.is_open(); 405 } 406 407 virtual void open(const char *filename, bool addEXTNAMEKey=true) 374 408 { 375 409 fDataSum = 0; … … 380 414 381 415 SetStr("XTENSION", "BINTABLE", "binary table extension"); 382 SetInt("BITPIX", 383 SetInt("NAXIS", 384 SetInt("NAXIS1", 385 SetInt("NAXIS2", 386 SetInt("PCOUNT", 387 SetInt("GCOUNT", 388 SetInt("TFIELDS", 416 SetInt("BITPIX", 8, "8-bit bytes"); 417 SetInt("NAXIS", 2, "2-dimensional binary table"); 418 SetInt("NAXIS1", 0, "width of table in bytes"); 419 SetInt("NAXIS2", 0, "number of rows in table"); 420 SetInt("PCOUNT", 0, "size of special data area"); 421 SetInt("GCOUNT", 1, "one data group (required keyword)"); 422 SetInt("TFIELDS", 0, "number of fields in each row"); 389 423 if (addEXTNAMEKey) 390 424 SetStr("EXTNAME", "", "name of extension table"); … … 394 428 SetStr("DATASUM", " 0", "Checksum for the data block"); 395 429 396 std::ofstream::open(filename); 430 if (!fFilebuf.open(filename, ios_base::out|ios_base::trunc)) 431 setstate(ios_base::failbit); 432 else 433 clear(); 434 } 435 436 virtual void open(const std::string &filename, bool addEXTNAMEKey=true) 437 { 438 open(filename.c_str(), addEXTNAMEKey); 397 439 } 398 440 … … 740 782 741 783 742 Checksum WriteHeader(std::o fstream &fout)784 Checksum WriteHeader(std::ostream &fout) 743 785 { 744 786 Checksum sum; … … 930 972 Checksum UpdateHeaderChecksum() 931 973 { 932 933 974 std::ostringstream dataSumStr; 934 975 dataSumStr << fDataSum.val(); … … 951 992 952 993 // We don't have to jump back to the end of the file 953 SetInt("NAXIS2", fTable.num_rows); 954 994 SetInt("NAXIS2", fTable.num_rows); 955 995 956 996 const Checksum chk = UpdateHeaderChecksum(); 957 997 958 std::ofstream::close(); 998 if (!fFilebuf.close()) 999 setstate(ios_base::failbit); 959 1000 960 1001 if ((chk+fDataSum).valid()) -
trunk/Mars/mcore/zofits.h
r17677 r17751 106 106 uint32_t numTiles = DefaultMaxNumTiles(), 107 107 uint32_t rowPerTile = DefaultNumRowsPerTile(), 108 uint32_t maxUsableMem= DefaultMaxMemory()) : ofits(fname), 109 fMemPool(0, maxUsableMem*1000), 110 fWriteToDiskQueue(std::bind(&zofits::WriteBufferToDisk, this, std::placeholders::_1), false) 111 { 108 uint32_t maxUsableMem= DefaultMaxMemory()) : ofits(), 109 fMemPool(0, maxUsableMem*1000), 110 fWriteToDiskQueue(std::bind(&zofits::WriteBufferToDisk, this, std::placeholders::_1), false) 111 { 112 open(fname); 113 InitMemberVariables(numTiles, rowPerTile, maxUsableMem*1000); 114 SetNumThreads(DefaultNumThreads()); 115 } 116 117 zofits(const std::string &fname, 118 uint32_t numTiles = DefaultMaxNumTiles(), 119 uint32_t rowPerTile = DefaultNumRowsPerTile(), 120 uint32_t maxUsableMem= DefaultMaxMemory()) : ofits(), 121 fMemPool(0, maxUsableMem*1000), 122 fWriteToDiskQueue(std::bind(&zofits::WriteBufferToDisk, this, std::placeholders::_1), false) 123 { 124 open(fname); 112 125 InitMemberVariables(numTiles, rowPerTile, maxUsableMem*1000); 113 126 SetNumThreads(DefaultNumThreads()); … … 199 212 fCatalogSum.reset(); 200 213 fRawSum.reset(); 214 } 215 216 void open(const std::string &filename, bool addEXTNAMEKey=true) 217 { 218 open(filename.c_str(), addEXTNAMEKey); 201 219 } 202 220 … … 513 531 const Checksum checksm = UpdateHeaderChecksum(); 514 532 515 std::ofstream::close(); 533 if (!fFilebuf.close()) 534 setstate(ios_base::failbit); 516 535 517 536 fSmartBuffer = std::shared_ptr<char>();
Note:
See TracChangeset
for help on using the changeset viewer.