#include #include #include "mex.h" #include "opnml_mex5_allocs.c" /* PROTOTYPES */ #ifdef __STDC__ void bandmsolve_c(int, double **, double *, int, int); void grad(int nn, int ne, double *x, double *y, int *ele, double *q, double *grax, double *gray); #endif /************************************************************ #### ## ##### ###### # # ## # # # # # # # # # # # # # # # # # # ##### # # # # # # ### ###### # # # ## # ###### # # # # # # # ## ## # # # #### # # # ###### # # # # # ************************************************************/ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { int cnt,*ele,i,j,nn,ne; double *x, *y, *q; double *dele; double *grax, *gray; /* ---- gradmex will be called as : [gradx,grady]=gradmex(x,y,ele,q); ------------------------------- */ /* ---- check I/O arguments ----------------------------------------- */ if (nrhs != 4) mexErrMsgTxt("gradmex requires 4 input arguments."); else if (nlhs != 2) mexErrMsgTxt("gradmex requires 2 output arguments."); /* ---- dereference input arrays ------------------------------------ */ x=mxGetPr(prhs[0]); y=mxGetPr(prhs[1]); dele=mxGetPr(prhs[2]); q=mxGetPr(prhs[3]); nn=mxGetM(prhs[0]); ne=mxGetM(prhs[2]); /* ---- allocate space for int representation of dele & convert double element representation to int & shift node numbers toward 0 by 1 for proper indexing -------- */ ele=(int *)mxIvector(0,3*ne); for (i=0;i<3*ne;i++){ ele[i]=(int)dele[i]; ele[i]=ele[i]-1; } /* ---- allocate space for gradient lists following NRC allocation style ------------- */ grax = (double *) mxDvector(0,nn-1); gray = (double *) mxDvector(0,nn-1); /* ---- call gradient routine -------------------------------------- */ grad(nn,ne,x,y,ele,q,grax,gray); /* ---- Set elements of return matricies, pointed to by plhs[0] & plhs[1] ---------------------------- */ plhs[0]=mxCreateDoubleMatrix(nn,1,mxREAL); mxSetPr(plhs[0],grax); plhs[1]=mxCreateDoubleMatrix(nn,1,mxREAL); mxSetPr(plhs[1],gray); /* --- No need to free memory allocated with "mxCalloc"; MATLAB does this automatically. The CMEX allocation functions in "opnml_allocs.c" use mxCalloc. ----------------------------------- */ return; } /*---------------------------------------------------------------------- #### ##### ## ##### # # # # # # # # # # # # # # # # ### ##### ###### # # # # # # # # # # #### # # # # ##### ----------------------------------------------------------------------*/ void grad(int nn,int ne, double *x, double *y, int *ele, double *q, double *grax, double *gray) #define ELE(i,j,m) ele[i+m*j] #define DZILCH (double)0. { double *ar,**av,**dx,**dy; double area6,area12; int i,j,l,m,n; int nbw=0, nh=0, nhm=0, l01, l02, l12; /* ---- Compute half bandwidth -------------------------------------- */ for (i=0;i