~ubuntu-branches/ubuntu/precise/scilab/precise

« back to all changes in this revision

Viewing changes to modules/api_scilab/help/en_US/common_getvardimension_api.xml

Tags: 5.3.0-1ubuntu1
* New upstream release
* URL in the watch file updated

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?xml version="1.0" encoding="utf-8"?>
2
 
<!--
3
 
 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
4
 
 * Copyright (C) 2009  - DIGITEO - Antoine ELIAS
5
 
 * 
6
 
 * This file must be used under the terms of the CeCILL.
7
 
 * This source file is licensed as described in the file COPYING, which
8
 
 * you should have received as part of this distribution.  The terms
9
 
 * are also available at    
10
 
 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
11
 
 *
12
 
 -->
13
 
<refentry version="5.0-subset Scilab" xml:id="Common_getvardimension_API"
14
 
          xml:lang="en" xmlns="http://docbook.org/ns/docbook"
15
 
          xmlns:xlink="http://www.w3.org/1999/xlink"
16
 
          xmlns:svg="http://www.w3.org/2000/svg"
17
 
          xmlns:ns5="http://www.w3.org/1999/xhtml"
18
 
          xmlns:mml="http://www.w3.org/1998/Math/MathML"
19
 
          xmlns:db="http://docbook.org/ns/docbook">
20
 
 
21
 
    <refnamediv>
22
 
        <refname>Variable dimension (Scilab gateway)</refname>
23
 
 
24
 
        <refpurpose>
25
 
            How to get the dimensions of an argument or a variable stored as matrix.
26
 
        </refpurpose>
27
 
    </refnamediv>
28
 
    <refsynopsisdiv>
29
 
      <title>Calling Sequence</title>
30
 
        <para>Input argument profile:</para>
31
 
        <synopsis>SciErr getVarDimension(void* _pvCtx, int* _piAddress, int* _piRows, int* _piCols)</synopsis>
32
 
        <para>Named variable profile:</para>
33
 
        <synopsis>SciErr getNamedVarDimension(void* _pvCtx, char *_pstName, int* _piRows, int* _piCols)</synopsis>
34
 
    </refsynopsisdiv>
35
 
    <refsection>
36
 
        <title>Parameters</title>
37
 
        <variablelist>
38
 
            <varlistentry>
39
 
                <term>_pvCtx</term>
40
 
                <listitem>
41
 
                    <para>
42
 
                        Scilab environment pointer, pass in "pvApiCtx" provided by api_scilab.h
43
 
                    </para>
44
 
                </listitem>
45
 
            </varlistentry>
46
 
            <varlistentry>
47
 
                <term>_piAddress</term>
48
 
                <listitem>
49
 
                    <para>
50
 
                        The address of the variable.
51
 
                    </para>
52
 
                </listitem>
53
 
            </varlistentry>
54
 
            <varlistentry>
55
 
                <term>_pstName</term>
56
 
                <listitem>
57
 
                    <para>
58
 
                        Scilab variable name.
59
 
                    </para>
60
 
                </listitem>
61
 
            </varlistentry>
62
 
            <varlistentry>
63
 
                <term>_piRows</term>
64
 
                <listitem>
65
 
                    <para>
66
 
                        Return number of rows.
67
 
                    </para>
68
 
                </listitem>
69
 
            </varlistentry>
70
 
            <varlistentry>
71
 
                <term>_piCols</term>
72
 
                <listitem>
73
 
                    <para>
74
 
                        Return number of columns.
75
 
                    </para>
76
 
                </listitem>
77
 
            </varlistentry>
78
 
            <varlistentry>
79
 
                <term>SciErr</term>
80
 
                <listitem>
81
 
                    <para>
82
 
                        Error structure where is stored errors messages history and first error number.
83
 
                    </para>
84
 
                </listitem>
85
 
            </varlistentry>
86
 
        </variablelist>
87
 
    </refsection>
88
 
    <refsection>
89
 
      <title>Description</title>
90
 
      <para>This help describes how to get the dimensions of a variable in a gateway.</para>
91
 
    </refsection>
92
 
    <refsection>
93
 
        <!--File_gateway: SCI/modules/api_scilab/tests/unit_tests/common_function_api.c-->
94
 
        <!--File_scilab: SCI/modules/api_scilab/tests/unit_tests/common_function.tst-->
95
 
        <!--Lib_name: common_function-->
96
 
        <!--Func_list: common_function-->
97
 
        <title>Gateway Source</title>
98
 
        <programlisting role="code_gateway">
