Index: trunk/FACT++/src/fitsCompressor.cc
===================================================================
--- trunk/FACT++/src/fitsCompressor.cc	(revision 16887)
+++ trunk/FACT++/src/fitsCompressor.cc	(revision 16897)
@@ -433,4 +433,6 @@
         bool writeBinaryRow(const char* bufferToWrite);
 
+        uint32_t getRowWidth();
+
         ///@brief assign a given (already loaded) drs calibration
         void setDrsCalib(int16_t* data);
@@ -627,4 +629,5 @@
     if (_buffer != NULL)
     {
+        _buffer = _buffer-4;
         delete[] _buffer;
         _buffer = NULL;
@@ -649,4 +652,5 @@
     if (_buffer)
     {
+        _buffer = _buffer - 4;
         delete[] _buffer;
         for (uint32_t i=0;i<_compressedBuffer.size();i++)
@@ -657,6 +661,8 @@
         }
     }
-    _buffer = new char[_rowWidth*_numRowsPerTile];
+    _buffer = new char[_rowWidth*_numRowsPerTile + 12];
     if (_buffer == NULL) return false;
+    memset(_buffer, 0, 4);
+    _buffer = _buffer + 4;
     if (_compressedBuffer.size() != _numThreads)
     {
@@ -667,5 +673,5 @@
     {
         _transposedBuffer[i] = new char[_rowWidth*_numRowsPerTile];
-        _compressedBuffer[i] = new char[_rowWidth*_numRowsPerTile + _columns.size() + sizeof(TileHeader)]; //use a bit more memory for compression flags
+        _compressedBuffer[i] = new char[_rowWidth*_numRowsPerTile + _columns.size() + sizeof(TileHeader) + 12]; //use a bit more memory for compression flags and checksumming
         if (_transposedBuffer[i] == NULL || _compressedBuffer[i] == NULL)
             return false;
@@ -1133,7 +1139,9 @@
         setHeaderKey(HeaderEntry("PCOUNT", 0, "size of special data area"));
     }
+    ostringstream str;
+
     writeHeader(true);
 
-    ostringstream str;
+    str.str("");
     str << _checksum.val();
 
@@ -1160,4 +1168,5 @@
 {
     uint32_t thisRoundNumRows = (_totalNumRows%_numRowsPerTile) ? _totalNumRows%_numRowsPerTile : _numRowsPerTile;
+
     //copy the tile and transpose it
     uint32_t offset = 0;
@@ -1215,4 +1224,9 @@
     }
     return _file.good();
+}
+
+uint32_t CompressedFitsWriter::getRowWidth()
+{
+    return _rowWidth;
 }
 
@@ -1642,5 +1656,7 @@
     //allocate the buffer for temporary storage of each read/written row
     uint32_t rowWidth = inFile.GetUInt("NAXIS1");
-    char* buffer = new char[rowWidth];
+    char* buffer = new char[rowWidth + 12];
+    memset(buffer, 0, 4);
+    buffer = buffer+4;
 
     //get the source columns
@@ -1651,4 +1667,5 @@
 
     //Add columns.
+    uint32_t totalRowWidth = 0;
     for (uint32_t i=0;i<sortedColumns.size(); i++)
     {
@@ -1674,4 +1691,6 @@
         smoothmanProcessings[1] = FACT_HUFFMAN16;
 //        smoothmanProcessings[2] = FACT_RAW;
+
+        totalRowWidth += sortedColumns[i].bytes;
 
         //first lets see if we do have an explicit request
@@ -1735,4 +1754,6 @@
 //        cout << i->first << endl;
     }
+
+    outFile.setHeaderKey(CompressedFitsFile::HeaderEntry("RAWSUM", "         0", "Checksum of raw littlen endian data"));
 
     //deal with the DRS calib
@@ -1826,4 +1847,5 @@
     }
 
+    Checksum rawsum;
     //Convert each row one after the other
     for (uint32_t i=0;i<inFile.GetNumRows();i++)
@@ -1838,4 +1860,16 @@
             count++;
         }
+
+        char* checkSumPointer = buffer;
+        const int chkOffset = (i*totalRowWidth)%4;
+        checkSumPointer -= chkOffset;
+        uint32_t sizeToChecksum = totalRowWidth + chkOffset;
+        if (sizeToChecksum%4 != 0)
+        {
+            int32_t extraBytes = 4 - (sizeToChecksum%4);
+            memset(checkSumPointer+sizeToChecksum, 0, extraBytes);
+            sizeToChecksum += extraBytes;
+        }
+        rawsum.add(checkSumPointer, sizeToChecksum, false);
 
         if (startCellOffset != -1)
@@ -1851,4 +1885,7 @@
         outFile.writeBinaryRow(buffer);
     };
+    ostringstream strSum;
+    strSum << rawsum.val();
+    outFile.setHeaderKey(CompressedFitsFile::HeaderEntry("RAWSUM", strSum.str(), "Checksum of raw littlen endian data"));
 
     //Get table name for later use in case the compressed file is to be verified
@@ -1927,4 +1964,8 @@
             continue;
         }
+        if (k == "RAWSUM")
+        {
+            continue;
+        }
 
         if (k == "ZDTASUM")
@@ -2028,5 +2069,5 @@
 //    verifyFile.close();
     if (!verifyFile.IsFileOk())
-        cout << "ERROR: file checksum seems wrong" << endl;
+        cout << "ERROR: file checksums seems wrong" << endl;
 
     reconstructedFile.close();
@@ -2051,7 +2092,7 @@
     }
 
+    buffer = buffer-4;
     delete[] buffer;
     return 0;
-
-}
-
+}
+
