From 096975d0f1c17fadd33340e7c0eacce889c795b3 Mon Sep 17 00:00:00 2001
From: James Goppert <jgoppert@w7.hsl.dynalias.com>
Date: Mon, 15 Aug 2011 20:50:31 -0400
Subject: [PATCH] Added read_csv.sci from sfUpdates branch

---
 read_csv.sci | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)
 create mode 100644 read_csv.sci

diff --git a/read_csv.sci b/read_csv.sci
new file mode 100644
index 0000000..48a851e
--- /dev/null
+++ b/read_csv.sci
@@ -0,0 +1,63 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2008 - INRIA
+// Copyright (C) 2009 - DIGITEO - Allan CORNET
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution.  The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+function stat = isfile(fname)
+	stat = (fileinfo(fname) ~= [])
+endfunction
+
+function strOut = gettext(str)
+	strOut = str
+endfunction
+
+function mat = read_csv(fname,sep)
+// Given an ascii  file created by Excel using "Text and comma" format
+// read_csv(fname) returns the corresponding Scilab matrix of strings.
+
+  if (type(fname) <> 10) then
+    error(msprintf(gettext("%s: Wrong type for input argument #%d: a string expected.\n"), 'write_csv', 1));
+  end
+  
+  if (size(fname,'*')<> 1) then
+    error(msprintf(gettext("%s: Wrong size for input argument #%d: a string expected.\n"), 'write_csv', 1));  
+  end
+  
+  if argn(2)<2 then 
+    sep = ',';
+  end
+  
+  if ~isfile(fname) then
+    //error(msprintf(gettext("%s: file %s does not exist.\n"), 'write_csv', 1, fname));  
+	error('file doesn''t exist')
+  end
+  
+  v = mgetl(fname);
+  ns = length(sep);
+  mat = [];
+  ki = 1;
+  for i = 1 : size(v,'*')
+    line = v(i);
+    K = [strindex(line, sep)];
+    ki = 1;
+    row = [];
+    for k = K
+      row = [row, part(line,ki:k-1)];
+      ki = k + ns;
+    end
+    row = [row, part(line, ki:length(line))];
+    if (i > 1) then
+      if size(row,2) > size(mat,2) then
+        mat($,size(row,2)) = '';
+      elseif size(row,2) < size(mat,2) then
+        row(size(mat,2)) = '';
+      end
+    end
+    mat = [mat; row];
+  end
+endfunction
-- 
GitLab