annotate toolboxes/FullBNT-1.0.7/KPMtools/mexutil.c @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 #include "mexutil.h"
wolffd@0 2
wolffd@0 3 /* Functions to create uninitialized arrays. */
wolffd@0 4
wolffd@0 5 mxArray *mxCreateNumericArrayE(int ndim, const int *dims,
wolffd@0 6 mxClassID class, mxComplexity ComplexFlag)
wolffd@0 7 {
wolffd@0 8 mxArray *a;
wolffd@0 9 int i, *dims1 = mxMalloc(ndim*sizeof(int));
wolffd@0 10 size_t sz = 1;
wolffd@0 11 for(i=0;i<ndim;i++) {
wolffd@0 12 sz *= dims[i];
wolffd@0 13 dims1[i] = 1;
wolffd@0 14 }
wolffd@0 15 a = mxCreateNumericArray(ndim,dims1,class,ComplexFlag);
wolffd@0 16 sz *= mxGetElementSize(a);
wolffd@0 17 mxSetDimensions(a, dims, ndim);
wolffd@0 18 mxFree(dims1);
wolffd@0 19 mxSetData(a, mxRealloc(mxGetData(a), sz));
wolffd@0 20 if(ComplexFlag == mxCOMPLEX) {
wolffd@0 21 mxSetPi(a, mxRealloc(mxGetPi(a),sz));
wolffd@0 22 }
wolffd@0 23 return a;
wolffd@0 24 }
wolffd@0 25 mxArray *mxCreateNumericMatrixE(int m, int n, mxClassID class,
wolffd@0 26 mxComplexity ComplexFlag)
wolffd@0 27 {
wolffd@0 28 size_t sz = m*n*sizeof(double);
wolffd@0 29 mxArray *a = mxCreateNumericMatrix(1, 1, class, ComplexFlag);
wolffd@0 30 mxSetM(a,m);
wolffd@0 31 mxSetN(a,n);
wolffd@0 32 mxSetPr(a, mxRealloc(mxGetPr(a),sz));
wolffd@0 33 if(ComplexFlag == mxCOMPLEX) {
wolffd@0 34 mxSetPi(a, mxRealloc(mxGetPi(a),sz));
wolffd@0 35 }
wolffd@0 36 return a;
wolffd@0 37 }
wolffd@0 38 mxArray *mxCreateDoubleMatrixE(int m, int n,
wolffd@0 39 mxComplexity ComplexFlag)
wolffd@0 40 {
wolffd@0 41 return mxCreateNumericMatrixE(m,n,mxDOUBLE_CLASS,ComplexFlag);
wolffd@0 42 }
wolffd@0 43