X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=sidebyside;f=octave_packages%2Fstatistics-1.1.3%2Fcaseread.m;fp=octave_packages%2Fstatistics-1.1.3%2Fcaseread.m;h=71f5b7b0e5da602687c03045ed46de9f4c769b33;hb=c880e8788dfc484bf23ce13fa2787f2c6bca4863;hp=0000000000000000000000000000000000000000;hpb=1705066eceaaea976f010f669ce8e972f3734b05;p=CreaPhase.git diff --git a/octave_packages/statistics-1.1.3/caseread.m b/octave_packages/statistics-1.1.3/caseread.m new file mode 100644 index 0000000..71f5b7b --- /dev/null +++ b/octave_packages/statistics-1.1.3/caseread.m @@ -0,0 +1,61 @@ +## Copyright (C) 2008 Bill Denney +## +## 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 . + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{names} =} caseread (@var{filename}) +## Read case names from an ascii file. +## +## Essentially, this reads all lines from a file as text and returns +## them in a string matrix. +## @seealso{casewrite, tblread, tblwrite, csv2cell, cell2csv, fopen} +## @end deftypefn + +## Author: Bill Denney +## Description: Read strings from a file + +function names = caseread (f="") + + ## Check arguments + if nargin != 1 + print_usage (); + endif + if isempty (f) + ## FIXME: open a file dialog box in this case when a file dialog box + ## becomes available + error ("caseread: filename must be given") + endif + + [fid msg] = fopen (f, "rt"); + if fid < 0 || (! isempty (msg)) + error ("caseread: cannot open %s: %s", f, msg); + endif + + names = {}; + t = fgetl (fid); + while ischar (t) + names{end+1} = t; + t = fgetl (fid); + endwhile + if (fclose (fid) < 0) + error ("caseread: error closing f") + endif + names = strvcat (names); + +endfunction + +## Tests +%!shared n +%! n = ["a ";"bcd";"ef "]; +%!assert (caseread ("caseread.dat"), n);