stack3.c

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------
00002  *    Graphic library
00003  *    Copyright (C) 1998-2000 Enpc/Inria 
00004  *    2003 JPC Enpc
00005  *        2007 Allan CORNET INRIA
00006  --------------------------------------------------------------------------*/
00007 /*------------------------------------------------------
00008  * Read and Write inside the Scilab stack 
00009  *------------------------------------------------------*/
00010 
00011 #include <string.h>
00012 #include "stack3.h"
00013 #include "stack-c.h"
00014 
00015 extern int C2F(dmcopy)  __PARAMS((double *a, integer *na, double *b, integer *nb, integer *m, integer *n));
00016 extern int C2F(stackg)  __PARAMS((integer *id));
00017 extern int C2F(stackp)  __PARAMS((integer *id, integer *macmod));
00018 
00019 /*------------------------------------------------------*/
00020 void *Name2ptr(char *namex);
00021 int Name2where(char *namex);
00022 
00023 /* Table of constant values */
00024 
00025 static integer cx0 = 0;
00026 static integer cx1 = 1;
00027 
00028 /*------------------------------------------------------
00029  * read a matrix 
00030  *------------------------------------------------------*/
00031 
00032 int C2F(readmat)(char *namex,integer *m, integer *n, double *scimat, unsigned long name_len)
00033 {
00034     int j;
00035     j = C2F(creadmat)(namex, m, n, scimat, name_len);
00036     return 0;
00037 }
00038 
00039 /*----------------------------------------------------------------
00040  * readmat reads vector/matrix in scilab's internal stack 
00041  * calling sequence 
00042  *     logic=creadmat('matrixname',m,n,scimat) 
00043  *  matrixname: character string; name of the scilab variable. 
00044  *  m: number of rows (output of readmat) 
00045  *  n: number of columns (output of readmat) 
00046  *  scimat: matrix entries stored columnwise (output of readmat) 
00047  *    Example of use: 
00048  *    Amat is a real 2 x 3 scilab matrix 
00049  *    your subroutine should be as follows: 
00050  *    subroutine mysubr(...) 
00051  *    ... 
00052  *    call readmat('Amat',m,n,scimat) 
00053  *    => m=3 , n=2, and scimat(1)=Amat(1,1) 
00054  *                      scimat(2)=Amat(2,1) 
00055  *                      scimat(3)=Amat(3,1) 
00056  *                      scimat(4)=Amat(1,2) ... 
00057  *                      scimat(5)=Amat(3,2) 
00058  *                      scimat(6)=Amat(3,2) 
00059  *----------------------------------------------------------------*/
00060 
00061 int C2F(creadmat)(char *namex, integer *m, integer *n, double *scimat, unsigned long name_len)
00062 {
00063     integer l;
00064     integer id[nsiz];
00065 
00066     C2F(str2name)(namex, id, name_len);
00067     /* read   : from scilab stack -> fortran variable */
00068     Fin = -1;
00069     C2F(stackg)(id);
00070     if (Err > 0) return FALSE_ ; 
00071     if (Fin == 0) {
00072       Scierror(4,"Undefined variable %s\r\n",get_fname(namex,name_len));
00073       return FALSE_;
00074     }
00075     if ( *Infstk(Fin ) == 2)  Fin = *istk(iadr(*Lstk(Fin )) + 1 +1);
00076     /* get matrix data pointer */
00077     if (! C2F(getrmat)("creadmat", &Fin, &Fin, m, n, &l, 8L))   return FALSE_;
00078 
00079     C2F(dmcopy)(stk(l ), m, scimat, m, m, n);
00080 
00081     return TRUE_;
00082 }
00083 /*----------------------------------------------------------------
00084  * creadcmat reads vector/matrix in scilab's internal stack 
00085  * calling sequence 
00086  *     logic=creadcmat('matrixname',m,n,scimat) 
00087  *  matrixname: character string; name of the scilab variable. 
00088  *  m: number of rows (output of readmat) 
00089  *  n: number of columns (output of readmat) 
00090  *  scimat: matrix entries stored columnwise (output of readmat) 
00091  *    Example of use: 
00092  *    Amat is a real 2 x 3 scilab matrix 
00093  *    your subroutine should be as follows: 
00094  *    subroutine mysubr(...) 
00095  *    ... 
00096  *    call readmat('Amat',m,n,scimat) 
00097  *    => m=3 , n=2, and scimat(1)=Amat(1,1) 
00098  *                      scimat(2)=Amat(2,1) 
00099  *                      scimat(3)=Amat(3,1) 
00100  *                      scimat(4)=Amat(1,2) ... 
00101  *                      scimat(5)=Amat(3,2) 
00102  *
00103  * Note d'Albert Y
00104  * 20/12/2003
00105  *    Cette routine est une simple copie de creadmat et légèrement
00106  *    modifiée pour les matrices complexes
00107  *
00108  *----------------------------------------------------------------*/
00109 
00110 int C2F(creadcmat)(char *namex, integer *m, integer *n, double *scimat, unsigned long name_len)
00111 {
00112     integer l, ix1;
00113     integer id[nsiz];
00114 
00115     C2F(str2name)(namex, id, name_len);
00116     /* read   : from scilab stack -> fortran variable */
00117     Fin = -1;
00118     C2F(stackg)(id);
00119     if (Err > 0) return FALSE_ ; 
00120     if (Fin == 0) {
00121       Scierror(4,"Undefined variable %s\r\n",get_fname(namex,name_len));
00122       return FALSE_;
00123     }
00124     if ( *Infstk(Fin ) == 2)  Fin = *istk(iadr(*Lstk(Fin )) + 1 +1);
00125     /* get matrix data pointer */
00126     if (! C2F(getcmat)("creadcmat", &Fin, &Fin, m, n, &l, 8L))  return FALSE_;
00127     ix1 = *m * *n;
00128     C2F(dmcopy)(stk(l ), m, scimat, m, m, n);
00129     C2F(dmcopy)(stk(l+ix1 ), m, scimat+ix1, m, m, n);
00130 
00131     return TRUE_;
00132 }
00133 
00134 /*----------------------------------------------------------------
00135  * cwritemat writes vector/matrix in scilab's internal stack
00136  * logic=cwritemat('matrixname'//char(0),m,n,mat)
00137  * name: character string; name of the scilab variable ( null terMinated) 
00138  * m: number of rows 
00139  * n: number of columns 
00140  * mat: matrix entries stored columnwise in Scilab object
00141 ----------------------------------------------------------------*/
00142 
00143 int C2F(cwritemat)(char *namex, integer *m, integer *n,  double *mat, unsigned long name_len)
00144 {
00145   integer   ix1 = *m * *n;
00146   integer Rhs_k = Rhs , Top_k = Top ;
00147   integer l4, id[nsiz], lc, lr;
00148   
00149   C2F(str2name)(namex, id, name_len);
00150   /* jpc april 2002 */ 
00151   /* ++Top; */
00152   Top = Top + Nbvars + 1; 
00153   if (! C2F(cremat)("cwritemat", &Top, &cx0, m, n, &lr, &lc, 9L)) return  FALSE_;
00154   C2F(dcopy)(&ix1, mat, &cx1, stk(lr ), &cx1);
00155   Rhs = 0;
00156   l4 = C2F(iop).lct[3];
00157   C2F(iop).lct[3] = -1;
00158   C2F(stackp)(id, &cx0);
00159   C2F(iop).lct[3] = l4;
00160   Top = Top_k;
00161   Rhs = Rhs_k;
00162   if (Err > 0)  return FALSE_;
00163   return TRUE_;
00164 } 
00165 
00166 
00167 /*-----------------------------------------------------------------------------------*/
00176 /*-----------------------------------------------------------------------------------*/
00177 int C2F(cwritecmat)(char *namex,integer *m, integer*n,double *mat,unsigned long name_len)
00178 {
00179         integer   ix1 = *m * *n *2; /* real part + imaginary part */
00180         integer Rhs_k = Rhs , Top_k = Top ;
00181         integer l4, id[nsiz], lc, lr;
00182         int IT=1; /* Type Complex */
00183 
00184         C2F(str2name)(namex, id, name_len);
00185         
00186         Top = Top + Nbvars + 1; 
00187         if (! C2F(cremat)("cwritecmat", &Top, &IT, m, n, &lr, &lc, 10L)) return  FALSE_;
00188         C2F(dcopy)(&ix1, mat, &cx1, stk(lr ), &cx1);
00189         Rhs = 0;
00190         l4 = C2F(iop).lct[3];
00191         C2F(iop).lct[3] = -1;
00192         C2F(stackp)(id, &cx0);
00193         C2F(iop).lct[3] = l4;
00194         Top = Top_k;
00195         Rhs = Rhs_k;
00196         if (Err > 0)  return FALSE_;
00197         return TRUE_;
00198 } 
00199 /*-----------------------------------------------------------------------------------*/
00200  /* Put variable number into Scilab internal stack with name "namex" */
00201 int C2F(putvar)(int  *number,char *namex,  unsigned long name_len)
00202 {
00203   integer Rhs_k = Rhs , Top_k = Top ;
00204   integer l4, id[nsiz],/* lc, lr,*/ cx0_2=1;
00205   
00206   C2F(str2name)(namex, id, name_len);
00207   Top = *number + Top -Rhs;
00208   Rhs = 0;
00209   l4 = C2F(iop).lct[3];
00210   C2F(iop).lct[3] = -1;
00211   C2F(stackp)(id, &cx0_2);
00212   C2F(iop).lct[3] = l4;
00213   Top = Top_k;
00214   Rhs = Rhs_k;
00215   if (Err > 0)  return FALSE_;
00216   return TRUE_;
00217 } 
00218 
00219 /*------------------------------------------------------
00220  *     see creadchain 
00221  *------------------------------------------------------*/
00222 
00223 int C2F(readchain)(char *namex,  integer *itslen, char *chai,  unsigned long name_len, unsigned long chai_len)
00224 {
00225     int j;
00226     j = C2F(creadchain)(namex, itslen, chai, name_len, chai_len);
00227     return 0;
00228 } 
00229 
00230 /*------------------------------------------------------
00231  *     this routine reads a string in scilab's  memory 
00232  *     and store it into chai 
00233  * !calling sequence 
00234  *     integer       itslen 
00235  *     character*(*) chai,name 
00236  *     name    : character string = name of scilab variable (input) 
00237  *     chai    : chain to be read (output) 
00238  *               null terMinated 
00239  *     itslen  : (input) Maximum number of character that can ne stored 
00240  *               in chain 
00241  *               (output) number of copied characters into chai 
00242  *     if Scilab variable x='qwert' exists 
00243  *     character ch*(10) 
00244  *     l=10 
00245  *     logic= creadchain('x',l,ch) returns l=5 and ch='qwert' 
00246  *------------------------------------------------------*/
00247 
00248 int C2F(creadchain)(char *namex,  integer *itslen,  char *chai,  unsigned long name_len,  unsigned long chai_len)
00249 {
00250     integer ix1;
00251     integer m1, n1;
00252     integer id[nsiz];
00253     integer lr1;
00254     integer nlr1;
00255 
00256     Err = 0;
00257     C2F(str2name)(namex, id, name_len);
00258     Fin = -1;
00259     C2F(stackg)(id);
00260     if (Err > 0) return FALSE_ ;
00261     if (Fin == 0) {
00262       Scierror(4,"Undefined variable %s\r\n",get_fname(namex,name_len));
00263       return FALSE_ ;
00264     }
00265     if (*Infstk(Fin ) == 2) {
00266         Fin = *istk(iadr(*Lstk(Fin )) + 1 +1);
00267     }
00268     if (! C2F(getsmat)("creadchain", &Fin, &Fin, &m1, &n1, &cx1, &cx1, &lr1, &nlr1, 10L)) {
00269         return FALSE_;
00270     }
00271     if (m1 * n1 != 1) {
00272       Scierror(999,"creadchain: argument must be a string\r\n");
00273       return FALSE_ ;
00274     }
00275 
00276     ix1 = *itslen - 1;
00277     *itslen = Min(ix1,nlr1);
00278     C2F(cvstr)(itslen, istk(lr1 ), chai, &cx1, chai_len);
00279     chai[*itslen] = '\0';
00280     return TRUE_ ;
00281 }
00282 
00283 /*----------------------------------------------------------------------
00284  *     this routine reads name(ir,ic) in scilab's  memory 
00285  *     and store it into chai 
00286  *     if ir=ic=-1 on entry then the routines returns in ir,ic 
00287  *     the size of the matrix 
00288  * !calling sequence 
00289  *     integer       itslen 
00290  *     character*(*) chai,name 
00291  *     name    : character string = name of scilab variable (input) 
00292  *     chai    : chain to be read (output) 
00293  *               null terMinated 
00294  *     itslen  : (input) Maximum number of character that can be stored 
00295  *               in chain 
00296  *               (output) number of copied characters into chai 
00297  *     if Scilab variable x='qwert' exists 
00298  *     character ch*(10) 
00299  *     l=10 
00300  *     logic= creadchain('x',l,ch) returns l=5 and ch='qwert' 
00301  *----------------------------------------------------------------------*/
00302 
00303 
00304 int C2F(creadchains)(char *namex, integer *ir, integer *ic, integer *itslen, char *chai, unsigned long name_len,  unsigned long chai_len)
00305 {
00306     integer ix1;
00307     integer m1, n1;
00308     integer id[nsiz];
00309     integer lr1;
00310     integer nlr1;
00311 
00312     Err = 0;
00313     C2F(str2name)(namex, id, name_len);
00314     Fin = -1;
00315     C2F(stackg)(id);
00316     if (Err > 0) return FALSE_ ;
00317 
00318     if (Fin == 0) {
00319       Scierror(4,"Undefined variable %s\r\n",get_fname(namex,name_len));
00320       return FALSE_ ;
00321     }
00322 
00323     if (*Infstk(Fin ) == 2) {
00324         Fin = *istk(iadr(*Lstk(Fin )) + 1 +1);
00325     }
00326     if (*ir == -1 && *ic == -1) {
00327         if (! C2F(getsmat)("creadchain", &Fin, &Fin, ir, ic, &cx1, &cx1, &lr1, &nlr1, 10L)) 
00328           return FALSE_;
00329         else 
00330           return TRUE_ ; 
00331     } else {
00332         if (! C2F(getsmat)("creadchain", &Fin, &Fin, &m1, &n1, ir, ic, &lr1, &nlr1, 10L)) {
00333           return FALSE_;
00334         }
00335     }
00336     ix1 = *itslen - 1;
00337     *itslen = Min(ix1,nlr1);
00338     C2F(cvstr)(itslen, istk(lr1 ), chai, &cx1, chai_len);
00339     chai[*itslen]='\0';
00340     return TRUE_;
00341 }
00342 
00343 /*----------------------------------------------------------------
00344  *     cwritemat writes vector/matrix in scilab's internal stack 
00345  *     logic=cwritemat('matrixname'//char(0),m,n,mat) 
00346  *  name: character string; name of the scilab variable ( null terMinated) 
00347  *  m: number of rows 
00348  *  n: number of columns 
00349  *  mat: matrix entries stored columnwise in Scilab object 
00350  *----------------------------------------------------------------*/
00351 
00352 int C2F(cwritechain)(char *namex, integer *m, char *chai, unsigned long name_len, unsigned long chai_len)
00353 {
00354     integer Rhs_k, Top_k;
00355     integer l4;
00356     integer id[nsiz], lr;
00357     C2F(str2name)(namex, id, name_len);
00358     Top_k = Top;
00359     /* jpc april 2002 */ 
00360     /* ++Top; */
00361     Top = Top + Nbvars + 1; 
00362     if (! C2F(cresmat2)("cwritechain", &Top, m, &lr, 11L)) {
00363         return FALSE_;
00364     }
00365     C2F(cvstr)(m, istk(lr ), chai, &cx0, chai_len);
00366     Rhs_k = Rhs;
00367     Rhs = 0;
00368     l4 = C2F(iop).lct[3];
00369     C2F(iop).lct[3] = -1;
00370     C2F(stackp)(id, &cx0);
00371     C2F(iop).lct[3] = l4;
00372     Top = Top_k ;
00373     Rhs = Rhs_k ;
00374     if (Err > 0)  return FALSE_;
00375     return TRUE_ ;
00376 }
00377 
00378 /*----------------------------------------------------------------
00379  *     see cmatptr 
00380  *----------------------------------------------------------------*/
00381 
00382 int C2F(matptr)(char *namex, integer *m, integer *n, integer *lp, unsigned long name_len)
00383 {
00384     int ix;
00385     ix = C2F(cmatptr)(namex, m, n, lp, name_len);
00386     return 0;
00387 } 
00388 
00389 /*----------------------------------------------------------------
00390  * !purpose 
00391  *     matptr returns the adress of real matrix "name" 
00392  *     in scilab's internal stack 
00393  *     m=number of rows 
00394  *     n=number of columns 
00395  *     stk(lp),stk(lp+1),...,stk(lp+m*n-1)= entries (columnwise) 
00396  *     If matrix "name" not in Scilab stack, returns m=n=-1. 
00397  *    Example of use: 
00398  *    Amat is a real 2 x 3 scilab matrix 
00399  *    your subroutine should be as follows: 
00400  *    subroutine mysubr(...) 
00401  *    ... 
00402  *    logic= cmatptr('Amat',m,n,lp) 
00403  *    => m=3 , n=2, and stk(lp)=Amat(1,1) 
00404  *                      stk(lp+1)=Amat(2,1) 
00405  *                      stk(lp+2)=Amat(3,1) 
00406  *                      stk(lp+3)=Amat(1,2) ... 
00407  *                      stk(lp+5)=Amat(3,2) 
00408  *   see example in fydot.f file 
00409  *   see also  readmat.f, matz.f 
00410  *----------------------------------------------------------------*/
00411 
00412 int C2F(cmatptr)(char *namex, integer *m,integer *n,integer *lp, unsigned long name_len)
00413 {
00414     integer id[nsiz];
00415     C2F(str2name)(namex, id, name_len);
00416     /* get the position in fin */
00417     Fin = -1;
00418     C2F(stackg)(id);
00419     if (Fin == 0) {
00420       Scierror(4,"Undefined variable %s\r\n",get_fname(namex,name_len));
00421       *m = -1;
00422       *n = -1;
00423       return FALSE_;
00424     }
00425     /* get data */
00426     if (*Infstk(Fin ) == 2) {
00427         Fin = *istk(iadr(*Lstk(Fin )) + 1 +1);
00428     }
00429     if (! C2F(getrmat)("creadmat", &Fin, &Fin, m, n, lp, 8L)) {
00430         return FALSE_;
00431     }
00432     return TRUE_ ;
00433 }
00434 
00435 /*----------------------------------------------------------------
00436  * !purpose 
00437  *     cmatcptr returns the adress of complex matrix "name" 
00438  *     in scilab's internal stack 
00439  *     m=number of rows 
00440  *     n=number of columns 
00441  *     stk(lp),stk(lp+1),...,stk(lp+m*n-1)= entries (columnwise) 
00442  *     If matrix "name" not in Scilab stack, returns m=n=-1. 
00443  *    Example of use: 
00444  *    Amat is a real 2 x 3 scilab matrix 
00445  *    your subroutine should be as follows: 
00446  *    subroutine mysubr(...) 
00447  *    ... 
00448  *    logic= cmatptr('Amat',m,n,lp) 
00449  *    => m=3 , n=2, and stk(lp)=Amat(1,1) 
00450  *                      stk(lp+1)=Amat(2,1) 
00451  *                      stk(lp+2)=Amat(3,1) 
00452  *                      stk(lp+3)=Amat(1,2) ... 
00453  *                      stk(lp+5)=Amat(3,2) 
00454  *   see example in fydot.f file 
00455  *   see also  readmat.f, matz.f
00456  * 
00457  * Note d'Albert Y
00458  * 20/12/2003
00459  *    Cette routine est une simple copie de creadmat et légèrement
00460  *    modifiée pour les matrices complexes
00461  *
00462  *----------------------------------------------------------------*/
00463 
00464 int C2F(cmatcptr)(char *namex, integer *m, integer *n, integer *lp, unsigned long name_len)
00465 {
00466     integer id[nsiz];
00467     C2F(str2name)(namex, id, name_len);
00468     /* get the position in fin */
00469     Fin = -1;
00470     C2F(stackg)(id);
00471     if (Fin == 0) {
00472       Scierror(4,"Undefined variable %s\r\n",get_fname(namex,name_len));
00473       *m = -1;
00474       *n = -1;
00475       return FALSE_;
00476     }
00477     /* get data */
00478     if (*Infstk(Fin ) == 2) {
00479         Fin = *istk(iadr(*Lstk(Fin )) + 1 +1);
00480     }
00481     if (! C2F(getcmat)("creadmat", &Fin, &Fin, m, n, lp, 8L)) {
00482         return FALSE_;
00483     }
00484     return TRUE_ ;
00485 }
00486 
00487 /*----------------------------------------------------------------
00488  * !purpose 
00489  *     matptr returns the adress of real matrix "name" 
00490  *     in scilab's internal stack 
00491  *     m=number of rows 
00492  *     n=number of columns 
00493  *     stk(lp),stk(lp+1),...,stk(lp+m*n-1)= entries (columnwise) 
00494  *     If matrix "name" not in Scilab stack, returns m=n=-1. 
00495  *    Example of use: 
00496  *    Amat is a real 2 x 3 scilab matrix 
00497  *    your subroutine should be as follows: 
00498  *    subroutine mysubr(...) 
00499  *    ... 
00500  *    logic= cmatptr('Amat',m,n,lp) 
00501  *    => m=3 , n=2, and stk(lp)=Amat(1,1) 
00502  *                      stk(lp+1)=Amat(2,1) 
00503  *                      stk(lp+2)=Amat(3,1) 
00504  *                      stk(lp+3)=Amat(1,2) ... 
00505  *                      stk(lp+5)=Amat(3,2) 
00506  *   see example in fydot.f file 
00507  *   see also  readmat.f, matz.f 
00508  *----------------------------------------------------------------*/
00509 
00510 int C2F(cmatsptr)(char *namex, integer *m, integer *n,integer *ix,integer *j,integer *lp,integer *nlr, unsigned long name_len)
00511 {
00512     integer id[nsiz];
00513     C2F(str2name)(namex, id, name_len);
00514     /* get the position in fin */
00515     Fin = -1;
00516     C2F(stackg)(id);
00517     if (Fin == 0) {
00518       Scierror(4,"Undefined variable %s\r\n",get_fname(namex,name_len));
00519       *m = -1;
00520       *n = -1;
00521       return FALSE_;
00522     }
00523     /* get data */
00524     if (*Infstk(Fin ) == 2) {
00525         Fin = *istk(iadr(*Lstk(Fin )) + 1 +1);
00526     }
00527     if (! C2F(getsmat)("creadmat", &Fin, &Fin, m, n, ix, j, lp, nlr, 8L)) {
00528         return FALSE_;
00529     }
00530     return TRUE_ ;
00531 }
00532 
00533 /*  Returns a pointer to the Scilab variable with name namex
00534         Usage:   int *header;
00535         header = (int *) Name2ptr("pipo");
00536         header[0], header[1], etc contains header info 
00537         about Scilab variable "pipo"   
00538 */
00539 void *Name2ptr(char *namex)
00540 {
00541   int l1; int *loci;
00542   integer id[nsiz];
00543   C2F(str2name)(namex, id, strlen(namex));
00544   /* get the position in fin */
00545   Fin = -1;
00546   C2F(stackg)(id);
00547   if (Fin == 0) {
00548     Scierror(4,"Undefined variable %s\r\n",get_fname(namex,strlen(namex)));
00549     return 0;
00550   }
00551   /* get data */
00552   if (*Infstk(Fin ) == 2) {
00553     Fin = *istk(iadr(*Lstk(Fin )) + 1 +1);
00554   }
00555   loci = (int *) stk(*Lstk(Fin));
00556   if (loci[0] < 0) 
00557     {
00558       l1 = loci[1];
00559       loci = (int *) stk(l1);
00560     }
00561   return loci;
00562 }
00563 
00564 
00565 /* returns the position in the internal stack of the variable with name
00566    namex 
00567    Usage:
00568    int l=Name2where("pipo");
00569    stk(l) points to Scilab variable named "pipo"
00570    e.g. if pipo is a standard real matrix
00571    stk(l)[2]=first entry of the matrix pipo(1,1)
00572    stk(l)[3]=pipo(2,1)  etc
00573    (The header of pipo is given by istk(iadr(h))[0], 
00574    istk(iadr(h))[1], etc )
00575 */
00576 int Name2where(char *namex)
00577 {
00578   int loci;
00579   integer id[nsiz];
00580   C2F(str2name)(namex, id, strlen(namex));
00581   /* get the position in fin */
00582   Fin = -1;
00583   C2F(stackg)(id);
00584   if (Fin == 0) {
00585     Scierror(4,"Undefined variable %s\r\n",get_fname(namex,strlen(namex)));
00586     return 0;
00587   }
00588   loci = *Lstk(Fin);
00589   return loci;
00590 }
00591 
00592 /*----------------------------------------------------------------
00593  *     string conversion to Scilab ID 
00594  *     Warning : the character name is null terMinated 
00595  *             and len(name) is not used 
00596  *             since it can be wrong (ex when name is transmited 
00597  *             by fort (intfort : function )
00598  *----------------------------------------------------------------*/
00599 
00600 int C2F(str2name)(char *namex, integer *id, unsigned long name_len)
00601 {
00602     integer ix;
00603     integer lon;
00604     lon = 0;
00605     for (ix = 0 ; ix < (integer) name_len ; ix++ ) {
00606       if ( namex[ix] == '\0') break;
00607       ++lon;
00608     }
00609     C2F(cvname)(id, namex, &cx0, lon);
00610     return 0;
00611 } 
00612 
00613 /*----------------------------------------------------------------
00614  *     objptr returns the adress of "name" 
00615  *     in scilab's internal stack 
00616  *----------------------------------------------------------------*/
00617 
00618 int C2F(objptr)(char *namex, integer *lp, integer *fin, unsigned long name_len)
00619 {
00620     integer id[nsiz];
00621     *lp = 0;
00622     /*     ---- get the id */
00623     C2F(str2name)(namex, id, name_len);
00624     /*     ---- get the position in fin */
00625     Fin = -1;
00626     C2F(stackg)(id);
00627     if (Fin == 0) {
00628       C2F(putid)(&C2F(recu).ids[(C2F(recu).pt + 1) * nsiz - nsiz], id);
00629       /*         we juste return false and lp is set to zero */
00630       /*         call error(4) */
00631       return FALSE_;
00632     }
00633     *fin = Fin;
00634     *lp = *Lstk(Fin );
00635     if (*Infstk(Fin ) == 2) {
00636         *lp = *Lstk(*istk(iadr(*lp) + 1 +1) );
00637     }
00638     return  TRUE_;
00639 }
00640 /*-----------------------------------------------------------------------------------*/
00641 /* read and write a boolean matrix in scilab stack */
00642 /*-----------------------------------------------------------------------------------*/
00643 int C2F(creadbmat)(char *namex, integer *m, integer *n, int *scimat, unsigned long name_len)
00644 {
00645         integer l = 0;
00646         integer id[nsiz];
00647         int c_x = 1;
00648         int N = 0;
00649 
00650         C2F(str2name)(namex, id, name_len);
00651         /* read   : from scilab stack -> fortran variable */
00652         Fin = -1;
00653         C2F(stackg)(id);
00654         if (Err > 0) return FALSE_ ; 
00655         if (Fin == 0) {
00656                 Scierror(4,"Undefined variable %s\r\n",get_fname(namex,name_len));
00657                 return FALSE_;
00658         }
00659         if ( *Infstk(Fin ) == 2)  Fin = *istk(iadr(*Lstk(Fin )) + 1 +1);
00660 
00661         /* get matrix data pointer */
00662         if (! C2F(getbmat)("creadbmat", &Fin, &Fin, m, n, &l , 9L))     return FALSE_;
00663 
00664         N = *n * *m;
00665         C2F(icopy)(&N,istk(l),&c_x,scimat,&c_x);
00666 
00667         return TRUE_;
00668 }
00669 /*-----------------------------------------------------------------------------------*/
00670 int C2F(cwritebmat)(char *namex, integer *m, integer *n,  int *mat, unsigned long name_len)
00671 {
00672         integer   ix1 = *m * *n;
00673         integer Rhs_k = Rhs , Top_k = Top ;
00674         integer l4, id[nsiz], lr;
00675 
00676         C2F(str2name)(namex, id, name_len);
00677         Top = Top + Nbvars + 1; 
00678         if (! C2F(crebmat)("cwritebmat", &Top, m, n, &lr, 10L)) return  FALSE_;
00679 
00680         C2F(icopy)(&ix1, mat, &cx1, istk(lr ), &cx1);
00681         Rhs = 0;
00682         l4 = C2F(iop).lct[3];
00683         C2F(iop).lct[3] = -1;
00684         C2F(stackp)(id, &cx0);
00685         C2F(iop).lct[3] = l4;
00686         Top = Top_k;
00687         Rhs = Rhs_k;
00688         if (Err > 0)  return FALSE_;
00689         return TRUE_;
00690 
00691 }
00692 /*-----------------------------------------------------------------------------------*/
00693 int C2F(cmatbptr)(char *namex, integer *m,integer *n,integer *lp, unsigned long name_len)
00694 {
00695         integer id[nsiz];
00696         C2F(str2name)(namex, id, name_len);
00697         /* get the position in fin */
00698         Fin = -1;
00699         C2F(stackg)(id);
00700         if (Fin == 0) 
00701         {
00702                 Scierror(4,"Undefined variable %s\r\n",get_fname(namex,name_len));
00703                 *m = -1;
00704                 *n = -1;
00705                 return FALSE_;
00706         }
00707         /* get data */
00708         if (*Infstk(Fin ) == 2) 
00709         {
00710                 Fin = *istk(iadr(*Lstk(Fin )) + 1 +1);
00711         }
00712 
00713         if (! C2F(getbmat)("creadbmat", &Fin, &Fin, m, n, lp , 9L))     return FALSE_;
00714         
00715         return TRUE_ ;
00716 }
00717 
00718 /*-----------------------------------------------------------------------------------*/
00726 int getlengthchain(char *namex)
00727 {
00728         int retLength = -1;
00729 
00730         integer m1, n1;
00731         integer id[nsiz];
00732         integer lr1;
00733         integer nlr1;
00734         unsigned long name_len= strlen(namex);
00735 
00736         Err = 0;
00737         C2F(str2name)(namex, id, name_len);
00738         Fin = -1;
00739         C2F(stackg)(id);
00740         if (Err > 0)  return -1;
00741         if (Fin == 0) return -1;
00742 
00743 
00744         if (*Infstk(Fin ) == 2) 
00745         {
00746                 Fin = *istk(iadr(*Lstk(Fin )) + 1 +1);
00747         }
00748 
00749         if (! C2F(getsmat)("getlengthchain", &Fin, &Fin, &m1, &n1, &cx1, &cx1, &lr1, &nlr1, 14L)) return -1;
00750 
00751         if (m1 * n1 != 1)  return -1;
00752         retLength = nlr1;
00753 
00754         return retLength;
00755 
00756 }
00757 /*-----------------------------------------------------------------------------------*/

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