Changeset 10946 for trunk/FACT++/src


Ignore:
Timestamp:
06/09/11 13:29:21 (13 years ago)
Author:
tbretz
Message:
Changed order in Write; properly catch exceptions from Converter::ToFits
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/Fits.cc

    r10933 r10946  
    265265void Fits::Write(Converter* conv)
    266266{
    267 
    268         fTable->makeThisCurrent();
    269         int status(0);
    270         if (fits_insert_rows(fTable->fitsPointer(), fNumRows, 1, &status))
    271         {
    272                 ostringstream str;
    273                 str << "Could not insert row in file " << fFileName << ". cfitsio error code: " << status;
    274                 fMess->Error(str);
    275         }
    276         fNumRows++;
    277 
    278         //the first standard variable is the current MjD
    279         if (fEndMjD == 0)
    280         {
    281                 double doubleValue = *static_cast<double*>(fStandardPointers[0]);// - fRefMjD;
    282                 WriteSingleHeaderKey("TSTART", doubleValue, "Time of the first received data");
    283         }
    284         fEndMjD = * static_cast<double*>(fStandardPointers[0]);
    285                        
    286         //first copy the standard variables to the copy buffer
    287         int shift = 0;
    288 
    289         for (unsigned int i=0;i<fStandardNumBytes.size();i++)
    290         {
    291                 const char * charSrc = static_cast<char*>(fStandardPointers[i]);
    292                 reverse_copy(charSrc, charSrc+fStandardNumBytes[i], &fCopyBuffer[shift]);
    293                 shift+= fStandardNumBytes[i];   
    294         }
    295 
    296         //now take care of the DIM data. The Converter is here for that purpose
    297         conv->ToFits(static_cast<void*>(&fCopyBuffer[shift]), fDataPointer, fDataNumBytes);
    298                          
    299         //data copied to buffer, can write to fits
    300         fits_write_tblbytes(fFile->fitsPointer(), fNumRows, 1, fTotalNumBytes, fCopyBuffer, &status);
    301         if (status)
    302         {
    303                 char text[30];//max length of cfitsio error strings (from doc)
    304                 fits_get_errstatus(status, text);
    305                 ostringstream str;
    306                 str << "Error while writing FITS row in " << fFileName << ". Message: " << text << " [" << status << "]";
    307                 fMess->Error(str);     
    308         }
    309 }
     267    //first copy the standard variables to the copy buffer
     268    int shift = 0;
     269    for (unsigned int i=0;i<fStandardNumBytes.size();i++)
     270    {
     271        const char *charSrc = reinterpret_cast<char*>(fStandardPointers[i]);
     272        reverse_copy(charSrc, charSrc+fStandardNumBytes[i], &fCopyBuffer[shift]);
     273        shift += fStandardNumBytes[i];
     274    }
     275
     276    try
     277    {
     278        //now take care of the DIM data. The Converter is here for that purpose
     279        conv->ToFits(&fCopyBuffer[shift], fDataPointer, fDataNumBytes);
     280    }
     281    catch (const runtime_error &e)
     282    {
     283        ostringstream str;
     284        str << fFileName << ": " << e.what();
     285        fMess->Error(str);
     286        return;
     287    }
     288
     289    fTable->makeThisCurrent();
     290
     291    int status(0);
     292    if (fits_insert_rows(fTable->fitsPointer(), fNumRows, 1, &status))
     293    {
     294        ostringstream str;
     295        str << "Inserting row into " << fFileName << " failed (fits_insert_rows, rc=" << status << ")";
     296        fMess->Error(str);
     297        // FIXME: What is a proper action here?
     298    }
     299
     300    fNumRows++;
     301
     302    //the first standard variable is the current MjD
     303    if (fEndMjD == 0)
     304    {
     305        const double doubleValue = *reinterpret_cast<double*>(fStandardPointers[0]);
     306        WriteSingleHeaderKey("TSTART", doubleValue,
     307                             "Time of the first received data");
     308    }
     309    fEndMjD = *reinterpret_cast<double*>(fStandardPointers[0]);
     310
     311    //data copied to buffer, can write to fits
     312    fits_write_tblbytes(fFile->fitsPointer(), fNumRows, 1, fTotalNumBytes, fCopyBuffer, &status);
     313    if (status)
     314    {
     315        char text[30];//max length of cfitsio error strings (from doc)
     316        fits_get_errstatus(status, text);
     317        ostringstream str;
     318        str << "Writing FITS row " << fNumRow << " in " << fFileName << ": " << text << " (file_write_tblbytes, rc=" << status << ")";
     319        fMess->Error(str);
     320        // FIXME: What is a proper action here?
     321    }
     322}
     323
    310324// --------------------------------------------------------------------------
    311325//
Note: See TracChangeset for help on using the changeset viewer.