diff options
author | Juan Gomez Luna <juan.gomez@safari.ethz.ch> | 2021-06-16 19:46:05 +0200 |
---|---|---|
committer | Juan Gomez Luna <juan.gomez@safari.ethz.ch> | 2021-06-16 19:46:05 +0200 |
commit | 3de4b495fb176eba9a0eb517a4ce05903cb67acb (patch) | |
tree | fc6776a94549d2d4039898f183dbbeb2ce013ba9 /TS/baselines/cpu/tools.cpp | |
parent | ef5c3688c486b80a56d3c1cded25f2b2387f2668 (diff) |
PrIM -- first commit
Diffstat (limited to 'TS/baselines/cpu/tools.cpp')
-rw-r--r-- | TS/baselines/cpu/tools.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/TS/baselines/cpu/tools.cpp b/TS/baselines/cpu/tools.cpp new file mode 100644 index 0000000..9a67619 --- /dev/null +++ b/TS/baselines/cpu/tools.cpp @@ -0,0 +1,48 @@ +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +//#include <ctime> +#include <iostream> +#include <fstream> +#include <iomanip> +#include <limits> +#include <vector> +#include <algorithm> +#include <string> +#include <sstream> + +#include "mprofile.h" + + +int loadTimeSeriesFromFile (std::string infilename, std::vector<DTYPE> &A, int &timeSeriesLength) +{ + std::fstream timeSeriesFile(std::string(PATH_TIME_SERIES) + infilename, std::ios_base::in); + double tempval; + timeSeriesLength = 0; + while (timeSeriesFile >> tempval) + { + A.push_back(tempval); + timeSeriesLength++; + } + timeSeriesFile.close(); + + return 0; +} + + +int saveProfileToFile(std::string outfilename, DTYPE * profile, int * profileIndex, int timeSeriesLength, int windowSize) +{ + std::string preoutfilename = std::string(PATH_RESULTS) + outfilename; + + std::fstream preprofileOutFile(preoutfilename.c_str(), std::ios_base::out); + + // Write PreSCRIMP Matrix Profile and Matrix Profile Index to file. + for (int i = 0; i < timeSeriesLength - windowSize + 1; i++) + { + preprofileOutFile << std::setprecision(std::numeric_limits<DTYPE>::digits10 + 2) << sqrt(abs(profile[i])) << " " << std::setprecision(std::numeric_limits<int>::digits10 + 1) << profileIndex[i] << std::endl; + } + + preprofileOutFile.close(); + + return 0; +} |