-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdraw.h
More file actions
67 lines (51 loc) · 957 Bytes
/
draw.h
File metadata and controls
67 lines (51 loc) · 957 Bytes
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
#include <vector>
#include <string>
using std::vector;
using std::string;
#include "../Graph.h"
struct Csv2rec {
vector<string> header;
vector<double> xs;
vector<vector<double> > data;
int line = -1;
Csv2rec() {
header.push_back(string("x"));
}
void addheader(char * s)
{
header.push_back(string(s));
}
void addline(double x)
{
xs.push_back(x);
data.push_back(vector<double>());
++line;
}
void adddata(double n)
{
data[line].push_back(n);
}
bool save(const char * fn)
{
FILE * fp = fopen(fn, "w");
if (!fp) return false;
size_t i;
fprintf(fp, "%s", header[0].c_str());
for (i = 1; i < header.size(); ++i)
{
fprintf(fp, ",%s", header[i].c_str());
}
fprintf(fp, "\n");
for (i = 0; i < data.size(); ++i)
{
fprintf(fp, "%lf", xs[i]);
for (size_t j = 0; j < data[i].size(); ++j)
{
fprintf(fp, ",%lf", data[i][j]);
}
fprintf(fp, "\n");
}
fclose(fp);
return true;
}
};