Skip to content

Commit

Permalink
Parse nutmeg scripts to find used simulations
Browse files Browse the repository at this point in the history
This avoids prefixing when custom simulations don't conflict.
  • Loading branch information
ivandi committed Feb 17, 2024
1 parent 1fafb3c commit 6868acd
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions qucs/extsimkernels/ngspice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ void Ngspice::createNetlist(QTextStream &stream, int ,
unsigned int freqSims = 0;
unsigned int timeSims = 0;
unsigned int fourSims = 0;
unsigned int pzSims = 0;

outputs.clear();
for ( unsigned int i = 0 ; i < Sch->DocComps.count() ; i++ ) {
Expand Down Expand Up @@ -212,11 +213,39 @@ void Ngspice::createNetlist(QTextStream &stream, int ,
}
}
} else if ( sim_typ == ".CUSTOMSIM" ) {
dcSims++; dcswpSims++; freqSims++; timeSims++; fourSims++;
spiceNetlist.append(pc->getSpiceNetlist());
nods = pc->Props.at(1)->Value;
nods.replace(';', ' ');
outputs.append(pc->Props.at(2)->Value.split(';', qucs::SkipEmptyParts));

QRegularExpression ac_rx("^\\s*ac\\s.*", QRegularExpression::CaseInsensitiveOption);
QRegularExpression sp_rx("^\\s*sp\\s.*", QRegularExpression::CaseInsensitiveOption);
QRegularExpression noise_rx("^\\s*noise\\s.*", QRegularExpression::CaseInsensitiveOption);
QRegularExpression disto_rx("^\\s*disto\\s.*", QRegularExpression::CaseInsensitiveOption);
QRegularExpression fft_rx("^\\s*fft\\s.*", QRegularExpression::CaseInsensitiveOption);
QRegularExpression four_rx("^\\s*(four|fourier)\\s.*", QRegularExpression::CaseInsensitiveOption);
QRegularExpression dc_rx("^\\s*dc\\s.*", QRegularExpression::CaseInsensitiveOption);
QRegularExpression op_rx("^\\s*op\\s*", QRegularExpression::CaseInsensitiveOption);
QRegularExpression tran_rx("^\\s*tran\\s.*", QRegularExpression::CaseInsensitiveOption);
QRegularExpression sens_ac_rx("^\\s*sens\\s.*ac\\s.*", QRegularExpression::CaseInsensitiveOption);
QRegularExpression sens_dc_rx("^\\s*sens\\s.*", QRegularExpression::CaseInsensitiveOption);
QRegularExpression pz_rx("^\\s*pz\\s.*", QRegularExpression::CaseInsensitiveOption);

QStringList lines = pc->getSpiceNetlist().split('\n');
for ( const QString& line : lines ) {
if ( ac_rx.match(line).hasMatch() ) freqSims++ ;
else if ( sp_rx.match(line).hasMatch() ) freqSims++ ;
else if ( noise_rx.match(line).hasMatch() ) freqSims++ ;
else if ( disto_rx.match(line).hasMatch() ) freqSims++ ;
else if ( fft_rx.match(line).hasMatch() ) freqSims++ ;
else if ( four_rx.match(line).hasMatch() ) fourSims++ ;
else if ( dc_rx.match(line).hasMatch() ) dcswpSims++ ;
else if ( op_rx.match(line).hasMatch() ) dcSims++ ;
else if ( tran_rx.match(line).hasMatch() ) timeSims++ ;
else if ( sens_ac_rx.match(line).hasMatch() ) freqSims++ ;
else if ( sens_dc_rx.match(line).hasMatch() ) dcSims++ ;
else if ( pz_rx.match(line).hasMatch() ) pzSims++ ;
}
} else if ( sim_typ == ".DISTO" ) {
freqSims++;
spiceNetlist.append(pc->getSpiceNetlist());
Expand All @@ -234,6 +263,7 @@ void Ngspice::createNetlist(QTextStream &stream, int ,
}
nods = "inoise_spectrum onoise_spectrum";
} else if ( sim_typ == ".PZ" ) {
pzSims++;
spiceNetlist.append(pc->getSpiceNetlist());
QString out = "spice4qucs." + sim_name + ".cir.pz";
// Add it twice for poles and zeros
Expand Down Expand Up @@ -322,7 +352,17 @@ void Ngspice::createNetlist(QTextStream &stream, int ,
<< ".endc\n";
stream << ".END\n";

needsPrefix = ( (dcSims | dcswpSims | freqSims | timeSims | fourSims) > 1 );
needsPrefix = ( (dcSims | dcswpSims | freqSims | timeSims | fourSims | pzSims) > 1 );

qDebug() << '\n'
<< "Simulations:\n"
<< "DC: " << dcSims << '\n'
<< "DC sweep: " << dcswpSims << '\n'
<< "Frequency: " << freqSims << '\n'
<< "Time: " << timeSims << '\n'
<< "Fourier: " << fourSims << '\n'
<< "Pole-Zero: " << pzSims << '\n'
<< '\n';
}

/*!
Expand Down

0 comments on commit 6868acd

Please sign in to comment.