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
7 * This file must be used under the terms of the CeCILL.
8 * This source file is licensed as described in the file COPYING, which
9 * you should have received as part of this distribution. The terms
10 * are also available at
11 * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
15 /*------------------------------------------------------------------------*/
16 /* file: sci_champ.c */
17 /* desc : interface for champ (and champ1) routine */
18 /*------------------------------------------------------------------------*/
20 #include "gw_graphics.h"
21 #include "api_scilab.h"
22 #include "GetCommandArg.h"
23 #include "BuildObjects.h"
24 #include "DefaultCommandArg.h"
26 #include "localization.h"
28 /*--------------------------------------------------------------------------*/
29 int sci_champ (char *fname, unsigned long fname_len)
31 return sci_champ_G(fname, C2F(champ), fname_len);
33 /*--------------------------------------------------------------------------*/
34 int sci_champ1 (char *fname, unsigned long fname_len)
36 return sci_champ_G(fname, C2F(champ1), fname_len);
38 /*--------------------------------------------------------------------------*/
39 int sci_champ_G(char *fname,
40 int (*func) (double *, double *, double *, double *, int *, int *, char *, double *, double *, int),
41 unsigned long fname_len)
44 double arfact_def = 1.0;
45 double* arfact = &arfact_def;
46 int m1 = 0, n1 = 0, m2 = 0, n2 = 0, m3 = 0, n3 = 0, m4 = 0, n4 = 0;
47 static rhs_opts opts[] =
49 { -1, "arfact", -1, 0, 0, NULL},
50 { -1, "rect", -1, 0, 0, NULL},
51 { -1, "strf", -1, 0, 0, NULL},
52 { -1, NULL, -1, 0, 0, NULL}
68 CheckInputArgument(pvApiCtx, -1, 7);
69 CheckOutputArgument(pvApiCtx, 0, 1);
71 if (nbInputArgument(pvApiCtx) <= 0)
73 sci_demo(fname, fname_len);
76 else if (nbInputArgument(pvApiCtx) < 4)
78 Scierror(999, _("%s: Wrong number of input arguments: At least %d expected.\n"), fname, 4);
82 if (getOptionals(pvApiCtx, fname, opts) == 0)
89 Scierror(999, _("%s: Misplaced optional argument: #%d must be at position %d.\n"), fname, 1, 5);
93 //get variable address
94 sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1);
97 printError(&sciErr, 0);
101 // Retrieve a matrix of double at position 1.
102 sciErr = getMatrixOfDouble(pvApiCtx, piAddr1, &m1, &n1, &l1);
105 Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 1);
106 printError(&sciErr, 0);
110 //get variable address
111 sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2);
114 printError(&sciErr, 0);
118 // Retrieve a matrix of double at position 2.
119 sciErr = getMatrixOfDouble(pvApiCtx, piAddr2, &m2, &n2, &l2);
122 Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 2);
123 printError(&sciErr, 0);
127 //get variable address
128 sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr3);
131 printError(&sciErr, 0);
135 // Retrieve a matrix of double at position 3.
136 sciErr = getMatrixOfDouble(pvApiCtx, piAddr3, &m3, &n3, &l3);
139 Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 3);
140 printError(&sciErr, 0);
144 //get variable address
145 sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddr4);
148 printError(&sciErr, 0);
152 // Retrieve a matrix of double at position 4.
153 sciErr = getMatrixOfDouble(pvApiCtx, piAddr4, &m4, &n4, &l4);
156 Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 4);
157 printError(&sciErr, 0);
162 if (m3 != m4 || n3 != n4)
164 Scierror(999, _("%s: Wrong size for input argument #%d: %d-by-%d matrix expected.\n"), fname, 3, m3, n3);
171 Scierror(999, _("%s: Wrong size for input arguments: Incompatible sizes.\n"), fname);
178 Scierror(999, _("%s: Wrong size for input arguments: Incompatible sizes.\n"), fname);
184 AssignOutputVariable(pvApiCtx, 1) = 0;
185 ReturnArguments(pvApiCtx);
189 GetOptionalDoubleArg(pvApiCtx, fname, 5, "arfact", &arfact, 1, opts);
190 GetRect(pvApiCtx, fname, 6, opts, &rect);
191 GetStrf(pvApiCtx, fname, 7, opts, &strf);
193 getOrCreateDefaultSubwin();
198 strcpy(strfl, DEFSTRFN);
200 if (!isDefRect(rect))
206 (*func)((l1), (l2), (l3), (l4), &m3, &n3, strf, rect, arfact, 4L);
207 AssignOutputVariable(pvApiCtx, 1) = 0;
208 ReturnArguments(pvApiCtx);
211 /*--------------------------------------------------------------------------*/