summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tools/process_perc.cpp73
1 files changed, 73 insertions, 0 deletions
diff --git a/tools/process_perc.cpp b/tools/process_perc.cpp
new file mode 100644
index 0000000..f1274b7
--- /dev/null
+++ b/tools/process_perc.cpp
@@ -0,0 +1,73 @@
+
+#include <fstream>
+#include <vector>
+#include <cinttypes>
+#include <sstream>
+#include <string>
+#include <cmath>
+
+int main(int argc, char* argv[]) {
+ std::vector<std::string> all_args;
+
+ if (argc > 1) {
+ all_args.assign(argv + 1, argv + argc);
+ }
+
+ for (std::string filename : all_args) {
+ std::ifstream in_file;
+ in_file.open(filename);
+
+ std::vector<std::vector<uint64_t>> dat;
+
+ unsigned line_num = 0;
+ std::string line;
+ while (std::getline(in_file, line)) {
+ dat.resize(line_num + 1);
+ std::istringstream iss(line);
+ uint64_t a;
+ while (iss >> a) {
+ dat[line_num].push_back(a);
+ }
+ line_num++;
+ }
+
+ in_file.close();
+
+ unsigned n_moms = 5;
+
+ std::vector<std::vector<double>> output(n_moms);
+
+ for (unsigned i = 0; i < n_moms; i++) {
+ output[i].resize(dat.size());
+ }
+
+ for (unsigned i = 1; i <= n_moms; i++) {
+ for (unsigned j = 0; j < dat.size(); j++) {
+ double mom = 0;
+ uint64_t total = 0;
+ for (unsigned k = 1; k <= dat[j].size(); k++) {
+ mom += pow(k, i) * dat[j][k - 1];
+ total += dat[j][k - 1];
+ }
+
+ output[i - 1][j] = mom / total;
+ }
+ }
+
+ std::ofstream out_file;
+ out_file.open(filename + ".processed");
+
+ for (unsigned i = 0; i < n_moms; i++) {
+ for (unsigned j = 0; j < output[i].size(); j++) {
+ out_file << output[i][j] << " ";
+ }
+ out_file << "\n";
+ }
+
+ out_file.close();
+
+ }
+
+ return 0;
+}
+