Skip to content
Snippets Groups Projects
Commit 9cd8b28e authored by Carl Philipp Klemm's avatar Carl Philipp Klemm
Browse files

eistype: add operator== to DataPoint, add sweep distance calculation function,...

eistype: add operator== to DataPoint, add sweep distance calculation function, add ability to add custom header to saved spectra
parent 6bad85d1
No related branches found
No related tags found
No related merge requests found
......@@ -7,10 +7,15 @@ typedef double fvalue;
namespace eis
{
struct DataPoint
class DataPoint
{
public:
std::complex<fvalue> im;
fvalue omega;
bool operator==(const DataPoint& in)
{
return im == in.im;
}
};
class Range
......@@ -32,7 +37,6 @@ public:
{
return at(step);
}
fvalue at(size_t index) const
{
assert(index < count);
......@@ -69,6 +73,8 @@ public:
static std::vector<Range> rangesFromParamString(const std::string& paramStr, size_t count);
};
bool saveToDisk(const std::vector<DataPoint>& data, std::string fileName);
bool saveToDisk(const std::vector<DataPoint>& data, const std::string& fileName, std::string headStr = "");
double eisDistance(const std::vector<eis::DataPoint>& a, const std::vector<eis::DataPoint>& b);
}
......@@ -7,7 +7,7 @@
using namespace eis;
bool eis::saveToDisk(const std::vector<DataPoint>& data, std::string fileName)
bool eis::saveToDisk(const std::vector<DataPoint>& data, const std::string& fileName, std::string headStr)
{
std::fstream file;
file.open(fileName, std::ios_base::out | std::ios_base::trunc);
......@@ -17,6 +17,8 @@ bool eis::saveToDisk(const std::vector<DataPoint>& data, std::string fileName)
return false;
}
if(!headStr.empty())
file<<headStr<<'\n';
file<<"omega,real,im\n";
for(const eis::DataPoint& point : data)
......@@ -92,3 +94,17 @@ bool eis::Range::isSane() const
return false;
return true;
}
double eis::eisDistance(const std::vector<eis::DataPoint>& a, const std::vector<eis::DataPoint>& b)
{
assert(a.size() == b.size());
double accum = 0;
for(size_t i = 0; i < a.size(); ++i)
{
double diffRe = std::pow(b[i].im.real() - a[i].im.real(), 2);
double diffIm = std::pow(b[i].im.imag() - a[i].im.imag(), 2);
accum += std::sqrt(diffRe+diffIm);
}
return accum/a.size();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment