/* Example 4b ========= Shows how to implement a Scilab wrapper calling a NAG routine using a User defined function written in Scilab. This requires an special C interface for this second function */ #include "stack-c.h" #undef Complex #define Complex NagComplex #include #include #include #define SciComplex doublecomplex #include "stdio.h" static double fSci(Integer n, double z[], Nag_User *comm); int nag_intext4b(char *fname) { /* to call this function in scilab use: [finval,acc,minpts,fail] = nag_multid_quad_funb(ndim,a,b,minpts,maxpts,eps)*/ 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 l7; int l8; int l9; int l10; int n, i, min, max; Integer ndim, minpts, maxpts; double eps, finval, acc; double *a=0, *b=0; Nag_User comm; 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, "i", &m1, &n1, &l1); /* input ndim */ GetRhsVar(2, "d", &m2, &n2, &l2); /* input a */ GetRhsVar(3, "d", &m3, &n3, &l3); /* input b */ GetRhsVar(4, "i", &m4, &n4, &l4); /* input minpts */ GetRhsVar(5, "i", &m5, &n5, &l5); /* input maxpts */ GetRhsVar(6, "d", &m6, &n6, &l6); /* input eps */ /********************************************************************/ /* Read in input variables from Scilab and convert to NAG variables */ /********************************************************************/ /* Read in ndim */ /**============**/ if (m1!=1 || n1!=1) { sciprint("%s: Dimension should be 1x1 character for arg 1\r\n",fname); Error(999); goto END; } else { n = *istk(l1); ndim = (Integer) n; } /* Allocate memory for a(ndim) and b(ndim)*/ /*========================================*/ if ( !(a = NAG_ALLOC(n,double) ) || !(b = NAG_ALLOC(n,double))) { sciprint("Allocation failure\n"); Error(999); goto END; } /* Read in a */ /*===========*/ if (m2!= n || n2!=1) { sciprint("%s: Dimension should be ndim by 1 for arg 2\r\n",fname); sciprint("n = %i", n); Error(999); goto END; } else { for (i=0; i