From 12818d9f7f54b60b7253765ccc23a6efec2b0a06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20K=C3=A4berich?= Date: Tue, 14 Dec 2021 16:41:33 +0100 Subject: [PATCH] Improve touchstone/csv file extensions when saving file --- .../Traces/tracetouchstoneexport.cpp | 2 +- Software/PC_Application/csv.cpp | 3 +++ Software/PC_Application/touchstone.cpp | 14 +++++++------- Software/PC_Application/touchstone.h | 2 +- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Software/PC_Application/Traces/tracetouchstoneexport.cpp b/Software/PC_Application/Traces/tracetouchstoneexport.cpp index c0ca130..dbaebfe 100644 --- a/Software/PC_Application/Traces/tracetouchstoneexport.cpp +++ b/Software/PC_Application/Traces/tracetouchstoneexport.cpp @@ -101,7 +101,7 @@ void TraceTouchstoneExport::on_buttonBox_accepted() case 2: format = Touchstone::Format::RealImaginary; break; } - t.toFile(filename.toStdString(), unit, format); + t.toFile(filename, unit, format); delete this; } } diff --git a/Software/PC_Application/csv.cpp b/Software/PC_Application/csv.cpp index 673a2f1..9508f1f 100644 --- a/Software/PC_Application/csv.cpp +++ b/Software/PC_Application/csv.cpp @@ -55,6 +55,9 @@ CSV CSV::fromFile(QString filename, char sep) void CSV::toFile(QString filename, char sep) { ofstream file; + if(!filename.endsWith(".csv")) { + filename.append(".csv"); + } file.open(filename.toStdString()); file << setprecision(10); unsigned maxlen = 0; diff --git a/Software/PC_Application/touchstone.cpp b/Software/PC_Application/touchstone.cpp index 5525dbe..c592fec 100644 --- a/Software/PC_Application/touchstone.cpp +++ b/Software/PC_Application/touchstone.cpp @@ -37,22 +37,22 @@ void Touchstone::AddDatapoint(Touchstone::Datapoint p) } } -void Touchstone::toFile(string filename, Scale unit, Format format) +void Touchstone::toFile(QString filename, Scale unit, Format format) { - // strip any potential file name extension and apply snp convention - if(filename.find_last_of('.') != string::npos) { - filename.erase(filename.find_last_of('.')); + // add correct file extension if not already present + QString extension = ".s"+QString::number(m_ports)+"p"; + if(!filename.endsWith(extension)) { + filename.append(extension); } - filename.append(".s" + to_string(m_ports) + "p"); // create file ofstream file; - file.open(filename); + file.open(filename.toStdString()); file << toString(unit, format).rdbuf(); file.close(); - this->filename = QString::fromStdString(filename); + this->filename = filename; } stringstream Touchstone::toString(Touchstone::Scale unit, Touchstone::Format format) diff --git a/Software/PC_Application/touchstone.h b/Software/PC_Application/touchstone.h index fa34fa1..daa9dd7 100644 --- a/Software/PC_Application/touchstone.h +++ b/Software/PC_Application/touchstone.h @@ -33,7 +33,7 @@ public: Touchstone(unsigned int m_ports); virtual ~Touchstone(){}; void AddDatapoint(Datapoint p); - void toFile(std::string filename, Scale unit = Scale::GHz, Format format = Format::RealImaginary); + void toFile(QString filename, Scale unit = Scale::GHz, Format format = Format::RealImaginary); std::stringstream toString(Scale unit = Scale::GHz, Format format = Format::RealImaginary); static Touchstone fromFile(std::string filename); double minFreq();