Changeset 12848 for trunk


Ignore:
Timestamp:
02/06/12 09:27:44 (13 years ago)
Author:
tbretz
Message:
If we have a fixed char-array and the unit is either text or string replace the format string by an A for ASCII characters.
File:
1 edited

Legend:

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

    r12710 r12848  
    2323#include <cstdio> // for file rename
    2424#include <cerrno>
     25
     26#include <boost/algorithm/string/predicate.hpp>
    2527
    2628using namespace std;
     
    6365    fDataPointer = dataPointer;
    6466
    65     //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
    66     if ((desc.size() == dataFormat.size()+1) || //regular service
    67         (desc.size() == dataFormat.size()+2))//service with ending string. skipped in fits
    68     {//services have one (or two) more description than columns. skip the first entry while copying as it describes the table itself.
     67    //we will copy this information here. It duplicates the data, which is not great,
     68    // but it is the easiest way of doing it right now
     69    if (
     70        (desc.size() == dataFormat.size()+1) || // regular service
     71        (desc.size() == dataFormat.size()+2)    // service with ending string. skipped in fits
     72       )
     73    {
     74        //services have one (or two) more description than columns. skip the first entry while copying as it describes the table itself.
     75
    6976        fDataColDesc.clear();
     77
    7078        fTableDesc = desc[0].comment;
    7179        if (fTableDesc.size() > 68)
    7280        {
    73             out->Warn("Table description \"" + fTableDesc + "\" too long. truncating it (68 char max.)");
     81            out->Warn("Table description '" + fTableDesc + "' exceeds 68 chars... truncated.");
    7482            fTableDesc = fTableDesc.substr(0,68);
    7583        }
    76         for (unsigned int i=0;i<dataFormat.size(); i++)
     84
     85        for (unsigned int i=0; i<dataFormat.size(); i++)
    7786        {
    7887            string name = desc[i+1].name;
    7988            if (name.length() > 68)
    8089            {
    81                 out->Warn("Column name " + name + "too long. truncating it (68 char max.)");
     90                out->Warn("Column name '" + name + "' exceeds 68 chars... truncated.");
    8291                name = name.substr(0, 68);
    8392            }
     93
    8494            string comment = desc[i+1].comment;
    85             if ((comment.length() + name.length()) > 71)
     95            if (comment.length() + name.length() > 71)
    8696            {
    87                 out->Warn("Column " + name + " added to \"" + comment + "\" too long. truncating to fit 68 chars.");
     97                out->Warn("Column '" + name + " / " + comment + "' exceeds 68 chars... truncated.");
    8898                comment = comment.substr(0,68);
    8999            }
     100
    90101            string unit = desc[i+1].unit;
    91             if (unit.length() > 68)  unit = comment.substr(0,68);
     102            if (unit.length() > 68)
     103            {
     104                out->Warn("Unit '" + name + "' exceeds 68 chars... truncated.");
     105                unit = comment.substr(0,68);
     106            }
     107
     108            const size_t p = fDataFormats[i].find_last_of('B');
     109            if ((boost::iequals(unit, "text") || boost::iequals(unit, "string")) && p!=string::npos)
     110            {
     111                out->Info("Column '" + name + "' detected to be an ascii string (FITS format 'A').");
     112                fDataFormats[i].replace(p, 1, "A");
     113            }
     114
    92115            fDataColDesc.push_back(Description(name, comment, unit));
    93116        }
Note: See TracChangeset for help on using the changeset viewer.