Ignore:
Timestamp:
12/11/11 16:33:32 (13 years ago)
Author:
tbretz
Message:
Implemented to allow a missing END tag or decline it.
File:
1 edited

Legend:

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

    r12707 r12714  
    2222#include <iostream>
    2323#define gLog cerr
    24 #define ___err___ ""
    25 #define ___all___ ""
     24#define ___err___  ""
     25#define ___all___  ""
    2626#else
    2727#include "MLog.h"
    2828#include "MLogManip.h"
    29 #define ___err___ err
    30 #define ___all___ all
     29#define ___err___  err
     30#define ___all___  all
    3131#endif
    3232
     
    389389    size_t fRow;
    390390
    391     vector<string> ReadBlock(vector<string> &vec)
    392     {
    393         bool endtag = false;
     391    bool ReadBlock(vector<string> &vec)
     392    {
     393        int endtag = 0;
    394394        for (int i=0; i<36; i++)
    395395        {
     
    400400                break;
    401401
    402             if (c[0]==0)
    403                 return vector<string>();
     402//            if (c[0]==0)
     403//                return vector<string>();
    404404
    405405            string str(c);
     
    408408//                cout << setw(2) << i << "|" << str << "|" << (endtag?'-':'+') << endl;
    409409
    410             if (str=="END                                                                             ")
    411             {
    412                 endtag = true;
    413 
    414                 // Make sure that no empty vector is returned
    415                 if (vec.size()%36==0)
    416                     vec.push_back(string("END     = '' / "));
    417             }
    418             else
    419             {
    420                 char value = str[0];
    421                 int valuei = (int)(value);
    422             }
    423             //Would have liked to do it with a string comparison, but could not figure out the character for value 32...
    424             bool isNULL = true;
    425             for (int j=0;j<80;j++)
    426                 if (int(str[j]) != 32)
    427                     isNULL = false;
    428             if (isNULL)
    429             {
    430                 if (!endtag)
    431                     cout << "WARNING: END keyword missing. Loaded data may be corrupted" << endl;
    432 
    433                 endtag = true;
    434 
    435                 if (vec.size()%36==0)
    436                     vec.push_back(string("END     = '' / "));
    437             }
    438 
    439             if (endtag)
     410            if (endtag==2 || str=="END                                                                             ")
     411            {
     412                endtag = 2; // valid END tag found
    440413                continue;
     414            }
     415
     416            if (endtag==1 || str=="                                                                                ")
     417            {
     418                endtag = 1; // end tag not found, but expected to be there
     419                continue;
     420            }
    441421
    442422            vec.push_back(str);
    443423        }
    444424
    445         return vec;
     425        // Make sure that no empty vector is returned
     426        if (endtag && vec.size()%36==0)
     427            vec.push_back(string("END     = '' / "));
     428
     429        return endtag==2;
    446430    }
    447431
     
    457441
    458442public:
    459     fits(const string &fname) : izstream(fname.c_str())
     443    fits(const string &fname, bool force=false) : izstream(fname.c_str())
    460444    {
    461445        char simple[10];
     
    483467            {
    484468                // FIXME: Set limit on memory consumption
    485                 ReadBlock(block);
     469                const int rc = ReadBlock(block);
    486470                if (!good())
    487471                {
     
    496480
    497481                if (block.size()%36)
     482                {
     483                    if (!rc && !force)
     484                    {
     485                        clear(rdstate()|ios::badbit);
     486#ifdef __EXCEPTIONS
     487                        throw runtime_error("END keyword missing in FITS header.");
     488#else
     489                        gLog << ___err__ << "ERROR - END keyword missing in FITS file... file might be corrupted." << endl;
     490                        return;
     491#endif
     492                    }
    498493                    break;
     494                }
    499495            }
    500496
     
    609605        {
    610606            ostringstream str;
    611             str <<"SetPtrAddress('" << name << "') - Column not found." << endl;
     607            str << "SetPtrAddress('" << name << "') - Column not found." << endl;
    612608#ifdef __EXCEPTIONS
    613609            throw runtime_error(str.str());
Note: See TracChangeset for help on using the changeset viewer.