changeset 9653:9a0099a892ab octave-forge

csvexplode, csv2cell, cell2csv, csvconcat: moving from miscellaneous to IO package. Fixing Makefiles
author carandraug
date Mon, 12 Mar 2012 22:46:21 +0000
parents e545fbde2535
children 0ec16ae37f41
files main/io/src/Makefile main/io/src/cell2csv.cc main/io/src/csv2cell.cc main/io/src/csvconcat.cc main/io/src/csvexplode.cc main/miscellaneous/src/Makefile main/miscellaneous/src/cell2csv.cc main/miscellaneous/src/csv2cell.cc main/miscellaneous/src/csvconcat.cc main/miscellaneous/src/csvexplode.cc
diffstat 10 files changed, 511 insertions(+), 516 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main/io/src/Makefile	Mon Mar 12 22:46:21 2012 +0000
@@ -0,0 +1,7 @@
+all: csvexplode.oct csv2cell.oct csvconcat.oct cell2csv.oct
+
+%.oct: %.cc
+	mkoctfile -Wall $<
+
+clean:
+	rm -f *.o octave-core core *.oct *~
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main/io/src/cell2csv.cc	Mon Mar 12 22:46:21 2012 +0000
@@ -0,0 +1,116 @@
+// Copyright (C) 2004 Laurent Mazet <mazet@crm.mot.com>
+//
+// This program is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free Software
+// Foundation; either version 3 of the License, or (at your option) any later
+// version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+// details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, see <http://www.gnu.org/licenses/>.
+
+#include <fstream>
+
+#include <octave/oct.h>
+#include <octave/Cell.h>
+
+DEFUN_DLD (cell2csv, args, nargout,
+           "-*- texinfo -*-\n"
+           "@deftypefn {Function File} {} cell2csv (@var{file}, @var{c})\n"
+	   "@deftypefnx {Function File} {} cell2csv (@var{file}, @var{c}, @var{sep})\n"
+	   "@deftypefnx {Function File} {} cell2csv (@var{file}, @var{c}, @var{sep}, @var{prot})\n"
+	   "\n"
+	   "Create a CSV file from a cell. "
+	   "@var{sep} changes the character used to separate two fields. By "
+	   "default, two fields are expected to be separated by a coma "
+	   "(@code{,}). @var{prot} changes the character used to protect a string. "
+	   "By default it's a double quote (@code{\"}).\n"
+           "@end deftypefn") {
+
+  /* Check argument */
+  if ((args.length() < 2) || (args.length() > 4)) {
+    print_usage ();
+    return octave_value();
+  }
+
+  /* Get arguments */
+  std::string file = args(0).string_value();
+
+  Cell c = args(1).cell_value();
+
+  std::string sep = (args.length() > 2) ? args(2).string_value() : ",";
+  if (sep.length() != 1) {
+    error("Only on charactere need as separator\n");
+    return octave_value();
+  }
+
+  std::string prot = (args.length() > 3) ? args(3).string_value() : "\"";
+  if (prot.length() != 1) {
+    error("Only on charactere need as protector\n");
+    return octave_value();
+  }
+
+  /* Open file */
+  std::ofstream fd(file.c_str());
+  if (!fd.is_open()) {
+    error("cannot write %s\n", file.c_str());
+    return octave_value();
+  }
+
+  /* Concat a cell into a string */
+  std::string word;
+
+  /* For each element */
+  for (int i=0, il=c.rows(); i<il; i++) {
+   
+    for (int j=0, jl=c.columns(); j<jl; j++) {
+      word = "";
+      
+      /* Add separator */
+      if (j != 0)
+	word += sep;
+
+      if (c(i, j).is_real_scalar()) {
+
+	/* Output real value */
+	char tmp[20];
+	sprintf(tmp, "%g", c(i, j).double_value());
+	word += tmp;
+      }
+
+      else if (c(i, j).is_string()) {
+	/* Output string value */
+	std::string str = c(i, j).string_value();
+	if (str.find(sep) != str.npos) {
+	  size_t pos = 0;
+	  while ((pos=str.find(prot, pos)) != str.npos) {
+	    str.replace(pos, 1, prot+prot);
+	    pos += 2;
+	  }
+	  str = prot + str + prot;
+	}
+	word += str;
+      }
+
+      else if (!c(i, j).is_empty()) {
+	/* Output NaN value */
+	warning ("not a real or a string\n");
+	word += "NaN";
+      }
+
+      fd << word;
+    }
+
+    /* Add end of line */
+    fd << std::endl;
+  }
+
+  /* Close file */
+  fd.close();
+
+  return octave_value();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main/io/src/csv2cell.cc	Mon Mar 12 22:46:21 2012 +0000
@@ -0,0 +1,193 @@
+// Copyright (C) 2004 Laurent Mazet <mazet@crm.mot.com>
+//
+// This program is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free Software
+// Foundation; either version 3 of the License, or (at your option) any later
+// version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+// details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, see <http://www.gnu.org/licenses/>.
+
+#include <fstream>
+
+#include <octave/oct.h>
+#include <octave/Cell.h>
+
+#define MAXSTRINGLENGTH 4096
+
+DEFUN_DLD (csv2cell, args, nargout, 
+       "-*- texinfo -*-\n"
+       "@deftypefn {Function File} {@var{c} = } csv2cell (@var{file})\n"
+       "@deftypefnx {Function File} {@var{c} = } csv2cell (@var{file}, @var{sep})\n"
+       "@deftypefnx {Function File} {@var{c} = } csv2cell (@var{file}, @var{sep}, @var{prot})\n"
+       "\n"
+       "Read a CSV (Comma Separated Values) file and convert it into a "
+       "cell. "
+       "@var{sep} changes the character used to separate two fields. By "
+       "default, two fields are expected to be separated by a coma "
+       "(@code{,}). @var{prot} changes the character used to protect a string. "
+       "By default it's a double quote (@code{\"}).\n"
+       "@end deftypefn") {
+
+  /* Get arguments */
+  const int nargin = args.length ();
+  octave_value_list retval;
+  if (nargin == 0)
+    {
+      error ("csv2cell: not enough input arguments");
+      return retval;
+    }
+    
+  const std::string file = args (0).string_value ();
+
+  const std::string _sep = (nargin > 1) ? args (1).string_value () : ",";
+  if (_sep.length() != 1)
+    {
+      error ("csv2cell: only on charactere need as separator");
+      return retval;
+    }
+  char sep = _sep[0];
+
+  const std::string _prot = (nargin > 2) ? args (2).string_value () : "\"";
+  if (_prot.length() != 1)
+    {
+      error ("csv2cell: only on charactere need as protector");
+      return retval;
+    }
+  char prot = _prot[0];
+
+  /* Open file */
+  std::ifstream fd (file.c_str ());
+  if (!fd.is_open ())
+    {
+      error ("csv2cell: cannot read %s", file.c_str());
+      return retval;
+    }
+  fd.seekg (0, std::ios::end);
+  long fdend = fd.tellg ();
+  fd.seekg (0, std::ios::beg);
+
+  if (fd.tellg () >= fdend)
+    return octave_value (Cell (0, 0));
+
+  /* Buffers */
+  char line [MAXSTRINGLENGTH];
+  std::string str, word;
+  bool inside = false;
+
+  /* Read a line */
+  str = "";
+  fd.getline (line, MAXSTRINGLENGTH);
+  while (fd.fail ())
+    {
+      fd.clear ();
+      str += line;
+      fd.getline (line, MAXSTRINGLENGTH);
+    }
+  str += line;
+
+  /* Parse first to get number of columns */
+  int nbcolumns = 0;
+  for (int i = 0, len = str.length (); i <= len; i++)
+    if (((i==len) || (str [i] == sep)) && (!inside))
+      nbcolumns++;
+    else if ((inside) && (str [i] == prot) && ((i < len) && (str [i+1] == prot)))
+      ++i;
+    else if (str [i] == prot)
+      inside = !inside;
+  
+  /* Read all the file to get number of rows */
+  int nbrows = 1;
+  while (fd.tellg () < fdend)
+    {
+      fd.getline (line, MAXSTRINGLENGTH);
+      while (fd.fail ())
+        {
+          fd.clear ();
+          fd.getline (line, MAXSTRINGLENGTH);
+        }
+      nbrows++;
+    }
+
+  /* Rewind */
+  fd.seekg (0, std::ios::beg);
+  if (!fd.good ())
+    {
+      error ("csv2cell: cannot reread %s", file.c_str ());
+      return retval;
+    }
+
+  /* Read all the file until the end */
+  Cell c (nbrows, nbcolumns);
+  for (int i = 0; i < nbrows; i++)
+    {
+      /* Read a line */
+      str = "";
+      fd.getline (line, MAXSTRINGLENGTH);
+      while (fd.fail ())
+        {
+          fd.clear ();
+          str += line;
+          fd.getline (line, MAXSTRINGLENGTH);
+        }
+      str += line;
+
+      /* Explode a line into a sub cell */
+      word = "";
+      inside = false;
+      int j = 0;
+      for (int k = 0, len = str.length (); k <= len; k++)
+        {
+          if (((k == len) || (str [k] == sep)) && (!inside))
+            {
+              /* Check number of columns */
+              if (j == nbcolumns)
+                {
+                  fd.close ();
+                  error ("csv2cell: incorrect CSV file, line %d too long", i+1);
+                  return retval;
+                }
+
+              /* Check if scalar */
+              const char *word_str = word.c_str ();
+              char *err;
+              double val = strtod (word_str, &err);
+
+              /* Store into the cell */
+              c (i, j++) = ((word == "") || (err != word_str+word.length())) ?
+                           octave_value (word) : octave_value (val);
+              word = "";
+            }
+          else if ((inside) && (str[k]==prot) && ((k<len) && (str[k+1]==prot)))
+            {
+              /* Insisde a string */
+              word += prot;
+              ++k;
+            }
+          else if (str[k] == prot)
+            /* Changing */
+            inside = !inside;
+          else
+            word += str[k];
+        }
+
+      /* Check number of columns */
+      if (j != nbcolumns)
+        {
+          fd.close ();
+          error ("csv2cell: incorrect CSV file, line %d too short", i+1);
+          return retval;
+        }
+    }
+
+  /* Close file */
+  fd.close ();
+
+  retval (0) = c;
+  return retval;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main/io/src/csvconcat.cc	Mon Mar 12 22:46:21 2012 +0000
@@ -0,0 +1,98 @@
+// Copyright (C) 2004 Laurent Mazet <mazet@crm.mot.com>
+//
+// This program is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free Software
+// Foundation; either version 3 of the License, or (at your option) any later
+// version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+// details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, see <http://www.gnu.org/licenses/>.
+
+#include <octave/oct.h>
+#include <octave/Cell.h>
+
+DEFUN_DLD (csvconcat, args, nargout,
+           "-*- texinfo -*-\n"
+           "@deftypefn {Function File} {@var{str} = } csvconcat (@var{c})\n"
+	   "@deftypefnx {Function File} {@var{str} = } csvconcat (@var{c}, @var{sep})\n"
+	   "@deftypefnx {Function File} {@var{str} = } csvconcat (@var{c}, @var{sep}, @var{prot})\n"
+	   "\n"
+	   "Concatenate a cell into a CSV string or array of strings. "
+	   "@var{sep} changes the character used to separate two fields. By "
+	   "default, two fields are expected to be separated by a coma "
+	   "(@code{,}). @var{prot} changes the character used to protect a string. "
+	   "By default it's a double quote (@code{\"}).\n"
+           "@end deftypefn") {
+
+  /* Check argument */
+  if ((args.length() < 1) || (args.length() > 3)) {
+    print_usage ();
+    return octave_value();
+  }
+
+  /* Get arguments */
+  Cell c = args(0).cell_value();
+
+  std::string sep = (args.length() > 1) ? args(1).string_value() : ",";
+  if (sep.length() != 1) {
+    error("Only on charactere need as separator\n");
+    return octave_value();
+  }
+
+  std::string prot = (args.length() > 2) ? args(2).string_value() : "\"";
+  if (prot.length() != 1) {
+    error("Only on charactere need as protector\n");
+    return octave_value();
+  }
+  
+  /* Concat a cell into a string */
+  string_vector vec(c.rows());
+  std::string word;
+
+  /* For each element */
+  for (int i=0, il=c.rows(); i<il; i++) {
+    word = "";
+    for (int j=0, jl=c.columns(); j<jl; j++) {
+      
+      /* Add separator */
+      if (j != 0)
+	word += sep;
+
+      if (c(i, j).is_real_scalar()) {
+
+	/* Output real value */
+	char tmp[20];
+	sprintf(tmp, "%g", c(i, j).double_value());
+	word += tmp;
+      }
+
+      else if (c(i, j).is_string()) {
+	/* Output string value */
+	std::string str = c(i, j).string_value();
+	if (str.find(sep) != str.npos) {
+	  unsigned int pos = 0;
+	  while ((pos=str.find(prot, pos)) != str.npos) {
+	    str.replace(pos, 1, prot+prot);
+	    pos += 2;
+	  }
+	  str = prot + str + prot;
+	}
+	word += str;
+      }
+
+      else {
+	/* Output NaN value */
+	warning ("not a real or a string\n");
+	word += "NaN";
+      }
+    }
+    vec(i) = word;
+  }
+  
+  return octave_value(vec);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main/io/src/csvexplode.cc	Mon Mar 12 22:46:21 2012 +0000
@@ -0,0 +1,97 @@
+// Copyright (C) 2004 Laurent Mazet <mazet@crm.mot.com>
+//
+// This program is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free Software
+// Foundation; either version 3 of the License, or (at your option) any later
+// version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+// details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, see <http://www.gnu.org/licenses/>.
+
+#include <octave/oct.h>
+#include <octave/Cell.h>
+
+DEFUN_DLD (csvexplode, args, nargout,
+           "-*- texinfo -*-\n"
+           "@deftypefn {Function File} {@var{c} = } csvexplode (@var{str})\n"
+	   "@deftypefnx {Function File} {@var{c} = } csvexplode (@var{str}, @var{sep})\n"
+	   "@deftypefnx {Function File} {@var{c} = } csvexplode (@var{str}, @var{sep}, @var{prot})\n"
+	   "\n"
+	   "Explode a CSV string into a cell. "
+	   "@var{sep} changes the character used to separate two fields. By "
+	   "default, two fields are expected to be separated by a coma "
+	   "(@code{,}). @var{prot} changes the character used to protect a string. "
+	   "By default it's a double quote (@code{\"}).\n"
+           "@end deftypefn") {
+
+  /* Check argument */
+  if ((args.length() < 1) || (args.length() > 3)) {
+    print_usage ();
+    return octave_value();
+  }
+
+  /* Get arguments */
+  if (!args(0).is_string()) {
+    if (args(0).is_cell())
+      return octave_value(args(0));
+    else
+      return octave_value(Cell(args(0)));
+  }
+  std::string str = args(0).string_value();
+
+  std::string _sep = (args.length() > 1) ? args(1).string_value() : ",";
+  if (_sep.length() != 1) {
+    error("Only on charactere need as separator\n");
+    return octave_value();
+  }
+  char sep = _sep[0];
+
+  std::string _prot = (args.length() > 2) ? args(2).string_value() : "\"";
+  if (_prot.length() != 1) {
+    error("Only on charactere need as protector\n");
+    return octave_value();
+  }
+  char prot = _prot[0];
+
+  /* Explode a line into a cell */
+  Cell retval;
+  std::string word;
+  bool inside = false;
+  for (int i=0, len=str.length(); i<=len; i++) {
+    if (((i==len) || (str[i] == sep)) && (!inside)) {
+
+      /* Extand cell */
+      retval.resize(dim_vector(1, retval.columns()+1));
+
+      /* Check if scalar */
+      const char *word_str=word.c_str();
+      char *err;
+      double val = strtod (word_str, &err);
+
+      /* Store into the cell */
+      retval(0, retval.columns()-1) =
+	((word == "") || (err != word_str+word.length())) ?
+	octave_value(word) : octave_value(val);
+
+      word = "";
+    }
+    else if ((inside) && (str[i]==prot) && ((i<len) && (str[i+1]==prot))) {
+
+      /* Insisde a string */
+      word += prot;
+      ++i;
+    }
+    else if (str[i] == prot)
+      /* Changing */
+      inside = !inside;
+    else
+      word += str[i];
+  }
+
+  return octave_value(retval);
+}
--- a/main/miscellaneous/src/Makefile	Mon Mar 12 22:37:25 2012 +0000
+++ b/main/miscellaneous/src/Makefile	Mon Mar 12 22:46:21 2012 +0000
@@ -49,18 +49,6 @@
 xmlread.oct: xmlread.o xmltree_read.o xmltree.o
 	$(MKOCTFILE) $^
 
-csvexplode.oct: csvexplode.cc
-	$(MKOCTFILE) $(MISCDEFS) $<
-
-csv2cell.oct: csv2cell.cc
-	$(MKOCTFILE) $(MISCDEFS) $<
-
-csvconcat.oct: csvconcat.cc
-	$(MKOCTFILE) $(MISCDEFS) $<
-
-cell2csv.oct: cell2csv.cc
-	$(MKOCTFILE) $(MISCDEFS) $<
-
 cell2cell.oct: cell2cell.cc
 	$(MKOCTFILE) $(MISCDEFS) $<
 
--- a/main/miscellaneous/src/cell2csv.cc	Mon Mar 12 22:37:25 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,116 +0,0 @@
-// Copyright (C) 2004 Laurent Mazet <mazet@crm.mot.com>
-//
-// This program is free software; you can redistribute it and/or modify it under
-// the terms of the GNU General Public License as published by the Free Software
-// Foundation; either version 3 of the License, or (at your option) any later
-// version.
-//
-// This program is distributed in the hope that it will be useful, but WITHOUT
-// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
-// details.
-//
-// You should have received a copy of the GNU General Public License along with
-// this program; if not, see <http://www.gnu.org/licenses/>.
-
-#include <fstream>
-
-#include <octave/oct.h>
-#include <octave/Cell.h>
-
-DEFUN_DLD (cell2csv, args, nargout,
-           "-*- texinfo -*-\n"
-           "@deftypefn {Function File} {} cell2csv (@var{file}, @var{c})\n"
-	   "@deftypefnx {Function File} {} cell2csv (@var{file}, @var{c}, @var{sep})\n"
-	   "@deftypefnx {Function File} {} cell2csv (@var{file}, @var{c}, @var{sep}, @var{prot})\n"
-	   "\n"
-	   "Create a CSV file from a cell. "
-	   "@var{sep} changes the character used to separate two fields. By "
-	   "default, two fields are expected to be separated by a coma "
-	   "(@code{,}). @var{prot} changes the character used to protect a string. "
-	   "By default it's a double quote (@code{\"}).\n"
-           "@end deftypefn") {
-
-  /* Check argument */
-  if ((args.length() < 2) || (args.length() > 4)) {
-    print_usage ();
-    return octave_value();
-  }
-
-  /* Get arguments */
-  std::string file = args(0).string_value();
-
-  Cell c = args(1).cell_value();
-
-  std::string sep = (args.length() > 2) ? args(2).string_value() : ",";
-  if (sep.length() != 1) {
-    error("Only on charactere need as separator\n");
-    return octave_value();
-  }
-
-  std::string prot = (args.length() > 3) ? args(3).string_value() : "\"";
-  if (prot.length() != 1) {
-    error("Only on charactere need as protector\n");
-    return octave_value();
-  }
-
-  /* Open file */
-  std::ofstream fd(file.c_str());
-  if (!fd.is_open()) {
-    error("cannot write %s\n", file.c_str());
-    return octave_value();
-  }
-
-  /* Concat a cell into a string */
-  std::string word;
-
-  /* For each element */
-  for (int i=0, il=c.rows(); i<il; i++) {
-   
-    for (int j=0, jl=c.columns(); j<jl; j++) {
-      word = "";
-      
-      /* Add separator */
-      if (j != 0)
-	word += sep;
-
-      if (c(i, j).is_real_scalar()) {
-
-	/* Output real value */
-	char tmp[20];
-	sprintf(tmp, "%g", c(i, j).double_value());
-	word += tmp;
-      }
-
-      else if (c(i, j).is_string()) {
-	/* Output string value */
-	std::string str = c(i, j).string_value();
-	if (str.find(sep) != str.npos) {
-	  size_t pos = 0;
-	  while ((pos=str.find(prot, pos)) != str.npos) {
-	    str.replace(pos, 1, prot+prot);
-	    pos += 2;
-	  }
-	  str = prot + str + prot;
-	}
-	word += str;
-      }
-
-      else if (!c(i, j).is_empty()) {
-	/* Output NaN value */
-	warning ("not a real or a string\n");
-	word += "NaN";
-      }
-
-      fd << word;
-    }
-
-    /* Add end of line */
-    fd << std::endl;
-  }
-
-  /* Close file */
-  fd.close();
-
-  return octave_value();
-}
--- a/main/miscellaneous/src/csv2cell.cc	Mon Mar 12 22:37:25 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,193 +0,0 @@
-// Copyright (C) 2004 Laurent Mazet <mazet@crm.mot.com>
-//
-// This program is free software; you can redistribute it and/or modify it under
-// the terms of the GNU General Public License as published by the Free Software
-// Foundation; either version 3 of the License, or (at your option) any later
-// version.
-//
-// This program is distributed in the hope that it will be useful, but WITHOUT
-// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
-// details.
-//
-// You should have received a copy of the GNU General Public License along with
-// this program; if not, see <http://www.gnu.org/licenses/>.
-
-#include <fstream>
-
-#include <octave/oct.h>
-#include <octave/Cell.h>
-
-#define MAXSTRINGLENGTH 4096
-
-DEFUN_DLD (csv2cell, args, nargout, 
-       "-*- texinfo -*-\n"
-       "@deftypefn {Function File} {@var{c} = } csv2cell (@var{file})\n"
-       "@deftypefnx {Function File} {@var{c} = } csv2cell (@var{file}, @var{sep})\n"
-       "@deftypefnx {Function File} {@var{c} = } csv2cell (@var{file}, @var{sep}, @var{prot})\n"
-       "\n"
-       "Read a CSV (Comma Separated Values) file and convert it into a "
-       "cell. "
-       "@var{sep} changes the character used to separate two fields. By "
-       "default, two fields are expected to be separated by a coma "
-       "(@code{,}). @var{prot} changes the character used to protect a string. "
-       "By default it's a double quote (@code{\"}).\n"
-       "@end deftypefn") {
-
-  /* Get arguments */
-  const int nargin = args.length ();
-  octave_value_list retval;
-  if (nargin == 0)
-    {
-      error ("csv2cell: not enough input arguments");
-      return retval;
-    }
-    
-  const std::string file = args (0).string_value ();
-
-  const std::string _sep = (nargin > 1) ? args (1).string_value () : ",";
-  if (_sep.length() != 1)
-    {
-      error ("csv2cell: only on charactere need as separator");
-      return retval;
-    }
-  char sep = _sep[0];
-
-  const std::string _prot = (nargin > 2) ? args (2).string_value () : "\"";
-  if (_prot.length() != 1)
-    {
-      error ("csv2cell: only on charactere need as protector");
-      return retval;
-    }
-  char prot = _prot[0];
-
-  /* Open file */
-  std::ifstream fd (file.c_str ());
-  if (!fd.is_open ())
-    {
-      error ("csv2cell: cannot read %s", file.c_str());
-      return retval;
-    }
-  fd.seekg (0, std::ios::end);
-  long fdend = fd.tellg ();
-  fd.seekg (0, std::ios::beg);
-
-  if (fd.tellg () >= fdend)
-    return octave_value (Cell (0, 0));
-
-  /* Buffers */
-  char line [MAXSTRINGLENGTH];
-  std::string str, word;
-  bool inside = false;
-
-  /* Read a line */
-  str = "";
-  fd.getline (line, MAXSTRINGLENGTH);
-  while (fd.fail ())
-    {
-      fd.clear ();
-      str += line;
-      fd.getline (line, MAXSTRINGLENGTH);
-    }
-  str += line;
-
-  /* Parse first to get number of columns */
-  int nbcolumns = 0;
-  for (int i = 0, len = str.length (); i <= len; i++)
-    if (((i==len) || (str [i] == sep)) && (!inside))
-      nbcolumns++;
-    else if ((inside) && (str [i] == prot) && ((i < len) && (str [i+1] == prot)))
-      ++i;
-    else if (str [i] == prot)
-      inside = !inside;
-  
-  /* Read all the file to get number of rows */
-  int nbrows = 1;
-  while (fd.tellg () < fdend)
-    {
-      fd.getline (line, MAXSTRINGLENGTH);
-      while (fd.fail ())
-        {
-          fd.clear ();
-          fd.getline (line, MAXSTRINGLENGTH);
-        }
-      nbrows++;
-    }
-
-  /* Rewind */
-  fd.seekg (0, std::ios::beg);
-  if (!fd.good ())
-    {
-      error ("csv2cell: cannot reread %s", file.c_str ());
-      return retval;
-    }
-
-  /* Read all the file until the end */
-  Cell c (nbrows, nbcolumns);
-  for (int i = 0; i < nbrows; i++)
-    {
-      /* Read a line */
-      str = "";
-      fd.getline (line, MAXSTRINGLENGTH);
-      while (fd.fail ())
-        {
-          fd.clear ();
-          str += line;
-          fd.getline (line, MAXSTRINGLENGTH);
-        }
-      str += line;
-
-      /* Explode a line into a sub cell */
-      word = "";
-      inside = false;
-      int j = 0;
-      for (int k = 0, len = str.length (); k <= len; k++)
-        {
-          if (((k == len) || (str [k] == sep)) && (!inside))
-            {
-              /* Check number of columns */
-              if (j == nbcolumns)
-                {
-                  fd.close ();
-                  error ("csv2cell: incorrect CSV file, line %d too long", i+1);
-                  return retval;
-                }
-
-              /* Check if scalar */
-              const char *word_str = word.c_str ();
-              char *err;
-              double val = strtod (word_str, &err);
-
-              /* Store into the cell */
-              c (i, j++) = ((word == "") || (err != word_str+word.length())) ?
-                           octave_value (word) : octave_value (val);
-              word = "";
-            }
-          else if ((inside) && (str[k]==prot) && ((k<len) && (str[k+1]==prot)))
-            {
-              /* Insisde a string */
-              word += prot;
-              ++k;
-            }
-          else if (str[k] == prot)
-            /* Changing */
-            inside = !inside;
-          else
-            word += str[k];
-        }
-
-      /* Check number of columns */
-      if (j != nbcolumns)
-        {
-          fd.close ();
-          error ("csv2cell: incorrect CSV file, line %d too short", i+1);
-          return retval;
-        }
-    }
-
-  /* Close file */
-  fd.close ();
-
-  retval (0) = c;
-  return retval;
-}
--- a/main/miscellaneous/src/csvconcat.cc	Mon Mar 12 22:37:25 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,98 +0,0 @@
-// Copyright (C) 2004 Laurent Mazet <mazet@crm.mot.com>
-//
-// This program is free software; you can redistribute it and/or modify it under
-// the terms of the GNU General Public License as published by the Free Software
-// Foundation; either version 3 of the License, or (at your option) any later
-// version.
-//
-// This program is distributed in the hope that it will be useful, but WITHOUT
-// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
-// details.
-//
-// You should have received a copy of the GNU General Public License along with
-// this program; if not, see <http://www.gnu.org/licenses/>.
-
-#include <octave/oct.h>
-#include <octave/Cell.h>
-
-DEFUN_DLD (csvconcat, args, nargout,
-           "-*- texinfo -*-\n"
-           "@deftypefn {Function File} {@var{str} = } csvconcat (@var{c})\n"
-	   "@deftypefnx {Function File} {@var{str} = } csvconcat (@var{c}, @var{sep})\n"
-	   "@deftypefnx {Function File} {@var{str} = } csvconcat (@var{c}, @var{sep}, @var{prot})\n"
-	   "\n"
-	   "Concatenate a cell into a CSV string or array of strings. "
-	   "@var{sep} changes the character used to separate two fields. By "
-	   "default, two fields are expected to be separated by a coma "
-	   "(@code{,}). @var{prot} changes the character used to protect a string. "
-	   "By default it's a double quote (@code{\"}).\n"
-           "@end deftypefn") {
-
-  /* Check argument */
-  if ((args.length() < 1) || (args.length() > 3)) {
-    print_usage ();
-    return octave_value();
-  }
-
-  /* Get arguments */
-  Cell c = args(0).cell_value();
-
-  std::string sep = (args.length() > 1) ? args(1).string_value() : ",";
-  if (sep.length() != 1) {
-    error("Only on charactere need as separator\n");
-    return octave_value();
-  }
-
-  std::string prot = (args.length() > 2) ? args(2).string_value() : "\"";
-  if (prot.length() != 1) {
-    error("Only on charactere need as protector\n");
-    return octave_value();
-  }
-  
-  /* Concat a cell into a string */
-  string_vector vec(c.rows());
-  std::string word;
-
-  /* For each element */
-  for (int i=0, il=c.rows(); i<il; i++) {
-    word = "";
-    for (int j=0, jl=c.columns(); j<jl; j++) {
-      
-      /* Add separator */
-      if (j != 0)
-	word += sep;
-
-      if (c(i, j).is_real_scalar()) {
-
-	/* Output real value */
-	char tmp[20];
-	sprintf(tmp, "%g", c(i, j).double_value());
-	word += tmp;
-      }
-
-      else if (c(i, j).is_string()) {
-	/* Output string value */
-	std::string str = c(i, j).string_value();
-	if (str.find(sep) != str.npos) {
-	  unsigned int pos = 0;
-	  while ((pos=str.find(prot, pos)) != str.npos) {
-	    str.replace(pos, 1, prot+prot);
-	    pos += 2;
-	  }
-	  str = prot + str + prot;
-	}
-	word += str;
-      }
-
-      else {
-	/* Output NaN value */
-	warning ("not a real or a string\n");
-	word += "NaN";
-      }
-    }
-    vec(i) = word;
-  }
-  
-  return octave_value(vec);
-}
--- a/main/miscellaneous/src/csvexplode.cc	Mon Mar 12 22:37:25 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,97 +0,0 @@
-// Copyright (C) 2004 Laurent Mazet <mazet@crm.mot.com>
-//
-// This program is free software; you can redistribute it and/or modify it under
-// the terms of the GNU General Public License as published by the Free Software
-// Foundation; either version 3 of the License, or (at your option) any later
-// version.
-//
-// This program is distributed in the hope that it will be useful, but WITHOUT
-// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
-// details.
-//
-// You should have received a copy of the GNU General Public License along with
-// this program; if not, see <http://www.gnu.org/licenses/>.
-
-#include <octave/oct.h>
-#include <octave/Cell.h>
-
-DEFUN_DLD (csvexplode, args, nargout,
-           "-*- texinfo -*-\n"
-           "@deftypefn {Function File} {@var{c} = } csvexplode (@var{str})\n"
-	   "@deftypefnx {Function File} {@var{c} = } csvexplode (@var{str}, @var{sep})\n"
-	   "@deftypefnx {Function File} {@var{c} = } csvexplode (@var{str}, @var{sep}, @var{prot})\n"
-	   "\n"
-	   "Explode a CSV string into a cell. "
-	   "@var{sep} changes the character used to separate two fields. By "
-	   "default, two fields are expected to be separated by a coma "
-	   "(@code{,}). @var{prot} changes the character used to protect a string. "
-	   "By default it's a double quote (@code{\"}).\n"
-           "@end deftypefn") {
-
-  /* Check argument */
-  if ((args.length() < 1) || (args.length() > 3)) {
-    print_usage ();
-    return octave_value();
-  }
-
-  /* Get arguments */
-  if (!args(0).is_string()) {
-    if (args(0).is_cell())
-      return octave_value(args(0));
-    else
-      return octave_value(Cell(args(0)));
-  }
-  std::string str = args(0).string_value();
-
-  std::string _sep = (args.length() > 1) ? args(1).string_value() : ",";
-  if (_sep.length() != 1) {
-    error("Only on charactere need as separator\n");
-    return octave_value();
-  }
-  char sep = _sep[0];
-
-  std::string _prot = (args.length() > 2) ? args(2).string_value() : "\"";
-  if (_prot.length() != 1) {
-    error("Only on charactere need as protector\n");
-    return octave_value();
-  }
-  char prot = _prot[0];
-
-  /* Explode a line into a cell */
-  Cell retval;
-  std::string word;
-  bool inside = false;
-  for (int i=0, len=str.length(); i<=len; i++) {
-    if (((i==len) || (str[i] == sep)) && (!inside)) {
-
-      /* Extand cell */
-      retval.resize(dim_vector(1, retval.columns()+1));
-
-      /* Check if scalar */
-      const char *word_str=word.c_str();
-      char *err;
-      double val = strtod (word_str, &err);
-
-      /* Store into the cell */
-      retval(0, retval.columns()-1) =
-	((word == "") || (err != word_str+word.length())) ?
-	octave_value(word) : octave_value(val);
-
-      word = "";
-    }
-    else if ((inside) && (str[i]==prot) && ((i<len) && (str[i+1]==prot))) {
-
-      /* Insisde a string */
-      word += prot;
-      ++i;
-    }
-    else if (str[i] == prot)
-      /* Changing */
-      inside = !inside;
-    else
-      word += str[i];
-  }
-
-  return octave_value(retval);
-}