Index: trunk/FACT++/src/fadctrl.cc
===================================================================
--- trunk/FACT++/src/fadctrl.cc	(revision 17238)
+++ trunk/FACT++/src/fadctrl.cc	(revision 17244)
@@ -18,4 +18,6 @@
 #include "EventBuilderWrapper.h"
 
+#include "../externals/zofits.h"
+
 namespace ba = boost::asio;
 namespace bs = boost::system;
@@ -843,4 +845,5 @@
         case FAD::kDebug:
         case FAD::kFits:
+        case FAD::kZFits:
         case FAD::kCfitsio:
         case FAD::kRaw:
@@ -1302,4 +1305,16 @@
         return T::GetCurrentState();
     }
+
+    // ============================================================================
+
+    int SetupZFits(const EventImp &evt, const std::function<void(int32_t)> &func)
+    {
+        if (!CheckEventSize(evt.GetSize(), "SetupZFits", 2))
+            return T::kSM_FatalError;
+
+        func(evt.GetShort());
+        return T::GetCurrentState();
+    }
+
 
     // ============================================================================
@@ -1909,4 +1924,23 @@
 
 
+        // --------- Setup compression of FITS files -----------
+        T::AddEvent("SET_ZFITS_DEFAULT_NUM_THREADS", "S")
+            (bind(&StateMachineFAD::SetupZFits, this, placeholders::_1, zofits::DefaultNumThreads))
+            ("Set the number of compression threads to use (+1 for writing)"
+             "|num[int]:Number of threads");
+        T::AddEvent("SET_ZFITS_DEFAULT_MAX_MEMORY", "S")
+            (bind(&StateMachineFAD::SetupZFits, this, placeholders::_1, zofits::DefaultMaxMemory))
+            ("Set the maximum amount of memory zfits will use for compression"
+             "|mem[int]:Memory in MB");
+        T::AddEvent("SET_ZFITS_DEFAULT_NUM_TILES", "S")
+            (bind(&StateMachineFAD::SetupZFits, this, placeholders::_1, zofits::DefaultMaxNumTiles))
+            ("Set the number of tiles with which the catalog is initialized"
+             "|num[int]:Number of tiles");
+        T::AddEvent("SET_ZFITS_DEFAULT_ROWS_PER_TILE", "S")
+            (bind(&StateMachineFAD::SetupZFits, this, placeholders::_1, zofits::DefaultNumRowsPerTile))
+            ("Set the number of rows which are compressed into one tile"
+             "|num[int]:Number of rows per tile");
+
+
         T::AddEvent("ADD_ADDRESS", "C", FAD::State::kOffline)
             (bind(&StateMachineFAD::AddAddress, this, placeholders::_1))
@@ -1990,4 +2024,14 @@
         fDebugTx = conf.Get<bool>("debug-tx");
 
+        // --------- Setup compression of FITS files -----------
+        if (conf.Has("zfits.num-threads"))
+            zofits::DefaultNumThreads(conf.Get<int16_t>("zfits.num-threads"));
+        if (conf.Has("zfits.max-mem"))
+            zofits::DefaultMaxMemory(conf.Get<uint16_t>("zfits.max-mem")*1000);
+        if (conf.Has("zfits.num-tiles"))
+            zofits::DefaultMaxNumTiles(conf.Get<uint16_t>("zfits.num-tiles"));
+        if (conf.Has("zfits.num-rows"))
+            zofits::DefaultNumRowsPerTile(conf.Get<uint16_t>("zfits.num-rows"));
+
         // ---------- Setup event builder ---------
         SetMaxMemory(conf.Get<unsigned int>("max-mem"));
@@ -2177,7 +2221,15 @@
     po::options_description builder("Event builder options");
     builder.add_options()
-        ("max-mem,m",          var<unsigned int>(100), "Maximum memory the event builder thread is allowed to consume for its event buffer")
+        ("max-mem",            var<unsigned int>(100), "Maximum memory the event builder thread is allowed to consume for its event buffer")
         ("event-timeout",      var<uint16_t>(30),      "After how many seconds is an event considered to be timed out? (<=0: disabled)")
         ("destination-folder", var<string>(""),        "Destination folder (base folder) for the event builder binary data files.")
+        ;
+
+    po::options_description zfits("FITS compression options");
+    zfits.add_options()
+        ("zfits.num-threads", var<int16_t>(),  "Number of threads to spawn writing compressed FITS files")
+        ("zfits.max-mem",     var<uint16_t>(), "Maximum amount of memory to be allocated by FITS compression in MB")
+        ("zfits.num-tiles",   var<uint16_t>(), "Maximum number of tiles in the catalog")
+        ("zfits.num-rows",    var<uint16_t>(), "Maximum number of rows per tile")
         ;
 
@@ -2216,4 +2268,5 @@
     conf.AddOptions(connect);
     conf.AddOptions(builder);
+    conf.AddOptions(zfits);
     conf.AddOptions(runtype);
 }
