Improve touchstone/csv file extensions when saving file

This commit is contained in:
Jan Käberich 2021-12-14 16:41:33 +01:00
parent c5cbfddbfe
commit 12818d9f7f
4 changed files with 12 additions and 9 deletions

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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)

View File

@ -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();