#include #include #include "mex.h" #include "opnml_mex5_allocs.c" /* PROTOTYPES */ void bandmsolve_c(int, double **, double *, int, int); void divg(int nn, int ne, double *x, double *y, int *ele, double *u, double *v, double *dv); /************************************************************ #### ## ##### ###### # # ## # # # # # # # # # # # # # # # # # # ##### # # # # # # ### ###### # # # ## # ###### # # # # # # # ## ## # # # #### # # # ###### # # # # # ************************************************************/ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { int cnt,*ele,i,j,nn,ne; double *x, *y, *u, *v; double *dele; double *dv; /* ---- divgmex will be called as : dv=divg(x,y,ele,u,v); ------------------------------- */ /* ---- check I/O arguments ----------------------------------------- */ if (nrhs != 5) mexErrMsgTxt("DIVG requires 5 input arguments."); else if (nlhs != 1) mexErrMsgTxt("DIVG requires 1 output arguments."); /* ---- dereference input arrays ------------------------------------ */ x=mxGetPr(prhs[0]); y=mxGetPr(prhs[1]); dele=mxGetPr(prhs[2]); u=mxGetPr(prhs[3]); v=mxGetPr(prhs[4]); 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 divergence list dv following NRC allocation style ------------- */ dv = (double *) mxDvector(0,nn-1); /* ---- call divergence routine ------------------------------------ */ divg(nn,ne,x,y,ele,u,v,dv); /* ---- Set elements of return matrix, pointed to by plhs[0] -------- */ plhs[0]=mxCreateDoubleMatrix(nn,1,mxREAL); mxSetPr(plhs[0],dv); /* --- No need to free memory allocated with "mxCalloc"; MATLAB does this automatically. The CMEX allocation functions in "opnml_allocs.c" use mxCalloc. ----------------------------------- */ return; } /*---------------------------------------------------------------------- ##### # # # #### # # # # # # # # # # # # # # # # # # # ### # # # # # # # ##### # ## #### ----------------------------------------------------------------------*/ void divg(int nn,int ne, double *x, double *y, int *ele, double *u, double *v, double *dv) #define ELE(i,j,m) ele[i+m*j] { double *ar,**av,**dx,**dy; double area6,area12; int i,j,l,m,n; int nbw=0, nh=0, nhm=0, n0 ,n1, n2, l01, l02, l12; /* ---- Compute half bandwidth -------------------------------------- */ for (i=0;i