Code covered by the BSD License  

Highlights from
Run ngspice simulation and import rawfile

5.0

5.0 | 1 rating Rate this file 31 Downloads (last 30 days) File Size: 3.08 KB File ID: #37457
image thumbnail

Run ngspice simulation and import rawfile

by

 

Runs ngspice with a given netlist and loads the simulation output (rawfile) into MATLAB.

| Watch this File

File Information
Description

This function provides a wrapper to 'ngspice' making it easier to use the software from within MATLAB.

ngspice is an open-source electronic circuit simulator based on the Simulation Program with Integrated Circuit Emphasis (SPICE). It uses a 'netlist' to describe the layout of the circuit which is provided as an input text file. The simulation produces an output file (called a 'rawfile') containing a number of variables including voltages and currents at various points in the circuit.

This function imports the rawfile into MATLAB allowing data to be analyzed and graphed more easily.

The ngspice software must be installed on your computer in order to use this function.

Acknowledgements

Fast Import Of Compressed Binary .Raw Files Created With L Tspice Circuit Simulator and Read Ngspice inspired this file.

Required Products MATLAB
MATLAB release MATLAB 7.12 (R2011a)
Other requirements ngspice
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (5)
17 Jan 2013 Richa

Thank you! That helped! I also moved everything including the program file to the same folder to avoid any pathway issues.

03 Jan 2013 Iain Robinson

Dear Richa,
it's hard to work out exactly where it is failing, but it seems to be something to do with paths.

You said that ngspice is producing the following error:

"SpiceModel_2e.txt": Invalid argument

Could the quotation marks around the file name be causing the problem? You could try removing them by changing line 40 from:

command = sprintf('ngspice --batch --rawfile="%s" "%s"', rawfilename, netlistfilename);

to:

command = sprintf('ngspice --batch --rawfile=%s %s', rawfilename, netlistfilename);

(The quotation marks are there so that the script can cope with spaces in file or folder names; but you are not using any spaces in your file names.)

Iain.

26 Dec 2012 Richa

I am getting the error:

spinit found in c:\spice\share\ngspice\scripts\spinit
"SpiceModel_2e.txt": Invalid argument
Could not delete temp file: Permission denied

in the NGSpice window and then:

Error using ngspice (line 49)
Could not open rawfile:
C:\...
No such file or directory
This may indicate that the simulation failed.

in Matlab. I think the error has to do with a pathway issue. I had put the Matlab file and the netlist file in the "bin" folder with the application. There is a temp file (with a different name than rawfilename)that is created in that folder. Any suggestions on what could be going wrong?

Thank you!!
Richa

26 Dec 2012 Richa

I am getting the error:

spinit found in c:\spice\share\ngspice\scripts\spinit
"SpiceModel_2e.txt": Invalid argument
Could not delete temp file: Permission denied

in the NGSpice window and then:

Error using ngspice (line 49)
Could not open rawfile:
C:\...
No such file or directory
This may indicate that the simulation failed.

in Matlab. I think the error has to do with a pathway issue. I had put the Matlab file and the netlist file in the "bin" folder with the application. There is a temp file (with a different name than rawfilename)that is created in that folder. Any suggestions on what could be going wrong?

Thank you!!
Richa

06 Nov 2012 Alan

This failed for me with this error.

Error using ngspice (line 135)
All expected data have been read, but there still appears to be some data remaining in the file:

I was running an example .net file I got from

http://www.ngspice.com/examples.php

I selected the "RC filter AC response" circuit and copied the netlist to a file and used that from MATLAB.

Contact us