Skip to content
Snippets Groups Projects
Commit ccb6cb2d authored by James Goppert's avatar James Goppert
Browse files

Added read_csv.sci from master.

parent 4cbb76ee
No related branches found
No related tags found
No related merge requests found
// 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment