Changeset 11911 for trunk


Ignore:
Timestamp:
08/24/11 15:14:40 (13 years ago)
Author:
lyard
Message:
moved fitsdump from interactive to command line
File:
1 edited

Legend:

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

    r11910 r11911  
    197197{
    198198    int cnt = 0;
    199 
    200199    vector<pair<int, int> >::const_iterator jt = ranges.begin();
    201200    for (vector<MyColumn*>::const_iterator it=list.begin(); it!=list.end(); it++, jt++)
    202201    {
     202        if (jt == ranges.end())
     203        {
     204            cout << "ERROR: END OF RANGE POINTER REACHED" << endl;
     205            return false;
     206        }
    203207        const MyColumn *col = *it;
    204208
     
    210214
    211215        // Loop over all array entries
     216        int sizeToSkip = 0;
     217        switch (col->type())
     218        {
     219        case CCfits::Tbyte:     sizeToSkip = sizeof(uint8_t); break;
     220        case CCfits::Tushort:   sizeToSkip = sizeof(uint16_t); break;
     221        case CCfits::Tuint:
     222        case CCfits::Tulong:    sizeToSkip = sizeof(uint32_t); break;
     223        case CCfits::Tshort:    sizeToSkip = sizeof(int16_t); break;
     224        case CCfits::Tint:
     225        case CCfits::Tlong:     sizeToSkip = sizeof(int32_t); break;
     226        case CCfits::Tlonglong: sizeToSkip = sizeof(int64_t); break;
     227        case CCfits::Tfloat:    sizeToSkip = sizeof(float); break;
     228        case CCfits::Tdouble:   sizeToSkip = sizeof(double); break;
     229        default:
     230            cerr << "Data type not implemented yet." << endl;
     231            return 0;
     232        }
     233        ptr += sizeToSkip*jt->first;
    212234        for (int width=jt->first; width<jt->second; width++)
    213235        {
     
    467489bool FitsDumper::Dump(const string &filename, const vector<string> &list, int precision)
    468490{
     491
     492    //first of all, let's separate the columns from their ranges and check that the requested columns are indeed part of the file
     493    vector<pair<int, int> > ranges;
     494    vector<string> listNamesOnly;
    469495    for (vector<string>::const_iterator it=list.begin(); it!=list.end(); it++)
    470         if (fColMap.find(*it) == fColMap.end())
    471         {
    472             cerr << "WARNING - Column '" << *it << "' not found in table." << endl;
     496    {
     497        string columnNameOnly = *it;
     498        unsigned long bracketIndex0 = columnNameOnly.find_first_of('[');
     499        unsigned long bracketIndex1 = columnNameOnly.find_first_of(']');
     500        unsigned long colonIndex = columnNameOnly.find_first_of(':');
     501        cout << bracketIndex0 << " " << bracketIndex1 << " " << colonIndex << endl;
     502        int columnStart = -1;
     503        int columnEnd = -1;
     504        if (bracketIndex0 != string::npos)
     505        {//there is a range given. Extract the range
     506            if (colonIndex != string::npos)
     507            {//we have a range here
     508                columnStart = atoi(columnNameOnly.substr(bracketIndex0+1, colonIndex-(bracketIndex0+1)).c_str());
     509                columnEnd = atoi(columnNameOnly.substr(colonIndex+1, bracketIndex1-(colonIndex+1)).c_str());
     510                columnEnd++;
     511            }
     512            else
     513            {//only a single index there
     514                columnStart = atoi(columnNameOnly.substr(bracketIndex0+1, bracketIndex1 - (bracketIndex0+1)).c_str());
     515                columnEnd = columnStart+1;
     516//                cout << "Cstart " << columnStart  << " end: " << columnEnd << endl;
     517            }
     518            columnNameOnly = columnNameOnly.substr(0, bracketIndex0);
     519        }
     520
     521        if (fColMap.find(columnNameOnly) == fColMap.end())
     522        {
     523            cerr << "ERROR - Column '" << columnNameOnly << "' not found in table." << endl;
    473524            return false;
    474525        }
    475 
     526//        cout << "The column name is: " << columnNameOnly << endl;
     527        MyColumn *cCol = static_cast<MyColumn*>(fColMap.find(columnNameOnly)->second);
     528        if (bracketIndex0 == string::npos)
     529        {//no range given: use the full range
     530            ranges.push_back(make_pair(0, cCol->width()));
     531            columnStart = 0;
     532            columnEnd = 1;
     533        }
     534        else
     535        {//use the range extracted earlier
     536            if (columnStart < 0)
     537            {
     538                cerr << "ERROR - Start range for column " << columnNameOnly << " is less than zero (" << columnStart << "). Aborting" << endl;
     539                return false;
     540            }
     541            if (columnEnd > cCol->width())
     542            {
     543                cerr << "ERROR - End range for column " << columnNameOnly << " is greater than the last element (" << cCol->width() << " vs " << columnEnd << "). Aborting" << endl;
     544                return false;
     545            }
     546            ranges.push_back(make_pair(columnStart, columnEnd));
     547        }
     548//        cout << "Will be exporting from " << columnStart << " to " << columnEnd-1 << " for column " << columnNameOnly << endl;
     549        listNamesOnly.push_back(columnNameOnly);
     550    }
    476551    // FIXME: Maybe do this when opening a table?
    477552    const vector<int> offsets = CalculateOffsets();
     
    501576    out << "## --------------------------------------------------------------------------\n";
    502577    out << "#\n";
    503     for (vector<string>::const_iterator it=list.begin(); it!=list.end(); it++)
     578    for (vector<string>::const_iterator it=listNamesOnly.begin(); it!=listNamesOnly.end(); it++)
    504579    {
    505580        const MyColumn *col = static_cast<MyColumn*>(fTable->column()[*it]);
     
    514589    // Loop over all columns in our list of requested columns
    515590    vector<MyColumn*> columns;
    516     vector<pair<int, int> > ranges;
    517     for (vector<string>::const_iterator it=list.begin(); it!=list.end(); it++)
     591    for (vector<string>::const_iterator it=listNamesOnly.begin(); it!=listNamesOnly.end(); it++)
    518592    {
    519593        MyColumn *cCol = static_cast<MyColumn*>(fColMap.find(*it)->second);
    520594        //CCfits::Column* cCol = fColMap.find(*it)->second;
    521595        columns.push_back(cCol);
    522         int start, end;
     596/*        int start, end;
    523597        if (cCol->width() != 1)
    524598        {//get the desired range of that column to output
     
    544618        {
    545619            ranges.push_back(make_pair(0, cCol->width()));
    546         }
    547     }
    548 
     620        }*/
     621    }
    549622    const int size = offsets[offsets.size()-1];
    550623    unsigned char* fitsBuffer = new unsigned char[size];
Note: See TracChangeset for help on using the changeset viewer.