#!/bin/bash # (C) 2018 Mithat Konar https://mithatkonar.com # A scheme to use arbitrary SPICE simulators in Kicad 5. # # Usage: # * Put all the stuff to be prepended (e.g., -PSPICE stuff) in pre.cir. # * Put all the stuff to be appended (e.g., +PSPICE stuff) in post.cir. # * In this script: # * Set CIRCUITNAME to point to the .cir file KiCad 5 generates. # * Set SPICE_ENGINE to your desired SPICE engine. (Hack the line # where it's invoked to add any needed command line parameters.) # * In the KiCad Netlist dialog's Spice tab, set the simulator to this # file using an absolute path. # * In the KiCad Netlist dialog's Spice tab, Run Simulator. # ----- config --------------------------------------------------------- # The name of the cir file to simulate with (w/o extension): CIRCUITNAME=opa-x5-spice # The command for the SPICE engine you want to use: SPICE_ENGINE="xterm -e ngspice" # ---------------------------------------------------------------------- ### constants CIRCUITFILE=${CIRCUITNAME}.cir CIRCUITFILE_CLEANED=${CIRCUITNAME}-cleaned.cir GENERATED_CIR=${CIRCUITNAME}-complete.cir ### go! # set the script's directory as the working directory cd $( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) # remove all lines starting with .title from CIRCUITFILE sed '/^.title/d' $CIRCUITFILE > $CIRCUITFILE_CLEANED # concatenate the final file cat pre.cir > $GENERATED_CIR cat $CIRCUITFILE_CLEANED >> $GENERATED_CIR cat post.cir >> $GENERATED_CIR # run it $SPICE_ENGINE $GENERATED_CIR # cleanup #~ rm $GENERATED_CIR rm $CIRCUITFILE_CLEANED