#include #include #include "mex.h" #include "opnml_mex5_allocs.c" #define BUFFER_SIZE 72 /************************************************************ #### ## ##### ###### # # ## # # # # # # # # # # # # # # # # # # ##### # # # # # # ### ###### # # # ## # ###### # # # # # # # ## ## # # # #### # # # ###### # # # # # ************************************************************/ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { /* ---- read_ucd_mex will be called as : [et,xt,yt,zt,data]=read_ucd(inpname); I/O argument count has already been checked in the calling routine, read_ucd. The input filename will have to be checked here, though. ------------------------ */ double *x, *y, *z, *dele, *data; int nnd,nne,nnd_data,nne_data,nmodel_data,i,j,**ele; int errflag,strlen,itrash,tcomp,ncomp,*ncompcomp; char *inpname, *line, *cell_type; FILE *fp=NULL, *fopen(); /* ---- extract input filename from first pointer to RHS --------------------------------------- */ strlen=mxGetN(prhs[0])+1; inpname=mxCalloc(strlen,sizeof(char)); if (mxGetString(prhs[0],inpname,strlen)==1) fprintf(stderr,"Input filename string extraction failed in READ_UCD_MEX."); /* ---- Open UCD filename ------------------------------------------- */ if (!(fp = fopen(inpname,"r"))){ fprintf(stderr,"Open of %s failed.\n",inpname); /* Allocate the return matricies as empty [] */ plhs[0]=mxCreateDoubleMatrix(0,0,mxREAL); plhs[1]=mxCreateDoubleMatrix(0,0,mxREAL); plhs[2]=mxCreateDoubleMatrix(0,0,mxREAL); plhs[3]=mxCreateDoubleMatrix(0,0,mxREAL); plhs[4]=mxCreateDoubleMatrix(0,0,mxREAL); return; } /* ---- Read until first line without leading character of "#" ------ */ line=mxCalloc(BUFFER_SIZE,sizeof(char)); fgets(line,BUFFER_SIZE,fp); while (!strncmp(line,"#",1)) fgets(line,BUFFER_SIZE,fp); /* ---- "line" now contains 5 integers embedded in a string They are: nnd, nne, nnd_data, nne_data, nmodel_data ------- */ sscanf(line,"%d %d %d %d %d",&nnd,&nne,&nnd_data,&nne_data,&nmodel_data); /* ---- Allocate space for x,y,z ------------------------------------ */ x= (double *) mxDvector(0,nnd-1); y= (double *) mxDvector(0,nnd-1); z= (double *) mxDvector(0,nnd-1); for(i=0;i