License Header change: Removed the LICENSE_END before beta
[scilab.git] / scilab / modules / api_scilab / help / ja_JP / legacy / low_level_functions / common_getvaraddr_api.xml
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  * Copyright (C) 2012 - 2016 - Scilab Enterprises
7  *
8  * This file is hereby licensed under the terms of the GNU GPL v2.0,
9  * pursuant to article 5.3.4 of the CeCILL v.2.1.
10  * This file was originally licensed under the terms of the CeCILL v2.1,
11  * and continues to be available under such terms.
12  * For more information, see the COPYING file which you should have received
13  * along with this program.
14  *
15  -->
16 <refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:id="Common_getvaraddr_API" xml:lang="ja">
17     <refnamediv>
18         <refname>変数リファレンス (Scilabゲートウェイ)</refname>
19         <refpurpose>
20             引数のアドレスまたはゲートウェイの変数を取得する方法.
21         </refpurpose>
22     </refnamediv>
23     <refsynopsisdiv>
24         <title>呼び出し手順</title>
25         <para>入力引数プロファイル:</para>
26         <synopsis>SciErr getVarAddressFromPosition(void* _pvCtx, int _iVar, int** _piAddress)</synopsis>
27         <para>名前指定変数プロファイル:</para>
28         <synopsis>SciErr getVarAddressFromName(void* _pvCtx, const char* _pstName, int** _piAddress)</synopsis>
29     </refsynopsisdiv>
30     <refsection>
31         <title>引数</title>
32         <variablelist>
33             <varlistentry>
34                 <term>_pvCtx</term>
35                 <listitem>
36                     <para>
37                         Scilab環境ポインタ, api_scilab.hで定義される "pvApiCtx" を指定
38                     </para>
39                 </listitem>
40             </varlistentry>
41             <varlistentry>
42                 <term>_iVar</term>
43                 <listitem>
44                     <para>
45                         関数コール時の引数の位置.
46                     </para>
47                 </listitem>
48             </varlistentry>
49             <varlistentry>
50                 <term>_pstName</term>
51                 <listitem>
52                     <para>
53                         Scilab変数名.
54                     </para>
55                 </listitem>
56             </varlistentry>
57             <varlistentry>
58                 <term>_piAddress</term>
59                 <listitem>
60                     <para>
61                         Scilab変数のリターンアドレス.
62                     </para>
63                 </listitem>
64             </varlistentry>
65             <varlistentry>
66                 <term>SciErr</term>
67                 <listitem>
68                     <para>
69                         エラー構造体で,エラーメッセージ履歴と最初のエラー番号を保持します.
70                     </para>
71                 </listitem>
72             </varlistentry>
73         </variablelist>
74     </refsection>
75     <refsection>
76         <title>説明</title>
77         <para>この関数はゲートウェイの引数のアドレスを取得します.</para>
78     </refsection>
79     <refsection>
80         <!--File_gateway: SCI/modules/api_scilab/tests/unit_tests/common_function_api.c-->
81         <!--File_scilab: SCI/modules/api_scilab/tests/unit_tests/common_function.tst-->
82         <!--Lib_name: common_function-->
83         <!--Func_list: common_function-->
84         <title>ゲートウェイのソース</title>
85         <programlisting role="code_gateway">
86             <![CDATA[ 
87 #include "api_scilab.h"
88 SciErr printf_info(int _iVar);
89 int common_function(char *fname,void* pvApiCtx)
90 {
91     SciErr sciErr;
92     int i;
93     int *piAddr1    = NULL;
94     int iBool       = 0;
95     for(i = 0 ; i < nbInputArgument(pvApiCtx) ; i++)
96     {
97         sciErr = printf_info(i + 1);
98         if(sciErr.iErr)
99         {
100             printError(&sciErr, 0);
101             break;
102         }
103         sciprint("\n\n");
104     }
105     // trueの場合に1,それ以外は 0
106     iBool = sciErr.iErr == 0 ? 1 : 0;
107     sciErr = createMatrixOfBoolean(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 1, 1, &iBool);
108     if(sciErr.iErr)
109     {
110         printError(&sciErr, 0);
111         return 0;
112     }
113     // 確保された変数を左辺に代入
114     AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
115     return 0;
116 }
117 SciErr printf_info(int _iVar)
118 {
119     SciErr sciErr;
120     int* piAddr     = NULL;
121     int iType       = 0;
122     int iRows       = 0;
123     int iCols       = 0;
124     int iItem       = 0;
125     int iComplex    = 0;
126     sciErr = getVarAddressFromPosition(pvApiCtx, _iVar, &piAddr);
127     if(sciErr.iErr)
128     {
129         return sciErr;
130     }
131     sciprint("Variable %d information:\n", _iVar);
132     sciErr = getVarType(pvApiCtx, piAddr, &iType);
133     if(sciErr.iErr)
134     {
135         return sciErr;
136     }
137     sciprint("\tType: ");
138     switch(iType)
139     {
140         case sci_matrix :
141             sciprint("double\n");
142             break;
143         case sci_poly :
144             sciprint("polynomial\n");
145             break;
146         case sci_boolean :
147             sciprint("boolean\n");
148             break;
149         case sci_sparse :
150             sciprint("sparse\n");
151             break;
152         case sci_boolean_sparse :
153             sciprint("boolean_sparse\n");
154             break;
155         case sci_ints :
156         {
157             char pstSigned[]    = "signed";
158             char pstUnsigned[]  = "unsigned";
159             char* pstSign       = pstSigned;
160             int iPrec           = 0;
161             sciErr = getMatrixOfIntegerPrecision(pvApiCtx, piAddr, &iPrec);
162             if(sciErr.iErr)
163             {
164                 return sciErr;
165             }
166             if(iPrec > 10)
167             {
168                 pstSign = pstUnsigned;
169             }
170             sciprint("%s integer %d bits\n", pstSign, (iPrec % 10) * 8);
171         }
172         break;
173         case sci_strings :
174             sciprint("strings\n");
175             break;
176         case sci_list :
177             sciprint("list\n");
178             break;
179         case sci_tlist :
180             sciprint("tlist\n");
181             break;
182         case sci_mlist :
183             sciprint("mlist\n");
184             break;
185         default :
186             sciprint("Not manage by this function\n");
187             return sciErr;
188     }
189     if(isVarComplex(pvApiCtx, piAddr))
190     {
191         sciprint("\tComplex: Yes\n");
192     }
193     sciprint("\tDimensions: ");
194     if(isVarMatrixType(pvApiCtx, piAddr))
195     {
196         sciErr = getVarDimension(pvApiCtx, piAddr, &iRows, &iCols);
197         if(sciErr.iErr)
198         {
199             return sciErr;
200         }
201         sciprint("%d x %d", iRows, iCols);
202     }
203     else
204     {
205         sciErr = getListItemNumber(pvApiCtx, piAddr, &iItem);
206         if(sciErr.iErr)
207         {
208             return sciErr;
209         }
210         sciprint("%d", iItem);
211     }
212     return sciErr;
213 }
214  ]]>
215         </programlisting>
216     </refsection>
217     <refsection>
218         <title>Scilabテストスクリプト</title>
219         <programlisting role="code_scilab"><![CDATA[ 
220 l1 = [1,2*%i,3;%i,2,3*%i];
221 l2 = ["may","the";"puffin","be";"with","you"];
222 l3 = int8([1,2,3]);
223 l4 = uint16([1000,2000,3000]);
224 l5 = list(l1,l2,l3);
225 l = list(l1,l2,l3,l4,l5);
226 common_function(l(1:$))
227  ]]></programlisting>
228     </refsection>
229 </refentry>