void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { double *prec,*eoutr,*eouti; int mrows,ncols; char *input_buf; char *w1,*w2; int buflen,status; mpfr_t xr,xi,yr,yi,zr,zi,temp,temp1; mp_exp_t expptr; /* Check for proper number of arguments. */ if(nrhs!=5) { mexErrMsgTxt("5 inputs required."); } else if(nlhs>4) { mexErrMsgTxt("Too many output arguments"); } /* The input must be a noncomplex scalar double.*/ mrows = mxGetM(prhs[0]); ncols = mxGetN(prhs[0]); if( !mxIsDouble(prhs[0]) || mxIsComplex(prhs[0]) || !(mrows==1 && ncols==1) ) { mexErrMsgTxt("Input must be a noncomplex scalar double."); } /* Set precision and initialize mpfr variables */ prec = mxGetPr(prhs[0]); mpfr_set_default_prec(*prec); mpfr_init(xr); mpfr_init(xi); mpfr_init(yr); mpfr_init(yi); mpfr_init(zr); mpfr_init(zi); mpfr_init(temp); mpfr_init(temp1); /* Read the input strings into mpfr x real */ buflen = (mxGetM(prhs[1]) * mxGetN(prhs[1])) + 1; input_buf=mxCalloc(buflen, sizeof(char)); status = mxGetString(prhs[1], input_buf, buflen); mpfr_set_str(xr,input_buf,10,GMP_RNDN); /* Read the input strings into mpfr x imag */ buflen = (mxGetM(prhs[2]) * mxGetN(prhs[2])) + 1; input_buf=mxCalloc(buflen, sizeof(char)); status = mxGetString(prhs[2], input_buf, buflen); mpfr_set_str(xi,input_buf,10,GMP_RNDN); /* Read the input strings into mpfr y real */ buflen = (mxGetM(prhs[3]) * mxGetN(prhs[3])) + 1; input_buf=mxCalloc(buflen, sizeof(char)); status = mxGetString(prhs[3], input_buf, buflen); mpfr_set_str(yr,input_buf,10,GMP_RNDN); /* Read the input strings into mpfr y imag */ buflen = (mxGetM(prhs[4]) * mxGetN(prhs[4])) + 1; input_buf=mxCalloc(buflen, sizeof(char)); status = mxGetString(prhs[4], input_buf, buflen); mpfr_set_str(yi,input_buf,10,GMP_RNDN); /* Mathematical operation */ /* denominator */ mpfr_mul(temp,yr,yr,GMP_RNDN); mpfr_mul(temp1,yi,yi,GMP_RNDN); mpfr_add(temp,temp,temp1,GMP_RNDN); /* real part */ mpfr_mul(temp1,xr,yr,GMP_RNDN); mpfr_mul(zr,xi,yi,GMP_RNDN); mpfr_add(zr,temp1,zr,GMP_RNDN); /* imag part */ mpfr_mul(temp1,xi,yr,GMP_RNDN); mpfr_mul(zi,xr,yi,GMP_RNDN); mpfr_sub(zi,temp1,zi,GMP_RNDN); /* divide by denominator */ mpfr_div(zr,zr,temp,GMP_RNDN); mpfr_div(zi,zi,temp,GMP_RNDN); /* Retrieve results */ mxFree(input_buf); input_buf=mpfr_get_str (NULL, &expptr, 10, 0, zr, GMP_RNDN); w1=malloc(strlen(input_buf)+20); w2=malloc(strlen(input_buf)+20); if (strncmp(input_buf, "-", 1)==0){ strcpy(w2,&input_buf[1]); sprintf(w1,"-.%se%i",w2,expptr); } else { strcpy(w2,&input_buf[0]); sprintf(w1,"+.%se%i",w2,expptr); } plhs[0] = mxCreateString(w1); /* plhs[1] = mxCreateDoubleMatrix(mrows,ncols, mxREAL); */ /* eoutr=mxGetPr(plhs[1]); */ /* *eoutr=expptr; */ mpfr_free_str(input_buf); input_buf=mpfr_get_str (NULL, &expptr, 10, 0, zi, GMP_RNDN); free(w1); free(w2); w1=malloc(strlen(input_buf)+20); w2=malloc(strlen(input_buf)+20); if (strncmp(input_buf, "-", 1)==0){ strcpy(w2,&input_buf[1]); sprintf(w1,"-.%se%i",w2,expptr); } else { strcpy(w2,&input_buf[0]); sprintf(w1,"+.%se%i",w2,expptr); } plhs[1] = mxCreateString(w1); /* plhs[3] = mxCreateDoubleMatrix(mrows,ncols, mxREAL); */ /* eouti=mxGetPr(plhs[3]); */ /* *eouti=expptr; */ mpfr_clear(xr); mpfr_clear(xi); mpfr_clear(yr); mpfr_clear(yi); mpfr_clear(zr); mpfr_clear(zi); mpfr_clear(temp); mpfr_clear(temp1); mpfr_free_str(input_buf); free(w1); free(w2); }
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { int display=0, from=0, to=0; long *lpenv=NULL, *p_lp=NULL; CPXENVptr env = NULL; CPXLPptr lp = NULL; int status ; if (nrhs > 5 || nrhs < 1) { mexErrMsgTxt("Usage: [how] " "= lp_delrows(lpenv,p_lp,from,to,disp)"); return; } switch (nrhs) { case 5: if (mxGetM(prhs[4]) != 0 || mxGetN(prhs[4]) != 0) { if (!mxIsNumeric(prhs[4]) || mxIsComplex(prhs[4]) || mxIsSparse(prhs[4]) || !(mxGetM(prhs[4])==1 && mxGetN(prhs[4])==1)) { mexErrMsgTxt("5th argument (display) must be " "an integer scalar."); return; } display = *mxGetPr(prhs[4]); } case 4: if (mxGetM(prhs[3]) != 0 || mxGetN(prhs[3]) != 0) { if (!mxIsNumeric(prhs[3]) || mxIsComplex(prhs[3]) || mxIsSparse(prhs[3]) || !(mxGetM(prhs[3])==1 && mxGetN(prhs[3])==1)) { mexErrMsgTxt("4th argument (display) must be " "an integer scalar."); return; } to = *mxGetPr(prhs[3]); } case 3: if (mxGetM(prhs[2]) != 0 || mxGetN(prhs[2]) != 0) { if (!mxIsNumeric(prhs[2]) || mxIsComplex(prhs[2]) || mxIsSparse(prhs[2]) || !(mxGetM(prhs[2])==1 && mxGetN(prhs[2])==1)) { mexErrMsgTxt("3rd argument (display) must be " "an integer scalar."); return; } from = *mxGetPr(prhs[2]); } case 2: if (mxGetM(prhs[1]) != 0 || mxGetN(prhs[1]) != 0) { if (!mxIsNumeric(prhs[1]) || mxIsComplex(prhs[1]) || mxIsSparse(prhs[1]) || !mxIsDouble(prhs[1]) || mxGetN(prhs[1])!=1 ) { mexErrMsgTxt("2nd argument (p_lp) must be " "a column vector."); return; } if (1 != mxGetM(prhs[1])) { mexErrMsgTxt("Dimension error (arg 2)."); return; } p_lp = (long*) mxGetPr(prhs[1]); } case 1: if (mxGetM(prhs[0]) != 0 || mxGetN(prhs[0]) != 0) { if (!mxIsNumeric(prhs[0]) || mxIsComplex(prhs[0]) || mxIsSparse(prhs[0]) || !mxIsDouble(prhs[0]) || mxGetN(prhs[0])!=1 ) { mexErrMsgTxt("1st argument (lpenv) must be " "a column vector."); return; } if (1 != mxGetM(prhs[0])) { mexErrMsgTxt("Dimension error (arg 1)."); return; } lpenv = (long*) mxGetPr(prhs[0]); } } if (nlhs > 1 || nlhs < 1) { mexErrMsgTxt("Usage: [how] " "= lp_delrows(lpenv,p_lp,from,to,disp)"); return; } if (display>3) fprintf(STD_OUT, "(from=%i, to=%i) \n", from, to) ; if (display>2) fprintf(STD_OUT, "argument processing finished\n") ; /* Initialize the CPLEX environment */ env = (CPXENVptr) lpenv[0] ; lp=(CPXLPptr)p_lp[0] ; if (display>2) fprintf(STD_OUT, "calling CPXdelrows\n") ; status = CPXdelrows(env, lp, (int)from, (int)to); if ( status ) { fprintf (STD_OUT, "CPXdelrows failed.\n"); goto TERMINATE; } TERMINATE: if (status) { char errmsg[1024]; CPXgeterrorstring (env, status, errmsg); fprintf (STD_OUT, "%s", errmsg); if (nlhs >= 1) plhs[0] = mxCreateString(errmsg) ; } else if (nlhs >= 1) plhs[0] = mxCreateString("OK") ; ; return ; }
void mexFunction(int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[]) { double *c=NULL, *b=NULL, *A=NULL, *Q=NULL, *H=NULL, *l=NULL, *u=NULL, *x=NULL, *lambda=NULL, *x0=NULL, *primal=NULL, *dual=NULL; double *tmpdp=NULL; double big=Inf; unsigned int neq=0; long nmat=0, mmat=0; long how=0; int i; unsigned int verb = 0; double sigfig_max = 8; int counter_max = 100000; double margin = 0.95; double bound = 10; int restart = 0; static char *str[] = { "STILL_RUNNING", "OPTIMAL_SOLUTION", "SUBOPTIMAL_SOLUTION", "ITERATION_LIMIT", "PRIMAL_INFEASIBLE", "DUAL_INFEASIBLE", "PRIMAL_AND_DUAL_INFEASIBLE", "INCONSISTENT", "PRIMAL_UNBOUNDED", "DUAL_UNBOUNDED", "TIME_LIMIT"}; if (nrhs > 9 || nrhs < 1) { mexErrMsgTxt("Usage: [x,lambda,how] = qp(H,c,A,b,l,u,x0,neqcstr,verbosity)"); return; } switch (nrhs) { case 9: if (mxGetM(prhs[8]) != 0 || mxGetN(prhs[8]) != 0) { if (!mxIsNumeric(prhs[8]) || mxIsComplex(prhs[8]) || mxIsSparse(prhs[8]) || !(mxGetM(prhs[8])==1 && mxGetN(prhs[8])==1)) { mexErrMsgTxt("Ninth argument (display) must be " "an integer scalar."); return; } verb = (unsigned int)*mxGetPr(prhs[8]); } case 8: if (mxGetM(prhs[7]) != 0 || mxGetN(prhs[7]) != 0) { if (!mxIsNumeric(prhs[7]) || mxIsComplex(prhs[7]) || mxIsSparse(prhs[7]) || !(mxGetM(prhs[7])==1 && mxGetN(prhs[7])==1)) { mexErrMsgTxt("Eighth argument (neqcstr) must be " "an integer scalar."); return; } neq = (unsigned int)*mxGetPr(prhs[7]); } case 7: if (mxGetM(prhs[6]) != 0 || mxGetN(prhs[6]) != 0) { if (!mxIsNumeric(prhs[6]) || mxIsComplex(prhs[6]) || mxIsSparse(prhs[6]) || !mxIsDouble(prhs[6]) || mxGetN(prhs[6])!=1 ) { mexErrMsgTxt("Seventh argument (x0) must be " "a column vector."); return; } x0 = mxGetPr(prhs[6]); nmat = mxGetM(prhs[6]); } case 6: if (mxGetM(prhs[5]) != 0 || mxGetN(prhs[5]) != 0) { if (!mxIsNumeric(prhs[5]) || mxIsComplex(prhs[5]) || mxIsSparse(prhs[5]) || !mxIsDouble(prhs[5]) || mxGetN(prhs[5])!=1 ) { mexErrMsgTxt("Sixth argument (u) must be " "a column vector."); return; } if (nmat != 0 && nmat != mxGetM(prhs[5])) { mexErrMsgTxt("Dimension error (arg 6 and later)."); return; } u = mxGetPr(prhs[5]); nmat = mxGetM(prhs[5]); } case 5: if (mxGetM(prhs[4]) != 0 || mxGetN(prhs[4]) != 0) { if (!mxIsNumeric(prhs[4]) || mxIsComplex(prhs[4]) || mxIsSparse(prhs[4]) || !mxIsDouble(prhs[4]) || mxGetN(prhs[4])!=1 ) { mexErrMsgTxt("Fifth argument (l) must be " "a column vector."); return; } if (nmat != 0 && nmat != mxGetM(prhs[4])) { mexErrMsgTxt("Dimension error (arg 5 and later)."); return; } l = mxGetPr(prhs[4]); nmat = mxGetM(prhs[4]); } case 4: if (mxIsEmpty(prhs[3])) { /* No Constraints*/ mmat = 0; } else { /*Constraints*/ if (mxGetM(prhs[3]) != 0 || mxGetN(prhs[3]) != 0) { if (!mxIsNumeric(prhs[3]) || mxIsComplex(prhs[3]) || mxIsSparse(prhs[3]) || !mxIsDouble(prhs[3]) || mxGetN(prhs[3])!=1 ) { mexErrMsgTxt("Fourth argument (b) must be " "a column vector."); return; } if (mmat != 0 && mmat != mxGetM(prhs[3])) { mexErrMsgTxt("Dimension error (arg 4 and later)."); return; } b = mxGetPr(prhs[3]); } } case 3: if (mxIsEmpty(prhs[2])) { /* No Constraints */ if (mmat != 0) { mexErrMsgTxt("Dimension error (arg 3 and later)."); return; } } else { /* Constraints */ if (mxGetM(prhs[2]) != 0 || mxGetN(prhs[2]) != 0) { if (!mxIsNumeric(prhs[2]) || mxIsComplex(prhs[2]) || mxIsSparse(prhs[2]) ) { mexErrMsgTxt("Third argument (A) must be " "a matrix."); return; } if (mmat != 0 && mmat != mxGetM(prhs[2])) { mexErrMsgTxt("Dimension error (arg 3 and later)."); return; } if (nmat != 0 && nmat != mxGetN(prhs[2])) { mexErrMsgTxt("Dimension error (arg 3 and later)."); return; } mmat = mxGetM(prhs[2]); nmat = mxGetN(prhs[2]); A = mxGetPr(prhs[2]); } } tmpdp = (double *)malloc((nmat+mmat)*sizeof(double)); for(i=0;i<nmat;i++) tmpdp[i] = (l[i] < -Inf ? -Inf : l[i]); l = tmpdp; tmpdp = (double *)malloc((nmat+mmat)*sizeof(double)); for(i=0;i<nmat;i++) tmpdp[i] = (u[i] > Inf ? Inf : u[i]); u = tmpdp; for(i=nmat;i<(int)(nmat+neq);i++) { l[i] = u[i] = 0; } for(i=nmat + neq;i<nmat+mmat;i++) { l[i] = -Inf; u[i] = 0; } case 2: if (mxGetM(prhs[1]) != 0 || mxGetN(prhs[1]) != 0) { if (!mxIsNumeric(prhs[1]) || mxIsComplex(prhs[1]) || mxIsSparse(prhs[1]) || !mxIsDouble(prhs[1]) || mxGetN(prhs[1])!=1 ) { mexErrMsgTxt("Second argument (c) must be " "a column vector."); return; } if (nmat != 0 && nmat != mxGetM(prhs[1])) { mexErrMsgTxt("Dimension error (arg 2 and later)."); return; } c = mxGetPr(prhs[1]); nmat = mxGetM(prhs[1]); } case 1: if (mxIsEmpty(prhs[0])) { H = (double *)calloc(nmat*nmat,sizeof(double)); } else { if (mxGetM(prhs[0]) != 0 || mxGetN(prhs[0]) != 0) { if (!mxIsNumeric(prhs[0]) || mxIsComplex(prhs[0]) || mxIsSparse(prhs[0]) ) { mexErrMsgTxt("First argument (H) must be " "a matrix."); return; } if (nmat != 0 && nmat != mxGetM(prhs[0])) { mexErrMsgTxt("Dimension error (arg 1 and later)."); return; } if (nmat != 0 && nmat != mxGetN(prhs[0])) { mexErrMsgTxt("Dimension error (arg 1 and later)."); return; } nmat = mxGetN(prhs[0]); Q = mxGetPr(prhs[0]); H = (double *)calloc(nmat*nmat,sizeof(double)); for(i=0;i<nmat*nmat;i++) H[i] = Q[i]; } } break; } if (nlhs > 3 || nlhs < 1) { mexErrMsgTxt("Usage: [x,lambda,how] = qp(H,c,A,b,l,u,x0,neqcstr,verbosity)"); return; } primal = (double *)calloc((3*nmat),sizeof(double)); dual = (double *)calloc((mmat+2*nmat),sizeof(double)); how = pr_loqo(nmat, mmat, c, H, A, b, l, u, primal, dual, verb, sigfig_max, counter_max, margin, bound, restart); switch (nlhs) { case 3: plhs[2] = mxCreateString(str[how]); case 2: plhs[1] = mxCreateDoubleMatrix(mmat, 1, mxREAL); lambda = mxGetPr(plhs[1]); for(i=0; i<mmat; i++) lambda[i] = dual[i]; case 1: plhs[0] = mxCreateDoubleMatrix(nmat, 1, mxREAL); x = mxGetPr(plhs[0]); for(i=0; i<nmat; i++) x[i] = primal[i]; break; } /* Free up memory */ free(l); free(u); free(primal); free(dual); free(H); }
mxArray *sf_c14_ARP_02_RPSs_Bdr_GK_BIS5_get_autoinheritance_info(void) { const char *autoinheritanceFields[] = { "checksum", "inputs", "parameters", "outputs", "locals" }; mxArray *mxAutoinheritanceInfo = mxCreateStructMatrix(1,1,5, autoinheritanceFields); { mxArray *mxChecksum = mxCreateString("fbs1NXNu3p3DqJAjoWAIqB"); mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum); } { const char *dataFields[] = { "size", "type", "complexity" }; mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields); { mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL); double *pr = mxGetPr(mxSize); pr[0] = (double)(1); pr[1] = (double)(1); mxSetField(mxData,0,"size",mxSize); } { const char *typeFields[] = { "base", "fixpt" }; mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields); mxSetField(mxType,0,"base",mxCreateDoubleScalar(10)); mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL)); mxSetField(mxData,0,"type",mxType); } mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0)); mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData); } { mxSetField(mxAutoinheritanceInfo,0,"parameters",mxCreateDoubleMatrix(0,0, mxREAL)); } { const char *dataFields[] = { "size", "type", "complexity" }; mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields); { mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL); double *pr = mxGetPr(mxSize); pr[0] = (double)(1); pr[1] = (double)(1); mxSetField(mxData,0,"size",mxSize); } { const char *typeFields[] = { "base", "fixpt" }; mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields); mxSetField(mxType,0,"base",mxCreateDoubleScalar(10)); mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL)); mxSetField(mxData,0,"type",mxType); } mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0)); mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData); } { mxSetField(mxAutoinheritanceInfo,0,"locals",mxCreateDoubleMatrix(0,0,mxREAL)); } return(mxAutoinheritanceInfo); }
MxArray::MxArray(const std::string& s) : p_(mxCreateString(s.c_str())) { if (!p_) mexErrMsgIdAndTxt("mexopencv:error", "Allocation error"); }
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { double *prec,*eout; int mrows,ncols; char *input_buf; char *w1,*w2; int buflen,status; mpfr_t x,y,z; mp_exp_t expptr; /* Check for proper number of arguments. */ if(nrhs!=2) { mexErrMsgTxt("2 inputs required."); } else if(nlhs>1) { mexErrMsgTxt("Too many output arguments"); } /* The input must be a noncomplex scalar double.*/ mrows = mxGetM(prhs[0]); ncols = mxGetN(prhs[0]); if( !mxIsDouble(prhs[0]) || mxIsComplex(prhs[0]) || !(mrows==1 && ncols==1) ) { mexErrMsgTxt("Input must be a noncomplex scalar double."); } /* Set precision and initialize mpfr variables */ prec = mxGetPr(prhs[0]); mpfr_set_default_prec(*prec); mpfr_init(x); mpfr_init(y); mpfr_init(z); /* Read the input strings into mpfr x and y */ buflen = (mxGetM(prhs[1]) * mxGetN(prhs[1])) + 1; input_buf=mxCalloc(buflen, sizeof(char)); status = mxGetString(prhs[1], input_buf, buflen); mpfr_set_str(x,input_buf,10,GMP_RNDN); /* Mathematical operation */ mpfr_erf(z,x,GMP_RNDN); /* Retrieve results */ mxFree(input_buf); input_buf=mpfr_get_str (NULL, &expptr, 10, 0, z, GMP_RNDN); w1=malloc(strlen(input_buf)+20); w2=malloc(strlen(input_buf)+20); if (strncmp(input_buf, "-", 1)==0){ strcpy(w2,&input_buf[1]); sprintf(w1,"-.%se%i",w2,expptr); } else { strcpy(w2,&input_buf[0]); sprintf(w1,"+.%se%i",w2,expptr); } plhs[0] = mxCreateString(w1); /* plhs[1] = mxCreateDoubleMatrix(mrows,ncols, mxREAL); */ /* eout=mxGetPr(plhs[1]); */ /* *eout=expptr; */ mpfr_clear(x); mpfr_clear(y); mpfr_clear(z); mpfr_free_str(input_buf); free(w1); free(w2); }
mxArray *sf_c4_MigrationBGOW_Proto6_MultiSwarm_get_autoinheritance_info(void) { const char *autoinheritanceFields[] = { "checksum", "inputs", "parameters", "outputs", "locals" }; mxArray *mxAutoinheritanceInfo = mxCreateStructMatrix(1,1,5, autoinheritanceFields); { mxArray *mxChecksum = mxCreateString("rzulmDbWcdsJ7hBXS7VHTC"); mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum); } { const char *dataFields[] = { "size", "type", "complexity" }; mxArray *mxData = mxCreateStructMatrix(1,2,3,dataFields); { mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL); double *pr = mxGetPr(mxSize); pr[0] = (double)(1); pr[1] = (double)(1); mxSetField(mxData,0,"size",mxSize); } { const char *typeFields[] = { "base", "fixpt" }; mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields); mxSetField(mxType,0,"base",mxCreateDoubleScalar(10)); mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL)); mxSetField(mxData,0,"type",mxType); } mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0)); { mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL); double *pr = mxGetPr(mxSize); pr[0] = (double)(1); pr[1] = (double)(1); mxSetField(mxData,1,"size",mxSize); } { const char *typeFields[] = { "base", "fixpt" }; mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields); mxSetField(mxType,0,"base",mxCreateDoubleScalar(10)); mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL)); mxSetField(mxData,1,"type",mxType); } mxSetField(mxData,1,"complexity",mxCreateDoubleScalar(0)); mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData); } { mxSetField(mxAutoinheritanceInfo,0,"parameters",mxCreateDoubleMatrix(0,0, mxREAL)); } { const char *dataFields[] = { "size", "type", "complexity" }; mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields); { mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL); double *pr = mxGetPr(mxSize); pr[0] = (double)(1); pr[1] = (double)(1); mxSetField(mxData,0,"size",mxSize); } { const char *typeFields[] = { "base", "fixpt" }; mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields); mxSetField(mxType,0,"base",mxCreateDoubleScalar(10)); mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL)); mxSetField(mxData,0,"type",mxType); } mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0)); mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData); } { mxSetField(mxAutoinheritanceInfo,0,"locals",mxCreateDoubleMatrix(0,0,mxREAL)); } return(mxAutoinheritanceInfo); }
void SDRuTransmitter_setupImplLocal(const emlrtStack *sp, comm_SDRuTransmitter *obj, UsrpErrorCapiEnumT *errStatus, char_T errMsg_data[1024], int32_T errMsg_size[2]) { BoardIdCapiEnumT boardId; uint8_T requester[15]; int32_T i; const mxArray *y; static const int32_T iv176[2] = { 1, 6 }; const mxArray *m36; char_T cv210[6]; static const char_T cv211[6] = { 's', 'i', 'l', 'e', 'n', 't' }; static const uint8_T addr_null[13] = { 49U, 57U, 50U, 46U, 49U, 54U, 56U, 46U, 49U, 48U, 46U, 50U, 0U }; char * addr_c; uint8_T req_null[16]; char * req_c; int32_T driverApiH; const mxArray *b_y; int32_T loop_ub; char_T b_errMsg_data[1024]; comm_SDRuTransmitter *b_obj; emlrtStack st; emlrtStack b_st; emlrtStack c_st; st.prev = sp; st.tls = sp->tls; b_st.prev = &st; b_st.tls = st.tls; c_st.prev = &b_st; c_st.tls = b_st.tls; st.site = &rj_emlrtRSI; b_st.site = &rj_emlrtRSI; c_st.site = &db_emlrtRSI; st.site = &rj_emlrtRSI; boardId = obj->pSubDevice; for (i = 0; i < 15; i++) { requester[i] = (uint8_T)obj->ObjectID[i]; } /* Copyright 2011-2012 The MathWorks, Inc. */ b_st.site = &vm_emlrtRSI; /* */ /* This function unifies handling of interp vs. codegen call as well as */ /* errStat / errStr assignment. */ /* */ /* Copyright 2011-2013 The MathWorks, Inc. */ if (!isSetupsdruCalled) { y = NULL; m36 = mxCreateCharArray(2, iv176); for (i = 0; i < 6; i++) { cv210[i] = cv211[i]; } emlrtInitCharArrayR2013a(&b_st, 6, m36, cv210); emlrtAssign(&y, m36); c_st.site = &pv_emlrtRSI; setupsdru(&c_st, sdruroot(&c_st, &p_emlrtMCI), y, &q_emlrtMCI); isSetupsdruCalled = TRUE; } /* These sizes must match those in C code. */ /* Arbitrary max imposed on ML/SL side */ /* function is being called in interpreted mode */ /* not being found: */ /* eml_allow_enum_inputs; */ /* errStat_i = int32(0); */ for (i = 0; i < 1024; i++) { errMsg_data[i] = '\x00'; } /* varargin 1 2 3 4 5 6 7 */ /* addr, boardId, requester, frameLength, dportType, buffMode, buffSize */ /* varargout 1 2 3 */ /* driverH, errStat, errMsg */ addr_c = (char *)(addr_null); for (i = 0; i < 15; i++) { req_null[i] = requester[i]; } req_null[15] = 0; req_c = (char *)(req_null); openDataConnection_c(addr_c, boardId, req_c, 38400U, DPortDTypeCDouble, FALSE, 0U, &driverApiH, errStatus, &errMsg_data[0]); /* Tell coder that addr_null & req_null must be alive and separate throughout the call to cmd_c. */ (void)(addr_null); (void)(req_null); /* errStat = UsrpErrorCapiEnumT(errStat_i); */ i = strlen(&errMsg_data[0]); if (i <= 1024) { } else { b_y = NULL; m36 = mxCreateString("Assertion failed."); emlrtAssign(&b_y, m36); c_st.site = &iv_emlrtRSI; c_error(&c_st, b_y, &o_emlrtMCI); } if (1 > i) { loop_ub = 0; } else { loop_ub = emlrtDynamicBoundsCheckFastR2012b(i, 1, 1024, &x_emlrtBCI, &b_st); } for (i = 0; i < loop_ub; i++) { b_errMsg_data[i] = errMsg_data[i]; } errMsg_size[0] = 1; errMsg_size[1] = loop_ub; for (i = 0; i < loop_ub; i++) { errMsg_data[i] = b_errMsg_data[i]; } st.site = &rj_emlrtRSI; b_obj = obj; b_obj->pDriverHandle = driverApiH; b_st.site = &db_emlrtRSI; }
void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { double orbfd; char *orbstring_code; char *nodelay_string; int nodelay = 0; char errmsg[STRSZ]; int pktid; char srcname[STRSZ]; char pkttype[STRSZ]; double time; char *packet = 0; int nbytes = 0; int bufsize = 0; int rc; if( nrhs < 1 || nrhs > 2 ) { antelope_mexUsageMsgTxt ( USAGE ); return; } else if( ! get_scalar( prhs[0], &orbfd ) ) { antelope_mexUsageMsgTxt ( USAGE ); return; } if( nrhs == 2 ) { if( ! mtlb_get_string( prhs[1], &nodelay_string ) || ! STREQ( nodelay_string, "nodelay" ) ) { antelope_mexUsageMsgTxt ( USAGE ); return; } else { mxFree( nodelay_string ); nodelay = 1; } } if( nodelay ) { rc = mex_orbreap_nd( (int) orbfd, &pktid, &srcname[0], &time, &packet, &nbytes, &bufsize ); } else { rc = mex_orbreap( (int) orbfd, &pktid, &srcname[0], &time, &packet, &nbytes, &bufsize ); } antelope_mex_clear_register( 1 ); if( rc < 0 ) { return; } plhs[0] = orbpkt2mxArray( srcname, time, packet, nbytes, pkttype ); plhs[1] = CreateDouble( time ); plhs[2] = mxCreateString( srcname ); plhs[3] = CreateDouble( (double) pktid ); plhs[4] = mxCreateString( pkttype ); free( packet ); }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { int err; int hslen; lo_address d; if (nrhs != 2 && nrhs!=1) { mexErrMsgTxt("Please specify host name/address and port or URL"); return; } if (nlhs > 1) { mexErrMsgTxt("Too many output arguments."); return; } if(! mxIsChar(prhs[0])) { mexErrMsgTxt("Expecting a character array in the first argument (hostname or URL)."); return; } if(nrhs==2 && ! mxIsNumeric(prhs[1])) { mexErrMsgTxt("Expecting a numeric scalar in the second argument (port number)."); return; } hslen = (mxGetM(prhs[0]) * mxGetN(prhs[0])) + 1; if(hslen > sizeof(host)+1) { mexErrMsgTxt("Maximum url/hostname string length is 255 characters."); return; } err = mxGetString(prhs[0], host, hslen); if(err != 0) { mexErrMsgTxt("Error reading url/hostname string."); return; } if (nrhs==2) { sprintf(port, "%d", (int)(mxGetScalar(prhs[1]))); d = lo_address_new(host, port); } else { d = lo_address_new_from_url(host); } if(! d) { mexErrMsgTxt(lo_address_errstr(d)); return; } if(sizeof(d) == sizeof(long int)) { sprintf(maddr, "osc_address:%lx", (long int)d); } else if(sizeof(d) == sizeof(long long int)) { sprintf(maddr, "osc_address:%llx", (long long int)d); } else { mexErrMsgTxt("Unsupported pointer size."); return; } plhs[0] = mxCreateString(maddr); }
const char *model_to_matlab_structure(mxArray *plhs[], int num_of_feature, struct svm_model *model) { int i, j, n; SVM_REAL *ptr; mxArray *return_model, **rhs; int out_id = 0; rhs = (mxArray **)mxMalloc(sizeof(mxArray *)*NUM_OF_RETURN_FIELD); /* Parameters */ #ifdef _ALL_FLOAT rhs[out_id] = mxCreateNumericMatrix(5, 1, mxSINGLE_CLASS, mxREAL); ptr = (float *) mxGetData(rhs[out_id]); #else rhs[out_id] = mxCreateDoubleMatrix(5, 1, mxREAL); ptr = mxGetPr(rhs[out_id]); #endif ptr[0] = (SVM_REAL)model->param.svm_type; ptr[1] = (SVM_REAL)model->param.kernel_type; ptr[2] = (SVM_REAL)model->param.degree; ptr[3] = model->param.gamma; ptr[4] = model->param.coef0; out_id++; /* nr_class */ #ifdef _ALL_FLOAT rhs[out_id] = mxCreateNumericMatrix(1, 1, mxSINGLE_CLASS,mxREAL); ptr = (float *) mxGetData(rhs[out_id]); #else rhs[out_id] = mxCreateDoubleMatrix(1, 1, mxREAL); ptr = mxGetPr(rhs[out_id]); #endif ptr[0] = (SVM_REAL)model->nr_class; out_id++; /* total SV */ #ifdef _ALL_FLOAT rhs[out_id] = mxCreateNumericMatrix(1, 1, mxSINGLE_CLASS,mxREAL); ptr = (float *) mxGetData(rhs[out_id]); #else rhs[out_id] = mxCreateDoubleMatrix(1, 1, mxREAL); ptr = mxGetPr(rhs[out_id]); #endif ptr[0] = (SVM_REAL)model->l; out_id++; /* rho */ n = model->nr_class*(model->nr_class-1)/2; #ifdef _ALL_FLOAT rhs[out_id] = mxCreateNumericMatrix(n, 1, mxSINGLE_CLASS,mxREAL); ptr = (float *) mxGetData(rhs[out_id]); #else rhs[out_id] = mxCreateDoubleMatrix(n, 1, mxREAL); ptr = mxGetPr(rhs[out_id]); #endif for(i = 0; i < n; i++) ptr[i] = model->rho[i]; out_id++; /* Label */ if(model->label) { #ifdef _ALL_FLOAT rhs[out_id] = mxCreateNumericMatrix(model->nr_class, 1, mxSINGLE_CLASS,mxREAL); ptr = (float *) mxGetData(rhs[out_id]); #else rhs[out_id] = mxCreateDoubleMatrix(model->nr_class, 1, mxREAL); ptr = mxGetPr(rhs[out_id]); #endif for(i = 0; i < model->nr_class; i++) ptr[i] = (SVM_REAL)model->label[i]; } else #ifdef _ALL_FLOAT rhs[out_id] = mxCreateNumericMatrix(0, 0, mxSINGLE_CLASS,mxREAL); #else rhs[out_id] = mxCreateDoubleMatrix(0, 0, mxREAL); #endif out_id++; /* probA */ if(model->probA != NULL) { #ifdef _ALL_FLOAT rhs[out_id] = mxCreateNumericMatrix(n, 1, mxSINGLE_CLASS,mxREAL); ptr = (float *) mxGetData(rhs[out_id]); #else rhs[out_id] = mxCreateDoubleMatrix(n, 1, mxREAL); ptr = mxGetPr(rhs[out_id]); #endif for(i = 0; i < n; i++) ptr[i] = model->probA[i]; } else #ifdef _ALL_FLOAT rhs[out_id] = mxCreateNumericMatrix(0, 0, mxSINGLE_CLASS,mxREAL); #else rhs[out_id] = mxCreateDoubleMatrix(0, 0, mxREAL); #endif out_id ++; /* probB */ if(model->probB != NULL) { #ifdef _ALL_FLOAT rhs[out_id] = mxCreateNumericMatrix(n, 1, mxSINGLE_CLASS,mxREAL); ptr = (float *) mxGetData(rhs[out_id]); #else rhs[out_id] = mxCreateDoubleMatrix(n, 1, mxREAL); ptr = mxGetPr(rhs[out_id]); #endif for(i = 0; i < n; i++) ptr[i] = model->probB[i]; } else #ifdef _ALL_FLOAT rhs[out_id] = mxCreateNumericMatrix(0, 0, mxSINGLE_CLASS,mxREAL); #else rhs[out_id] = mxCreateDoubleMatrix(0, 0, mxREAL); #endif out_id++; /* nSV */ if(model->nSV) { #ifdef _ALL_FLOAT rhs[out_id] = mxCreateNumericMatrix(model->nr_class, 1, mxSINGLE_CLASS,mxREAL); ptr = (float *) mxGetData(rhs[out_id]); #else rhs[out_id] = mxCreateDoubleMatrix(model->nr_class, 1, mxREAL); ptr = mxGetPr(rhs[out_id]); #endif for(i = 0; i < model->nr_class; i++) ptr[i] = (SVM_REAL)model->nSV[i]; } else #ifdef _ALL_FLOAT rhs[out_id] = mxCreateNumericMatrix(0, 0, mxSINGLE_CLASS,mxREAL); #else rhs[out_id] = mxCreateDoubleMatrix(0, 0, mxREAL); #endif out_id++; /* sv_coef */ #ifdef _ALL_FLOAT rhs[out_id] = mxCreateNumericMatrix(model->l, model->nr_class-1, mxSINGLE_CLASS,mxREAL); ptr = (float *) mxGetData(rhs[out_id]); #else rhs[out_id] = mxCreateDoubleMatrix(model->l, model->nr_class-1, mxREAL); ptr = mxGetPr(rhs[out_id]); #endif for(i = 0; i < model->nr_class-1; i++) for(j = 0; j < model->l; j++) ptr[(i*(model->l))+j] = model->sv_coef[i][j]; out_id++; /* SVs */ { #ifdef _DENSE_REP #ifdef _ALL_FLOAT rhs[out_id] = mxCreateNumericMatrix(model->l, num_of_feature, mxSINGLE_CLASS,mxREAL); ptr = (float *) mxGetData(rhs[out_id]); #else rhs[out_id] = mxCreateDoubleMatrix(model->l, num_of_feature, mxREAL); ptr = mxGetPr(rhs[out_id]); #endif for(i=0;i < num_of_feature;i++) for(j=0;j < model->l;j++) ptr[(i*(model->l))+j] = model->SV[j].values[i]; #else int ir_index, nonzero_element; mwIndex *ir, *jc; mxArray *pprhs[1], *pplhs[1]; if(model->param.kernel_type == PRECOMPUTED) { nonzero_element = model->l; num_of_feature = 1; } else { nonzero_element = 0; for(i = 0; i < model->l; i++) { j = 0; while(model->SV[i][j].index != -1) { nonzero_element++; j++; } } } /* SV in column, easier accessing */ double *ptr2; rhs[out_id] = mxCreateSparse(num_of_feature, model->l, nonzero_element, mxREAL); ptr2 = mxGetPr(rhs[out_id]); ir = mxGetIr(rhs[out_id]); jc = mxGetJc(rhs[out_id]); jc[0] = ir_index = 0; for(i = 0;i < model->l; i++) { if(model->param.kernel_type == PRECOMPUTED) { /* make a (1 x model->l) matrix */ ir[ir_index] = 0; ptr2[ir_index] = model->SV[i][0].value; ir_index++; jc[i+1] = jc[i] + 1; } else { int x_index = 0; while (model->SV[i][x_index].index != -1) { ir[ir_index] = model->SV[i][x_index].index - 1; ptr2[ir_index] = model->SV[i][x_index].value; ir_index++, x_index++; } jc[i+1] = jc[i] + x_index; } } /* transpose back to SV in row */ pprhs[0] = rhs[out_id]; if(mexCallMATLAB(1, pplhs, 1, pprhs, "transpose")) return "cannot transpose SV matrix"; rhs[out_id] = pplhs[0]; #endif out_id++; } #ifdef _USE_CHI_SQUARE rhs[out_id] = mxCreateString(model->param.feat_parm_text); #endif /* Create a struct matrix contains NUM_OF_RETURN_FIELD fields */ return_model = mxCreateStructMatrix(1, 1, NUM_OF_RETURN_FIELD, field_names); /* Fill struct matrix with input arguments */ for(i = 0; i < NUM_OF_RETURN_FIELD; i++) mxSetField(return_model,0,field_names[i],mxDuplicateArray(rhs[i])); /* return */ plhs[0] = return_model; mxFree(rhs); return NULL; }
void alc_getstring( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { plhs[0]=mxCreateString((const char *)alcGetString(alcGetContextsDevice(alcGetCurrentContext()), (ALenum)mxGetScalar(prhs[0]))); }
void al_getstring( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { plhs[0]=mxCreateString((const char *)alGetString((ALenum)mxGetScalar(prhs[0]))); }
// To run SAXParser in MATLAB: // [v, ds, ws, es, ews, des, ss, ess, ns, ens] = SAXParser('') void MATProcedure(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { // pass the inverted index back to matlab // here we have to individually pass all the data from the maps into mxArrays // create the vocab array //int vocab_size = InvertedIndex::instance()->getVocabSize(); map<string, int>* vocab = &(InvertedIndex::instance()->vocab); int vocab_size = InvertedIndex::instance()->vocab.size(); //int i = 0; mwSize vsize = static_cast<mwSize>(vocab_size); plhs[0] = mxCreateCellArray(1, &vsize); for(map<string, int>::iterator it = vocab->begin(); it != vocab->end(); it++) { mxSetCell(plhs[0], (*it).second - 1, mxCreateString((*it).first.c_str())); } // create WS and DS arrays // WS, DS is size 1 x n where n is the number of word tokens. // The word stream WS contains word indices in order of occurence with WS=0 // representing the end-of-sentence-end marker. // The document indices DS contains all document indices and max(DS) = D = number of documents // they should be double-precision vectors int numwords = InvertedIndex::instance()->docs.size(); plhs[1] = mxCreateDoubleMatrix(numwords, 1, mxREAL); plhs[2] = mxCreateDoubleMatrix(numwords, 1, mxREAL); double *Z = mxGetPr(plhs[1]); double *D = mxGetPr(plhs[2]); for(multimap<int, int>::const_iterator it = InvertedIndex::instance()->docs.begin(); it != InvertedIndex::instance()->docs.end(); it++) { //cout << (*it).first << " " << (*it).second << "\n"; *(Z++) = (*it).first; *(D++) = (*it).second; } // Create sparse arrays for entities int rows, cols, nzmax; rows = InvertedIndex::instance()->entities.highest(); // highest index in entities; cols = vocab_size; nzmax = InvertedIndex::instance()->entities.size(); multimap<int, int> rev = InvertedIndex::instance()->entities.reverseMap(); plhs[3] = createMATSparseMatrix(rows, cols, nzmax, rev.begin(), rev.end()); // create an array for entity_weights mwSize dims[2]; dims[1] = 1; dims[0] = InvertedIndex::instance()->entities.highest(); plhs[4] = mxCreateNumericArray(2, dims, mxINT32_CLASS, mxREAL); int *W = (int*)mxGetData(plhs[4]); for(multimap<int,int>::const_iterator it = InvertedIndex::instance()->entity_weights.begin(); it != InvertedIndex::instance()->entity_weights.end(); it++) { W[(*it).first-1] = (*it).second; //cout << (*it).second << " " << W[(*it).first] << "\n"; } // create a sparse matrix for doc_entities rows = InvertedIndex::instance()->docs.highest(); cols = InvertedIndex::instance()->entities.highest(); nzmax = InvertedIndex::instance()->doc_entities.size(); rev = InvertedIndex::instance()->doc_entities.reverseMap(); plhs[5] = createMATSparseMatrix(rows, cols, nzmax, rev.begin(), rev.end()); // crate a sparse matrix for syns rows = InvertedIndex::instance()->syns.highest(); cols = vocab_size; nzmax = InvertedIndex::instance()->syns.size(); rev = InvertedIndex::instance()->syns.reverseMap(); plhs[6] = createMATSparseMatrix(rows, cols, nzmax, rev.begin(), rev.end()); // create a sparse matrix for entity_syn rows = InvertedIndex::instance()->entities.highest(); cols = InvertedIndex::instance()->syns.highest(); nzmax = InvertedIndex::instance()->entity_syns.size(); rev = InvertedIndex::instance()->entity_syns.reverseMap(); plhs[7] = createMATSparseMatrix(rows, cols, nzmax, rev.begin(), rev.end()); // crate a sparse matrix for names rows = InvertedIndex::instance()->names.highest(); cols = vocab_size; nzmax = InvertedIndex::instance()->names.size(); rev = InvertedIndex::instance()->names.reverseMap(); plhs[8] = createMATSparseMatrix(rows, cols, nzmax, rev.begin(), rev.end()); // create a sparse matrix for entity_names rows = InvertedIndex::instance()->entities.highest(); cols = InvertedIndex::instance()->names.highest(); nzmax = InvertedIndex::instance()->entity_names.size(); rev = InvertedIndex::instance()->entity_names.reverseMap(); plhs[9] = createMATSparseMatrix(rows, cols, nzmax, rev.begin(), rev.end()); }
mxArray *sf_c2_DYNctl_ver4_etud_nonlineaire_get_autoinheritance_info(void) { const char *autoinheritanceFields[] = { "checksum", "inputs", "parameters", "outputs", "locals", "postCodegenInfo" }; mxArray *mxAutoinheritanceInfo = mxCreateStructMatrix(1, 1, sizeof (autoinheritanceFields)/sizeof(autoinheritanceFields[0]), autoinheritanceFields); { mxArray *mxChecksum = mxCreateString("sERS3oCLq0hbTWa6GftcDD"); mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum); } { const char *dataFields[] = { "size", "type", "complexity" }; mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields); { mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL); double *pr = mxGetPr(mxSize); pr[0] = (double)(1); pr[1] = (double)(1); mxSetField(mxData,0,"size",mxSize); } { const char *typeFields[] = { "base", "fixpt" }; mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields); mxSetField(mxType,0,"base",mxCreateDoubleScalar(10)); mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL)); mxSetField(mxData,0,"type",mxType); } mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0)); mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData); } { mxSetField(mxAutoinheritanceInfo,0,"parameters",mxCreateDoubleMatrix(0,0, mxREAL)); } { const char *dataFields[] = { "size", "type", "complexity" }; mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields); { mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL); double *pr = mxGetPr(mxSize); pr[0] = (double)(1); pr[1] = (double)(1); mxSetField(mxData,0,"size",mxSize); } { const char *typeFields[] = { "base", "fixpt" }; mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields); mxSetField(mxType,0,"base",mxCreateDoubleScalar(10)); mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL)); mxSetField(mxData,0,"type",mxType); } mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0)); mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData); } { mxSetField(mxAutoinheritanceInfo,0,"locals",mxCreateDoubleMatrix(0,0,mxREAL)); } { mxArray* mxPostCodegenInfo = sf_c2_DYNctl_ver4_etud_nonlineaire_get_post_codegen_info(); mxSetField(mxAutoinheritanceInfo,0,"postCodegenInfo",mxPostCodegenInfo); } return(mxAutoinheritanceInfo); }
mxArray *sf_c3_Engine_Vehicle_CVT_Wit_System1_trial1_get_autoinheritance_info (void) { const char *autoinheritanceFields[] = { "checksum", "inputs", "parameters", "outputs", "locals", "postCodegenInfo" }; mxArray *mxAutoinheritanceInfo = mxCreateStructMatrix(1, 1, sizeof (autoinheritanceFields)/sizeof(autoinheritanceFields[0]), autoinheritanceFields); { mxArray *mxChecksum = mxCreateString("TCZPPqBKYZYQqqSv2Yl1LH"); mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum); } { const char *dataFields[] = { "size", "type", "complexity" }; mxArray *mxData = mxCreateStructMatrix(1,3,3,dataFields); { mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL); double *pr = mxGetPr(mxSize); pr[0] = (double)(1); pr[1] = (double)(1); mxSetField(mxData,0,"size",mxSize); } { const char *typeFields[] = { "base", "fixpt" }; mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields); mxSetField(mxType,0,"base",mxCreateDoubleScalar(10)); mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL)); mxSetField(mxData,0,"type",mxType); } mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0)); { mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL); double *pr = mxGetPr(mxSize); pr[0] = (double)(1); pr[1] = (double)(1); mxSetField(mxData,1,"size",mxSize); } { const char *typeFields[] = { "base", "fixpt" }; mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields); mxSetField(mxType,0,"base",mxCreateDoubleScalar(10)); mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL)); mxSetField(mxData,1,"type",mxType); } mxSetField(mxData,1,"complexity",mxCreateDoubleScalar(0)); { mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL); double *pr = mxGetPr(mxSize); pr[0] = (double)(1); pr[1] = (double)(1); mxSetField(mxData,2,"size",mxSize); } { const char *typeFields[] = { "base", "fixpt" }; mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields); mxSetField(mxType,0,"base",mxCreateDoubleScalar(10)); mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL)); mxSetField(mxData,2,"type",mxType); } mxSetField(mxData,2,"complexity",mxCreateDoubleScalar(0)); mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData); } { mxSetField(mxAutoinheritanceInfo,0,"parameters",mxCreateDoubleMatrix(0,0, mxREAL)); } { const char *dataFields[] = { "size", "type", "complexity" }; mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields); { mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL); double *pr = mxGetPr(mxSize); pr[0] = (double)(1); pr[1] = (double)(1); mxSetField(mxData,0,"size",mxSize); } { const char *typeFields[] = { "base", "fixpt" }; mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields); mxSetField(mxType,0,"base",mxCreateDoubleScalar(10)); mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL)); mxSetField(mxData,0,"type",mxType); } mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0)); mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData); } { mxSetField(mxAutoinheritanceInfo,0,"locals",mxCreateDoubleMatrix(0,0,mxREAL)); } { mxArray* mxPostCodegenInfo = sf_c3_Engine_Vehicle_CVT_Wit_System1_trial1_get_post_codegen_info(); mxSetField(mxAutoinheritanceInfo,0,"postCodegenInfo",mxPostCodegenInfo); } return(mxAutoinheritanceInfo); }
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray*prhs[] ) { /* Pointer to temporary matlab array */ const mxArray *mx; mxArray *m_shape_type; int nShapeType, nEntities, i, j, k, iPart, nFields, nStructElem, isPoint, firstInPoints = 1; int num_dbf_fields, num_dbf_records; /* number of DBF attributes, records */ int buflen; /* length of input shapefile name */ int status; /* success or failure */ char *shapefile; /* holder for input shapefile name */ const char *pszPartType = ""; /* Not used. */ double adfMinBound[4], adfMaxBound[4]; /* pointer to the shapefile */ SHPHandle hSHP; SHPObject *psShape; DBFHandle dbh; /* handle for DBF file */ /* This structure will hold a description of each field in the DBF file. */ typedef struct DBF_Field_Descriptor { char pszFieldName[12]; DBFFieldType field_type; } DBF_Field_Descriptor; DBF_Field_Descriptor *dbf_field; /* stores individual values from the DBF. */ int dbf_integer_val, dims[2], *p_parts_ptr, nNaNs, c, i_start, i_stop; char *dbf_char_val, error_buffer[500]; char *fnames[100]; /* holds name of fields */ mxArray *out_struct, *x_out, *y_out, *z_out, *bbox, *p_parts; double *x_out_ptr, *y_out_ptr, *z_out_ptr, *bb_ptr, nan, dbf_double_val; size_t sizebuf; /* Initialize the dbf record. */ dbf_field = NULL; /* Check for proper number of arguments */ if (nrhs != 1) mexErrMsgTxt("One input arguments are required."); if (nlhs != 2) mexErrMsgTxt("Two output arguments required."); /* Make sure the input is a proper string. */ if ( mxIsChar(prhs[0]) != 1 ) mexErrMsgTxt("Shapefile parameter must be a string\n" ); if ( mxGetM(prhs[0]) != 1 ) mexErrMsgTxt("Shapefile parameter must be a row vector, not a column string\n" ); buflen = mxGetN(prhs[0]) + 1; shapefile = mxCalloc( buflen, sizeof(char) ); /* copy the string data from prhs[0] into a C string. */ status = mxGetString( prhs[0], shapefile, buflen ); if ( status != 0 ) mxErrMsgTxt( "Not enough space for shapefile argument.\n" ); /* -------------------------------------------------------------------- */ /* Open the passed shapefile. */ /* -------------------------------------------------------------------- */ hSHP = SHPOpen( shapefile, "rb" ); if( hSHP == NULL ) mxErrMsgTxt( "Unable to open:%s\n", shapefile ); /* -------------------------------------------------------------------- */ /* Get the needed information about the shapefile. */ /* -------------------------------------------------------------------- */ SHPGetInfo( hSHP, &nEntities, &nShapeType, adfMinBound, adfMaxBound ); /* Make sure that we can handle the type. */ switch ( nShapeType ) { case SHPT_POINT: break; case SHPT_POINTZ: break; case SHPT_ARC: break; case SHPT_ARCZ: break; case SHPT_POLYGON: break; case SHPT_POLYGONZ: break; case SHPT_MULTIPOINT: /* JL */ break; default: sprintf ( error_buffer, "Unhandled shape code %d (%s)", nShapeType, SHPTypeName ( nShapeType ) ); mexErrMsgTxt( error_buffer ); } /* Create the output shape type parameter. */ plhs[1] = mxCreateString ( SHPTypeName ( nShapeType ) ); /* Open the DBF, and retrieve the number of fields and records */ dbh = DBFOpen (shapefile, "rb"); num_dbf_fields = DBFGetFieldCount ( dbh ); num_dbf_records = DBFGetRecordCount ( dbh ); /* Allocate space for a description of each record, and populate it. * I allocate space for two extra "dummy" records that go in positions * 0 and 1. These I reserve for the xy data. */ nFields = 3; if ( (nShapeType == SHPT_POLYGONZ) || (nShapeType == SHPT_ARCZ) || (nShapeType == SHPT_POINTZ) ) nFields++; dbf_field = (DBF_Field_Descriptor *) mxMalloc ( (num_dbf_fields+nFields) * sizeof ( DBF_Field_Descriptor ) ); if ( dbf_field == NULL ) mexErrMsgTxt("Memory allocation for DBF_Field_Descriptor failed."); for ( j = 0; j < num_dbf_fields; ++j ) dbf_field[j+nFields].field_type = DBFGetFieldInfo ( dbh, j, dbf_field[j+nFields].pszFieldName, NULL, NULL ); fnames[0] = strdup ( "X" ); fnames[1] = strdup ( "Y" ); if ( (nShapeType == SHPT_POLYGONZ) || (nShapeType == SHPT_ARCZ) || (nShapeType == SHPT_POINTZ) ) { fnames[2] = strdup ( "Z" ); fnames[3] = strdup ( "BoundingBox" ); } else fnames[2] = strdup ( "BoundingBox" ); for ( j = 0; j < num_dbf_fields; ++j ) fnames[j+nFields] = strdup ( dbf_field[j+nFields].pszFieldName ); /* To hold information on eventual polygons with rings */ /*fnames[num_dbf_fields+3] = strdup ( "nParts" );*/ /*fnames[num_dbf_fields+4] = strdup ( "PartsIndex" );*/ /* Allocate space for the output structure. */ isPoint = ( nShapeType == SHPT_POINT || nShapeType == SHPT_POINTZ ) ? 1: 0; nStructElem = ( nShapeType == SHPT_POINT || nShapeType == SHPT_POINTZ ) ? 1: nEntities; out_struct = mxCreateStructMatrix ( nStructElem, 1, nFields + num_dbf_fields, (const char **)fnames ); /* create the BoundingBox */ dims[0] = 4; dims[1] = 2; bbox = mxCreateNumericArray ( 2, dims, mxDOUBLE_CLASS, mxREAL ); bb_ptr = mxGetData ( bbox ); for (i = 0; i < 4; i++) bb_ptr[i] = adfMinBound[i]; for (i = 0; i < 4; i++) bb_ptr[i+4] = adfMaxBound[i]; mxSetField ( out_struct, 0, "BoundingBox", bbox ); nan = mxGetNaN(); /* -------------------------------------------------------------------- */ /* Skim over the list of shapes, printing all the vertices. */ /* -------------------------------------------------------------------- */ for( i = 0; i < nEntities; i++ ) { psShape = SHPReadObject( hSHP, i ); /* Create the fields in this struct element. */ if ( !isPoint ) { nNaNs = psShape->nParts > 1 ? psShape->nParts : 0; dims[0] = psShape->nVertices + nNaNs; dims[1] = 1; x_out = mxCreateNumericArray ( 2, dims, mxDOUBLE_CLASS, mxREAL ); x_out_ptr = mxGetData ( x_out ); y_out = mxCreateNumericArray ( 2, dims, mxDOUBLE_CLASS, mxREAL ); y_out_ptr = mxGetData ( y_out ); if ( (nShapeType == SHPT_POLYGONZ) || (nShapeType == SHPT_POINTZ) || (nShapeType == SHPT_ARCZ)) { z_out = mxCreateNumericArray ( 2, dims, mxDOUBLE_CLASS, mxREAL ); z_out_ptr = mxGetData ( z_out ); } } else if (firstInPoints) { /* Allocate all memory we'll need */ x_out = mxCreateDoubleMatrix (nEntities, 1, mxREAL); x_out_ptr = mxGetPr ( x_out ); y_out = mxCreateDoubleMatrix (nEntities, 1, mxREAL); y_out_ptr = mxGetPr ( y_out ); if (nShapeType == SHPT_POINTZ) { z_out = mxCreateDoubleMatrix (nEntities, 1, mxREAL); z_out_ptr = mxGetPr ( z_out ); } firstInPoints = 0; } if (!isPoint && psShape->nParts > 1) { for (k = c = 0; k < psShape->nParts; k++) { i_start = psShape->panPartStart[k]; if (k < psShape->nParts - 1) i_stop = psShape->panPartStart[k+1]; else i_stop = psShape->nVertices; if ( nShapeType == SHPT_POLYGONZ ) { for (j = i_start; j < i_stop; c++, j++) { x_out_ptr[c] = psShape->padfX[j]; y_out_ptr[c] = psShape->padfY[j]; z_out_ptr[c] = psShape->padfZ[j]; } x_out_ptr[c] = nan; y_out_ptr[c] = nan; z_out_ptr[c] = nan; } else { for (j = i_start; j < i_stop; c++, j++) { x_out_ptr[c] = psShape->padfX[j]; y_out_ptr[c] = psShape->padfY[j]; } x_out_ptr[c] = nan; y_out_ptr[c] = nan; } c++; } } else if ( isPoint ) { x_out_ptr[i] = *psShape->padfX; y_out_ptr[i] = *psShape->padfY; if (nShapeType == SHPT_POINTZ) z_out_ptr[i] = *psShape->padfZ; if (i > 0) { SHPDestroyObject( psShape ); continue; } } else { /* Just copy the vertices over. */ sizebuf = mxGetElementSize ( x_out ) * psShape->nVertices; memcpy ( (void *) x_out_ptr, (void *) psShape->padfX, sizebuf ); memcpy ( (void *) y_out_ptr, (void *) psShape->padfY, sizebuf ); if ( (nShapeType == SHPT_POLYGONZ) || (nShapeType == SHPT_ARCZ)) memcpy ( (void *) z_out_ptr, (void *) psShape->padfZ, sizebuf ); } mxSetField ( out_struct, i, "X", x_out ); mxSetField ( out_struct, i, "Y", y_out ); if ( (nShapeType == SHPT_POLYGONZ) || (nShapeType == SHPT_ARCZ) ) mxSetField ( out_struct, i, "Z", z_out ); bbox = mxCreateNumericMatrix ( 4, 2, mxDOUBLE_CLASS, mxREAL ); bb_ptr = (double *)mxGetData ( bbox ); bb_ptr[0] = psShape->dfXMin; bb_ptr[1] = psShape->dfYMin; bb_ptr[2] = psShape->dfZMin; bb_ptr[3] = psShape->dfMMin; bb_ptr[4] = psShape->dfXMax; bb_ptr[5] = psShape->dfYMax; bb_ptr[6] = psShape->dfZMax; bb_ptr[7] = psShape->dfMMax; if (i > 0) /* First BB contains the ensemble extent */ mxSetField ( out_struct, i, "BoundingBox", bbox ); for ( j = 0; j < num_dbf_fields; ++j ) { switch ( dbf_field[j+nFields].field_type ) { case FTString: dbf_char_val = (char *) DBFReadStringAttribute ( dbh, i, j ); mxSetField ( out_struct, i, dbf_field[j+nFields].pszFieldName, mxCreateString ( dbf_char_val ) ); break; case FTDouble: dbf_double_val = DBFReadDoubleAttribute ( dbh, i, j ); mxSetField ( out_struct, i, dbf_field[j+nFields].pszFieldName, mxCreateDoubleScalar ( dbf_double_val ) ); break; case FTInteger: case FTLogical: dbf_integer_val = DBFReadIntegerAttribute ( dbh, i, j ); dbf_double_val = dbf_integer_val; mxSetField ( out_struct, i, dbf_field[j+nFields].pszFieldName, mxCreateDoubleScalar ( dbf_double_val ) ); break; default: sprintf ( error_buffer, "Unhandled code %d, shape %d, record %d\n", dbf_field[j+nFields].field_type, i, j ); mexErrMsgTxt("Unhandled code"); } } SHPDestroyObject( psShape ); } if ( isPoint ) { /* In this case we still need to "send the true data out" */ mxSetField ( out_struct, 0, "X", x_out ); mxSetField ( out_struct, 0, "Y", y_out ); if (nShapeType == SHPT_POINTZ) mxSetField ( out_struct, 0, "Z", z_out ); } /* Clean up, close up shop. */ SHPClose( hSHP ); DBFClose ( dbh ); if ( dbf_field != NULL ) mxFree ( (void *)dbf_field ); plhs[0] = out_struct; }
mxArray *sf_c2_ARP_02_RPSsmile_Glove_get_autoinheritance_info(void) { const char *autoinheritanceFields[] = { "checksum", "inputs", "parameters", "outputs", "locals" }; mxArray *mxAutoinheritanceInfo = mxCreateStructMatrix(1,1,5, autoinheritanceFields); { mxArray *mxChecksum = mxCreateString("ytkMaZ3LJMwsAy7iUSYW1D"); mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum); } { const char *dataFields[] = { "size", "type", "complexity" }; mxArray *mxData = mxCreateStructMatrix(1,7,3,dataFields); { mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL); double *pr = mxGetPr(mxSize); pr[0] = (double)(1); pr[1] = (double)(1); mxSetField(mxData,0,"size",mxSize); } { const char *typeFields[] = { "base", "fixpt" }; mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields); mxSetField(mxType,0,"base",mxCreateDoubleScalar(10)); mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL)); mxSetField(mxData,0,"type",mxType); } mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0)); { mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL); double *pr = mxGetPr(mxSize); pr[0] = (double)(1); pr[1] = (double)(1); mxSetField(mxData,1,"size",mxSize); } { const char *typeFields[] = { "base", "fixpt" }; mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields); mxSetField(mxType,0,"base",mxCreateDoubleScalar(10)); mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL)); mxSetField(mxData,1,"type",mxType); } mxSetField(mxData,1,"complexity",mxCreateDoubleScalar(0)); { mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL); double *pr = mxGetPr(mxSize); pr[0] = (double)(1); pr[1] = (double)(1); mxSetField(mxData,2,"size",mxSize); } { const char *typeFields[] = { "base", "fixpt" }; mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields); mxSetField(mxType,0,"base",mxCreateDoubleScalar(10)); mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL)); mxSetField(mxData,2,"type",mxType); } mxSetField(mxData,2,"complexity",mxCreateDoubleScalar(0)); { mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL); double *pr = mxGetPr(mxSize); pr[0] = (double)(1); pr[1] = (double)(1); mxSetField(mxData,3,"size",mxSize); } { const char *typeFields[] = { "base", "fixpt" }; mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields); mxSetField(mxType,0,"base",mxCreateDoubleScalar(10)); mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL)); mxSetField(mxData,3,"type",mxType); } mxSetField(mxData,3,"complexity",mxCreateDoubleScalar(0)); { mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL); double *pr = mxGetPr(mxSize); pr[0] = (double)(1); pr[1] = (double)(1); mxSetField(mxData,4,"size",mxSize); } { const char *typeFields[] = { "base", "fixpt" }; mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields); mxSetField(mxType,0,"base",mxCreateDoubleScalar(10)); mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL)); mxSetField(mxData,4,"type",mxType); } mxSetField(mxData,4,"complexity",mxCreateDoubleScalar(0)); { mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL); double *pr = mxGetPr(mxSize); pr[0] = (double)(1); pr[1] = (double)(1); mxSetField(mxData,5,"size",mxSize); } { const char *typeFields[] = { "base", "fixpt" }; mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields); mxSetField(mxType,0,"base",mxCreateDoubleScalar(10)); mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL)); mxSetField(mxData,5,"type",mxType); } mxSetField(mxData,5,"complexity",mxCreateDoubleScalar(0)); { mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL); double *pr = mxGetPr(mxSize); pr[0] = (double)(1); pr[1] = (double)(1); mxSetField(mxData,6,"size",mxSize); } { const char *typeFields[] = { "base", "fixpt" }; mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields); mxSetField(mxType,0,"base",mxCreateDoubleScalar(10)); mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL)); mxSetField(mxData,6,"type",mxType); } mxSetField(mxData,6,"complexity",mxCreateDoubleScalar(0)); mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData); } { mxSetField(mxAutoinheritanceInfo,0,"parameters",mxCreateDoubleMatrix(0,0, mxREAL)); } { mxSetField(mxAutoinheritanceInfo,0,"outputs",mxCreateDoubleMatrix(0,0,mxREAL)); } { mxSetField(mxAutoinheritanceInfo,0,"locals",mxCreateDoubleMatrix(0,0,mxREAL)); } return(mxAutoinheritanceInfo); }
PsychError PSYCHHIDReceiveReports(void) { long error=0; int deviceIndex; mxArray **mxErrPtr; const mxArray *mxOptions,*mx; PsychPushHelp(useString,synopsisString,seeAlsoString); if(PsychIsGiveHelp()){PsychGiveHelp();return(PsychError_none);}; PsychErrorExit(PsychCapNumOutputArgs(1)); PsychErrorExit(PsychCapNumInputArgs(2)); PsychCopyInIntegerArg(1,TRUE,&deviceIndex); if(deviceIndex < 0 || deviceIndex >= MAXDEVICEINDEXS) PrintfExit("Sorry. Can't cope with deviceNumber %d (more than %d). Please tell [email protected]",deviceIndex, (int) MAXDEVICEINDEXS-1); /* "\"options.print\" =1 (default 0) enables diagnostic printing of a summary of each report when our callback routine receives it. " "\"options.printCrashers\" =1 (default 0) enables diagnostic printing of the creation of the callback source and its addition to the CFRunLoop. " "\"options.maxReports\" (default 10000) allocate space for at least this many reports, shared among all devices. " "\"options.maxReportSize\" (default 65) allocate this many bytes per report. " */ //optionsPrintReportSummary=0; // options.print //optionsPrintCrashers=0; // options.printCrashers //optionsMaxReports=10000; // options.maxReports //optionsMaxReportSize=65; // options.maxReportSize //optionsSecs=0.010; // options.secs mxOptions=PsychGetInArgMxPtr(2); if(mxOptions!=NULL){ mx=mxGetField(mxOptions,0,"print"); if(mx!=NULL)optionsPrintReportSummary=(psych_bool)mxGetScalar(mx); mx=mxGetField(mxOptions,0,"printCrashers"); if(mx!=NULL)optionsPrintCrashers=(psych_bool)mxGetScalar(mx); mx=mxGetField(mxOptions,0,"secs"); if(mx!=NULL)optionsSecs=mxGetScalar(mx); mx=mxGetField(mxOptions,0,"consistencyChecks"); if(mx!=NULL)optionsConsistencyChecks=(psych_bool)mxGetScalar(mx); // Changing maxReports or maxReportSize triggers a reallocation of // buffer memory: mx=mxGetField(mxOptions,0,"maxReports"); if(mx!=NULL) { oneShotRealloc = TRUE; optionsMaxReports = (int) mxGetScalar(mx); } mx=mxGetField(mxOptions,0,"maxReportSize"); if(mx!=NULL) { oneShotRealloc = TRUE; optionsMaxReportSize = (int) mxGetScalar(mx); } } // Sanity check: if(optionsMaxReports < 1) PsychErrorExitMsg(PsychError_user, "PsychHID ReceiveReports: Sorry, requested maxReports count must be at least 1!"); if(optionsMaxReportSize < 1) PsychErrorExitMsg(PsychError_user, "PsychHID ReceiveReports: Sorry, requested maxReportSize must be at least 1 byte!"); if(optionsMaxReportSize > MAXREPORTSIZE) { printf("PsychHID ReceiveReports: Sorry, requested maximum report size %d bytes exceeds built-in maximum of %d bytes.\n", optionsMaxReportSize, (int) MAXREPORTSIZE); PsychErrorExitMsg(PsychError_user, "Invalid option.maxReportSize provided!"); } // Start reception of reports: This will also allocate memory for the reports // on first invocation for this deviceIndex: error = ReceiveReports(deviceIndex); mxErrPtr=PsychGetOutArgMxPtr(1); if(mxErrPtr!=NULL){ const char *fieldNames[]={"n", "name", "description"}; char *name="",*description=""; mxArray *fieldValue; PsychHIDErrors(NULL, error,&name,&description); // Get error name and description, if available. *mxErrPtr=mxCreateStructMatrix(1,1,3,fieldNames); fieldValue=mxCreateString(name); if(fieldValue==NULL)PrintfExit("PSYCHHIDReceiveReports: Couldn't allocate \"err\"."); mxSetField(*mxErrPtr,0,"name",fieldValue); fieldValue=mxCreateString(description); if(fieldValue==NULL)PrintfExit("PSYCHHIDReceiveReports: Couldn't allocate \"err\"."); mxSetField(*mxErrPtr,0,"description",fieldValue); fieldValue=mxCreateDoubleMatrix(1,1,mxREAL); if(fieldValue==NULL)PrintfExit("PSYCHHIDReceiveReports: Couldn't allocate \"err\"."); *mxGetPr(fieldValue)=(double)error; mxSetField(*mxErrPtr,0,"n",fieldValue); } return(PsychError_none); }
mxArray *sf_c16_HIL_model_overall_get_autoinheritance_info(void) { const char *autoinheritanceFields[] = { "checksum", "inputs", "parameters", "outputs", "locals" }; mxArray *mxAutoinheritanceInfo = mxCreateStructMatrix(1,1,5, autoinheritanceFields); { mxArray *mxChecksum = mxCreateString("G64yU3zmbafFuwxSzxbspC"); mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum); } { const char *dataFields[] = { "size", "type", "complexity" }; mxArray *mxData = mxCreateStructMatrix(1,4,3,dataFields); { mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL); double *pr = mxGetPr(mxSize); pr[0] = (double)(2); pr[1] = (double)(2); mxSetField(mxData,0,"size",mxSize); } { const char *typeFields[] = { "base", "fixpt" }; mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields); mxSetField(mxType,0,"base",mxCreateDoubleScalar(10)); mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL)); mxSetField(mxData,0,"type",mxType); } mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0)); { mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL); double *pr = mxGetPr(mxSize); pr[0] = (double)(1); pr[1] = (double)(1); mxSetField(mxData,1,"size",mxSize); } { const char *typeFields[] = { "base", "fixpt" }; mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields); mxSetField(mxType,0,"base",mxCreateDoubleScalar(10)); mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL)); mxSetField(mxData,1,"type",mxType); } mxSetField(mxData,1,"complexity",mxCreateDoubleScalar(0)); { mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL); double *pr = mxGetPr(mxSize); pr[0] = (double)(1); pr[1] = (double)(1); mxSetField(mxData,2,"size",mxSize); } { const char *typeFields[] = { "base", "fixpt" }; mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields); mxSetField(mxType,0,"base",mxCreateDoubleScalar(10)); mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL)); mxSetField(mxData,2,"type",mxType); } mxSetField(mxData,2,"complexity",mxCreateDoubleScalar(0)); { mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL); double *pr = mxGetPr(mxSize); pr[0] = (double)(1); pr[1] = (double)(1); mxSetField(mxData,3,"size",mxSize); } { const char *typeFields[] = { "base", "fixpt" }; mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields); mxSetField(mxType,0,"base",mxCreateDoubleScalar(10)); mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL)); mxSetField(mxData,3,"type",mxType); } mxSetField(mxData,3,"complexity",mxCreateDoubleScalar(0)); mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData); } { mxSetField(mxAutoinheritanceInfo,0,"parameters",mxCreateDoubleMatrix(0,0, mxREAL)); } { const char *dataFields[] = { "size", "type", "complexity" }; mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields); { mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL); double *pr = mxGetPr(mxSize); pr[0] = (double)(3); pr[1] = (double)(1); mxSetField(mxData,0,"size",mxSize); } { const char *typeFields[] = { "base", "fixpt" }; mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields); mxSetField(mxType,0,"base",mxCreateDoubleScalar(10)); mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL)); mxSetField(mxData,0,"type",mxType); } mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0)); mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData); } { mxSetField(mxAutoinheritanceInfo,0,"locals",mxCreateDoubleMatrix(0,0,mxREAL)); } return(mxAutoinheritanceInfo); }
mxArray *sf_c2_SALTStabilizationInnerOuterLoopSIM_get_autoinheritance_info(void) { const char *autoinheritanceFields[] = { "checksum", "inputs", "parameters", "outputs", "locals" }; mxArray *mxAutoinheritanceInfo = mxCreateStructMatrix(1,1,5, autoinheritanceFields); { mxArray *mxChecksum = mxCreateString("xG35iPbBEaGhACUEmUwYK"); mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum); } { const char *dataFields[] = { "size", "type", "complexity" }; mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields); { mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL); double *pr = mxGetPr(mxSize); pr[0] = (double)(1); pr[1] = (double)(1); mxSetField(mxData,0,"size",mxSize); } { const char *typeFields[] = { "base", "fixpt" }; mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields); mxSetField(mxType,0,"base",mxCreateDoubleScalar(9)); mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL)); mxSetField(mxData,0,"type",mxType); } mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0)); mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData); } { mxSetField(mxAutoinheritanceInfo,0,"parameters",mxCreateDoubleMatrix(0,0, mxREAL)); } { const char *dataFields[] = { "size", "type", "complexity" }; mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields); { mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL); double *pr = mxGetPr(mxSize); pr[0] = (double)(1); pr[1] = (double)(1); mxSetField(mxData,0,"size",mxSize); } { const char *typeFields[] = { "base", "fixpt" }; mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields); mxSetField(mxType,0,"base",mxCreateDoubleScalar(9)); mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL)); mxSetField(mxData,0,"type",mxType); } mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0)); mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData); } { mxSetField(mxAutoinheritanceInfo,0,"locals",mxCreateDoubleMatrix(0,0,mxREAL)); } return(mxAutoinheritanceInfo); }
void mexFunction ( /* === Parameters ======================================================= */ int nlhs, /* number of left-hand sides */ mxArray *plhs [], /* left-hand side matrices */ int nrhs, /* number of right--hand sides */ const mxArray *prhs [] /* right-hand side matrices */ ) { Zmat A; char *fname, rhstyp[4], title[81], key[9], type[4]; int i,j,k,l, mynrhs, status; integer nrhsix, m, *rhsptr=NULL, *rhsind=NULL, ierr, nr,nc,nz, tmp,tmp0,tmp2,tmp3,ncolumns; size_t mrows, ncols, sizebuf; mwSize nnz, buflen; mwIndex *irs, *jcs; double *pr, *pi, *sr, *si; doublecomplex *sol, *rhs=NULL, *rhsval=NULL; mxArray *fout, *f_input; FILE *fp; if (nrhs!=1) mexErrMsgTxt("Only one input argument required."); else if (nlhs!=3) mexErrMsgTxt("Three output arguments are required."); else if (mxGetClassID(prhs[0])!=mxCHAR_CLASS) mexErrMsgTxt("Input must be a string."); /* get filename */ f_input = (mxArray *) prhs[0]; mrows = mxGetM (f_input) ; ncols = mxGetN (f_input) ; /* Get the length of the input string. */ buflen = (mrows*ncols) + 1; /* Allocate memory for input and output strings. */ fname = (char *) mxCalloc((size_t)buflen, (size_t)sizeof(char)); /* Copy the string data from tmp into a C string pdata */ status = mxGetString(f_input, fname, buflen); ncolumns = 0; tmp0 = 0; if ((fp=fopen(fname,"r"))==NULL) { mexPrintf(" file %s",fname); mexErrMsgTxt(" not found"); return; } fclose(fp); rhstyp[0]=' '; rhstyp[1]=' '; rhstyp[2]=' '; A.nc=0; Zreadmtc(&tmp0,&tmp0,&tmp0,fname,A.a,A.ja,A.ia, rhs,&ncolumns,rhstyp,&nr,&nc,&nz,title,key,type, &nrhsix,rhsptr,rhsind,rhsval,&ierr,strlen(fname),2,72,8,3); ncols=ncolumns; /* if a right hand side is given, then use these */ if (ierr) { mexPrintf(" ierr = %d\n",ierr); mexErrMsgTxt(" error in reading the matrix, stop.\n"); switch(ierr) { case 1: mexErrMsgTxt("too many columns\n"); break; case 2: mexErrMsgTxt("too many nonzeros\n"); break; case 3: mexErrMsgTxt("too many columns and nonzeros\n"); break; case 4: mexErrMsgTxt("right hand side has incompatible type\n"); break; case 5: mexErrMsgTxt("too many right hand side entries\n"); break; case 6: mexErrMsgTxt("wrong type (real/complex)\n"); break; } exit(ierr); } if (ncols>0) { m=1; if (rhstyp[1]=='G' || rhstyp[1]=='g') { m++; } if (rhstyp[2]=='X' || rhstyp[2]=='x') { m++; } } else m=0; m*=nr*ncols; rhsptr=NULL; rhsind=NULL; rhsval=NULL; if (ncols!=0 && (rhstyp[0]=='M' || rhstyp[0]=='m')) { rhsptr=(integer *) MAlloc((size_t)(ncols+1)*sizeof(integer),"Zloadhbo:rhsptr"); rhsind=(integer *) MAlloc((size_t)nrhsix*sizeof(integer), "Zloadhbo:rhsind"); rhsval=(doublecomplex *) MAlloc((size_t)nrhsix*sizeof(doublecomplex), "Zloadhbo:rhsval"); } A.ia=(integer *) MAlloc((size_t)(nc+1)*sizeof(integer), "Zloadhbo:A.ia"); A.ja=(integer *) MAlloc((size_t)nz*sizeof(integer), "Zloadhbo:A.ja"); A.a =(doublecomplex*)MAlloc((size_t)nz*sizeof(doublecomplex),"Zloadhbo:A.a"); A.nr=nr; A.nc=nc; rhs =(doublecomplex *)MAlloc((size_t)m*sizeof(doublecomplex),"Zloadhbo:rhs"); /* advance pointer to reserve space when uncompressing the right hand side */ if (ncols!=0 && (rhstyp[0]=='M' || rhstyp[0]=='m')) rhs+=nr*ncols; tmp = 3; tmp2 = nc; tmp3 = nz; if (ncols!=0 && (rhstyp[0]=='M' || rhstyp[0]=='m')) m-=nr*ncols; Zreadmtc(&tmp2,&tmp3,&tmp,fname,A.a,A.ja,A.ia, rhs,&m,rhstyp,&nr,&nc,&nz,title,key,type, &nrhsix,rhsptr,rhsind,rhsval,&ierr,strlen(fname),2,72,8,3); if (ncols!=0 && (rhstyp[0]=='M' || rhstyp[0]=='m')) m+=nr*ncols; if (ierr) { mexPrintf(" ierr = %d\n",ierr); mexErrMsgTxt(" error in reading the matrix, stop.\n"); return; } /* set output parameters */ nlhs=3; fout =mxCreateSparse((mwSize)nr,(mwSize)nc, (mwSize)nz, mxCOMPLEX); plhs[0]=fout; sr = (double *) mxGetPr(fout); si = (double *) mxGetPi(fout); irs = (mwIndex *) mxGetIr(fout); jcs = (mwIndex *) mxGetJc(fout); jcs[0]=0; for (i=0; i<nc; i++) { jcs[i+1]=A.ia[i+1]-1; for (j=A.ia[i]-1; j<A.ia[i+1]-1; j++) { irs[j]=A.ja[j]-1; sr[j] =A.a[j].r; si[j] =A.a[j].i; } } if (ncols>0) { m=1; if (rhstyp[1]=='G' || rhstyp[1]=='g') { m++; } if (rhstyp[2]=='X' || rhstyp[2]=='x') { m++; } } else m=0; fout=mxCreateDoubleMatrix((mwSize)nr,(mwSize)m*ncols, mxCOMPLEX); plhs[1]=fout; if (ncols!=0 && (rhstyp[0]=='M' || rhstyp[0]=='m')) { } else { pr = mxGetPr(fout); pi = mxGetPi(fout); for (i=0; i<nr*m*ncols; i++) { pr[i]=rhs[i].r; pi[i]=rhs[i].i; } } rhstyp[3]='\0'; plhs[2] = mxCreateString(rhstyp); free(A.a); free(A.ia); free(A.ja); if (ncols>0) free(rhs); if (ncols!=0 && (rhstyp[0]=='M' || rhstyp[0]=='m')) { free(rhsptr); free(rhsind); free(rhsval); } return; }
/* * [type, num_constraint, constraint_val, dconstraint_val, constraint_name, lower_bound, upper_bound] * = testSingleTimeKinCnstmex(kinCnst_ptr, q, t) * @param kinCnst_ptr A pointer to a SingleTimeKinematicConstraint * object * @param q A nqx1 double vector * @param t A double scalar, the time to evaluate constraint * value, bounds and name. This is optional. * @retval type The type of the constraint * @retval num_constraint The number of constraint active at time t * @retval constraint_val The value of the constraint at time t * @retval dconstraint_val The gradient of the constraint w.r.t q at time t * @retval constraint_name The name of the constraint at time t * @retval lower_bound The lower bound of the constraint at time t * @retval upper_bound The upper bound of the constraint at time t * */ void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) { if ((nrhs != 3 && nrhs != 2) || nlhs != 7) { mexErrMsgIdAndTxt("Drake:testSingleTimeKinCnstmex:BadInputs", "Usage [type, " "num_cnst, cnst_val, dcnst_val, cnst_name, lb, ub] = " "testSingleTimeKinKinCnstmex(kinCnst, q, t)"); } SingleTimeKinematicConstraint* cnst = (SingleTimeKinematicConstraint*)getDrakeMexPointer(prhs[0]); double* t_ptr; if (nrhs == 2) { t_ptr = nullptr; } else { size_t num_t = mxGetNumberOfElements(prhs[2]); if (num_t == 0) { t_ptr = nullptr; } if (num_t == 1) { t_ptr = mxGetPrSafe(prhs[2]); } if (num_t > 1) { mexErrMsgIdAndTxt("Drake:testSingleTimeKinCnstmex:BadInputs", "t must be either empty or a single number"); } } int type = cnst->getType(); int num_cnst = cnst->getNumConstraint(t_ptr); // mexPrintf("num_cnst = %d\n", num_cnst); int nq = cnst->getRobotPointer()->get_num_positions(); Eigen::Map<Eigen::VectorXd> q(mxGetPrSafe(prhs[1]), nq); KinematicsCache<double> cache = cnst->getRobotPointer()->doKinematics(q); Eigen::VectorXd c(num_cnst); Eigen::MatrixXd dc(num_cnst, nq); cnst->eval(t_ptr, cache, c, dc); // mexPrintf("get c, dc\n"); Eigen::VectorXd lb(num_cnst); Eigen::VectorXd ub(num_cnst); cnst->bounds(t_ptr, lb, ub); // mexPrintf("get lb, ub\n"); std::vector<std::string> cnst_names; cnst->name(t_ptr, cnst_names); // mexPrintf("get name\n"); int retvec_size; if (num_cnst == 0) { retvec_size = 0; } else { retvec_size = 1; } plhs[0] = mxCreateDoubleScalar((double)type); plhs[1] = mxCreateDoubleScalar((double)num_cnst); plhs[2] = mxCreateDoubleMatrix(num_cnst, retvec_size, mxREAL); memcpy(mxGetPrSafe(plhs[2]), c.data(), sizeof(double) * num_cnst); plhs[3] = mxCreateDoubleMatrix(num_cnst, nq, mxREAL); memcpy(mxGetPrSafe(plhs[3]), dc.data(), sizeof(double) * num_cnst * nq); int name_ndim = 1; mwSize name_dims[] = {(mwSize)num_cnst}; plhs[4] = mxCreateCellArray(name_ndim, name_dims); mxArray* name_ptr; for (int i = 0; i < num_cnst; i++) { name_ptr = mxCreateString(cnst_names[i].c_str()); mxSetCell(plhs[4], i, name_ptr); } plhs[5] = mxCreateDoubleMatrix(num_cnst, retvec_size, mxREAL); plhs[6] = mxCreateDoubleMatrix(num_cnst, retvec_size, mxREAL); memcpy(mxGetPrSafe(plhs[5]), lb.data(), sizeof(double) * num_cnst); memcpy(mxGetPrSafe(plhs[6]), ub.data(), sizeof(double) * num_cnst); }
// Calling convention: // comp_filterbank(f,g,a); void mexFunction( int UNUSED(nlhs), mxArray *plhs[], int UNUSED(nrhs), const mxArray *prhs[] ) { static int atExitRegistered = 0; if(!atExitRegistered) { atExitRegistered = 1; mexAtExit(filterbankAtExit); } const mxArray* mxf = prhs[0]; const mxArray* mxg = prhs[1]; const mxArray* mxa = prhs[2]; // input data length const mwSize L = mxGetM(mxf); const mwSize W = mxGetN(mxf); // filter number const mwSize M = mxGetNumberOfElements(mxg); // a col count mwSize acols = mxGetN(mxa); // pointer to a double *a = (double*) mxGetData(mxa); if (acols > 1) { int isOnes = 1; for (mwIndex m = 0; m < M; m++) { isOnes = isOnes && a[M + m] == 1; } if (isOnes) { acols = 1; } } // Cell output plhs[0] = mxCreateCellMatrix(M, 1); // Stuff for sorting the filters mwSize tdCount = 0; mwSize fftCount = 0; mwSize fftblCount = 0; mwIndex tdArgsIdx[M]; mwIndex fftArgsIdx[M]; mwIndex fftblArgsIdx[M]; // WALK the filters to determine what has to be done for (mwIndex m = 0; m < M; m++) { mxArray * gEl = mxGetCell(mxg, m); if (mxGetField(gEl, 0, "h") != NULL) { tdArgsIdx[tdCount++] = m; continue; } if (mxGetField(gEl, 0, "H") != NULL) { if (acols == 1 && L == mxGetNumberOfElements(mxGetField(gEl, 0, "H"))) { fftArgsIdx[fftCount++] = m; continue; } else { fftblArgsIdx[fftblCount++] = m; continue; } } } if (tdCount > 0) { /* Here, we have to reformat the inputs and pick up results to comply with: c=comp_filterbank_td(f,g,a,offset,ext); BEWARE OF THE AUTOMATIC DEALLOCATION!! by the Matlab engine. Arrays can be very easily freed twice causing segfaults. This happends particulary when using mxCreateCell* which stores pointers to other mxArray structs. Setting all such pointers to NULL after they are used seems to solve it. */ mxArray* plhs_td[1]; mxArray* prhs_td[5]; prhs_td[0] = (mxArray*) mxf; prhs_td[1] = mxCreateCellMatrix(tdCount, 1); prhs_td[2] = mxCreateDoubleMatrix(tdCount, 1, mxREAL); double* aPtr = mxGetData(prhs_td[2]); prhs_td[3] = mxCreateDoubleMatrix(tdCount, 1, mxREAL); double* offsetPtr = mxGetData(prhs_td[3]); prhs_td[4] = mxCreateString("per"); for (mwIndex m = 0; m < tdCount; m++) { mxArray * gEl = mxGetCell(mxg, tdArgsIdx[m]); mxSetCell(prhs_td[1], m, mxGetField(gEl, 0, "h")); // This has overhead //mxSetCell((mxArray*)prhs_td[1],m,mxDuplicateArray(mxGetField(gEl,0,"h"))); aPtr[m] = a[tdArgsIdx[m]]; offsetPtr[m] = mxGetScalar(mxGetField(gEl, 0, "offset")); } // Finally call it! // comp_filterbank_td(1,plhs_td,5, prhs_td); // This has overhead: mexCallMATLAB(1, plhs_td, 5, prhs_td, "comp_filterbank_td"); // Copy pointers to a proper index in the output + unset all duplicate cell elements for (mwIndex m = 0; m < tdCount; m++) { mxSetCell(plhs[0], tdArgsIdx[m], mxGetCell(plhs_td[0], m)); mxSetCell(plhs_td[0], m, NULL); mxSetCell(prhs_td[1], m, NULL); } mxDestroyArray(plhs_td[0]); mxDestroyArray(prhs_td[1]); mxDestroyArray(prhs_td[2]); mxDestroyArray(prhs_td[3]); mxDestroyArray(prhs_td[4]); } if (fftCount > 0 || fftblCount > 0) { // Need to do FFT of mxf mwIndex ndim = 2; const mwSize dims[] = {L, W}; if (mxF == NULL || mxGetM(mxF) != L || mxGetN(mxF) != W || mxGetClassID(mxF) != mxGetClassID(mxf)) { if (mxF != NULL) { mxDestroyArray(mxF); mxF = NULL; // printf("Should be called just once\n"); } if (mxIsDouble(mxf)) { mxF = mxCreateNumericArray(ndim, dims, mxDOUBLE_CLASS, mxCOMPLEX); fftw_iodim fftw_dims[1]; fftw_iodim howmanydims[1]; fftw_dims[0].n = L; fftw_dims[0].is = 1; fftw_dims[0].os = 1; howmanydims[0].n = W; howmanydims[0].is = L; howmanydims[0].os = L; if (p_double == NULL) p_double = (fftw_plan*) malloc(sizeof(fftw_plan)); else fftw_destroy_plan(*p_double); // FFTW_MEASURE sometimes hangs here *p_double = fftw_plan_guru_split_dft( 1, fftw_dims, 1, howmanydims, mxGetData(mxF), mxGetImagData(mxF), mxGetData(mxF), mxGetImagData(mxF), FFTW_ESTIMATE); } else if (mxIsSingle(mxf)) { mxF = mxCreateNumericArray(ndim, dims, mxSINGLE_CLASS, mxCOMPLEX); // mexPrintf("M= %i, N= %i\n",mxGetM(mxF),mxGetN(mxF)); fftwf_iodim fftw_dims[1]; fftwf_iodim howmanydims[1]; fftw_dims[0].n = L; fftw_dims[0].is = 1; fftw_dims[0].os = 1; howmanydims[0].n = W; howmanydims[0].is = L; howmanydims[0].os = L; if (p_float == NULL) p_float = (fftwf_plan*) malloc(sizeof(fftwf_plan)); else fftwf_destroy_plan(*p_float); *p_float = fftwf_plan_guru_split_dft( 1, fftw_dims, 1, howmanydims, mxGetData(mxF), mxGetImagData(mxF), mxGetData(mxF), mxGetImagData(mxF), FFTW_ESTIMATE); } } if (mxIsDouble(mxf)) { memcpy(mxGetPr(mxF), mxGetPr(mxf), L * W * sizeof(double)); memset(mxGetPi(mxF), 0, L * W * sizeof(double)); if (mxIsComplex(mxf)) memcpy(mxGetPi(mxF), mxGetPi(mxf), L * W * sizeof(double)); fftw_execute(*p_double); } else if (mxIsSingle(mxf)) { memcpy(mxGetPr(mxF), mxGetPr(mxf), L * W * sizeof(float)); memset(mxGetPi(mxF), 0, L * W * sizeof(float)); if (mxIsComplex(mxf)) memcpy(mxGetPi(mxF), mxGetPi(mxf), L * W * sizeof(float)); fftwf_execute(*p_float); } } if (fftCount > 0) { mxArray* plhs_fft[1]; mxArray* prhs_fft[3]; prhs_fft[0] = mxF; prhs_fft[1] = mxCreateCellMatrix(fftCount, 1); prhs_fft[2] = mxCreateDoubleMatrix(fftCount, 1, mxREAL); double* aPtr = mxGetData(prhs_fft[2]); for (mwIndex m = 0; m < fftCount; m++) { mxArray * gEl = mxGetCell(mxg, fftArgsIdx[m]); mxSetCell(prhs_fft[1], m, mxGetField(gEl, 0, "H")); // This has overhead //mxSetCell((mxArray*)prhs_td[1],m,mxDuplicateArray(mxGetField(gEl,0,"h"))); aPtr[m] = a[fftArgsIdx[m]]; } //comp_filterbank_fft(1,plhs_fft,3, prhs_fft); mexCallMATLAB(1, plhs_fft, 3, prhs_fft, "comp_filterbank_fft"); for (mwIndex m = 0; m < fftCount; m++) { mxSetCell(plhs[0], fftArgsIdx[m], mxGetCell(plhs_fft[0], m)); mxSetCell(plhs_fft[0], m, NULL); mxSetCell(prhs_fft[1], m, NULL); } mxDestroyArray(plhs_fft[0]); mxDestroyArray(prhs_fft[1]); mxDestroyArray(prhs_fft[2]); } if (fftblCount > 0) { mxArray* plhs_fftbl[1]; mxArray* prhs_fftbl[5]; prhs_fftbl[0] = mxF; prhs_fftbl[1] = mxCreateCellMatrix(fftblCount, 1); prhs_fftbl[2] = mxCreateDoubleMatrix(fftblCount, 1, mxREAL); prhs_fftbl[3] = mxCreateDoubleMatrix(fftblCount, 2, mxREAL); prhs_fftbl[4] = mxCreateDoubleMatrix(fftblCount, 1, mxREAL); double* foffPtr = mxGetData(prhs_fftbl[2]); double* aPtr = mxGetData(prhs_fftbl[3]); double* realonlyPtr = mxGetData(prhs_fftbl[4]); // Set all realonly flags to zero memset(realonlyPtr, 0, fftblCount * sizeof * realonlyPtr); for (mwIndex m = 0; m < fftblCount; m++) { mxArray * gEl = mxGetCell(mxg, fftblArgsIdx[m]); mxSetCell(prhs_fftbl[1], m, mxGetField(gEl, 0, "H")); foffPtr[m] = mxGetScalar(mxGetField(gEl, 0, "foff")); aPtr[m] = a[fftblArgsIdx[m]]; if (acols > 1) aPtr[m + fftblCount] = a[fftblArgsIdx[m] + M]; else aPtr[m + fftblCount] = 1; // Only if realonly is specified mxArray* mxrealonly; if ((mxrealonly = mxGetField(gEl, 0, "realonly"))) realonlyPtr[m] = mxGetScalar(mxrealonly); } // comp_filterbank_fftbl(1,plhs_fftbl,5, prhs_fftbl); mexCallMATLAB(1, plhs_fftbl, 5, prhs_fftbl, "comp_filterbank_fftbl"); for (mwIndex m = 0; m < fftblCount; m++) { mxSetCell(plhs[0], fftblArgsIdx[m], mxGetCell(plhs_fftbl[0], m)); mxSetCell(plhs_fftbl[0], m, NULL); mxSetCell(prhs_fftbl[1], m, NULL); } mxDestroyArray(plhs_fftbl[0]); mxDestroyArray(prhs_fftbl[1]); mxDestroyArray(prhs_fftbl[2]); mxDestroyArray(prhs_fftbl[3]); mxDestroyArray(prhs_fftbl[4]); } if (mxF != NULL) mexMakeArrayPersistent(mxF); if (L * W > MAXARRAYLEN && mxF != NULL) { //printf("Damn. Should not get here\n"); mxDestroyArray(mxF); mxF = NULL; } }
/* Function Definitions */ void do_vectors(const emlrtStack *sp, const real_T a_data[1224], const int32_T a_size[1], const real_T b[8], real_T c_data[8], int32_T c_size[1], int32_T ia_data[8], int32_T ia_size[1], int32_T ib_data[8], int32_T ib_size[1]) { int32_T ncmax; boolean_T y; int32_T ialast; boolean_T exitg4; boolean_T guard9 = FALSE; boolean_T p; boolean_T exitg3; boolean_T guard8 = FALSE; int32_T nc; int32_T iafirst; int32_T ibfirst; int32_T iblast; int32_T b_ialast; real_T ak; boolean_T exitg2; real_T absxk; int32_T exponent; boolean_T guard6 = FALSE; boolean_T guard7 = FALSE; int32_T b_iblast; real_T bk; boolean_T exitg1; int32_T b_exponent; boolean_T guard4 = FALSE; boolean_T guard5 = FALSE; int32_T c_exponent; boolean_T guard2 = FALSE; boolean_T guard3 = FALSE; boolean_T guard1 = FALSE; const mxArray *b_y; const mxArray *m37; int32_T b_ia_data[8]; const mxArray *c_y; const mxArray *d_y; real_T b_c_data[8]; emlrtStack st; st.prev = sp; st.tls = sp->tls; st.site = &dw_emlrtRSI; ncmax = muIntScalarMin_sint32(a_size[0], 8); c_size[0] = (int8_T)ncmax; ia_size[0] = ncmax; ib_size[0] = ncmax; st.site = &ew_emlrtRSI; y = TRUE; if (a_size[0] == 0) { } else { ialast = 1; exitg4 = FALSE; while ((exitg4 == FALSE) && (ialast <= a_size[0] - 1)) { guard9 = FALSE; if (a_data[ialast - 1] <= a_data[ialast]) { guard9 = TRUE; } else if (muDoubleScalarIsNaN(a_data[ialast])) { guard9 = TRUE; } else { p = FALSE; } if (guard9 == TRUE) { p = TRUE; } if (!p) { y = FALSE; exitg4 = TRUE; } else { ialast++; } } } if (!y) { st.site = &fw_emlrtRSI; eml_error(&st); } st.site = &gw_emlrtRSI; y = TRUE; ialast = 1; exitg3 = FALSE; while ((exitg3 == FALSE) && (ialast < 8)) { guard8 = FALSE; if (b[ialast - 1] <= b[ialast]) { guard8 = TRUE; } else if (muDoubleScalarIsNaN(b[ialast])) { guard8 = TRUE; } else { p = FALSE; } if (guard8 == TRUE) { p = TRUE; } if (!p) { y = FALSE; exitg3 = TRUE; } else { ialast++; } } if (!y) { st.site = &hw_emlrtRSI; b_eml_error(&st); } nc = 0; iafirst = 0; ialast = 0; ibfirst = 0; iblast = 0; while ((ialast + 1 <= a_size[0]) && (iblast + 1 <= 8)) { st.site = &iw_emlrtRSI; b_ialast = ialast + 1; ak = a_data[ialast]; exitg2 = FALSE; while ((exitg2 == FALSE) && (b_ialast < a_size[0])) { absxk = muDoubleScalarAbs(a_data[ialast] / 2.0); if ((!muDoubleScalarIsInf(absxk)) && (!muDoubleScalarIsNaN(absxk))) { if (absxk <= 2.2250738585072014E-308) { absxk = 4.94065645841247E-324; } else { frexp(absxk, &exponent); absxk = ldexp(1.0, exponent - 53); } } else { absxk = rtNaN; } guard6 = FALSE; guard7 = FALSE; if (muDoubleScalarAbs(a_data[ialast] - a_data[b_ialast]) < absxk) { guard7 = TRUE; } else if (muDoubleScalarIsInf(a_data[b_ialast])) { if (muDoubleScalarIsInf(a_data[ialast]) && ((a_data[b_ialast] > 0.0) == (a_data[ialast] > 0.0))) { guard7 = TRUE; } else { guard6 = TRUE; } } else { guard6 = TRUE; } if (guard7 == TRUE) { p = TRUE; } if (guard6 == TRUE) { p = FALSE; } if (p) { b_ialast++; } else { exitg2 = TRUE; } } ialast = b_ialast - 1; st.site = &jw_emlrtRSI; b_iblast = iblast + 1; bk = b[iblast]; exitg1 = FALSE; while ((exitg1 == FALSE) && (b_iblast < 8)) { absxk = muDoubleScalarAbs(b[iblast] / 2.0); if ((!muDoubleScalarIsInf(absxk)) && (!muDoubleScalarIsNaN(absxk))) { if (absxk <= 2.2250738585072014E-308) { absxk = 4.94065645841247E-324; } else { frexp(absxk, &b_exponent); absxk = ldexp(1.0, b_exponent - 53); } } else { absxk = rtNaN; } guard4 = FALSE; guard5 = FALSE; if (muDoubleScalarAbs(b[iblast] - b[b_iblast]) < absxk) { guard5 = TRUE; } else if (muDoubleScalarIsInf(b[b_iblast])) { if (muDoubleScalarIsInf(b[iblast]) && ((b[b_iblast] > 0.0) == (b[iblast] > 0.0))) { guard5 = TRUE; } else { guard4 = TRUE; } } else { guard4 = TRUE; } if (guard5 == TRUE) { p = TRUE; } if (guard4 == TRUE) { p = FALSE; } if (p) { b_iblast++; } else { exitg1 = TRUE; } } iblast = b_iblast - 1; st.site = &kw_emlrtRSI; absxk = muDoubleScalarAbs(bk / 2.0); if ((!muDoubleScalarIsInf(absxk)) && (!muDoubleScalarIsNaN(absxk))) { if (absxk <= 2.2250738585072014E-308) { absxk = 4.94065645841247E-324; } else { frexp(absxk, &c_exponent); absxk = ldexp(1.0, c_exponent - 53); } } else { absxk = rtNaN; } guard2 = FALSE; guard3 = FALSE; if (muDoubleScalarAbs(bk - ak) < absxk) { guard3 = TRUE; } else if (muDoubleScalarIsInf(ak)) { if (muDoubleScalarIsInf(bk) && ((ak > 0.0) == (bk > 0.0))) { guard3 = TRUE; } else { guard2 = TRUE; } } else { guard2 = TRUE; } if (guard3 == TRUE) { p = TRUE; } if (guard2 == TRUE) { p = FALSE; } if (p) { st.site = &lw_emlrtRSI; nc++; c_data[nc - 1] = ak; ia_data[nc - 1] = iafirst + 1; ib_data[nc - 1] = ibfirst + 1; st.site = &mw_emlrtRSI; ialast = b_ialast; iafirst = b_ialast; st.site = &nw_emlrtRSI; iblast = b_iblast; ibfirst = b_iblast; } else { st.site = &ow_emlrtRSI; guard1 = FALSE; if (ak < bk) { guard1 = TRUE; } else if (muDoubleScalarIsNaN(bk)) { guard1 = TRUE; } else { p = FALSE; } if (guard1 == TRUE) { p = TRUE; } if (p) { st.site = &pw_emlrtRSI; ialast = b_ialast; iafirst = b_ialast; } else { st.site = &qw_emlrtRSI; iblast = b_iblast; ibfirst = b_iblast; } } } if (ncmax > 0) { if (nc <= ncmax) { } else { b_y = NULL; m37 = mxCreateString("Assertion failed."); emlrtAssign(&b_y, m37); st.site = &kbb_emlrtRSI; c_error(&st, b_y, &hb_emlrtMCI); } if (1 > nc) { ialast = 0; } else { ialast = nc; } for (iafirst = 0; iafirst < ialast; iafirst++) { b_ia_data[iafirst] = ia_data[iafirst]; } ia_size[0] = ialast; for (iafirst = 0; iafirst < ialast; iafirst++) { ia_data[iafirst] = b_ia_data[iafirst]; } } if (ncmax > 0) { if (nc <= ncmax) { } else { c_y = NULL; m37 = mxCreateString("Assertion failed."); emlrtAssign(&c_y, m37); st.site = &jbb_emlrtRSI; c_error(&st, c_y, &ib_emlrtMCI); } if (1 > nc) { ialast = 0; } else { ialast = nc; } for (iafirst = 0; iafirst < ialast; iafirst++) { b_ia_data[iafirst] = ib_data[iafirst]; } ib_size[0] = ialast; for (iafirst = 0; iafirst < ialast; iafirst++) { ib_data[iafirst] = b_ia_data[iafirst]; } } if (ncmax > 0) { if (nc <= ncmax) { } else { d_y = NULL; m37 = mxCreateString("Assertion failed."); emlrtAssign(&d_y, m37); st.site = &ibb_emlrtRSI; c_error(&st, d_y, &jb_emlrtMCI); } if (1 > nc) { ialast = 0; } else { ialast = nc; } for (iafirst = 0; iafirst < ialast; iafirst++) { b_c_data[iafirst] = c_data[iafirst]; } c_size[0] = ialast; for (iafirst = 0; iafirst < ialast; iafirst++) { c_data[iafirst] = b_c_data[iafirst]; } } }
void xmlmethods(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) { int j, m, iok = 0; char* file, *key, *val, *nm; int job = getInt(prhs[1]); int i = getInt(prhs[2]); // Check for proper number of arguments if (!nargs_ok(job,nrhs-1)) { mexErrMsgTxt("Wrong number of inputs."); return; } else if (nlhs > 1) { mexErrMsgTxt("Too many output arguments"); } // options that do not return a value if (job < 20) { switch (job) { case 0: nm = getString(prhs[3]); iok = xml_new(nm); break; case 1: iok = xml_del(i); break; case 2: iok = xml_copy(i); break; case 4: file = getString(prhs[3]); iok = xml_build(i, file); break; case 5: key = getString(prhs[3]); val = getString(prhs[4]); iok = xml_addAttrib(i, key, val); break; case 6: key = getString(prhs[3]); iok = xml_child(i, key); break; case 7: m = getInt(prhs[3]); iok = xml_child_bynumber(i, m); break; case 8: key = getString(prhs[3]); iok = xml_findID(i, key); break; case 9: key = getString(prhs[3]); iok = xml_findByName(i, key); break; case 10: iok = xml_nChildren(i); break; case 11: key = getString(prhs[3]); val = getString(prhs[4]); iok = xml_addChild(i, key, val); break; case 12: key = getString(prhs[3]); j = getInt(prhs[4]); iok = xml_addChildNode(i, j); break; case 13: file = getString(prhs[3]); iok = xml_write(i, file); break; case 14: j = getInt(prhs[3]); iok = xml_removeChild(i, j); break; case 15: file = getString(prhs[3]); iok = xml_get_XML_File(file, 0); break; default: mexErrMsgTxt("unknown job parameter"); } plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL); double* h = mxGetPr(plhs[0]); *h = double(iok); if (iok < 0) { reportError(); } return; } // options that return strings char* v = (char*)mxCalloc(80, sizeof(char)); switch (job) { case 20: // return an attribute key = getString(prhs[3]); iok = xml_attrib(i, key, v); break; case 21: // return the value of the node iok = xml_value(i, v); break; case 22: iok = xml_tag(i, v); break; default: mexErrMsgTxt("unknown job parameter"); } if (iok < 0) { plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL); double* h = mxGetPr(plhs[0]); *h = double(iok); if (iok < 0) { reportError(); } } else { plhs[0] = mxCreateString(v); } }
mxArray *sf_c9_CusakisME4901arcs2_get_autoinheritance_info(void) { const char *autoinheritanceFields[] = { "checksum", "inputs", "parameters", "outputs", "locals" }; mxArray *mxAutoinheritanceInfo = mxCreateStructMatrix(1,1,5, autoinheritanceFields); { mxArray *mxChecksum = mxCreateString("HZ0vqAZelhjx3fSnYOWjIG"); mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum); } { const char *dataFields[] = { "size", "type", "complexity" }; mxArray *mxData = mxCreateStructMatrix(1,2,3,dataFields); { mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL); double *pr = mxGetPr(mxSize); pr[0] = (double)(5); pr[1] = (double)(1); mxSetField(mxData,0,"size",mxSize); } { const char *typeFields[] = { "base", "fixpt" }; mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields); mxSetField(mxType,0,"base",mxCreateDoubleScalar(10)); mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL)); mxSetField(mxData,0,"type",mxType); } mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0)); { mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL); double *pr = mxGetPr(mxSize); pr[0] = (double)(10); pr[1] = (double)(1); mxSetField(mxData,1,"size",mxSize); } { const char *typeFields[] = { "base", "fixpt" }; mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields); mxSetField(mxType,0,"base",mxCreateDoubleScalar(1)); mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL)); mxSetField(mxData,1,"type",mxType); } mxSetField(mxData,1,"complexity",mxCreateDoubleScalar(0)); mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData); } { mxSetField(mxAutoinheritanceInfo,0,"parameters",mxCreateDoubleMatrix(0,0, mxREAL)); } { const char *dataFields[] = { "size", "type", "complexity" }; mxArray *mxData = mxCreateStructMatrix(1,3,3,dataFields); { mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL); double *pr = mxGetPr(mxSize); pr[0] = (double)(2); pr[1] = (double)(1); mxSetField(mxData,0,"size",mxSize); } { const char *typeFields[] = { "base", "fixpt" }; mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields); mxSetField(mxType,0,"base",mxCreateDoubleScalar(10)); mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL)); mxSetField(mxData,0,"type",mxType); } mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0)); { mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL); double *pr = mxGetPr(mxSize); pr[0] = (double)(4); pr[1] = (double)(1); mxSetField(mxData,1,"size",mxSize); } { const char *typeFields[] = { "base", "fixpt" }; mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields); mxSetField(mxType,0,"base",mxCreateDoubleScalar(10)); mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL)); mxSetField(mxData,1,"type",mxType); } mxSetField(mxData,1,"complexity",mxCreateDoubleScalar(0)); { mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL); double *pr = mxGetPr(mxSize); pr[0] = (double)(1); pr[1] = (double)(1); mxSetField(mxData,2,"size",mxSize); } { const char *typeFields[] = { "base", "fixpt" }; mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields); mxSetField(mxType,0,"base",mxCreateDoubleScalar(10)); mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL)); mxSetField(mxData,2,"type",mxType); } mxSetField(mxData,2,"complexity",mxCreateDoubleScalar(0)); mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData); } { mxSetField(mxAutoinheritanceInfo,0,"locals",mxCreateDoubleMatrix(0,0,mxREAL)); } return(mxAutoinheritanceInfo); }
mxArray *sf_c32_ArregloSeisPorSeis_get_autoinheritance_info(void) { const char *autoinheritanceFields[] = { "checksum", "inputs", "parameters", "outputs", "locals" }; mxArray *mxAutoinheritanceInfo = mxCreateStructMatrix(1,1,5, autoinheritanceFields); { mxArray *mxChecksum = mxCreateString("1KPkaEZ7HoPbK8UmULOSJ"); mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum); } { const char *dataFields[] = { "size", "type", "complexity" }; mxArray *mxData = mxCreateStructMatrix(1,3,3,dataFields); { mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL); double *pr = mxGetPr(mxSize); pr[0] = (double)(1); pr[1] = (double)(1); mxSetField(mxData,0,"size",mxSize); } { const char *typeFields[] = { "base", "fixpt" }; mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields); mxSetField(mxType,0,"base",mxCreateDoubleScalar(10)); mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL)); mxSetField(mxData,0,"type",mxType); } mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0)); { mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL); double *pr = mxGetPr(mxSize); pr[0] = (double)(1); pr[1] = (double)(1); mxSetField(mxData,1,"size",mxSize); } { const char *typeFields[] = { "base", "fixpt" }; mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields); mxSetField(mxType,0,"base",mxCreateDoubleScalar(10)); mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL)); mxSetField(mxData,1,"type",mxType); } mxSetField(mxData,1,"complexity",mxCreateDoubleScalar(0)); { mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL); double *pr = mxGetPr(mxSize); pr[0] = (double)(1); pr[1] = (double)(1); mxSetField(mxData,2,"size",mxSize); } { const char *typeFields[] = { "base", "fixpt" }; mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields); mxSetField(mxType,0,"base",mxCreateDoubleScalar(10)); mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL)); mxSetField(mxData,2,"type",mxType); } mxSetField(mxData,2,"complexity",mxCreateDoubleScalar(0)); mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData); } { mxSetField(mxAutoinheritanceInfo,0,"parameters",mxCreateDoubleMatrix(0,0, mxREAL)); } { const char *dataFields[] = { "size", "type", "complexity" }; mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields); { mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL); double *pr = mxGetPr(mxSize); pr[0] = (double)(1); pr[1] = (double)(1); mxSetField(mxData,0,"size",mxSize); } { const char *typeFields[] = { "base", "fixpt" }; mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields); mxSetField(mxType,0,"base",mxCreateDoubleScalar(10)); mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL)); mxSetField(mxData,0,"type",mxType); } mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0)); mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData); } { mxSetField(mxAutoinheritanceInfo,0,"locals",mxCreateDoubleMatrix(0,0,mxREAL)); } return(mxAutoinheritanceInfo); }
mxArray *sf_c38_old_Demo_RPS_get_autoinheritance_info(void) { const char *autoinheritanceFields[] = { "checksum", "inputs", "parameters", "outputs", "locals" }; mxArray *mxAutoinheritanceInfo = mxCreateStructMatrix(1,1,5, autoinheritanceFields); { mxArray *mxChecksum = mxCreateString("WKTB2CbkBm1dCdjFlE90P"); mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum); } { const char *dataFields[] = { "size", "type", "complexity" }; mxArray *mxData = mxCreateStructMatrix(1,2,3,dataFields); { mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL); double *pr = mxGetPr(mxSize); pr[0] = (double)(1); pr[1] = (double)(1); mxSetField(mxData,0,"size",mxSize); } { const char *typeFields[] = { "base", "fixpt" }; mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields); mxSetField(mxType,0,"base",mxCreateDoubleScalar(10)); mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL)); mxSetField(mxData,0,"type",mxType); } mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0)); { mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL); double *pr = mxGetPr(mxSize); pr[0] = (double)(1); pr[1] = (double)(1); mxSetField(mxData,1,"size",mxSize); } { const char *typeFields[] = { "base", "fixpt" }; mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields); mxSetField(mxType,0,"base",mxCreateDoubleScalar(10)); mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL)); mxSetField(mxData,1,"type",mxType); } mxSetField(mxData,1,"complexity",mxCreateDoubleScalar(0)); mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData); } { mxSetField(mxAutoinheritanceInfo,0,"parameters",mxCreateDoubleMatrix(0,0, mxREAL)); } { const char *dataFields[] = { "size", "type", "complexity" }; mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields); { mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL); double *pr = mxGetPr(mxSize); pr[0] = (double)(1); pr[1] = (double)(1); mxSetField(mxData,0,"size",mxSize); } { const char *typeFields[] = { "base", "fixpt" }; mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields); mxSetField(mxType,0,"base",mxCreateDoubleScalar(10)); mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL)); mxSetField(mxData,0,"type",mxType); } mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0)); mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData); } { mxSetField(mxAutoinheritanceInfo,0,"locals",mxCreateDoubleMatrix(0,0,mxREAL)); } return(mxAutoinheritanceInfo); }
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { /* variable declarations here */ char *zsql, *strbuf; int k, iret, istep, irow=0, nrow_alloc=0, kk, kval, nval, ncol, iargbind=4; int classid, ldestroy=1; int n_par_tobind=0, n_val_tobind=1; const mxArray *mxBindPar=NULL; strcat(errmsgstr1, "select_numeric:"); /* check for proper number of arguments */ if( nrhs<2) ERRABORT("nrhs", "at least two input arguments are needed."); /* Make sure that input arguments 2...3rd last are strings: */ /* for( k=2; k<nrhs-2; k++ ) if( !mxIsChar(prhs[k]) ) ERRABORT("notChar", "After the 2nd argument string input is expected."); */ /* if the first argument is a string, then open a database connection */ if( mxIsChar(prhs[0]) ) { mexCallMATLAB(1, &mxppDb, 1, (mxArray **) &prhs[0], "sql_open"); ppDb = *((sqlite3 **) mxGetData(mxppDb)); } else ppDb = *((sqlite3 **) mxGetData(prhs[0])); zsql = getzsql(nrhs, prhs, &iargbind); /* mexPrintf("zsql = %s\n", zsql); */ /* Prepare the SQL library for the select statement: */ iret = sqlite3_prepare_v2(ppDb, zsql, strlen(zsql), &ppStmt, NULL); /* Return the statement in the second optional output argument*/ if( nlhs>=2 ) plhs[1] = mxCreateString(zsql); else mxFree(zsql); if( iret!=SQLITE_OK ) { char errmsgbuf[strlen(sqlite3_errmsg(ppDb))+1]; strcpy(errmsgbuf, sqlite3_errmsg(ppDb)); CLOSE_DB; ERRABORT("prepare", errmsgbuf); } /* If there are parameters to bind, check the matlab variables and find out how many parameters/values: */ mxBindPar = bind_m2sql(ppStmt, iargbind, prhs, &n_par_tobind, &n_val_tobind); /* mexPrintf("n_par_tobind = %d, n_val_tobind = %d\n", n_par_tobind, n_val_tobind); */ /* How many columns? */ ncol = sqlite3_column_count(ppStmt); /* mexPrintf("ncol = %d\n", ncol); */ /* If there is a numeric last argument, it specifies which type to return. The default is double, so return a double matrix if there is no numeric last argument or a last numeric argument explicitely specifies double: */ if( !mxIsNumeric(prhs[nrhs-1]) || mxGetClassID(prhs[nrhs-1])==mxDOUBLE_CLASS ) { plhs[0] = mxCreateNumericMatrix(ncol, 0, mxDOUBLE_CLASS, mxREAL); DB2MAT(double, double); } else if( nrhs>=3 && mxIsNumeric(prhs[nrhs-1]) ) { /* A numeric last argument specifies something else than double. */ /* mexPrintf("numeric last argument %d found\n", *((int *) mxGetData(prhs[nrhs-1]))); */ classid = mxGetClassID(prhs[nrhs-1]); switch( classid ) { case mxSINGLE_CLASS: plhs[0] = mxCreateNumericMatrix(ncol, 0, classid, mxREAL); DB2MAT(float, double); break; case mxUINT8_CLASS: plhs[0] = mxCreateNumericMatrix(ncol, 0, mxUINT8_CLASS, mxREAL); DB2MAT_INT(uint8_t, int); break; case mxINT8_CLASS: plhs[0] = mxCreateNumericMatrix(ncol, 0, mxINT8_CLASS, mxREAL); DB2MAT_INT(int8_t, int); break; case mxUINT16_CLASS: plhs[0] = mxCreateNumericMatrix(ncol, 0, mxUINT16_CLASS, mxREAL); DB2MAT_INT(uint16_t, int); break; case mxINT16_CLASS: plhs[0] = mxCreateNumericMatrix(ncol, 0, mxINT16_CLASS, mxREAL); DB2MAT_INT(int16_t, int); break; case mxUINT32_CLASS: plhs[0] = mxCreateNumericMatrix(ncol, 0, mxUINT32_CLASS, mxREAL); DB2MAT_INT(uint32_t, int); break; case mxINT32_CLASS: plhs[0] = mxCreateNumericMatrix(ncol, 0, mxINT32_CLASS, mxREAL); DB2MAT_INT(int32_t, int); break; case mxUINT64_CLASS: plhs[0] = mxCreateNumericMatrix(ncol, 0, mxUINT64_CLASS, mxREAL); DB2MAT_INT(uint64_t, int64); break; case mxINT64_CLASS: plhs[0] = mxCreateNumericMatrix(ncol, 0, mxINT64_CLASS, mxREAL); DB2MAT_INT(int64_t, int64); break; default: CLOSE_DB; ERRABORT("category", "this function cannot return db elements of this type"); } } if( istep!=SQLITE_DONE ) { CLOSE_DB; ERRABORT("done", sqlite3_errmsg(ppDb)); } TRY_SQLFUN(sqlite3_finalize(ppStmt), select_numeric, finalize); /* if the first argument was a string, then close the database connection */ CLOSE_DB; }