00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <string.h>
00010 #include "GetCommandArg.h"
00011 #include "GetProperty.h"
00012 #include "DefaultCommandArg.h"
00013 #include "CurrentObjectsManagement.h"
00014
00015 static char logFlagsCpy[3] ;
00016
00017
00018
00019
00020 int get_style_arg(char *fname,int pos, int n1,rhs_opts opts[], int ** style )
00021 {
00022 int m,n,l,first_opt=FirstOpt(),kopt,un=1,ix,i,l1;
00023
00024 Nbvars = Max(Nbvars,Rhs);
00025
00026
00027 if ( pos < first_opt )
00028 {
00029 if (VarType(pos))
00030 {
00031 GetRhsVar(pos, "i", &m, &n, &l);
00032 if (m * n < n1)
00033 {
00034 Scierror(999,"%s: style is too small (%d < %d)\r\n",fname,m*n,n1);
00035 return 0;
00036 }
00037 if ( n1 == 1 && m * n == 1 )
00038 {
00039 ix = 2;
00040 CreateVar(Nbvars+1,"i",&un,&ix,&l1);
00041 *istk(l1)=*istk(l);
00042 *istk(l1+1)=1;
00043 l=l1;
00044 }
00045 *style = istk(l);
00046 }
00047 else
00048 {
00049 ix = Max(n1,2);
00050 CreateVar(Nbvars+1,"i",&un,&ix,&l);
00051 for ( i = 0 ; i < n1 ; ++i )
00052 {
00053 *istk(l + i) = i+1 ;
00054 }
00055 if (n1 == 1)
00056 {
00057 *istk(l + 1) = 1 ;
00058 }
00059 *style = istk(l);
00060 }
00061 }
00062 else if ((kopt=FindOpt("style",opts)))
00063 {
00064 GetRhsVar(kopt, "i", &m, &n, &l);
00065 if (m * n < n1)
00066 {
00067 Scierror(999,"%s: style is too small (%d < %d)\r\n",fname,m*n,n1);
00068 return 0;
00069 }
00070 if (n1==1&&m*n==1)
00071 {
00072 ix = 2;
00073 CreateVar(Nbvars+1,"i",&un,&ix,&l1);
00074 *istk(l1)=*istk(l);
00075 *istk(l1+1)=1;
00076 l=l1;
00077 }
00078 *style = istk(l);
00079 }
00080 else
00081 {
00082 ix = Max(n1,2);
00083 CreateVar(Nbvars+1,"i",&un,&ix,&l);
00084 for (i = 0 ; i < n1 ; ++i)
00085 {
00086 *istk(l + i) = i+1;
00087 }
00088 if (n1 == 1)
00089 {
00090 *istk(l +1) = 1;
00091 }
00092 *style = istk(l);
00093 }
00094 return 1;
00095 }
00096
00097
00098
00099 int get_rect_arg(char *fname,int pos,rhs_opts opts[], double ** rect )
00100 {
00101 int m,n,l,first_opt=FirstOpt(),kopt,i;
00102
00103 if (pos < first_opt)
00104 {
00105 if (VarType(pos)) {
00106 GetRhsVar(pos, "d", &m, &n, &l);
00107 if (m * n != 4) {
00108 Scierror(999,"%s: rect has wrong size (%d), 4 expected \r\n",fname,m*n);
00109 return 0;
00110 }
00111 *rect = stk(l);
00112
00113 for(i=0;i<4;i++)
00114 if(finite((*rect)[i]) == 0){
00115 Scierror(999,"%s: rect has Nan or Inf values, 4 finite values expected \r\n",fname,m*n);
00116 return 0;
00117 }
00118 }
00119 else
00120 {
00122 double zeros[4] = { 0.0, 0.0, 0.0, 0.0 } ;
00123 setDefRect( zeros ) ;
00124 *rect = getDefRect() ;
00125 }
00126 }
00127 else if ((kopt=FindOpt("rect",opts))) {
00128 GetRhsVar(kopt, "d", &m, &n, &l);
00129 if (m * n != 4) {
00130 Scierror(999,"%s: rect has wrong size (%d), 4 expected \r\n",fname,m*n);
00131 return 0;
00132 }
00133 *rect = stk(l);
00134
00135 for(i=0;i<4;i++)
00136 if(finite((*rect)[i]) == 0){
00137 Scierror(999,"%s: rect has Nan or Inf values, 4 finite values expected \r\n",fname,m*n);
00138 return 0;
00139 }
00140 }
00141 else
00142 {
00144 double zeros[4] = { 0.0, 0.0, 0.0, 0.0 } ;
00145 setDefRect( zeros ) ;
00146 *rect = getDefRect() ;
00147 }
00148
00149 return 1;
00150 }
00151
00152 int get_strf_arg(char *fname,int pos,rhs_opts opts[], char ** strf )
00153 {
00154 int m,n,l,first_opt=FirstOpt(),kopt;
00155
00156 if (pos < first_opt)
00157 {
00158 if (VarType(pos))
00159 {
00160 GetRhsVar(pos, "c", &m, &n, &l);
00161 if ( m * n != 3 )
00162 {
00163 Scierror(999,"%s: strf has wrong size (%d), 3 expected \r\n",fname,m*n);
00164 return 0;
00165 }
00166 *strf = cstk(l);
00167 }
00168 else
00169 {
00170
00171 reinitDefStrf() ;
00172 *strf = getDefStrf() ;
00173 }
00174 }
00175 else if ((kopt=FindOpt("strf",opts)))
00176 {
00177 GetRhsVar(kopt, "c", &m, &n, &l);
00178 if (m * n != 3)
00179 {
00180 Scierror(999,"%s: strf has wrong size (%d), 3 expected \r\n",fname,m*n);
00181 return 0;
00182 }
00183 *strf = cstk(l);
00184 }
00185 else
00186 {
00187
00188
00189 reinitDefStrfN() ;
00190 *strf = getDefStrf() ;
00191
00192 }
00193 return 1;
00194 }
00195
00196
00197 int get_legend_arg(char *fname,int pos,rhs_opts opts[], char ** legend )
00198 {
00199 int m,n,l,first_opt=FirstOpt(),kopt;
00200
00201 if (pos < first_opt)
00202 {
00203 if (VarType(pos)) {
00204 GetRhsVar(pos, "c", &m, &n, &l);
00205 *legend = cstk(l);
00206 }
00207 else
00208 {
00209 *legend = getDefLegend() ;
00210 }
00211 }
00212 else if ((kopt=FindOpt("leg",opts))) {
00213 GetRhsVar(kopt, "c", &m, &n, &l);
00214 *legend = cstk(l);
00215 }
00216 else
00217 {
00218 *legend = getDefLegend() ;
00219 }
00220 return 1;
00221 }
00222
00226 int get_labels_arg(char *fname,int pos,rhs_opts opts[], char ** labels )
00227 {
00228 int m,n,l,first_opt=FirstOpt(),kopt;
00229
00230 if (pos < first_opt)
00231 {
00232 if (VarType(pos)) {
00233 GetRhsVar(pos, "c", &m, &n, &l);
00234 *labels = cstk(l);
00235 }
00236 else
00237 {
00238
00239
00240
00241 sciPointObj * pSubWin = sciGetCurrentSubWin() ;
00242 if ( sciGetLegendDefined( pSubWin ) )
00243 {
00244 *labels = NULL ;
00245 }
00246 else
00247 {
00248 *labels = getDefLegend() ;
00249 }
00250 }
00251 }
00252 else if ((kopt=FindOpt("leg",opts)))
00253 {
00254 GetRhsVar(kopt, "c", &m, &n, &l);
00255 *labels = cstk(l);
00256 }
00257 else
00258 {
00259
00260
00261
00262 sciPointObj * pSubWin = sciGetCurrentSubWin() ;
00263 if ( sciGetLegendDefined( pSubWin ) )
00264 {
00265 *labels = NULL ;
00266 }
00267 else
00268 {
00269 *labels = getDefLegend() ;
00270 }
00271 }
00272 return 1;
00273 }
00274
00275
00276 int get_nax_arg(int pos,rhs_opts opts[], int ** nax, BOOL * flagNax )
00277 {
00278 int i,m,n,l,first_opt=FirstOpt(),kopt;
00279
00280 if (pos < first_opt)
00281 {
00282 if (VarType(pos))
00283 {
00284 GetRhsVar(pos, "i", &m, &n, &l);
00285 CheckLength(pos,m*n,4);
00286 for (i = 0 ; i < 4; ++i)
00287 {
00288 *istk(l+i) = Max((integer) *istk(l+i),0);
00289 }
00290 *nax=istk(l);
00291 *flagNax = TRUE;
00292 }
00293 else
00294 {
00295 *nax = getDefNax() ;
00296 *flagNax = FALSE;
00297 }
00298 }
00299 else if ((kopt=FindOpt("nax",opts)))
00300 {
00301 GetRhsVar(kopt, "i", &m, &n, &l);
00302 CheckLength(kopt,m*n,4);
00303 for (i = 0 ; i < 4; ++i)
00304 {
00305 *istk(l+i) = Max((integer) *istk(l+i),0);
00306 }
00307 *nax=istk(l);
00308 *flagNax = TRUE;
00309 }
00310 else
00311 {
00312 *nax = getDefNax() ;
00313 *flagNax = FALSE;
00314 }
00315 return 1;
00316 }
00317
00318
00319
00320 int get_zminmax_arg(char *fname,int pos,rhs_opts opts[], double ** zminmax )
00321 {
00322 int m,n,l,first_opt=FirstOpt(),kopt;
00323
00324 if (pos < first_opt)
00325 {
00326 if (VarType(pos)) {
00327 GetRhsVar(pos, "d", &m, &n, &l);
00328 if (m * n != 2) {
00329 Scierror(999,"%s: zminmax has wrong size (%d), 2 expected \r\n",fname,m*n);
00330 return 0;
00331 }
00332 *zminmax = stk(l);
00333 }
00334 else
00335 {
00337 double zeros[2] = { 0.0, 0.0 } ;
00338 setDefZminMax( zeros ) ;
00339 *zminmax = getDefZminMax() ;
00340 }
00341 }
00342 else if ((kopt=FindOpt("zminmax",opts))) {
00343 GetRhsVar(kopt, "d", &m, &n, &l);
00344 if (m * n != 2) {
00345 Scierror(999,"%s: zminmax has wrong size (%d), 2 expected \r\n",fname,m*n);
00346 return 0;
00347 }
00348 *zminmax = stk(l);
00349 }
00350 else
00351 {
00353 double zeros[2] = { 0.0, 0.0 } ;
00354 setDefZminMax( zeros ) ;
00355 *zminmax = getDefZminMax() ;
00356 }
00357
00358 return 1;
00359 }
00360
00361
00362 int get_colminmax_arg(char *fname,int pos,rhs_opts opts[], int ** colminmax )
00363 {
00364 int m,n,l,first_opt=FirstOpt(),kopt;
00365
00366 if (pos < first_opt)
00367 {
00368 if (VarType(pos))
00369 {
00370 GetRhsVar(pos, "i", &m, &n, &l);
00371 CheckLength(pos,m*n,2);
00372 *colminmax=istk(l);
00373 }
00374 else
00375 {
00377 int zeros[2] = { 0, 0 } ;
00378 setDefColMinMax( zeros ) ;
00379 *colminmax = getDefColMinMax() ;
00380 }
00381 }
00382 else if ((kopt=FindOpt("colminmax",opts)))
00383 {
00384 GetRhsVar(kopt, "i", &m, &n, &l);
00385 CheckLength(kopt,m*n,2);
00386 *colminmax=istk(l);
00387 }
00388 else
00389 {
00391 int zeros[2] = { 0, 0 } ;
00392 setDefColMinMax( zeros ) ;
00393 *colminmax = getDefColMinMax() ;
00394 }
00395 return 1;
00396 }
00397
00398
00399 int get_colout_arg(char *fname,int pos,rhs_opts opts[], int ** colout )
00400 {
00401 int m,n,l,first_opt=FirstOpt(),kopt;
00402
00403 if (pos < first_opt)
00404 {
00405 if (VarType(pos))
00406 {
00407 GetRhsVar(pos, "i", &m, &n, &l);
00408 CheckLength(pos,m*n,2);
00409 *colout = istk(l);
00410 }
00411 else
00412 {
00414 int newDefCO[2] = { -1, -1 } ;
00415 setDefColOut( newDefCO ) ;
00416 *colout = getDefColOut() ;
00417 }
00418 }
00419 else if ((kopt=FindOpt("colout",opts)))
00420 {
00421 GetRhsVar(kopt, "i", &m, &n, &l);
00422 CheckLength(kopt,m*n,2);
00423 *colout=istk(l);
00424 }
00425 else
00426 {
00428 int newDefCO[2] = { -1, -1 } ;
00429 setDefColOut( newDefCO ) ;
00430 *colout = getDefColOut() ;
00431 }
00432 return 1;
00433 }
00434
00435 int get_with_mesh_arg(char *fname,int pos,rhs_opts opts[], BOOL * withMesh)
00436 {
00437 int m,n,l,first_opt=FirstOpt(),kopt;
00438
00439 if (pos < first_opt)
00440 {
00441 if (VarType(pos))
00442 {
00443 GetRhsVar(pos, "b", &m, &n, &l);
00444 CheckLength(pos,m*n,1);
00445 *withMesh = *(istk(l));
00446 }
00447 else
00448 {
00450 setDefWithMesh( FALSE );
00451 *withMesh = getDefWithMesh() ;
00452 }
00453 }
00454 else if ((kopt=FindOpt("mesh",opts)))
00455 {
00456 GetRhsVar(kopt, "b", &m, &n, &l);
00457 CheckLength(kopt,m*n,1);
00458 *withMesh = *(istk(l));
00459 }
00460 else
00461 {
00463 setDefWithMesh( FALSE );
00464 *withMesh = getDefWithMesh() ;
00465 }
00466 return 1;
00467 }
00468
00469
00470 int get_logflags_arg(char *fname,int pos,rhs_opts opts[], char ** logFlags )
00471 {
00472 int m,n,l,first_opt=FirstOpt(),kopt;
00473
00474 if (pos < first_opt)
00475 {
00476 if (VarType(pos))
00477 {
00478 GetRhsVar(pos, "c", &m, &n, &l);
00479 if ((m * n != 2)&&(m * n != 3))
00480 {
00481 Scierror(999,"%s: logflag has wrong size (%d), expected 2 or 3\r\n",fname,m*n);
00482 return 0;
00483 }
00484 if (m * n == 2)
00485 {
00486 if ((*cstk(l)!='l'&&*cstk(l)!='n')||(*cstk(l+1)!='l'&&*cstk(l+1)!='n'))
00487 {
00488 Err=pos;
00489 Error(116);
00490 return 0;
00491 }
00492 logFlagsCpy[0]='g';
00493 logFlagsCpy[1]=*cstk(l);
00494 logFlagsCpy[2]=*cstk(l+1) ;
00495 *logFlags = logFlagsCpy ;
00496 }
00497 else
00498 {
00499 if (((*cstk(l)!='g')&&(*cstk(l)!='e')&&(*cstk(l)!='o')) ||
00500 (*cstk(l+1)!='l'&&*cstk(l+1)!='n') ||
00501 (*cstk(l+2)!='l'&&*cstk(l+2)!='n'))
00502 {
00503 Err=pos;
00504 Error(116);
00505 return 0;
00506 }
00507 *logFlags = cstk(l) ;
00508 }
00509
00510 }
00511 else
00512 {
00513 *logFlags = getDefLogFlags() ;
00514 }
00515 }
00516 else if ((kopt=FindOpt("logflag",opts)))
00517 {
00518 GetRhsVar(kopt,"c", &m, &n, &l);
00519 if ((m * n != 2)&&(m * n != 3))
00520 {
00521 Scierror(999,"%s: logflag has wrong size (%d), expected 2 or 3\r\n",fname,m * n);
00522 return 0;
00523 }
00524 if (m * n == 2)
00525 {
00526 if ((*cstk(l)!='l'&&*cstk(l)!='n')||(*cstk(l+1)!='l'&&*cstk(l+1)!='n'))
00527 {
00528 Err=kopt;
00529 Error(116);
00530 return 0;
00531 }
00532 logFlagsCpy[0]='g';
00533 logFlagsCpy[1]=*cstk(l);
00534 logFlagsCpy[2]=*cstk(l+1) ;
00535 *logFlags = logFlagsCpy ;
00536 }
00537 else
00538 {
00539 if (((*cstk(l)!='g')&&(*cstk(l)!='e')&&(*cstk(l)!='o')) ||
00540 (*cstk(l+1)!='l'&&*cstk(l+1)!='n') ||
00541 (*cstk(l+2)!='l'&&*cstk(l+2)!='n'))
00542 {
00543 Err=kopt;
00544 Error(116);
00545 return 0;
00546 }
00547
00548 *logFlags = cstk(l) ;
00549 }
00550 }
00551 else
00552 {
00553 *logFlags = getDefLogFlags() ;
00554 }
00555 return 1;
00556 }
00557
00558 int get_optional_double_arg( char * fname,
00559 int pos ,
00560 char * name ,
00561 double ** value,
00562 int sz ,
00563 rhs_opts opts[] )
00564 {
00565 int m,n,l,first_opt=FirstOpt(),kopt;
00566
00567 if (pos < first_opt)
00568 {
00569 if (VarType(pos)) {
00570 GetRhsVar(pos, "d", &m, &n, &l);
00571 CheckLength(pos,m*n,sz)
00572 *value = stk(l);
00573 }
00574 }
00575 else if ((kopt=FindOpt(name,opts))) {
00576 GetRhsVar(kopt,"d", &m, &n, &l);
00577 CheckLength(kopt,m*n,sz)
00578 *value = stk(l);
00579 }
00580 return 1;
00581 }
00582
00583 int get_optional_int_arg( char * fname,
00584 int pos ,
00585 char * name ,
00586 int ** value,
00587 int sz ,
00588 rhs_opts opts[] )
00589 {
00590 int m,n,l,first_opt=FirstOpt(),kopt;
00591
00592 if (pos < first_opt)
00593 {
00594 if (VarType(pos)) {
00595 GetRhsVar(pos, "i", &m, &n, &l);
00596 CheckLength(pos,m*n,sz)
00597 *value = istk(l);
00598 }
00599 }
00600 else if ((kopt=FindOpt(name,opts))) {
00601 GetRhsVar(kopt,"i", &m, &n, &l);
00602 CheckLength(kopt,m*n,sz)
00603 *value = istk(l);
00604 }
00605 return 1;
00606 }
00607