1 ## Copyright (C) 2008 Bill Denney <bill@denney.ws>
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
17 ## @deftypefn {Function File} {} casewrite (@var{strmat}, @var{filename})
18 ## Write case names to an ascii file.
20 ## Essentially, this writes all lines from @var{strmat} to
21 ## @var{filename} (after deblanking them).
22 ## @seealso{caseread, tblread, tblwrite, csv2cell, cell2csv, fopen}
25 ## Author: Bill Denney <bill@denney.ws>
26 ## Description: Write strings from a file
28 function names = casewrite (s="", f="")
35 ## FIXME: open a file dialog box in this case when a file dialog box
37 error ("casewrite: filename must be given")
40 error ("casewrite: strmat must be given")
42 error ("casewrite: strmat must be a character matrix")
44 error ("casewrite: strmat must be two dimensional")
47 [fid msg] = fopen (f, "wt");
48 if fid < 0 || (! isempty (msg))
49 error ("casewrite: cannot open %s for writing: %s", f, msg);
53 status = fputs (fid, sprintf ("%s\n", deblank (s(i,:))));
56 error ("casewrite: error closing f")
63 %! s = ["a ";"bcd";"ef "];
65 %! casewrite (s, "casewrite.dat")
66 %! assert(caseread ("casewrite.dat"), s);