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
6 * This file must be used under the terms of the CeCILL.
7 * This source file is licensed as described in the file COPYING, which
8 * you should have received as part of this distribution. The terms
9 * are also available at
10 * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
14 /*------------------------------------------------------------------------*/
15 /* file: sci_plot2d1.c */
16 /* desc : interface for plot2d1, plot2d2, plot2d3 and plot2d4 routines */
17 /*------------------------------------------------------------------------*/
19 #include "gw_graphics.h"
20 #include "api_scilab.h"
21 #include "GetCommandArg.h"
22 #include "DefaultCommandArg.h"
24 #include "localization.h"
28 /*--------------------------------------------------------------------------*/
29 int sci_plot2d1_1 (char *fname, unsigned long fname_len)
31 return sci_plot2d1_G("plot2d1", 1, fname_len); /* NG */
33 /*--------------------------------------------------------------------------*/
34 int sci_plot2d1_2 (char *fname, unsigned long fname_len)
36 return sci_plot2d1_G("plot2d2", 2, fname_len); /* NG */
38 /*--------------------------------------------------------------------------*/
39 int sci_plot2d1_3 (char *fname, unsigned long fname_len)
41 return sci_plot2d1_G("plot2d3", 3, fname_len); /* NG */
43 /*--------------------------------------------------------------------------*/
44 int sci_plot2d1_4 (char *fname, unsigned long fname_len)
46 return sci_plot2d1_G("plot2d4", 4, fname_len); /* NG */
48 /*--------------------------------------------------------------------------*/
49 int sci_plot2d1_G(char * fname, int ptype, unsigned long fname_len)
59 int *frame = &frame_def;
61 int *axes = &axes_def;
62 int iskip = 0, test = 0;
63 int m1 = 0, n1 = 0, m2 = 0, n2 = 0, i = 0, j = 0;
65 static rhs_opts opts[] =
67 { -1, "axesflag", -1, 0, 0, NULL},
68 { -1, "frameflag", -1, 0, 0, NULL},
69 { -1, "leg", -1, 0, 0, NULL},
70 { -1, "logflag", -1, 0, 0, NULL},
71 { -1, "nax", -1, 0, 0, NULL},
72 { -1, "rect", -1, 0, 0, NULL},
73 { -1, "strf", -1, 0, 0, NULL},
74 { -1, "style", -1, 0, 0, NULL},
75 { -1, NULL, -1, 0, 0, NULL}
83 char * legend = NULL ;
84 char * logFlags = NULL ;
86 if (nbInputArgument(pvApiCtx) <= 0)
88 /* lauch the default routines depending on the name of the calling function */
89 sci_demo(fname, fname_len);
92 CheckInputArgument(pvApiCtx, 1, 9); /* to allow plot2dxx(y) */
96 if (getOptionals(pvApiCtx, fname, opts) == 0)
98 ReturnArguments(pvApiCtx);
102 if (checkInputArgumentType(pvApiCtx, 1, sci_strings))
105 GetLogflags(pvApiCtx, fname, 1, opts, &logFlags);
109 /* added to support plot2dxx([logflags],y) */
110 if (nbInputArgument(pvApiCtx) == 1 + iskip)
112 if (FirstOpt() <= nbInputArgument(pvApiCtx))
114 Scierror(999, _("%s: Misplaced optional argument: #%d must be at position %d.\n"), fname, 1, 3 + iskip);
118 sciErr = getVarAddressFromPosition(pvApiCtx, 1 + iskip, &piAddrl2);
121 printError(&sciErr, 0);
125 // Retrieve a matrix of double at position 1 + iskip.
126 sciErr = getMatrixOfDouble(pvApiCtx, piAddrl2, &m2, &n2, &l2);
129 printError(&sciErr, 0);
130 Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 1 + iskip);
134 sciErr = allocMatrixOfDouble(pvApiCtx, 2 + iskip, m2, n2, &l1);
137 printError(&sciErr, 0);
138 Scierror(999, _("%s: Memory allocation error.\n"), fname);
142 if (m2 == 1 && n2 > 1)
151 for (i = 0; i < m2 ; ++i)
153 for (j = 0 ; j < n2 ; ++j)
155 *(l1 + i + m2 * j) = (double) i + 1;
161 if (nbInputArgument(pvApiCtx) >= 2 + iskip)
163 if (FirstOpt() < 3 + iskip)
165 Scierror(999, _("%s: Misplaced optional argument: #%d must be at position %d.\n"),
166 fname, 1, 3 + iskip);
172 sciErr = getVarAddressFromPosition(pvApiCtx, 1 + iskip, &piAddrl1);
175 printError(&sciErr, 0);
179 // Retrieve a matrix of double at position 1 + iskip.
180 sciErr = getMatrixOfDouble(pvApiCtx, piAddrl1, &m1, &n1, &l1);
183 printError(&sciErr, 0);
184 Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 1 + iskip);
190 if (logFlags[0] == 'e')
198 sciErr = getVarAddressFromPosition(pvApiCtx, 2 + iskip, &piAddrl2);
201 printError(&sciErr, 0);
205 // Retrieve a matrix of double at position 2 + iskip.
206 sciErr = getMatrixOfDouble(pvApiCtx, piAddrl2, &m2, &n2, &l2);
209 printError(&sciErr, 0);
210 Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 2 + iskip);
214 /* if (m2 * n2 == 0) { m1 = 0; n1 = 0;} */
216 test = (m1 * n1 == 0) /* x = [] */
217 /* x,y vectors of same length */
218 || ((m1 == 1 || n1 == 1) && (m2 == 1 || n2 == 1) && (m1 * n1 == m2 * n2))
219 || ((m1 == m2) && (n1 == n2)) /* size(x) == size(y) */
220 /* x vector size(y)==[size(x),.] */
221 || ((m1 == 1 && n1 == m2) || (n1 == 1 && m1 == m2));
226 Scierror(999, _("%s: Wrong size for input arguments: Incompatible sizes.\n"), fname);
234 sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, m2, n2, <);
237 printError(&sciErr, 0);
238 Scierror(999, _("%s: Memory allocation error.\n"), fname);
242 if (m2 == 1 && n2 > 1)
247 for (i = 0; i < m2 ; ++i)
249 for (j = 0 ; j < n2 ; ++j)
251 *(lt + i + m2 * j) = (double) i + 1;
258 else if ((m1 == 1 || n1 == 1) && (m2 != 1 && n2 != 1))
260 /* a single x vector for mutiple columns for y */
261 sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, m2, n2, <);
264 printError(&sciErr, 0);
265 Scierror(999, _("%s: Memory allocation error.\n"), fname);
269 for (i = 0; i < m2 ; ++i)
271 for (j = 0 ; j < n2 ; ++j)
273 *(lt + i + m2 * j) = l1[i];
280 else if ((m1 == 1 && n1 == 1) && (n2 != 1))
282 /* a single y row vector for a single x */
283 sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, m1, n2, <);
286 printError(&sciErr, 0);
287 Scierror(999, _("%s: Memory allocation error.\n"), fname);
291 for (j = 0 ; j < n2 ; ++j)
300 if (m2 == 1 && n2 > 1)
305 if (m1 == 1 && n1 > 1)
313 sciGetStyle(pvApiCtx, fname, 3 + iskip, n1, opts, &style);
314 GetStrf(pvApiCtx, fname, 4 + iskip, opts, &strf);
315 GetLegend(pvApiCtx, fname, 5 + iskip, opts, &legend);
316 GetRect(pvApiCtx, fname, 6 + iskip, opts, &rect);
317 GetNax(pvApiCtx, 7 + iskip, opts, &nax, &flagNax);
320 GetLogflags(pvApiCtx, fname, 8, opts, &logFlags);
326 strcpy(strfl, DEFSTRFN);
329 if (!isDefRect(rect))
333 if (!isDefLegend(legend))
337 GetOptionalIntArg(pvApiCtx, fname, 9, "frameflag", &frame, 1, opts);
338 if (frame != &frame_def)
340 strfl[1] = (char)(*frame + 48);
342 GetOptionalIntArg(pvApiCtx, fname, 9, "axesflag", &axes, 1, opts);
343 if (axes != &axes_def)
345 strfl[2] = (char)(*axes + 48);
354 Objplot2d (ptype, logFlags, (l1), (l2), &n1, &m1, style, strf, legend, rect, nax, flagNax);
356 // Allocated by sciGetStyle (get_style_arg function in GetCommandArg.c)
359 AssignOutputVariable(pvApiCtx, 1) = 0;
360 ReturnArguments(pvApiCtx);
363 /*--------------------------------------------------------------------------*/