-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathopj2dat.cpp
More file actions
128 lines (113 loc) · 4.79 KB
/
opj2dat.cpp
File metadata and controls
128 lines (113 loc) · 4.79 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/***************************************************************************
File : opj2dat.cpp
--------------------------------------------------------------------
Copyright : (C) 2008 Stefan Gerlach
(C) 2017 Miquel Garriga
Email (use @ for *) : stefan.gerlach*uni-konstanz.de
Description : Origin project converter
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301 USA *
* *
***************************************************************************/
#include "OriginFile.h"
#include <cmath>
#include <fstream>
#include <sstream>
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char *argv[]) {
if (argc < 2) {
cout << "Usage : ./opj2dat [--check-only] <file.opj>" << endl;
return -1;
}
cout << "opj2dat " << liboriginVersionString() << ", Copyright (C) 2008 Stefan Gerlach, 2017 Miquel Garriga" << endl;
if (string(argv[1]) == "-v")
return 0;
bool write_spreads = true;
if ((argc > 2) && (string(argv[1]) == "--check-only")) write_spreads = false;
string inputfile=argv[argc-1];
OriginFile opj(inputfile);
int status = opj.parse();
cout << "Parsing status = " << status << endl;
if (! status)
return -1;
cout << "OPJ PROJECT \"" << inputfile.c_str() << "\" VERSION = " << opj.version() << endl;
cout << "number of datasets = " << opj.datasetCount() << endl;
cout << "number of spreadsheets = " << opj.spreadCount() << endl;
cout << "number of matrixes = " << opj.matrixCount() << endl;
cout << "number of excels = " << opj.excelCount() << endl;
cout << "number of functions = " << opj.functionCount() << endl;
cout << "number of graphs = " << opj.graphCount() << endl;
cout << "number of notes = " << opj.noteCount() << endl;
for (unsigned int s=0;s<opj.spreadCount();s++) {
Origin::SpreadSheet spread = opj.spread(s);
size_t columnCount = spread.columns.size();
cout << "Spreadsheet " << (s+1) << endl;
cout << " Name: " << spread.name.c_str() << endl;
cout << " Label: " << spread.label.c_str() << endl;
cout << " Columns: " << columnCount << endl;
for (size_t j=0;j<columnCount;j++) {
Origin::SpreadColumn column = spread.columns[j];
cout << " Column " << (j+1) << " : " << column.name.c_str() << " / type : " << column.type << ", rows : " << spread.maxRows << endl;
}
if (write_spreads) {
ostringstream sfilename;
sfilename << inputfile.c_str() << "." << (s+1) << ".dat";
cout << "saved to " << sfilename.str() << endl;
ofstream outf;
outf.open(sfilename.str().c_str(), ios_base::out);
if (!outf.good()) {
cout << "Could not open " << sfilename.str() << endl;
return -1;
}
// header
for (size_t j=0;j<columnCount;j++) {
outf << spread.columns[j].name.c_str() << "; ";
cout << spread.columns[j].name.c_str();
}
outf << endl;
cout << endl << " Data: " << endl;
// data
for (int i=0;i<(int)spread.maxRows;i++) {
for (size_t j=0;j<columnCount;j++) {
if (i<(int)spread.columns[j].data.size()) {
Origin::variant value(spread.columns[j].data[i]);
double v=0.;
if (value.type() == Origin::variant::V_DOUBLE) {
v = value.as_double();
if (v != _ONAN) {
outf << v << "; ";
} else {
outf << nan("NaN") << "; ";
}
}
if (value.type() == Origin::variant::V_STRING) {
outf << value.as_string() << "; ";
}
} else {
outf << "; ";
}
}
outf << endl;
}
outf.close();
}
}
return 0;
}