Changeset 16331 for trunk/Mars/mcore/ofits.h
- Timestamp:
- 05/27/13 17:06:23 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Mars/mcore/ofits.h
r15125 r16331 39 39 string value; 40 40 string comment; 41 string fitsString; 41 42 42 43 off_t offset; // offset in file … … 44 45 bool changed; // For closing the file 45 46 46 Key(const string &k="") : key(k), delim(false), offset(0), changed(true) { }47 Key(const string &k="") : key(k), delim(false), fitsString(""), offset(0), changed(true) { } 47 48 48 49 string Trim(const string &str) … … 180 181 string Compile() 181 182 { 183 184 if (fitsString != "") 185 return fitsString; 186 182 187 ostringstream sout; 183 188 sout << std::left << setw(8) << key; … … 331 336 332 337 bool fCommentTrimming; 338 bool fManualExtName; 333 339 334 340 public: 335 ofits() : fCommentTrimming(false) 341 ofits() : fCommentTrimming(false), 342 fManualExtName(false) 336 343 { 337 344 } 338 345 ofits(const char *fname) : ofstream(), 339 fCommentTrimming(false) 346 fCommentTrimming(false), 347 fManualExtName(false) 340 348 { 341 349 this->open(fname); … … 343 351 ~ofits() { close(); } 344 352 345 void open(const char * filename )353 void open(const char * filename, bool addEXTNAMEKey=true) 346 354 { 347 355 fDataSum = 0; … … 359 367 SetInt("GCOUNT", 1, "one data group (required keyword)"); 360 368 SetInt("TFIELDS", 0, "number of fields in each row"); 361 SetStr("EXTNAME", "", "name of extension table"); 369 if (addEXTNAMEKey) 370 SetStr("EXTNAME", "", "name of extension table"); 371 else 372 fManualExtName = true; 362 373 SetStr("CHECKSUM", "0000000000000000", "Checksum for the whole HDU"); 363 374 SetStr("DATASUM", " 0", "Checksum for the data block"); … … 370 381 fCommentTrimming = allow; 371 382 } 372 383 //Etienne: required to enable 1 to 1 reconstruction of files 384 bool SetKeyComment(const string& key, const string& comment) 385 { 386 auto it = findkey(key); 387 if (it==fKeys.end()) 388 return false; 389 it->comment = comment; 390 it->changed = true; 391 return true; 392 } 393 bool SetKeyFromFitsString(const string& fitsString) 394 { 395 if (fTable.num_rows>0) 396 { 397 ostringstream sout; 398 sout << "No new header key can be defined, rows were already written to the file... ignoring new key '" << fitsString << "'"; 399 #ifdef __EXCEPTIONS 400 throw runtime_error(sout.str()); 401 #else 402 gLog << ___err___ << "ERROR - " << sout.str() << endl; 403 return false; 404 #endif 405 } 406 407 Key entry; 408 entry.fitsString = fitsString; 409 entry.changed = true; 410 fKeys.push_back(entry); 411 return true; 412 } 373 413 bool SetRaw(const string &key, const string &val, const string &comment) 374 414 { … … 455 495 } 456 496 457 bool AddColumn(uint32_t cnt, char typechar, const string &name, const string &unit, const string &comment="") 497 //ETIENNE to be able to restore the file 1 to 1, I must restore the header keys myself 498 bool AddColumn(uint32_t cnt, char typechar, const string &name, const string &unit, const string &comment="", bool addHeaderKeys=true) 458 499 { 459 500 if (tellp()<0) … … 533 574 } 534 575 535 SetStr(formkey.str(), type.str(), typecom.str()); 536 SetStr(typekey.str(), name, comment); 537 538 if (!unit.empty()) 539 SetStr(unitkey.str(), unit, unitcom.str()); 540 576 if (addHeaderKeys) 577 { 578 SetStr(formkey.str(), type.str(), typecom.str()); 579 SetStr(typekey.str(), name, comment); 580 if (!unit.empty()) 581 SetStr(unitkey.str(), unit, unitcom.str()); 582 } 541 583 size_t size = 0; 542 584 … … 682 724 fHeaderSum = WriteFitsHeader(); 683 725 684 SetStr("EXTNAME", name); 726 if (!fManualExtName) 727 SetStr("EXTNAME", name); 685 728 SetInt("NAXIS1", fTable.bytes_per_row); 686 729 SetInt("TFIELDS", fTable.cols.size()); … … 819 862 return false; 820 863 #endif 864 } 865 866 pair<string, int> GetChecksumData() 867 { 868 string datasum; 869 string checksum; 870 //cannot directly use the Get methods, because they are only in fits.h 871 for (vector<Key>::const_iterator it=fKeys.begin(); it!= fKeys.end(); it++) 872 { 873 if (it->key == "CHECKSUM") checksum = it->value; 874 if (it->key == "DATASUM") datasum = it->value; 875 } 876 if (checksum[0] == '\'') 877 checksum = checksum.substr(1,checksum.size()-2); 878 if (datasum[0] == '\'') 879 datasum = datasum.substr(1, datasum.size()-2); 880 return make_pair(checksum, atoi(datasum.c_str())); 821 881 } 822 882 };
Note:
See TracChangeset
for help on using the changeset viewer.