summaryrefslogtreecommitdiff
path: root/modules/atoms/macros/atoms_internals/atomsGetAvailable.sci
blob: 28c7d97312183d3887b1a2c8e5ed655b0cd3e27e (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 2010 - DIGITEO - Pierre MARECHAL <pierre.marechal@scilab.org>
//
// 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

// Internal function

// Input parameters
//
// - category: [], 1x1 or 1x2 string array
//   + []
//   + "Data Analysis And Statistics"
//   + "Data Analysis And Statistics - Neural networks"
//   + ["Data Analysis And Statistics","Neural networks"]
//
// - nameonly: %T or %F (%F is the default value)


// Returns the list of available packages
// - In ascending (lexical) order for the name
// - In descending order for the versions

// if nameonly is TRUE, a mx1 matrix is returned:
//
//         !ampl_toolbox      !
//         !                  !
//         !ANN_Toolbox       !
//         !                  !
//         !celestlab         !
//         !                  !
//         ...

// if nameonly is FALSE, a mx2 matrix is returned:
//
//        !ampl_toolbox      1.3-1      !
//        !                             !
//        !ampl_toolbox      1.2-1      !
//        !                             !
//        !ANN_Toolbox       0.4.2.3-1  !
//        !                             !
//        !celestlab         2.0.0-1    !
//        !                             !
//        !celestlab         1.0.1-1    !
//        ...

function packages = atomsGetAvailable(category,nameonly)

    packages = [];

    // Check input parameters
    // =========================================================================

    rhs = argn(2);

    if rhs > 2 then
        error(msprintf(gettext("%s: Wrong number of input arguments: %d to %d expected.\n"),"atomsGetAvailable",0,2))
    end

    if rhs==0 then
        category = [];
    end

    if category<>[] then

        if type(category) <> 10 then
            error(msprintf(gettext("%s: Wrong type for input argument #%d: A string expected.\n"),"atomsGetAvailable",1));
        end

        if (size(category,"*") <> 1) & or(size(category) <> [1 2]) then
            error(msprintf(gettext("%s: Wrong size for input argument #%d: A 1x1 or 1x2 string matrix expected.\n"),"atomsGetAvailable",1));
        end

        if and(size(category)==[1 2]) then
            category = category(1)+" - "+category(2);
        end

        if ~atomsIsCategory(category) then
            error(msprintf(gettext("%s: Wrong value for input argument #%d: A valid category expected.\n"),"atomsGetAvailable",1));
        end

    end

    if rhs>=2 then

        if type(nameonly) <> 4 then
            error(msprintf(gettext("%s: Wrong type for input argument #%d: A boolean expected.\n"),"atomsGetAvailable",2));
        end

        if size(nameonly,"*") <> 1 then
            error(msprintf(gettext("%s: Wrong size for input argument #%d: A boolean expected.\n"),"atomsGetAvailable",2));
        end

    else
        nameonly = %F;
    end

    // Get the list of available packages
    // =========================================================================

    [packages_struct,categories_struct] = atomsDESCRIPTIONget();

    if category==[] then
        // All packages
        packages_list      = getfield(1,packages_struct);
        packages_list(1:2) = [];
        packages_list      = packages_list';
    else
        // Filter by category
        category_struct    = categories_struct(category);
        packages_list      = category_struct("packages");
        packages_list      = unique(packages_list(:,1));
    end

    [A,k]         = gsort(convstr(packages_list,"l"),"lr","i");
    packages_list = packages_list(k);

    // Loop on package list
    // =========================================================================

    for i=1:size(packages_list,"*")

        // packages_list(i) is the technical name of the current package

        // Get the list of versions compatibles with this version of Scilab
        this_package_versions = atomsCompatibleVersions(packages_list(i));

        // If no compatible version, no need to add this package to the list
        if isempty(this_package_versions) then
            continue;
        end

        // Add the package to the list
        if nameonly then
            packages = [ packages;packages_list(i)];
        else
            packages = [ packages; ..
            emptystr(size(this_package_versions,"*"),1)+packages_list(i), ..
            this_package_versions ];
        end
    end

endfunction