summaryrefslogtreecommitdiff
path: root/TS/baselines/cpu/tools.cpp
blob: 9a67619d71d969b818ba6fbd190bb25767cfd092 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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;
}