Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ export default function SimulationProperties (props) {
if (typeSimulation !== 'noiseAnalysis') {
controlBlock = `\n.control \nrun \nprint ${cblockline} > data.txt \n.endc \n.end`
} else {
controlBlock = `\n.control \nrun \n${noiseMode} \nprint ${cblockline} > data.txt \n.endc \n.end`
controlBlock = `\n.control \nrun \n${noiseMode}\nprint all > data.txt \n.endc \n.end`
}
// console.log(controlLine)

Expand Down
35 changes: 12 additions & 23 deletions esim-cloud-backend/simulationAPI/helpers/parse.py
Original file line number Diff line number Diff line change
@@ -1,80 +1,69 @@
import re
import sys

NGSPICE_INTERNAL_VARS = {
'false', 'true', 'boltz', 'c', 'pi', 'kelvin', 'e',
'echarge', 'i', 'infinity', 'nan', 'no', 'yes', 'planck'
}

def extract_data_from_ngspice_output(pathToFile):
""" Parses the output file generated by ngspice and
returns a json containing points to plot graph.
"""

try:
with open(pathToFile, 'r') as f:
f_contents = f.readlines()
graph = False

curernt_headers = []
total_number_of_tables = 0
if(len(f_contents) > 3):
if('---' in f_contents[2]):
graph = True

if(not graph):
json_data = {"data": [], "graph": "false"}
for line in f_contents:
contents_of_line = line.split()
if len(contents_of_line) >= 1:
var_name = contents_of_line[0].lower().rstrip('=').split('(')[-1].rstrip(')')
if var_name in NGSPICE_INTERNAL_VARS:
continue
json_data["data"].append(contents_of_line)

else:
json_data = {"data": [], "graph": "true"}
for line in f_contents:
contents_of_line = line.split()

if len(contents_of_line) >= 1:
var_name = contents_of_line[0].lower().rstrip('=').split('(')[-1].rstrip(')')
if var_name in NGSPICE_INTERNAL_VARS:
continue
if('Index' in contents_of_line):
# line_set = remove_duplicate_items_from_list(
# contents_of_line)
line_set = contents_of_line

if(line_set != curernt_headers):
curernt_headers = line_set
json_data["data"].append(
{"labels": [], "x": [], "y": []})
index = len(json_data["data"]) - 1
for x in range(2, len(curernt_headers)):
json_data["data"][index]["y"].append([])

for x in range(1, len(curernt_headers)):
json_data["data"][index]["labels"].append(
curernt_headers[x])
total_number_of_tables += 1

else:
m = re.match('[0-9]+', line)
if(m):
index = len(json_data["data"]) - 1
data = json_data["data"][index]
data["x"].append(contents_of_line[1])

for x in range(len(data["y"])):
data["y"][x].append(contents_of_line[x+2])
json_data["total_number_of_tables"] = total_number_of_tables -\
len(json_data["data"])
return json_data

except IOError as e:
print('Cannot Open File')
raise e


# def remove_duplicate_items_from_list(line_list):
# res = []
# for i in line_list:
# if i not in res:
# res.append(i)
# return res


# for testing provide the filepath as command line argument
if __name__ == "__main__":

filePath = sys.argv[1]
print(extract_data_from_ngspice_output(filePath))