summaryrefslogtreecommitdiff
path: root/modules/parameters/macros/get_param.sci
blob: 88ae5b20a3f3b2deb40a4a116ed6181385c6505a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 2008 - Yann COLLETTE <yann.collette@renault.com>
// Copyright (C) 2009-2010 - DIGITEO - Yann COLLETTE
// Copyright (C) 2010 - DIGITEO - Michael Baudin
//
// 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.1-en.txt

function [result,err] = get_param(list_name,param_name,param_default)
    [nargout,nargin] = argn();
    if ~isdef("param_default","local") then
        param_default = [];
    end

    if ( type(param_default) == 13 ) then
        prot=funcprot()
        funcprot(0);
    end
    result = param_default;
    if ( type(param_default) == 13 ) then
        funcprot(prot);
    end

    if typeof(list_name)=="plist" then
        if is_param(list_name,param_name) then
            if ( type(param_default) == 13 ) then
                prot=funcprot()
                funcprot(0);
            end
            result = list_name(param_name);
            if ( type(param_default) == 13 ) then
                funcprot(prot);
            end
            if nargout==2 then
                err = %F;
            end
        else
            if nargout==2 then
                err = %T;
            else
                warning(sprintf(gettext("%s: parameter %s not defined"),"get_param",param_name));
            end
        end
    else
        if nargout==2 then
            err = %T;
        else
            error(sprintf(gettext("%s: Wrong type for input argument #%d: %s expected.\n"), "get_param", 1, "plist"));
        end
    end
endfunction