License Header change: Removed the LICENSE_END before beta
[scilab.git] / scilab / modules / api_scilab / help / ja_JP / legacy / low_level_functions / poly_getpolyvariablename_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="poly_getpolyvariablename_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 getPolyVariableName(void* _pvCtx, int* _piAddress, char* _pstVarName, int* _piVarNameLen)</synopsis>
27     </refsynopsisdiv>
28     <refsection>
29         <title>引数</title>
30         <variablelist>
31             <varlistentry>
32                 <term>_pvCtx</term>
33                 <listitem>
34                     <para>
35                         Scilab環境ポインタ, api_scilab.h により定義された "pvApiCtx"で指定.
36                     </para>
37                 </listitem>
38             </varlistentry>
39             <varlistentry>
40                 <term>_piAddress</term>
41                 <listitem>
42                     <para>
43                         変数のアドレス.
44                     </para>
45                 </listitem>
46             </varlistentry>
47             <varlistentry>
48                 <term>_pstVarName</term>
49                 <listitem>
50                     <para>
51                         返される記号変数名
52                     </para>
53                 </listitem>
54             </varlistentry>
55             <varlistentry>
56                 <term>_piVarNameLen</term>
57                 <listitem>
58                     <para>
59                         返される _pstVarNameの長さ
60                     </para>
61                 </listitem>
62             </varlistentry>
63             <varlistentry>
64                 <term>SciErr</term>
65                 <listitem>
66                     <para>
67                         エラー構造体で,エラーメッセージ履歴と最初のエラー番号を格納します.
68                     </para>
69                 </listitem>
70             </varlistentry>
71         </variablelist>
72     </refsection>
73     <refsection>
74         <title>説明</title>
75         <para>このヘルプは記号変数名を取得する方法を示します.</para>
76     </refsection>
77     <refsection>
78         <!--File_gateway: SCI/modules/api_scilab/tests/unit_tests/poly_reading_api.c-->
79         <!--File_scilab: SCI/modules/api_scilab/tests/unit_tests/poly_reading_api.tst-->
80         <!--Lib_name: poly_reading-->
81         <!--Func_list: read_poly-->
82         <title>ゲートウェイのソース</title>
83         <programlisting role="code_gateway"><![CDATA[ 
84 #include "api_scilab.h"
85 int read_poly(char *fname,void* pvApiCtx)
86 {
87         SciErr sciErr;
88         int i,j;
89         //変数の情報
90         int iRows                       = 0;
91         int iCols                       = 0;
92         int iVarLen                     = 0;
93         int* piAddr                     = NULL;
94         int* piNbCoef           = NULL;
95         double** pdblReal       = NULL;
96         double** pdblImg        = NULL;
97         char* pstVarname        = NULL;
98         //入力/出力引数を確認
99     CheckInputArgument(pvApiCtx, 1, 1);
100     CheckOutputArgument(pvApiCtx, 1, 1);
101         sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
102         if(sciErr.iErr)
103         {
104                 printError(&sciErr, 0);
105                 return 0;
106         }
107         if(isVarComplex(pvApiCtx, piAddr) == FALSE)
108         {
109                 //Error
110                 return 0;
111         }
112         //変数名の長さを取得
113         sciErr = getPolyVariableName(pvApiCtx, piAddr, NULL, &iVarLen);
114         if(sciErr.iErr)
115         {
116                 printError(&sciErr, 0);
117                 return 0;
118         }
119         //変数名を得るバッファを確保
120         pstVarname = (char*)malloc(sizeof(char) * (iVarLen + 1));//ヌル終端用に1
121         //変数名を取得
122         sciErr = getPolyVariableName(pvApiCtx, piAddr, pstVarname, &iVarLen);
123         if(sciErr.iErr)
124         {
125                 printError(&sciErr, 0);
126                 return 0;
127         }
128         //最初のコール: 次元を取得
129         sciErr = getComplexMatrixOfPoly(pvApiCtx, piAddr, &iRows, &iCols, NULL, NULL, NULL);
130         if(sciErr.iErr)
131         {
132                 printError(&sciErr, 0);
133                 return 0;
134         }
135         //係数の配列を確保
136         piNbCoef = (int*)malloc(sizeof(int) * iRows * iCols);
137         //2回目のコール: 係数を取得
138         sciErr = getComplexMatrixOfPoly(pvApiCtx, piAddr, &iRows, &iCols, piNbCoef, NULL, NULL);
139         if(sciErr.iErr)
140         {
141                 printError(&sciErr, 0);
142                 return 0;
143         }
144         //データ配列を確保
145         pdblReal    = (double**)malloc(sizeof(double*) * iRows * iCols);
146         pdblImg     = (double**)malloc(sizeof(double*) * iRows * iCols);
147         for(i = 0 ; i < iRows * iCols ; i++)
148         {
149                 pdblReal[i] = (double*)malloc(sizeof(double) * piNbCoef[i]);
150                 pdblImg[i] = (double*)malloc(sizeof(double) * piNbCoef[i]);
151         }
152         //3回目のコール: データを取得
153         sciErr = getComplexMatrixOfPoly(pvApiCtx, piAddr, &iRows, &iCols, piNbCoef, pdblReal, pdblImg);
154         if(sciErr.iErr)
155         {
156                 printError(&sciErr, 0);
157                 return 0;
158         }
159         //何らかのデータ処理
160         //行列の多項式を反転し 係数を反転
161         for(i = 0 ; i < (iRows * iCols) / 2 ; i++)
162         {
163                 int iPos1                       = iRows * iCols - 1 - i;
164                 double* pdblSave        = NULL;
165                 int iNbCoefSave         = 0;
166                 //switch array of coefficient
167                 pdblSave                        = pdblReal[i];
168                 pdblReal[i]                     = pdblReal[iPos1];
169                 pdblReal[iPos1]         = pdblSave;
170                 pdblSave                        = pdblImg[i];
171                 pdblImg[i]                      = pdblImg[iPos1];
172                 pdblImg[iPos1]          = pdblSave;
173                 //switch number of coefficient
174                 iNbCoefSave                     = piNbCoef[i];
175                 piNbCoef[i]                     = piNbCoef[iPos1];
176                 piNbCoef[iPos1]         = iNbCoefSave;
177         }
178         //係数を切り替え
179         for(i = 0 ; i < iRows * iCols ; i++)
180         {
181                 for(j = 0 ; j < piNbCoef[i] /2 ; j++)
182                 {
183                         int iPos2                       = piNbCoef[i] - 1 - j;
184                         double dblVal           = pdblReal[i][j];
185                         pdblReal[i][j]          = pdblReal[i][iPos2];
186                         pdblReal[i][iPos2]      = dblVal;
187                         dblVal                          = pdblImg[i][j];
188                         pdblImg[i][j]           = pdblImg[i][iPos2];
189                         pdblImg[i][iPos2]       = dblVal;
190                 }
191         }
192         sciErr = createComplexMatrixOfPoly(pvApiCtx, nbInputArgument(pvApiCtx) + 1, pstVarname, iRows, iCols, piNbCoef, pdblReal, pdblImg);
193         if(sciErr.iErr)
194         {
195                 printError(&sciErr, 0);
196                 return 0;
197         }
198         //OSメモリを解放
199         free(pstVarname);
200         free(piNbCoef);
201         for(i = 0 ; i < iRows * iCols ; i++)
202         {
203                 free(pdblReal[i]);
204                 free(pdblImg[i]);
205         }
206         free(pdblReal);
207         free(pdblImg);
208         //assign allocated variables to Lhs position
209         AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
210         return 0;
211 }
212  ]]></programlisting>
213     </refsection>
214     <refsection>
215         <title>Scilabテストスクリプト</title>
216         <programlisting role="code_scilab"><![CDATA[ 
217 coeff1 = [ ..
218 29*%i,22*%i,16*%i,11*%i,7*%i,30,23,17,12,8,-31*%i,-24*%i,-18*%i,-13*%i,-9*%i,32,25,19,14,10,-33*%i,-26*%i,-20*%i,-15*%i,0,34,27,21,0,0,0,-28*%i,0,0,0,36-35*%i,0,0,0,0; ..
219 4*%i,2*%i,%i,22,16,5,-3,0,-23*%i,-17*%i,-6*%i,0,0,24,18,0,0,0,-25*%i,-19*%i,0,0,0,26,20,0,0,0,-27*%i,-21*%i,0,0,0,28,0,0,0,0,0,0; ..
220 11,7,4,2,1,-12*%i,-8*%i,-5*%i,3*%i,0,13,9,6,0,0,-14*%i,-10*%i,0,0,0,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
221 x = poly(0, "x");
222 p1  = 1;
223 p2  = 2 * x + 3 * %i;
224 p3  = 4 * x**2 - 5 * %i * x + 6;
225 p4  = 7 * x**3 - 8 * %i * x**2 + 9 * x - 10 * %i;
226 p5  = 11 * x**4 - 12 * %i * x**3 + 13 * x**2 - 14 * %i * x + 15;
227 p6  = 16 * x**5 - 17 * %i * x**4 + 18 * x**3 - 19 * %i * x**2 + 20 * x  - 21 * %i;
228 p7  = 22 * x**6 - 23 * %i * x**5 + 24 * x**4 - 25 * %i * x**3 + 26 * x**2 - 27 * %i * x + 28;
229 p8  = %i;
230 p9  = 2 * %i * x - 3;
231 p10 = 4 * %i * x**2 + 5 * x - 6 * %i;
232 p11 = 7 * %i * x**3 + 8 * x**2 - 9 * %i * x + 10;
233 p12 = 11 * %i * x**4 + 12 * x**3 - 13 * %i * x**2 + 14 * x - 15 * %i;
234 p13 = 16 * %i * x**5 + 17 * x**4 - 18 * %i * x**3 + 19 * x**2 - 20 * %i * x  + 21;
235 p14 = 22 * %i * x**6 + 23 * x**5 - 24 * %i * x**4 + 25 * x**3 - 26 * %i * x**2 + 27 * x - 28 * %i;
236 p15 = 29 * %i * x**7 + 30 * x**6 - 31 * %i * x**5 + 32 * x**4 - 33 * %i * x**3 + 34 * x**2 - 35 * %i + 36;
237 p = [p1, p2, p3, p4, p5 ; p6, p7, p8, p9 ,p10 ; p11, p12, p13, p14, p15];
238 p1 = read_poly(p);
239 coeff2 = coeff(p1);
240 if or(coeff2 <> coeff1) then error("failed"), end
241  ]]></programlisting>
242     </refsection>
243 </refentry>