86 lines
2.1 KiB
C++
86 lines
2.1 KiB
C++
#include <iostream>
|
|
#include <kisstype/spectra.h>
|
|
#include <relaxisloader/relaxisloader.h>
|
|
#include <eisgenerator/basicmath.h>
|
|
#include <kisstype/type.h>
|
|
#include <filesystem>
|
|
|
|
int main(int argc, char** argv)
|
|
{
|
|
if(argc < 2)
|
|
{
|
|
std::cout<<"Usage: "<<argv[0]<<" RELAXIS_FILES...\n";
|
|
return 1;
|
|
}
|
|
|
|
std::filesystem::path outdir("./out");
|
|
std::filesystem::create_directory(outdir);
|
|
|
|
for(int i = 1; i < argc; ++i)
|
|
{
|
|
const char* err;
|
|
struct rlxfile* file = rlx_open_file(argv[i], &err);
|
|
if(!file)
|
|
{
|
|
std::cerr<<"Could not load "<<argv[i]<<'\n';
|
|
return 2;
|
|
}
|
|
|
|
struct rlx_project **projects = rlx_get_projects(file, NULL);
|
|
if(!projects)
|
|
{
|
|
std::cerr<<"Could not load projects\n";
|
|
return 2;
|
|
}
|
|
|
|
for(struct rlx_project **piter = projects; *piter; ++piter)
|
|
{
|
|
struct rlx_project *project = *piter;
|
|
struct rlx_spectra **spectras = rlx_get_all_spectra(file, project);
|
|
if(!spectras)
|
|
{
|
|
std::cerr<<"Could not load spectras in "<<argv[i]<<'\n';
|
|
continue;
|
|
}
|
|
|
|
for(struct rlx_spectra **siter = spectras; *siter; ++siter)
|
|
{
|
|
struct rlx_spectra *spectra = *siter;
|
|
struct rlx_metadata *meta = rlx_metadata_get(spectra, rlx_metadata_get_key(RLX_FIELD_FREE_VARIABLE_ONE));
|
|
|
|
float* real;
|
|
float* imag;
|
|
float* omega;
|
|
rlx_get_float_arrays(spectra, &real, &imag, &omega);
|
|
std::vector<eis::DataPoint> data(spectra->length);
|
|
for(size_t i = 0; i < spectra->length; ++i)
|
|
{
|
|
data[i].im = {real[i], imag[i]};
|
|
data[i].omega = omega[i];
|
|
}
|
|
|
|
data = eis::rescale(data, 50);
|
|
|
|
eis::Spectra eisSpectra(data, !meta || meta->value == 0 ? "Pass" : "Fail", argv[i]);
|
|
size_t index = 0;
|
|
std::filesystem::path filename;
|
|
do
|
|
{
|
|
filename.assign("relaxisPassFail_");
|
|
filename.concat(!meta || meta->value == 0 ? "Pass" : "Fail");
|
|
filename.concat("_");
|
|
filename.concat(std::to_string(index));
|
|
filename.concat(".csv");
|
|
++index;
|
|
} while(std::filesystem::exists(outdir/filename));
|
|
eisSpectra.saveToDisk(outdir/filename);
|
|
++spectra;
|
|
}
|
|
rlx_spectra_free_array(spectras);
|
|
}
|
|
rlx_project_free_array(projects);
|
|
rlx_close_file(file);
|
|
}
|
|
|
|
return 0;
|
|
}
|