Changeset 13987 for trunk/Mars/mcore


Ignore:
Timestamp:
05/30/12 16:36:39 (12 years ago)
Author:
lyard
Message:
fixed checksum issues with the ofits class.
Location:
trunk/Mars/mcore
Files:
2 edited

Legend:

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

    r12995 r13987  
    6969        uint32_t *hilo  = reinterpret_cast<uint32_t*>(&buffer);
    7070
    71         for (size_t ii = 0; ii < len/2; ii++)
    72             hilo[(ii+1)%2] += sbuf[ii];
    73 
     71        for (size_t i = 0; i < len/2; i++)
     72        {
     73            //swap the bytes of the 32 bits value. but...
     74            //the hi and lo values are stored in fits-like order. do not swap them
     75            hilo[i%2] += (sbuf[i]&0xff00)>>8 | (sbuf[i]&0x00ff)<<8;
     76        }
    7477        HandleCarryBits();
    7578
     
    9295        };
    9396
    94         const uint32_t value = complm ? ~val() : val();   // complement each bit of the value
    95 /*
     97        uint32_t value = complm ? ~val() : val();   // complement each bit of the value
     98
    9699        for (int ii = 0; ii < 4; ii++)
    97100        {
    98101            uint8_t byte = (value >> (24 - (8 * ii)));
    99102
    100             const uint8_t quotient  = byte / 4 + offset;
     103            const uint8_t quotient  = byte / 4 + '0';
    101104            const uint8_t remainder = byte % 4;
    102105
     
    128131        }
    129132
     133        char lastChar = rc[15];
     134        for (int i=15;i>0;i--)
     135            rc[i] = rc[i-1];
     136        rc[0] = lastChar;
    130137        return rc;
    131         */
    132         const uint8_t *p = reinterpret_cast<const uint8_t*>(&value);
     138/*
     139        uint8_t *p = reinterpret_cast<uint8_t*>(&value);
     140        //swap the bytes of the value
     141        uint8_t temp;
     142        temp = p[0];
     143        p[0] = p[3];
     144        p[3] = temp;
     145        temp = p[1];
     146        p[1] = p[2];
     147        p[2] = temp;
    133148
    134149        for (int i=0; i<4; i++)
     
    160175
    161176        return rc;
    162     }
     177 */
     178   }
    163179};
    164180}
  • trunk/Mars/mcore/ofits.h

    r13115 r13987  
    326326        SetInt("TFIELDS",                    0, "number of fields in each row");
    327327        SetStr("EXTNAME", "", "name of extension table");
    328         SetStr("CHECKSUM", "{0000000000000000}", "Checksum for the whole file");
    329         SetInt("DATASUM",                    0, "Checksum for the data block");
     328        SetStr("CHECKSUM", "0000000000000000", "Checksum for the whole HDU");
     329        SetStr("DATASUM",  "         0", "Checksum for the data block");
    330330
    331331        ofstream::open(filename);
     
    608608        h.SetInt ("NAXIS",     0, "number of data axes");
    609609        h.SetBool("EXTEND", true, "FITS dataset may contain extensions");
    610 
     610        h.SetStr ("CHECKSUM","4AcB48bA4AbA45bA", "Checksum for the whole HDU");
     611        h.SetStr ("DATASUM", "         0", "Checksum for the data block");
    611612        h.AddComment("FITS (Flexible Image Transport System) format is defined in 'Astronomy");
    612613        h.AddComment("and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H");
     
    733734        if (tellp()%(80*36)>0)
    734735        {
    735             //cout << "fill" << endl;
    736736            const vector<char> filler(80*36-tellp()%(80*36));
    737737            write(filler.data(), filler.size());
    738738        }
    739739
    740         // We don't hav eto jump back to the end of the file
     740        // We don't have to jump back to the end of the file
    741741        SetInt("NAXIS2",  fTable.num_rows);
    742         SetInt("DATASUM", fDataSum.val());
     742
     743        ostringstream dataSumStr;
     744        dataSumStr << fDataSum.val();
     745        SetStr("DATASUM", dataSumStr.str());
    743746
    744747        const Checksum sum = WriteHeader();
     748
    745749        //sum += headersum;
    746750
    747         SetStr("CHECKSUM", "{"+(sum+fDataSum).str()+"}");
     751        SetStr("CHECKSUM", (sum+fDataSum).str());
    748752
    749753        const Checksum chk = WriteHeader();
Note: See TracChangeset for help on using the changeset viewer.