Skip to content

Commit

Permalink
Add support for custom prefix to dataset variables. The prefix is
Browse files Browse the repository at this point in the history
enclosed between # # in the output file name. If the file name contains
a #custom_prefix# section it will be prepended to the dataset variables.
Useful for custom simulations where one can set multiple simulations and
multiple output files.

Example nutmeg script:
============================
AC DEC 10 1MEG 1G
write custom#ac1#.txt v(out)
destroy all

AC LIN 100 90MEG 110MEG
write custom#ac2#.txt v(out)
destroy all
============================

The dataset will contain:
ac1.ac.v(out) ac1.frequency
ac2.ac.v(out) ac2.frequency

Prevent duplications in simulations QStringList of Ngspice::createNetlist.
With current code if one has two nutmeg scripts both scripts are placed
twice in the control section of the netlist.
  • Loading branch information
ivandi committed Dec 27, 2023
1 parent 7df0e3e commit ce8ef3c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
18 changes: 12 additions & 6 deletions qucs/extsimkernels/abstractspicekernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,8 @@ void AbstractSpiceKernel::convertToQucsData(const QString &qucs_dataset)
bool hasParSweep = false;
bool hasDblParSweep = false;

QRegularExpression custom_prefix_rx("(?<=#).*?(?=#)");
QString custom_prefix = custom_prefix_rx.match(ngspice_output_filename).captured(0);
QRegularExpression four_rx(".*\\.four[0-9]+$");
QString full_outfile = workdir+QDir::separator()+ngspice_output_filename;
if (ngspice_output_filename.endsWith("HB.FD.prn")) {
Expand Down Expand Up @@ -1199,7 +1201,7 @@ void AbstractSpiceKernel::convertToQucsData(const QString &qucs_dataset)
}
}
if (var_list.isEmpty()) continue; // nothing to convert
normalizeVarsNames(var_list);
normalizeVarsNames(var_list, custom_prefix);

QString indep = var_list.first();
//QList<double> sim_point;
Expand Down Expand Up @@ -1298,22 +1300,26 @@ void AbstractSpiceKernel::removeAllSimulatorOutputs()
* for harmonic balance variable and current probes variables are supported.
* \param var_list This list contains variable names that need normalization.
*/
void AbstractSpiceKernel::normalizeVarsNames(QStringList &var_list)
void AbstractSpiceKernel::normalizeVarsNames(QStringList &var_list, const QString &custom_prefix)
{
QString prefix="";
QString iprefix="";
QString indep = var_list.first();
QString cprefix = custom_prefix;
if(!cprefix.isEmpty())
cprefix.append(".");
bool HB = false;
indep = indep.toLower();
if (indep=="time") {
prefix = "tran.";
iprefix = "i(tran.";
prefix = cprefix + "tran.";
iprefix = cprefix + "i(tran.";
} else if (indep=="frequency") {
prefix = "ac.";
iprefix = "i(ac.";
prefix = cprefix + "ac.";
iprefix = cprefix + "i(ac.";
} else if (indep=="hbfrequency") {
HB = true;
}
var_list.first().insert(0, cprefix);

for(auto & it : var_list) { // For subcircuit nodes output i.e. v(X1:n1)
it.replace(":","_"); // colon symbol is reserved in Qucs as dataset specifier
Expand Down
2 changes: 1 addition & 1 deletion qucs/extsimkernels/abstractspicekernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class AbstractSpiceKernel : public QObject
private:
enum outType {xyceSTD, spiceRaw, spiceRawSwp, xyceSTDswp, Unknown};

void normalizeVarsNames(QStringList &var_list);
void normalizeVarsNames(QStringList &var_list, const QString &custom_prefix);
int checkRawOutupt(QString ngspice_file, QStringList &values);
void extractBinSamples(QDataStream &dbl, QList< QList<double> > &sim_points,
int NumPoints, int NumVars, bool isComplex);
Expand Down
22 changes: 11 additions & 11 deletions qucs/extsimkernels/ngspice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,18 @@ void Ngspice::createNetlist(QTextStream &stream, int ,
if(pc->isSimulation && pc->isActive == COMP_IS_ACTIVE) {
s = pc->getSpiceNetlist();
QString sim_typ = pc->Model;
if (sim_typ==".AC") simulations.append("ac");
if (sim_typ==".TR") simulations.append("tran");
if (sim_typ==".CUSTOMSIM") simulations.append("custom");
if (sim_typ==".DISTO") simulations.append("disto");
if (sim_typ==".NOISE") simulations.append("noise");
if (sim_typ==".PZ") simulations.append("pz");
if (sim_typ==".SENS") simulations.append("sens");
if (sim_typ==".SENS_AC") simulations.append("sens_ac");
if (sim_typ==".SP") simulations.append("sp");
if (sim_typ==".FFT") simulations.append("fft");
if (sim_typ==".AC") if(!simulations.contains("ac")) simulations.append("ac");
if (sim_typ==".TR") if(!simulations.contains("tran")) simulations.append("tran");
if (sim_typ==".CUSTOMSIM") if(!simulations.contains("custom")) simulations.append("custom");
if (sim_typ==".DISTO") if(!simulations.contains("disto")) simulations.append("disto");
if (sim_typ==".NOISE") if(!simulations.contains("noise")) simulations.append("noise");
if (sim_typ==".PZ") if(!simulations.contains("pz")) simulations.append("pz");
if (sim_typ==".SENS") if(!simulations.contains("sens")) simulations.append("sens");
if (sim_typ==".SENS_AC") if(!simulations.contains("sens_ac")) simulations.append("sens_ac");
if (sim_typ==".SP") if(!simulations.contains("sp")) simulations.append("sp");
if (sim_typ==".FFT") if(!simulations.contains("fft")) simulations.append("fft");
if ((sim_typ==".SW")&&
(pc->Props.at(0)->Value.startsWith("DC"))) simulations.append("dc");
(pc->Props.at(0)->Value.startsWith("DC"))) if(!simulations.contains("dc")) simulations.append("dc");
// stream<<s;
}
}
Expand Down

0 comments on commit ce8ef3c

Please sign in to comment.