-
Notifications
You must be signed in to change notification settings - Fork 1
/
oct2cube.cc
62 lines (42 loc) · 1.27 KB
/
oct2cube.cc
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
53
54
55
56
57
58
59
60
61
62
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <string>
#include <octave/oct.h>
/*
/usr/include/octave-3.8.2/octave/oct.h
/usr/lib/octave/3.8.2/liboctave.dll.a
*/
using namespace std;
void printHelp() {
printf("\n oct2cube <output_cube_file> <input_oct_file> [<oct_variable_name>]\n\n");
exit(1);
}
void getAllVariableNames(vector<string> &vars, MATFile *matfile) {
vars.clear();
while (true) {
const char *name;
mxArray *array = matGetNextVariableInfo(matfile, &name);
if (array == NULL) break;
vars.push_back(name);
mxDestroyArray(array);
}
}
int main(int argc, char **argv) {
if (argc < 3 || argc > 4) printHelp();
const char *outputCubeFilename = argv[1];
const char *inputOctaveFilename = argv[2];
const char *octVariableName = argv[3];
MATFile *matfile = matOpen(inputMatlabFilename, "r");
if (!matfile) {
fprintf(stderr, "ERROR: cannot open \"%s\".\n", inputMatlabFilename);
return 1;
}
vector<string> variables;
getAllVariableNames(variables, matfile);
printf("Variables found in \"%s\":\n", inputMatlabFilename);
for (size_t i=0; i < variables.size(); i++) {
printf(" %s\n", variables[i].c_str());
}
return 0;
}