Changeset 15277 for trunk/Mars/mfileio
- Timestamp:
- 04/08/13 12:21:14 (12 years ago)
- Location:
- trunk/Mars/mfileio
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Mars/mfileio/MWriteFitsFile.cc
r14935 r15277 337 337 return kTRUE; 338 338 } 339 340 339 template<> 340 std::string MWriteFitsFile::GetFitsString(const double& value) 341 { 342 std::ostringstream returnVal; 343 returnVal << std::setprecision(value>1e-100 && value<1e100 ? 15 : 14) << value; 344 std::string temp = returnVal.str(); 345 std::replace(temp.begin(), temp.end(), 'e', 'E'); 346 if (temp.find_first_of('E')==std::string::npos && temp.find_first_of('.')==std::string::npos) 347 temp += "."; 348 return temp; 349 } 350 template<> 351 std::string MWriteFitsFile::GetFitsString(const float& value) 352 { 353 return GetFitsString((double)(value)); 354 } 341 355 // -------------------------------------------------------------------------- 342 356 // … … 355 369 356 370 // remove the extension from the filename 371 // this has been disabled for now 357 372 char fileNameNoExt[strlen(GetFileName()) + 1]; 358 373 strcpy(fileNameNoExt, GetFileName()); 359 char * pos = strrchr(fileNameNoExt, '.');360 if (pos) *pos = 0;361 374 // char * pos = strrchr(fileNameNoExt, '.'); 375 // if (pos) *pos = 0; 376 //*fLog << inf <<"Filename no ext: " << fileNameNoExt << endl; 362 377 // loop over all FITS tables which have to be created. 363 378 map<TString, map<TString, MFitsSubTable> >::iterator i_table = … … 373 388 { 374 389 dol = dol(0, dol.Length()-5); 375 // *fLog << err << "New name: " << dol.Data() << endl; 376 } 377 // else 378 // *fLog << err << dol(dol.Length()-5, dol.Length()).Data() << endl; 390 } 391 if (dol(dol.Length()-5, dol.Length()) == ".fits") 392 { 393 dol = dol(0, dol.Length()-5); 394 } 379 395 dol += "_"; 380 396 dol += i_table->first; … … 1038 1054 if (!fTableHeaderWritten[tableName]) 1039 1055 { 1056 for (vector<ofits::Key>::const_iterator it = fHeaderKeys.begin(); it != fHeaderKeys.end(); it++) 1057 fFitsTables[tableName]->SetRaw(it->key, it->value, it->comment); 1040 1058 fFitsTables[tableName]->WriteTableHeader(tableName.Data()); 1041 1059 fTableHeaderWritten[tableName] = true; … … 1102 1120 // get new filename 1103 1121 const TString readFileName = read->GetFullFileName(); 1104 const TString newname = MWriteRootFile::SubstituteName(fRule, readFileName) +".fits";1122 const TString newname = MWriteRootFile::SubstituteName(fRule, readFileName); 1105 1123 1106 1124 // create new files -
trunk/Mars/mfileio/MWriteFitsFile.h
r14935 r15277 138 138 Int_t PostProcess(); 139 139 140 //Header keys related stuff 141 template<typename _T> 142 std::string GetFitsString(const _T& value) 143 { 144 std::ostringstream returnVal; 145 std::string typeName = typeid(_T).name(); 146 if (typeName == "i" || typeName == "j" || //int 147 typeName == "s" || typeName == "t" || //short 148 typeName == "l" || typeName == "m" || //long 149 typeName == "x" || typeName == "y") //long long 150 returnVal << value; 151 152 if (typeName == "b") 153 { 154 if (value) returnVal << "T"; else returnVal << "F"; 155 } 156 if (typeName == "Ss" || typeName == "PKc" || 157 (typeName.size() >= 4 && typeName[0] == 'A' && typeName[typeName.size()-1] == 'c' && typeName[typeName.size()-2] == '_')) 158 { 159 returnVal << value; 160 std::string temp = returnVal.str(); 161 returnVal.str(""); 162 for (std::string::iterator c=temp.begin(); c<temp.end(); c++) 163 if (*c=='\'') 164 temp.insert(c++, '\''); 165 returnVal << "'" << temp << "'"; 166 } 167 if (returnVal.str() == "") 168 *fLog << warn << "WARNING: could not construct fits string from \"" << value << "\" typename: " << typeName << endl; 169 return returnVal.str(); 170 } 171 172 public: 173 template<typename _T> 174 bool SetHeaderKey(const std::string& key, 175 const _T& value, 176 const std::string& comment="") 177 { 178 //check if header was already written 179 for (std::map<TString, bool>::iterator it=fTableHeaderWritten.begin(); it!= fTableHeaderWritten.end(); it++) 180 if (it->second == true) 181 return false; 182 //headers were not written yet. Add one key 183 std::vector<ofits::Key>::iterator it = fHeaderKeys.begin(); 184 //check if the value had been set beforel 185 for (;it!=fHeaderKeys.end();it++) 186 { 187 if (it->key == key) 188 { 189 it->value = GetFitsString(value); 190 it->comment = comment; 191 break; 192 } 193 } 194 //did we find the key ? 195 if (it == fHeaderKeys.end()) 196 {//no ? add it ! 197 ofits::Key temp; 198 temp.key = key; 199 temp.value = GetFitsString(value); 200 temp.comment = comment; 201 fHeaderKeys.push_back(temp); 202 } 203 return true; 204 } 205 private: 206 std::vector<ofits::Key> fHeaderKeys; 207 140 208 std::string Trim(const std::string &str); 141 209 … … 145 213 std::vector<std::string> fVetoedColumns; 146 214 std::map<std::string, uint32_t> fBytesPerSamples; 215 147 216 148 217 public: … … 186 255 ClassDef(MWriteFitsFile, 0) 187 256 }; 188 189 190 #endif 257 //Specializations for float and doubles (because of the precision handling, I could not deal with it in the main function 258 template<> 259 std::string MWriteFitsFile::GetFitsString(const double& value); 260 template<> 261 std::string MWriteFitsFile::GetFitsString(const float& value); 262 #endif
Note:
See TracChangeset
for help on using the changeset viewer.