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-en.txt
14 /*------------------------------------------------------------------------*/
15 /* file: sci_plot2d1.c */
16 /* desc : interface for plot2d1, plot2d2, plot2d3 and plot2d4 routines */
17 /*------------------------------------------------------------------------*/
19 #include "gw_graphics.h"
21 #include "GetCommandArg.h"
22 #include "DefaultCommandArg.h"
24 #include "localization.h"
26 /*--------------------------------------------------------------------------*/
27 int sci_plot2d1_1 (char *fname,unsigned long fname_len)
29 return sci_plot2d1_G("plot2d1",1,fname_len);/* NG */
31 /*--------------------------------------------------------------------------*/
32 int sci_plot2d1_2 (char *fname,unsigned long fname_len)
34 return sci_plot2d1_G("plot2d2",2,fname_len); /* NG */
36 /*--------------------------------------------------------------------------*/
37 int sci_plot2d1_3 (char *fname,unsigned long fname_len)
39 return sci_plot2d1_G("plot2d3",3,fname_len);/* NG */
41 /*--------------------------------------------------------------------------*/
42 int sci_plot2d1_4 (char *fname,unsigned long fname_len)
44 return sci_plot2d1_G("plot2d4",4,fname_len);/* NG */
46 /*--------------------------------------------------------------------------*/
47 int sci_plot2d1_G( char * fname, int ptype, unsigned long fname_len )
50 int *frame=&frame_def;
53 int iskip = 0, test = 0;
54 int m1 = 0,n1 = 0,l1 = 0, m2 = 0, n2 = 0, l2 = 0, lt = 0, i = 0, j = 0;
56 static rhs_opts opts[]= { {-1,"axesflag","?",0,0,0},
57 {-1,"frameflag","?",0,0,0},
59 {-1,"logflag","?",0,0,0},
61 {-1,"rect","?",0,0,0},
62 {-1,"strf","?",0,0,0},
63 {-1,"style","?",0,0,0},
67 double * rect = NULL ;
69 BOOL flagNax = FALSE ;
71 char * legend = NULL ;
72 char * logFlags = NULL ;
76 /* lauch the default routines depending on the name of the calling funtion */
77 sci_demo(fname, fname_len);
80 CheckRhs(1,9); /* to allow plot2dxx(y) */
84 if ( get_optionals(fname,opts) == 0)
90 if (GetType(1)==sci_strings) {
92 GetLogflags(fname,1,opts,&logFlags);
96 /* added to support plot2dxx([logflags],y) */
97 if ( Rhs == 1 + iskip )
99 if ( FirstOpt() <= Rhs)
101 Scierror(999,_("%s: Misplaced optional argument: #%d must be at position %d.\n"),fname,1, 3+iskip);
105 GetRhsVar(1+iskip,MATRIX_OF_DOUBLE_DATATYPE, &m2, &n2, &l2);
106 CreateVar(2+iskip,MATRIX_OF_DOUBLE_DATATYPE, &m2, &n2, &l1);
107 if (m2 == 1 && n2 > 1) { m2 = n2; n2 = 1;}
109 for (i = 0; i < m2 ; ++i)
110 for (j = 0 ; j < n2 ; ++j)
111 *stk( l1 + i + m2*j) = (double) i+1;
117 if ( FirstOpt() < 3+iskip)
119 Scierror(999,_("%s: Misplaced optional argument: #%d must be at position %d.\n"),
126 GetRhsVar(1+iskip,MATRIX_OF_DOUBLE_DATATYPE, &m1, &n1, &l1);
129 if (logFlags[0]=='e')
137 GetRhsVar(2+iskip,MATRIX_OF_DOUBLE_DATATYPE, &m2, &n2, &l2);
138 /* if (m2 * n2 == 0) { m1 = 0; n1 = 0;} */
140 test = (m1*n1 == 0) /* x = [] */
141 /* x,y vectors of same length */
142 || ((m1 == 1 || n1 == 1) && (m2 == 1 || n2 ==1) && (m1*n1 == m2*n2))
143 || ((m1 == m2) && (n1 == n2)) /* size(x) == size(y) */
144 /* x vector size(y)==[size(x),.] */
145 || ((m1 == 1 && n1 == m2) || (n1 == 1 && m1 == m2));
147 CheckDimProp(1+iskip,2+iskip,!test);
150 { /* default x=1:n */
151 CreateVar(Rhs+1,MATRIX_OF_DOUBLE_DATATYPE, &m2, &n2, <);
152 if (m2 == 1 && n2 > 1) { m2 = n2; n2 = 1;}
153 for (i = 0; i < m2 ; ++i)
155 for (j = 0 ; j < n2 ; ++j)
157 *stk( lt + i + m2*j) = (double) i+1;
164 else if ((m1 == 1 || n1 == 1) && (m2 != 1 && n2 != 1) ) {
165 /* a single x vector for mutiple columns for y */
166 CreateVar(Rhs+1,MATRIX_OF_DOUBLE_DATATYPE, &m2, &n2, <);
167 for (i = 0; i < m2 ; ++i)
169 for (j = 0 ; j < n2 ; ++j)
171 *stk( lt + i + m2*j) = *stk(l1 +i);
178 else if ((m1 == 1 && n1 == 1) && (n2 != 1) ) {
179 /* a single y row vector for a single x */
180 CreateVar(Rhs+1,MATRIX_OF_DOUBLE_DATATYPE, &m1, &n2, <);
181 for (j = 0 ; j < n2 ; ++j)
183 *stk( lt + j ) = *stk(l1);
189 if (m2 == 1 && n2 > 1) { m2 = n2; n2 = 1;}
190 if (m1 == 1 && n1 > 1) { m1 = n1; n1 = 1;}
194 sciGetStyle(fname,3+iskip,n1,opts,&style);
195 GetStrf(fname,4+iskip,opts,&strf);
196 GetLegend(fname,5+iskip,opts,&legend);
197 GetRect(fname,6+iskip,opts,&rect);
198 GetNax(7+iskip,opts,&nax,&flagNax);
199 if (iskip==0) GetLogflags(fname,8,opts,&logFlags);
201 if ( isDefStrf( strf ) ) {
202 strcpy(strfl,DEFSTRFN);
205 if ( !isDefRect( rect ) )
209 if ( !isDefLegend( legend ) )
213 GetOptionalIntArg(fname,9,"frameflag",&frame,1,opts);
214 if(frame != &frame_def)
216 strfl[1] = (char)(*frame+48);
218 GetOptionalIntArg(fname,9,"axesflag",&axes,1,opts);
219 if(axes != &axes_def)
221 strfl[2] = (char)(*axes+48);
225 if(ptype == 0) { ptype = 1 ; }
227 Objplot2d (ptype,logFlags,stk(l1), stk(l2), &n1, &m1, style, strf,legend,rect, nax, flagNax);
234 /*--------------------------------------------------------------------------*/