License Header change: Removed the LICENSE_END before beta
[scilab.git] / scilab / modules / api_scilab / help / ja_JP / legacy / sparse / F_sparseExample.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="sparseExample" xml:lang="ja">
17     <refnamediv>
18         <refname>疎行列の例</refname>
19         <refpurpose>
20             疎行列の使用例.
21         </refpurpose>
22     </refnamediv>
23     <refsection>
24         <title>説明</title>
25         <para>この例は疎行列変数を取得し,Scilabに返す方法を示します.</para>
26     </refsection>
27     <refsection>
28         <!--File_gateway: SCI/modules/api_scilab/tests/unit_tests/sparseExample.c-->
29         <!--File_scilab: SCI/modules/api_scilab/tests/unit_tests/sparseExample.tst-->
30         <!--Lib_name: sparseExample-->
31         <!--Func_list: sparseExample-->
32         <title>ゲートウェイのソース</title>
33         <programlisting role="code_gateway"><![CDATA[ 
34 #include "api_scilab.h"
35 int sparseExample(char *fname,void* pvApiCtx)
36 {
37         SciErr sciErr;
38         int* piAddr = NULL;
39         int iType   = 0;
40         int iRet    = 0;
41     CheckInputArgument(pvApiCtx, 1, 1);
42     CheckOutputArgument(pvApiCtx, 0, 1);
43         sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
44         if(sciErr.iErr)
45         {
46                 printError(&sciErr, 0);
47                 return 0;
48         }
49         if(isSparseType(pvApiCtx, piAddr))
50         {
51                 int iRows           = 0;
52                 int iCols           = 0;
53                 int iNbItem         = 0;
54                 int* piNbItemRow        = NULL;
55                 int* piColPos       = NULL;
56                 double* pdblReal        = NULL;
57                 double* pdblImg         = NULL;
58                 if(isVarComplex(pvApiCtx, piAddr))
59                 {
60                         iRet = getAllocatedComplexSparseMatrix(pvApiCtx, piAddr, &iRows, &iCols, &iNbItem, &piNbItemRow, &piColPos, &pdblReal, &pdblImg);
61                         if(iRet)
62                         {
63                                 freeAllocatedComplexSparseMatrix(piNbItemRow, piColPos, pdblReal, pdblImg);
64                                 return iRet;
65                         }
66                         sciErr = createComplexSparseMatrix(pvApiCtx, nbInputArgument(pvApiCtx) + 1, iRows, iCols, iNbItem, piNbItemRow, piColPos, pdblReal, pdblImg);
67                         if(sciErr.iErr)
68                         {
69                                 freeAllocatedComplexSparseMatrix(piNbItemRow, piColPos, pdblReal, pdblImg);
70                                 printError(&sciErr, 0);
71                                 return sciErr.iErr;
72                         }
73                         freeAllocatedComplexSparseMatrix(piNbItemRow, piColPos, pdblReal, pdblImg);
74                 }
75                 else
76                 {
77                         iRet = getAllocatedSparseMatrix(pvApiCtx, piAddr, &iRows, &iCols, &iNbItem, &piNbItemRow, &piColPos, &pdblReal);
78                         if(iRet)
79                         {
80                                 freeAllocatedSparseMatrix(piNbItemRow, piColPos, pdblReal);
81                                 return iRet;
82                         }
83                         sciErr = createSparseMatrix(pvApiCtx, nbInputArgument(pvApiCtx) + 1, iRows, iCols, iNbItem, piNbItemRow, piColPos, pdblReal);
84                         if(sciErr.iErr)
85                         {
86                                 freeAllocatedSparseMatrix(piNbItemRow, piColPos, pdblReal);
87                                 printError(&sciErr, 0);
88                                 return sciErr.iErr;
89                         }
90                         freeAllocatedSparseMatrix(piNbItemRow, piColPos, pdblReal);
91                 }
92                 AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
93         }
94         else
95         {
96                 AssignOutputVariable(pvApiCtx, 1) = 0;
97         }
98         return 0;
99 }
100  ]]></programlisting>
101     </refsection>
102     <refsection>
103         <title>Scilab テストスクリプト</title>
104         <programlisting role="code_scilab"><![CDATA[ 
105 a = sparse([1,1;2,2;3,3], [1, 2, 3]);
106 b = sparse([1,1;2,2;3,3], [1 + 2 * %i, 3 , -4 * %i]);
107 if sparseExample(a) <> a then pause;end
108 if sparseExample(b) <> b then pause;end
109  ]]></programlisting>
110     </refsection>
111 </refentry>