diff options
author | fahimkhan | 2016-08-23 12:02:09 +0530 |
---|---|---|
committer | fahimkhan | 2016-08-23 12:02:09 +0530 |
commit | af10f80e9f318f0329e477a07d540b1aee19baeb (patch) | |
tree | 05911153b9eb947ab174d3ca9254cf62d6bdf202 | |
parent | 9c1e0a4a5fd4099302e63144987f67f5b28b4890 (diff) | |
download | Online-NgSpice-Simulator-af10f80e9f318f0329e477a07d540b1aee19baeb.tar.gz Online-NgSpice-Simulator-af10f80e9f318f0329e477a07d540b1aee19baeb.tar.bz2 Online-NgSpice-Simulator-af10f80e9f318f0329e477a07d540b1aee19baeb.zip |
Subject: Added plots details
Description: Now user can write what voltage or current needs to plot
-rw-r--r-- | routes/routes.js | 27 | ||||
-rw-r--r-- | scripts/Oldparser.py | 226 | ||||
-rw-r--r-- | scripts/parser.py | 80 | ||||
-rw-r--r-- | views/index.html | 10 |
4 files changed, 260 insertions, 83 deletions
diff --git a/routes/routes.js b/routes/routes.js index 5dbda92..f65a084 100644 --- a/routes/routes.js +++ b/routes/routes.js @@ -12,7 +12,6 @@ module.exports = function(express,app,fs,os,io,PythonShell,scriptPath){ io.on('connection', function (socket) { socketID = getSocketID(socket); var plot_allv_file = '/tmp/plot_allv_'+socketID.toLowerCase()+'.txt' - var plot_alli_file = '/tmp/plot_alli_'+socketID.toLowerCase()+'.txt' var fileName = '/tmp/'+socketID+'.cir.out'; socket.emit('loadingPage', 'User with socket ID '+socket.id+' is Connected'); @@ -20,8 +19,11 @@ module.exports = function(express,app,fs,os,io,PythonShell,scriptPath){ console.log('Socket ID : '+data['socketID']); }); - socket.on('netlist',function(netlistContent){ + socket.on('netlist',function(data){ + netlistContent = data['netlist']; + plotOption = data['plotOption']; console.log('Server : '+netlistContent); + console.log('Plot Option :'+plotOption); // socket.emit('serverMessage','Recived message for client '+socketID); fs.writeFile(fileName, netlistContent, function (err) { if (err){ @@ -30,7 +32,7 @@ module.exports = function(express,app,fs,os,io,PythonShell,scriptPath){ console.log('File is stored at '+fileName); fs.exists(fileName, function(exists) { if (exists) { - addPlotDetails(fileName); + addPlotDetails(fileName,plotOption); executeNgspiceNetlist(fileName); } @@ -58,23 +60,15 @@ module.exports = function(express,app,fs,os,io,PythonShell,scriptPath){ } }); - fs.exists(plot_alli_file, function(exists) { - // console.log("Check Plot alli "+plot_alli_file) - if (exists) { - console.log("Check Plot alli files") - //Deleting plot alli file - deleteNetlistFile(plot_alli_file); - } - }); + }); - function addPlotDetails(fileName) + function addPlotDetails(fileName,plotOption) { - + plotOption=plotOption.replace(/^(\r\n)|(\n)/,''); //Adding Plot component in a file - sed('-i', 'run', 'run \n print allv > /tmp/plot_allv_'+socketID+'.txt \n \ - print alli > /tmp/plot_alli_'+socketID+'.txt', fileName); + sed('-i', 'run', 'run \n print '+plotOption.trim()+'> /tmp/plot_allv_'+socketID+'.txt \n' , fileName); } @@ -113,7 +107,6 @@ module.exports = function(express,app,fs,os,io,PythonShell,scriptPath){ 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); @@ -123,7 +116,7 @@ module.exports = function(express,app,fs,os,io,PythonShell,scriptPath){ pythonPath: pyEnv, pythonOptions: ['-u'], scriptPath: scriptPath, - args: [analysisInfo, plot_allv_file, plot_alli_file] + args: [analysisInfo, plot_allv_file] }; PythonShell.run('parser.py', options, function (err, results) { diff --git a/scripts/Oldparser.py b/scripts/Oldparser.py new file mode 100644 index 0000000..5017118 --- /dev/null +++ b/scripts/Oldparser.py @@ -0,0 +1,226 @@ + +AC_TYPE = 0 +TRANS_TYPE = 1 +DC_TYPE = 2 + +import sys +import os +import json +from decimal import Decimal + +class DataExtraction: + def __init__(self,analysisInfo,VOLT_FILE,CURRENT_FILE): + self.data = [] + self.analysisInfo = analysisInfo.split() #['.dc', 'v1', '-1e-00', '5e-00', '0.02e-00', 'i1', '-1e-03', '5e-03', '1e-03'] + self.VOLT_FILE = VOLT_FILE + self.CURRENT_FILE = CURRENT_FILE + self.val_dict = {} + self.voltList = [] + self.currentList = [] + + def openFile(self): + try: + with open(self.VOLT_FILE) as volt_reader: + self.allv = volt_reader.read() + self.allv = self.allv.split("\n") + + with open(self.CURRENT_FILE) as current_reader: + self.alli = current_reader.read() + self.alli = self.alli.split("\n") + + except Exception as e: + print "Exception Message : ",str(e) + + for line in self.alli[3].split(" "): + if len(line): + self.currentList.append(line) + self.currentList = self.currentList[2:] + #print "current list ----->", self.currentList + + for line in self.allv[3].split(" "): + if len(line): + self.voltList.append(line) + self.voltList = self.voltList[2:] + #print "volt list ------>", self.voltList + + numberList = self.calculateNumbers() + plotType = self.createDataList(numberList) + + return plotType + + + def calculateNumbers(self): + + lines_number = partition_number = volt_number = current_number = 0 + + for line in self.allv[3:]: + if "Index" in line: + volt_number += 1 + + for line in self.alli[3:]: + if "#branch" in line: + current_number += 1 + + self.dec = 0 + + if self.analysisInfo[0][-3:]==".ac": + self.analysisType = AC_TYPE + if "dec" in self.analysisInfo: + self.dec = 1 + + for line in self.allv[3:]: + lines_number += 1 + if "Index" in line: + partition_number += 1 + if "AC" in line: + break + + elif ".tran" in self.analysisInfo: + self.analysisType = TRANS_TYPE + for line in self.allv[3:]: + lines_number += 1 + if "Index" in line: + partition_number += 1 + if "Transient" in line: + break + + else: + self.analysisType = DC_TYPE + for line in self.allv[3:]: + lines_number += 1 + if "Index" in line: + partition_number += 1 + if "DC" in line: + break + + volt_number //= partition_number + current_number //= partition_number + + return [lines_number, volt_number, current_number] + + + def createDataList(self, numberList): + lines_number = numberList[0] + 1 + volt_number = numberList[1] + current_number = numberList[2] + + dec = [self.analysisType, self.dec] + + vnum = len(self.allv[5].split("\t")) + inum = len(self.alli[5].split("\t")) + + len_volt = len(self.voltList) + len_current = len(self.currentList) + + full_data = [] + + #creating data + for i in xrange(1, volt_number): + for line in self.allv[3+i*lines_number].split(" "): + if len(line) > 0: + self.voltList.append(line) + self.voltList.pop(len_volt) + self.voltList.pop(len_volt) + len_volt = len(self.voltList) + + for i in xrange(1, current_number): + for line in self.alli[3+i*lines_number].split(" "): + if len(line) > 0: + self.currentList.append(line) + self.currentList.pop(len_current) + self.currentList.pop(len_current) + len_current = len(self.currentList) + + p = k = m = 0 + + for line in self.alli[5:lines_number-1]: + if len(line.split("\t")) == inum: + j2 = line.split("\t") + j2.pop(0) + j2.pop(0) + j2.pop() + if self.analysisType == 0: + j2.pop() + + for i in xrange(1, current_number): + j3 = self.alli[5+i*lines_number+k].split("\t") + j3.pop(0) + j3.pop(0) + if self.analysisType == 0: + j3.pop() + j3.pop() + j2 = j2 + j3 + + full_data.append(j2) + + k += 1 + + for line in self.allv[5:lines_number-1]: + if len(line.split("\t")) == vnum: + j = line.split("\t") + j.pop() + if self.analysisType == 0: + j.pop() + for i in xrange(1, volt_number): + j1 = self.allv[5+i*lines_number+p].split("\t") + j1.pop(0) + j1.pop(0) + if self.analysisType == 0: + j1.pop() + if self.voltList[len(self.voltList)-1] == 'v-sweep': + self.voltList.pop() + j1.pop() + + j1.pop() + j = j + j1 + j = j + full_data[m] + m += 1 + j = "\t".join(j[1:]) + j = j.replace(",", "") + self.data.append(j) + + p += 1 + + self.volts_length = len(self.voltList) + self.voltList = self.voltList + self.currentList + + #print dec + return dec + + + def computeAxes(self): + nums = len(self.data[0].split("\t")) + #print "i'm nums:",nums + x_cordinates = [] + y_cordinates = [] + var = self.data[0].split("\t") + for i in range(1,nums): + y_cordinates.append([float(var[i])]) + for i in self.data[1:]: + temp = i.split("\t") + for j in range(1,nums): + y_cordinates[j-1].append(float(temp[j])) + for i in self.data: + temp = i.split("\t") + x_cordinates.append(float(temp[0])) + + for i in xrange(0, nums-1): + self.val_dict[self.voltList[i]] = y_cordinates[i] + self.val_dict['x-axis'] = x_cordinates + + +def main(): + analysisInfo = sys.argv[1] + VOLT_FILE = sys.argv[2] + CURRENT_FILE = sys.argv[3] + app = DataExtraction(analysisInfo,VOLT_FILE,CURRENT_FILE) + app.openFile() + app.computeAxes() + + print json.dumps(app.val_dict) + +# Call main function +if __name__ == '__main__': + # Create and display the splash screen + main() + diff --git a/scripts/parser.py b/scripts/parser.py index 5017118..3b8f1c2 100644 --- a/scripts/parser.py +++ b/scripts/parser.py @@ -9,40 +9,27 @@ import json from decimal import Decimal class DataExtraction: - def __init__(self,analysisInfo,VOLT_FILE,CURRENT_FILE): + def __init__(self,analysisInfo,plotFile): self.data = [] self.analysisInfo = analysisInfo.split() #['.dc', 'v1', '-1e-00', '5e-00', '0.02e-00', 'i1', '-1e-03', '5e-03', '1e-03'] - self.VOLT_FILE = VOLT_FILE - self.CURRENT_FILE = CURRENT_FILE + self.plotFile = plotFile self.val_dict = {} self.voltList = [] - self.currentList = [] def openFile(self): try: - with open(self.VOLT_FILE) as volt_reader: - self.allv = volt_reader.read() + with open(self.plotFile) as plotFile_reader: + self.allv = plotFile_reader.read() self.allv = self.allv.split("\n") - with open(self.CURRENT_FILE) as current_reader: - self.alli = current_reader.read() - self.alli = self.alli.split("\n") - except Exception as e: print "Exception Message : ",str(e) - for line in self.alli[3].split(" "): - if len(line): - self.currentList.append(line) - self.currentList = self.currentList[2:] - #print "current list ----->", self.currentList - for line in self.allv[3].split(" "): if len(line): self.voltList.append(line) self.voltList = self.voltList[2:] - #print "volt list ------>", self.voltList - + numberList = self.calculateNumbers() plotType = self.createDataList(numberList) @@ -51,16 +38,12 @@ class DataExtraction: def calculateNumbers(self): - lines_number = partition_number = volt_number = current_number = 0 + lines_number = partition_number = volt_number = 0 for line in self.allv[3:]: if "Index" in line: volt_number += 1 - for line in self.alli[3:]: - if "#branch" in line: - current_number += 1 - self.dec = 0 if self.analysisInfo[0][-3:]==".ac": @@ -93,25 +76,21 @@ class DataExtraction: if "DC" in line: break + volt_number //= partition_number - current_number //= partition_number - return [lines_number, volt_number, current_number] + return [lines_number, volt_number] def createDataList(self, numberList): lines_number = numberList[0] + 1 volt_number = numberList[1] - current_number = numberList[2] - dec = [self.analysisType, self.dec] vnum = len(self.allv[5].split("\t")) - inum = len(self.alli[5].split("\t")) - + len_volt = len(self.voltList) - len_current = len(self.currentList) - + full_data = [] #creating data @@ -123,37 +102,9 @@ class DataExtraction: self.voltList.pop(len_volt) len_volt = len(self.voltList) - for i in xrange(1, current_number): - for line in self.alli[3+i*lines_number].split(" "): - if len(line) > 0: - self.currentList.append(line) - self.currentList.pop(len_current) - self.currentList.pop(len_current) - len_current = len(self.currentList) - + p = k = m = 0 - for line in self.alli[5:lines_number-1]: - if len(line.split("\t")) == inum: - j2 = line.split("\t") - j2.pop(0) - j2.pop(0) - j2.pop() - if self.analysisType == 0: - j2.pop() - - for i in xrange(1, current_number): - j3 = self.alli[5+i*lines_number+k].split("\t") - j3.pop(0) - j3.pop(0) - if self.analysisType == 0: - j3.pop() - j3.pop() - j2 = j2 + j3 - - full_data.append(j2) - - k += 1 for line in self.allv[5:lines_number-1]: if len(line.split("\t")) == vnum: @@ -173,7 +124,7 @@ class DataExtraction: j1.pop() j = j + j1 - j = j + full_data[m] + # j = j + full_data[m] ## Not required as we are not adding alli m += 1 j = "\t".join(j[1:]) j = j.replace(",", "") @@ -182,7 +133,7 @@ class DataExtraction: p += 1 self.volts_length = len(self.voltList) - self.voltList = self.voltList + self.currentList + self.voltList = self.voltList #+ self.currentList #print dec return dec @@ -211,9 +162,8 @@ class DataExtraction: def main(): analysisInfo = sys.argv[1] - VOLT_FILE = sys.argv[2] - CURRENT_FILE = sys.argv[3] - app = DataExtraction(analysisInfo,VOLT_FILE,CURRENT_FILE) + plotFile = sys.argv[2] + app = DataExtraction(analysisInfo,plotFile) app.openFile() app.computeAxes() diff --git a/views/index.html b/views/index.html index 3991361..2971225 100644 --- a/views/index.html +++ b/views/index.html @@ -78,6 +78,12 @@ v1 in gnd pwl(0m 0 0.5m 5 50m 5 50.5m 0 100m 0) .endc
.end
</textarea>
+ <h3>Plots:</h3>
+ <textarea class="form-control" id="plotOption" rows="1">
+v(in) v(out)
+
+ </textarea>
+
</div>
</form>
@@ -139,12 +145,14 @@ v1 in gnd pwl(0m 0 0.5m 5 50m 5 50.5m 0 100m 0) var clearButton = document.getElementById("doClear");
var messages = document.getElementById("messages");
var plotArea = document.getElementById("plotArea");
+ var plotVariable = document.getElementById("plotOption");
submitButton.addEventListener("click", function() {
var netlist = editorContent.value;
+ var plotOption = plotVariable.value;
console.log("Netlist :"+editorContent.value);
messages.innerHTML = "";
- socket.emit("netlist", netlist);
+ socket.emit("netlist",{"netlist":netlist,"plotOption":plotOption});
document.getElementById('plot').style.display = 'block';
});
|