Changeset 10489 for trunk/FACT++/src/Fits.cc
- Timestamp:
- 04/29/11 10:19:46 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/Fits.cc
r10442 r10489 79 79 //! @param file a pointer to an existing FITS file. If NULL, file will be opened and managed internally 80 80 // 81 void Fits::Open(const std::string& fileName, const std::string& tableName, FITS* file )81 void Fits::Open(const std::string& fileName, const std::string& tableName, FITS* file, int* fitsCounter, std::ostream& out) 82 82 { 83 if (fMess) 84 delete fMess; 85 fMess = new MessageImp(out); 86 83 87 fFileName = fileName; 84 88 if (file == NULL) … … 88 92 fFile = new FITS(fileName, RWmode::Write); 89 93 } 90 catch (FITS::CantOpen) 91 { 92 std::ostringstream err; 93 err << "Could not open " << fileName << ".Skipping it."; 94 throw runtime_error(err.str()); 94 catch (CCfits::FitsError e) 95 { 96 std::stringstream str; 97 str << "Could not open FITS file " << fileName << " reason: " << e.message(); 98 fMess->Error(str); 99 fFile = NULL; 100 return; 95 101 } 96 102 fOwner = true; 103 fNumOpenFitsFiles = fitsCounter; 104 (*fNumOpenFitsFiles)++; 97 105 } 98 106 else … … 133 141 try 134 142 { 135 fTable = fFile->addTable(tableName, 0, allNames, allDataTypes, allUnits); 143 std::string factTableName = "FACT-" + tableName; 144 fTable = fFile->addTable(factTableName, 0, allNames, allDataTypes, allUnits); 136 145 fCopyBuffer = new unsigned char[fTotalNumBytes]; 137 146 fNumRows = fTable->rows(); … … 153 162 catch(CCfits::FitsError e) 154 163 { 155 std::ostringstream err; 156 err << "Error when adding table " << tableName << " : " << e.message(); 157 throw runtime_error(err.str()); 164 std::stringstream str; 165 str << "Could not open or create FITS table " << tableName << " in file " << fileName << " reason: " << e.message(); 166 fMess->Error(str); 167 fTable = NULL; 158 168 } 159 169 160 f EndMjD = * static_cast<double*>(fStandardPointers[0]);170 fRefMjD = * static_cast<double*>(fStandardPointers[0]); 161 171 if (!updating) 162 172 WriteHeaderKeys(); … … 168 178 void Fits::WriteHeaderKeys() 169 179 { 180 if (!fTable) 181 return; 170 182 std::string name; 171 183 std::string comment; … … 174 186 double doubleValue; 175 187 std::string stringValue; 188 try 189 { 190 name = "EXTREL"; 191 comment = "Release Number"; 192 floatValue = 1.0f; 193 fTable->addKey(name, floatValue, comment); 194 195 name = "BASETYPE"; 196 comment = "Base type of the data structure"; 197 stringValue = "??????"; 198 fTable->addKey(name, stringValue, comment); 199 200 name = "TELESCOP"; 201 comment = "Telescope that acquired this data"; 202 stringValue = "FACT"; 203 fTable->addKey(name, stringValue, comment); 204 205 name = "ORIGIN"; 206 comment = "Institution that wrote the file"; 207 stringValue = "ISDC"; 208 fTable->addKey(name, stringValue, comment); 209 210 name = "CREATOR"; 211 comment = "Program that wrote this file"; 212 stringValue = "FACT++_DataLogger"; 213 fTable->addKey(name, stringValue, comment); 214 215 name = "DATE"; 216 stringValue = Time().GetAsStr(); 217 stringValue[10] = 'T'; 218 comment = "File creation date"; 219 fTable->addKey(name, stringValue, comment); 220 221 name = "TIMESYS"; 222 stringValue = "TT"; 223 comment = "Time frame system"; 224 fTable->addKey(name, stringValue, comment); 225 226 name = "TIMEUNIT"; 227 stringValue = "d"; 228 comment = "Time unit"; 229 fTable->addKey(name, stringValue, comment); 230 231 name = "TIMEREF"; 232 stringValue = "UTC"; 233 comment = "Time reference frame"; 234 fTable->addKey(name, stringValue, comment); 176 235 177 name = "EXTREL"; 178 comment = "Release Number"; 179 floatValue = 1.0f; 180 fTable->addKey(name, floatValue, comment); 181 182 name = "BASETYPE"; 183 comment = "Base class that wrote this file"; 184 stringValue = "CCFits_table"; 185 fTable->addKey(name, stringValue, comment); 186 187 name = "TELESCOP"; 188 comment = "Telescope that acquired this data"; 189 stringValue = "FACT"; 190 fTable->addKey(name, stringValue, comment); 191 192 name = "ORIGIN"; 193 comment = "Institution that wrote the file"; 194 stringValue = "ISDC"; 195 fTable->addKey(name, stringValue, comment); 196 197 name = "CREATOR"; 198 comment = "Program that wrote this file"; 199 stringValue = "FACT++_DataLogger"; 200 fTable->addKey(name, stringValue, comment); 201 202 name = "DATE"; 203 stringValue = Time().GetAsStr(); 204 stringValue[10] = 'T'; 205 comment = "File creation date"; 206 fTable->addKey(name, stringValue, comment); 207 208 name = "TIMEREF"; 209 stringValue = "UTC"; 210 comment = "Time reference system"; 211 fTable->addKey(name, stringValue, comment); 212 213 name = "TSTART"; 214 doubleValue = fEndMjD; 215 comment = "Time of the first received data"; 216 fTable->addKey(name, doubleValue, comment); 217 236 name = "MJDREF"; 237 doubleValue = fRefMjD; 238 comment = "Modified Julian Date of origin"; 239 fTable->addKey(name, doubleValue, comment); 240 } 241 catch (CCfits::FitsError e) 242 { 243 std::stringstream str; 244 str << "Could not add header keys in file " << fFileName << " reason: " << e.message(); 245 fMess->Error(str); 246 } 218 247 //More ? 219 248 } … … 233 262 catch(CCfits::FitsError e) 234 263 { 235 std:: ostringstream err;236 err << "Error when inserting a row: " << e.message();237 throw runtime_error(err.str());264 std::stringstream str; 265 str << "Could not insert row in file " << fFileName << " reason: " << e.message(); 266 fMess->Error(str); 238 267 } 239 268 fNumRows++; 240 269 241 270 //the first standard variable is the current MjD 271 if (fEndMjD == 0) 272 { 273 std::string name = "TSTART"; 274 double doubleValue = *static_cast<double*>(fStandardPointers[0]) - fRefMjD; 275 std::string comment = "Time of the first received data"; 276 fTable->addKey(name, doubleValue, comment); 277 } 242 278 fEndMjD = * static_cast<double*>(fStandardPointers[0]); 243 279 … … 259 295 //TODO check the status after the write operation 260 296 fits_write_tblbytes(fFile->fitsPointer(), fNumRows, 1, fTotalNumBytes, fCopyBuffer, &status); 261 297 if (status) 298 { 299 char text[30];//max length of cfitsio error strings (from doc) 300 fits_get_errstatus(status, text); 301 std::stringstream str; 302 str << "Error while writing FITS row in " << fFileName << ". Message: " << text << " [" << status << "]"; 303 fMess->Error(str); 304 } 262 305 //This forces the writting of each row to the disk. Otherwise all rows are written when the file is closed. 263 306 ///TODO check whether this consumes too much resources or not. If it does, flush every N write operations instead 264 fFile->flush(); 307 try 308 { 309 fFile->flush(); 310 } 311 catch (CCfits::FitsError e) 312 { 313 std::stringstream str; 314 str << "Error while flushing bytes to disk. File: " << fFileName << " reason: " << e.message(); 315 fMess->Error(str); 316 } 265 317 } 266 318 // -------------------------------------------------------------------------- … … 274 326 // if (fTable != NULL) 275 327 // delete fTable; 276 277 328 std::string name = "TEND"; 278 double doubleValue = fEndMjD ;329 double doubleValue = fEndMjD - fRefMjD; 279 330 std::string comment = "Time of the last received data"; 280 331 fTable->addKey(name, doubleValue, comment); … … 286 337 delete [] fCopyBuffer; 287 338 fCopyBuffer = NULL; 339 if (fOwner && fNumOpenFitsFiles != NULL) 340 (*fNumOpenFitsFiles)--; 341 if (fMess) 342 delete fMess; 343 fMess = NULL; 288 344 } 289 345
Note:
See TracChangeset
for help on using the changeset viewer.