Changeset 17259 for trunk/FACT++/src


Ignore:
Timestamp:
10/18/13 16:50:39 (11 years ago)
Author:
lyard
Message:
added output of tables in a file for fitsdump
File:
1 edited

Legend:

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

    r17166 r17259  
    7272    /// Lists all columns of an open file
    7373    void List();                         
     74    void ListFileContent(const string& filename);
    7475    void ListHeader(const string& filename);
    7576    void ListKeywords(ostream &);
     
    165166}
    166167
     168void FitsDumper::ListFileContent(const string& filename)
     169{
     170    ofstream fout(filename=="-"?"/dev/stdout":filename);
     171    if (!fout)
     172    {
     173        cerr << "Cannot open file " << filename << ": " << strerror(errno) << endl;
     174        return;
     175    }
     176
     177    int table_id = 0;
     178
     179    vector<string> table_names;
     180    vector<uint32_t> table_rows;
     181    try
     182    {
     183
     184        while (true)
     185        {
     186            clear();
     187            seekg(0);
     188            fTable = Table();
     189            Constructor(fFilename, "", "", false, table_id);
     190
     191            table_names.push_back(fTable.Get<string>("EXTNAME"));
     192            table_rows.push_back(GetNumRows());
     193
     194            table_id++;
     195        }
     196    }
     197    catch (runtime_error e)
     198    {
     199        //nothing to see here, just catching the error thrown by EOF
     200    }
     201
     202    fout << "File " << fFilename << " has " << table_names.size() << " tables: " << endl;
     203    for (uint32_t i=0; i<table_names.size(); i++)
     204    {
     205        fout << "#" << i << ": \"" << table_names[i];
     206        fout << "\" num. rows = " << table_rows[i] << endl;
     207    }
     208}
    167209void FitsDumper::ListHeader(const string& filename)
    168210{
     
    929971        List();
    930972
     973    if (conf.Get<bool>("filecontent"))
     974        ListFileContent(conf.Get<string>("outfile"));
     975
    931976    if (conf.Get<bool>("header"))
    932977        ListHeader(conf.Get<string>("outfile"));
    933978
    934979
    935     if (conf.Get<bool>("header") || conf.Get<bool>("list"))
     980    if (conf.Get<bool>("header") || conf.Get<bool>("list") || conf.Get<bool>("filecontent"))
    936981        return 1;
    937982
     
    11101155        ("limit",       var<size_t>(size_t(0)), "Limit for the maximum number of rows to read (0=unlimited)")
    11111156        ("tablename,t", var<string>(""),        "Name of the table to open. If not specified, first binary table is opened")
     1157        ("filecontent", po_switch(),            "List the number of tables in the file, along with their name")
    11121158#ifdef HAVE_ROOT
    11131159        ("root,r",      po_switch(),            "Enable root mode")
Note: See TracChangeset for help on using the changeset viewer.