Index: /trunk/Mars/mcore/checksum.h
===================================================================
--- /trunk/Mars/mcore/checksum.h	(revision 13986)
+++ /trunk/Mars/mcore/checksum.h	(revision 13987)
@@ -69,7 +69,10 @@
         uint32_t *hilo  = reinterpret_cast<uint32_t*>(&buffer);
 
-        for (size_t ii = 0; ii < len/2; ii++)
-            hilo[(ii+1)%2] += sbuf[ii];
-
+        for (size_t i = 0; i < len/2; i++)
+        {
+            //swap the bytes of the 32 bits value. but...
+            //the hi and lo values are stored in fits-like order. do not swap them
+            hilo[i%2] += (sbuf[i]&0xff00)>>8 | (sbuf[i]&0x00ff)<<8;
+        }
         HandleCarryBits();
 
@@ -92,11 +95,11 @@
         };
 
-        const uint32_t value = complm ? ~val() : val();   // complement each bit of the value
-/*
+        uint32_t value = complm ? ~val() : val();   // complement each bit of the value
+
         for (int ii = 0; ii < 4; ii++)
         {
             uint8_t byte = (value >> (24 - (8 * ii)));
 
-            const uint8_t quotient  = byte / 4 + offset;
+            const uint8_t quotient  = byte / 4 + '0';
             const uint8_t remainder = byte % 4;
 
@@ -128,7 +131,19 @@
         }
 
+        char lastChar = rc[15];
+        for (int i=15;i>0;i--)
+            rc[i] = rc[i-1];
+        rc[0] = lastChar;
         return rc;
-        */
-        const uint8_t *p = reinterpret_cast<const uint8_t*>(&value);
+/*
+        uint8_t *p = reinterpret_cast<uint8_t*>(&value);
+        //swap the bytes of the value
+        uint8_t temp;
+        temp = p[0];
+        p[0] = p[3];
+        p[3] = temp;
+        temp = p[1];
+        p[1] = p[2];
+        p[2] = temp;
 
         for (int i=0; i<4; i++)
@@ -160,5 +175,6 @@
 
         return rc;
-    }
+ */
+   }
 };
 }
Index: /trunk/Mars/mcore/ofits.h
===================================================================
--- /trunk/Mars/mcore/ofits.h	(revision 13986)
+++ /trunk/Mars/mcore/ofits.h	(revision 13987)
@@ -326,6 +326,6 @@
         SetInt("TFIELDS",                    0, "number of fields in each row");
         SetStr("EXTNAME", "", "name of extension table");
-        SetStr("CHECKSUM", "{0000000000000000}", "Checksum for the whole file");
-        SetInt("DATASUM",                    0, "Checksum for the data block");
+        SetStr("CHECKSUM", "0000000000000000", "Checksum for the whole HDU");
+        SetStr("DATASUM",  "         0", "Checksum for the data block");
 
         ofstream::open(filename);
@@ -608,5 +608,6 @@
         h.SetInt ("NAXIS",     0, "number of data axes");
         h.SetBool("EXTEND", true, "FITS dataset may contain extensions");
-
+        h.SetStr ("CHECKSUM","4AcB48bA4AbA45bA", "Checksum for the whole HDU");
+        h.SetStr ("DATASUM", "         0", "Checksum for the data block");
         h.AddComment("FITS (Flexible Image Transport System) format is defined in 'Astronomy");
         h.AddComment("and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H");
@@ -733,17 +734,20 @@
         if (tellp()%(80*36)>0)
         {
-            //cout << "fill" << endl;
             const vector<char> filler(80*36-tellp()%(80*36));
             write(filler.data(), filler.size());
         }
 
-        // We don't hav eto jump back to the end of the file
+        // We don't have to jump back to the end of the file
         SetInt("NAXIS2",  fTable.num_rows);
-        SetInt("DATASUM", fDataSum.val());
+
+        ostringstream dataSumStr;
+        dataSumStr << fDataSum.val();
+        SetStr("DATASUM", dataSumStr.str());
 
         const Checksum sum = WriteHeader();
+
         //sum += headersum;
 
-        SetStr("CHECKSUM", "{"+(sum+fDataSum).str()+"}");
+        SetStr("CHECKSUM", (sum+fDataSum).str());
 
         const Checksum chk = WriteHeader();
