Index: trunk/FACT++/src/fitsCompressor.cc
===================================================================
--- trunk/FACT++/src/fitsCompressor.cc	(revision 16941)
+++ trunk/FACT++/src/fitsCompressor.cc	(revision 16944)
@@ -424,4 +424,6 @@
         bool setHeaderKey(const HeaderEntry&);
 
+        bool changeHeaderKey(const string& origName, const string& newName);
+
         ///@brief open a new fits file
         bool open(const string& fileName, const string& tableName="Data");
@@ -931,4 +933,26 @@
 }
 
+bool CompressedFitsWriter::changeHeaderKey(const string& origName, const string& newName)
+{
+    for (vector<HeaderEntry>::iterator it=_header.begin(); it != _header.end(); it++)
+    {
+        if (it->key() == origName)
+        {
+            (*it) = HeaderEntry(newName, it->value(), it->comment());
+            _headerFlushed = false;
+            return true;
+        }
+    }
+    for (vector<HeaderEntry>::iterator it=_defaultHeader.begin(); it != _defaultHeader.end(); it++)
+    {
+        if (it->key() == origName)
+        {
+            (*it) = HeaderEntry(newName, it->value(), it->comment());
+            _headerFlushed = false;
+            return true;
+        }
+    }
+    return false;
+}
 /****************************************************************
  *              OPEN
@@ -1134,8 +1158,9 @@
     else
     {
-        setHeaderKey(HeaderEntry("NAXIS1", _rowWidth, "width of table in bytes"));
+        setHeaderKey(HeaderEntry("NAXIS1", _columns.size()*2*sizeof(int64_t), "width of table in bytes"));
         setHeaderKey(HeaderEntry("NAXIS2", 0, ""));
         setHeaderKey(HeaderEntry("TFIELDS", _columns.size(), "number of fields in each row"));
         setHeaderKey(HeaderEntry("PCOUNT", 0, "size of special data area"));
+        changeHeaderKey("THEAP", "ZHEAP");
     }
     ostringstream str;
@@ -1849,4 +1874,8 @@
     Checksum rawsum;
     //Convert each row one after the other
+    ostringstream wrongChannels;
+    map<int, int> wrongChannelsMap;
+    for (uint32_t i=0;i<1440;i++)
+        wrongChannelsMap[i] = 0;
     for (uint32_t i=0;i<inFile.GetNumRows();i++)
     {
@@ -1878,5 +1907,10 @@
             {
                 const int thisStartCell = reinterpret_cast<int16_t*>(&buffer[startCellOffset])[j];
-                if (thisStartCell < 0) continue;
+                if (thisStartCell > 1023)
+                {
+                    wrongChannelsMap[j]++;
+                    wrongChannels << j;
+                }
+                if (thisStartCell < 0)  continue;
                 for (int k=0;k<numSlices;k++)
                     reinterpret_cast<int16_t*>(&buffer[dataOffset])[numSlices*j + k] -= drsCalib16[1024*j + (thisStartCell+k)%1024];
@@ -1885,4 +1919,16 @@
         outFile.writeBinaryRow(buffer);
     };
+
+    if (wrongChannels.str() != "")
+    {
+        cout << "ERROR: Wrong channels: ";
+        for (uint32_t i=0;i<1440;i++)
+        {
+            if (wrongChannelsMap[i] != 0)
+                cout << i << "(" << wrongChannelsMap[i] << ") ";
+        }
+        cout << endl;
+        exit(-1);
+    }
     ostringstream strSum;
     strSum << rawsum.val();
@@ -1953,5 +1999,5 @@
             k == "TFIELDS"  || k == "ZTABLE"  || k == "ZNAXIS1"  || k == "ZNAXIS2" ||
             k == "ZHEAPPTR" || k == "ZPCOUNT" || k == "ZTILELEN" || k == "THEAP" ||
-            k == "CHECKSUM" || k == "DATASUM" || k == "FCTCPVER")
+            k == "CHECKSUM" || k == "DATASUM" || k == "FCTCPVER" || k == "ZHEAP")
         {
             continue;
