-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathm_get_comp_order.c
55 lines (40 loc) · 1.32 KB
/
m_get_comp_order.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* #include "perplex.h" */
#include "math.h"
#include "mex.h"
#define p_cname_len 6
/* int ini_phaseq(char *inputfile); */
EXTERN_C void mexFunction(int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
char *order, *spcloc;
char compname[p_cname_len];
int i, j, ret, n, bytes_to_copy;
int *charLengthArr;
mxChar *dataPtr;
if (nrhs > 0) {
mexErrMsgIdAndTxt("PrplxWrap:m_get_comp_order:nrhs", "Too many arguments");
return;
}
if (nlhs != 1) {
mexErrMsgIdAndTxt("PrplxWrap:m_get_comp_order:nlhs", "Expect one output argument");
return;
}
ret = get_comp_order(&order);
n = ret / p_cname_len;
mexPrintf("%d \n %s\n", n, order);
charLengthArr = (int *)malloc(sizeof(int)*n);
for (i = 0; i < n; i++) {
charLengthArr[i] = p_cname_len-1; /* one char is reserved for NUL */
}
plhs[0] = mxCreateCharArray(n, (const int *)charLengthArr);
dataPtr = (mxChar *)mxGetData(plhs[0]);
for (i = 0; i < n; i++) {
memcpy(dataPtr + i * p_cname_len, order + i * p_cname_len, 1);
}
/*bytes_to_copy = n * p_cname_; /* n * mxGetElementSize(plhs[0]);
memcpy(dataPtr, order, bytes_to_copy);*/
free(order);
}