fahimkhan / Online-NgSpice-Simulator

This repositry contains code for Online NgSpice Simulator
MIT License
4 stars 0 forks source link

parsing ng-spice output #3

Open hopewise opened 8 years ago

hopewise commented 8 years ago

As you have tried to parse ng-spice, I would like to ask please, do you think I can fully parse the ng-spice output to power a simulator features like this one as I would need to cast the current value for each component including wires, do you encourage me to start such a parser? Do you know any good ng-spice output parser library there?

fahimkhan commented 8 years ago

We are actually getting all node voltages and node current from ngspice. Our parser is capable to parse this value for ac,dc and tran analysis. The result we got from the parser is in the form of dictionary having key as node/branch name and value as list of voltage/current value for each iteration. You can easily use this dictionary in your plot.

Now this is up to you how you reflect it in your front end. You can just show the value or just plot branch current or node voltage. I am not aware of any other open source ngspice output parser library. But if you are planning to write your own parser then I would suggest to use rawfile generated in ngspice instead of content of 'print allv' and 'print alli'

By the way you can check https://www.circuitlab.com/ I think they are using ngspice at the backend.

hopewise commented 8 years ago

Can you please refer to the dictionary in the source code in where you store the result?

Also, using rawfile generated in ngspice will not consume memory as ngspice will write to the rawfile directly?

fahimkhan commented 8 years ago

Yes, ngSpice will directly write it to the file. Just like 'print allv > file.txt' there is command for raw file as well.

We have written a parser in python which can be found under scripts directory. It takes the analysis,file details and after parsing ,it store the result in dictionary. We call this parser from nodeJS using python-shell module. Here is the code for calling parser.py from nodeJS.

`function parsePlotData(){ console.log("Ngspice netlist executed successfully "+fileName); // console.log("Allv :"+plot_allv_file) //socket.emit('serverMessage','Ngspice netlist executed successfully: ');
//var analysisInfo = grep('.tran|.dc|.ac', fileName); //Not reliable var analysisInfo = getAnalysisInfo(fileName); console.log("Analysis :"+analysisInfo) var options = { mode: 'json', pythonPath: pyEnv, pythonOptions: ['-u'], scriptPath: scriptPath, args: [analysisInfo, plot_allv_file, plot_alli_file] };

        PythonShell.run('parser.py', options, function (err, results) {
        if (err) throw err;
            // results is an array consisting of messages collected during execution 
        // console.log('results: %j', results);
        var resultString = results[0];
        // console.log(resultString);
        //Emitting Data Points to client
        socket.emit('plotData',resultString);

        });
    }`  
hopewise commented 8 years ago

Thanks Fahimkhan, is there any social network I can follow you on? Twitter maybe?

fahimkhan commented 8 years ago

Here is my twitter profile https://twitter.com/bitwisenoise

hopewise commented 8 years ago

Thanks Fahim, but where is parser.py file?

fahimkhan commented 8 years ago

Its there under scripts directory.

hopewise commented 8 years ago

Ah, sorry didn't notice!

higuoxing commented 6 years ago

Wow, thank you for all of your efforts! Much helpful! Such an useful project!

higuoxing commented 6 years ago

Hi, whatever, thanks for your efforts! I found that in ngspice27 there's a command wrdata v(in), which will write data as following

 8.24500000e-02  0.00000000e+00
 8.25500000e-02  0.00000000e+00
 8.26500000e-02  0.00000000e+00
 8.27500000e-02  0.00000000e+00
 8.28500000e-02  0.00000000e+00
 8.29500000e-02  0.00000000e+00
 8.30500000e-02  0.00000000e+00
 8.31500000e-02  0.00000000e+00
 8.32500000e-02  0.00000000e+00
 8.33500000e-02  0.00000000e+00

So, I think it's easier to parse :)