annotate rDiff/mex/mex_input.cpp @ 2:233c30f91d66

updated python based GFF parsing module which will handle GTF/GFF/GFF3 file types
author vipints <vipin@cbio.mskcc.org>
date Tue, 08 Oct 2013 07:15:44 -0400
parents 0f80a5141704
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
1 /*
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
2 * This program is free software; you can redistribute it and/or modify
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
3 * it under the terms of the GNU General Public License as published by
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
4 * the Free Software Foundation; either version 3 of the License, or
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
5 * (at your option) any later version.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
6 *
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
7 * Written (W) 2010-2011 Jonas Behr, Regina Bohnert, Gunnar Raetsch
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
8 * Copyright (C) 2010-2011 Max Planck Society
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
9 */
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
10
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
11
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
12 #include <stdio.h>
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
13 #include <mex.h>
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
14 #include "mex_input.h"
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
15
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
16 char *get_string(const mxArray *prhs) {
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
17 char *buf;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
18 int buflen;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
19 if (!prhs)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
20 mexErrMsgTxt("get_string called with NULL pointer arg");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
21 if (!mxIsChar(prhs))
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
22 mexErrMsgTxt("input is not a string");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
23 if (mxGetM(prhs) != 1)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
24 mexErrMsgTxt("input is not a row vector");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
25 buflen = mxGetN(prhs) + 1;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
26 buf = (char*) malloc(buflen);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
27 /* copy the string from prhs into buf and add terminating NULL char */
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
28 if (mxGetString(prhs, buf, buflen))
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
29 mexErrMsgTxt("not enough space");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
30 return buf;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
31 }
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
32
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
33 bool get_bool(const mxArray *prhs)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
34 {
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
35 const int M = mxGetM(prhs);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
36 const int N = mxGetN(prhs);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
37 double *f = (double*) mxGetPr(prhs);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
38
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
39 if (!prhs)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
40 mexErrMsgTxt("Arg is NULL pointer");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
41 if (M != 1 || N != 1)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
42 mexErrMsgTxt("Arg is not a scalar");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
43 if (f[0] != 0)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
44 return true;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
45 return false;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
46 }
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
47
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
48 int get_int(const mxArray *prhs)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
49 {
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
50 const int M = mxGetM(prhs);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
51 const int N = mxGetN(prhs);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
52 double *f = (double*) mxGetPr(prhs);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
53
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
54 if (!prhs)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
55 mexErrMsgTxt("Arg is NULL pointer");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
56 if (M != 1 || N != 1)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
57 mexErrMsgTxt("Arg is not a scalar");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
58
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
59 return (int) f[0];
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
60 }