forked from mscrawford/IBC-grass
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgamma.cpp
146 lines (133 loc) · 5.15 KB
/
gamma.cpp
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <set>
#include <string>
std::map<long, std::set<std::string> > gamma;
std::map<long, std::map<long, std::set<std::string> > > alpha;
int main(int argc, char**argv) {
if (argc > 1) {
long linecount = 0;
std::string line;
std::vector<std::string> headerlist;
std::ifstream gammafile(argv[1]);
while (getline(gammafile, line).good()) {
if (linecount == 0) {
std::string header;
size_t start = 0;
size_t end = 0;
do {
end=line.find_first_of(",", start);
if (end != std::string::npos) {
header=line.substr(start, end-start);
} else {
header=line.substr(start);
}
/*
* trim front
*/
while (header[0]==' ') header.erase(0, 1);
/*
* if extraheader has a size after trimming we can add it to the
* list of extra headers
*/
if (header.size()>0) {
headerlist.push_back(header);
}
/*
* if we are not at end of search we skip a character.
* At end we do nothing and let the loop condition stop
* the loop.
*/
if (end == std::string::npos) {
start = end;
} else {
start = end + 1;
}
} while (end!=std::string::npos);
} else {
std::string header;
size_t start = 0;
size_t end = 0;
int colcount = 0;
long count;
long year;
long run;
do {
end=line.find_first_of(",", start);
if (end != std::string::npos) {
header=line.substr(start, end-start);
} else {
header=line.substr(start);
}
/*
* trim front
*/
while (header[0]==' ') header.erase(0, 1);
/*
* if extraheader has a size after trimming we can add it to the
* list of extra headers
*/
if (header.size()>0) {
count = strtol(header.c_str(), 0, 0);
switch (colcount) {
case 0:
run = count;
break;
case 1:
year = count;
break;
default:
if (count > 0) {
std::map<long, std::map<long, std::set<std::string> > >::iterator ai = alpha.find(year);
if (ai != alpha.end()) {
ai->second[run].insert(headerlist[colcount]);
} else {
std::map<long, std::set<std::string> > newyear;
newyear[run].insert(headerlist[colcount]);
alpha.insert(std::pair<long, std::map<long, std::set<std::string> > >(year, newyear));
}
gamma[year].insert(headerlist[colcount]);
}
break;
}
colcount++;
}
/*
* if we are not at end of search we skip a character.
* At end we do nothing and let the loop condition stop
* the loop.
*/
if (end == std::string::npos) {
start = end;
} else {
start = end + 1;
}
} while ((end!=std::string::npos) && (headerlist[colcount] != "OMcount"));
}
linecount++;
}
std::map<long, std::set<std::string> >::iterator gi;
std::cerr << "year,gamma,alpha,beta\n";
size_t i;
double gsum = 0;
double gav = 0;
for (i = 1; i<= gamma.size(); i++) {
gsum+= gamma[i].size();
}
gav = gsum/gamma.size();
for (i = 1; i<= gamma.size(); i++) {
std::cerr << i << "," << gamma[i].size() << ",";
double asum = 0;
size_t a;
for (a = 0; a < alpha[i].size(); ++a) {
asum+=alpha[i][a].size();
}
double thealpha = asum/a;
std::cerr << thealpha << "," << gamma[i].size()/thealpha;
std::cerr << std::endl;
}
}
return 0;
}