diff options
author | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2020-06-30 14:57:15 -0400 |
---|---|---|
committer | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2020-06-30 14:57:15 -0400 |
commit | 8eb0fbff3470bc56ec798101435f5e90e069b027 (patch) | |
tree | e712a8cdb153157bb94fcb386d10cf13609c6296 | |
parent | 82b8dddfef6b453d364b4cf1b97a07a735d5ff41 (diff) | |
download | code-master.tar.gz code-master.tar.bz2 code-master.zip |
-rw-r--r-- | process_distributions.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/process_distributions.cpp b/process_distributions.cpp new file mode 100644 index 0000000..210b686 --- /dev/null +++ b/process_distributions.cpp @@ -0,0 +1,66 @@ + + +#include <cinttypes> +#include <cmath> +#include <fstream> +#include <sstream> +#include <string> +#include <vector> +#include <iostream> +#include <iomanip> + +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); + + if (!in_file.is_open()) { + std::cout << "Failed to open " << filename << ".\n"; + } else { + + unsigned n_moms = 5; + std::vector<double> o(n_moms); + std::vector<double> δo(n_moms); + + uint64_t norm = 0; + + uint64_t j = 0; + uint64_t a; + + while (in_file >> a) { + norm += a; + for (unsigned i = 0; i < n_moms; i++) { + o[i] += a * pow(j + 1, i + 1); + δo[i] += a * pow(j + 1, 2 * (i + 1)); + } + j++; + } + + in_file.close(); + + for (unsigned i = 0; i < n_moms; i++) { + o[i] /= norm; + δo[i] = sqrt(δo[i]) / norm; + } + + std::ofstream out_file; + out_file.open(filename + ".processed"); + + for (unsigned i = 0; i < n_moms; i++) { + out_file << o[i] << " " << δo[i] << "\n"; + } + + out_file.close(); + + std::cout << "Finished processing " << filename << ".\n"; + } + } + + return 0; +} |