Multiline directives

Yes sir. I know the new method. BUT is not help “multi-line” JUST like you are discussion in here!

Wrong if ngpsice is only the world you working with, sir.

Please give an example line that is not working with ngspice. This will be the only way that I can have a look if there is a bug.

I think you can try it yourself. Make a simple simulation schematic. eeschema->Tools->Generate Netlist file… -> Spice -> run simulator with Simulator Command: "c:\ngspice\bin\ngspice.exe

You would get “absolute_path_to_netlist_file” : Invalid argument on the ngspice.
Also, I found that the ngspice.exe did not find it own init file correctly, but if the “current” path is set to where the netlist file at. Then copy the spinit file to that folder. I will be able to run my simulator by using the Simulator Command: “c:\ngspice\bin\ngspice.exe sim.cir” perfectly.

I think both KiCad and ngpsice need to fix. But that most importance is the fix from KiCad so that I can run other netlist simulation directly from the ngspice console without typing long absolute path of every netlist file, and what about the include path that I use as relative from the netlist file where include statement at.!

What I did (on Windows 10):
Expand https://sourceforge.net/projects/ngspice/files/ng-spice-rework/30/ngspice-30_64.zip/download into directory C:, so you have ngspice in C:\Spice64\bin.

Copy C:\Program Files\KiCad\share\kicad\demos\simulation into C:\KiCad, to get C:\KiCad\simulation\laser_driver. This just serves as an example for an arbitrary eeschema project placed into an arbitrary folder.

Set the access for the whole directory tree C:\KiCad to full access for all users. This allows KiCad to read and write to this directory without the need for having admin rights.

Install recent KiCad nightly 5.1rc.

Run eeschema

Open file c:\KiCad\simulation\laser_driver\laser_driver.sch

Replace the text box entry

.tran 10p 150n

by

.tran 10p 150n
.control
run
rusage
set filetype=ascii
write c:\Kicad\laser.out "/in" "/out"
plot "/in" "/out"
.endc

File–>Save current sheet
Tools–>Generate netlist file…–>Spice
Select ‘Default format’
Simulator command: C:\Spice64\bin\ngspice.exe
Button: Generate netlist
Button: Save (Store laser_driver.cir to C:\KiCad\Simulation\laser_driver)
Button: Run Simulator

Voila:
ngspice.exe simulates the file laser_driver.cir and plots the resulting output. No problem finding the spinit file. No need to type anything in addition. No “absolute_path_to_netlist_file” : Invalid argument response.

BTW: My ngspice version is 28

Above I have shown a way for external simulation using ngspice.exe. My conclusionis that there is no need for a fix to achieve this, neither in ngspice nor in KiCad.

Concerning the multiline request: Problem if first line in text box starts with a ‘*’:
I changed the textbox ofthe example given above to

*bug fix test
.tran 10p 150n
*.control
*run
*rusage
*set filetype=ascii
*write c:\Kicad\laser.out "/in" "/out"
*plot "/in" "/out"
*.endc

Using the procedure above, ngspice opens, loads the netlist file and then stops waiting for a command like’run’ --> o.k.

Using internal ngspice with Tools–>Simulator–>Run Simulation o.k. as well.
So this bug has been fixed by the KiCad devs.

Well I giving up on you since I feel like my issue seem to not to be believable by you. Also, It seem typing 20+ characters each time when run ngspice from KiCad is not a concerning to you. Then yes, there is not fix need to be done. If your present solution is work for ngspice version 30 then that to me it already fix from 28 to 30 version. But it not going to solve the typing long characters issue for absolute path. Thank you @holger.

This is the exactly issue with KiCad for multiline directive. I cannot have that whole directive include in my netlist with the new style of line by line directive with the “.” at beginning. I would like +pspice for include everything in the text box exclude the first line in the text box. In addition with the line by line directive!. Most of my simulations directive contains full simulation control block, or event a short sub circuitry model. By removing the +pspice for multi-line is it become some what impossible to do any useful simulation on my case.

As current state for the KiCad software - I would not consider using this way for “serious” simulations.

There are several commands, procedures and tools available that might help here.

ngspice has a command ‘cd ‘directory’’ to be placed into a control section to change its working directory. The command ‘getcwd’ will show the actual working directory for ngspice.

You may add a ‘.include ‘filename’’ command to the text box to get additional subcircuits into your netlist. You just have to place them into file ‘filename’.

If you are on MS Windows, and you want to avoid any typing, you may use my small GUI to be found at http://ngspice.sourceforge.net/download.html#bin1 . This allows you to select any input file and start external ngspice.exe without any typing, just mouse clicks.

If you always have the same ngspice input file directories, you may add a command 'set sourcepath . path1 path2 ’ to spice.rc or to the beginning of your .control section. ngspice the will search for the input file in the current directory (the dot .) and in any other directory given.

You may even set an environmental variable NGSPICE_INPUT_DIR to the search path for input files.

So there are many options to customize a working environment without need to patch KiCad or ngspice.

It might be useful to switch to ngspice-30, because there are included many fixes that have been requested by users, and it is more stable than ngspice-28.

3 Likes

I still like to have KiCad do the job for the path. It would allow my stuff can run on other coworker computer without the need of exactly path setting. They first two solution are what I had tried, The source path is one that new to me. But again it do not give me what I needed - that is my coworker can just open, run simulation without need to set up exactly path and location in this machine. This mean, he also don’t need to event need to do anything with environment variables too.