Bump version numbers to 6.2.0
[scilab.git] / scilab / modules / api_scilab / help / en_US / legacy / double / F_doubleExample.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="doubleExample" xml:lang="en">
17     <refnamediv>
18         <refname>double example</refname>
19         <refpurpose>
20             Double use case.
21         </refpurpose>
22     </refnamediv>
23     <refsection>
24         <title>Description</title>
25         <para>This example shows how to get a double variable and return it to Scilab.</para>
26     </refsection>
27     <refsection>
28         <!--File_gateway: SCI/modules/api_scilab/tests/unit_tests/doubleExample.c-->
29         <!--File_scilab: SCI/modules/api_scilab/tests/unit_tests/doubleExample.tst-->
30         <!--Lib_name: doubleExample-->
31         <!--Func_list: doubleExample-->
32         <title>Gateway Source</title>
33         <programlisting role="code_gateway">
34             <![CDATA[
35 #include "api_scilab.h"
36
37 int doubleExample(char *fname,void* pvApiCtx)
38 {
39         SciErr sciErr;
40         int* piAddr = NULL;
41         int iType   = 0;
42         int iRet    = 0;
43
44     CheckInputArgument(pvApiCtx, 1, 1);
45     CheckOutputArgument(pvApiCtx, 0, 1);
46
47     sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
48         if(sciErr.iErr)
49         {
50                 printError(&sciErr, 0);
51                 return 0;
52         }
53
54         if(isEmptyMatrix(pvApiCtx, piAddr))
55         {
56                 iRet = createEmptyMatrix(pvApiCtx, nbInputArgument(pvApiCtx) + 1);
57                 if(iRet)
58                 {
59                         return iRet;
60                 }
61
62                 AssignOutputVariable(pvApiCtx, 1) = 0;
63         }
64         else if(isDoubleType(pvApiCtx, piAddr))
65         {
66                 if(isScalar(pvApiCtx, piAddr))
67                 {
68                         double dblReal  = 0;
69                         double dblImg   = 0;
70
71                         if(isVarComplex(pvApiCtx, piAddr))
72                         {
73                                 iRet = getScalarComplexDouble(pvApiCtx, piAddr, &dblReal, &dblImg);
74                                 if(iRet)
75                                 {
76                                         return iRet;
77                                 }
78
79                                 iRet = createScalarComplexDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, dblReal, dblImg);
80                                 if(iRet)
81                                 {
82                                         return iRet;
83                                 }
84                         }
85                         else
86                         {
87                                 iRet = getScalarDouble(pvApiCtx, piAddr, &dblReal);
88                                 if(iRet)
89                                 {
90                                         return iRet;
91                                 }
92
93                                 iRet = createScalarDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, dblReal);
94                                 if(iRet)
95                                 {
96                                         return iRet;
97                                 }
98                         }
99                 }
100                 else
101                 {
102                         int iRows                       = 0;
103                         int iCols                       = 0;
104                         double* pdblReal        = NULL;
105                         double* pdblImg         = NULL;
106
107                         if(isVarComplex(pvApiCtx, piAddr))
108                         {
109                                 sciErr = getComplexMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols, &pdblReal, &pdblImg);
110                                 if(sciErr.iErr)
111                                 {
112                                         printError(&sciErr, 0);
113                                         return sciErr.iErr;
114                                 }
115
116                                 sciErr = createComplexMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, iRows, iCols, pdblReal, pdblImg);
117                                 if(sciErr.iErr)
118                                 {
119                                         printError(&sciErr, 0);
120                                         return sciErr.iErr;
121                                 }
122                         }
123                         else
124                         {
125                                 sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols, &pdblReal);
126                                 if(sciErr.iErr)
127                                 {
128                                         printError(&sciErr, 0);
129                                         return sciErr.iErr;
130                                 }
131
132                                 sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, iRows, iCols, pdblReal);
133                                 if(sciErr.iErr)
134                                 {
135                                         printError(&sciErr, 0);
136                                         return sciErr.iErr;
137                                 }
138                         }
139                 }
140
141         AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
142         }
143
144         return 0;
145 }
146  ]]>
147         </programlisting>
148     </refsection>
149     <refsection>
150         <title>Scilab test script</title>
151         <programlisting role="code_scilab"><![CDATA[
152 a = 1;
153 b = %i;
154 c = [1,2,3;4,5,6];
155 d = c(1:$) + c($:-1:1) * %i;
156
157 doubleExample(a) == a
158 doubleExample(b) == b
159 doubleExample(c) == c
160 doubleExample(d) == d
161  ]]></programlisting>
162     </refsection>
163 </refentry>