intex1c.c

Go to the documentation of this file.
00001 #include "stack-c.h"
00002 
00003 extern int ex1c __PARAMS((char *ch, int *a, int *ia, float *b, int *ib, double *c, int *mc, int *nc, double *d, double *w, int *err));
00004 
00005 
00006 /**************************************************
00007  * An example of an hand written interface 
00008  * the interface program is intex1c, the
00009  * associated scilab function is ex1c
00010  **************************************************/
00011 
00012 int intex1c(fname) 
00013      char *fname;
00014 {
00015   int i1, i2;
00016   static int ierr;
00017   static int l1, m1, n1, m2, n2, l2, m3, n3, l3, m4, n4, l4, l5, l6;
00018   static int minlhs=1, minrhs=4, maxlhs=5, maxrhs=4;
00019 
00020   CheckRhs(minrhs,maxrhs) ;
00021   CheckLhs(minlhs,maxlhs) ;
00022   /*  1-Get the 4 input variables of ex1f:
00023    *
00024    * Variable #1 is a chain ("c") , GetRhsVar returns its
00025    * dimensions: m1 = # of rows = length of the chain, 
00026    * n1 = # of columns = 1 default value for chains.
00027    * The chain starts at cstk(l1)  
00028    */
00029   GetRhsVar(1, "c", &m1, &n1, &l1);
00030 
00031   /*  a=variable #2 is an integer ('i') matrix, getrhsvar returns its
00032    *   dimensions: m2 = # of rows , n2 = # of columns
00033    * values in matrix a are istk(l2), istk(l2+1), ... (columnwise) 
00034    */
00035   GetRhsVar(2, "i", &m2, &n2, &l2);
00036 
00037   /*  b=variable #3 is an real ('r') matrix, getrhsvar returns its
00038    * dimensions: m3 = # of rows , n3 = # of columns
00039    * values in matrix a are sstk(l2), sstk(l2+1), ... (columnwise) 
00040    */
00041 
00042   GetRhsVar(3, "r", &m3, &n3, &l3);
00043 
00044   /*  c=variable #4 is an double ('d') matrix, getrhsvar returns its
00045    * dimensions: m4 = # of rows , n4 = # of columns
00046    *  values in matrix a are stk(l2), stk(l2+1), ... (columnwise)  
00047    */
00048   
00049   GetRhsVar(4, "d", &m4, &n4, &l4);
00050 
00051   /*  2-Create  Scilab variable #5  as double matrix of
00052    *  dimensions  m4 x n4. The first fourth parameters of
00053    *  Createvar are input parameters. Createvar returns the adress l5
00054    *  as output. 
00055    *  The values of stk(l5), stk(l5+1), ... should be set
00056    *  to desired values.  
00057    */
00058 
00059   CreateVar(5, "d", &m4, &n4, &l5);
00060   CreateVar(6, "d", &m4, &n4, &l6);
00061 
00062   i1 = n2 * m2;
00063   i2 = n3 * m3;
00064 
00065   ex1c( cstk(l1),istk(l2), &i1, sstk(l3), &i2, stk(l4), 
00066              &m4, &n4, stk(l5),stk(l6), &ierr);
00067   
00068   if (ierr > 0) 
00069     {
00070       Scierror(999,"%s: Internal error \r\n",fname);
00071       return 0;
00072     }
00073   
00074   /*   Variables #5, #4, #3, #2, #1 are returned in that
00075    *   order. For instance, w=ex1f('chain',a,b,c) puts
00076    *   in w the variable #5 and [w,r]=ex1f('chain',a,b,c)
00077    *   puts in w the variable #5 and in r the variable #4  
00078    */
00079 
00080   LhsVar(1) = 5;
00081   LhsVar(2) = 4;
00082   LhsVar(3) = 3;
00083   LhsVar(4) = 2;
00084   LhsVar(5) = 1;
00085   return 0;
00086 }
00087 
00088 
00089 /**************************************************
00090  *     inputs:  ch, a,b and c; ia,ib and mc,nc 
00091  *     ch=character, a=integer, b=float and c=double 
00092  *     ia,ib and [mc,nc] are the dimensions of a,b and c resp. 
00093  *     outputs: a,b,c,d 
00094  *     if ch='mul'   a,b and c = 2 * (a,b and c) 
00095  *     and d of same dimensions as c with 
00096  *     d(i,j)=(i+j)*c(i,j) 
00097  *     if ch='add' a,b and c = 2 + (a,b and c) 
00098  *     d(i,j)=(i+j)+c(i,j) 
00099  *     w is a working array of size [mc,nc] 
00100  *********************************************/
00101 
00102 int ex1c(ch, a, ia, b, ib, c, mc, nc, d, w, err)
00103      char *ch;     int *a, *ia;     float *b;
00104      int *ib;     double *c;     int *mc, *nc;
00105      double *d, *w;     int *err;
00106 {
00107   static int i, j, k;
00108   *err = 0;
00109   if (strcmp(ch, "mul") == 0) 
00110     {
00111       for (k = 0 ; k < *ib; ++k) 
00112         a[k] <<= 1;
00113       for (k = 0; k < *ib ; ++k) 
00114         b[k] *= (float)2.;
00115       for (i =  0 ; i < *mc ; ++i) 
00116         for (j = 0 ;  j < *nc ; ++j) 
00117           c[i + j *(*mc) ] *= 2.;
00118       for (i = 0 ; i < *mc ; ++i) 
00119         for (j = 0 ; j < *nc ; ++j) 
00120             {
00121               w[i + j * (*mc) ] = (double) (i + j);
00122               d[i + j * (*mc) ] = w[i + j *(*mc)] * c[i + j *(*mc)];
00123             }
00124     } 
00125   else if (strcmp(ch, "add") == 0) 
00126     {
00127       for (k = 0; k < *ia ; ++k) 
00128         a[k] += 2;
00129       for (k = 0 ; k < *ib ; ++k) 
00130         b[k] += (float)2.;
00131       for (i =  0 ; i < *mc ; ++i) 
00132         for (j = 0 ;  j < *nc ; ++j) 
00133           c[i + j *(*mc) ] += 2.;
00134       for (i = 0 ; i < *mc ; ++i) 
00135         for (j = 0 ; j < *nc ; ++j) 
00136             {
00137               w[i + j * (*mc) ] = (double) (i + j);
00138               d[i + j * (*mc) ] = w[i + j *(*mc)] + c[i + j *(*mc)];
00139             }
00140     } 
00141   else 
00142     {
00143       *err = 1;
00144     }
00145   return(0);
00146 }
00147 
00148 
00149 
00150 
00151 
00152 
00153 

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