]> Creatis software - CreaPhase.git/blob - octave_packages/general-1.3.1/private/parcellfun_opts.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / general-1.3.1 / private / parcellfun_opts.m
1 ## Copyright (C) 2010 VZLU Prague, a.s., Czech Republic
2 ##
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
6 ## version.
7 ##
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
11 ## details.
12 ##
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/>.
15
16 ## -*- texinfo -*-
17 ## @deftypefn{Function File} {} parcellfun_opts (args)
18 ## Undocumented internal function.
19 ## @end deftypefn
20
21 function [nargs, uniform_output, error_handler, ...
22   verbose_level, chunks_per_proc, vectorized] = parcellfun_opts (args)
23
24   uniform_output = true;
25   error_handler = [];
26   verbose_level = 1; # default to normal output level
27   chunks_per_proc = 0; # 0 means than size of chunk is 1
28   vectorized = false;
29
30   nargs = length (args);
31
32   ## parse options
33   while (nargs > 1)
34     opt = args{nargs-1};
35     if (! ischar (opt))
36       break;
37     else
38       opt = tolower (opt);
39       val = args{nargs};
40     endif
41     switch (opt)
42     case "uniformoutput"
43       uniform_output = logical (val);
44       if (! isscalar (uniform_output))
45         error ("parcellfun: UniformOutput must be a logical scalar");
46       endif
47     case "errorhandler"
48       error_handler = val;
49       if (! isa (error_handler, "function_handle"))
50         error ("parcellfun: ErrorHandler must be a function handle");
51       endif
52     case "verboselevel"
53       verbose_level = val;
54       if (! isscalar (verbose_level))
55         error ("parcellfun: VerboseLevel must be a numeric scalar");
56       endif
57     case "chunksperproc"
58       chunks_per_proc = round (val);
59       if (! isscalar (chunks_per_proc) || chunks_per_proc <= 0)
60         error ("parcellfun: ChunksPerProc must be a positive scalar");
61       endif
62     case "vectorized"
63       vectorized = logical (val);
64       if (! isscalar (vectorized))
65         error ("parcellfun: Vectorized must be a logical scalar");
66       endif
67     otherwise
68       break;
69     endswitch
70     nargs -= 2;
71   endwhile
72
73   if (vectorized && chunks_per_proc <= 0)
74     error ("parcellfun: the ""Vectorized"" option requires also ""ChunksPerProc""");
75   endif
76
77 endfunction