Changeset 15125 for trunk/Mars/mcore


Ignore:
Timestamp:
03/19/13 18:23:36 (12 years ago)
Author:
tbretz
Message:
Reorganized some code around the triming of comments to get more reasonable output.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Mars/mcore/ofits.h

    r14960 r15125  
    121121        }
    122122
    123         bool check()
     123        bool check(bool trim=false)
    124124        {
    125125            if (!FormatKey())
     
    129129                return false;
    130130
    131             const size_t sz = CalcSize();
    132             if (sz>80)
     131            size_t sz = CalcSize();
     132            if (sz<=80)
     133                return true;
     134
     135            if (!trim)
    133136            {
    134137                ostringstream sout;
     
    138141#else
    139142                gLog << ___err___ << "ERROR - " << sout.str() << endl;
     143#endif
    140144                return false;
    141 #endif
    142145            }
    143146
    144             return true;
     147            //looks like something went wrong. Maybe entry is too long ?
     148            //try to remove the comment
     149            comment = "";
     150
     151            sz = CalcSize();
     152            if (sz<=80)
     153            {
     154#ifndef __EXCEPTIONS
     155                ostringstream sout;
     156                sout << "Size " << sz << " of entry for key '" << key << "' exceeds 80 characters... removed comment.";
     157                gLog << ___warn___ << "WARNING - " << sout.str() << endl;
     158#endif
     159                return true;
     160            }
     161
     162            ostringstream sout;
     163            sout << "Size " << sz << " of entry for key '" << key << "' exceeds 80 characters even without comment.";
     164#ifdef __EXCEPTIONS
     165            throw runtime_error(sout.str());
     166#else
     167            gLog << ___err___ << "ERROR - " << sout.str() << endl;
     168            return false;
     169#endif
    145170        }
    146171
     
    257282        entry.changed = true;
    258283
    259         if (!entry.check())
    260         {
    261             if (!fCommentTrimming)
    262                 return false;
    263 
    264             //looks like something went wrong. Maybe entry is too long ?
    265             //try to remove the comment
    266             entry.comment = "";
    267             if (!entry.check())
    268                 return false;
    269 
    270 #ifdef __MARS__
    271             gLog << ___warn___ << "WARNING - Removed comment from over-sized entry " << key << endl;
    272 #endif
    273         }
     284        if (!entry.check(fCommentTrimming))
     285            return false;
    274286
    275287        fKeys.push_back(entry);
     
    460472        {
    461473            ostringstream sout;
    462             sout << "Header already writtenm, no new column can be defined... ignoring column '" << name << "'";
     474            sout << "Header already written, no new column can be defined... ignoring column '" << name << "'";
    463475#ifdef __EXCEPTIONS
    464476            throw runtime_error(sout.str());
Note: See TracChangeset for help on using the changeset viewer.