ivan@137
|
1 /**************************************************************************
|
ivan@137
|
2 *
|
ivan@137
|
3 * File name: mexutils.c
|
ivan@137
|
4 *
|
ivan@137
|
5 * Ron Rubinstein
|
ivan@137
|
6 * Computer Science Department
|
ivan@137
|
7 * Technion, Haifa 32000 Israel
|
ivan@137
|
8 * ronrubin@cs
|
ivan@137
|
9 *
|
ivan@137
|
10 * Last Updated: 15.8.2009
|
ivan@137
|
11 *
|
ivan@137
|
12 *************************************************************************/
|
ivan@137
|
13
|
ivan@137
|
14 #include "mexutils.h"
|
ivan@137
|
15 #include <math.h>
|
ivan@137
|
16
|
ivan@137
|
17
|
ivan@137
|
18
|
ivan@137
|
19 /* verify that the mxArray contains a double matrix */
|
ivan@137
|
20
|
ivan@137
|
21 void checkmatrix(const mxArray *param, char *fname, char *pname)
|
ivan@137
|
22 {
|
ivan@137
|
23 char errmsg[100];
|
ivan@137
|
24 sprintf(errmsg, "%.15s requires that %.25s be a double matrix.", fname, pname);
|
ivan@137
|
25 if (!mxIsDouble(param) || mxIsComplex(param) || mxGetNumberOfDimensions(param)>2) {
|
ivan@137
|
26 mexErrMsgTxt(errmsg);
|
ivan@137
|
27 }
|
ivan@137
|
28 }
|
ivan@137
|
29
|
ivan@137
|
30
|
ivan@137
|
31 /* verify that the mxArray contains a 1-D double vector */
|
ivan@137
|
32
|
ivan@137
|
33 void checkvector(const mxArray *param, char *fname, char *pname)
|
ivan@137
|
34 {
|
ivan@137
|
35 char errmsg[100];
|
ivan@137
|
36 sprintf(errmsg, "%.15s requires that %.25s be a double vector.", fname, pname);
|
ivan@137
|
37 if (!mxIsDouble(param) || mxIsComplex(param) || mxGetNumberOfDimensions(param)>2 || (mxGetM(param)!=1 && mxGetN(param)!=1)) {
|
ivan@137
|
38 mexErrMsgTxt(errmsg);
|
ivan@137
|
39 }
|
ivan@137
|
40 }
|
ivan@137
|
41
|
ivan@137
|
42
|
ivan@137
|
43 /* verify that the mxArray contains a double scalar */
|
ivan@137
|
44
|
ivan@137
|
45 void checkscalar(const mxArray *param, char *fname, char *pname)
|
ivan@137
|
46 {
|
ivan@137
|
47 char errmsg[100];
|
ivan@137
|
48 sprintf(errmsg, "%.15s requires that %.25s be a double scalar.", fname, pname);
|
ivan@137
|
49 if (!mxIsDouble(param) || mxIsComplex(param) || mxGetNumberOfDimensions(param)>2 ||
|
ivan@137
|
50 mxGetM(param)!=1 || mxGetN(param)!=1)
|
ivan@137
|
51 {
|
ivan@137
|
52 mexErrMsgTxt(errmsg);
|
ivan@137
|
53 }
|
ivan@137
|
54 }
|
ivan@137
|
55
|
ivan@137
|
56
|
ivan@137
|
57 /* verify that the mxArray contains a sparse matrix */
|
ivan@137
|
58
|
ivan@137
|
59 void checksparse(const mxArray *param, char *fname, char *pname)
|
ivan@137
|
60 {
|
ivan@137
|
61 char errmsg[100];
|
ivan@137
|
62 sprintf(errmsg, "%.15s requires that %.25s be sparse.", fname, pname);
|
ivan@137
|
63 if (!mxIsSparse(param)) {
|
ivan@137
|
64 mexErrMsgTxt(errmsg);
|
ivan@137
|
65 }
|
ivan@137
|
66 }
|
ivan@137
|
67
|
ivan@137
|
68
|
ivan@137
|
69 /* verify that the mxArray contains a 1-dimensional cell array */
|
ivan@137
|
70
|
ivan@137
|
71 void checkcell_1d(const mxArray *param, char *fname, char *pname)
|
ivan@137
|
72 {
|
ivan@137
|
73 char errmsg[100];
|
ivan@137
|
74 sprintf(errmsg, "%.15s requires that %.25s be a 1-D cell array.", fname, pname);
|
ivan@137
|
75 if (!mxIsCell(param) || mxGetNumberOfDimensions(param)>2 || (mxGetM(param)!=1 && mxGetN(param)!=1)) {
|
ivan@137
|
76 mexErrMsgTxt(errmsg);
|
ivan@137
|
77 }
|
ivan@137
|
78 }
|
ivan@137
|
79
|