]> Creatis software - CreaPhase.git/blob - octave_packages/m/set/private/validargs.m
update packages
[CreaPhase.git] / octave_packages / m / set / private / validargs.m
1 ## Copyright (C) 2000-2012 Paul Kienzle
2 ## Copyright (C) 2009-2010 Jaroslav Hajek
3 ##
4 ## This file is part of Octave.
5 ##
6 ## Octave is free software; you can redistribute it and/or modify it
7 ## under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation; either version 3 of the License, or (at
9 ## your option) any later version.
10 ##
11 ## Octave is distributed in the hope that it will be useful, but
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 ## General Public License for more details.
15 ##
16 ## You should have received a copy of the GNU General Public License
17 ## along with Octave; see the file COPYING.  If not, see
18 ## <http://www.gnu.org/licenses/>.
19
20 ## Validate arguments for binary set operation.
21 function [x, y] = validargs (caller, x, y, byrows_arg)
22
23   if (nargin == 3)
24     icx = iscellstr (x);
25     icy = iscellstr (y);
26     if (icx || icy)
27       if (icx && ischar (y))
28         y = cellstr (y);
29       elseif (icy && ischar (x))
30         x = cellstr (x);
31       elseif (! (icx && icy))
32         error ("%s: cell array of strings cannot be combined with a nonstring value", caller);
33       endif
34     elseif (! (ismatrix (x) && ismatrix (y)))
35       error ("%s: input arguments must be arrays or cell arrays of strings", caller);
36     endif
37   elseif (nargin == 4)
38     if (strcmpi (byrows_arg, "rows"))
39       if (iscell (x) || iscell (y))
40         error ('%s: cells not supported with "rows"', caller);
41       elseif (! (ismatrix (x) && ismatrix (y)))
42         error ("%s: input arguments must be arrays or cell arrays of strings", caller);
43       else
44         if (ndims (x) > 2 || ndims (y) > 2)
45           error ('%s: need 2-dimensional matrices for "rows"', caller);
46         elseif (columns (x) != columns (y) && ! (isempty (x) || isempty (y)))
47           error ("%s: number of columns must match", caller);
48         endif
49       endif
50     else
51       error ("%s: invalid option: %s", caller, byrows_arg);
52     endif
53   else
54     print_usage (caller);
55   endif
56
57 endfunction