Changeset 10741 for trunk/FACT++/src/Fits.cc
- Timestamp:
- 05/18/11 16:00:41 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/Fits.cc
r10725 r10741 35 35 //! @param numDataBytes the number of bytes taken by the variable 36 36 // 37 void Fits::AddStandardColumn(Description& desc, st d::string dataFormat, void* dataPointer, long unsigned int numDataBytes)37 void Fits::AddStandardColumn(Description& desc, string dataFormat, void* dataPointer, long unsigned int numDataBytes) 38 38 { 39 39 //check if entry already exist 40 for ( std::vector<Description>::iterator it=fStandardColDesc.begin(); it != fStandardColDesc.end(); it++)40 for (vector<Description>::iterator it=fStandardColDesc.begin(); it != fStandardColDesc.end(); it++) 41 41 if (it->name == desc.name) 42 42 return; … … 54 54 //! @param numDataBytes the number of bytes taken by the DIM data. 55 55 // 56 void Fits::InitDataColumns( std::vector<Description> desc, std::vector<std::string>& dataFormat, void* dataPointer, int numDataBytes)56 void Fits::InitDataColumns(vector<Description> desc, vector<string>& dataFormat, void* dataPointer, int numDataBytes) 57 57 {//we will copy this information here. It duplicates the data, which is not great, but it is the easiest way of doing it right now 58 58 if (desc.size() == dataFormat.size()) … … 65 65 for (unsigned int i=0;i<dataFormat.size();i++) 66 66 { 67 st d::stringstream stt;67 stringstream stt; 68 68 stt << "Data" << i; 69 69 fDataColDesc.push_back(Description(stt.str(), "comment", "unit")); … … 83 83 //! @param out a pointer to the MessageImp that should be used to log errors 84 84 // 85 void Fits::Open(const st d::string& fileName, const std::string& tableName, FITS* file, int* fitsCounter, MessageImp* out)//std::ostream& out)85 void Fits::Open(const string& fileName, const string& tableName, FITS* file, int* fitsCounter, MessageImp* out)//ostream& out) 86 86 { 87 87 // if (fMess) … … 98 98 catch (CCfits::FitsError e) 99 99 { 100 st d::stringstream str;100 stringstream str; 101 101 str << "Could not open FITS file " << fileName << " reason: " << e.message(); 102 102 fMess->Error(str); … … 115 115 //concatenate the standard and data columns 116 116 //do it the inneficient way first: its easier and faster to code. 117 std::vector<std::string> allNames;118 std::vector<std::string> allDataTypes;119 std::vector<std::string> allUnits;117 vector<string> allNames; 118 vector<string> allDataTypes; 119 vector<string> allUnits; 120 120 fTotalNumBytes = 0; 121 121 for (unsigned int i=0;i<fStandardColDesc.size();i++) … … 133 133 else 134 134 { 135 st d::stringstream stt;135 stringstream stt; 136 136 stt << "Data" << i; 137 137 allNames.push_back(stt.str()); … … 145 145 try 146 146 { 147 st d::string factTableName = "FACT-" + tableName;147 string factTableName = "FACT-" + tableName; 148 148 fTable = fFile->addTable(factTableName, 0, allNames, allDataTypes, allUnits); 149 149 fTable->makeThisCurrent(); … … 159 159 } 160 160 //read the table binary data. 161 std::vector<string> colName;161 vector<string> colName; 162 162 bTable->readData(true, colName); 163 163 164 164 //double check that the data was indeed read from the disk. Go through the fTable instead as colName is empty (yes, it is !) 165 std::map<std::string, Column*> cMap = fTable->column();166 std::map<std::string, Column*>::iterator cMapIt;165 map<string, Column*> cMap = fTable->column(); 166 map<string, Column*>::iterator cMapIt; 167 167 168 168 for (cMapIt = cMap.begin(); cMapIt != cMap.end(); cMapIt++) … … 179 179 catch(CCfits::FitsError e) 180 180 { 181 st d::stringstream str;181 stringstream str; 182 182 str << "Could not open or create FITS table " << tableName << " in file " << fileName << " reason: " << e.message(); 183 183 fMess->Error(str); … … 190 190 WriteHeaderKeys(); 191 191 } 192 // -------------------------------------------------------------------------- 193 // 194 //!This writes a single header key in the currently open file. 195 //!@param name the key 196 //!@param value the key value 197 //!@param a comment explaining the meaning of the key 192 198 template <typename T> 193 199 void Fits::WriteSingleHeaderKey(string name, T value, string comment) … … 199 205 catch (CCfits::FitsError e) 200 206 { 201 st d::stringstream str;207 stringstream str; 202 208 str << "Could not add header keys in file " << fFileName << " reason: " << e.message(); 203 209 fMess->Error(str); … … 212 218 if (!fTable) 213 219 return; 214 std::string name; 215 std::string comment; 216 217 // float floatValue; 218 // double doubleValue; 219 std::string stringValue; 220 string name; 221 string comment; 222 223 string stringValue; 220 224 221 225 WriteSingleHeaderKey("EXTREL", 1.0f, "Release Number"); … … 230 234 WriteSingleHeaderKey("TIMEREF", "UTC", "Time reference frame"); 231 235 WriteSingleHeaderKey("MJDREF", fRefMjD, "Modified Julian Date of origin"); 236 WriteSingleHeaderKey("TSTOP", fEndMjD, "Time of the last receied data"); 232 237 } 233 238 // -------------------------------------------------------------------------- … … 239 244 { 240 245 241 // try242 // {243 246 fTable->makeThisCurrent(); 244 247 int status(0); 245 248 if (fits_insert_rows(fTable->fitsPointer(), fNumRows, 1, &status)) 246 249 { 247 st d::stringstream str;250 stringstream str; 248 251 str << "Could not insert row in file " << fFileName << ". cfitsio error code: " << status; 249 252 fMess->Error(str); 250 253 } 251 // fTable->insertRows(fNumRows);252 // }253 // catch(CCfits::FitsError e)254 // {255 // std::stringstream str;256 // str << "Could not insert row in file " << fFileName << " reason: " << e.message();257 // fMess->Error(str);258 // }259 254 fNumRows++; 260 255 … … 273 268 { 274 269 const char * charSrc = static_cast<char*>(fStandardPointers[i]); 275 276 270 reverse_copy(charSrc, charSrc+fStandardNumBytes[i], &fCopyBuffer[shift]); 277 // for (int j=0; j<fStandardNumBytes[i]; j++)278 // fCopyBuffer[shift+j] = static_cast<char*>(fStandardPointers[i])[fStandardNumBytes[i]-(j+1)];279 271 shift+= fStandardNumBytes[i]; 280 272 } … … 284 276 285 277 //data copied to buffer, can write to fits 286 // int status = 0;287 //TODO check the status after the write operation288 278 fits_write_tblbytes(fFile->fitsPointer(), fNumRows, 1, fTotalNumBytes, fCopyBuffer, &status); 289 279 if (status) … … 291 281 char text[30];//max length of cfitsio error strings (from doc) 292 282 fits_get_errstatus(status, text); 293 st d::stringstream str;283 stringstream str; 294 284 str << "Error while writing FITS row in " << fFileName << ". Message: " << text << " [" << status << "]"; 295 285 fMess->Error(str); 296 286 } 297 //This forces the writting of each row to the disk. Otherwise all rows are written when the file is closed. 298 ///TODO check whether this consumes too much resources or not. If it does, flush every N write operations instead 299 /* try 300 { 301 fFile->flush(); 302 } 303 catch (CCfits::FitsError e) 304 { 305 std::stringstream str; 306 str << "Error while flushing bytes to disk. File: " << fFileName << " reason: " << e.message(); 307 fMess->Error(str); 308 } 309 */} 287 } 310 288 // -------------------------------------------------------------------------- 311 289 // … … 335 313 336 314 // -------------------------------------------------------------------------- 337 // 315 //! Returns the size on the disk of the Fits file being written. 338 316 int Fits::GetWrittenSize() 339 317 {
Note:
See TracChangeset
for help on using the changeset viewer.