diff options
author | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2019-09-04 08:18:37 -0400 |
---|---|---|
committer | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2019-09-04 08:18:37 -0400 |
commit | d4e6135a179cf6005cc50800f060854b34ae2e8b (patch) | |
tree | 8db94b56d7bd13a9a55219597f6b27753c954c0e /tools | |
parent | 492419f0ae1b32c1d4bc60997ca8eb7daba22182 (diff) | |
download | fuse_networks-d4e6135a179cf6005cc50800f060854b34ae2e8b.tar.gz fuse_networks-d4e6135a179cf6005cc50800f060854b34ae2e8b.tar.bz2 fuse_networks-d4e6135a179cf6005cc50800f060854b34ae2e8b.zip |
added tool for processing percolation data
Diffstat (limited to 'tools')
-rw-r--r-- | tools/process_perc.cpp | 73 |
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; +} + |