0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #include <stdio.h>
0014 #include <string.h>
0015 #include "mex.h"
0016
0017
0018
0019 void mexFunction(int nlhs, mxArray *plhs[],
0020 int nrhs, const mxArray *prhs[] )
0021 {
0022 char *file;
0023 int length,status;
0024 int ndims,*dim,size,*cookie;
0025 double *vals;
0026
0027 if (mxIsChar(prhs[0]) != 1)
0028 {mexErrMsgTxt("Input must be a string.");}
0029 else{
0030 length=(mxGetM(prhs[0]) * mxGetN(prhs[0])) + 1;
0031 file=mxCalloc(length,sizeof(char));
0032 status = mxGetString(prhs[0], file, length);
0033 if (status != 0)
0034 {mexWarnMsgTxt("Not enough space. String is truncated.");}
0035 }
0036
0037 FILE *TENSOR=fopen(file,"r");
0038 fread(&cookie,sizeof(int),1,TENSOR);
0039 fread(&ndims,sizeof(int),1,TENSOR);
0040 dim=mxCalloc(ndims,sizeof(int));
0041 fread(dim,sizeof(int),ndims,TENSOR);
0042 fread(&size,sizeof(int),1,TENSOR);
0043 vals=mxCalloc(size,sizeof(double));
0044 fread(vals,sizeof(double),size,TENSOR);
0045 fclose(TENSOR);
0046 mxArray * pA;
0047 plhs[0]=mxCreateNumericArray(ndims,dim,mxDOUBLE_CLASS,mxREAL);
0048 mxSetPr(plhs[0],vals);
0049 return;
0050 }