99
 
            <![CDATA[ 
100
 
SciErr printf_info(int _iVar);
101
 
 
102
 
int common_function(char *fname,unsigned long fname_len)
103
 
{
104
 
    SciErr sciErr;
105
 
    int i;
106
 
    int *piAddr1    = NULL;
107
 
    int iBool       = 0;
108
 
 
109
 
    for(i = 0 ; i < Rhs ; i++)
110
 
    {
111
 
        sciErr = printf_info(i + 1);
112
 
        if(sciErr.iErr)
113
 
        {
114
 
            printError(&sciErr, 0);
115
 
            break;
116
 
        }
117
 
        sciprint("\n\n");
118
 
    }
119
 
 
120
 
    //1 for true, 0 for false
121
 
    iBool = sciErr.iErr == 0 ? 1 : 0;
122
 
    sciErr = createMatrixOfBoolean(pvApiCtx, 1, 1, 1, &iBool);
123
 
    if(sciErr.iErr)
124
 
    {
125
 
        printError(&sciErr, 0);
126
 
        return 0;
127
 
    }
128
 
    //assign allocated variables to Lhs position
129
 
    LhsVar(1) = 1;
130
 
 
131
 
    return 0;
132
 
}
133
 
 
134
 
SciErr printf_info(int _iVar)
135
 
{
136
 
    SciErr sciErr;
137
 
    int* piAddr     = NULL;
138
 
    int iType       = 0;
139
 
    int iRows       = 0;
140
 
    int iCols       = 0;
141
 
    int iItem       = 0;
142
 
    int iComplex    = 0;
143
 
 
144
 
    sciErr = getVarAddressFromPosition(pvApiCtx, _iVar, &piAddr);
145
 
    if(sciErr.iErr)
146
 
    {
147
 
        return sciErr;
148
 
    }
149
 
 
150
 
    sciprint("Variable %d information:\n", _iVar);
151
 
 
152
 
    sciErr = getVarType(pvApiCtx, piAddr, &iType);
153
 
    if(sciErr.iErr)
154
 
    {
155
 
        return sciErr;
156
 
    }
157
 
 
158
 
    sciprint("\tType: ");
159
 
    switch(iType)
160
 
    {
161
 
        case sci_matrix : 
162
 
            sciprint("double\n");
163
 
            break;
164
 
        case sci_poly : 
165
 
            sciprint("polynomial\n");
166
 
            break;
167
 
        case sci_boolean : 
168
 
            sciprint("boolean\n");
169
 
            break;
170
 
        case sci_sparse : 
171
 
            sciprint("sparse\n");
172
 
            break;
173
 
        case sci_boolean_sparse : 
174
 
            sciprint("boolean_sparse\n");
175
 
            break;
176
 
        case sci_ints : 
177
 
        {
178
 
            char pstSigned[]    = "signed";
179
 
            char pstUnsigned[]  = "unsigned";
180
 
            char* pstSign       = pstSigned;
181
 
 
182
 
            int iPrec           = 0;
183
 
            sciErr = getMatrixOfIntegerPrecision(pvApiCtx, piAddr, &iPrec);
184
 
            if(sciErr.iErr)
185
 
            {
186
 
                return sciErr;
187
 
            }
188
 
 
189
 
            if(iPrec > 10)
190
 
            {
191
 
                pstSign = pstUnsigned;
192
 
            }
193
 
 
194
 
            sciprint("%s integer %d bits\n", pstSign, (iPrec % 10) * 8);
195
 
        }
196
 
        break;
197
 
        case sci_strings : 
198
 
            sciprint("strings\n");
199
 
            break;
200
 
        case sci_list : 
201
 
            sciprint("list\n");
202
 
            break;
203
 
        case sci_tlist : 
204
 
            sciprint("tlist\n");
205
 
            break;
206
 
        case sci_mlist : 
207
 
            sciprint("mlist\n");
208
 
            break;
209
 
        default :
210
 
            sciprint("Not manage by this function\n");
211
 
            return sciErr;
212
 
    }
213
 
 
214
 
    if(isVarComplex(pvApiCtx, piAddr))
215
 
    {
216
 
        sciprint("\tComplex: Yes\n");
217
 
    }
218
 
 
219
 
    sciprint("\tDimensions: ");
220
 
    if(isVarMatrixType(pvApiCtx, piAddr))
221
 
    {
222
 
        sciErr = getVarDimension(pvApiCtx, piAddr, &iRows, &iCols);
223
 
        if(sciErr.iErr)
224
 
        {
225
 
            return sciErr;
226
 
        }
227
 
 
228
 
        sciprint("%d x %d", iRows, iCols);
229
 
    }
230
 
    else
231
 
    {
232
 
        sciErr = getListItemNumber(pvApiCtx, piAddr, &iItem);
233
 
        if(sciErr.iErr)
234
 
        {
235
 
            return sciErr;
236
 
        }
237
 
        sciprint("%d", iItem);
238
 
    }
239
 
    return sciErr;
240
 
}
241
 
 ]]></programlisting>
242
 
    </refsection>
243
 
 
244
 
    <refsection>
245
 
        <title>Scilab test script</title>
246
 
        <programlisting role="code_scilab"><![CDATA[ 
247
 
l1 = [1,2*%i,3;%i,2,3*%i];
248
 
l2 = ["may","the";"puffin","be";"with","you"];
249
 
l3 = int8([1,2,3]);
250
 
l4 = uint16([1000,2000,3000]);
251
 
l5 = list(l1,l2,l3);
252
 
l = list(l1,l2,l3,l4,l5);
253
 
common_function(l(1:$))
254
 
 ]]></programlisting>
255
 
    </refsection>
256
 
</refentry>