Fix some issues with the matlabtoeis converter
This commit is contained in:
parent
04c5aab3e0
commit
f1b0a33e71
@ -43,6 +43,11 @@ target_link_libraries(rlxpassfail ${COMMON_LINK_LIBRARIES} -lrelaxisloader)
|
||||
set_property(TARGET rlxpassfail PROPERTY CXX_STANDARD 17)
|
||||
install(TARGETS rlxpassfail RUNTIME DESTINATION bin)
|
||||
|
||||
add_executable(matlabarraytoeis ${COMMON_SRC_FILES} src/matlabarraytoeis.cpp)
|
||||
target_link_libraries(matlabarraytoeis ${COMMON_LINK_LIBRARIES} -lrelaxisloader)
|
||||
set_property(TARGET matlabarraytoeis PROPERTY CXX_STANDARD 17)
|
||||
install(TARGETS matlabarraytoeis RUNTIME DESTINATION bin)
|
||||
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -s")
|
||||
|
||||
|
||||
|
@ -1,26 +1,26 @@
|
||||
#include <filesystem>
|
||||
#include <kisstype/spectra.h>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <kisstype/type.h>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "tokenize.h"
|
||||
|
||||
bool saveData(const std::string& exportName, const eis::Spectra& spectra, const std::filesystem::path& outDir, const std::filesystem::path& originFile)
|
||||
static bool saveData(const std::string& exportName, const eis::Spectra& spectra, const std::filesystem::path& outDir)
|
||||
{
|
||||
std::filesystem::path filename;
|
||||
size_t index = 0;
|
||||
do
|
||||
{
|
||||
filename.assign(exportName);
|
||||
filename.concat("_");
|
||||
filename.concat(std::to_string(index));
|
||||
filename.concat(".csv");
|
||||
++index;
|
||||
} while(std::filesystem::exists(outDir/filename));
|
||||
static size_t index = 0;
|
||||
|
||||
filename.assign(exportName);
|
||||
filename.concat("_");
|
||||
filename.concat(std::to_string(index));
|
||||
filename.concat(".csv");
|
||||
++index;
|
||||
|
||||
try
|
||||
{
|
||||
eis::Spectra(data.data, data.modelStr, data.id + ", \"" + originFile.filename().string() + "\"").saveToDisk(outDir/filename);
|
||||
spectra.saveToDisk(outDir/filename);
|
||||
return true;
|
||||
}
|
||||
catch(...)
|
||||
@ -29,15 +29,18 @@ bool saveData(const std::string& exportName, const eis::Spectra& spectra, const
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<eis::DataPoint> parseLine(const std::string& line)
|
||||
static std::vector<eis::DataPoint> parseLine(const std::string& line)
|
||||
{
|
||||
std::vector<eis::DataPoint> data;
|
||||
std::vector<std::string> tokens = tokenize(line, '\t');
|
||||
std::vector<eis::DataPoint> data(tokens.size()/2);
|
||||
if(tokens.size() % 2 != 0)
|
||||
throw std::invalid_argument("Line must have an even number of tokens");
|
||||
|
||||
for(size_t i = 0; i < tokens.size()/2; ++i)
|
||||
data.push_back({std::stof(tokens[i]), std::stof(tokens[i+tokens.size()/2])});
|
||||
{
|
||||
data[tokens.size()/2-i-1].omega = tokens.size()/2-i-1;
|
||||
data[tokens.size()/2-i-1].im = std::complex<fvalue>(std::stof(tokens[i]), 0-std::stof(tokens[i+tokens.size()/2]));
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
@ -66,29 +69,34 @@ int main(int argc, char** argv)
|
||||
}
|
||||
|
||||
|
||||
for(std::string eisLine; std::getline(eisFile, eisLine).good();)
|
||||
for(std::string eisLine; std::getline(eisFile, eisLine).good();)
|
||||
{
|
||||
try
|
||||
{
|
||||
try
|
||||
std::string rul;
|
||||
if(!std::getline(rulFile, rul).good())
|
||||
{
|
||||
std::string rul;
|
||||
if(!std::getline(rulFile, rul).good())
|
||||
{
|
||||
std::cout<<argv[3]<<" dose not have the same number of lines as "<<argv[2]<<" aborting\n";
|
||||
return 3;
|
||||
}
|
||||
|
||||
std::vector<eis::DataPoint> data = parseLine(eisLine);
|
||||
eis::Spectra spectra (data, "Unkown", argv[2]);
|
||||
spectra.addLabel(argv[1], std::stod(rul));
|
||||
|
||||
|
||||
std::cout<<argv[3]<<" dose not have the same number of lines as "<<argv[2]<<" aborting\n";
|
||||
return 3;
|
||||
}
|
||||
catch(const std::invalid_argument& ex)
|
||||
|
||||
std::vector<eis::DataPoint> data = parseLine(eisLine);
|
||||
eis::Spectra spectra (data, "Unkown", argv[2]);
|
||||
spectra.addLabel(argv[1], std::stod(rul));
|
||||
if(!std::filesystem::exists(argv[4]))
|
||||
std::filesystem::create_directory(argv[4]);
|
||||
if(!saveData("matlab", spectra, argv[4]))
|
||||
{
|
||||
std::cout<<ex.what()<<std::endl;
|
||||
continue;
|
||||
std::cout<<"Could not save to"<<argv[4]<<'\n';
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
catch(const std::invalid_argument& ex)
|
||||
{
|
||||
std::cout<<ex.what()<<std::endl;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user