Skip to content

Commit

Permalink
Loading files with no first or second line correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
AKMaily committed Oct 24, 2024
1 parent b4ab1d3 commit 938340d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 17 deletions.
1 change: 0 additions & 1 deletion src/handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,5 +481,4 @@ void addPlotFromFile(externData &dataObj) {
dataObj.xValues.data(),
dataObj.yValues.data(),
static_cast<int>(dataObj.xValues.size()), 0, 0, sizeof(double));
std::cout << "falsche funktion" << std::endl;
}
58 changes: 42 additions & 16 deletions src/loadingFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,50 +101,76 @@ void externData::loadDataFromFile() {
throw std::runtime_error("Error: File cant be opened " + filepath.string());
}

std::string line;
std::string line;

// Check for old data format with Omniscope
bool firstLineIsData = false; // Flag, um zu überprüfen, ob die erste Zeile Werte enthält
bool secondLineIsData = false; // Flag, ob die zweite Zeile Werte enthält
units.clear();

// Check for OmniScope in the first line or if it's data
if (std::getline(file, line)) {
std::istringstream iss(line);
double potential_x, potential_y;
if (line.find("Omniscope") != std::string::npos) {
isOmnAIScope = true;
std::cout << "Old OmnAIScope file detected\n";
sampling_rate = 100000; // sampling rate of the OmnAIScope
sampling_rate = 100000; // Set the sampling rate for the OmniScope format
} else if (iss >> potential_x >> potential_y) {
// If the first line contains two doubles, it is treated as data
firstLineIsData = true;
xValues.push_back(potential_x);
yValues.push_back(potential_y);
if (units.size() < 2) {
std::cout << "No units provided, standard units (s) and (V) are set" << std::endl;
units = {"s", "V"}; // Set standard units
}
}
}

// Try reading units from the second line, else set standard units
// Check for units in the second line or if it's data
if (std::getline(file, line)) {
std::istringstream iss(line);
double potential_x, potential_y;
std::string unit;
units.clear();

while (iss >> unit) {
if (iss >> unit && !std::isdigit(unit[0])) {
// If the second line contains units (strings), add them to the units vector
units.push_back(unit);
while (iss >> unit) {
units.push_back(unit);
}
} else if (iss >> potential_x >> potential_y) {
// If the second line contains two doubles, treat it as data
secondLineIsData = true;
xValues.push_back(potential_x);
yValues.push_back(potential_y);
}

// If no units were found, set the standard units
if (units.size() < 2) {
std::cout << "No units provided, standard units (V) and (s) are set" << std::endl;
units = {"s", "V"}; // set standard units
std::cout << "No units provided, standard units (s) and (V) are set" << std::endl;
units = {"s", "V"}; // Set standard units
}
} else {
std::cout << "No Units provided. Standard Units (V) and (s) are set" << std::endl;
units = {"s", "V"};
}

double x = 0.0, y = 0.0;
int index = 0;
int index = firstLineIsData + secondLineIsData; // Start the index based on pre-read data

// Continue reading the rest of the file
while (std::getline(file, line)) {
std::istringstream iss(line);
char comma;

if (isOmnAIScope) {
// if old omniscope data
x = index / sampling_rate; // X-Wert berechnen
// OmniScope format: Only Y-values are present, X is calculated
x = index / sampling_rate;
if (!(iss >> y)) {
throw std::runtime_error("Error: Y-Values could not be read correctly");
}
} else {
if (!(iss >> x >> y)) {
throw std::runtime_error("Error: Y and X-Values could not be read correctly");
// Normal format: Read X and Y values
if (!(iss >> x >> comma >> y) || comma != ',') {
throw std::runtime_error("Error: X and Y-Values could not be read correctly");
}
}

Expand Down

0 comments on commit 938340d

Please sign in to comment.