diff options
author | fahim-oscad | 2016-03-22 17:17:53 +0530 |
---|---|---|
committer | fahim-oscad | 2016-03-22 17:17:53 +0530 |
commit | 09306d977713deba69879a3f35a025c018b74876 (patch) | |
tree | f25900cb65da380e41feaa68022b33e1c6cda029 /src/ngspicetoModelica/NgspicetoModelica.py | |
parent | 697ff38a5712f97a4ca5b81731d4bd3bf0bc69f6 (diff) | |
download | eSim-09306d977713deba69879a3f35a025c018b74876.tar.gz eSim-09306d977713deba69879a3f35a025c018b74876.tar.bz2 eSim-09306d977713deba69879a3f35a025c018b74876.zip |
write getUnitVal function to fetch the proper unit value for modelica
Diffstat (limited to 'src/ngspicetoModelica/NgspicetoModelica.py')
-rw-r--r-- | src/ngspicetoModelica/NgspicetoModelica.py | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index 582e8796..61843c25 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -1,11 +1,17 @@ import sys import os import re +import json from string import maketrans class NgMoConverter: + ifMOS = False + def __init__(self): - pass + #Loading JSON file which hold the mapping information between ngspice and Modelica. + with open('Mapping.json') as mappingFile: + self.mappingData = json.load(mappingFile) + def readNetlist(self,filename): """ @@ -43,6 +49,10 @@ class NgMoConverter: optionInfo.append(eachline) ##No need of making it lower case as netlist is already converted to ngspice #optionInfo.append(eachline.lower()) + elif eachline[0]=='m': + ifMOS = True + print "Mos is present ",ifMOS + schematicInfo.append(eachline) else: schematicInfo.append(eachline) ##No need of making it lower case as netlist is already converted to ngspice @@ -203,6 +213,24 @@ class NgMoConverter: value = val return value + def getUnitVal(self,compValue): + print "Received compValue--------> ",compValue + regExp = re.compile("([0-9]+)([a-zA-Z]+)") + matchString = regExp.match(str(compValue)) #separating number and string + try: + numValue = matchString.group(1) + unitValue = matchString.group(2) + #print "Num Value---------->",numValue + #print "Unit Value------->",unitValue + #print "Converted Unit ------->",self.mappingData["Units"][unitValue] + modifiedcompValue = numValue+self.mappingData["Units"][unitValue] + return modifiedcompValue + except: + return compValue + + def getModelicaComponent(self): + print "Get Modelica Component" + def compInit(self,compInfo, node, modelInfo, subcktName): """ For each component in the netlist initialize it according to Modelica format @@ -233,6 +261,7 @@ class NgMoConverter: words = eachline.split() val = words[3] value = self.splitIntoVal(val) + _value = self.getUnitVal(words[-1]) if eachline[0] == 'r': stat = 'Analog.Basic.Resistor ' + words[0] + '(R = ' + value + ');' modelicaCompInit.append(stat) |