Index: trunk/FACT++/src/csv2root.cc
===================================================================
--- trunk/FACT++/src/csv2root.cc	(revision 19878)
+++ trunk/FACT++/src/csv2root.cc	(revision 19879)
@@ -35,4 +35,6 @@
         ("rename.*",       var<string>(),             "Can be used to rename a column")
         ("delimiter",      var<string>(";:, \t"),     "List of possible delimiters")
+        ("null",           po_switch(),               "Enable detection of NULL and replace it with 0")
+        ("empty",          po_switch(),               "Enable detection of empty fields (two immediately consecutive delimiters) and replace them with 0")
         ("dry-run",        po_switch(),               "Do not create or manipulate any output file")
         ("verbose,v",      var<uint16_t>(1),          "Verbosity (0: quiet, 1: default, 2: more, 3, ...)")
@@ -147,4 +149,6 @@
     const bool force             = conf.Get<bool>("force");
     const bool update            = conf.Get<bool>("update");
+    const bool detectnull        = conf.Get<bool>("null");
+    const bool detectempty       = conf.Get<bool>("empty");
 //    const bool dryrun            = conf.Get<bool>("dry-run");
     const bool noheader          = conf.Get<bool>("no-header");
@@ -343,8 +347,28 @@
             continue;
 
+        if (detectempty)
+        {
+            string delim = delimiter;
+
+
+            for (int i=0; i<delimiter.size(); i++)
+                if (delimiter[i]!=' ')
+                {
+                    boost::regex rexpr1("(["+delimiter+"])(["+delimiter+"])");
+                    buf = boost::regex_replace(string(buf.Data()), rexpr1, "\\10\\2");
+
+                    boost::regex rexpr2("^(["+delimiter+"])");
+                    buf = boost::regex_replace(string(buf.Data()), rexpr2, "0\\1");
+
+                    boost::regex rexpr3("(["+delimiter+"])$");
+                    buf = boost::regex_replace(string(buf.Data()), rexpr3, "\\10");
+                }
+        }
+
         TObjArray *arr = buf.Tokenize(delimiter);
         if (arr->GetEntries()!=numcol)
         {
-            cerr << "Column count mismatch in line " << line+1 << "!" << endl;
+            cerr << buf << endl;
+            cerr << "Column count [" << arr->GetEntries() << "] mismatch in line " << line+1 << "!" << endl;
             return 7;
         }
@@ -354,9 +378,16 @@
             try
             {
+                if (detectnull && arr->At(i)->GetName()==string("NULL"))
+                {
+                    vec[i] = 0;
+                    continue;
+                }
+
                 vec[i] = stof(arr->At(i)->GetName());
             }
             catch (const exception &e)
             {
-                cerr << "Conversion of '" << arr->At(i)->GetName() << "' failed!" << endl;
+                cerr << buf << endl;
+                cerr << "Conversion of field " << i << " '" << arr->At(i)->GetName() << "' in line " << line+1 <<  " failed!" << endl;
                 return 8;
             }
