2

Is there a way to use ngspice command line without providing a circuit file? ex: passing the circuit as a string within the command line ?

EDIT

Currently the only way I could use ngspice in command line is by providing an input file.. I could not find an example of using pipe mode though to pass netlist directly via command line without have to use a file to read from.

simo
  • 273
  • 1
  • 13

2 Answers2

1

In the interactive shell you can input the netlist line by line using "circbyline". Remember, the first line you always enter is a title, the last line needs to be ".end".

e.g., you can save a file codebyline.cir as follows:

circbyline Example Listing
circbyline R1 1 0 1k
circbyline C1 1 0 1m
circbyline V1 1 0 pulse(0 1 0 1n 1n 1u 2u)
circbyline .tran 0.1n 2u
circbyline .end

And then:

cat codebyline.cir | ngspice

Instead of reading out from a file, any other program can generate the netlist and you can pipe it to ngspice. "circbyline" has to prepend every statement.

B Pete
  • 2,832
  • 18
  • 23
0

As commented before, the Window GUI version of ngspice will not work with pipes due to a Windows specific I/O handling.
Maybe you could try finding a workaround.

I think you should have the GUI write the netlist to a file called e.g. "circuit.cir" and have the code of the GUI execute ngspice circuit.cir.

Another option having the GUI making a string based on the netlist and using a batch file which parses the netlist string, writes it to (e.g.) "circuit.cir" and lastly, executes ngspice circuit.cir.
Make sure you seperate each line of the netlist with a unique character (e.g. ¶ or ­§ or whatever) when making one big string of it.

Huisman
  • 10,694
  • 2
  • 20
  • 40
  • I don't want to use any GUI, I just want to be able to pass netlist to ngspice without using a file but I have no idea about the pipe mode, can you please share an example of passing netlist using pipe mode? – simo Jul 10 '19 at 08:35
  • Any update about this? – simo Jul 18 '19 at 12:39
  • @simo I hardly use ngspice. As said it won't work on Windows and I don't have linux. So, I'm afraid I can't help – Huisman Jul 18 '19 at 12:45
  • No worries, thank you – simo Jul 18 '19 at 14:46