Changeset 11910 for trunk


Ignore:
Timestamp:
08/23/11 12:09:46 (13 years ago)
Author:
lyard
Message:
added vector columns dump
File:
1 edited

Legend:

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

    r11578 r11910  
    1414
    1515using namespace std;
     16
     17class MyColumn : public CCfits::Column
     18{
     19public:
     20    const string &comment() const { return CCfits::Column::comment(); }
     21    long width() const
     22    {//the width() method seems to be buggy (or empty ?) as it always return 1... redo it ourselves.
     23        string inter = format();
     24        inter = inter.substr(0, inter.size()-1);
     25        return atoi(inter.c_str());
     26    }
     27};
    1628
    1729class FitsDumper
     
    2537    CCfits::FITS  *fFile;                 /// FITS pointer
    2638    CCfits::Table *fTable;                /// Table pointer
    27     map<string, CCfits::Column*> fColMap; /// map between the column names and their CCfits objects
     39    map<string, MyColumn*> fColMap; /// map between the column names and their CCfits objects
    2840
    2941    // Convert CCfits::ValueType into a human readable string
     
    4355
    4456    /// Write a single row of the selected data
    45     int  WriteRow(ostream &, const vector<CCfits::Column*> &, const vector<int> &, unsigned char *) const;
     57    int  WriteRow(ostream &, const vector<MyColumn*> &, const vector<int> &, unsigned char *, const vector<pair<int, int> >&) const;
    4658
    4759    bool OpenFile(const string &);        /// Open a file
     
    182194//!         the memory were the row has been loaded by cfitsio
    183195//
    184 int FitsDumper::WriteRow(ostream &out, const vector<CCfits::Column*> &list, const vector<int> &offsets, unsigned char* fitsBuffer) const
     196int FitsDumper::WriteRow(ostream &out, const vector<MyColumn*> &list, const vector<int> &offsets, unsigned char* fitsBuffer, const vector<pair<int, int> >& ranges) const
    185197{
    186198    int cnt = 0;
    187199
    188     for (vector<CCfits::Column*>::const_iterator it=list.begin(); it!=list.end(); it++)
    189     {
    190         const CCfits::Column *col = *it;
     200    vector<pair<int, int> >::const_iterator jt = ranges.begin();
     201    for (vector<MyColumn*>::const_iterator it=list.begin(); it!=list.end(); it++, jt++)
     202    {
     203        const MyColumn *col = *it;
    191204
    192205        // CCfits starts counting at 1 not 0
     
    197210
    198211        // Loop over all array entries
    199         for (int width=0; width<col->width(); width++)
     212        for (int width=jt->first; width<jt->second; width++)
    200213        {
    201214            switch (col->type())
     
    243256    map<int,int> sizes;
    244257
    245     for (map<string, CCfits::Column*>::const_iterator it=fColMap.begin();
     258    for (map<string, MyColumn*>::const_iterator it=fColMap.begin();
    246259         it!=fColMap.end(); it++)
    247260    {
     
    325338    }
    326339
    327     fColMap = fTable->column();
     340    map<string, CCfits::Column*>& tCols = fTable->column();
     341    for (map<string, CCfits::Column*>::const_iterator it = tCols.begin(); it != tCols.end(); it++)
     342    {
     343        fColMap.insert(make_pair(it->first, static_cast<MyColumn*>(it->second)));
     344    }
     345//    fColMap = fTable->column();
    328346
    329347    fTable->makeThisCurrent();
     
    336354}
    337355
    338 class MyColumn : public CCfits::Column
    339 {
    340 public:
    341     const string &comment() const { return CCfits::Column::comment(); }
    342 };
    343356
    344357void FitsDumper::List()
     
    358371        CCfits::Table *table = dynamic_cast<CCfits::Table*>(extMap.find(it->first)->second);
    359372
     373        table->makeThisCurrent();
     374        table->readData();
     375
    360376        cout << " " << it->first << " [" << table->rows() << "]\n";
    361377
    362378        const map<string, CCfits::Column*> &cols = table->column();
     379
     380//        for (map<string, CCfits::Column*>::const_iterator id = cols.begin(); ib != cols.end(); ib++)
     381//        {
     382//            TFORM
     383//        }
    363384
    364385        for (map<string, CCfits::Column*>::const_iterator ic=cols.begin();
     
    492513
    493514    // Loop over all columns in our list of requested columns
    494     vector<CCfits::Column*> columns;
     515    vector<MyColumn*> columns;
     516    vector<pair<int, int> > ranges;
    495517    for (vector<string>::const_iterator it=list.begin(); it!=list.end(); it++)
    496         columns.push_back(fColMap.find(*it)->second);
    497 
     518    {
     519        MyColumn *cCol = static_cast<MyColumn*>(fColMap.find(*it)->second);
     520        //CCfits::Column* cCol = fColMap.find(*it)->second;
     521        columns.push_back(cCol);
     522        int start, end;
     523        if (cCol->width() != 1)
     524        {//get the desired range of that column to output
     525            cout << "Column " << *it << " has " << cCol->width() << " entries. Please tell us which of them should be outputted. " << endl;
     526            cout << "Please enter the first value to dump (min 0, max " << cCol->width()-1 << "): ";
     527            cin >> start;
     528            while (start < 0 || start > cCol->width()-1)
     529            {
     530                cout << "value invalid. Please stick to the range 0-" << cCol->width()-1 << ": ";
     531                cin >> start;
     532            }
     533            cout << "Please enter the last value to dump (min " << start << ", max " << cCol->width()-1 << "): ";
     534            cin >> end;
     535            while (end < start || end > cCol->width()-1)
     536            {
     537                cout << "value invalid. Please stick to the range " << start << "-" << cCol->width()-1 << ": ";
     538                cin >> end;
     539            }
     540            end++;
     541            ranges.push_back(make_pair(start, end));
     542        }
     543        else
     544        {
     545            ranges.push_back(make_pair(0, cCol->width()));
     546        }
     547    }
    498548
    499549    const int size = offsets[offsets.size()-1];
     
    509559            break;
    510560        }
    511         if (WriteRow(out, columns, offsets, fitsBuffer)<0)
     561        if (WriteRow(out, columns, offsets, fitsBuffer, ranges)<0)
    512562        {
    513563            status=1;
     
    623673    if (conf.Has("outfile"))
    624674    {
     675        if (!conf.Has("col"))
     676        {
     677            cout << "Please specify the columns that should be dumped as arguments. Aborting" << endl;
     678            return 0;
     679        }
    625680        if (!Dump(conf.Get<string>("outfile"),
    626681                  conf.Get<vector<string>>("col"),
Note: See TracChangeset for help on using the changeset viewer.