From 82d020c82fb0a3ac8f1b56da8b3e00a0fff4716d Mon Sep 17 00:00:00 2001 From: Matt Spraggs Date: Thu, 9 Jun 2016 17:38:41 +0100 Subject: [PATCH] Utils: Renamed sample_flatten.cpp to sample_element.cpp as suggested --- utils/Makefile.am | 8 ++++---- utils/sample_element.cpp | 39 +++++++++++++++++++++++++++++++++++++++ utils/sample_flatten.cpp | 31 ------------------------------- 3 files changed, 43 insertions(+), 35 deletions(-) create mode 100644 utils/sample_element.cpp delete mode 100644 utils/sample_flatten.cpp diff --git a/utils/Makefile.am b/utils/Makefile.am index b7b200a..bc38c79 100644 --- a/utils/Makefile.am +++ b/utils/Makefile.am @@ -9,7 +9,7 @@ endif bin_PROGRAMS = \ latan_make_fake_sample\ latan_sample_combine \ - latan_sample_flatten \ + latan_sample_element \ latan_sample_plot_corr\ latan_sample_read \ latan_resample @@ -22,9 +22,9 @@ latan_sample_combine_SOURCES = sample_combine.cpp latan_sample_combine_CXXFLAGS = $(COM_CXXFLAGS) latan_sample_combine_LDFLAGS = -L../lib/.libs -lLatAnalyze -latan_sample_flatten_SOURCES = sample_flatten.cpp -latan_sample_flatten_CXXFLAGS = $(COM_CXXFLAGS) -latan_sample_flatten_LDFLAGS = -L../lib/.libs -lLatAnalyze +latan_sample_element_SOURCES = sample_element.cpp +latan_sample_element_CXXFLAGS = $(COM_CXXFLAGS) +latan_sample_element_LDFLAGS = -L../lib/.libs -lLatAnalyze latan_sample_plot_corr_SOURCES = sample_plot_corr.cpp latan_sample_plot_corr_CXXFLAGS = $(COM_CXXFLAGS) diff --git a/utils/sample_element.cpp b/utils/sample_element.cpp new file mode 100644 index 0000000..9797bd2 --- /dev/null +++ b/utils/sample_element.cpp @@ -0,0 +1,39 @@ +#include +#include + +#include +#include + + +int main(int argc, char* argv[]) +{ + using namespace std; + using namespace Latan; + + if (argc != 4 and argc != 5) { + cout << "Usage: " << argv[0] << " "; + cout << "[output filename]" << endl; + return -1; + } + + string inFileName = argv[1]; + auto row = strTo(argv[2]); + auto col = strTo(argv[3]); + string outFileName = (argc == 5) ? argv[4] : ""; + + auto inputData = Io::load(inFileName); + cout << scientific; + cout << "central value:\n" << inputData[central](row, col) << endl; + cout << "standard deviation:\n"; + cout << inputData.variance().cwiseSqrt()(row, col) << endl; + + if (not outFileName.empty()) + { + DSample outputData(inputData.size()); + FOR_STAT_ARRAY(inputData, s) { + outputData[s] = inputData[s](row, col); + } + + Io::save(outputData, outFileName); + } +} diff --git a/utils/sample_flatten.cpp b/utils/sample_flatten.cpp deleted file mode 100644 index 46f68b3..0000000 --- a/utils/sample_flatten.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include - -#include -#include - - -namespace La = Latan; - -int main(int argc, char* argv[]) -{ - if (argc != 4) { - std::cout << "Usage: " << argv[0] << " " << std::endl; - return -1; - } - - std::string inFileName = argv[1]; - std::string outFileName = argv[2]; - auto nSamples = La::strTo(argv[3]); - - La::DMatSample inputData(nSamples, 1, 1); - La::DSample outputData(nSamples); - - inputData = La::Io::load(inFileName); - - FOR_STAT_ARRAY(inputData, s) { - outputData[s] = inputData[s](0, 0); - } - - La::Io::save(outputData, outFileName); -}