Index: trunk/FACT++/src/smartfact.cc
===================================================================
--- trunk/FACT++/src/smartfact.cc	(revision 14135)
+++ trunk/FACT++/src/smartfact.cc	(revision 14136)
@@ -526,20 +526,10 @@
 
     template<class T>
-        void WriteBinary(const EventImp &d, const string &fname, const T &t, double scale, double offset=0)
-    {
-        const Statistics stat(t);
-
-        vector<uint8_t> val(t.size(), 0);
-        for (uint64_t i=0; i<t.size(); i++)
-        {
-            float range = nearbyint(128*(t[i]-offset)/scale); // [-2V; 2V]
-            if (range>127)
-                range=127;
-            if (range<0)
-                range=0;
-            val[i] = (uint8_t)range;
-        }
-
-        const char *ptr = reinterpret_cast<char*>(val.data());
+        void WriteBinaryVec(const EventImp &d, const string &fname, const vector<T> &vec, double scale, double offset=0)
+    {
+        if (vec.size()==0)
+            return;
+
+        const Statistics stat(vec[0]);
 
         ostringstream out;
@@ -550,8 +540,32 @@
         out << stat.min << '\n';
         out << stat.med << '\n';
-        out << stat.max << '\n';
-        out.write(ptr, val.size()*sizeof(uint8_t));
+        out << stat.max << '\0';
+        for (auto it=vec.begin(); it!=vec.end(); it++)
+        {
+            // The valid range is from 1 to 127
+            // \0 is used to seperate different curves
+            vector<uint8_t> val(it->size());
+            for (uint64_t i=0; i<it->size(); i++)
+            {
+                float range = nearbyint(126*(double(it->at(i))-offset)/scale)+1; // [-2V; 2V]
+                if (range>127)
+                    range=127;
+                if (range<1)
+                    range=1;
+                val[i] = (uint8_t)range;
+            }
+
+            const char *ptr = reinterpret_cast<char*>(val.data());
+            out.write(ptr, val.size()*sizeof(uint8_t));
+            out << '\0';
+        }
 
         ofstream(fPath+"/"+fname+".bin") << out.str();
+    }
+
+    template<class T>
+        void WriteBinary(const EventImp &d, const string &fname, const T &t, double scale, double offset=0)
+    {
+        WriteBinaryVec(d, fname, vector<T>(&t, &t+1), scale, offset);
     }
 
