From d4e6135a179cf6005cc50800f060854b34ae2e8b Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Wed, 4 Sep 2019 08:18:37 -0400 Subject: added tool for processing percolation data --- tools/process_perc.cpp | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 tools/process_perc.cpp 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 +#include +#include +#include +#include +#include + +int main(int argc, char* argv[]) { + std::vector 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> 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> 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; +} + -- cgit v1.2.3-54-g00ecf