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
0020 mexFunction( int nlhs, mxArray *plhs[],
0021 int nrhs, const mxArray *prhs[] )
0022 {
0023 double *pr;
0024 int m,i,p=1;
0025 int* n;
0026 FILE *io;
0027 size_t one = 1;
0028 int MAT_FILE_COOKIE=1211216;
0029 (void) nlhs;
0030 (void) plhs;
0031
0032 char *filename;
0033 int buflen,status;
0034
0035
0036 if (nrhs != 2)
0037 mexErrMsgTxt("Two inputs required.");
0038
0039
0040 if (mxIsChar(prhs[0]) != 1)
0041 mexErrMsgTxt("First argument must be a string.");
0042
0043
0044
0045 buflen = (mxGetM(prhs[0]) * mxGetN(prhs[0])) + 1;
0046
0047
0048 filename = mxCalloc(buflen, sizeof(char));
0049
0050
0051
0052 status = mxGetString(prhs[0], filename, buflen);
0053 if (status != 0)
0054 mexWarnMsgTxt("Not enough space. String is truncated.");
0055
0056
0057 pr = mxGetPr(prhs[1]);
0058
0059 m = mxGetNumberOfDimensions(prhs[1]);
0060 n = mxGetDimensions(prhs[1]);
0061
0062 for(i=0;i"w");
0065 fwrite (&MAT_FILE_COOKIE,sizeof(int),one,io);
0066
0067 fwrite (&m,sizeof(int),one,io);
0068
0069
0070 fwrite (n,sizeof(int),m,io);
0071 fwrite (&p,sizeof(int),one,io);
0072
0073
0074 "%i\n"
0075 "p"
0076
0077
0078
0079
0080
0081 fwrite(pr, sizeof(double),p,io);
0082
0083 "sizeofint"
0084
0085
0086
0087 fclose(io);
0088
0089 return;
0090 }