← Back to team overview

kicad-developers team mailing list archive

Patch for spice netlist

 

	Hello everyone,

	I have written a patch for Spice netlist exporter. I spend a lot of
time when I want to switch from .AC analysis to .TRAN or .NOISE. This
patch allows spice exporter to use different configurations with two new
instructions .if and .config.

	Usage :
.config <configuration name>
.if <configuration name>: <spice command>

	For example :

.title PP7591
.config ac
.if tran: .tran 1u 100m 0 1u
.if ac: .ac dec 10000 1 1MEG
.options method=gear reltol=1m minbreak=200ps
.control
	run
	write results.raw
	.if tran: fourier 1k v("/V1")
	.if tran: fourier 1k v("/a1")
	.if tran: fourier 1k v("/a2")
	.if tran: quit
	.if ac: plot 180/PI*(cph("/vf")-cph("/vd"))
.endc

will produce a netlist that contains:

.title PP7591
.config ac
.ac dec 10000 1 1MEG
.options method=gear reltol=1m minbreak=200ps
.control
	run
	write results.raw
	plot 180/PI*(cph("/vf")-cph("/vd"))
.endc

	Best regards,

	JKB
--- netlist_exporter_pspice.cpp.orig	2019-03-09 10:26:28.153565666 +0100
+++ netlist_exporter_pspice.cpp	2019-03-09 12:10:48.417449513 +0100
@@ -382,6 +382,8 @@
 
     m_directives.clear();
     bool controlBlock = false;
+	wxString currentConfig( "" );
+	wxString localConfig( "" );
 
     for( unsigned i = 0; i < sheetList.size(); i++ )
     {
@@ -409,11 +411,29 @@
                 line.Trim( true ).Trim( false );
                 // Convert to lower-case for parsing purposes only
                 wxString lowercaseline = line;
+
                 lowercaseline.MakeLower();
 
+				if ( lowercaseline.StartsWith( ".if " ) )
+				{
+					localConfig = lowercaseline.AfterFirst( ' ' )
+							.BeforeFirst( ':' ).Trim( false );
+
+					if ( ! localConfig.IsSameAs(currentConfig) )
+					{
+						continue;
+					}
+					else
+					{
+						lowercaseline = lowercaseline.AfterFirst( ':' )
+								.Trim( false );
+						line = line.AfterFirst( ':' ).Trim( false );
+					}
+				}
+
                 // 'Include' directive stores the library file name, so it
                 // can be later resolved using a list of paths
-                if( lowercaseline.StartsWith( ".inc" ) )
+				if( lowercaseline.StartsWith( ".inc" ) )
                 {
                     wxString lib = line.AfterFirst( ' ' );
 
@@ -437,6 +457,11 @@
                     m_title = line.AfterFirst( ' ' );
                 }
 
+				else if( lowercaseline.StartsWith( ".config " ) )
+				{
+					currentConfig = lowercaseline.AfterFirst( ' ' );
+				}
+
                 // Handle .control .. .endc blocks
                 else if( lowercaseline.IsSameAs( ".control" ) && ( !controlBlock ) )
                 {

Follow ups