stack2.c

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------
00002  *    Graphic library
00003  *    Copyright (C) 1998-2000 Enpc/Inria 
00004  *    jpc@cereve.enpc.fr 
00005  --------------------------------------------------------------------------*/
00006 /*---------------------------------------------------------------------
00007  * Interface Library:   ilib 
00008  *---------------------------------------------------------------------*/
00009 
00010 #include <string.h>
00011 #include <stdio.h>
00012 
00013 
00014 #include "MALLOC.h"
00015 
00016 #include "stack-c.h" 
00017 #include "sciprint.h"
00018 #include "stack2.h"
00019 #include "../../../string/includes/men_Sutils.h" 
00020 
00021 
00022 #ifdef _MSC_VER
00023 #define abs(x) ((x) >= 0 ? (x) : -(x)) /* pour abs  C2F(mvfromto) line 2689 */
00024 #endif
00025 /* Table of constant values */
00026 static integer cx1 = 1;
00027 static integer cx0 = 0;
00028 
00029 static char *Get_Iname __PARAMS((void));
00030 static int C2F(mvfromto) __PARAMS((integer *itopl,integer *));
00031 
00032 static int rhs_opt_find __PARAMS((char *name,rhs_opts opts[]));
00033 static void rhs_opt_print_names __PARAMS((rhs_opts opts[]));
00034 static void intersci_pop();
00035 static int intersci_push();
00036 
00037 /*------------------------------------------------*/
00038 void strcpy_tws(char *str1,char *str2, int len);
00039 int C2F(copyvarfromsciptr)(integer lw, integer n,integer l);
00040 static int intersci_push(void);
00041 static void intersci_pop(void);
00042 /*------------------------------------------------
00043  * checkrhs: checks right hand side arguments 
00044  *-----------------------------------------------*/
00045 
00046 int C2F(checkrhs)(char *fname, integer *iMin, integer *iMax, unsigned long  fname_len)
00047 {
00048   /*
00049    * store the name in recu array, fname can be a non null terminated char array  
00050    * Get_Iname() can be used in other function to get the interface name 
00051    */
00052 
00053   C2F(cvname)(&C2F(recu).ids[(C2F(recu).pt + 1) * nsiz - nsiz], fname, &cx0, fname_len);
00054   
00055   if ( Rhs < *iMin || Rhs > *iMax) 
00056     {
00057       Scierror(77,"%s: wrong number of rhs arguments\r\n",get_fname(fname,fname_len));
00058       return FALSE_; 
00059     }
00060   return TRUE_;
00061 } 
00062 
00063 /*------------------------------------------------
00064  * checkrhs: checks left hand side arguments 
00065  *-----------------------------------------------*/
00066 
00067 int C2F(checklhs)(char *fname, integer *iMin, integer *iMax, unsigned long  fname_len)
00068 {
00069   if ( Lhs < *iMin || Lhs > *iMax) 
00070     {
00071       Scierror(78,"%s: wrong number of lhs arguments\r\n",get_fname(fname,fname_len));
00072       return FALSE_;
00073     }
00074   return TRUE_;
00075 } 
00076 
00077 /*---------------------------------------------------------------------
00078  * isopt:
00079  * returns the status of the variable number k
00080  * if its an optional variable f(x=...) 
00081  * returns .true. and variable name in namex
00082  * namex must have a size of nlgh + 1
00083  *---------------------------------------------------------------------*/
00084 
00085 int C2F(isopt)(integer *k, char *namex,unsigned long name_len)
00086 {
00087   integer i1 =  *k + Top - Rhs;
00088   if ( C2F(isoptlw)(&Top, &i1, namex, name_len) == FALSE_) return FALSE_ ;
00089   /* add a '\0' at the end of the string removing trailing blanks */
00090   for ( i1 = nlgh-1 ; i1 >=0 ; i1--) { if ( namex[i1] != ' ') break ;} 
00091   namex[i1+1]='\0';
00092   return TRUE_;
00093 } 
00094 
00095 /*--------------------------------------- 
00096  * isoptlw :
00097  * returns the status of the variable at position lw in the stack 
00098  * if its an optional variable f(x=...) 
00099  * returns .true. and variable name in namex
00100  *--------------------------------------- */
00101 
00102 int C2F(isoptlw)(integer *topk,integer  *lw, char *namex, unsigned long name_len)
00103 {
00104   if (*Infstk(*lw ) != 1) return FALSE_ ;
00105   C2F(cvname)(&C2F(vstk).idstk[(*lw) * nsiz - nsiz], namex, &cx1, name_len);
00106   return TRUE_;
00107 }
00108 
00109 /*--------------------------------------- 
00110  * firstopt :
00111  * return the position of the first optionnal argument 
00112  * given as xx=val in the calling sequence. 
00113  * If no such argument it returns Rhs+1.
00114  *--------------------------------------- */
00115 integer C2F(firstopt)()
00116 
00117 {
00118   integer k;
00119   for (k = 1; k <= Rhs ; ++k) 
00120     if (*Infstk(k + Top - Rhs )==1)
00121       return k;
00122   return(Rhs+1);
00123 }
00124 
00125 
00126 /*--------------------------------------- 
00127  * findopt :
00128  * checks if option str has been passed. 
00129  * If yes returns the position of the variable 
00130  * If no  returns 0
00131  *--------------------------------------- */
00132 
00133 int C2F(findopt)(char * str,rhs_opts opts[])
00134 {
00135   int i, pos;
00136 
00137   pos = 0;
00138   i = rhs_opt_find(str,opts);
00139   if ( i>=0 ) 
00140     if (opts[i].position>0) 
00141       pos = opts[i].position;
00142   
00143   return(pos);
00144 }
00145 
00146 
00147 /*--------------------------------------- 
00148  * numopt :
00149  *  returns the number of optional variables 
00150  *  given as xx=val in the caling sequence 
00151  *  top must have a correct value when using this function 
00152  *--------------------------------------- */
00153 
00154 integer C2F(numopt)()
00155 {
00156   integer k, ret=0;
00157   for (k = 1; k <= Rhs ; ++k) 
00158     if ( *Infstk(k + Top - Rhs) == 1 ) ret++;
00159   return ret;
00160 } 
00161 
00162 /*---------------------------------------------------------------------
00163  * vartype:
00164  *   type of variable number number in the stack 
00165  *---------------------------------------------------------------------*/
00166 
00167 integer C2F(vartype)(integer *number)
00168 {
00169   integer ix1=  *number + Top - Rhs;
00170   return  C2F(gettype)(&ix1);
00171 } 
00172 
00173 /*------------------------------------------------
00174  * gettype: 
00175  *    returns the type of object at position lw in the stack 
00176  *------------------------------------------------*/
00177 
00178 integer C2F(gettype)(integer *lw)
00179 {
00180   integer il;
00181   il = iadr(*Lstk(*lw ));
00182   if (*istk(il ) < 0) il = iadr(*istk(il +1));
00183   return *istk(il);
00184 }
00185 
00186 
00187 /*------------------------------------------------
00188  * overloadtype:
00189  *    set mechanism to overloaded function fname if object type
00190  *    does not fit given type
00191  *------------------------------------------------*/
00192 
00193 integer C2F(overloadtype)(integer *lw,char *fname,char *typ)
00194 {
00195   integer il=0;
00196   integer ityp=0;
00197   il = iadr(*Lstk(*lw ));
00198   if (*istk(il ) < 0) il = iadr(*istk(il +1));
00199   switch (*typ) {
00200   case 'c' : /* string */
00201   case 'S' : /* string Matrix */
00202     ityp=10;
00203     break;
00204   case 'd' :  case 'i' :  case 'r' :  case 'z' :   /* numeric */
00205     ityp=1;
00206     break ;
00207   case 'b' : /* boolean */
00208     ityp=4;
00209     break;
00210   case 'h' : /* handle */
00211     ityp=9;
00212     break;
00213   case 'l' : /* list */
00214     ityp=15;
00215     break;
00216   case 't' : /* tlist */
00217     ityp=16;
00218     break;
00219   case 'm' : /* mlist */
00220     ityp=17;
00221     break;
00222   case 'f' : /* external */
00223     ityp=13;
00224     break;
00225   case 'p' : /* pointer */
00226     ityp=128;
00227     break;
00228   case 's' : /* sparse */
00229     ityp= 5;
00230     break;
00231   case 'I' : /* int matrix */
00232     ityp=8;
00233     break;
00234 
00235   }
00236   if (*istk(il ) != ityp) {
00237     return C2F(overload)(lw,fname,strlen(fname));
00238   }
00239   return 1;
00240 }
00241 
00242 
00243 /*------------------------------------------------
00244  * overload
00245  *    set mechanism to overloaded function fname for object lw
00246  *------------------------------------------------*/
00247 
00248 integer C2F(overload)(integer *lw,char *fname,unsigned long l)
00249 {
00250   C2F(putfunnam)(fname,lw,l);
00251   C2F(com).fun=-1;
00252   return 0;
00253 }
00254 
00255 
00256 
00257 /*------------------------------------------------
00258  * ogettype : unused 
00259  *------------------------------------------------*/
00260 integer C2F(ogettype)(integer *lw)
00261 {
00262   return  *istk(iadr(*Lstk(*lw )) );
00263 }
00264 
00265 
00266 /*----------------------------------------------------
00267  * Optional arguments f(....., arg =val,...) 
00268  *          in interfaces 
00269  * function get_optionals : example is provided in 
00270  *    examples/addinter-examples/intex2c.c
00271  *----------------------------------------------------*/
00272 
00273 
00274 int get_optionals(char *fname ,rhs_opts opts[])
00275 {
00276   int k,i=0;
00277   char name[nlgh+1];
00278   int nopt = NumOpt(); /* optional arguments on the stack */
00279 
00280   /* reset first field since opts is declared static in calling function */
00281   /* this could be avoided with ansi compilers by removing static in the 
00282    * opts declaration */
00283 
00284   while ( opts[i].name != NULL )
00285     {
00286       opts[i].position = -1;
00287       i++;
00288     }
00289 
00290   /* Walking through last arguments */
00291 
00292   for ( k = Rhs - nopt + 1; k <= Rhs ;k++)
00293     {
00294       if ( IsOpt(k,name) == 0  ) 
00295         {
00296           Scierror(999,"%s: optional arguments name=val must be at the end\r\n",fname);
00297           return 0;
00298         }
00299       else 
00300         {
00301           int isopt = rhs_opt_find(name,opts);
00302           if ( isopt >= 0 ) 
00303             {
00304               rhs_opts *ro = &opts[isopt];
00305               ro->position = k;
00306               if (ro->type[0] != '?')
00307                 GetRhsVar(ro->position, ro->type,&ro->m,&ro->n,&ro->l);
00308             }
00309           else 
00310             {
00311               sciprint("%s: unrecognized optional arguments %s\r\n",fname,name);
00312               rhs_opt_print_names(opts) ;
00313               Error(999); 
00314               return(0);
00315             }
00316         }
00317     }
00318   return 1;
00319 }
00320 
00321 /* Is name in opts */
00322 
00323 int rhs_opt_find(char *name,rhs_opts opts[]) 
00324 {
00325   int rep=-1,i=0;
00326   while ( opts[i].name != NULL ) 
00327     {
00328       int cmp;
00329       /* name is terminated by white space and we want to ignore them */
00330       if ( (cmp=strcmp(name,opts[i].name)) == 0 )
00331         {
00332           rep = i ; break;
00333         }
00334       else if ( cmp < 0 )
00335         {
00336           break;
00337         }
00338       else 
00339         {
00340           i++;
00341         }
00342     }
00343   return rep;
00344 }
00345 
00346 void rhs_opt_print_names(rhs_opts opts[]) 
00347       /* array of optinal names (in alphabetical order) 
00348                        * the array is null terminated */
00349 {
00350   int i=0;
00351   if ( opts[i].name == NULL )
00352     {
00353       sciprint("optional argument list is empty\r\n");
00354       return;
00355     }
00356   sciprint("optional arguments list: ");
00357   while ( opts[i+1].name != NULL ) 
00358     {
00359       sciprint("%s, ",opts[i].name);
00360       i++;
00361     }
00362   sciprint("and %s.\r\n",opts[i].name);
00363   return ;
00364 }
00365 
00366 /*---------------------------------------------------------------------
00367  * isref :
00368  *   checks if variable number lw is on the stack 
00369  *   or is just a reference to a variable on the stack 
00370  *---------------------------------------------------------------------*/
00371 
00372 int IsRef(int number) { 
00373   return C2F(isref)(&number);
00374 }
00375 
00376 int C2F(isref)(integer *number) 
00377 {
00378   integer il,lw;
00379   lw = *number + Top - Rhs;
00380   if ( *number > Rhs) {
00381     Scierror(999,"isref: bad call to isref! (1rst argument)\r\n");
00382     return FALSE_;
00383   }
00384   il = iadr(*Lstk(lw));
00385   if ( *istk(il) < 0) 
00386     return TRUE_ ; 
00387   else 
00388     return FALSE_ ; 
00389 }
00390 
00391 /*---------------------------------------------------------------------
00392  *     create a variable number lw in the stack of type 
00393  *     type and size m,n 
00394  *     the argument must be of type type ('c','d','r','i','l','b') 
00395  *     return values m,n,lr 
00396  *     c : string  (m-> number of characters and n->1) 
00397  *     d,r,i : matrix of double,float or integer 
00398  *     b : boolean matrix 
00399  *     l : a list  (m-> number of elements and n->1) 
00400  *         for each element of the list an other function 
00401  *         must be used to <<get>> them 
00402  *     side effects : arguments in the common intersci are modified 
00403  *     see examples in addinter-examples 
00404  *---------------------------------------------------------------------*/
00405 
00406 int C2F(createvar)(integer *lw,char *typex,integer *m,integer *n,integer  *lr,unsigned long type_len)
00407 {
00408   integer ix1, ix, it=0, lw1, lcs, IT;
00409   unsigned char Type = *typex;
00410   char *fname = Get_Iname();
00411   if (*lw > intersiz) {
00412     Scierror(999,"%s: (createvar) too many arguments in the stack edit stack.h and enlarge intersiz\r\n",
00413              fname);
00414     return FALSE_ ;
00415   }
00416   Nbvars = Max(*lw,Nbvars);
00417   lw1 = *lw + Top - Rhs;
00418   if (*lw < 0) {
00419     Scierror(999,"%s: bad call to createvar! (1rst argument)\r\n",
00420              fname);
00421     return FALSE_ ;
00422   }
00423   switch (Type ) 
00424     {
00425     case 'c' : 
00426       ix1 = *m * *n;
00427       if (! C2F(cresmat2)(fname, &lw1, &ix1, lr, nlgh)) return FALSE_; 
00428       *lr = cadr(*lr);
00429       for (ix = 0; ix < (*m)*(*n) ; ++ix) *cstk(*lr+ix)= ' ';
00430       *cstk(*lr+ (*m)*(*n) )= '\0';
00431       C2F(intersci).ntypes[*lw - 1] = Type;
00432       C2F(intersci).iwhere[*lw - 1] = *Lstk(lw1);
00433       C2F(intersci).lad[*lw - 1] = *lr;
00434       break;
00435     case 'd' : 
00436       if (! C2F(cremat)(fname, &lw1, &it, m, n, lr, &lcs, nlgh))    return FALSE_;
00437       C2F(intersci).ntypes[*lw - 1] = Type;
00438       C2F(intersci).iwhere[*lw - 1] = *Lstk(lw1);
00439       C2F(intersci).lad[*lw - 1] = *lr;
00440       break;
00441     case 'z' : 
00442       IT = 1;
00443       if (!(*Lstk(lw1) % 2) ) *Lstk(lw1) = *Lstk(lw1)+1;
00444       if (! C2F(cremat)(fname, &lw1, &IT, m, n, lr, &lcs, nlgh))    return FALSE_;
00445       C2F(intersci).ntypes[*lw - 1] = Type;
00446       C2F(intersci).iwhere[*lw - 1] = *Lstk(lw1);
00447       C2F(intersci).lad[*lw - 1] = *lr;
00448       *lr = sadr(*lr);
00449       break;
00450     case 'l' : 
00451       C2F(crelist)(&lw1, m, lr);
00452       C2F(intersci).ntypes[*lw - 1] = '$';
00453       C2F(intersci).iwhere[*lw - 1] = *Lstk(lw1);
00454       C2F(intersci).lad[*lw - 1] = *lr;
00455       break;
00456     case 't' : 
00457       C2F(cretlist)(&lw1, m, lr);
00458       C2F(intersci).ntypes[*lw - 1] = '$';
00459       C2F(intersci).iwhere[*lw - 1] = *Lstk(lw1);
00460       C2F(intersci).lad[*lw - 1] = *lr;
00461       break;
00462     case 'm' : 
00463       C2F(cremlist)(&lw1, m, lr);
00464       C2F(intersci).ntypes[*lw - 1] = '$';
00465       C2F(intersci).iwhere[*lw - 1] = *Lstk(lw1);
00466       C2F(intersci).lad[*lw - 1] = *lr;
00467       break;
00468     case 'r' : 
00469       if (! C2F(cremat)(fname, &lw1, &it, m, n, lr, &lcs, nlgh)) return FALSE_;
00470       *lr = iadr(*lr);
00471       C2F(intersci).ntypes[*lw - 1] = Type;
00472       C2F(intersci).iwhere[*lw - 1] = *Lstk(lw1);
00473       C2F(intersci).lad[*lw - 1] = *lr;
00474       break ;
00475     case 'i' :
00476       if (! C2F(cremat)(fname, &lw1, &it, m, n, lr, &lcs, nlgh)) return FALSE_;
00477       *lr = iadr(*lr) ;
00478       C2F(intersci).ntypes[*lw - 1] = Type;
00479       C2F(intersci).iwhere[*lw - 1] = *Lstk(lw1);
00480       C2F(intersci).lad[*lw - 1] = *lr;
00481       break ;
00482     case 'b' :
00483       if (! C2F(crebmat)(fname, &lw1, m, n, lr, nlgh))  return FALSE_; 
00484       C2F(intersci).ntypes[*lw - 1] = Type;
00485       C2F(intersci).iwhere[*lw - 1] = *Lstk(lw1);
00486       C2F(intersci).lad[*lw - 1] = *lr;
00487       break;
00488     case 'p' : 
00489       if (! C2F(crepointer)(fname, &lw1, lr, nlgh))    return FALSE_;
00490       C2F(intersci).ntypes[*lw - 1] = '$';
00491       C2F(intersci).iwhere[*lw - 1] = *Lstk(lw1);
00492       C2F(intersci).lad[*lw - 1] = *lr;
00493       break;
00494     case 'I' : 
00495       it = *lr ; /* on entry lr gives the int type */ 
00496       if (! C2F(creimat)(fname, &lw1, &it, m, n, lr, nlgh))    return FALSE_;
00497       C2F(intersci).ntypes[*lw - 1] = '$';
00498       C2F(intersci).iwhere[*lw - 1] = *Lstk(lw1);
00499       C2F(intersci).lad[*lw - 1] = *lr;
00500       break;
00501     case 'h' : 
00502       if (! C2F(crehmat)(fname, &lw1, m, n, lr, nlgh))    return FALSE_;
00503       C2F(intersci).ntypes[*lw - 1] = Type;
00504       C2F(intersci).iwhere[*lw - 1] = *Lstk(lw1);
00505       C2F(intersci).lad[*lw - 1] = *lr;
00506       break;
00507     }
00508   return TRUE_; 
00509 }
00510 
00511 /*---------------------------------------------------------------------
00512  *     create a variable number lw in the stack of type 
00513  *     type and size m,n 
00514  *     the argument must be of type type ('d','r','i') 
00515  *     return values m,n,lr 
00516  *     d,r,i : matrix of double,float or integer 
00517  *     side effects : arguments in the common intersci are modified 
00518  *     see examples in addinter-examples 
00519  *     Like createvar but for complex matrices 
00520  *---------------------------------------------------------------------*/
00521 
00522 int C2F(createcvar)(integer *lw, char *typex,integer *it,integer *m,integer *n,integer *lr,integer *lc,unsigned long type_len)
00523 {
00524   unsigned char Type = *typex ;
00525   integer lw1;
00526   char *fname = Get_Iname();
00527   if (*lw > intersiz) {
00528     Scierror(999,"%s: (createcvar) too many arguments in the stack edit stack.h and enlarge intersiz\r\n",
00529              fname);
00530     return FALSE_;
00531   }
00532   Nbvars = Max(*lw,Nbvars);
00533   lw1 = *lw + Top - Rhs;
00534   if (*lw < 0) {
00535     Scierror(999,"%s: bad call to createcvar! (1rst argument)\r\n",
00536              fname);
00537     return FALSE_;
00538   }
00539   switch ( Type )  {
00540   case 'd' : 
00541     if (! C2F(cremat)(fname, &lw1, it, m, n, lr, lc, nlgh))  return FALSE_;
00542     C2F(intersci).ntypes[*lw - 1] = Type;
00543     C2F(intersci).iwhere[*lw - 1] = *Lstk(lw1);
00544     C2F(intersci).lad[*lw - 1] = *lr;
00545     break;
00546   case 'r' : 
00547     if (! C2F(cremat)(fname, &lw1, it, m, n, lr, lc, nlgh))  return FALSE_;
00548     *lr = iadr(*lr);
00549     *lc = *lr + *m * *n;
00550     C2F(intersci).ntypes[*lw - 1] = Type;
00551     C2F(intersci).iwhere[*lw - 1] = *Lstk(lw1);
00552     C2F(intersci).lad[*lw - 1] = *lr;
00553     break;
00554   case 'i' : 
00555     if (! C2F(cremat)(fname, &lw1, it, m, n, lr, lc, nlgh))  return FALSE_;
00556     *lr = iadr(*lr);
00557     *lc = *lr + *m * *n;
00558     C2F(intersci).ntypes[*lw - 1] = Type;
00559     C2F(intersci).iwhere[*lw - 1] = *Lstk(lw1);
00560     C2F(intersci).lad[*lw - 1] = *lr;
00561     break;
00562   }
00563   return TRUE_;
00564 } 
00565 
00566 /*---------------------------------------------------------------------
00567  *     create a variable number lw on the stack of type 
00568  *     list with nel elements 
00569  *---------------------------------------------------------------------*/
00570 
00571 int C2F(createlist)(integer *lw,integer *nel)
00572 {
00573   char *fname = Get_Iname();
00574   integer lr, lw1;
00575   if (*lw > intersiz) {
00576     Scierror(999,"%s: (createlist) too many arguments in the stack edit stack.h and enlarge intersiz\r\n",
00577              fname);
00578     return FALSE_;
00579   }
00580   Nbvars = Max(*lw,Nbvars);
00581   lw1 = *lw + Top - Rhs;
00582   if (*lw < 0) {
00583     Scierror(999,"%s: bad call to createlist! (1rst argument)\r\n",fname);
00584     return FALSE_;
00585   }
00586   C2F(crelist)(&lw1, nel, &lr);
00587   C2F(intersci).ntypes[*lw - 1] = '$';
00588   C2F(intersci).iwhere[*lw - 1] = *Lstk(lw1);
00589   C2F(intersci).lad[*lw - 1] = lr;
00590   return TRUE_;
00591 } 
00592 
00593 /*---------------------------------------------------------------------
00594  *     create a variable number lw on the stack of type 
00595  *     type and size m,n 
00596  *     the argument must be of type type ('c','d','r','i','b') 
00597  *     return values m,n,lr,lar 
00598  *     lar is also an input value 
00599  *     if lar != -1 var is filled with data stored at lar 
00600  *---------------------------------------------------------------------*/
00601 
00602 int C2F(createvarfrom)(integer *lw,char *typex,integer *m,integer *n,integer *lr,integer *lar,unsigned long type_len)
00603 {
00604   int M=*m,N=*n,MN=M*N;
00605   unsigned char Type = *typex;
00606   integer inc=1;
00607   integer it=0, lw1, lcs;
00608   char *fname = Get_Iname();
00609   if (*lw > intersiz) {
00610     Scierror(999,"%s: (createvarfrom) too many arguments in the stack edit stack.h and enlarge intersiz\r\n",
00611              fname);
00612     return FALSE_;
00613   }
00614   Nbvars = Max(*lw,Nbvars);
00615   lw1 = *lw + Top - Rhs;
00616   if (*lw < 0) {
00617     Scierror(999,"%s: bad call to createvarfrom! (1rst argument)\r\n",
00618              fname);
00619     return FALSE_;
00620   }
00621   switch ( Type ) {
00622   case 'c' :
00623     if (! C2F(cresmat2)(fname, &lw1, &MN, lr, nlgh)) return FALSE_;
00624     if (*lar != -1)  C2F(cvstr1)(&MN, istk(*lr), cstk(*lar), &cx0,  MN + 1);
00625     *lar = *lr;
00626     *lr = cadr(*lr);
00627     M=MN; N= 1;
00628     break;
00629   case 'd' :
00630     if (! C2F(cremat)(fname, &lw1, &it, m, n, lr, &lcs, nlgh))  return FALSE_;
00631     if (*lar != -1)  C2F(dcopy)(&MN, stk(*lar), &cx1, stk(*lr), &cx1);
00632     *lar = *lr;
00633     break;
00634   case 'r' :
00635     if (! C2F(cremat)(fname, &lw1, &it, m, n, lr, &lcs, nlgh)) return FALSE_;
00636     if (*lar != -1)   C2F(rea2db)(&MN, sstk(*lar), &cx1, stk(*lr), & cx1);
00637     *lar = *lr;
00638     *lr = iadr(*lr);
00639     break;
00640   case 'i' :
00641     if (! C2F(cremat)(fname, &lw1, &it, m, n, lr, &lcs, nlgh)) return FALSE_;
00642     if (*lar != -1) C2F(int2db)(&MN,istk(*lar), &cx1, stk(*lr), &cx1);
00643     *lar = *lr;
00644     *lr = iadr(*lr);
00645     break;
00646   case 'b' :
00647     if (! C2F(crebmat)(fname, &lw1, m, n, lr, nlgh)) return FALSE_;
00648     if (*lar != -1) C2F(icopy)(&MN, istk(*lar), &cx1, istk(*lr), &cx1);
00649     *lar = *lr;
00650     break;
00651   case 'I' :
00652     it = *lr;
00653     if (! C2F(creimat)(fname, &lw1, &it, m, n, lr,  nlgh))  return FALSE_;
00654     if (*lar != -1) 
00655       C2F(tpconv)(&it,&it,&MN,istk(*lar), &inc,istk(*lr), &inc);
00656     *lar = *lr;
00657     break;
00658   case 'p' :
00659     MN=1;
00660     if (! C2F(crepointer)(fname, &lw1, lr, nlgh))    return FALSE_;
00661     if (*lar != -1)  C2F(dcopy)(&MN, stk(*lar), &cx1, stk(*lr), &cx1);
00662     *lar = *lr;
00663     break;
00664   case 'h' :
00665     if (! C2F(crehmat)(fname, &lw1, m, n, lr, nlgh))  return FALSE_;
00666     if (*lar != -1)  C2F(dcopy)(&MN, stk(*lar), &cx1, stk(*lr), &cx1);
00667     *lar = *lr;
00668     break;
00669   }
00670   C2F(intersci).ntypes[*lw - 1] = '$';
00671   C2F(intersci).iwhere[*lw - 1] = *Lstk(lw1);
00672   C2F(intersci).lad[*lw - 1] = *lr;
00673   return TRUE_;
00674 }
00675 
00676 
00677 /*---------------------------------------------------------------------
00678  *     create a variable number lw on the stack of type 
00679  *     type and size m,n 
00680  *     the argument must be of type type ('d','r','i') 
00681  *     return values it,m,n,lr,lc,lar,lac 
00682  *     lar is also an input value 
00683  *     if lar != -1 var is filled with data stored at lar 
00684  *     idem for lac 
00685  *     ==> like createvarfrom for complex matrices 
00686 *---------------------------------------------------------------------*/
00687 
00688 int C2F(createcvarfrom)(integer *lw,char *typex,integer *it,integer *m,integer *n,integer *lr,integer *lc,integer *lar,integer *lac,unsigned long type_len)
00689 {
00690   unsigned char Type = *typex;
00691   int MN;
00692   integer lw1, lcs;
00693   char *fname =     Get_Iname();
00694   if (*lw > intersiz) {
00695     Scierror(999,"%s: (createcvarfrom) too many arguments in the stack edit stack.h and enlarge intersiz\r\n",
00696              fname);
00697     return FALSE_;
00698   }
00699   Nbvars = Max(*lw,Nbvars);
00700   lw1 = *lw + Top - Rhs;
00701   MN = (*m)*(*n);
00702   if (*lw < 0) {
00703     Scierror(999,"%s: bad call to createcvarfrom! (1rst argument)\r\n",
00704              fname);
00705     return FALSE_;
00706   }
00707   switch ( Type ) {
00708   case 'd' : 
00709     if (! C2F(cremat)(fname, &lw1, it, m, n, lr, lc, nlgh)) return FALSE_;
00710     if (*lar != -1) C2F(dcopy)(&MN, stk(*lar), &cx1,stk(*lr) , &cx1);
00711     if (*lac != -1 && *it == 1) C2F(dcopy)(&MN, stk(*lac), &cx1,stk(*lc) , &cx1);
00712     *lar = *lr;
00713     *lac = *lc;
00714     break;
00715   case 'r' :
00716     if (! C2F(cremat)(fname, &lw1, it, m, n, lr, lc, nlgh)) return FALSE_;
00717     if (*lar != -1) C2F(rea2db)(&MN, sstk(*lar), &cx1, stk(*lr), &cx1);
00718     if (*lac != -1 && *it==1) C2F(rea2db)(&MN, sstk(*lac), &cx1, stk(*lc), &cx1);
00719     *lar = *lr;
00720     *lac = *lc;
00721     *lr = iadr(*lr);
00722     *lc = *lr + *m * *n;
00723     break ;
00724   case 'i' :
00725     if (! C2F(cremat)(fname, &lw1, it, m, n, lr, &lcs, nlgh)) return FALSE_;
00726     if (*lar != -1) C2F(int2db)(&MN, istk(*lar), &cx1, stk(*lr), & cx1);
00727     if (*lac != -1 && (*it==1)) C2F(int2db)(&MN, istk(*lac), &cx1, stk(*lc), &cx1);
00728     *lar = *lr;
00729     *lac = *lc;
00730     *lr = iadr(*lr);
00731     *lc = *lr + *m * *n;
00732     break;
00733   }
00734   C2F(intersci).ntypes[*lw - 1] = '$';
00735   C2F(intersci).iwhere[*lw - 1] = *Lstk(lw1);
00736   C2F(intersci).lad[*lw - 1] = *lr;
00737   return TRUE_;
00738 }
00739 
00740 /*---------------------------------------------------------------------
00741  *     This function must be called after createvar(lnumber,'l',...) 
00742  *     Argument lnumber is a list 
00743  *     we want here to get its argument number number 
00744  *     the argument must be of type type ('c','d','r','i','b') 
00745  *     input values lnumber,number,type,lar 
00746  *     lar : input value ( -1 or the adress of an object which is used 
00747  *           to fill the new variable data slot. 
00748  *     lar must be a variable since it is used as input and output 
00749  *     return values m,n,lr,lar 
00750  *         (lar --> data is coded at stk(lar) 
00751  *          lr  --> data is coded at istk(lr) or stk(lr) or sstk(lr) 
00752  *                  or cstk(lr) 
00753  *     c : string  (m-> number of characters and n->1) 
00754  *     d,r,i : matrix of double,float or integer 
00755  *---------------------------------------------------------------------*/
00756 
00757 int C2F(createlistvarfrom)(integer *lnumber,integer *number,char * typex,integer *m,integer *n,integer *lr,integer *lar,unsigned long type_len)
00758 {
00759   unsigned Type = *typex;
00760   integer lc, ix1, it = 0, mn = (*m)*(*n),inc=1;
00761   char *fname = Get_Iname();
00762   if (*lnumber > intersiz) {
00763     Scierror(999,"%s: (createlistvar) too many arguments in the stack edit stack.h and enlarge intersiz\r\n",
00764              fname);
00765     return FALSE_;
00766   }
00767   switch ( Type ) {
00768   case 'c' :
00769     *n = 1;
00770     ix1 = *lnumber + Top - Rhs;
00771     if (! C2F(listcrestring)(fname, &ix1, number, &C2F(intersci).lad[*lnumber - 1], m, lr, nlgh)) {
00772       return FALSE_;
00773     }
00774     if (*lar != -1) C2F(cvstr1)(m, istk(*lr), cstk(*lar), &cx0,  *m * *n + 1);
00775     *lar = *lr;
00776     *lr = cadr( *lr);
00777     break;
00778   case 'd' :
00779     ix1 = *lnumber + Top - Rhs;
00780     if (! C2F(listcremat)(fname, &ix1, number, &C2F(intersci).lad[*lnumber - 1],
00781                           &it, m, n, lr, &lc, nlgh)) {
00782       return FALSE_;
00783     }
00784     if (*lar != -1) C2F(dcopy)(&mn, stk(*lar), &cx1,stk(*lr) , &cx1);
00785     *lar = *lr;
00786     break;
00787   case 'r' :
00788     ix1 = *lnumber + Top - Rhs;
00789     if (! C2F(listcremat)(fname, &ix1, number, &C2F(intersci).lad[*lnumber - 1],
00790                           &it, m, n, lr, &lc, nlgh)) {
00791       return FALSE_;
00792     }
00793     if (*lar != -1)     C2F(rea2db)(&mn, sstk(*lar), &cx1, stk(*lr), &cx1);
00794     *lar = *lr;
00795     *lr = iadr(*lr);
00796     break;
00797   case 'i' :
00798     ix1 = *lnumber + Top - Rhs;
00799     if (! C2F(listcremat)(fname, &ix1, number, &C2F(intersci).lad[*lnumber - 1],
00800                           &it, m, n, lr, &lc, nlgh)) {
00801       return FALSE_;
00802     }
00803     if (*lar != -1)     C2F(int2db)(&mn, istk(*lar), &cx1, stk(*lr), &cx1);
00804     *lar = *lr;
00805     *lr = iadr(*lr);
00806     break;
00807   case 'b' :
00808     ix1 = *lnumber + Top - Rhs;
00809     if (! C2F(listcrebmat)(fname, &ix1, number, &C2F(intersci).lad[*lnumber - 1]
00810                            , m, n, lr, nlgh)) {
00811       return FALSE_;
00812     }
00813     if (*lar != -1) C2F(icopy)(&mn, istk(*lar), &cx1, istk(*lr), &cx1);
00814     *lar = *lr;
00815     break;
00816   case 'I' : 
00817     it = *lr ; /* it gives the type on entry */
00818     ix1 = *lnumber + Top - Rhs;
00819     if (! C2F(listcreimat)(fname, &ix1, number, &C2F(intersci).lad[*lnumber - 1],
00820                           &it, m, n, lr, nlgh)) {
00821       return FALSE_;
00822     }
00823     if (*lar != -1) 
00824       C2F(tpconv)(&it,&it,&mn,istk(*lar), &inc,istk(*lr), &inc);
00825     *lar = *lr;
00826     break;
00827   case 'p' :
00828     ix1 = *lnumber + Top - Rhs;
00829     if (! C2F(listcrepointer)(fname, &ix1, number, 
00830                               &C2F(intersci).lad[*lnumber - 1], lr, nlgh)) 
00831       {
00832         return FALSE_;
00833       }
00834     if (*lar != -1) *stk(*lr)= *stk(*lar);
00835     *lar = *lr;
00836     break;
00837   case 'h' :
00838     ix1 = *lnumber + Top - Rhs;
00839     if (! C2F(listcrehmat)(fname, &ix1, number, &C2F(intersci).lad[*lnumber - 1],
00840                            m, n, lr, nlgh)) {
00841       return FALSE_;
00842     }
00843     if (*lar != -1) C2F(dcopy)(&mn, stk(*lar), &cx1,stk(*lr) , &cx1);
00844     *lar = *lr;
00845     break;
00846   default :
00847     Scierror(999,"%s: (createlistvar) bad third argument!\r\n",fname);
00848     return FALSE_;
00849     break;
00850   }
00851   return TRUE_;
00852 }
00853 
00854 
00855 
00856 /*---------------------------------------------------------------------
00857  * create a complex list variable from data 
00858  *---------------------------------------------------------------------*/
00859 
00860 int C2F(createlistcvarfrom)(integer *lnumber, integer *number, char *typex, integer *it, integer *m,integer *n,integer *lr,integer *lc,integer *lar,integer *lac, unsigned long type_len)
00861 {
00862   integer ix1;
00863   int mn = (*m)*(*n);
00864   unsigned char Type = *typex;
00865   char *fname = Get_Iname();
00866 
00867   if (*lnumber > intersiz) {
00868     Scierror(999,"%s: (createlistcvar) too many arguments in the stack edit stack.h and enlarge intersiz\r\n",
00869              fname) ;
00870     return FALSE_;
00871   }
00872 
00873   switch ( Type ) { 
00874   case 'd' :
00875     ix1 = *lnumber + Top - Rhs;
00876     if (! C2F(listcremat)(fname, &ix1, number, &C2F(intersci).lad[*lnumber - 1],it, m, n, lr, lc, nlgh)) 
00877       return FALSE_;
00878     if (*lar != -1) C2F(dcopy)(&mn,  stk(*lar), &cx1, stk(*lr), &cx1);
00879     if (*lac != -1 && *it==1) C2F(dcopy)(&mn, stk(*lac), &cx1,stk(*lc) , &cx1);
00880     *lar = *lr;
00881     *lac = *lc;
00882     break;
00883   case 'r' :
00884     ix1 = *lnumber + Top - Rhs;
00885     if (! C2F(listcremat)(fname, &ix1, number, &C2F(intersci).lad[*lnumber - 1],
00886                           it, m, n, lr, lc, nlgh)) 
00887       return FALSE_;
00888     if (*lar != -1) C2F(rea2db)(&mn, sstk(*lar), &cx1, stk(*lr), &cx1);
00889     if (*lac != -1 && *it==1) C2F(rea2db)(&mn, sstk(*lac), &cx1, stk(*lc), & cx1);
00890     *lar = *lr;
00891     *lac = *lc;
00892     *lr = iadr(*lr);
00893     *lc = *lr + *m * *n;
00894     break; 
00895   case 'i' :
00896     ix1 = *lnumber + Top - Rhs;
00897     if (! C2F(listcremat)(fname, &ix1, number, &C2F(intersci).lad[*lnumber - 1],
00898                           it, m, n, lr, lc, nlgh)) 
00899       return FALSE_;
00900     if (*lar != -1) C2F(int2db)(&mn,istk(*lar), &cx1, stk(*lr), &cx1);
00901     if (*lac != -1 && *it==1) C2F(int2db)(&mn, istk(*lac), &cx1, stk(*lc), &cx1);
00902     *lar = *lr;
00903     *lac = *lc;
00904     *lr = iadr(*lr);
00905     *lc = *lr + *m * *n;
00906     break;
00907   default :
00908     Scierror(999,"%s:  createlistcvar called with bad third argument!\r\n",fname);
00909     return FALSE_;
00910   }
00911   return TRUE_;
00912 }
00913 
00914 
00915 
00916 /*---------------------------------------------------------------------
00917  *     This function must be called after createvar(lnumber,'l',...) 
00918  *     Argument lnumber is a list 
00919  *     we want here to get its argument number number 
00920  *     the argument must be of type type ('c','d','r','i','b') 
00921  *     input values lnumber,number,type,lar 
00922  *     lar : input value ( -1 or the adress of an object which is used 
00923  *           to fill the new variable data slot. 
00924  *     lar must be a variable since it is used as input and output 
00925  *     return values m,n,lr,lar 
00926  *         (lar --> data is coded at stk(lar) 
00927  *          lr  --> data is coded at istk(lr) or stk(lr) or sstk(lr) 
00928  *                  or cstk(lr) 
00929  *     c : string  (m-> number of characters and n->1) 
00930  *     d,r,i : matrix of double,float or integer 
00931  *---------------------------------------------------------------------*/
00932 
00933 int C2F(createlistvarfromptr)(integer *lnumber,integer * number,char *typex,integer *m,integer *n,void *iptr,unsigned long type_len)
00934 {
00935   unsigned Type = *typex;
00936   integer lc, ix1, it = 0, lr,inc=1;
00937   char *fname = Get_Iname();
00938   if (*lnumber > intersiz) {
00939     Scierror(999,"%s: (createlistvarfromptr) too many arguments in the stack edit stack.h and enlarge intersiz\r\n",
00940              fname);
00941     return FALSE_;
00942   }
00943 
00944   ix1 = *lnumber + Top - Rhs;  /* factorization of this term (Bruno 9 march 2005, bugfix ) */
00945   switch ( Type ) {
00946   case 'c' :
00947     *n = 1;
00948     if (! C2F(listcrestring)(fname, &ix1, number, &C2F(intersci).lad[*lnumber - 1], m, &lr, nlgh)) {
00949       return FALSE_;
00950     }
00951     C2F(cchar)(m,(char **) iptr, istk(lr));
00952     break;
00953   case 'd' :
00954     if (! C2F(listcremat)(fname, &ix1, number, &C2F(intersci).lad[*lnumber - 1],
00955                           &it, m, n, &lr, &lc, nlgh)) {
00956       return FALSE_;
00957     }
00958     ix1= (*m)*(*n);
00959     C2F(cdouble) (&ix1,(double **) iptr, stk(lr));
00960     break;
00961   case 'r' :
00962     if (! C2F(listcremat)(fname, &ix1, number, &C2F(intersci).lad[*lnumber - 1],
00963                           &it, m, n, &lr, &lc, nlgh)) {
00964       return FALSE_;
00965     }
00966     ix1= (*m)*(*n);
00967     C2F(cfloat) (&ix1,(float **) iptr, stk(lr));
00968     break;
00969   case 'i' :
00970     if (! C2F(listcremat)(fname, &ix1, number, &C2F(intersci).lad[*lnumber - 1],
00971                           &it, m, n, &lr, &lc, nlgh)) {
00972       return FALSE_;
00973     }
00974     ix1 = *m * *n;
00975     C2F(cint)(&ix1,(int **) iptr, stk(lr));
00976     break;
00977   case 'b' :
00978     if (! C2F(listcrebmat)(fname, &ix1, number, &C2F(intersci).lad[*lnumber - 1]
00979                            , m, n, &lr, nlgh)) {
00980       return FALSE_;
00981     }
00982     ix1 = *m * *n;
00983     C2F(cbool)(&ix1,(int **) iptr, istk(lr));
00984     break;
00985   case 'S' : 
00986     if ( !cre_listsmat_from_str(fname,&ix1, number, &C2F(intersci).lad[*lnumber - 1]
00987                                 , m, n, (char **) iptr, nlgh)) /* XXX */
00988       return FALSE_;
00989     break;
00990   case 's' :
00991     if ( !cre_listsparse_from_ptr(fname,&ix1,number,
00992                               &C2F(intersci).lad[*lnumber - 1]
00993                               , m, n, (SciSparse *) iptr, nlgh))
00994       return FALSE_;
00995     break;
00996   case 'I' :
00997     it = ((SciIntMat *) iptr)->it;
00998     if (! C2F(listcreimat)(fname, &ix1, number, &C2F(intersci).lad[*lnumber - 1],
00999                           &it, m, n, &lr, nlgh)) {
01000       return FALSE_;
01001     }
01002     ix1= (*m)*(*n);
01003     C2F(tpconv)(&it,&it,&ix1,((SciIntMat *) iptr)->D, &inc,istk(lr), &inc);
01004     break;
01005   case 'p' :
01006     if (! C2F(listcrepointer)(fname, &ix1, number, 
01007                               &C2F(intersci).lad[*lnumber - 1],&lr,nlgh)) 
01008       {
01009         return FALSE_;
01010       }
01011     *stk(lr) = (double) ((unsigned long int) iptr);
01012     break;
01013   default :
01014     Scierror(999,"%s: (createlistvarfromptr) bad third argument!\r\n",fname);
01015     return FALSE_;
01016     break;
01017   }
01018   return TRUE_;
01019 }
01020 
01021 
01022 /*---------------------------------------------------------------------
01023  *     This function must be called after createvar(lnumber,'l',...) 
01024  *     Argument lnumber is a list 
01025  *     we want here to get its argument number number 
01026  *     the argument must be of type type ('c','d','r','i','b') 
01027  *     input values lnumber,number,type,lar 
01028  *     lar : input value ( -1 or the adress of an object which is used 
01029  *           to fill the new variable data slot. 
01030  *     lar must be a variable since it is used as input and output 
01031  *     return values m,n,lr,lar 
01032  *         (lar --> data is coded at stk(lar) 
01033  *          lr  --> data is coded at istk(lr) or stk(lr) or sstk(lr) 
01034  *                  or cstk(lr) 
01035  *     c : string  (m-> number of characters and n->1) 
01036  *     d,r,i : matrix of double,float or integer 
01037  *---------------------------------------------------------------------*/
01038 
01039 int C2F(createlistcvarfromptr)(integer *lnumber,integer *number,char *typex,integer *it,integer *m,integer *n,void *iptr,void *iptc,unsigned long type_len)
01040 {
01041   unsigned Type = *typex;
01042   integer lr,lc, ix1;
01043   char *fname = Get_Iname();
01044   if (*lnumber > intersiz) {
01045     Scierror(999,"%s: (createlistvarfromptr) too many arguments in the stack edit stack.h and enlarge intersiz\r\n",
01046              fname);
01047     return FALSE_;
01048   }
01049   switch ( Type ) {
01050   case 'd' :
01051     ix1 = *lnumber + Top - Rhs;
01052     if (! C2F(listcremat)(fname, &ix1, number, &C2F(intersci).lad[*lnumber - 1],
01053                           it, m, n, &lr, &lc, nlgh)) {
01054       return FALSE_;
01055     }
01056     ix1= (*m)*(*n);
01057     C2F(cdouble) (&ix1,(double **) iptr, stk(lr));
01058     if ( *it == 1) C2F(cdouble) (&ix1,(double **) iptc, stk(lc));
01059     break;
01060   case 'r' :
01061     ix1 = *lnumber + Top - Rhs;
01062     if (! C2F(listcremat)(fname, &ix1, number, &C2F(intersci).lad[*lnumber - 1],
01063                           it, m, n, &lr, &lc, nlgh)) {
01064       return FALSE_;
01065     }
01066     ix1= (*m)*(*n);
01067     C2F(cfloat) (&ix1,(float **) iptr, stk(lr));
01068     if ( *it == 1)     C2F(cfloat) (&ix1,(float **) iptc, stk(lc));
01069     break;
01070   case 'i' :
01071     ix1 = *lnumber + Top - Rhs;
01072     if (! C2F(listcremat)(fname, &ix1, number, &C2F(intersci).lad[*lnumber - 1],
01073                           it, m, n, &lr, &lc, nlgh)) {
01074       return FALSE_;
01075     }
01076     ix1 = *m * *n;
01077     C2F(cint)(&ix1,(int **) iptr, stk(lr));
01078     if ( *it == 1)     C2F(cint)(&ix1,(int **) iptc, stk(lc));
01079     break;
01080   default :
01081     Scierror(999,"%s: (createlistcvarfromptr) bad third argument!\r\n",fname);
01082     return FALSE_;
01083     break;
01084   }
01085   return TRUE_;
01086 }
01087 
01088 
01089 /*---------------------------------------------------------------------
01090  * use the rest of the stack as working area 
01091  * the allowed size (in double) is returned in m
01092  *---------------------------------------------------------------------*/
01093 
01094 int C2F(creatework)(integer *number,integer *m,integer *lr)
01095 {
01096   int n,it=0,lw1,lcs,il;
01097   char *fname = Get_Iname();
01098   if (*number > intersiz) {
01099     Scierror(999,"%s: (creatework) too many arguments in the stack edit stack.h and enlarge intersiz\r\n",
01100              fname);
01101     return FALSE_ ;
01102   }
01103   Nbvars = Max(*number,Nbvars);
01104   lw1 = *number + Top - Rhs;
01105   if (lw1 < 0) {
01106     Scierror(999,"%s: bad call to creatework! (1rst argument)\r\n",
01107              fname);
01108     return FALSE_ ;
01109   }
01110   il = iadr(*Lstk(lw1));
01111   *m = *Lstk(Bot ) - sadr(il+4);
01112   n = 1;
01113   if (! C2F(cremat)(fname, &lw1, &it, m, &n, lr, &lcs, nlgh))    return FALSE_;
01114   return TRUE_; 
01115 }
01116 
01117 
01118 /*---------------------------------------------------------------------
01119  * This can be used with creatework to 
01120  * set the size of object which was intialy sized to the whole 
01121  * remaining space with creatework 
01122  * Moreover informations the objet is recorded 
01123  *---------------------------------------------------------------------*/
01124 
01125 int C2F(setworksize)(integer *number,integer *size)
01126 {
01127   int lw1;
01128   char *fname = Get_Iname();
01129   if (*number > intersiz) {
01130     Scierror(999,"%s: (creatework) too many arguments in the stack edit stack.h and enlarge intersiz\r\n",
01131              fname);
01132     return FALSE_ ;
01133   }
01134   Nbvars = Max(*number,Nbvars);
01135   lw1 = *number + Top - Rhs;
01136   if (lw1 < 0) {
01137     Scierror(999,"%s: bad call to setworksize! (1rst argument)\r\n",
01138              fname);
01139     return FALSE_ ;
01140   }
01141   *istk(iadr(*Lstk(lw1)))=0;
01142   *Lstk(lw1+1) = *Lstk(lw1) + *size ;
01143   C2F(intersci).ntypes[*number - 1] = '$';
01144   C2F(intersci).iwhere[*number - 1] = *Lstk(lw1);
01145   C2F(intersci).lad[*number - 1] = 0; /* not to be used XXXX */ 
01146   return TRUE_; 
01147 }
01148 
01149 
01150 /*---------------------------------------------------------------------
01151  * getmatdims :
01152  *     check if argument number <<number>> is a matrix and 
01153  *     returns its dimensions
01154  *---------------------------------------------------------------------*/
01155 
01156 int C2F(getmatdims)(integer *number,integer *m,integer *n)
01157 {
01158   char *fname = Get_Iname();
01159   integer il,lw,typ;
01160 
01161   lw = *number + Top - Rhs;
01162   if ( *number > Rhs) {
01163     Scierror(999,"%s: bad call to getmatdims! (1rst argument)\r\n",fname);
01164     return FALSE_;
01165   }
01166 
01167   il = iadr(*Lstk(lw));
01168   if (*istk(il ) < 0) il = iadr(*istk(il +1));
01169   typ = *istk(il );
01170   if (typ > 10) {
01171     Scierror(201,"%s: argument %d should be a matrix\r\n", fname,*number);
01172     return  FALSE_;    
01173   }
01174   *m = *istk(il + 1);
01175   *n = *istk(il + 2);
01176   return TRUE_;
01177 }
01178 
01179 /*---------------------------------------------------------------------
01180  * getrhsvar :
01181  *     get the argument number <<number>> 
01182  *     the argument must be of type type ('c','d','r','i','f','l','b') 
01183  *     return values m,n,lr 
01184  *     c : string  (m-> number of characters and n->1) 
01185  *     d,r,i : matrix of double,float or integer 
01186  *     f : external (function) 
01187  *     b : boolean matrix 
01188  *     l : a list  (m-> number of elements and n->1) 
01189  *         for each element of the list an other function 
01190  *         must be used to <<get>> them 
01191  *     side effects : arguments in the common intersci are modified 
01192  *     see examples in addinter-examples 
01193  *---------------------------------------------------------------------*/
01194 
01195 int C2F(getrhsvar)(integer *number,char *typex,integer *m,integer *n,integer *lr,unsigned long type_len)
01196 {
01197   int ierr=0,il1,ild1,nn;
01198   int lrr;
01199   char *fname = Get_Iname();
01200   char **items, namex[nlgh+1];
01201   unsigned char Type = *(unsigned char *) typex;
01202   integer topk,ltype, m1, n1, lc,lr1, it=0, lw, ile, ils, ix1,ix2;
01203   integer mnel,icol;
01204   SciSparse *Sp;
01205   SciIntMat *Im;
01206   /* we accept a call to getrhsvar after a createvarfromptr call */
01207   if ( *number > Rhs && *number > Nbvars ) {
01208     Scierror(999,"%s: bad call to getrhsvar! (1rst argument)\r\n",fname);
01209     return FALSE_;
01210   }
01211 
01212   Nbvars = Max(Nbvars,*number);
01213   lw = *number + Top - Rhs;
01214 
01215   if (*number > intersiz) {
01216     Scierror(999,"%s: (getrhsvar) too many arguments in the stack edit stack.h and enlarge intersiz\r\n",
01217              fname);
01218     return FALSE_;
01219   }
01220 
01221   if (  C2F(overloadtype)(&lw,fname,&Type) == 0) return FALSE_;
01222   
01223   topk = Top;
01224   switch ( Type ) 
01225     {
01226     case 'c' : 
01227       *n = 1;
01228       if (! C2F(getsmat)(fname,&topk,&lw,&m1,&n1,&cx1,&cx1,lr,m, nlgh))
01229         return FALSE_;
01230       ix2 = *m * *n;
01231       /* in case where ix2 is 0 in2str adds the \0 char after the end of
01232          the storage of the variable, so it writes over the next variable 
01233          tp avoid this pb we shift up by one the location where the 
01234          data is written*/
01235       lrr=*lr;
01236       if (ix2==0) lrr--;
01237 
01238       C2F(in2str)(&ix2, istk(*lr), cstk(cadr(*lr)), ix2 + 1);
01239       *lr = cadr(*lr);
01240       C2F(intersci).ntypes[*number - 1] = Type ;
01241       C2F(intersci).iwhere[*number - 1] = *Lstk(lw);
01242       C2F(intersci).lad[*number - 1] = *lr;
01243       break;
01244 
01245     case 'd' :
01246       if (! C2F(getmat)(fname, &topk, &lw, &it, m, n, lr, &lc, nlgh)) return FALSE_;
01247       C2F(intersci).ntypes[*number - 1] = Type ;
01248       C2F(intersci).iwhere[*number - 1] = *Lstk(lw);
01249       C2F(intersci).lad[*number - 1] = *lr;
01250       break ;
01251     case 'z' :
01252       if (! C2F(getmat)(fname, &topk, &lw, &it, m, n, lr, &lc, nlgh)) return FALSE_;
01253       ix2 = *m * *n;
01254       if ((it != 1) && (ix2 !=0)) {
01255         Scierror(999," Waiting for a complex argument (z)"); return FALSE_;
01256       };
01257       if (!(*lr % 2) ) {  /* bad adress (lr is even) shift up the stack */
01258         double2z(stk(*lr), stk(*lr)-1, ix2, ix2);
01259         *istk(iadr(*lr)-4)=133;
01260         *istk(iadr(*lr)-3)=iadr(*lr + 2*ix2-1);
01261         *istk( iadr(*lr + 2*ix2-1) )= *m;
01262         *istk( iadr(*lr + 2*ix2-1) +1 )= *n;
01263         C2F(intersci).ntypes[*number - 1] = Type ;
01264         C2F(intersci).iwhere[*number - 1] = *Lstk(lw);
01265         C2F(intersci).lad[*number - 1] = *lr-1;
01266         *lr = sadr(*lr-1);
01267       }
01268       else {
01269         SciToF77(stk(*lr), ix2, ix2);
01270         C2F(intersci).ntypes[*number - 1] = Type ;
01271         C2F(intersci).iwhere[*number - 1] = *Lstk(lw);
01272         C2F(intersci).lad[*number - 1] = *lr;
01273         *lr = sadr(*lr);
01274       };
01275       break ;
01276     case 'r' :
01277       if (! C2F(getmat)(fname, &topk, &lw, &it, m, n, lr, &lc, nlgh))  return FALSE_;
01278       ix1 = *m * *n;
01279       C2F(simple)(&ix1, stk(*lr), sstk(iadr(*lr)));
01280       *lr = iadr(*lr);
01281       C2F(intersci).ntypes[*number - 1] = Type ;
01282       C2F(intersci).iwhere[*number - 1] = *Lstk(lw);
01283       C2F(intersci).lad[*number - 1] = *lr;
01284       break;
01285     case 'i' :
01286       if (! C2F(getmat)(fname, &topk, &lw, &it, m, n, lr, &lc, nlgh)) return FALSE_;
01287       ix1 = *m * *n;
01288       C2F(entier)(&ix1, stk(*lr), istk(iadr(*lr)));
01289       *lr = iadr(*lr) ;
01290       C2F(intersci).ntypes[*number - 1] = Type ;
01291       C2F(intersci).iwhere[*number - 1] = *Lstk(lw);
01292       C2F(intersci).lad[*number - 1] = *lr;
01293       break;
01294     case 'b' : 
01295       if (! C2F(getbmat)(fname, &topk, &lw, m, n, lr, nlgh))  return FALSE_;
01296       C2F(intersci).ntypes[*number - 1] = Type ;
01297       C2F(intersci).iwhere[*number - 1] = *Lstk(lw);
01298       C2F(intersci).lad[*number - 1] = *lr;
01299       break;
01300     case 'l' :    case 't' :    case 'm' :
01301       *n = 1;
01302       if (! C2F(getilist)(fname, &topk, &lw, m, n, lr, nlgh))  return FALSE_;
01303       /* No data conversion for list members ichar(type)='$' */
01304       Type = '$' ;
01305       C2F(intersci).ntypes[*number - 1] = Type ;
01306       C2F(intersci).iwhere[*number - 1] = *Lstk(lw);
01307       C2F(intersci).lad[*number - 1] = *lr;
01308       break;
01309     case 'S' :
01311       if (! C2F(getwsmat)(fname,&topk,&lw,m,n,&il1,&ild1, nlgh)) return FALSE_;
01312       nn= (*m)*(*n);
01313       ScilabMStr2CM(istk(il1),&nn,istk(ild1),&items,&ierr);
01314       if ( ierr == 1) return FALSE_;
01315       Type = '$';
01316       /*
01317        * Warning : lr must have the proper size when calling getrhsvar 
01318        * char **Str1; .... GetRhsVar(...., &lr) 
01319        */
01320       *((char ***) lr) = items ;
01321       C2F(intersci).ntypes[*number - 1] = Type ;
01322       C2F(intersci).iwhere[*number - 1] = *Lstk(lw);
01323       C2F(intersci).lad[*number - 1] = *lr;
01324       break;
01325     case 's' :
01326       /* sparse matrices */ 
01327       Sp = (SciSparse *) lr ;
01328       if (! C2F(getsparse)(fname,&topk,&lw,&it,m,n,&(Sp->nel),&mnel,&icol,&lr1,&lc,nlgh))
01329         return FALSE_;
01330       Sp->m = *m ; Sp->n = *n ; Sp->it = it; 
01331       Sp->mnel = istk(mnel);
01332       Sp->icol = istk(icol);
01333       Sp->R = stk(lr1);
01334       Sp->I = (it==1) ? stk(lc): NULL;
01335       Type = '$';
01336       C2F(intersci).ntypes[*number - 1] = Type ;
01337       C2F(intersci).iwhere[*number - 1] = *Lstk(lw);
01338       C2F(intersci).lad[*number - 1] = *lr;
01339       break;
01340     case 'I' :
01341       /* int matrices */ 
01342       Im = (SciIntMat *) lr ;
01343       if (! C2F(getimat)(fname,&topk,&lw,&it,m,n,&lr1,nlgh))
01344         return FALSE_;
01345       Im->m = *m ; Im->n = *n ; Im->it = it; Im->l = lr1;
01346       Im->D = istk(lr1);
01347       Type = '$';
01348       C2F(intersci).ntypes[*number - 1] = Type ;
01349       C2F(intersci).iwhere[*number - 1] = *Lstk(lw);
01350       C2F(intersci).lad[*number - 1] = *lr;
01351       break;
01352     case 'f' :
01353       /* XXXXXX : gros bug ici car getexternal a besoin de savoir 
01354          pour quelle fonction on recupere un external 
01355          or ici on presuppose que c'est setfeval 
01356          de plus on ne sait pas exactement de quel type d'external il s'agit
01357       */
01358          
01359       /*      int function getrhsvar(number,type,m,n,lr) */
01360       *lr = *Lstk(lw);
01361       ils = iadr(*lr) + 1;
01362       *m = *istk(ils);
01363       ile = ils + *m * nsiz + 1;
01364       *n = *istk(ile);
01365       if (! C2F(getexternal)(fname, &topk, &lw, namex, &ltype, C2F(setfeval), nlgh, 
01366                              nlgh)) {
01367         return FALSE_;
01368       }
01369       Type = '$';
01370       C2F(intersci).ntypes[*number - 1] = Type ;
01371       C2F(intersci).iwhere[*number - 1] = *Lstk(lw);
01372       C2F(intersci).lad[*number - 1] = *lr;
01373       break;
01374     case 'p' : 
01375       if (! C2F(getpointer)(fname, &topk, &lw,lr, nlgh)) return FALSE_;
01376       C2F(intersci).ntypes[*number - 1] = Type ;
01377       C2F(intersci).iwhere[*number - 1] = *Lstk(lw);
01378       C2F(intersci).lad[*number - 1] = *lr;
01379       break;
01380     case 'h' :
01381       if (! C2F(gethmat)(fname, &topk, &lw, m, n, lr, nlgh)) return FALSE_;
01382       C2F(intersci).ntypes[*number - 1] = Type ;
01383       C2F(intersci).iwhere[*number - 1] = *Lstk(lw);
01384       C2F(intersci).lad[*number - 1] = *lr;
01385       break ;
01386     }
01387   return TRUE_;
01388 } 
01389 
01390 
01391 /*---------------------------------------------------------------------
01392  * getrhsvcar :
01393  *     get the argument number <<number>> 
01394  *     the argument must be of type type ('d','r','i') 
01395  *     like getrhsvar but for complex matrices 
01396  *---------------------------------------------------------------------*/
01397 
01398 int C2F(getrhscvar)(integer *number,char *typex,integer *it,integer *m,integer *n,integer *lr,integer *lc,unsigned long type_len)
01399 {
01400   integer ix1, lw, topk;
01401   unsigned char Type = *typex;
01402   char *fname = Get_Iname();
01403   
01404   Nbvars = Max(Nbvars,*number);
01405   lw = *number + Top - Rhs;
01406   if (*number > Rhs) {
01407     Scierror(999,"%s: bad call to getrhscvar! (1rst argument)\r\n", fname);
01408     return FALSE_;
01409   }
01410   if (*number > intersiz) {
01411     Scierror(999,"%s: (getrhscvar) too many arguments in the stack edit stack.h and enlarge intersiz\r\n",
01412              fname);
01413     return FALSE_;
01414   }
01415   topk = Top;
01416   switch ( Type ) {
01417   case 'd' :
01418     if (! C2F(getmat)(fname, &topk, &lw, it, m, n, lr, lc, nlgh)) return FALSE_;
01419     break;
01420   case 'r' :
01421     if (! C2F(getmat)(fname, &topk, &lw, it, m, n, lr, lc, nlgh)) return FALSE_;
01422     ix1 = *m * *n * (*it + 1);
01423     C2F(simple)(&ix1, stk(*lr), sstk(iadr(*lr)));
01424     *lr = iadr(*lr);
01425     *lc = *lr + *m * *n;
01426     break;
01427   case 'i' :
01428     if (! C2F(getmat)(fname, &topk, &lw, it, m, n, lr, lc, nlgh)) return FALSE_;
01429     ix1 = *m * *n * (*it + 1);
01430     C2F(entier)(&ix1, stk(*lr), istk(iadr(*lr)));
01431     *lr = iadr(*lr);
01432     *lc = *lr + *m * *n;
01433     break;
01434   }
01435   C2F(intersci).ntypes[*number - 1] = Type;
01436   C2F(intersci).iwhere[*number - 1] = *Lstk(lw);
01437   C2F(intersci).lad[*number - 1] = *lr;
01438   return TRUE_;
01439 }
01440 /*---------------------------------------------------------------------
01441  * elementtype:
01442  *   returns the type of the element indexed by *number in the list 
01443  *   whose variable number is *lnumber. If the indexed element does not exist
01444  *   the function returns 0.
01445  *---------------------------------------------------------------------*/
01446 
01447 int C2F(elementtype)(integer *lnumber, integer *number)
01448 {
01449   integer il,lw,itype,n,ix,ili;
01450   char *fname = Get_Iname();
01451 
01452   if (*lnumber > Rhs) {
01453     Scierror(999,"%s: bad call to elementtype! \r\n",fname);
01454     return FALSE_;
01455   }
01456 
01457   lw = *lnumber + Top - Rhs; /*index of the variable numbered *lnumber in the stack */
01458   il = iadr(*Lstk(lw)); 
01459   if (*istk(il) < 0) il = iadr(*istk(il + 1));
01460   itype = *istk(il ); /* type of the variable numbered *lnumber */
01461   if (itype < 15 || itype > 17) { /* check if it is really a list */
01462     Scierror(210,"%s: Argument %d: wrong type argument, expecting a list\r\n",fname,*lnumber);
01463     return FALSE_;
01464   }
01465   n = *istk(il + 1);/* number of elements in the list */
01466   itype = 0; /*default answer if *number is not a valid element index */
01467   if (*number<=n && *number>0) {
01468     ix = sadr(il + 3 + n); /* adress of the first list element */
01469     if (*istk(il + 1+ *number) < *istk(il + *number + 2)) { /* the required element is defined */
01470       ili = iadr(ix + *istk(il + 1+ *number) - 1); /* adress of the required element */
01471       itype = *istk(ili);
01472     }
01473   }
01474   return itype;
01475 }
01476 
01477 /*---------------------------------------------------------------------
01478  *     This function must be called after getrhsvar(lnumber,'l',...) 
01479  *     Argument lnumber is a list 
01480  *     we want here to get its argument number number 
01481  *     the argument must be of type type ('c','d','r','i','b') 
01482  *     return values m,n,lr,lar 
01483  *         (lar --> data is coded at stk(lar) 
01484  *          lr  --> data is coded at istk(lr) or stk(lr) or sstk(lr) 
01485  *                  or cstk(lr) 
01486  *     c : string  (m-> number of characters and n->1) 
01487  *     d,r,i : matrix of double,float or integer 
01488  *---------------------------------------------------------------------*/
01489 
01490 int C2F(getlistrhsvar)(integer *lnumber,integer *number,char *typex,integer *m,integer *n,integer *lr,unsigned long type_len)
01491 {
01492   int lr1;
01493   char **items;
01494   int il1,ild1,nn,ierr=0;
01495   char *fname = Get_Iname();
01496   integer m1, n1, lc, it, lw, topk = Top, ix1,ix2;
01497   unsigned char Type = *typex;   
01498   integer mnel,icol;
01499   SciSparse *Sp;
01500   SciIntMat *Im;
01501 
01502   Nbvars = Max(Nbvars,*lnumber);
01503   lw = *lnumber + Top - Rhs;
01504   if (*lnumber > Rhs) {
01505     Scierror(999,"%s: bad call to getlistrhsvar! (1rst argument)\r\n",fname);
01506     return FALSE_;
01507   }
01508   if (*lnumber > intersiz) {
01509     Scierror(999,"%s: (getlistrhsvar) too many arguments in the stack edit stack.h and enlarge intersiz\r\n",
01510              fname);
01511     return FALSE_;
01512   }
01513 
01514   switch ( Type ) { 
01515   case 'c' : 
01516     *n = 1;
01517     if (! C2F(getlistsimat)(fname, &topk, &lw, number, &m1, &n1, &cx1, &cx1,lr, m, nlgh)) 
01518       return FALSE_;
01519     ix2 = *m * *n;
01520     C2F(in2str)(&ix2, istk(*lr), cstk(cadr(*lr)), ix2 + 1);
01521     *lr = cadr(*lr);
01522     break;
01523   case 'd' : 
01524     if (! C2F(getlistmat)(fname, &topk, &lw, number, &it, m, n, lr, &lc, nlgh))
01525       return FALSE_;
01526     break;
01527   case 'r' :
01528     if (! C2F(getlistmat)(fname, &topk, &lw, number, &it, m, n, lr, &lc, nlgh))
01529       return FALSE_;
01530     ix1 = *m * *n;
01531     C2F(simple)(&ix1, stk(*lr), sstk(iadr(*lr)));
01532     *lr = iadr(*lr);
01533     break;
01534   case 'i' :
01535     if (! C2F(getlistmat)(fname, &topk, &lw, number, &it, m, n, lr, &lc, nlgh))
01536       return FALSE_;
01537     ix1 = *m * *n;
01538     C2F(entier)(&ix1, stk(*lr), istk(iadr(*lr)));
01539     *lr = iadr(*lr);
01540     break;
01541   case 'b' :
01542     if (! C2F(getlistbmat)(fname, &topk, &lw, number, m, n, lr, nlgh)) 
01543       return FALSE_;
01544     *lr = *lr;
01545     break;
01546   case 'z' :
01547     if (! C2F(getlistmat)(fname, &topk, &lw,number, &it, m, n, lr, &lc, nlgh)) return FALSE_;
01548     ix2 = *m * *n;
01549     if ((it != 1) && (ix2 !=0)){
01550       Scierror(999,"%s: argument %d >(%d) should be a complex matrix\r\n",
01551                fname, Rhs + (lw -topk) , *number);
01552       return FALSE_;
01553     };
01554       if (!(*lr % 2) ) {  /* bad adress (lr is even) shift up the stack */
01555         double2z(stk(*lr), stk(*lr)-1, ix2, ix2);
01556         ix2=2*ix2;
01557         *istk(iadr(*lr)-4)=133;
01558         *istk(iadr(*lr)-3)=iadr(*lr + ix2);
01559         *istk( iadr(*lr + ix2) )= *m;
01560         *istk( iadr(*lr + ix2) +1 )= *n;
01561         *lr = sadr(*lr-1); 
01562       } else
01563         {
01564       SciToF77(stk(*lr), ix2, ix2);
01565       *lr = sadr(*lr);
01566         }
01567     break;
01568   case 'S' :
01570     if (! C2F(getlistwsmat)(fname,&topk,&lw,number,m,n,&il1,&ild1, nlgh)) return FALSE_;
01571     nn= (*m)*(*n);
01572     ScilabMStr2CM(istk(il1),&nn,istk(ild1),&items,&ierr);
01573     if ( ierr == 1) return FALSE_;
01574     Type = '$';
01575     /*
01576      * Warning : lr must have the proper size when calling getrhsvar 
01577      * char **Str1; .... GetRhsVar(...., &lr) 
01578      */
01579     *((char ***) lr) = items ;
01580     break;
01581   case 's' :
01582     /* sparse matrices */ 
01583     Sp = (SciSparse *) lr ;
01584     if (! C2F(getlistsparse)(fname,&topk,&lw,number,&it,m,n,&(Sp->nel),&mnel,&icol,&lr1,&lc,nlgh))
01585       return FALSE_;
01586     Sp->m = *m ; Sp->n = *n ; Sp->it = it; 
01587     Sp->mnel = istk(mnel);
01588     Sp->icol = istk(icol);
01589     Sp->R = stk(lr1);
01590     Sp->I = stk(lc);
01591     Type = '$';
01592     break;
01593   case 'I' :
01594     /* int matrices */ 
01595     Im = (SciIntMat *) lr ;
01596     if (! C2F(getlistimat)(fname,&topk,&lw,number,&it,m,n,&lr1,nlgh))
01597       return FALSE_;
01598     Im->m = *m ; Im->n = *n ; Im->it = it; Im->l = lr1;
01599     Im->D = istk(lr1);
01600     Type = '$';
01601     break;
01602   case 'p' :
01603     if (! C2F(getlistpointer)(fname, &topk, &lw, number, lr,  nlgh))
01604       return FALSE_;
01605     break;
01606   default :
01607     Scierror(999,"%s: getlistrhsvar was called with bad third argument (%c)\r\n",fname,Type);
01608     return FALSE_;
01609   }
01610   /* can't perform back data conversion with lists */
01611   C2F(intersci).ntypes[*number - 1] = '$';
01612   return TRUE_ ; 
01613 }
01614   
01615 /*---------------------------------------------------------------------
01616  * for complex 
01617  *---------------------------------------------------------------------*/
01618 
01619 int C2F(getlistrhscvar)(integer *lnumber,integer *number,char *typex,integer *it,integer *m,integer *n,integer *lr,integer *lc,unsigned long type_len)
01620 {
01621   integer ix1, topk= Top, lw;
01622   char *fname = Get_Iname();
01623   unsigned  char    Type = * typex;
01624 
01625   Nbvars = Max(Nbvars,*lnumber);
01626   lw = *lnumber + Top - Rhs;
01627   if (*lnumber > Rhs) {
01628     Scierror(999,"%s: bad call to getlistrhscvar! (1rst argument)\r\n",fname);
01629     return FALSE_;
01630   }
01631   if (*lnumber > intersiz) {
01632     Scierror(999,"%s: (getlistrhscvar) too many arguments in the stack edit stack.h and enlarge intersiz\r\n",
01633              fname);
01634     return FALSE_;
01635   }
01636   switch ( Type ) {
01637   case 'd' :
01638     if (! C2F(getlistmat)(fname, &topk, &lw, number, it, m, n, lr, lc, nlgh)) return FALSE_;
01639     break;
01640   case 'r' :
01641     if (! C2F(getlistmat)(fname, &topk, &lw, number, it, m, n, lr, lc, nlgh)) 
01642       return FALSE_;
01643     ix1 = *m * *n * (*it + 1);
01644     C2F(simple)(&ix1, stk(*lr), sstk(iadr(*lr)));
01645     *lr  = iadr(*lr);
01646     *lc = *lr + *m * *n;
01647     break;
01648   case 'i' :
01649     if (! C2F(getlistmat)(fname, &topk, &lw, number, it, m, n, lr, lc, nlgh)) 
01650       return FALSE_;
01651     ix1 = *m * *n * (*it + 1);
01652     C2F(entier)(&ix1, stk(*lr), istk(iadr(*lr)));
01653     *lr = iadr(*lr) ;
01654     *lc = *lr + *m * *n;
01655     break;
01656   default :
01657     Scierror(999,"%s: getlistrhscvar was called with  bad third argument!\r\n",fname);
01658     return FALSE_;
01659   }
01660   /* can't perform back data conversion with lists */
01661   C2F(intersci).ntypes[*number - 1] = '$';
01662   return TRUE_;
01663 }
01664 
01665 /*---------------------------------------------------------------------
01666  *     creates variable number number of type "type" and dims m,n 
01667  *     from pointer ptr 
01668  *     
01669  *---------------------------------------------------------------------*/
01670 
01671 int C2F(createvarfromptr)(integer *number,char *typex,integer *m,integer *n,void *iptr,unsigned long type_len)
01672 {
01673   static int un=1;
01674   unsigned char Type = *typex;
01675   int MN= (*m)*(*n),lr,it,lw1;
01676   char *fname = Get_Iname();
01677   lw1 = *number + Top - Rhs;
01678   switch ( Type ) 
01679     {
01680     case 'd' :
01681       if ( C2F(createvar)(number, typex, m, n, &lr, type_len) == FALSE_ ) return FALSE_;
01682       C2F(dcopy)(&MN,*((double **) iptr),&un, stk(lr),&un);
01683       break;
01684     case 'i' :
01685     case 'b' :
01686       if ( C2F(createvar)(number, typex, m, n, &lr, type_len) == FALSE_ ) return FALSE_;
01687       C2F(icopy)(&MN,*((int **) iptr), &un, istk(lr), &un);
01688       break;
01689     case 'r' :
01690       if ( C2F(createvar)(number, typex, m, n, &lr, type_len) == FALSE_ ) return FALSE_;
01691       C2F(rcopy)(&MN,*((float **)iptr), &un, sstk(lr), &un);
01692       break;
01693     case 'c' :
01694       if ( C2F(createvar)(number, typex, m, n, &lr, type_len) == FALSE_ ) return FALSE_;
01695       strcpy(cstk(lr),*((char **) iptr));
01696       break;
01697     case 'I' :
01698       /* on entry lr must gives the int type */
01699       it = lr = ((SciIntMat *) iptr)->it;
01700       if ( C2F(createvar)(number, typex, m, n, &lr, type_len) == FALSE_ ) return FALSE_;
01701       C2F(tpconv)(&it,&it,&MN,((SciIntMat *) iptr)->D, &un,istk(lr), &un);
01702       break;
01703     case 'p' :
01704       if ( C2F(createvar)(number, typex, m, n, &lr, type_len) == FALSE_ ) return FALSE_;
01705       *stk(lr) = (double) ((unsigned long int) iptr);
01706       break;
01707     case 'S' :
01708       /* special case: not taken into account in createvar */
01709       Nbvars = Max(*number,Nbvars);
01710       if ( !cre_smat_from_str(fname,&lw1, m, n, (char **) iptr, nlgh)) 
01711         return FALSE_;
01712       C2F(intersci).iwhere[*number - 1] = *Lstk(lw1);
01713       C2F(intersci).ntypes[*number - 1] = '$';
01714       break;
01715     case 's' :
01716       /* special case: not taken into account in createvar */
01717       Nbvars = Max(*number,Nbvars);
01718       if ( !cre_sparse_from_ptr(fname,&lw1, m, n, (SciSparse *) iptr, nlgh))
01719         return FALSE_;
01720       C2F(intersci).iwhere[*number - 1] = *Lstk(lw1);
01721       C2F(intersci).ntypes[*number - 1] = '$';
01722       break;
01723     default :
01724       Scierror(999,"%s: createvarfromptr was called with bad second argument!\r\n",fname);
01725       return FALSE_;
01726     }
01727   /*     this object will be copied with a vcopyobj in putlhsvar */
01728   return TRUE_; 
01729 } 
01730 
01731 
01732 
01733 /*---------------------------------------------------------------------
01734  *     for complex 
01735  *---------------------------------------------------------------------*/
01736 
01737 int C2F(createcvarfromptr)(integer *number,char *typex,integer *it,integer *m,integer *n,double *iptr,double *iptc,unsigned long type_len)
01738 {
01739   unsigned char Type = *typex;
01740   char *fname = Get_Iname();
01741   integer lw1, lcs, lrs, ix1;
01742 
01743   Nbvars = Max(Nbvars,*number);
01744   if (*number > intersiz) {
01745     Scierror(999,"%s: createcvarfromptr: too many arguments on the stack, enlarge intersiz\r\n",
01746              fname);
01747     return FALSE_;
01748   }
01749   lw1 = *number + Top - Rhs;
01750   switch ( Type ) {
01751   case 'd' : 
01752     if (! C2F(cremat)(fname, &lw1, it, m, n, &lrs, &lcs, nlgh)) 
01753       return FALSE_;
01754     ix1 = *m * *n;
01755     C2F(cdouble)(&ix1, (double **) iptr, stk(lrs));
01756     if (*it == 1) {
01757       ix1 = *m * *n;
01758       C2F(cdouble)(&ix1,(double **) iptc, stk(lcs));
01759     }
01760     break;
01761   case 'i' :
01762     if (! C2F(cremat)(fname, &lw1, it, m, n, &lrs, &lcs, nlgh)) 
01763       return FALSE_;
01764     ix1 = *m * *n;
01765     C2F(cint)(&ix1, (int **) iptr, stk(lrs));
01766     if (*it == 1) {
01767       ix1 = *m * *n;
01768       C2F(cint)(&ix1,(int **) iptc, stk(lcs));
01769     }
01770     break;
01771   default :
01772     Scierror(999,"%s: createcvarfromptr was called with bad second argument!\r\n",fname);
01773     return FALSE_;
01774   }
01775   /*     this object will be copied with a vcopyobj in putlhsvar */
01776   C2F(intersci).ntypes[*number - 1] = '$';
01777   return  TRUE_;
01778 } 
01779 
01780 /*---------------------------------------------------------------------
01781  * mklistfromvars : 
01782  *     replace the last n variables created at postions pos:pos-1+n 
01783  *     by a list of these variables at position pos 
01784  *---------------------------------------------------------------------*/
01785 
01786 int C2F(mklistfromvars)(integer *pos,integer *n)
01787 {
01788   integer tops =  Top;
01789   int k;
01790   for ( k= *pos; k < *pos+*n; k++) C2F(convert2sci)(&k);
01791   Top = Top - Rhs + *pos - 1 + *n;
01792   C2F(mklist)(n);
01793   Top = tops;
01794   C2F(intersci).ntypes[*pos - 1] = '$';
01795   return  TRUE_;
01796 } 
01797 /*---------------------------------------------------------------------
01798  * mktlistfromvars : 
01799  *     similar to mklistfromvars but create a tlist 
01800  *---------------------------------------------------------------------*/
01801 
01802 int C2F(mktlistfromvars)(integer *pos,integer *n)
01803 {
01804   integer type=16;
01805   integer tops =  Top;
01806   int k;
01807   for ( k= *pos; k < *pos+*n; k++) C2F(convert2sci)(&k);
01808   Top = Top - Rhs + *pos - 1 + *n;
01809   C2F(mklistt)(n,&type);
01810   Top = tops;
01811   C2F(intersci).ntypes[*pos - 1] = '$';
01812   return  TRUE_;
01813 } 
01814 /*---------------------------------------------------------------------
01815  * mktlistfromvars : 
01816  *     similar to mklistfromvars but create a mlist 
01817  *---------------------------------------------------------------------*/
01818 
01819 int C2F(mkmlistfromvars)(integer *pos,integer *n)
01820 {
01821   integer type=17;
01822   integer tops =  Top;
01823   int k;
01824   for ( k= *pos; k < *pos+*n; k++) C2F(convert2sci)(&k);
01825   Top = Top - Rhs + *pos - 1 + *n;
01826   C2F(mklistt)(n,&type);
01827   Top = tops;
01828   C2F(intersci).ntypes[*pos - 1] = '$';
01829   return  TRUE_;
01830 } 
01831 
01832 /*---------------------------------------------------------------------
01833  * call a Scilab function given its name 
01834  *---------------------------------------------------------------------*/
01835 
01836 int C2F(callscifun)(char *string,unsigned long string_len)
01837 {
01838   integer id[nsiz];
01839   C2F(cvname)(id, string, &cx0, string_len);
01840   C2F(putid)(&C2F(recu).ids[(C2F(recu).pt + 1) * nsiz - nsiz], id);
01841   C2F(com).fun = -1;
01842   return 0;
01843 } 
01844 
01845 /*---------------------------------------------------------------------
01846  * scifunction(number,ptr,mlhs,mrhs) >
01847  *     execute scilab function with mrhs input args and mlhs output 
01848  *     variables 
01849  *     input args are supposed to be stored in the top of the stack 
01850  *     at positions top-mrhs+1:top 
01851  *---------------------------------------------------------------------*/
01852 
01853 int C2F(scifunction)(integer *number,integer *ptr,integer *mlhs,integer *mrhs)
01854 {
01855   integer cx26 = 26;
01856   integer ix1, krec, iflagint, ix, k, intop, il, ir, lw;
01857   
01858   if ( intersci_push() == 0 ) 
01859     {
01860       Scierror(999,"scifunction: Running out of memory \r\n");
01861       goto L9999;
01862     }
01863 
01864   /*     macro execution */
01865   intop = Top;
01866   Top = Top - Rhs + *number + *mrhs - 1;
01867   ++C2F(recu).pt;
01868   if (C2F(recu).pt > psiz) {
01869     C2F(error)(&cx26);
01870     goto L9999;
01871   }
01872   C2F(recu).ids[C2F(recu).pt * nsiz - nsiz] = Lhs;
01873   C2F(recu).ids[C2F(recu).pt * nsiz - (nsiz-1)] = Rhs;
01874   C2F(recu).rstk[C2F(recu).pt - 1] = 1001;
01875   Lhs = *mlhs;
01876   Rhs = *mrhs;
01877   ++C2F(recu).niv;
01878   C2F(com).fun = 0;
01879   C2F(com).fin = *ptr;
01880   C2F(recu).icall = 5;
01881   krec = -1;
01882 
01883  L60:
01884   C2F(parse)();
01885   if (C2F(com).fun == 99) {
01886     C2F(com).fun = 0;
01887     goto L200;
01888   }
01889   if (Err > 0)  goto L9999;
01890   if (C2F(recu).rstk[C2F(recu).pt - 1] / 100 == 9) {
01891     ir = C2F(recu).rstk[C2F(recu).pt - 1] - 900;
01892     if (ir == 1) {
01893       /*     .     back to matsys */
01894       k = 13;
01895     } else if (ir >= 2 && ir <= 9) {
01896       /*     .     back to matio */
01897       k = 5;
01898       /*<          elseif(ir.eq.10) then >*/
01899     } else if (ir == 10) {
01900       /*     .     end of overloaded function */
01901       goto L96;
01902       /*<          elseif(ir.gt.40) then >*/
01903     } else if (ir > 40) {
01904       /*     .     back to matus2 */
01905       k = 24;
01906     } else if (ir > 20) {
01907       /*     .     back to matusr */
01908       k = 14;
01909     } else {
01910       goto L89;
01911     }
01912     iflagint = 0;
01913     goto L95;
01914   }
01915 
01916  L89:
01917   if (Top < Rhs) {
01918     Scierror(22,"scifunction: recursion problems. Sorry....\r\n");
01919     goto L9999;
01920   }
01921   if (Top - Rhs + Lhs + 1 >= Bot) {
01922     Scierror(18,"scifunction: too many names\r\n");
01923     goto L9999;
01924   }
01925   goto L91;
01926  L90:
01927   if (Err > 0) {
01928     goto L9999;
01929   }
01930   if (Top - Lhs + 1 > 0) {
01931     C2F(iset)(&Lhs, &cx0, &C2F(vstk).infstk[Top - Lhs], &cx1);
01932   }
01933  L91:
01934   k = C2F(com).fun;
01935   C2F(com).fun = 0;
01936   if (k == krec) {
01937     Scierror(22,"scifunction: recursion problems. Sorry....\r\n");
01938     goto L9999;
01939   }
01940   if (k == 0) {
01941     goto L60;
01942   }
01943   if (k == 2) {
01944     il = iadr( *Lstk(Top + 1 - Rhs));
01945     iflagint = *istk(il + 3);
01946   }
01947  L95:
01948   if (! C2F(allowptr)(&k)) {
01949     C2F(ref2val)();
01950   }
01951   C2F(callinterf)(&k, &iflagint);
01952   if (C2F(com).fun >= 0) {
01953     goto L90;
01954   }
01955   /*    called interface ask for a scilab function to perform the function (fun=-1)
01956    *     the function name is given in ids(1,pt+1) 
01957    */
01958   C2F(ref2val)();
01959   C2F(com).fun = 0;
01960   C2F(funs)(&C2F(recu).ids[(C2F(recu).pt + 1)* nsiz - nsiz]);
01961   if (Err > 0) {
01962     goto L9999;
01963   }
01964   if (C2F(com).fun > 0) {
01965     goto L91;
01966   }
01967   if (C2F(com).fin == 0) {
01968     integer cx4 = 4;
01969     C2F(error)(&cx4);
01970     if (Err > 0) {
01971       goto L9999;
01972     }
01973     goto L90;
01974   }
01975   ++C2F(recu).pt;
01976   C2F(com).fin = *Lstk(C2F(com).fin);
01977   C2F(recu).rstk[C2F(recu).pt - 1] = 910;
01978   C2F(recu).icall = 5;
01979   C2F(com).fun = 0;
01980   /*     *call*  macro */
01981   goto L60;
01982  L96:
01983   --C2F(recu).pt;
01984   goto L90;
01985  L200:
01986   Lhs = C2F(recu).ids[C2F(recu).pt * nsiz -nsiz ];
01987   Rhs = C2F(recu).ids[C2F(recu).pt * nsiz -(nsiz-1)];
01988   --C2F(recu).pt;
01989   --C2F(recu).niv;
01990   /* + */
01991   Top = intop;
01992   ix1 = *mlhs;
01993   intersci_pop();
01994   for (ix = 1; ix <= ix1; ++ix) {
01995     lw = Top - Rhs + *number + ix - 1;
01996     C2F(intersci).ntypes[lw - 1] = '$';
01997   }
01998   return TRUE_;
01999 
02000  L9999:
02001   Top = intop;
02002   --C2F(recu).niv;
02003   intersci_pop();
02004   return FALSE_;
02005 } 
02006 
02007 /*---------------------------------------------------------------------
02008  * scistring :
02009  *   executes scilab string (name of a scilab function) with mrhs 
02010  *     input args and mlhs output variables 
02011  *     input args are supposed to be indexed by ifirst,ifirst+1,... 
02012  *     thestring= string made of the name of a Scilab function 
02013  *     mlhs,mlhs = number of lhs and rhs parameters of the function 
02014  *     ifisrt,thestring,mlhs and mrhs are input parameters. 
02015  *---------------------------------------------------------------------*/
02016 
02017 int C2F(scistring)(integer *ifirst,char *thestring,integer *mlhs,integer *mrhs,unsigned long thestring_len)
02018 {
02019   int ret = FALSE_;
02020   integer ifin, ifun, tops, moutputs, id[nsiz], lf, op, ile, ils, nnn, ninputs;
02021   nnn =  thestring_len;
02022   op = 0;
02023   if (nnn <= 2) {
02024     op = C2F(getopcode)(thestring, thestring_len);
02025   }
02026   if (op == 0) {
02027     C2F(cvname)(id, thestring, &cx0, nnn);
02028     C2F(com).fin = 0;
02029     tops = Top;
02030     Top = Top - Rhs + *ifirst + *mrhs - 1;
02031     C2F(funs)(id);
02032     Top = tops;
02033     if (C2F(com).fin == 0) {
02034       Scierror(999,"scistring: %s is not a Scilab function\r\n", 
02035                get_fname(thestring,thestring_len));
02036       return ret;
02037     }
02038     if (C2F(com).fun <= 0) {
02039       lf = *Lstk(C2F(com).fin);
02040       ils = iadr(lf) + 1;
02041       moutputs = *istk(ils);
02042       ile = ils + moutputs * nsiz + 1;
02043       ninputs = *istk(ile);
02044       /*  
02045        *   ninputs=actual number of inputs, moutputs=actual number of outputs
02046        *   of thestring: checking mlhs=ninputs and mrhs=moutputs not done. 
02047        */
02048       ret = C2F(scifunction)(ifirst, &lf, mlhs, mrhs);
02049     } else {
02050       ifin = C2F(com).fin;
02051       ifun = C2F(com).fun;
02052       ret = C2F(scibuiltin)(ifirst, &ifun, &ifin, mlhs, mrhs);
02053     }
02054   } else {
02055     ret = C2F(sciops)(ifirst, &op, mlhs, mrhs);
02056   }
02057   return ret;
02058 }
02059 
02060 integer C2F(getopcode)(char *string,unsigned long string_len)
02061 {
02062   unsigned char ch = string[0];
02063   integer op = 0;
02064   if (  string_len >= 2) {
02065     /*     .op  or op. */
02066     if ( ch  == '.') ch = string[1];
02067     op += 51;
02068   }
02069   switch ( ch ) 
02070     {
02071     case  '*'  :  op += 47; break;
02072     case  '+'  :  op += 45; break;
02073     case  '-'  :  op += 46; break;
02074     case  '\'' :  op += 53; break;
02075     case  '/'  :  op += 48; break;
02076     case  '\\' :  op += 49; break;
02077     case  '^'  :  op += 62; break;
02078     }
02079   return op;
02080 }
02081 
02082 /*---------------------------------------------------------------------
02083  *     same as scifunction: executes scilab built-in function (ifin,ifun) 
02084  *
02085  *     =(interface-number, function-nmber-in-interface) 
02086  *     for the input parameters located at number, number+1, .... 
02087  *     mlhs,mrhs = # of lhs and rhs parameters of the function. 
02088  *---------------------------------------------------------------------*/
02089 
02090 int C2F(scibuiltin)(integer *number,integer *ifun,integer *ifin,integer *mlhs,integer *mrhs)
02091 {
02092   integer krec, srhs, slhs, iflagint;
02093   integer ix, k, intop, il, ir, lw, pt0;
02094   intop = Top;
02095   
02096   if ( intersci_push() == 0 ) 
02097     {
02098       Scierror(999,"scifunction: Running out of memory \r\n");
02099       goto L9999;
02100     }
02101 
02102   Top = Top - Rhs + *number + *mrhs - 1;
02103   slhs = Lhs;
02104   srhs = Rhs;
02105   Lhs = *mlhs;
02106   Rhs = *mrhs;
02107   krec = -1;
02108   pt0 = C2F(recu).pt;
02109   goto L90;
02110   /* ***************************** */
02111   /*<  60   call  parse >*/
02112  L60:
02113   C2F(parse)();
02114   if (C2F(com).fun == 99) {
02115     C2F(com).fun = 0;
02116     goto L200;
02117   }
02118   if (Err > 0) {
02119     goto L9999;
02120   }
02121   if (C2F(recu).rstk[C2F(recu).pt - 1] / 100 == 9) {
02122     ir = C2F(recu).rstk[C2F(recu).pt - 1] - 900;
02123     if (ir == 1) {
02124       /*     .     back to matsys */
02125       k = 13;
02126     } else if (ir >= 2 && ir <= 9) {
02127       /*     .     back to matio */
02128       k = 5;
02129     } else if (ir == 10) {
02130       /*     .     end of overloaded function */
02131       goto L96;
02132     } else if (ir > 40) {
02133       /*     .     back to matus2 */
02134       k = 24;
02135     } else if (ir > 20) {
02136       /*     .     back to matusr */
02137       k = 14;
02138     } else {
02139       goto L89;
02140     }
02141     iflagint = 0;
02142     goto L95;
02143   }
02144  L89:
02145   if (Top < Rhs) {
02146     Scierror(22,"scibuiltin: recursion problems. Sorry....\r\n");
02147     goto L9999;
02148   }
02149   if (Top - Rhs + Lhs + 1 >= Bot) {
02150     Scierror(18,"scibuiltin: too many names\r\n");
02151     goto L9999;
02152   }
02153   goto L91;
02154  L90:
02155   if (Err > 0) {
02156     goto L9999;
02157   }
02158   if (Top - Lhs + 1 > 0) {
02159     C2F(iset)(&Rhs, &cx0, &C2F(vstk).infstk[Top - Lhs], &cx1);
02160   }
02161  L91:
02162   k = C2F(com).fun;
02163   C2F(com).fun = 0;
02164   if (k == krec) {
02165     Scierror(22,"scibuiltin: recursion problems. Sorry....\r\n");
02166     goto L9999;
02167   }
02168   if (k == 0) {
02169     if (C2F(recu).pt > pt0) {
02170       goto L60;
02171     }
02172     goto L200;
02173   }
02174   if (k == 2) {
02175     il = iadr(*Lstk(Top + 1 - Rhs));
02176     iflagint = *istk(il + 3);
02177   }
02178   if (! C2F(allowptr)(&k)) {
02179     C2F(ref2val)();
02180   }
02181  L95:
02182   C2F(callinterf)(&k, &iflagint);
02183   if (C2F(recu).icall != 0) {
02184     goto L60;
02185   }
02186   if (C2F(com).fun >= 0) {
02187     goto L90;
02188   }
02189   /*    called interface ask for a sci function to perform the function (fun=-1)*/
02190   /*     the function name is given in ids(1,pt+1) */
02191   C2F(ref2val)();
02192   C2F(com).fun = 0;
02193   C2F(funs)(&C2F(recu).ids[(C2F(recu).pt + 1)* nsiz - nsiz]);
02194   if (Err > 0) {
02195     goto L9999;
02196   }
02197   if (C2F(com).fun > 0) {
02198     goto L91;
02199   }
02200   if (C2F(com).fin == 0) {
02201     integer cx4 = 4;
02202     C2F(error)(&cx4);
02203     if (Err > 0) {
02204       goto L9999;
02205     }
02206   }
02207   ++C2F(recu).pt;
02208   C2F(com).fin = *Lstk(C2F(com).fin);
02209   C2F(recu).rstk[C2F(recu).pt - 1] = 910;
02210   C2F(recu).icall = 5;
02211   C2F(com).fun = 0;
02212   /*     *call*  macro */
02213   goto L60;
02214  L96:
02215   --C2F(recu).pt;
02216   goto L90;
02217   /* ************************** */
02218  L200:
02219   Lhs = slhs;
02220   Rhs = srhs;
02221   Top = intop;
02222   intersci_pop();
02223   for (ix = 0 ; ix < *mlhs ; ++ix) {
02224     lw = Top - Rhs + *number + ix ;
02225     C2F(intersci).ntypes[lw - 1] = '$';
02226   }
02227   return TRUE_;
02228  L9999:
02229   intersci_pop();
02230   return FALSE_;
02231 }
02232 
02233 /*---------------------------------------------------------------------
02234  *     same as scibuiltin: executes scilab operation op 
02235  *     for the input parameters located at number, number+1, .... 
02236  *     mlhs,mrhs = # of lhs and rhs parameters of the operation. 
02237  *---------------------------------------------------------------------*/
02238 
02239 int C2F(sciops)(integer *number,integer *op,integer *mlhs,integer *mrhs)
02240 {
02241   integer ifin, ifun, srhs= Rhs , slhs= Lhs, ix, intop=Top , lw;
02242 
02243   Fin   = *op;
02244   Top = Top - Rhs + *number + *mrhs - 1;
02245   Lhs = *mlhs;
02246   Rhs = *mrhs;
02247 
02248   while (1) 
02249     {
02250       C2F(allops)();
02251       if (Err > 0) {return FALSE_;} ;
02252       if (C2F(com).fun == 0) break; 
02253       Top = intop;
02254       ifun = C2F(com).fun;
02255       ifin = C2F(com).fin;
02256       if (! C2F(scibuiltin)(number, &ifun, &ifin, mlhs, mrhs)) 
02257         {return FALSE_;} ;
02258       if (Err > 0) {return FALSE_;} ;
02259     }
02260   Lhs = slhs;
02261   Rhs = srhs;
02262   Top = intop;
02263   
02264   for (ix = 1 ; ix <= *mlhs ; ++ix) {
02265     lw = Top - Rhs + *number + ix - 1;
02266     C2F(intersci).ntypes[lw - 1] = '$';
02267   }
02268   C2F(com).fun = 0;
02269   C2F(com).fin = *op;
02270   C2F(recu).icall = 0;
02271   return TRUE_;
02272 } 
02273 
02274 /*-------------------------------------------------------------
02275  *     test and return linear system (syslin tlist) 
02276  *     inputs: lw = variable number 
02277  *     outputs: 
02278  *     N=size of A matrix (square)                    
02279  *     M=number of inputs = col. dim B matrix         
02280  *     P=number of outputs = row. dim of C matrix     
02281  *     ptr(A,B,C,D,X0) adresses of A,B,C,D,X0 in stk  
02282  *     h=type   h=0.0  continuous system              
02283  *              h=1.0  discrete time system 
02284  *              h=h    sampled system h=sampling period 
02285  -------------------------------------------------------------*/
02286 
02287 int C2F(getrhssys)(integer *lw,integer *n,integer *m,integer *p,integer *ptra,integer *ptrb,integer *ptrc,integer *ptrd,integer *ptrx0,double *hx)
02288 {
02289   integer cx2 = 2, cx3 = 3, cx4 = 4, cx5 = 5, cx6 = 6;
02290   integer ix1, junk, msys, nsys, ix, icord;
02291   integer ma, na, mb, nb, mc, nc, il, md, nd;
02292   integer mx0, nx0, ptrsys, itimedomain;
02293   static integer iwork[23] = { 10,1,7,0,1,4,5,6,7,8,10,12,21,28,28,-10,-11,
02294                                -12,-13,-33,0,13,29 };
02295   if (! C2F(getrhsvar)(lw, "t", &msys, &nsys, &ptrsys, 1L)) return FALSE_;
02296   il = iadr(ptrsys) - msys - 1;
02297   /*     syslin tlist=[ chain, (A,B,C,D,X0) ,chain or scalar ]
02298    *                     10     1 1 1 1 1      10       1    
02299    */
02300   junk = il + msys + iadr(*istk(il));
02301   if ( *istk(junk) != 10) return FALSE_;
02302   if ( *istk(il + msys + iadr(*istk(il + 1))) != 1) return FALSE_;
02303   if ( *istk(il + msys + iadr(*istk(il + 2))) != 1) return FALSE_;
02304   if ( *istk(il + msys + iadr(*istk(il + 3))) != 1) return FALSE_;
02305   if ( *istk(il + msys + iadr(*istk(il + 4))) != 1) return FALSE_;
02306   if ( *istk(il + msys + iadr(*istk(il + 5))) != 1) return FALSE_;
02307   itimedomain = *istk(il + msys + iadr(*istk(il + 6)));
02308   switch ( itimedomain ) {
02309   case 10 :
02310     /* Sys(7)='c' or 'd' */
02311     icord = *istk(il + msys + iadr(*istk(il + 6))+ 6);
02312     switch ( icord ) 
02313       {
02314       case 12 :  *hx = 0.; break;
02315       case 13 :  *hx = 1.; break;
02316       default : 
02317         Scierror(999,"invalid time domain\r\n");
02318         return FALSE_;
02319       }
02320     break;
02321   case 1 : 
02322     /*     Sys(7)=h */
02323     ix1 = il + msys + iadr(*istk(il + 6)) + 4;
02324     *hx = *stk(sadr(ix1));
02325     break;
02326   default : 
02327     Scierror(999,"invalid time domain\r\n");
02328     return FALSE_;
02329   }
02330   for (ix = 0; ix < 23; ++ix) 
02331     {
02332       if (iwork[ix] != *istk(junk + ix)) {
02333         Scierror(999,"invalid system\r\n");
02334         return FALSE_;
02335       }
02336     }
02337   if (! C2F(getlistrhsvar)(lw, &cx2, "d", &ma, &na, ptra, 1L)) return FALSE_;
02338   if (! C2F(getlistrhsvar)(lw, &cx3, "d", &mb, &nb, ptrb, 1L)) return FALSE_;
02339   if (! C2F(getlistrhsvar)(lw, &cx4, "d", &mc, &nc, ptrc, 1L)) return FALSE_;
02340   if (! C2F(getlistrhsvar)(lw, &cx5, "d", &md, &nd, ptrd, 1L)) return FALSE_;
02341   if (! C2F(getlistrhsvar)(lw, &cx6, "d", &mx0, &nx0, ptrx0, 1L))  return FALSE_;
02342   if (ma != na) {
02343     Scierror(999,"A matrix non square!\r\n");
02344     return FALSE_;
02345   }
02346   if (ma != mb && mb != 0) {
02347     Scierror(999,"Invalid A,B matrices\r\n");
02348     return FALSE_;
02349   }
02350   if (ma != nc && nc != 0) {
02351     Scierror(999,"Invalid A,C matrices\r\n");
02352     return FALSE_;
02353   }
02354   if (mc != md && md != 0) {
02355     Scierror(999,"Invalid C,D matrices\r\n");
02356     return FALSE_;
02357   }
02358   if (nb != nd && nd != 0) {
02359     Scierror(999,"Invalid B;D matrices\r\n");
02360     return FALSE_;
02361   }
02362   *n = ma;
02363   *m = nb;
02364   *p = mc;
02365   return TRUE_;
02366 }
02367 
02368 
02369 /*--------------------------------------------------- 
02370  * call Scilab error function (for Fortran use)
02371  *---------------------------------------------------*/
02372 
02373 int C2F(errorinfo)(char *fname,integer *info,unsigned long fname_len)
02374 {
02375   Scierror(998,"%s: internal error, info=%d\r\n",get_fname(fname,fname_len),*info);
02376   return 0;
02377 }
02378 
02379 
02380 /*-------------------------------------------------------------
02381  *  returns Maximal available size in scilab stack 
02382  *  for variable <<number>> lw 
02383  *  In a Fortran call 
02384  *     lw = 
02385  *     type= 'd','r','i','c' 
02386  *     type_len is here for C/Fortran calling conventions 
02387  *  This function is used for creating a working array of Maximal dimension 
02388  *  Example : 
02389  *     lwork=Maxvol(nb,'d')
02390  *     if(.not.createvar(nb,'d',lwork,1,idwork)) return
02391  *     call pipo(   ,stk(idwork),[lwork],...) 
02392  *-------------------------------------------------------------*/
02393 
02394 integer C2F(maxvol)(integer *lw,char *lw_type,unsigned long type_len)
02395 {
02396   unsigned char Type =  *(unsigned char *)lw_type ;
02397   /* I like this one a lot: a kind of free jazz pattern  */
02398   integer m = *Lstk(Bot) - sadr(iadr(*Lstk(*lw + Top - Rhs)) +4);
02399   switch ( Type ) 
02400     {
02401     case 'd' : return m; break;
02402     case 'i' : return iadr(m);break;
02403     case 'r' : return iadr(m);break;
02404     case 'c' : return cadr(m);break;
02405     case 'z' : return sadr(m)-3;break;
02406     }
02407   /* should never get there */
02408   return m; 
02409 }
02410 
02411 
02412 /*---------------------------------------------
02413  * This function checks all the variables which 
02414  * where references and restore their contents 
02415  * to Scilab value. 
02416  *---------------------------------------------*/ 
02417 
02418 static int Check_references()
02419 {
02420         int ivar ; 
02421         for (ivar = 1; ivar <= Rhs ; ++ivar) 
02422                 {
02423                         unsigned char Type = (unsigned char)C2F(intersci).ntypes[ivar - 1];
02424                         if ( Type != '$') 
02425                                 {
02426                                         int lw = ivar + Top - Rhs;
02427                                         int il = iadr(*Lstk(lw));
02428                                         if ( *istk(il) < 0) 
02429                                                 {
02430                                                         int m,n,it,size;
02431                                                         /* back conversion if necessary of a reference */ 
02432                                                         /* sciprint("%d: is a reference\r\n",ivar);  */
02433                                                         if ( *istk(il) < 0)  il = iadr(*istk(il +1));
02434                                                         m =*istk(il +1);
02435                                                         n =*istk(il +2);
02436                                                         it = *istk(il +3);
02437                                                         switch ( Type ) {
02438                                                                 case 'i' : 
02439                                                                 case 'r' : 
02440                                                                 case 'd' :
02441                                                                         size  = m * n * (it + 1); break; 
02442                                                                 case 'z' :
02443                                                                         size  = 0;break; /* size is unsued for 'z' in ConvertData;*/
02444                                                                 case 'c' : 
02445                                                                         size =*istk(il + 4  +1) - *istk(il + 4 ); break;
02446                                                                 case 'b' :
02447                                                                         size = m*n ; break;
02448                                                                 default:
02449                                                                         return FALSE_; 
02450                                                         }
02451                                                         ConvertData(&Type,size,C2F(intersci).lad[ivar - 1]);
02452                                                         C2F(intersci).ntypes[ivar - 1] = '$';
02453                                                 }
02454                                 }
02455                         else 
02456                                 {
02457                                         /* sciprint("%d: is of type $ \n",ivar);  */
02458                                 }
02459                 }
02460         return TRUE_; 
02461 }
02462 
02463 
02464 
02465 
02466 /*---------------------------------------------------------------------
02467  * int C2F(putlhsvar)()
02468  *     This function put on the stack the lhs 
02469  *     variables which are at position lhsvar(i) 
02470  *     on the calling stack 
02471  *     Warning : this function supposes that the last 
02472  *     variable on the stack is at position top-rhs+nbvars 
02473  *---------------------------------------------------------------------*/
02474 
02475 int C2F(putlhsvar)()
02476 {
02477   integer ix2, ivar, ibufprec, ix, k, lcres, nbvars1;
02478   integer plhsk;
02479   Check_references();
02480   
02481   for (k = 1; k <= Lhs; k++)
02482     {
02483       plhsk=*Lstk(LhsVar(k)+Top-Rhs);
02484       if (*istk( iadr(plhsk) ) < 0) {
02485         if (*Lstk(Bot) > *Lstk(*istk(iadr (plhsk) +2)) )
02486         LhsVar(k)=*istk(iadr(plhsk)+2);
02487         /* lcres = 0 */
02488       }
02489     }
02490 
02491   if (C2F(iop).err > 0||C2F(errgst).err1> 0)  return TRUE_ ; 
02492   if (C2F(com).fun== -1 ) return TRUE_ ; /* execution continue with an 
02493                                             overloaded function */
02494   if (LhsVar(1) == 0) 
02495     {
02496       Top = Top - Rhs + Lhs;
02497       C2F(objvide)(" ", &Top, 1L);
02498       Nbvars = 0;
02499       return TRUE_;
02500     }
02501   nbvars1 = 0;
02502   for (k = 1; k <= Lhs ; ++k) nbvars1 = Max( nbvars1 , LhsVar(k));
02503   /* check if output variabe are in increasing order in the stack */
02504   lcres = TRUE_;
02505   ibufprec = 0;
02506   for (ix = 1; ix <= Lhs ; ++ix) {
02507     if (LhsVar(ix) < ibufprec) {
02508       lcres = FALSE_;
02509       break;
02510     } else {
02511       ibufprec = LhsVar(ix );
02512     }
02513   }
02514   if (! lcres) {
02515     /* First pass if output variables are not 
02516      * in increasing order 
02517      */
02518     for (ivar = 1; ivar <= Lhs; ++ivar) {
02519       ix2 = Top - Rhs + nbvars1 + ivar;
02520       if (! C2F(mvfromto)(&ix2, &LhsVar(ivar))) {
02521         return FALSE_;
02522       }
02523       LhsVar(ivar) = nbvars1 + ivar;
02524       /* I change type of variable nbvars1 + ivar 
02525        * in order to just perform a dcopy at next pass 
02526        */
02527       if (nbvars1 + ivar > intersiz) {
02528         Scierror(999,"putlhsvar: intersiz is too small\r\n");
02529         return FALSE_;
02530       }
02531       C2F(intersci).ntypes[nbvars1 + ivar - 1] = '$';
02532     }
02533   }
02534   /*  Second pass */
02535   for (ivar = 1; ivar <= Lhs ; ++ivar) 
02536     {
02537       ix2 = Top - Rhs + ivar;
02538       if (! C2F(mvfromto)(&ix2, &LhsVar(ivar))) {
02539         return FALSE_;
02540       }
02541     }
02542   Top = Top - Rhs + Lhs;
02543   LhsVar(1) = 0;
02544   Nbvars = 0;
02545   return TRUE_;
02546 } 
02547 
02548 
02549 /*---------------------------------------------------------------------
02550  * mvfromto : 
02551  *     this routines copies the variable number i
02552  *     (created by getrhsvar or createvar or by mvfromto itself in a precedent call)
02553  *     from its position on the stack to position itopl 
02554  *     returns false if there's no more stack space available 
02555  *     - if type(i) # '$'  : This variable is at 
02556  *                         position lad(i) on the stack ) 
02557  *                         and itopl must be the first free position 
02558  *                         on the stack 
02559  *                         copy is performed + type conversion (type(i)) 
02560  *     - if type(i) == '$': then it means that object at position i 
02561  *                         is the result of a previous call to mvfromto 
02562  *                         a copyobj is performed and itopl can 
02563  *                         can be any used position on the stack 
02564  *                         the object which was at position itopl 
02565  *                         is replaced by object at position i 
02566  *                         (and access to object itopl+1 can be lost if 
02567  *                         the object at position i is <> from object at 
02568  *                         position itopl 
02569  *---------------------------------------------------------------------*/
02570 
02571 static int C2F(mvfromto)(integer *itopl,integer *ix)
02572 {
02573   integer ix1=0;
02574   integer m=0;
02575   integer n=0;
02576   integer it=0;
02577   integer lcs=0;
02578   integer lrs=0;
02579   integer l=0;
02580   integer size=0;
02581   integer pointed=0;
02582   unsigned long int ilp=0;
02583   unsigned char Type;
02584   double wsave;
02585 
02586   Type = (unsigned char)C2F(intersci).ntypes[*ix - 1];
02587   if ( Type != '$') 
02588     {
02589       /* int iwh = *ix + Top - Rhs;
02590          ilp = iadr(*Lstk(iwh)); */ 
02591       int iwh = C2F(intersci).iwhere[*ix - 1];
02592       ilp = iadr(iwh); 
02593       if ( *istk(ilp) < 0)  ilp = iadr(*istk(ilp +1));
02594       m =*istk(ilp +1);
02595       n =*istk(ilp +2);
02596       it = *istk(ilp +3);
02597     }
02598 
02599   switch ( Type ) {
02600   case 'i' : 
02601     if (! C2F(cremat)("mvfromto", itopl, &it, &m, &n, &lrs, &lcs, 8L)) {
02602       return FALSE_;
02603     }
02604     ix1 = m * n * (it + 1);
02605     C2F(stacki2d)(&ix1, &C2F(intersci).lad[*ix - 1], &lrs);
02606     C2F(intersci).lad[*ix - 1] = iadr(lrs);
02607     break ;
02608   case 'r' :
02609     if (! C2F(cremat)("mvfromto", itopl, &it, &m, &n, &lrs, &lcs, 8L)) {
02610       return FALSE_;
02611     }
02612     ix1 = m * n * (it + 1);
02613     C2F(stackr2d)(&ix1, &C2F(intersci).lad[*ix - 1], &lrs);
02614     C2F(intersci).lad[*ix - 1] = iadr(lrs);
02615     break;
02616   case 'd' :
02617     if (! C2F(cremat)("mvfromto", itopl, &it, &m, &n, &lrs, &lcs, 8L)) {
02618       return FALSE_;
02619     }
02620     /* no copy if the two objects are the same 
02621      * the cremat above is kept to deal with possible size changes 
02622      */
02623     if (C2F(intersci).lad[*ix - 1] != lrs) {
02624       ix1 = m * n * (it + 1);
02625       l=C2F(intersci).lad[*ix - 1];
02626       if (abs(l-lrs)<ix1)
02627         C2F(unsfdcopy)(&ix1, stk(l), &cx1, stk(lrs), &cx1);
02628       else
02629         C2F(dcopy)(&ix1, stk(l), &cx1, stk(lrs), &cx1);
02630       C2F(intersci).lad[*ix - 1] = lrs;
02631     }
02632     break;
02633   case 'z' :
02634     if ( *istk(ilp) == 133 ) {
02635       wsave=*stk(C2F(intersci).lad[*ix - 1]); 
02636       n=*istk(m+1);
02637           m=*istk(m);
02638           it=1;
02639       if (! C2F(cremat)("mvfromto", itopl, &it, &m, &n, &lrs, &lcs, 8L)) {
02640       return FALSE_;  }
02641       z2double(stk(C2F(intersci).lad[*ix - 1]),stk(lrs),m*n, m*n);
02642       *stk(lrs)=wsave;
02643       C2F(intersci).lad[*ix - 1] = lrs;
02644       }
02645     else { 
02646       if (! C2F(cremat)("mvfromto", itopl, &it, &m, &n, &lrs, &lcs, 8L)) {
02647         return FALSE_;
02648       }
02649     z2double(stk(C2F(intersci).lad[*ix - 1]), stk(lrs), m*n, m*n);
02650     C2F(intersci).lad[*ix - 1] = lrs;
02651     }
02652     break;
02653   case 'c' : 
02654     m = *istk(ilp + 4  +1) - *istk(ilp + 4 );
02655     n = 1;
02656     ix1 = m * n;
02657     if (! C2F(cresmat2)("mvfromto", itopl, &ix1, &lrs, 8L)) {
02658       return FALSE_;
02659     }
02660     C2F(stackc2i)(&ix1, &C2F(intersci).lad[*ix - 1], &lrs);
02661     C2F(intersci).lad[*ix - 1] = cadr(lrs);
02662     break;
02663   
02664   case 'b' :
02665     if (! C2F(crebmat)("mvfromto", itopl, &m, &n, &lrs, 8L)) {
02666       return FALSE_;
02667     }
02668     ix1 = m * n;
02669     C2F(icopy)(&ix1, istk(C2F(intersci).lad[*ix - 1]), &cx1,istk(lrs), &cx1);
02670     C2F(intersci).lad[*ix - 1] = lrs;
02671     break;
02672   case '-' :
02673     /*    reference  '-' = ascii(45) */
02674     ilp = iadr(*Lstk(*ix));
02675     size = *istk(ilp+3);
02676     pointed = *istk(ilp+2);
02677     if (! C2F(cremat)("mvfromto", itopl, (it=0 ,&it), (m=1, &m), &size, &lrs, &lcs, 8L)) {
02678       return FALSE_;
02679     }
02680     if ( C2F(vcopyobj)("mvfromto", &pointed, itopl, 8L) == FALSE_) 
02681           return FALSE_;
02682     break;
02683   case 'h' :
02684     if (! C2F(crehmat)("mvfromto", itopl, &m, &n, &lrs, 8L)) {
02685       return FALSE_;
02686     }
02687     /* no copy if the two objects are the same 
02688      * the cremat above is kept to deal with possible size changes 
02689      */
02690     if (C2F(intersci).lad[*ix - 1] != lrs) {
02691       ix1 = m * n;
02692       l=C2F(intersci).lad[*ix - 1];
02693       if (abs(l-lrs)<ix1)
02694         C2F(unsfdcopy)(&ix1, stk(l), &cx1, stk(lrs), &cx1);
02695       else
02696         C2F(dcopy)(&ix1, stk(l), &cx1, stk(lrs), &cx1);
02697       C2F(intersci).lad[*ix - 1] = lrs;
02698     }
02699     break;
02700   case 'p' :   case '$' :
02701     /*     special case */
02702     if (Top - Rhs + *ix != *itopl) 
02703       {
02704         ix1 = Top - Rhs + *ix;
02705         if ( C2F(vcopyobj)("mvfromto", &ix1, itopl, 8L) == FALSE_) 
02706           return FALSE_;
02707       }
02708   }
02709   return TRUE_;
02710 } 
02711 
02712 
02713 
02714 /*---------------------------------------------------------------------
02715  * copyref 
02716  * copy object at position from to position to 
02717  * without changing data. 
02718  * The copy is only performed if object is a reference 
02719  * and ref object is replaced by its value 
02720  *---------------------------------------------------------------------*/
02721 
02722 int Ref2val(int from , int to ) 
02723 {
02724   integer il,lw;
02725   lw = from + Top - Rhs;
02726   if ( from  > Rhs) {
02727     Scierror(999,"copyref: bad call to isref! (1rst argument)\r\n");
02728     return FALSE_;
02729   }
02730   il = iadr(*Lstk(lw));
02731   if ( *istk(il) < 0) 
02732     {
02733       int lwd ; 
02734       /* from contains a reference */ 
02735       lw= *istk(il+2); 
02736       lwd = to + Top -Rhs;
02737       C2F(copyobj)("copyref", &lw, &lwd, strlen("copyref"));
02738     }
02739   return 0;
02740 }
02741 
02742 /*---------------------------------------------------------------------
02743  * convert2sci : 
02744  *     this routine converts data of variable number num 
02745  *     to scilab standard data code 
02746  *     see how it is used in matdes.c 
02747  *---------------------------------------------------------------------*/
02748 
02749 int C2F(convert2sci)(integer *ix)
02750 {
02751   integer ix1 = Top - Rhs + *ix;
02752   if (! C2F(mvfromto)(&ix1, ix)) return FALSE_;
02753   C2F(intersci).ntypes[*ix - 1] = '$';
02754   return TRUE_;
02755 } 
02756 
02757 
02758 
02759 /*-----------------------------------------------------------
02760  * strcpy_tws : fname[0:nlgh-2]=' '
02761  * fname[nlgh-1] = '\0'
02762  * then second string is copied into first one 
02763  * ------------------------------------------------------------*/
02764 
02765 void strcpy_tws(char *str1,char *str2, int len)
02766 {
02767   int i; 
02768   for ( i =0 ; i  < (int)strlen(str2); i++ ) str1[i]=str2[i];
02769   for (i = strlen(str2) ; i < len ; i++) str1[i]=' ';
02770   str1[len-1] ='\0';
02771 }
02772 
02773 /*---------------------------------------------------------------------
02774  *     conversion from Scilab code --> ascii 
02775  *     + add a 0 at end of string 
02776  *---------------------------------------------------------------------*/
02777 
02778 int C2F(in2str)(integer *n,integer *line,char *str,unsigned long str_len)
02779 {
02780   C2F(codetoascii)(n,line, str, str_len);
02781   str[*n] = '\0';
02782   return 0;
02783 } 
02784 
02785 /*---------------------------------------------------------------------
02786  * Get_Iname: 
02787  * Get the name (interfcae name) which was stored in ids while in checkrhs 
02788  *---------------------------------------------------------------------*/
02789 
02790 static char Fname[nlgh+1];
02791 
02792 static char *Get_Iname() 
02793 {
02794   int i;
02795   C2F(cvname)(&C2F(recu).ids[(C2F(recu).pt + 1) * nsiz - nsiz], Fname, &cx1, nlgh);
02797   for (i=0 ; i < nlgh ; i++) if (Fname[i]==' ') { Fname[i]='\0'; break;} 
02798   Fname[nlgh]='\0'; 
02799   return Fname;
02800 }
02801 
02802 
02803 /*---------------------------------------------------------------------
02804  * Utility for error message 
02805  *---------------------------------------------------------------------*/
02806 
02807 static char *pos[] ={"first","second","third","fourth"};
02808 static char arg_position[56];
02809 
02810 char *ArgPosition(int i)
02811 {
02812   if ( i > 0 && i <= 4 ) 
02813     sprintf(arg_position,"%s argument",pos[i-1]);
02814   else 
02815     sprintf(arg_position,"argument number %d",i);
02816   return arg_position;
02817 }
02818 
02819 char *ArgsPosition(int i,int j)
02820 {
02821   if ( i > 0 && i <= 4 ) 
02822     {
02823       if ( j > 0 && j <= 4 ) 
02824         sprintf(arg_position,"%s and %s arguments",pos[i-1],pos[j-1]);
02825       else 
02826         sprintf(arg_position,"%s argument and argument %d",pos[i-1],j);
02827     }
02828   else 
02829     {
02830       if ( j > 0 && j <= 4 ) 
02831         sprintf(arg_position,"%s argument and argument %d",pos[j-1],i);
02832       else 
02833         sprintf(arg_position,"arguments %d and %d",i,j);
02834     }
02835   return arg_position;
02836 }
02837 
02838 
02839 /*---------------------------------------------------------------------
02840  * Utility for back convertion to Scilab format 
02841  * (can be used with GetListRhsVar ) 
02842  *---------------------------------------------------------------------*/
02843 
02844 void ConvertData(char *type, int size,int l)
02845 {
02846   int zero=0,mu=-1; int laddr; int prov,m,n,it;
02847   double wsave;
02848   switch (type[0]) {
02849   case 'c' :
02850     C2F(cvstr1)(&size,(int *) cstk(l),cstk(l),&zero,size);
02851     break;
02852   case 'r'  :
02853     C2F(rea2db)(&size,sstk(l),&mu,(double *)sstk(l),&mu);
02854     break;
02855   case 'i' :
02856     C2F(int2db)(&size,istk(l),&mu,(double *)istk(l),&mu);
02857     break;
02858   case 'z' :
02859     if (*istk( iadr(iadr(l))-2 ) == 133 ){  /* values @ even adress */
02860       prov=*istk( iadr(iadr(l))-1 );
02861       m=*istk(prov);n=*istk(prov+1);it=1;
02862       laddr=iadr(l);       wsave=*stk(laddr);   
02863       /* make header */
02864       *istk( iadr(iadr(l))-2 ) = 1;
02865       *istk( iadr(iadr(l))-1 ) = m;
02866       *istk( iadr(iadr(l)) ) = n;
02867       *istk( iadr(iadr(l))+1 ) = it;
02868       /* convert values */
02869       z2double(stk(laddr),stk(laddr+1),m*n, m*n);
02870       *stk(laddr+1)=wsave;
02871     } else
02872       {
02873         F77ToSci((double *) zstk(l), size, size);
02874       }
02875   }
02876 }
02877 
02878 /*---------------------------------------------------------------------
02879  * Utility for checking properties 
02880  *---------------------------------------------------------------------*/
02881 
02882 static int check_prop(char *mes,int posi,int m)
02883 {
02884   if ( m ) 
02885     { 
02886       /* XXXX moduler 999 en fn des messages */
02887       Scierror(999,"%s: %s %s\r\n",
02888                Get_Iname(),
02889                ArgPosition(posi),
02890                mes);
02891       return FALSE_;
02892     }
02893   return TRUE_;
02894 }
02895 
02896 int check_square (int posi,int m,int n)
02897 {
02898   return check_prop("should be square",posi, m != n);
02899 }
02900 
02901 int check_vector (int posi,int m,int n)
02902 {
02903   return check_prop("should be a vector",posi, m != 1 && n != 1);
02904 }
02905 
02906 int check_row (int posi,int m,int n)
02907 {
02908   return check_prop("should be a row vector",posi, m != 1);
02909 }
02910 
02911 int check_col (int posi,int m,int n)
02912 {
02913   return check_prop("should be a column vector",posi, n != 1);
02914 }
02915 
02916 int check_scalar (int posi,int m,int n)
02917 {
02918   return check_prop("should be a scalar",posi, n != 1 || m != 1);
02919 }
02920 
02921 int check_dims(int posi,int m,int n,int m1,int n1)
02922 {
02923   if ( m != m1 ||  n != n1 ) 
02924     { 
02925       Scierror(999,"%s: %s has wrong dimensions (%d,%d), expecting (%d,%d)\r\n",
02926                Get_Iname(),
02927                ArgPosition(posi),
02928                m,n,
02929                m1,n1);
02930       return FALSE_;
02931     }
02932   return TRUE_;
02933 }
02934 
02935 int check_one_dim(int posi,int dim,int val,int valref)
02936 {
02937   if ( val != valref) 
02938     { 
02939       Scierror(999,"%s: %s has wrong %s dimension (%d), expecting (%d)\r\n",
02940                Get_Iname(),
02941                ArgPosition(posi),
02942                ( dim == 1 ) ? "first" : "second" ,
02943                val,valref);
02944       return FALSE_;
02945     }
02946   return TRUE_;
02947 }
02948 
02949 int check_length(int posi,int m,int m1)
02950 {
02951   if ( m != m1 )
02952     { 
02953       Scierror(999,"%s: %s has wrong length %d, expecting (%d)\r\n",
02954                Get_Iname(),
02955                ArgPosition(posi),
02956                m, m1);
02957       return FALSE_;
02958     }
02959   return TRUE_;
02960 }
02961 
02962 int check_same_dims(int i,int j,int m1,int n1,int m2,int n2) 
02963 {
02964   if ( m1 == m2 && n1 == n2 ) return TRUE_ ;
02965   Scierror(999,"%s: %s have incompatible dimensions (%dx%d) # (%dx%d)\r\n",
02966            Get_Iname(),
02967            ArgsPosition(i,j),
02968            m1,n1,m2,n2);
02969   return FALSE_;
02970 }
02971 
02972 int check_dim_prop(int i,int j,int flag) 
02973 {
02974   if ( flag ) 
02975     {
02976       Scierror(999,"%s: %s have incompatible dimensions\r\n",
02977                Get_Iname(),
02978                ArgsPosition(i,j));
02979       return FALSE_;
02980     }
02981   return TRUE_;
02982 }
02983  
02984 
02985 static int check_list_prop(char *mes, int lpos,int posi, int m)
02986 {
02987   if ( m ) 
02988     { 
02989       Scierror(999,"%s: %s should be a list with %d-element being %s \r\n",
02990                Get_Iname(),
02991                ArgPosition(posi),
02992                posi,mes);
02993       return FALSE_;
02994     }
02995   return TRUE_;
02996 }
02997 
02998 int check_list_square __PARAMS((int lpos,int posi,int m,int n))
02999 {
03000   return check_list_prop("square",lpos,posi, (m != n));
03001 }
03002 
03003 int check_list_vector (int lpos,int posi,int m,int n) 
03004 {
03005   return check_list_prop("a vector",lpos,posi, m != 1 && n != 1);
03006 }
03007 
03008 int check_list_row (int lpos,int posi,int m,int n) 
03009 {
03010   return check_list_prop("a row vector",lpos,posi, m != 1);
03011 }
03012 
03013 int check_list_col (int lpos,int posi,int m,int n) 
03014 {
03015   return check_list_prop("a column vector",lpos,posi, n != 1);
03016 }
03017 
03018 int check_list_scalar (int lpos,int posi,int m,int n) 
03019 {
03020   return check_list_prop("a scalar",lpos, posi, n != 1 || m != 1);
03021 }
03022 
03023 int check_list_one_dim(int lpos,int posi,int dim,int val,int valref)
03024 {
03025   if ( val != valref) 
03026     { 
03027       Scierror(999,"%s: argument %d(%d) has wrong %s dimension (%d), expecting (%d)\r\n",
03028                Get_Iname(),lpos,posi,
03029                ( dim == 1 ) ? "first" : "second" ,
03030                val,valref);
03031       return FALSE_;
03032     }
03033   return TRUE_;
03034 }
03035 
03036 
03037 
03038 /*---------------------------------------------------------------------
03039  * Utility for hand writen data extraction or creation 
03040  *---------------------------------------------------------------------*/
03041 
03042 int C2F(createdata)(integer *lw, integer n)
03043 {
03044   integer lw1;
03045   char *fname = Get_Iname();
03046   if (*lw > intersiz) {
03047     Scierror(999,"%s: (createdata) too many arguments in the stack edit stack.h and enlarge intersiz\r\n",
03048              fname);
03049     return FALSE_ ;
03050   }
03051   Nbvars = Max(*lw,Nbvars);
03052   lw1 = *lw + Top - Rhs;
03053   if (*lw < 0) {
03054     Scierror(999,"%s: bad call to createdata! (1rst argument)\r\n",
03055              fname);
03056     return FALSE_ ;
03057   }
03058   if (! C2F(credata)(fname, &lw1, n, nlgh))    return FALSE_;
03059   C2F(intersci).ntypes[*lw - 1] = '$';
03060   C2F(intersci).iwhere[*lw - 1] = *Lstk(lw1);
03061   C2F(intersci).lad[*lw - 1] = *Lstk(lw1);
03062   return TRUE_; 
03063 }
03064 
03065 /*---------------------------------------------------------------------
03066  * copyvarfromsciptr 
03067  *     copy a Scilab variable given by 
03068  *      - its first adress l in stk 
03069  *      - its size n
03070  *    to the variable position  lw
03071  *----------------------------------------------------------------------*/
03072 int C2F(copyvarfromsciptr)(integer lw, integer n,integer l)
03073 {
03074   int ret,un=1;
03075   if ((ret=C2F(createdata)(&lw, n))==FALSE_) return ret;
03076   C2F(unsfdcopy)(&n,stk(l),&un,stk(*Lstk(lw + Top - Rhs)),&un);
03077   return TRUE_; 
03078 }
03079  
03080 void *GetData(int lw)
03081      /* Usage: header = (int *) GetData(lw); header[0] = type of variable lw etc */
03082 {
03083   int lw1 = lw + Top - Rhs ;
03084   int l1 = *Lstk(lw1);
03085   int *loci = (int *) stk(l1);
03086   if (loci[0] < 0) 
03087     {
03088       l1 = loci[1];
03089       loci = (int *) stk(l1);
03090     }
03091   C2F(intersci).ntypes[lw - 1] = '$';
03092   C2F(intersci).iwhere[lw - 1] = l1;
03093   C2F(intersci).lad[lw - 1] = l1;
03094   return loci;
03095 }
03096 
03097 int GetDataSize(int lw)
03098      /* get memory used by the argument lw in double world etc */
03099 {
03100   int lw1 = lw + Top - Rhs ;
03101   int l1 = *Lstk(lw1);
03102   int *loci = (int *) stk(l1);
03103   int n =  *Lstk(lw1+1)-*Lstk(lw1);
03104   if (loci[0] < 0) 
03105     {
03106       l1 = loci[1];
03107       loci = (int *) stk(l1);
03108       n=loci[3];
03109     }
03110   return n;
03111 }
03112 
03113 void *GetRawData(int lw)
03114      /* same as GetData BUT does not go to the pointed variable if lw is a reference */
03115 {
03116   int lw1 = lw + Top - Rhs ;
03117   int l1 = *Lstk(lw1);
03118   int *loci = (int *) stk(l1);
03119   C2F(intersci).ntypes[lw - 1] = '$';
03120   C2F(intersci).iwhere[lw - 1] = l1;
03121   /*  C2F(intersci).lad[lw - 1] = l1;  to be checked */
03122   return loci;
03123 }
03124 
03125 void *GetDataFromName( char *name )
03126      /* usage:  header = (int *) GetDataFromName("pipo"); header[0] = type of variable pipo etc... */
03127 {
03128   void *header; int lw; int fin;
03129  if (C2F(objptr)(name,&lw,&fin,strlen(name))) {
03130     header = istk( iadr(*Lstk(fin)));  
03131     return (void *) header;
03132   }
03133  else
03134     {  
03135       Scierror(999,"GetDataFromName: variable %s not found\r\n",name);
03136       return (void *) 0;
03137     }
03138 }
03139 
03140 int C2F(createreference)(int number, int pointed)
03141 /* variable number is created as a reference to variable pointed */
03142 {
03143   int offset; int point_ed; int *header;
03144   CreateData( number, 4*sizeof(int) );
03145   header =  GetRawData(number);
03146   offset = Top -Rhs;
03147   point_ed = offset + pointed;
03148   header[0]= - *istk( iadr(*Lstk( point_ed )) );  /* reference : 1st entry (type) is opposite */
03149   header[1]= *Lstk(point_ed);  /* pointed adress */
03150   header[2]= point_ed; /* pointed variable */
03151   header[3]= *Lstk(point_ed + 1)- *Lstk(point_ed);  /* size of pointed variable */
03152   C2F(intersci).ntypes[number-1]= '-';
03153   return 1;
03154 }
03155 
03156 int C2F(changetoref)(int number, int pointed)
03157 /* variable number is changed as a reference to variable pointed */
03158 {
03159   int offset; int point_ed; int *header;
03160   header =  GetRawData(number);
03161   offset = Top - Rhs;
03162   point_ed = offset + pointed;
03163   header[0]= - *istk( iadr(*Lstk( point_ed )) );  /* reference : 1st entry (type) is opposite */
03164   header[1]= *Lstk(point_ed);  /* pointed adress */
03165   header[2]= pointed; /* pointed variable */
03166   header[3]= *Lstk(point_ed + 1) - *Lstk(point_ed);  /* size of pointed variable */
03167   C2F(intersci).ntypes[number-1]= '-';
03168   return 1;
03169 }
03170 
03171 int C2F(createreffromname)(int number, char *name)
03172      /* variable number is created as a reference pointing to variable "name" */
03173      /* name must be an existing Scilab variable */
03174 {
03175   int *header; int lw; int fin;
03176   CreateData(number, 4*sizeof(int));
03177   header = (int *) GetData(number);
03178   if (C2F(objptr)(name,&lw,&fin,strlen(name))) {
03179     header[0]= - *istk( iadr(*Lstk(fin))); /* type of reference = - type of pointed variable */
03180     header[1]= lw; /* pointed adress */
03181     header[2]= fin; /* pointed variable */
03182     header[3]= *Lstk(fin+1)- *Lstk(fin);  /*size of pointed variable */
03183     return 1;
03184   }
03185   else
03186     {  
03187       Scierror(999,"CreateRefFromName: variable %s not found\r\n",name);
03188       return 0;
03189     }
03190 }
03191 
03192 /*-------------------------------------------------------
03193  * protect the intersci common during recursive calls 
03194  *-------------------------------------------------------*/ 
03195 
03196 typedef struct inter_s_ { 
03197   int iwhere,nbrows,nbcols,itflag,ntypes,lad,ladc,lhsvar;
03198 } intersci_state ;
03199 
03200 typedef struct inter_l {
03201   intersci_state *state ;
03202   int nbvars;
03203   struct inter_l * next ;
03204 } intersci_list ;
03205 
03206 static intersci_list * L_intersci;
03207 
03208 
03209 static int intersci_push(void)
03210 {
03211   int i;
03212   intersci_list *loc;
03213   intersci_state *new ;
03214   new = MALLOC( Nbvars * sizeof(intersci_state) );
03215   if (new == 0 ) return 0;
03216   loc = MALLOC( sizeof(intersci_list) );
03217   if ( loc == NULL ) return 0;
03218   loc->next = L_intersci;
03219   loc->state = new; 
03220   loc->nbvars =  Nbvars;
03221   for ( i = 0 ; i <  Nbvars ; i++ ) 
03222     {
03223       loc->state[i].iwhere = C2F(intersci).iwhere[i];
03224       loc->state[i].ntypes = C2F(intersci).ntypes[i];
03225       loc->state[i].lad    = C2F(intersci).lad[i];
03226       loc->state[i].lhsvar = C2F(intersci).lhsvar[i];
03227     }
03228   L_intersci = loc;
03229   return 1;
03230 }
03231 
03232 static void intersci_pop(void)
03233 {
03234   int i;
03235   intersci_list *loc = L_intersci;
03236   if ( loc == NULL ) return ;
03237   Nbvars =  loc->nbvars;
03238   for ( i = 0 ; i <  Nbvars ; i++ ) 
03239     {
03240       C2F(intersci).iwhere[i] =   loc->state[i].iwhere ;
03241       C2F(intersci).ntypes[i] =   loc->state[i].ntypes ;
03242       C2F(intersci).lad[i] =   loc->state[i].lad    ;
03243       C2F(intersci).lhsvar[i] =   loc->state[i].lhsvar ;
03244     }
03245   L_intersci = loc->next ;
03246   FREE(loc->state);
03247   FREE(loc);
03248 }
03249 
03250 /* 
03251 static void intersci_show()
03252 {
03253   int i;
03254   fprintf(stderr,"======================\n");
03255   for ( i = 0 ; i < C2F(intersci).nbvars ; i++ ) 
03256     {
03257       fprintf(stderr,"%d %d %d\n",i,
03258               C2F(intersci).iwhere[i],
03259               C2F(intersci).ntypes[i]);
03260     }
03261   fprintf(stderr,"======================\n");
03262 }
03263 
03264 */
03265 

Generated on Sun Mar 4 15:03:48 2007 for Scilab [trunk] by  doxygen 1.5.1