Fix some issues with the matlabtoeis converter
This commit is contained in:
@ -43,6 +43,11 @@ target_link_libraries(rlxpassfail ${COMMON_LINK_LIBRARIES} -lrelaxisloader)
|
|||||||
set_property(TARGET rlxpassfail PROPERTY CXX_STANDARD 17)
|
set_property(TARGET rlxpassfail PROPERTY CXX_STANDARD 17)
|
||||||
install(TARGETS rlxpassfail RUNTIME DESTINATION bin)
|
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")
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -s")
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,26 +1,26 @@
|
|||||||
|
#include <filesystem>
|
||||||
#include <kisstype/spectra.h>
|
#include <kisstype/spectra.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <kisstype/type.h>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
#include "tokenize.h"
|
#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;
|
std::filesystem::path filename;
|
||||||
size_t index = 0;
|
static size_t index = 0;
|
||||||
do
|
|
||||||
{
|
|
||||||
filename.assign(exportName);
|
filename.assign(exportName);
|
||||||
filename.concat("_");
|
filename.concat("_");
|
||||||
filename.concat(std::to_string(index));
|
filename.concat(std::to_string(index));
|
||||||
filename.concat(".csv");
|
filename.concat(".csv");
|
||||||
++index;
|
++index;
|
||||||
} while(std::filesystem::exists(outDir/filename));
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
eis::Spectra(data.data, data.modelStr, data.id + ", \"" + originFile.filename().string() + "\"").saveToDisk(outDir/filename);
|
spectra.saveToDisk(outDir/filename);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch(...)
|
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<std::string> tokens = tokenize(line, '\t');
|
||||||
|
std::vector<eis::DataPoint> data(tokens.size()/2);
|
||||||
if(tokens.size() % 2 != 0)
|
if(tokens.size() % 2 != 0)
|
||||||
throw std::invalid_argument("Line must have an even number of tokens");
|
throw std::invalid_argument("Line must have an even number of tokens");
|
||||||
|
|
||||||
for(size_t i = 0; i < tokens.size()/2; ++i)
|
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;
|
return data;
|
||||||
}
|
}
|
||||||
@ -80,8 +83,13 @@ int main(int argc, char** argv)
|
|||||||
std::vector<eis::DataPoint> data = parseLine(eisLine);
|
std::vector<eis::DataPoint> data = parseLine(eisLine);
|
||||||
eis::Spectra spectra (data, "Unkown", argv[2]);
|
eis::Spectra spectra (data, "Unkown", argv[2]);
|
||||||
spectra.addLabel(argv[1], std::stod(rul));
|
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<<"Could not save to"<<argv[4]<<'\n';
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch(const std::invalid_argument& ex)
|
catch(const std::invalid_argument& ex)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user