1 /*
2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2006 - INRIA - Fabrice Leray
4 * Copyright (C) 2006 - INRIA - Jean-Baptiste Silvy
5 * Copyright (C) 2011 - DIGITEO - Bruno JOFRET
6 *
7 * Copyright (C) 2012 - 2016 - Scilab Enterprises
8 *
9 * This file is hereby licensed under the terms of the GNU GPL v2.0,
10 * pursuant to article 5.3.4 of the CeCILL v.2.1.
11 * This file was originally licensed under the terms of the CeCILL v2.1,
12 * and continues to be available under such terms.
13 * For more information, see the COPYING file which you should have received
14 * along with this program.
15 *
16 */
17
18 /*------------------------------------------------------------------------*/
19 /* file: sci_champ.c */
20 /* desc : interface for champ (and champ1) routine */
21 /*------------------------------------------------------------------------*/
22 #include <string.h>
23 #include "gw_graphics.h"
24 #include "api_scilab.h"
25 #include "GetCommandArg.h"
26 #include "BuildObjects.h"
27 #include "DefaultCommandArg.h"
28 #include "Champ.h"
29 #include "sciprint.h"
30 #include "localization.h"
31 #include "Scierror.h"
32 /*--------------------------------------------------------------------------*/
sci_champ(char * fname,void * pvApiCtx)33 int sci_champ (char *fname, void *pvApiCtx)
34 {
35 return sci_champ_G(fname, C2F(champ), pvApiCtx);
36 }
37 /*--------------------------------------------------------------------------*/
sci_champ1(char * fname,void * pvApiCtx)38 int sci_champ1 (char *fname, void *pvApiCtx)
39 {
40 sciprint(_("%s: Feature %s is obsolete and will be permanently removed in Scilab %s\n"), _("Warning"), "champ1()", "6.1.x");
41 sciprint(_("%s: Please use %s instead.\n"), _("Warning"), "champ().colored");
42
43 return sci_champ_G(fname, C2F(champ1), pvApiCtx);
44 }
45 /*--------------------------------------------------------------------------*/
sci_champ_G(char * fname,int (* func)(double *,double *,double *,double *,int *,int *,char *,double *,double *,int),void * pvApiCtx)46 int sci_champ_G(char *fname,
47 int (*func) (double *, double *, double *, double *, int *, int *, char *, double *, double *, int),
48 void *pvApiCtx)
49 {
50 SciErr sciErr;
51 double arfact_def = 1.0;
52 double* arfact = &arfact_def;
53 int m1 = 0, n1 = 0, m2 = 0, n2 = 0, m3 = 0, n3 = 0, m4 = 0, n4 = 0;
54 static rhs_opts opts[] =
55 {
56 { -1, "arfact", -1, 0, 0, NULL},
57 { -1, "rect", -1, 0, 0, NULL},
58 { -1, "strf", -1, 0, 0, NULL},
59 { -1, NULL, -1, 0, 0, NULL}
60 };
61
62 char * strf = NULL;
63 BOOL freeStrf = FALSE;
64 char strfl[4];
65 double* rect = NULL;
66
67 int* piAddr1 = NULL;
68 int* piAddr2 = NULL;
69 int* piAddr3 = NULL;
70 int* piAddr4 = NULL;
71
72 double* l1 = NULL;
73 double* l2 = NULL;
74 double* l3 = NULL;
75 double* l4 = NULL;
76
77 CheckInputArgument(pvApiCtx, -1, 7);
78 CheckOutputArgument(pvApiCtx, 0, 1);
79
80 if (nbInputArgument(pvApiCtx) <= 0)
81 {
82 sci_demo(fname, pvApiCtx);
83 return 0;
84 }
85 else if (nbInputArgument(pvApiCtx) < 4)
86 {
87 Scierror(999, _("%s: Wrong number of input arguments: At least %d expected.\n"), fname, 4);
88 return 0;
89 }
90
91 if (getOptionals(pvApiCtx, fname, opts) == 0)
92 {
93 return 0;
94 }
95
96 if (FirstOpt(pvApiCtx) < 5)
97 {
98 Scierror(999, _("%s: Misplaced optional argument: #%d must be at position %d.\n"), fname, 1, 5);
99 return -1;
100 }
101
102 //get variable address
103 sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1);
104 if (sciErr.iErr)
105 {
106 printError(&sciErr, 0);
107 return 1;
108 }
109
110 // Retrieve a matrix of double at position 1.
111 sciErr = getMatrixOfDouble(pvApiCtx, piAddr1, &m1, &n1, &l1);
112 if (sciErr.iErr)
113 {
114 Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1);
115 printError(&sciErr, 0);
116 return 1;
117 }
118
119 //get variable address
120 sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2);
121 if (sciErr.iErr)
122 {
123 printError(&sciErr, 0);
124 return 1;
125 }
126
127 // Retrieve a matrix of double at position 2.
128 sciErr = getMatrixOfDouble(pvApiCtx, piAddr2, &m2, &n2, &l2);
129 if (sciErr.iErr)
130 {
131 Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 2);
132 printError(&sciErr, 0);
133 return 1;
134 }
135
136 //get variable address
137 sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr3);
138 if (sciErr.iErr)
139 {
140 printError(&sciErr, 0);
141 return 1;
142 }
143
144 // Retrieve a matrix of double at position 3.
145 sciErr = getMatrixOfDouble(pvApiCtx, piAddr3, &m3, &n3, &l3);
146 if (sciErr.iErr)
147 {
148 Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 3);
149 printError(&sciErr, 0);
150 return 1;
151 }
152
153 //get variable address
154 sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddr4);
155 if (sciErr.iErr)
156 {
157 printError(&sciErr, 0);
158 return 1;
159 }
160
161 // Retrieve a matrix of double at position 4.
162 sciErr = getMatrixOfDouble(pvApiCtx, piAddr4, &m4, &n4, &l4);
163 if (sciErr.iErr)
164 {
165 Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 4);
166 printError(&sciErr, 0);
167 return 1;
168 }
169
170 //CheckSameDims
171 if (m3 != m4 || n3 != n4)
172 {
173 Scierror(999, _("%s: Wrong size for input argument #%d: %d-by-%d matrix expected.\n"), fname, 3, m3, n3);
174 return 1;
175 }
176
177 //CheckDimProp
178 if (m2 * n2 != n3)
179 {
180 Scierror(999, _("%s: Wrong size for input arguments: Incompatible sizes.\n"), fname);
181 return 1;
182 }
183
184 //CheckDimProp
185 if (m1 * n1 != m3)
186 {
187 Scierror(999, _("%s: Wrong size for input arguments: Incompatible sizes.\n"), fname);
188 return 1;
189 }
190
191 if (m3 * n3 == 0)
192 {
193 AssignOutputVariable(pvApiCtx, 1) = 0;
194 ReturnArguments(pvApiCtx);
195 return 0;
196 }
197
198 if (get_optional_double_arg(pvApiCtx, fname, 5, "arfact", &arfact, 1, opts) == 0)
199 {
200 return 0;
201 }
202 if (get_rect_arg(pvApiCtx, fname, 6, opts, &rect) == 0)
203 {
204 return 0;
205 }
206 if (get_strf_arg(pvApiCtx, fname, 7, opts, &strf) == 0)
207 {
208 return 0;
209 }
210 freeStrf = !isDefStrf(strf);
211
212 getOrCreateDefaultSubwin();
213
214 if (isDefStrf(strf))
215 {
216 strcpy(strfl, DEFSTRFN);
217 strf = strfl;
218 if (!isDefRect(rect))
219 {
220 strf[1] = '5';
221 }
222 }
223
224 (*func)((l1), (l2), (l3), (l4), &m3, &n3, strf, rect, arfact, 4L);
225 if (freeStrf)
226 {
227 freeAllocatedSingleString(strf);
228 }
229 AssignOutputVariable(pvApiCtx, 1) = 0;
230 ReturnArguments(pvApiCtx);
231 return 0;
232 }
233 /*--------------------------------------------------------------------------*/
234