intex17c.c

Go to the documentation of this file.
00001 #include <string.h>
00002 
00003 #include "stack-c.h"
00004 
00005 typedef void (*voidf)();
00006 
00007 typedef struct {
00008   char *name;
00009   voidf f;
00010 } FTAB;
00011 
00012 /*******************************************
00013  * Table of predefined functions f1c and f2c
00014  *******************************************/
00015 
00016 #define ARGS_ex17c double,double, double *
00017 
00018 typedef int (*funcex) __PARAMS((ARGS_ex17c));
00019 extern int f1c __PARAMS((ARGS_ex17c));
00020 extern int f2c __PARAMS((ARGS_ex17c));
00021 extern int ex17c __PARAMS((double *,integer ,double *,integer,double *, funcex));
00022  
00023 FTAB FTab_ex17c[] ={
00024   {"f1c", (voidf) f1c},
00025   {"f2c", (voidf) f2c},
00026   {(char *) 0, (voidf) 0}};
00027 
00028 /***************************************************
00029  * deal with errors in scilab functions 
00030  ***************************************************/
00031 
00032 #include <setjmp.h>
00033 static  jmp_buf ex17cenv; 
00034 
00035 /***************************************************
00036  * data for interface 
00037  ***************************************************/
00038 
00039 static int sci_f, lhs_f, rhs_f;
00040 
00041 /***************************************************
00042  * Functions 
00043  ***************************************************/
00044 
00045 static int sciex17c __PARAMS((ARGS_ex17c));
00046 static funcex Argex17c;
00047 
00048 /***************************************************
00049  * intex17c interface for ex17c 
00050  ***************************************************/
00051 
00052 int intex17c(fname) 
00053      char *fname;
00054 { 
00055   int returned_from_longjump ;
00056   int m_X,n_X,l_X,m_Y,n_Y,l_Y,m_Z,n_Z,l_Z;
00057   static int minlhs=1, minrhs=3, maxlhs=1, maxrhs=3;
00058 
00059   /*   Check rhs and lhs   */  
00060   CheckRhs(minrhs,maxrhs) ;
00061   CheckLhs(minlhs,maxlhs) ;
00062 
00063   /*   Variable #1 (X = real vector)   */
00064   GetRhsVar(1, "d", &m_X, &n_X, &l_X);
00065 
00066   /*   Variable #2 (Y = real vector)   */
00067   GetRhsVar(2, "d", &m_Y, &n_Y, &l_Y);
00068 
00069   /*   Variable #3 (f = "argument function")   */
00070   /*   ex17c(X,Y,f) 
00071    *   if f is a string we search for f in Tables and on succes 
00072    *         Argex17c will be the function to be called  
00073    *   if f is a macro then sciex17c will be called (see its definition bellow) 
00074    *         returned arguments are sci_f, lhs_f, rhs_f 
00075    *         function position in the stack sci_f required lhs and rhs in lhs_f, rhs_f 
00076    *         (we do not use lhs_f and rhs_f in this example)
00077    */
00078 
00079   Argex17c  = (funcex) GetFuncPtr("ex17c", 3, FTab_ex17c, (voidf) sciex17c, &sci_f, &lhs_f, &rhs_f);
00080   if ( Argex17c == (funcex) 0 ) return 0;
00081   
00082   m_Z= m_X*n_X;  n_Z= m_Y*n_Y;
00083 
00084   /*  Creating the output variable Z (#4) , real matrix variable with m_Z rows and n_Z columns    */
00085 
00086   CreateVar(4, "d", &m_Z, &n_Z, &l_Z);
00087   
00088   /* If an error occurs while Z is calculated ... */
00089 
00090   if (( returned_from_longjump = setjmp(ex17cenv)) != 0 )
00091     {
00092       Scierror(999,"%s: Internal error \r\n",fname);
00093       return 0;
00094     } 
00095   
00096   /*  Now matrix Z is populated i.e. appropriate values are 
00097    *  assigned to stk(l_Z)[0] ( = Z(1,1) ), stk(l_Z)[1]  ( = Z(2,1) ), ... 
00098    */
00099 
00100   ex17c(stk(l_X), m_X*n_X, stk(l_Y), m_Y*n_Y, stk(l_Z), Argex17c);
00101 
00102   /*  Variable #4 is returned to Scilab  */
00103   LhsVar(1) = 4;
00104   return 0;
00105 }
00106 
00107 /*---------------------------------------------------------------
00108  *  Computing z=f(x,y), f being the Scilab argument function 
00109  * C function emulating the Scilab function pointed to by sci_f 
00110  *---------------------------------------------------------------*/
00111 
00112 static int sciex17c(x, y, z)
00113      double x, y, *z;
00114 {
00115   static int lhs=1,rhs=2;
00116   int scilab_i,scilab_j, un=1;
00117   /* Inputs (x(i),y(j)) at positions  (5,6) */
00118   CreateVar(5, "d", &un, &un, &scilab_i);
00119   stk(scilab_i)[0] = x;
00120 
00121   CreateVar(6, "d", &un, &un, &scilab_j);
00122   stk(scilab_j)[0] = y;
00123 
00124   /* executes the Scilab function (f) pointed to by sci_f. 
00125    * we provide a rhs=2 and expect lhs = 1 
00126    */
00127   PExecSciFunction(5, &sci_f, &lhs, &rhs, "ArgFex", ex17cenv);
00128   /* One output at position of first input (5) */
00129   *z = *stk(scilab_i);
00130   return 0;
00131 }
00132 
00133 
00134 
00135 
00136 

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