1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
#include <string.h>
#include <stdio.h>
#include "stack-c.h"
/**************************************************
* examples of an hand written interface
* Shows how to pass
* - Scilab complex scalar matrices
* - Scilab boolean matrices
* how to create and return new complex matrices
**************************************************/
static void f99 __PARAMS((double *,double *,int*, int *,int *));
/*------------------------------------------------------
* A complex matrix as argument which is transmited to
* the routine f99, modified and returned back to Scilab.
* When using GetRhsCVar: the returned argument it is
* a flag which indicated the type of the scalar matrix
* it==1 the matrix is complex, it==0 the matrix is real.
* when the matrix is complex on can access the complex part
* through the lc parameter.
* according to the second argument which can be 'i','r','d'
* one access data throug istk, sstk or stk
*------------------------------------------------------*/
int intex2c_1(fname)
char *fname;
{
static int lr1,lc1,it1,m1, n1;
static int minlhs=1, minrhs=1, maxlhs=1, maxrhs=1;
CheckRhs(minrhs,maxrhs) ;
CheckLhs(minlhs,maxlhs) ;
GetRhsCVar(1, "d", &it1, &m1, &n1, &lr1,&lc1);
f99(stk(lr1), stk(lc1), &it1, &m1, &n1);
LhsVar(1) = 1;
return 0;
}
static void f99( ar,ac, ita,ma,na)
int *ma,*na,*ita;
double *ar,*ac;
{
int i;
for ( i= 0 ; i < (*ma)*(*na) ; i++) ar[i] = 2*ar[i] ;
if ( *ita == 1)
for ( i= 0 ; i < (*ma)*(*na) ; i++) ac[i] = 3*ac[i] ;
}
/*------------------------------------------------------
* A complex matrix as argument.
* Here we want to convert the arrays (real,imag) as
* a complex array. This can be done by using 'z' as
* the type-flag of GetRhsCVar or GetRhsVar
* but note that the argument here must be complex.
*------------------------------------------------------*/
static void f99z __PARAMS((doublecomplex *,int m,int n));
int intex2c_2(fname)
char *fname;
{
static int lr1,m1, n1;
static int minlhs=1, minrhs=1, maxlhs=1, maxrhs=1;
doublecomplex *z;
CheckRhs(minrhs,maxrhs) ;
CheckLhs(minlhs,maxlhs) ;
GetRhsVar(1, "z", &m1, &n1, &lr1); /* expecting a complex matrix */
z = zstk(lr1);
f99z(z,m1,n1) ;
LhsVar(1) = 1;
return 0;
}
static void f99z( Z, m,n )
int m,n;
doublecomplex *Z;
{
int i;
for ( i= 0 ; i < m*n ; i++)
{
Z[i].r *= 2.0 ;
Z[i].i *= 3.0 ;
}
}
|