/* Example 3 ========= Shows how to implement a Scilab wrapper calling in Complex matrix arguments and characters */ #include "stack-c.h" #undef Complex #define Complex NagComplex #include #include #include #define SciComplex doublecomplex #include "stdio.h" // Macros to allow matrix notation in the code. // Here the matrices are accessed in row order due to working in C #define A_NAG(I,J) a_nag[(I)*n + J] #define AMAT(I,J) amat[I*n + J] #define V_NAG(I,J) v_nag[(I)*n + J] #define VMAT(I,J) vmat[(I)*n + J] int nag_intext3(char *fname) { // to call this function in scilab use: // [w,v,m,ifail] = nag_cmplx_eisys_sel_fun(crit,n,a,wl,wu,mest) int m1,n1,l1; int m2,n2,l2; int m3,n3,l3; int m4,n4,l4; int m5,n5,l5; int m6,n6,l6; int m7,n7,l7; int m8,n8,l8; int m9,n9,l9; int m10, n10, l10; int n, tda, mest,i,j, tdv; Integer m; double wl, wu; char crit; SciComplex *amat=0, *vmat=0, *wmat=0; NagComplex *a_nag=0, *v_nag=0, *w_nag=0; Nag_Select_Eigenvalues crit_nag; NagError ifail; // define minimum and maximum left and right hand arguments int minlhs=1, minrhs=6, maxlhs=4, maxrhs=6; Nbvars = 0; CheckRhs(minrhs, maxrhs); CheckLhs(minlhs,maxlhs); // Initialise ifail INIT_FAIL(ifail); GetRhsVar(1, "c", &m1, &n1, &l1); // input crit GetRhsVar(2, "i", &m2, &n2, &l2); // input n GetRhsVar(3, "z", &m3, &n3, &l3); // input a GetRhsVar(4, "d", &m4, &n4, &l4); // input wl GetRhsVar(5, "d", &m5, &n5, &l5); // input wu GetRhsVar(6, "i", &m6, &n6, &l6); // input mest // Allocate memory for a_nag and amat if ( !(a_nag = NAG_ALLOC(m3*n3,NagComplex) ) || !(amat = NAG_ALLOC(m3*n3,SciComplex))) { sciprint("Allocation failure\n"); Error(999); goto END; } //****************************************************************** // Read in input variables from Scilab and convert to NAG variables //****************************************************************** // Read in crit //*============* if (m1!=1 || n1!=1) { sciprint("%s: Dimension should be 1x1 character for arg 1\r\n",fname); Error(999); goto END; } else { crit = *cstk(l1); if (crit == 'r' || crit == 'R') { crit_nag = Nag_Select_RealPart; } else if( crit == 'm' || crit == 'M') { crit_nag = Nag_Select_Modulus; } else { sciprint("%s: Arg 1 should be either 'r' or 'm'. \r\n",fname); Error(999); goto END; } } // Read in n //=========== if (m2!=1 || n2!=1) { sciprint("%s: Dimension should be 1x1 for arg 2\r\n",fname); Error(999); goto END; } else { n = *istk(l2); } // Read in amat //============== if (m3!=n || n3!=n) { sciprint("%s: Dimension should be nxn for arg 3\r\n",fname); Error(999); goto END; } else { // Convert Complex data types Scilab to NAG // Matrices are stored in column order in Scilab for(i=0; i