1 | /* |
---|
2 | * ---------------------------------------------------------------------- |
---|
3 | * INTERFACE: Matlab Rappture Library Interface Helper Functions |
---|
4 | * |
---|
5 | * ====================================================================== |
---|
6 | * AUTHOR: Derrick Kearney, Purdue University |
---|
7 | * Copyright (c) 2005 |
---|
8 | * Purdue Research Foundation, West Lafayette, IN |
---|
9 | * ====================================================================== |
---|
10 | */ |
---|
11 | #include "RpMatlabInterface.h" |
---|
12 | |
---|
13 | int |
---|
14 | getIntInput ( const mxArray* prhs ) { |
---|
15 | |
---|
16 | int retVal = -1; |
---|
17 | retVal = (int) getDoubleInput(prhs); |
---|
18 | return retVal; |
---|
19 | } |
---|
20 | |
---|
21 | double |
---|
22 | getDoubleInput ( const mxArray* prhs ) { |
---|
23 | |
---|
24 | double retVal = -1; |
---|
25 | |
---|
26 | /* Input must be a double. */ |
---|
27 | if (mxIsDouble(prhs) != 1) { |
---|
28 | mexErrMsgTxt("Input must be a double."); |
---|
29 | return retVal; |
---|
30 | } |
---|
31 | |
---|
32 | /* Input must be a scalar. */ |
---|
33 | if ( (mxGetN(prhs)*mxGetM(prhs)) != 1) { |
---|
34 | mexErrMsgTxt("Input must be a scalar."); |
---|
35 | return retVal; |
---|
36 | } |
---|
37 | |
---|
38 | retVal = *mxGetPr(prhs); |
---|
39 | |
---|
40 | return retVal; |
---|
41 | } |
---|
42 | |
---|
43 | char* |
---|
44 | getStringInput ( const mxArray* prhs ) { |
---|
45 | |
---|
46 | int buflen = 0; |
---|
47 | int status = 0; |
---|
48 | char* path = NULL; |
---|
49 | |
---|
50 | /* Input must be a string. */ |
---|
51 | if (mxIsChar(prhs) != 1) |
---|
52 | mexErrMsgTxt("Input must be a string."); |
---|
53 | |
---|
54 | /* Input must be a row vector. */ |
---|
55 | if ( (mxGetM(prhs)) != 1) |
---|
56 | mexErrMsgTxt("Input must be a row vector."); |
---|
57 | |
---|
58 | /* Get the length of the input string. */ |
---|
59 | buflen = (mxGetM(prhs) * mxGetN(prhs)) + 1; |
---|
60 | |
---|
61 | /* Allocate memory for input and output strings. */ |
---|
62 | path = (char*) mxCalloc(buflen, sizeof(char)); |
---|
63 | |
---|
64 | /* Copy the string data from prhs[0] into a C string |
---|
65 | * path. */ |
---|
66 | status = mxGetString(prhs, path, buflen); |
---|
67 | if (status != 0) |
---|
68 | mexWarnMsgTxt("Not enough space. String is truncated."); |
---|
69 | |
---|
70 | return path; |
---|
71 | } |
---|