import sys import os.path from PyQt4 import QtGui,QtCore from PyQt4.QtGui import * from random import choice class NewWindow(QtGui.QWidget): def __init__(self): QWidget.__init__(self) self.horizontalLayout = QtGui.QVBoxLayout(self) self.scrollArea = QtGui.QScrollArea(self) self.scrollArea.setWidgetResizable(True) self.scrollAreaWidgetContents = QtGui.QWidget() self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 100, 100)) self.horizontalLayout_2 = QtGui.QHBoxLayout(self.scrollAreaWidgetContents) self.grid = QtGui.QGridLayout() self.horizontalLayout_2.addLayout(self.grid) self.scrollArea.setWidget(self.scrollAreaWidgetContents) self.SubmitButton = QtGui.QPushButton("Submit and Exit") self.ClearButton= QtGui.QPushButton("Clear Button") self.BackButton= QtGui.QPushButton("Back Button") self.horizontalLayout.addWidget(self.scrollArea) self.horizontalLayout.addWidget(self.BackButton) self.horizontalLayout.addWidget(self.ClearButton) self.horizontalLayout.addWidget(self.SubmitButton) self.SubmitButton.clicked.connect(self.Submit) self.ClearButton.clicked.connect(self.ClearModelParamValue) self.BackButton.clicked.connect(self.BackAgain) self.setGeometry(0,0,700, 400) self.center() def ClearModelParamValue(self): for line in guimodellisttrack: #print "line",line start=line[5] end=line[6] count=start for item in range(end-start+1): nextentry_var[count].setText("") count=count+1 def BackAgain(self): firstwindow=1 w.show() nw.close() def Submit(self): try: AddModelParametr() #Adding Model Parameter for item in modelparamvalue: schematicInfo.append(item[2]) #Adding Comment line schematicInfo.append(item[1]) #Adding Model line print "Successfully Closed" #print "SchematicInfo" #print SchematicInfo self.close() except: QMessageBox.about(self,"Exception","Please Add before Submit") create_ngspice_netlist() def center(self): qr=self.frameGeometry() cp = QtGui.QDesktopWidget().availableGeometry().center() qr.moveCenter(cp) self.move(qr.topLeft()) class Window(QtGui.QWidget): def __init__(self): super(Window,self).__init__() def createrootwindow(self,sourcelist,sourcelisttrack): self.backClicked=0 global nextrow self.nextrow=0 self.horizontalLayout = QtGui.QVBoxLayout(self) self.scrollArea = QtGui.QScrollArea(self) self.scrollArea.setWidgetResizable(True) self.scrollAreaWidgetContents = QtGui.QWidget() self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 100, 100)) self.horizontalLayout_2 = QtGui.QHBoxLayout(self.scrollAreaWidgetContents) self.grid = QtGui.QGridLayout() self.horizontalLayout_2.addLayout(self.grid) self.scrollArea.setWidget(self.scrollAreaWidgetContents) self.Nextbutton = QtGui.QPushButton("Next Button") self.Clearbutton= QtGui.QPushButton("Clear Button") self.horizontalLayout.addWidget(self.scrollArea) self.horizontalLayout.addWidget(self.Nextbutton) self.horizontalLayout.addWidget(self.Clearbutton) self.setGeometry(0,0,700, 400) self.show() self.Nextbutton.clicked.connect(self.NextPage) self.Clearbutton.clicked.connect(self.ClearSourceValue) self.center() global count global start global end count=1 global row row=0 global entry_var entry_var={} if sourcelist: for line in sourcelist: #print "Voltage source line index: ",line[0] #print "SourceList line Test: ",line track_id=line[0] print "track_id is ",track_id if line[2]=='ac': label=QLabel(line[3]) self.grid.addWidget(label,row,1) row=row+1 start=count label=QLabel(line[4]) self.grid.addWidget(label,row,0) entry_var[count]=QLineEdit() self.grid.addWidget(entry_var[count],row,1) value=present_already(line[1],line[2]) if value == 0: entry_var[count].setText("") else: entry_var[count].setText(store_ans) row=row+1 end=count count=count+1 sourcelisttrack.append([track_id,'ac',start,end]) elif line[2]=='dc': label=QLabel(line[3]) self.grid.addWidget(label,row,1) row=row+1 start=count label=QLabel(line[4]) self.grid.addWidget(label,row,0) entry_var[count]=QLineEdit() self.grid.addWidget(entry_var[count],row,1) value=present_already(line[1],line[2]) if value == 0: entry_var[count].setText("") else: entry_var[count].setText(store_ans) row=row+1 end=count count=count+1 sourcelisttrack.append([track_id,'dc',start,end]) elif line[2]=='sine': label=QLabel(line[3]) self.grid.addWidget(label,row,1) row=row+1 start=count value=present_already(line[1],line[2]) indi=0 for it in range(4,9): label=QLabel(line[it]) self.grid.addWidget(label,row,0) entry_var[count]=QLineEdit() self.grid.addWidget(entry_var[count],row,1) if value !=0: store_ans_list=store_ans.split() ans_list_size=len(store_ans_list) if value==0 or indi >= ans_list_size : entry_var[count].setText("") else: entry_var[count].setText(str(store_ans_list[indi])) indi=indi+1 row=row+1 count=count+1 end=count-1 sourcelisttrack.append([track_id,'sine',start,end]) elif line[2]=='pulse': label=QLabel(line[3]) self.grid.addWidget(label,row,1) row=row+1 start=count value=present_already(line[1],line[2]) indi=0; for it in range(4,11): label=QLabel(line[it]) self.grid.addWidget(label,row,0) entry_var[count]=QLineEdit() self.grid.addWidget(entry_var[count],row,1) if value!=0: store_ans_list=store_ans.split() ans_list_size=len(store_ans_list) if value==0 or indi >= ans_list_size: entry_var[count].setText("") else: entry_var[count].setText(str(store_ans_list[indi])) indi=indi+1 row=row+1 count=count+1 end=count-1 sourcelisttrack.append([track_id,'pulse',start,end]) elif line[2]=='pwl': label=QLabel(line[3]) self.grid.addWidget(label,row,1) row=row+1 start=count label=QLabel(line[4]) self.grid.addWidget(label,row,0) entry_var[count]=QLineEdit() self.grid.addWidget(entry_var[count],row,1) value=present_already(line[1],line[2]) if value==0: entry_var[count].setText(""); else: entry_var[count].setText(str(store_ans)) row=row+1 end=count count=count+1 sourcelisttrack.append([track_id,'pwl',start,end]) elif line[2]=='exp': label=QLabel(line[3]) self.grid.addWidget(label,row,1) row=row+1 start=count indi=0 value=present_already(line[1],line[2]) for it in range(4,10): label=QLabel(line[it]) self.grid.addWidget(label,row,0) entry_var[count]=QLineEdit() self.grid.addWidget(entry_var[count],row,1) if value != 0: store_ans_list=store_ans.split() ans_list_size=len(store_ans_list) if value == 0 or indi >= ans_list_size: entry_var[count].setText("") else: entry_var[count].setText(str(store_ans_list[indi])) indi=indi+1 row=row+1 count=count+1 end=count-1 sourcelisttrack.append([track_id,'exp',start,end]) count=count+1 #print "startcount ",start #print "endcount ",end else: print "No source is present in your circuit" return sourcelist,sourcelisttrack def closeEvent(self,event): print "window closed" def NextPage(self): #print "next page" AddSourceValue() w.close() nw.show() firstwindow=0 self.backClicked+=1 global schematicInfo global outputOption global guimodelvalue global guimodellisttrack global guimodellist if self.backClicked==1: guimodelvalue=[] outputOption=[] #check whether it affects the working guimodellisttrack=[] guimodellist=['adc8','dac8','gain','summer','multiplier','divider','limit','integrator','differentiator','limit8','controlledlimiter', 'analogswitch','zener','d_buffer','d_inverter','d_and','d_nand','d_or','d_nor','d_xor','d_xnor','d_tristate','d_pullup', 'd_pulldown','d_srlatch','d_jklatch','d_dlatch','d_tlatch','d_srff','d_jkff','d_dff','ic','transfo'] ##Calling function which take information for entry and label if self.backClicked==1: schematicInfo,outputOption,guimodelvalue=convertICintoBasicBlocks(schematicInfo,outputOption,guimodelvalue) #print "Info is",schematicInfo #print "outoption is",outputOption #print "guivalue is",guimodelvalue global nextcount nextcount=0 global nextentry_var if self.backClicked ==1: nextentry_var={} ##Checking if any model is present if guimodelvalue: ## Calling Next frame generation function for line in guimodelvalue: print "line is ",line if line[2] in guimodellist: #print "ConvertICBlock index :",line[0] if self.backClicked==1: nextcount=self.nextframegeneration(line,nextentry_var,nextcount) else: print "Please look whether model is added in guimodellist inside code" else: print "There is no model in your circuit" QMessageBox.about(self,"Model information","There is no model in your circuit") #AddModelParametr() # tkMessageBox.showinfo("Model List Info","There is no model in your circuit, please click on Submit & Exit Button" ) def nextframegeneration(self,line,nextentry_var,nextcount): print "Model Line in netlist is : ",line[1] div=line[1].split() #flag=present_already_model(div[0],line[2]) flag=0 #print "store ans here",stored_ans store_ans_list=[] if flag!=0: store_ans_list=stored_ans.split() print "list ",store_ans_list indi=0 label=QLabel(line[5]) nw.grid.addWidget(label,self.nextrow,1) start=nextcount self.nextrow=self.nextrow+1 if line[2]=='ic': for item in range(len(line)-7): label=QLabel(line[7+item]) nw.grid.addWidget(label,self.nextrow,0) nextentry_var[nextcount]=QLineEdit() nw.grid.addWidget(nextentry_var[nextcount],self.nextrow,1) nextcount=nextcount+1 self.nextrow=self.nextrow+1 end=nextcount-1 guimodellisttrack.append([line[0],line[1],line[2],line[3],line[4],start,end,line[6]]) else: for item in range(len(line)-6): label=QLabel(line[6+item]) nw.grid.addWidget(label,self.nextrow,0) nextentry_var[nextcount]=QLineEdit() nw.grid.addWidget(nextentry_var[nextcount],self.nextrow,1) if indi < len(store_ans_list) and flag ==1: nextentry_var[nextcount].setText(store_ans_list[indi]) indi=indi+1 nextcount=nextcount+1 self.nextrow=self.nextrow+1 end=nextcount-1 guimodellisttrack.append([line[0],line[1],line[2],line[3],line[4],start,end]) return nextcount def ClearSourceValue(self): #print "Clear Source Value" for line in sourcelisttrack: start=line[2] end=line[3] count=start for item in range(int(end-start+1)): entry_var[count].setText("") count=count+1 def center(self): qr=self.frameGeometry() cp = QtGui.QDesktopWidget().availableGeometry().center() qr.moveCenter(cp) self.move(qr.topLeft()) '''def present_already_model(val,model_name): global stored_ans print "model name is ", model_name if os.path.exists(last_input_file): last_file=open(last_input_file) else: last_file=open(last_input_file,'w+') stored_val=last_file.read().strip().split('\n') print "model test val ",val flag=0 for line in stored_val: word=line.split() if len(word)==0: continue if word[0]=='.model': print "word is ",word," len is ",len(word) if word[1]==val: if ((word[2].startswith(model_name))): stored_ans="" for tmp in range(2,len(word)-1): try: ind=word[tmp].index('=')+1 stored_ans=stored_ans+word[tmp][ind:]+" " except: print "Exception" store_ans.strip() print "model ans ",stored_ans flag=1 break last_file.close() return flag ''' def present_already(vol,inpscr): words=vol.split() volsrc=words[0] global store_ans if os.path.exists(last_input_file): last_file=open(last_input_file) else: last_file=open(last_input_file,'w+') stored_val=last_file.read().strip().split('\n') flag=0 for line in stored_val: word=line.split() if len(word)==0: continue; if word[0] == volsrc : if ((inpscr == 'ac' and inpscr == word[3]) or (inpscr == 'dc' and inpscr==word[3]) ): if len(word)>4: store_ans=word[4] flag=1 break if ((inpscr == 'pwl' and word[3].startswith(inpscr)) or (inpscr=='exp' and word[3].startswith(inpscr)) or (inpscr=='pulse' and word[3].startswith(inpscr)) or (inpscr=='sine' and word[3].startswith(inpscr)) ): store_ans="" i=word[3].index('(')+1 j=word[len(word)-1].index(')') store_ans=word[3][i:]+" " for num in range(4,len(word)-1): store_ans=store_ans+word[num]+" " store_ans=store_ans+word[len(word)-1][:j] print store_ans flag=1 break last_file.close() return flag; def AddModelParametr(): #print "models here" #print "Adding Model Parameter" #print "GuiModelValue",guimodelvalue global guimodellisttrack global modelparamvalue global addmodelline modelparamvalue=[] addmodelline=[] for line in guimodellisttrack: #print "model",line if line[2]=='transfo': try: #print "here in transfo" start=line[5] end=line[6] num_turns=str(nextentry_var[start].text()) if num_turns=="": num_turns="310" h_array= "H_array = [ " b_array = "B_array = [ " h1=str(nextentry_var[start+1].text()) b1=str(nextentry_var[start+2].text()) if len(h1)!=0 and len(b1)!=0: h_array=h_array+h1+" " b_array=b_array+b1+" " bh_array = h_array+" ] " + b_array+" ]" else: bh_array = "H_array = [-1000 -500 -375 -250 -188 -125 -63 0 63 125 188 250 375 500 1000] B_array = [-3.13e-3 -2.63e-3 -2.33e-3 -1.93e-3 -1.5e-3 -6.25e-4 -2.5e-4 0 2.5e-4 6.25e-4 1.5e-3 1.93e-3 2.33e-3 2.63e-3 3.13e-3]" area=str(nextentry_var[start+3].text()) length=str(nextentry_var[start+4].text()) if area=="": area="1" if length=="":length="0.01" num_turns2=str(nextentry_var[start+5].text()) if num_turns2=="": num_turns2="620" addmodelline=".model "+line[3]+"_primary lcouple (num_turns= "+num_turns+")" modelparamvalue.append([line[0],addmodelline,line[4]]) addmodelline=".model "+line[3]+"_iron_core core ("+bh_array+" area = "+area+" length ="+length +")" modelparamvalue.append([line[0],addmodelline,line[4]]) addmodelline=".model "+line[3]+"_secondary lcouple (num_turns ="+num_turns2+ ")" modelparamvalue.append([line[0],addmodelline,line[4]]) except: print "Caught an exception in transfo model ",line[1] elif line[2]=='adc8': try: start=line[5] end=line[6] in_low=str(nextentry_var[start].text()) in_high=str(nextentry_var[end].text()) if in_low=="": in_low="0.8" if in_high=="": in_high="2.0" addmodelline=".model "+ line[3]+" adc_bridge(in_low="+in_low+" in_high="+in_high+" )" modelparamvalue.append([line[0],addmodelline,line[4]]) except: print "Caught an exception in adc8 model ",line[1] elif line[2]=='dac8': try: start=line[5] end=line[6] out_low=str(nextentry_var[start].text()) out_high=str(nextentry_var[start+1].text()) out_undef=str(nextentry_var[end].text()) if out_low=="": out_low="0.2" if out_high=="": out_high="5.0" if out_undef=="": out_undef="5.0" addmodelline=".model "+ line[3]+" dac_bridge(out_low="+out_low+" out_high="+out_high+" out_undef="+out_undef+" )" modelparamvalue.append([line[0],addmodelline,line[4]]) except: print "Caught an exception in dac8 model ",line[1] elif line[2]=='gain': try: start=line[5] end=line[6] in_offset=str(nextentry_var[start].text()) gain=str(nextentry_var[start+1].text()) out_offset=str(nextentry_var[end].text()) if in_offset=="": in_offset="0.0" if gain=="": gain="1.0" if out_offset=="": out_offset="0.0" addmodelline=".model "+ line[3]+" gain(in_offset="+in_offset+" out_offset="+out_offset+" gain="+gain+" )" modelparamvalue.append([line[0],addmodelline,line[4]]) except: print "Caught an exception in gain model ",line[1] elif line[2]=='summer': try: start=line[5] end=line[6] in1_offset=str(nextentry_var[start].text()) in2_offset=str(nextentry_var[start+1].text()) in1_gain=str(nextentry_var[start+2].text()) in2_gain=str(nextentry_var[start+3].text()) out_gain=str(nextentry_var[start+4].text()) out_offset=str(nextentry_var[end].text()) if in1_offset=="": in1_offset="0.0" if in2_offset=="": in2_offset="0.0" if in1_gain=="": in1_gain="1.0" if in2_gain=="": in2_gain="1.0" if out_gain=="": out_gain="1.0" if out_offset=="": out_offset="0.0" addmodelline=".model "+ line[3]+" summer(in_offset=["+in1_offset+" "+in2_offset+"] in_gain=["+in1_gain+" "+in2_gain+"] out_offset="+out_offset+" out_gain="+out_gain+" )" modelparamvalue.append([line[0],addmodelline,line[4]]) except: print "Caught an exception in summer model ",line[1] elif line[2]=='multiplier': try: start=line[5] end=line[6] in1_offset=str(nextentry_var[start].text()) in2_offset=str(nextentry_var[start+1].text()) in1_gain=str(nextentry_var[start+2].text()) in2_gain=str(nextentry_var[start+3].text()) out_gain=str(nextentry_var[start+4].text()) out_offset=str(nextentry_var[end].text()) if in1_offset=="": in1_offset="0.0" if in2_offset=="": in2_offset="0.0" if in1_gain=="": in1_gain="1.0" if in2_gain=="": in2_gain="1.0" if out_gain=="": out_gain="1.0" if out_offset=="": out_offset="0.0" addmodelline=".model "+ line[3]+" mult(in_offset=["+in1_offset+" "+in2_offset+"] in_gain=["+in1_gain+" "+in2_gain+"] out_offset="+out_offset+" out_gain="+out_gain+" )" modelparamvalue.append([line[0],addmodelline,line[4]]) except: print "Caught an exception in multiplier model ",line[1] elif line[2]=='divider': try: start=line[5] end=line[6] num_offset=str(nextentry_var[start].text()) den_offset=str(nextentry_var[start+1].text()) num_gain=str(nextentry_var[start+2].text()) den_gain=str(nextentry_var[start+3].text()) out_gain=str(nextentry_var[start+4].text()) out_offset=str(nextentry_var[start+5].text()) den_lower_limit=str(nextentry_var[end].text()) if num_offset=="": num_offset="0.0" if den_offset=="": den_offset="0.0" if num_gain=="": num_gain="1.0" if den_gain=="": den_gain="1.0" if out_gain=="": out_gain="1.0" if out_offset=="": out_offset="0.0" if den_lower_limit=="": den_lower_limit="1.0e-10" addmodelline=".model "+ line[3]+" divide(num_offset="+num_offset+" den_offset="+den_offset+" num_gain="+num_gain+" den_gain="+den_gain+" out_offset="+out_offset+" out_gain="+out_gain+" den_lower_limit="+den_lower_limit+" )" modelparamvalue.append([line[0],addmodelline,line[4]]) except: print "Caught an exception in divider model ",line[1] elif line[2]=='limit': try: start=line[5] end=line[6] lowerLimit=str(nextentry_var[start].text()) upperLimit=str(nextentry_var[start+1].text()) in_offset=str(nextentry_var[start+2].text()) gain=str(nextentry_var[end].text()) if lowerLimit=="": lowerLimit="0.0" if upperLimit=="": upperLimit="5.0" if in_offset=="": in_offset="0.0" if gain=="": gain="1.0" addmodelline=".model "+ line[3]+" limit(out_lower_limit="+lowerLimit+" out_upper_limit="+upperLimit+" in_offset="+in_offset+" gain="+gain+" )" modelparamvalue.append([line[0],addmodelline,line[4]]) except: print "Caught an exception in limit model ",line[1] elif line[2]=='integrator': try: start=line[5] end=line[6] out_lower_limit=str(nextentry_var[start].text()) out_upper_limit=str(nextentry_var[start+1].text()) in_offset=str(nextentry_var[start+2].text()) gain=str(nextentry_var[start+3].text()) out_ic=str(nextentry_var[end].text()) if out_lower_limit=="": out_lower_limit="0.0" if out_upper_limit=="": out_upper_limit="5.0" if in_offset=="": in_offset="0.0" if gain=="": gain="1.0" if out_ic=="": out_ic="0.0" addmodelline=".model "+ line[3]+" int(out_lower_limit="+out_lower_limit+" out_upper_limit="+out_upper_limit+" in_offset="+in_offset+" gain="+gain+" out_ic="+out_ic+" )" modelparamvalue.append([line[0],addmodelline,line[4]]) except: print "Caught an exception in integrator model ",line[1] elif line[2]=='differentiator': try: start=line[5] end=line[6] out_lower_limit=str(nextentry_var[start].text()) out_upper_limit=str(nextentry_var[start+1].text()) out_offset=str(nextentry_var[start+2].text()) gain=str(nextentry_var[end].text()) if out_lower_limit=="": out_lower_limit="0.0" if out_upper_limit=="": out_upper_limit="5.0" if out_offset=="": out_offset="0.0" if gain=="": gain="1.0" addmodelline=".model "+ line[3]+" d_dt(out_lower_limit="+out_lower_limit+" out_upper_limit="+out_upper_limit+" out_offset="+out_offset+" gain="+gain+" )" modelparamvalue.append([line[0],addmodelline,line[4]]) except: print "Caught an exception in differentiator model ",line[1] elif line[2]=='limit8': try: start=line[5] end=line[6] lowerLimit=str(nextentry_var[start].text()) upperLimit=str(nextentry_var[start+1].text()) in_offset=str(nextentry_var[start+2].text()) gain=str(nextentry_var[end].text()) if lowerLimit=="": lowerLimit="0.0" if upperLimit=="": upperLimit="5.0" if in_offset=="": in_offset="0.0" if gain=="": gain="1.0" addmodelline=".model "+ line[3]+" limit(out_lower_limit="+lowerLimit+" out_upper_limit="+upperLimit+" in_offset="+in_offset+" gain="+gain+" )" modelparamvalue.append([line[0],addmodelline,line[4]]) except: print "Caught an exception in limit8 model ",line[1] elif line[2]=='controlledlimiter': try: start=line[5] end=line[6] in_offset=str(nextentry_var[start].text()) gain=str(nextentry_var[end].text()) if in_offset=="": in_offset="0.0" if gain=="": gain="1.0" addmodelline=".model "+ line[3]+" climit(in_offset="+in_offset+" gain="+gain+")" modelparamvalue.append([line[0],addmodelline,line[4]]) except: print "Caught an exception in controlledlimiter model ",line[1] elif line[2]=='analogswitch': try: start=line[5] end=line[6] cntl_on=str(nextentry_var[start].text()) cntl_off=str(nextentry_var[start+1].text()) r_on=str(nextentry_var[start+2].text()) r_off=str(nextentry_var[end].text()) if cntl_on=="": cntl_on="5.0" if cntl_off=="": cntl_off="0.0" if r_on=="": r_on="10.0" if r_off=="": r_off="1e6" addmodelline=".model "+ line[3]+" aswitch(cntl_on="+cntl_on+" cntl_off="+cntl_off+" r_on="+r_on+" r_off="+r_off+" )" modelparamvalue.append([line[0],addmodelline,line[4]]) except: print "Caught an exception in analogswitch model ",line[1] elif line[2]=='zener': try: start=line[5] end=line[6] v_breakdown=str(nextentry_var[start].text()) i_breakdown=str(nextentry_var[start+1].text()) i_sat=str(nextentry_var[start+2].text()) n_forward=str(nextentry_var[end].text()) if v_breakdown=="": v_breakdown="5.6" if i_breakdown=="": i_breakdown="1.0e-2" if i_sat=="": i_sat="1.0e-12" if n_forward=="": n_forward="1.0" addmodelline=".model "+ line[3]+" zener(v_breakdown="+v_breakdown+" i_breakdown="+i_breakdown+" i_sat="+i_sat+" n_forward="+n_forward+" )" modelparamvalue.append([line[0],addmodelline,line[4]]) except: print "Caught an exception in zener model ",line[1] elif line[2]=='d_buffer': try: start=line[5] end=line[6] rise_delay=str(nextentry_var[start].text()) fall_delay=str(nextentry_var[start+1].text()) input_load=str(nextentry_var[end].text()) if rise_delay=="": rise_delay="1e-12" if fall_delay=="": fall_delay="1e-12" if input_load=="": input_load="1e-12" addmodelline=".model "+ line[3]+" d_buffer(rise_delay="+rise_delay+" fall_delay="+fall_delay+" input_load="+input_load+" )" modelparamvalue.append([line[0],addmodelline,line[4]]) except: print "Caught an exception in d_buffer model ",line[1] elif line[2]=='d_inverter': try: start=line[5] end=line[6] rise_delay=str(nextentry_var[start].text()) fall_delay=str(nextentry_var[start+1].text()) input_load=str(nextentry_var[end].text()) if rise_delay=="": rise_delay="1e-12" if fall_delay=="": fall_delay="1e-12" if input_load=="": input_load="1e-12" addmodelline=".model "+ line[3]+" d_inverter(rise_delay="+rise_delay+" fall_delay="+fall_delay+" input_load="+input_load+" )" modelparamvalue.append([line[0],addmodelline,line[4]]) except: print "Caught an exception in d_inverter model ",line[1] elif line[2]=='d_and': try: start=line[5] end=line[6] rise_delay=str(nextentry_var[start].text()) fall_delay=str(nextentry_var[start+1].text()) input_load=str(nextentry_var[end].text()) if rise_delay=="": rise_delay="1e-12" if fall_delay=="": fall_delay="1e-12" if input_load=="": input_load="1e-12" addmodelline=".model "+ line[3]+" d_and(rise_delay="+rise_delay+" fall_delay="+fall_delay+" input_load="+input_load+" )" modelparamvalue.append([line[0],addmodelline,line[4]]) except: print "Caught an exception in d_and model ",line[1] elif line[2]=='d_nand': try: start=line[5] end=line[6] rise_delay=str(nextentry_var[start].text()) fall_delay=str(nextentry_var[start+1].text()) input_load=str(nextentry_var[end].text()) if rise_delay=="": rise_delay="1e-12" if fall_delay=="": fall_delay="1e-12" if input_load=="": input_load="1e-12" addmodelline=".model "+ line[3]+" d_nand(rise_delay="+rise_delay+" fall_delay="+fall_delay+" input_load="+input_load+" )" modelparamvalue.append([line[0],addmodelline,line[4]]) except: print "Caught an exception in d_nand model ",line[1] elif line[2]=='d_or': try: start=line[5] end=line[6] rise_delay=str(nextentry_var[start].text()) fall_delay=str(nextentry_var[start+1].text()) input_load=str(nextentry_var[end].text()) if rise_delay=="": rise_delay="1e-12" if fall_delay=="": fall_delay="1e-12" if input_load=="": input_load="1e-12" addmodelline=".model "+ line[3]+" d_or(rise_delay="+rise_delay+" fall_delay="+fall_delay+" input_load="+input_load+" )" modelparamvalue.append([line[0],addmodelline,line[4]]) except: print "Caught an exception in d_or model ",line[1] elif line[2]=='d_nor': try: start=line[5] end=line[6] rise_delay=str(nextentry_var[start].text()) fall_delay=str(nextentry_var[start+1].text()) input_load=str(nextentry_var[end].text()) if rise_delay=="": rise_delay="1e-12" if fall_delay=="": fall_delay="1e-12" if input_load=="": input_load="1e-12" addmodelline=".model "+ line[3]+" d_nor(rise_delay="+rise_delay+" fall_delay="+fall_delay+" input_load="+input_load+" )" modelparamvalue.append([line[0],addmodelline,line[4]]) except: print "Caught an exception in d_nor model ",line[1] elif line[2]=='d_xor': try: start=line[5] end=line[6] rise_delay=str(nextentry_var[start].text()) fall_delay=str(nextentry_var[start+1].text()) input_load=str(nextentry_var[end].text()) if rise_delay=="": rise_delay="1e-12" if fall_delay=="": fall_delay="1e-12" if input_load=="": input_load="1e-12" addmodelline=".model "+ line[3]+" d_xor(rise_delay="+rise_delay+" fall_delay="+fall_delay+" input_load="+input_load+" )" modelparamvalue.append([line[0],addmodelline,line[4]]) except: print "Caught an exception in d_xor model ",line[1] elif line[2]=='d_xnor': try: start=line[5] end=line[6] rise_delay=str(nextentry_var[start].text()) fall_delay=str(nextentry_var[start+1].text()) input_load=str(nextentry_var[end].text()) if rise_delay=="": rise_delay="1e-12" if fall_delay=="": fall_delay="1e-12" if input_load=="": input_load="1e-12" addmodelline=".model "+ line[3]+" d_xnor(rise_delay="+rise_delay+" fall_delay="+fall_delay+" input_load="+input_load+" )" modelparamvalue.append([line[0],addmodelline,line[4]]) except: print "Caught an exception in d_xnor model ",line[1] elif line[2]=='d_tristate': try: start=line[5] end=line[6] delay=str(nextentry_var[start].text()) input_load=str(nextentry_var[start+1].text()) enable_load=str(nextentry_var[end].text()) if delay=="": delay="1e-12" if input_load=="": input_load="1e-12" if enable_load=="": enable_load="1e-12" addmodelline=".model "+ line[3]+" d_tristate(delay="+delay+" enable_load="+enable_load+" input_load="+input_load+" )" modelparamvalue.append([line[0],addmodelline,line[4]]) except: print "Caught an exception in d_tristate model ",line[1] elif line[2]=='d_pullup': try: start=line[5] end=line[6] load=str(nextentry_var[start].text()) if load=="": load="1e-12" addmodelline=".model "+ line[3]+" d_pullup(load="+load+" )" modelparamvalue.append([line[0],addmodelline,line[4]]) except: print "Caught an exception in d_pullup model ",line[1] elif line[2]=='d_pulldown': try: start=line[5] end=line[6] load=str(nextentry_var[start].text()) if load=="": load="1e-12" addmodelline=".model "+ line[3]+" d_pulldown(load="+load+" )" modelparamvalue.append([line[0],addmodelline,line[4]]) except: print "Caught an exception in d_pulldown model ",line[1] elif line[2]=='d_srlatch': try: start=line[5] end=line[6] sr_delay=str(nextentry_var[start].text()) enable_delay=str(nextentry_var[start+1].text()) set_delay=str(nextentry_var[start+2].text()) reset_delay=str(nextentry_var[start+3].text()) ic=str(nextentry_var[start+4].text()) sr_load=str(nextentry_var[start+5].text()) enable_load=str(nextentry_var[start+6].text()) set_load=str(nextentry_var[start+7].text()) reset_load=str(nextentry_var[start+8].text()) rise_delay=str(nextentry_var[start+9].text()) fall_delay=str(nextentry_var[end].text()) if sr_delay=="": sr_delay="1e-12" if enable_delay=="": enable_delay="1e-12" if set_delay=="": set_delay="1e-12" if reset_delay=="": reset_delay="1e-12" if ic=="": ic="0" if sr_load=="": sr_load="1e-12" if enable_load=="": enable_load="1e-12" if set_load=="": set_load="1e-12" if reset_load=="": reset_load="1e-12" if rise_delay=="": rise_delay="1e-12" if fall_delay=="": fall_delay="1e-12" addmodelline=".model "+ line[3]+" d_srlatch(rise_delay="+rise_delay+" fall_delay="+fall_delay+" ic="+ic+"\n+sr_load="+sr_load+" enable_load="+enable_load+" set_load="+set_load+" reset_load="+reset_load+"\n+sr_delay="+sr_delay+" enable_delay="+enable_delay+" set_delay="+set_delay+" reset_delay="+reset_delay+" )" modelparamvalue.append([line[0],addmodelline,line[4]]) except: print "Caught an exception in d_srlatch model ",line[1] elif line[2]=='d_jklatch': try: start=line[5] end=line[6] jk_delay=str(nextentry_var[start].text()) enable_delay=str(nextentry_var[start+1].text()) set_delay=str(nextentry_var[start+2].text()) reset_delay=str(nextentry_var[start+3].text()) ic=str(nextentry_var[start+4].text()) jk_load=str(nextentry_var[start+5].text()) enable_load=str(nextentry_var[start+6].text()) set_load=str(nextentry_var[start+7].text()) reset_load=str(nextentry_var[start+8].text()) rise_delay=str(nextentry_var[start+9].text()) fall_delay=str(nextentry_var[end].text()) if jk_delay=="": jk_delay="1e-12" if enable_delay=="": enable_delay="1e-12" if set_delay=="": set_delay="1e-12" if reset_delay=="": reset_delay="1e-12" if ic=="": ic="0" if jk_load=="": jk_load="1e-12" if enable_load=="": enable_load="1e-12" if set_load=="": set_load="1e-12" if reset_load=="": reset_load="1e-12" if rise_delay=="": rise_delay="1e-12" if fall_delay=="": fall_delay="1e-12" addmodelline=".model "+ line[3]+" d_jklatch(rise_delay="+rise_delay+" fall_delay="+fall_delay+" ic="+ic+"\n+jk_load="+jk_load+" enable_load="+enable_load+" set_load="+set_load+" reset_load="+reset_load+"\n+jk_delay="+jk_delay+" enable_delay="+enable_delay+" set_delay="+set_delay+" reset_delay="+reset_delay+" )" modelparamvalue.append([line[0],addmodelline,line[4]]) except: print "Caught an exception in d_jklatch model ",line[1] elif line[2]=='d_dlatch': try: start=line[5] end=line[6] data_delay=str(nextentry_var[start].text()) enable_delay=str(nextentry_var[start+1].text()) set_delay=str(nextentry_var[start+2].text()) reset_delay=str(nextentry_var[start+3].text()) ic=str(nextentry_var[start+4].text()) data_load=str(nextentry_var[start+5].text()) enable_load=str(nextentry_var[start+6].text()) set_load=str(nextentry_var[start+7].text()) reset_load=str(nextentry_var[start+8].text()) rise_delay=str(nextentry_var[start+9].text()) fall_delay=str(nextentry_var[end].text()) if data_delay=="": data_delay="1e-12" if enable_delay=="": enable_delay="1e-12" if set_delay=="": set_delay="1e-12" if reset_delay=="": reset_delay="1e-12" if ic=="": ic="0" if data_load=="": data_load="1e-12" if enable_load=="": enable_load="1e-12" if set_load=="": set_load="1e-12" if reset_load=="": reset_load="1e-12" if rise_delay=="": rise_delay="1e-12" if fall_delay=="": fall_delay="1e-12" addmodelline=".model "+ line[3]+" d_dlatch(rise_delay="+rise_delay+" fall_delay="+fall_delay+" ic="+ic+"\n+data_load="+data_load+" enable_load="+enable_load+" set_load="+set_load+" reset_load="+reset_load+"\n+data_delay="+data_delay+" enable_delay="+enable_delay+" set_delay="+set_delay+" reset_delay="+reset_delay+" )" modelparamvalue.append([line[0],addmodelline,line[4]]) except: print "Caught an exception in d_dlatch model ",line[1] elif line[2]=='d_tlatch': try: start=line[5] end=line[6] t_delay=str(nextentry_var[start].text()) enable_delay=str(nextentry_var[start+1].text()) set_delay=str(nextentry_var[start+2].text()) reset_delay=str(nextentry_var[start+3].text()) ic=str(nextentry_var[start+4].text()) t_load=str(nextentry_var[start+5].text()) enable_load=str(nextentry_var[start+6].text()) set_load=str(nextentry_var[start+7].text()) reset_load=str(nextentry_var[start+8].text()) rise_delay=str(nextentry_var[start+9].text()) fall_delay=str(nextentry_var[end].text()) if t_delay=="": t_delay="1e-12" if enable_delay=="": enable_delay="1e-12" if set_delay=="": set_delay="1e-12" if reset_delay=="": reset_delay="1e-12" if ic=="": ic="0" if t_load=="": t_load="1e-12" if enable_load=="": enable_load="1e-12" if set_load=="": set_load="1e-12" if reset_load=="": reset_load="1e-12" if rise_delay=="": rise_delay="1e-12" if fall_delay=="": fall_delay="1e-12" addmodelline=".model "+ line[3]+" d_tlatch(rise_delay="+rise_delay+" fall_delay="+fall_delay+" ic="+ic+"\n+t_load="+t_load+" enable_load="+enable_load+" set_load="+set_load+" reset_load="+reset_load+"\n+t_delay="+t_delay+" enable_delay="+enable_delay+" set_delay="+set_delay+" reset_delay="+reset_delay+" )" modelparamvalue.append([line[0],addmodelline,line[4]]) except: print "Caught an exception in d_tlatch model ",line[1] elif line[2]=='d_srff': try: start=line[5] end=line[6] clk_delay=str(nextentry_var[start].text()) set_delay=str(nextentry_var[start].text()) reset_delay=str(nextentry_var[start].text()) ic=str(nextentry_var[start].text()) sr_load=str(nextentry_var[start].text()) clk_load=str(nextentry_var[start].text()) set_load=str(nextentry_var[start].text()) reset_load=str(nextentry_var[start].text()) rise_delay=str(nextentry_var[start].text()) fall_delay=str(nextentry_var[start].text()) if clk_delay=="": clk_delay="1e-12" if set_delay=="": set_delay="1e-12" if reset_delay=="": reset_delay="1e-12" if ic=="": ic="0" if sr_load=="": sr_load="1e-12" if clk_load=="": clk_load="1e-12" if set_load=="": set_load="1e-12" if reset_load=="": reset_load="1e-12" if rise_delay=="": rise_delay="1e-12" if fall_delay=="": fall_delay="1e-12" addmodelline=".model "+ line[3]+" d_srff(rise_delay="+rise_delay+" fall_delay="+fall_delay+" ic="+ic+"\n+sr_load="+sr_load+" clk_load="+clk_load+" set_load="+set_load+" reset_load="+reset_load+"\n+clk_delay="+clk_delay+" set_delay="+set_delay+" reset_delay="+reset_delay+" )" modelparamvalue.append([line[0],addmodelline,line[4]]) except: print "Caught an exception in d_srff model ",line[1] elif line[2]=='d_jkff': try: start=line[5] end=line[6] clk_delay=str(nextentry_var[start].text()) set_delay=str(nextentry_var[start].text()) reset_delay=str(nextentry_var[start].text()) ic=str(nextentry_var[start].text()) jk_load=str(nextentry_var[start].text()) clk_load=str(nextentry_var[start].text()) set_load=str(nextentry_var[start].text()) reset_load=str(nextentry_var[start].text()) rise_delay=str(nextentry_var[start].text()) fall_delay=str(nextentry_var[start].text()) if clk_delay=="": clk_delay="1e-12" if set_delay=="": set_delay="1e-12" if reset_delay=="": reset_delay="1e-12" if ic=="": ic="0" if jk_load=="": sr_load="1e-12" if clk_load=="": clk_load="1e-12" if set_load=="": set_load="1e-12" if reset_load=="": reset_load="1e-12" if rise_delay=="": rise_delay="1e-12" if fall_delay=="": fall_delay="1e-12" addmodelline=".model "+ line[3]+" d_jkff(rise_delay="+rise_delay+" fall_delay="+fall_delay+" ic="+ic+"\n+jk_load="+jk_load+" clk_load="+clk_load+" set_load="+set_load+" reset_load="+reset_load+"\n+clk_delay="+enable_delay+" set_delay="+set_delay+" reset_delay="+reset_delay+" )" modelparamvalue.append([line[0],addmodelline,line[4]]) except: print "Caught an exception in d_jkff model ",line[1] elif line[2]=='d_dff': try: start=line[5] end=line[6] clk_delay=str(nextentry_var[start].text()) set_delay=str(nextentry_var[start+1].text()) reset_delay=str(nextentry_var[start+2].text()) ic=str(nextentry_var[start+3].text()) data_load=str(nextentry_var[start+4].text()) clk_load=str(nextentry_var[start+5].text()) set_load=str(nextentry_var[start+6].text()) reset_load=str(nextentry_var[start+7].text()) rise_delay=str(nextentry_var[start+8].text()) fall_delay=str(nextentry_var[end].text()) if clk_delay=="": clk_delay="1e-12" if set_delay=="": set_delay="1e-12" if reset_delay=="": reset_delay="1e-12" if ic=="": ic="0" if data_load=="": data_load="1e-12" if clk_load=="": clk_load="1e-12" if set_load=="": set_load="1e-12" if reset_load=="": reset_load="1e-12" if rise_delay=="": rise_delay="1e-12" if fall_delay=="": fall_delay="1e-12" addmodelline=".model "+ line[3]+" d_dff(rise_delay="+rise_delay+" fall_delay="+fall_delay+" ic="+ic+"\n+data_load="+data_load+" clk_load="+clk_load+" set_load="+set_load+" reset_load="+reset_load+"\n+clk_delay="+clk_delay+" set_delay="+set_delay+" reset_delay="+reset_delay+" )" modelparamvalue.append([line[0],addmodelline,line[4]]) except: print "Caught an exception in d_dff model ",line[1] elif line[2]=='d_tff': try: start=line[5] end=line[6] clk_delay=str(nextentry_var[start].text()) set_delay=str(nextentry_var[start+1].text()) reset_delay=str(nextentry_var[start+2].text()) ic=str(nextentry_var[start+3].text()) t_load=str(nextentry_var[start+4].text()) clk_load=str(nextentry_var[start+5].text()) set_load=str(nextentry_var[start+6].text()) reset_load=str(nextentry_var[start+7].text()) rise_delay=str(nextentry_var[start+8].text()) fall_delay=str(nextentry_var[end].text()) if t_delay=="": t_delay="1e-12" if enable_delay=="": enable_delay="1e-12" if set_delay=="": set_delay="1e-12" if reset_delay=="": reset_delay="1e-12" if ic=="": ic="0" if t_load=="": t_load="1e-12" if enable_load=="": enable_load="1e-12" if set_load=="": set_load="1e-12" if reset_load=="": reset_load="1e-12" if rise_delay=="": rise_delay="1e-12" if fall_delay=="": fall_delay="1e-12" addmodelline=".model "+ line[3]+" d_tff(rise_delay="+rise_delay+" fall_delay="+fall_delay+" ic="+ic+"\n+t_load="+t_load+" clk_load="+clk_load+" set_load="+set_load+" reset_load="+reset_load+"\n+clk_delay="+clk_delay+" set_delay="+set_delay+" reset_delay="+reset_delay+" )" modelparamvalue.append([line[0],addmodelline,line[4]]) except: print "Caught an exception in d_tff model ",line[1] elif line[2]=='ic': try: start=line[5] end=line[6] ic=str(nextentry_var[start].text()) if ic=="": ic="0" addmodelline=".ic v("+line[7]+")="+ic modelparamvalue.append([line[0],addmodelline,line[4]]) except: print "Caught an exception in ic initial condition ",line[1] else: print "No model found" QMessageBox.about(self,"Model Information","Please check whether used model is available inside code") #tkMessageBox.showinfo("Model Info","Please check whether used model is available inside code") print "Model List has been added",modelparamvalue def AddSourceValue(): #print "Add Source Value" global sourcelistvalue sourcelistvalue=[] global start global end start=0 end=0 #print "Track Source List :",sourcelisttrack #print "Initial Source List Value :",sourcelistvalue for compline in sourcelisttrack: print "compline ",compline index=compline[0] addline=schematicInfo[index] #print "addline ",addline,"for index ",index if compline[1]=='sine': try: start=compline[2] end=compline[3] vo_val=str(entry_var[start].text()) if len(str(entry_var[start].text()))>0 else '0' va_val=str(entry_var[start+1].text()) if len(str(entry_var[start+1].text()))>0 else '0' freq_val=str(entry_var[start+2].text()) if len(str(entry_var[start+2].text()))>0 else '0' td_val=str(entry_var[start+3].text()) if len(str(entry_var[start+3].text()))>0 else '0' theta_val=str(entry_var[end].text()) if len(str(entry_var[end].text()))>0 else '0' addline=addline.partition('(')[0] + "("+vo_val+" "+va_val+" "+freq_val+" "+td_val+" "+theta_val+")" #print "Line Added ",addline sourcelistvalue.append([index,addline]) except: print "Caught an exception in sine voltage source ",addline elif compline[1]=='pulse': try: print "yessss" start=compline[2] end=compline[3] v1_val=str(entry_var[start].text()) if len(str(entry_var[start].text()))>0 else '0' v2_val=str(entry_var[start+1].text()) if len(str(entry_var[start+1].text()))>0 else '0' td_val=str(entry_var[start+2].text()) if len(str(entry_var[start+2].text()))>0 else '0' tr_val=str(entry_var[start+3].text()) if len(str(entry_var[start+3].text()))>0 else '0' tf_val=str(entry_var[start+4].text()) if len(str(entry_var[start+4].text()))>0 else '0' pw_val=str(entry_var[start+5].text()) if len(str(entry_var[start+5].text()))>0 else '0' tp_val=str(entry_var[end].text()) if len(str(entry_var[end].text()))>0 else '0' addline=addline.partition('(')[0] + "("+v1_val+" "+v2_val+" "+td_val+" "+tr_val+" "+tf_val+" "+pw_val+" "+tp_val+")" #print "Line Added ",addline sourcelistvalue.append([index,addline]) except: print "Caught an exception in pulse voltage source ",addline elif compline[1]=='pwl': try: start=compline[2] t_v_val=str(entry_var[start].text()) if len(str(entry_var[start].text()))>0 else '0 0' addline=addline.partition('(')[0] + "("+t_v_val+")" #print "Line Added ",addline sourcelistvalue.append([index,addline]) except: print "Caught an exception in pwl voltage source ",addline elif compline[1]=='ac': try: start=compline[2] va_val=str(entry_var[start].text()) if len(str(entry_var[start].text()))>0 else '0' addline=' '.join(addline.split()) addline=addline.partition('ac')[0] +" "+'ac'+" "+ va_val #print "Line Added ",addline sourcelistvalue.append([index,addline]) except: print "Caught an exception in ac voltage source ",addline elif compline[1]=='dc': try: start=compline[2] v1_val=str(entry_var[start].text()) if len(str(entry_var[start].text()))>0 else '0' addline=' '.join(addline.split()) addline=addline.partition('dc')[0] + " " +'dc'+ " "+v1_val #print "Line Added ",addline sourcelistvalue.append([index,addline]) except: print "Caught an exception in dc voltage source",addline elif compline[1]=='exp': try: start=compline[2] end=compline[3] v1_val=str(entry_var[start].text()) if len(str(entry_var[start].text()))>0 else '0' v2_val=str(entry_var[start+1].text()) if len(str(entry_var[start+1].text()))>0 else '0' td1_val=str(entry_var[start+2].text()) if len(str(entry_var[start+2].text()))>0 else '0' tau1_val=str(entry_var[start+3].text()) if len(str(entry_var[start+3].text()))>0 else '0' td2_val=str(entry_var[start+4].text()) if len(str(entry_var[start+4].text()))>0 else '0' tau2_val=str(entry_var[end].text()) if len(str(entry_var[end].text()))>0 else '0' addline=addline.partition('(')[0] + "("+v1_val+" "+v2_val+" "+td1_val+" "+tau1_val+" "+td2_val+" "+tau2_val+")" #print "Line Added ",addline sourcelistvalue.append([index,addline]) except: print "Caught an exception in exp voltage source ",addline #print "Final Source List Value :",sourcelistvalue ##Adding into schematicInfo for item in sourcelistvalue: del schematicInfo[item[0]] schematicInfo.insert(item[0],item[1]) def create_ngspice_netlist(): #print "sche in create_ng ",schematicInfo last_file=open(last_input_file,"w"); global spec_info for info in schematicInfo: spec_info=info.split() if spec_info[0][0]=='v' or spec_info[0]=='.model': last_file.writelines(info) last_file.writelines('\n') #Add newline in the schematic information for i in range(len(schematicInfo),0,-1): schematicInfo.insert(i,'\n') outfile=filename+".out" cktfile=filename+".ckt" out=open(outfile,"w") ckt=open(cktfile,"w") out.writelines(infoline) out.writelines('\n') ckt.writelines(infoline) ckt.writelines('\n') for modelName in modelList: if os.path.exists(modelName+".lib"): out.writelines('.include '+modelName+'.lib\n') ckt.writelines('.include '+modelName+'.lib\n') for subcktName in subcktList: out.writelines('.include '+subcktName+'.sub\n') ckt.writelines('.include '+subcktName+'.sub\n') if finalNetlist: sections=[simulatorOption, initialCondOption, schematicInfo, analysisOption] else: sections=[simulatorOption, initialCondOption, schematicInfo] for section in sections: if len(section) == 0: continue else: out.writelines('\n') out.writelines(section) ckt.writelines('\n') ckt.writelines(section) if finalNetlist: out.writelines('\n* Control Statements \n') out.writelines('.control\n') out.writelines('run\n') out.writelines(outputOption) outputOption1=[] for option in outputOption: if (("plot" in option) or ("print" in option)): outputOption1.append("."+option) else: outputOption1.append(option) ckt.writelines(outputOption1) out.writelines('print allv > plot_data_v.txt\n') out.writelines('print alli > plot_data_i.txt\n') out.writelines('.endc\n') out.writelines('.end\n') ckt.writelines('.end\n') last_file.close() out.close() ckt.close() print "The ngspice netlist has been written in "+filename+".out" print "The scilab netlist has been written in "+filename+".ckt" def convertICintoBasicBlocks(schematicInfo,outputOption,guimodelvalue): #Insert Special source parameters k=1 #print "schematicInfo is ",schematicInfo #print "guimodelvalue is ",guimodelvalue for compline in schematicInfo: words=compline.split() compName=words[0] # Find the IC from schematic if compName[0]=='u': # Find the component from the circuit index=schematicInfo.index(compline) compType=words[len(words)-1]; schematicInfo.remove(compline) if (compType=="7404" or compType=="74hc04" or compType=="74hct04" or compType=="74ls04" or compType=="74ls14"): i=1; # Add first three Not gates while words[i]!="0": # Add analog to digital converter for input A schematicInfo.append("a"+str(k)+" ["+words[i]+"] ["+words[i]+"_in] "+" "+compName+"adc") k=k+1 # Add Not gate schematicInfo.append("a"+str(k)+" "+words[i]+"_in "+words[i+1]+"_out "+compName) k=k+1 # Add digital to analog converter for output B schematicInfo.append("a"+str(k)+" ["+words[i+1]+"_out] ["+words[i+1]+"] "+" "+compName+"dac") k=k+1 i=i+2 i=i+1 # Add last three Not gates while i11: # Add analog to digital converter for inputs schematicInfo.append("a"+str(k)+" ["+words[12]+" "+words[11]+" "+words[10]+" "+words[13]+"] ["+words[12]+"_in "+words[11]+"_in "+words[10]+"_in "+words[13]+"_in] "+compName+"adc") k=k+1 # Add D Flip-flop schematicInfo.append("a"+str(k)+" "+words[12]+"_in "+words[11]+"_in ~"+words[10]+"_in ~"+words[13]+"_in "+words[9]+"_out "+words[8]+"_out "+compName) k=k+1 # Add digital to analog converter for outputs schematicInfo.append("a"+str(k)+" ["+words[9]+"_out "+words[8]+"_out] ["+words[9]+" "+words[8]+"] "+" "+compName+"dac") k=k+1 # Insert comment in-place of components schematicInfo.insert(index,"* "+compType) # Add model for D Flip-Flop schematicInfo.append(".model "+ compName+" d_dff") # Add model for analog-to-digital bridge schematicInfo.append(".model "+ compName+"adc adc_bridge(in_low=0.8 in_high=2.0)") # Add model for digital-to-analog bridge schematicInfo.append(".model "+ compName+"dac dac_bridge(out_low=0.25 out_high=5.0 out_undef=1.8 t_rise=0.5e-9 t_fall=0.5e-9)") elif (compType=="7475" or compType=="74hc75" or compType=="74ls75"): # Add analog to digital converter for inputs schematicInfo.append("a"+str(k)+" ["+words[2]+" "+words[3]+" "+words[4]+" "+words[1]+"] ["+words[2]+"_in "+words[3]+"_in "+words[4]+"_in "+words[1]+"_in] "+compName+"adc") k=k+1 # Add T Flip-flop schematicInfo.append("a"+str(k)+" "+words[2]+"_in "+words[3]+"_in ~"+words[4]+"_in ~"+words[1]+"_in "+words[5]+"_out "+words[6]+"_out "+compName) k=k+1 # Add digital to analog converter for outputs schematicInfo.append("a"+str(k)+" ["+words[5]+"_out "+words[6]+"_out] ["+words[5]+" "+words[6]+"] "+" "+compName+"dac") k=k+1 # Insert comment in-place of components schematicInfo.insert(index,"* "+compType) # Add model for T Flip-Flop schematicInfo.append(".model "+ compName+" d_tff") # Add model for analog-to-digital bridge schematicInfo.append(".model "+ compName+"adc adc_bridge(in_low=0.8 in_high=2.0)") # Add model for digital-to-analog bridge schematicInfo.append(".model "+ compName+"dac dac_bridge(out_low=0.25 out_high=5.0 out_undef=1.8 t_rise=0.5e-9 t_fall=0.5e-9)") elif (compType=="74107" or compType=="74hc107" or compType=="74ls107"): if len(words)>11: # Add analog to digital converter for inputs schematicInfo.append("a"+str(k)+" ["+words[1]+" "+words[4]+" "+words[12]+" "+words[13]+"] ["+words[1]+"_in "+words[4]+"_in "+words[12]+"_in "+words[13]+"_in] "+compName+"adc") k=k+1 # Add J-K Flip-flop schematicInfo.append("a"+str(k)+" "+words[1]+"_in "+words[4]+"_in ~"+words[12]+"_in ~"+words[13]+"_in ~"+words[13]+"_in "+words[3]+"_out "+words[2]+"_out "+compName) k=k+1 # Add digital to analog converter for outputs schematicInfo.append("a"+str(k)+" ["+words[3]+"_out "+words[2]+"_out] ["+words[3]+" "+words[2]+"] "+" "+compName+"dac") k=k+1 # Add analog to digital converter for inputs schematicInfo.append("a"+str(k)+" ["+words[8]+" "+words[11]+" "+words[9]+" "+words[10]+"] ["+words[8]+"_in "+words[11]+"_in "+words[9]+"_in "+words[10]+"_in] "+compName+"adc") k=k+1 # Add J-K Flip-flop schematicInfo.append("a"+str(k)+" "+words[8]+"_in "+words[11]+"_in ~"+words[9]+"_in ~"+words[10]+"_in ~"+words[10]+"_in "+words[5]+"_out "+words[6]+"_out "+compName) k=k+1 # Add digital to analog converter for outputs schematicInfo.append("a"+str(k)+" ["+words[5]+"_out "+words[6]+"_out] ["+words[5]+" "+words[6]+"] "+" "+compName+"dac") k=k+1 else: # Add analog to digital converter for inputs schematicInfo.append("a"+str(k)+" ["+words[1]+" "+words[4]+" "+words[12]+" "+words[13]+"] ["+words[1]+"_in "+words[4]+"_in "+words[12]+"_in "+words[13]+"_in] "+compName+"adc") k=k+1 # Add J-K Flip-flop schematicInfo.append("a"+str(k)+" "+words[1]+"_in "+words[4]+"_in ~"+words[12]+"_in ~"+words[13]+"_in ~"+words[13]+"_in "+words[3]+"_out "+words[2]+"_out "+compName) k=k+1 # Add digital to analog converter for outputs schematicInfo.append("a"+str(k)+" ["+words[3]+"_out "+words[2]+"_out] ["+words[3]+" "+words[2]+"] "+" "+compName+"dac") k=k+1 # Insert comment in-place of components schematicInfo.insert(index,"* "+compType) # Add model for JK Flip-Flop schematicInfo.append(".model "+ compName+" d_jkff") # Add model for analog-to-digital bridge schematicInfo.append(".model "+ compName+"adc adc_bridge(in_low=0.8 in_high=2.0)") # Add model for digital-to-analog bridge schematicInfo.append(".model "+ compName+"dac dac_bridge(out_low=0.25 out_high=5.0 out_undef=1.8 t_rise=0.5e-9 t_fall=0.5e-9)") elif (compType=="74109" or compType=="74hc109" or compType=="74ls109"): # Add analog to digital converter for inputs schematicInfo.append("a"+str(k)+" ["+words[2]+" "+words[3]+" "+words[4]+" "+words[5]+" "+words[1]+"] ["+words[2]+"_in "+words[3]+"_in "+words[4]+"_in "+words[5]+"_in "+words[1]+"_in] "+compName+"adc") k=k+1 # Add J-K Flip-flop schematicInfo.append("a"+str(k)+" "+words[2]+"_in ~"+words[3]+"_in "+words[4]+"_in ~"+words[5]+"_in ~"+words[1]+"_in "+words[6]+"_out "+words[7]+"_out "+compName) k=k+1 # Add digital to analog converter for outputs schematicInfo.append("a"+str(k)+" ["+words[6]+"_out "+words[7]+"_out] ["+words[6]+" "+words[7]+"] "+" "+compName+"dac") k=k+1 if len(words)>12: # Add analog to digital converter for inputs schematicInfo.append("a"+str(k)+" ["+words[14]+" "+words[13]+" "+words[12]+" "+words[11]+" "+words[15]+"] ["+words[14]+"_in "+words[13]+"_in "+words[12]+"_in "+words[11]+"_in "+words[15]+"_in] "+compName+"adc") k=k+1 # Add J-K Flip-flop schematicInfo.append("a"+str(k)+" "+words[14]+"_in ~"+words[13]+"_in "+words[12]+"_in ~"+words[11]+"_in ~"+words[15]+"_in "+words[10]+"_out "+words[9]+"_out "+compName) k=k+1 # Add digital to analog converter for outputs schematicInfo.append("a"+str(k)+" ["+words[10]+"_out "+words[9]+"_out] ["+words[10]+" "+words[9]+"] "+" "+compName+"dac") k=k+1 # Insert comment in-place of components schematicInfo.insert(index,"* "+compType) # Add model for JK Flip-Flop schematicInfo.append(".model "+ compName+" d_jkff") # Add model for analog-to-digital bridge schematicInfo.append(".model "+ compName+"adc adc_bridge(in_low=0.8 in_high=2.0)") # Add model for digital-to-analog bridge schematicInfo.append(".model "+ compName+"dac dac_bridge(out_low=0.25 out_high=5.0 out_undef=1.8 t_rise=0.5e-9 t_fall=0.5e-9)") elif (compType=="7471" or compType=="74hc71" or compType=="74ls71"): # Add analog to digital converter for inputs schematicInfo.append("a"+str(k)+" ["+words[2]+" "+words[3]+" "+words[4]+" "+words[5]+" "+words[1]+"] ["+words[2]+"_in "+words[3]+"_in "+words[4]+"_in "+words[5]+"_in "+words[1]+"_in] "+compName+"adc") k=k+1 # Add S-R Flip-flop schematicInfo.append("a"+str(k)+" "+words[2]+"_in ~"+words[3]+"_in "+words[4]+"_in ~"+words[5]+"_in ~"+words[1]+"_in "+words[6]+"_out "+words[7]+"_out "+compName) k=k+1 # Add digital to analog converter for outputs schematicInfo.append("a"+str(k)+" ["+words[6]+"_out "+words[7]+"_out] ["+words[6]+" "+words[7]+"] "+" "+compName+"dac") k=k+1 # Insert comment in-place of components schematicInfo.insert(index,"* "+compType) # Add model for SR Flip-Flop schematicInfo.append(".model "+ compName+" d_srff") # Add model for analog-to-digital bridge741 schematicInfo.append(".model "+ compName+"adc adc_bridge(in_low=0.8 in_high=2.0)") # Add model for digital-to-analog bridge schematicInfo.append(".model "+ compName+"dac dac_bridge(out_low=0.25 out_high=5.0 out_undef=1.8 t_rise=0.5e-9 t_fall=0.5e-9)") elif (compType=="74112" or compType=="74hc112" or compType=="74ls112"): if len(words)>12: schematicInfo.append("a"+str(k)+" "+words[3]+" "+words[2]+" ~"+words[1]+" ~"+words[4]+" ~"+words[15]+" "+words[5]+" "+words[6]+" "+compName) k=k+1 schematicInfo.append("a"+str(k)+" "+words[11]+" "+words[12]+" ~"+words[13]+" ~"+words[10]+" ~"+words[14]+" "+words[9]+" "+words[7]+" "+compName) k=k+1 else: schematicInfo.append("a"+str(k)+" "+words[3]+" "+words[2]+" ~"+words[1]+" ~"+words[4]+" ~"+words[8]+" "+words[5]+" "+words[6]+" "+compName) k=k+1 schematicInfo.insert(index,"* "+compType) schematicInfo.append(".model "+ compName+" d_jkff") elif compType=="dac": schematicInfo.append("a"+str(k)+" ["+words[1]+"] ["+words[2]+"] "+compName) k=k+1 schematicInfo.insert(index,"* Digital to Analog converter "+compType) schematicInfo.append(".model "+ compName+" dac_bridge") elif compType=="adc": schematicInfo.append("a"+str(k)+" ["+words[1]+"] ["+words[2]+"] "+compName) k=k+1 schematicInfo.insert(index,"* Analog to Digital converter "+compType) schematicInfo.append(".model "+ compName+" adc_bridge") elif compType=="adc8": for i in range(0,len(words)/2-1): schematicInfo.append("a"+str(k)+" ["+words[i+1]+"] ["+words[i+len(words)/2]+"] "+compName) k=k+1 #Insert comment at remove line schematicInfo.insert(index,"* "+compline) print "-----------------------------------------------------------\n" print "Adding Analog to Digital Converter" Comment='* Analog to Digital converter '+compType Title='Add parameters for analog to digital converter '+compName in_low=' Enter input low level voltage (default=0.8): ' in_high=' Enter input high level voltage (default=2.0): ' print "-----------------------------------------------------------" guimodelvalue.append([index,compline,compType,compName,Comment,Title,in_low,in_high]) elif compType=="dac8": for i in range(0,len(words)/2-1): schematicInfo.append("a"+str(k)+" ["+words[i+1]+"] ["+words[i+len(words)/2]+"] "+compName) k=k+1 #Insert comment at remove line schematicInfo.insert(index,"* "+compline) print "-----------------------------------------------------------\n" print "Adding Digital to Analog converter" Comment='* Digital to Analog converter '+compType Title='Add parameters for digital to analog converter '+compName out_low=' Enter output low level voltage (default=0.2): ' out_high=' Enter output high level voltage (default=5.0): ' out_undef=' Enter output for undefined voltage level (default=2.2): ' print "-----------------------------------------------------------" guimodelvalue.append([index,compline,compType,compName,Comment,Title,out_low,out_high,out_undef]) elif compType=="gain": schematicInfo.append("a"+str(k)+" "+words[1]+" "+words[2]+" "+compName) k=k+1 #Insert comment at remove line schematicInfo.insert(index,"* "+compline) print "-----------------------------------------------------------\n" print "Adding Gain" Comment='* Gain '+compType Title='Add parameters for Gain '+compName in_offset=' Enter offset for input (default=0.0): ' gain=' Enter gain (default=1.0): ' out_offset=' Enter offset for output (default=0.0): ' print "-----------------------------------------------------------" guimodelvalue.append([index,compline,compType,compName,Comment,Title,in_offset,gain,out_offset]) elif compType=="summer": schematicInfo.append("a"+str(k)+" ["+words[1]+" "+words[2]+"] "+words[3]+" "+compName) k=k+1 #Insert comment at remove line schematicInfo.insert(index,"* "+compline) print "-----------------------------------------------------------\n" print "Adding summer" Comment='* Summer '+compType Title='Add parameters for Summer '+compName in1_offset=' Enter offset for input 1 (default=0.0): ' in2_offset=' Enter offset for input 2 (default=0.0): ' in1_gain=' Enter gain for input 1 (default=1.0): ' in2_gain=' Enter gain for input 2 (default=1.0): ' out_gain=' Enter gain for output (default=1.0): ' out_offset=' Enter offset for output (default=0.0): ' print "-----------------------------------------------------------" guimodelvalue.append([index,compline,compType,compName,Comment,Title,in1_offset,in2_offset,in1_gain,in2_gain,out_gain,out_offset]) elif compType=="multiplier": schematicInfo.append("a"+str(k)+" ["+words[1]+" "+words[2]+"] "+words[3]+" "+compName) k=k+1 #Insert comment at remove line schematicInfo.insert(index,"* "+compline) print "-----------------------------------------------------------\n" print "Adding Multiplier" Comment='* Multiplier '+compType Title='Add parameters for Multiplier '+compName in1_offset=' Enter offset for input 1 (default=0.0): ' in2_offset=' Enter offset for input 2 (default=0.0): ' in1_gain=' Enter gain for input 1 (default=1.0): ' in2_gain=' Enter gain for input 2 (default=1.0): ' out_gain=' Enter gain for output (default=1.0): ' out_offset=' Enter offset for output (default=0.0): ' print "-----------------------------------------------------------" guimodelvalue.append([index,compline,compType,compName,Comment,Title,in1_offset,in2_offset,in1_gain,in2_gain,out_gain,out_offset]) elif compType=="divider": schematicInfo.append("a"+str(k)+" "+words[1]+" "+words[2]+" "+words[3]+" "+compName) k=k+1 #Insert comment at remove line schematicInfo.insert(index,"* "+compline) print "-----------------------------------------------------------\n" print "Adding Divider" Comment='Divider '+compType Title='Add parameters for Divider '+compName num_offset=' Enter offset for numerator (default=0.0): ' den_offset=' Enter offset for denominator (default=0.0): ' num_gain=' Enter gain for numerator (default=1.0): ' den_gain=' Enter gain for denominator (default=1.0): ' out_gain=' Enter gain for output (default=1.0): ' out_offset=' Enter offset for output (default=0.0): ' den_lower_limit=' Enter lower limit for denominator value (default=1.0e-10): ' print "-----------------------------------------------------------" guimodelvalue.append([index,compline,compType,compName,Comment,Title,num_offset,den_offset,num_gain,den_gain,out_gain,out_offset,den_lower_limit]) elif compType=="limit": schematicInfo.append("a"+str(k)+" "+words[1]+" "+words[2]+" "+compName) k=k+1 #Insert comment at remove line schematicInfo.insert(index,"* "+compline) print "-----------------------------------------------------------\n" print "Adding limiter" Comment='* Limiter '+compType Title='Add parameters for Limiter '+compName lowerLimit=' Enter out lower limit (default=0.0): ' upperLimit=' Enter out upper limit (default=5.0): ' in_offset=' Enter offset for input (default=0.0): ' gain=' Enter gain (default=1.0): ' print "-----------------------------------------------------------" guimodelvalue.append([index,compline,compType,compName,Comment,Title,lowerLimit,upperLimit,in_offset,gain]) elif compType=="integrator": schematicInfo.append("a"+str(k)+" "+words[1]+" "+words[2]+" "+compName) k=k+1 #Insert comment at remove line schematicInfo.insert(index,"* "+compline) print "-----------------------------------------------------------\n" print "Adding integrator" Comment='* Integrator '+compType Title='Add parameters for Integrator '+compName out_lower_limit=' Enter out lower limit (default=0.0): ' out_upper_limit=' Enter out upper limit (default=5.0): ' in_offset=' Enter offset for input (default=0.0): ' gain=' Enter gain (default=1.0): ' out_ic=' Enter initial condition on output (default=0.0): ' print "-----------------------------------------------------------" guimodelvalue.append([index,compline,compType,compName,Comment,Title,out_lower_limit,out_upper_limit,in_offset,gain,out_ic]) elif compType=="differentiator": schematicInfo.append("a"+str(k)+" "+words[1]+" "+words[2]+" "+compName) k=k+1 #Insert comment at remove line schematicInfo.insert(index,"* "+compline) print "-----------------------------------------------------------\n" print "Adding Differentiator" Comment='* Differentiator '+compType Title='Add parameters for Differentiator '+compName out_lower_limit=' Enter out lower limit (default=0.0): ' out_upper_limit=' Enter out upper limit (default=5.0): ' out_offset=' Enter offset for output (default=0.0): ' gain=' Enter gain (default=1.0): ' print "-----------------------------------------------------------" guimodelvalue.append([index,compline,compType,compName,Comment,Title,out_lower_limit,out_upper_limit,out_offset,gain]) elif compType=="limit8": for i in range(0,len(words)/2-1): schematicInfo.append("a"+str(k)+" "+words[i+1]+" "+words[i+len(words)/2]+" "+compName) k=k+1 #Insert comment at remove line schematicInfo.insert(index,"* "+compline) print "-----------------------------------------------------------\n" print "Adding limiter" Comment='* Limiter '+compType Title='Add parameters for Limiter '+compName lowerLimit=' Enter out lower limit (default=0.0): ' upperLimit=' Enter out upper limit (default=5.0): ' in_offset=' Enter offset for input (default=0.0): ' gain=' Enter gain (default=1.0): ' print "-----------------------------------------------------------" guimodelvalue.append([index,compline,compType,compName,Comment,Title,lowerLimit,upperLimit,in_offset,gain]) elif compType=="controlledlimiter": schematicInfo.append("a"+str(k)+" "+words[1]+" "+words[2]+" "+words[3]+" "+words[4]+" "+compName) k=k+1 #Insert comment at remove line schematicInfo.insert(index,"* "+compline) print "-----------------------------------------------------------\n" print "Adding controlledlimiter" Comment='* Controlled Limiter '+compType Title='Add parameters for Controlled Limiter '+compName in_offset=' Enter offset for input (default=0.0): ' gain=' Enter gain (default=1.0): ' print "-----------------------------------------------------------" guimodelvalue.append([index,compline,compType,compName,Comment,Title,in_offset,gain]) elif compType=="analogswitch": schematicInfo.append("a"+str(k)+" "+words[1]+" ("+words[2]+" "+words[3]+") "+compName) k=k+1 #Insert comment at remove line schematicInfo.insert(index,"* "+compline) print "-----------------------------------------------------------\n" print "Adding analogswitch" Comment='* Analog Switch '+compType Title='Add parameters for Analog Switch '+compName cntl_on=' Enter control ON voltage (default=5.0): ' cntl_off=' Enter control OFF voltage (default=0.0): ' r_on=' Enter ON resistance value (default=10.0): ' r_off=' Enter OFF resistance value (default=1e6): ' print "-----------------------------------------------------------" guimodelvalue.append([index,compline,compType,compName,Comment,Title,cntl_on,cntl_off,r_on,r_off]) elif compType=="zener": schematicInfo.append("a"+str(k)+" "+words[1]+" "+words[2]+" "+compName) k=k+1 #Insert comment at remove line schematicInfo.insert(index,"* "+compline) print "-----------------------------------------------------------\n" print "Adding Zener" Comment='* Zener Diode '+compType Title='Add parameters for Zener Diode '+compName v_breakdown=' Enter Breakdown voltage (default=5.6): ' i_breakdown=' Enter Breakdown current (default=2.0e-2): ' i_sat=' Enter saturation current (default=1.0e-12): ' n_forward=' Enter forward emission coefficient (default=0.0): ' print "-----------------------------------------------------------" guimodelvalue.append([index,compline,compType,compName,Comment,Title,v_breakdown,i_breakdown,i_sat,n_forward]) elif compType=="d_buffer": schematicInfo.append("a"+str(k)+" "+words[1]+" "+words[2]+" "+compName) k=k+1 #Insert comment at remove line schematicInfo.insert(index,"* "+compline) print "-----------------------------------------------------------\n" print "Adding Buffer" Comment='* Buffer '+compType Title='Add parameters for Buffer '+compName rise_delay=' Enter rise delay (default=1e-12): ' fall_delay=' Enter fall delay (default=1e-12): ' input_load=' Enter input load capacitance (default=1e-12): ' print "-----------------------------------------------------------" guimodelvalue.append([index,compline,compType,compName,Comment,Title,rise_delay,fall_delay,input_load]) elif compType=="d_inverter": schematicInfo.append("a"+str(k)+" "+words[1]+" "+words[2]+" "+compName) k=k+1 #Insert comment at remove line schematicInfo.insert(index,"* "+compline) print "-----------------------------------------------------------\n" print "Adding Inverter" Comment='* Inverter '+compType Title='Add parameters for Inverter '+compName rise_delay=' Enter rise delay (default=1e-12): ' fall_delay=' Enter fall delay (default=1e-12): ' input_load=' Enter input load capacitance (default=1e-12): ' print "-----------------------------------------------------------" guimodelvalue.append([index,compline,compType,compName,Comment,Title,rise_delay,fall_delay,input_load]) elif compType=="d_and": schematicInfo.append("a"+str(k)+" ["+words[1]+" "+words[2]+"] "+words[3]+" "+compName) k=k+1 #Insert comment at remove line schematicInfo.insert(index,"* "+compline) print "-----------------------------------------------------------\n" print "Adding AND" Comment='* And '+compType Title= 'Add parameters for And '+compName rise_delay=' Enter rise delay (default=1e-12): ' fall_delay=' Enter fall delay (default=1e-12): ' input_load=' Enter input load capacitance (default=1e-12): ' print "-----------------------------------------------------------" guimodelvalue.append([index,compline,compType,compName,Comment,Title,rise_delay,fall_delay,input_load]) elif compType=="d_nand": schematicInfo.append("a"+str(k)+" ["+words[1]+" "+words[2]+"] "+words[3]+" "+compName) k=k+1 #Insert comment at remove line schematicInfo.insert(index,"* "+compline) print "-----------------------------------------------------------\n" print "Adding NAND" Comment='* Nand '+compType Title='Add parameters for Nand '+compName rise_delay=' Enter rise delay (default=1e-12): ' fall_delay=' Enter fall delay (default=1e-12): ' input_load=' Enter input load capacitance (default=1e-12): ' print "-----------------------------------------------------------" guimodelvalue.append([index,compline,compType,compName,Comment,Title,rise_delay,fall_delay,input_load]) elif compType=="d_or": schematicInfo.append("a"+str(k)+" ["+words[1]+" "+words[2]+"] "+words[3]+" "+compName) k=k+1 #Insert comment at remove line schematicInfo.insert(index,"* "+compline) print "-----------------------------------------------------------\n" print "Adding OR" Comment='* OR '+compType Title='Add parameters for OR '+compName rise_delay=' Enter rise delay (default=1e-12): ' fall_delay=' Enter fall delay (default=1e-12): ' input_load=' Enter input load capacitance (default=1e-12): ' print "-----------------------------------------------------------" guimodelvalue.append([index,compline,compType,compName,Comment,Title,rise_delay,fall_delay,input_load]) elif compType=="d_nor": schematicInfo.append("a"+str(k)+" ["+words[1]+" "+words[2]+"] "+words[3]+" "+compName) k=k+1 #Insert comment at remove line schematicInfo.insert(index,"* "+compline) print "-----------------------------------------------------------\n" print "Adding NOR" Comment='* NOR '+compType Title ='Add parameters for NOR '+compName rise_delay=' Enter rise delay (default=1e-12): ' fall_delay=' Enter fall delay (default=1e-12): ' input_load=' Enter input load capacitance (default=1e-12): ' print "-----------------------------------------------------------" guimodelvalue.append([index,compline,compType,compName,Comment,Title,rise_delay,fall_delay,input_load]) elif compType=="d_xor": schematicInfo.append("a"+str(k)+" ["+words[1]+" "+words[2]+"] "+words[3]+" "+compName) k=k+1 print "-----------------------------------------------------------\n" print "Adding XOR" Comment='* XOR '+compType Title='Add parameters for XOR '+compName rise_delay=' Enter rise delay (default=1e-12): ' fall_delay=' Enter fall delay (default=1e-12): ' input_load=' Enter input load capacitance (default=1e-12): ' print "-----------------------------------------------------------" guimodelvalue.append([index,compline,compType,compName,Comment,Title,rise_delay,fall_delay,input_load]) elif compType=="d_xnor": schematicInfo.append("a"+str(k)+" ["+words[1]+" "+words[2]+"] "+words[3]+" "+compName) k=k+1 #Insert comment at remove line schematicInfo.insert(index,"* "+compline) print "-----------------------------------------------------------\n" print "Adding XNOR" Comment='* XNOR '+compType Title='Add parameters for XNOR '+compName rise_delay=' Enter rise delay (default=1e-12): ' fall_delay=' Enter fall delay (default=1e-12): ' input_load=' Enter input load capacitance (default=1e-12): ' print "-----------------------------------------------------------" guimodelvalue.append([index,compline,compType,compName,Comment,Title,rise_delay,fall_delay,input_load]) elif compType=="d_tristate": schematicInfo.append("a"+str(k)+" "+words[1]+" "+words[2]+" "+words[3]+" "+compName) k=k+1 #Insert comment at remove line schematicInfo.insert(index,"* "+compline) print "-----------------------------------------------------------\n" print "Adding Tristate" Comment='* Tristate '+compType Title='Add parameters for Tristate '+compName delay=' Enter delay (default=1e-12): ' input_load=' Enter input load capacitance (default=1e-12): ' enable_load=' Enter enable load capacitance (default=1e-12): ' print "-----------------------------------------------------------" guimodelvalue.append([index,compline,compType,compName,Comment,Title,delay,input_load,enable_load]) elif compType=="d_pullup": schematicInfo.append("a"+str(k)+" "+words[1]+" "+compName) k=k+1 #Insert comment at remove line schematicInfo.insert(index,"* "+compline) print "-----------------------------------------------------------\n" print "Adding pullup" Comment='* Pullup '+compType Title='Add parameters for Pullup '+compName load=' Enter load capacitance (default=1e-12): ' print "-----------------------------------------------------------" guimodelvalue.append([index,compline,compType,compName,Comment,Title,load]) elif compType=="d_pulldown": schematicInfo.append("a"+str(k)+" "+words[1]+" "+compName) k=k+1 #Insert comment at remove line schematicInfo.insert(index,"* "+compline) print "-----------------------------------------------------------\n" print "Adding pulldown" Comment='* Pulldown '+compType Title='Add parameters for Pulldown '+compName load=' Enter load capacitance (default=1e-12): ' print "-----------------------------------------------------------" guimodelvalue.append([index,compline,compType,compName,Comment,Title,load]) elif compType=="d_srlatch": schematicInfo.append("a"+str(k)+" "+words[1]+" "+words[2]+" "+words[3]+" "+words[4]+" "+words[5]+" "+words[6]+" "+words[7]+" "+compName) k=k+1 #Insert comment at remove line schematicInfo.insert(index,"* "+compline) print "-----------------------------------------------------------\n" print "Adding SR Latch" Comment='* SR Latch '+compType Title='Add parameters for SR Latch '+compName sr_delay=' Enter input to set-reset delay (default=1e-12): ' enable_delay=' Enter enable delay (default=1e-12): ' set_delay=' Enter set delay (default=1e-12): ' reset_delay=' Enter reset delay (default=1e-12): ' ic=' Enter initial condition on output (default=0): ' sr_load=' Enter input to set-reset load (default=1e-12): ' enable_load=' Enter enable load (default=1e-12): ' set_load=' Enter set load (default=1e-12): ' reset_load=' Enter reset load (default=1e-12): ' rise_delay=' Enter rise delay (default=1e-12): ' fall_delay=' Enter fall delay (default=1e-12): ' print "-----------------------------------------------------------" guimodelvalue.append([index,compline,compType,compName,Comment,Title,sr_delay,enable_delay,set_delay,reset_delay,ic,sr_load,enable_load,set_load,reset_load,rise_delay,fall_delay]) elif compType=="d_jklatch": schematicInfo.append("a"+str(k)+" "+words[1]+" "+words[2]+" "+words[3]+" "+words[4]+" "+words[5]+" "+words[6]+" "+words[7]+" "+compName) k=k+1 #Insert comment at remove line schematicInfo.insert(index,"* "+compline) print "-----------------------------------------------------------\n" print "Adding JK Latch" Comment='* JK Latch '+compType Title= 'Add parameters for JK Latch '+compName jk_delay=' Enter input to j-k delay (default=1e-12): ' enable_delay=' Enter enable delay (default=1e-12): ' set_delay=' Enter set delay (default=1e-12): ' reset_delay=' Enter reset delay (default=1e-12): ' ic=' Enter initial condition on output (default=0): ' jk_load=' Enter input to j-k load (default=1e-12): ' enable_load=' Enter enable load (default=1e-12): ' set_load=' Enter set load (default=1e-12): ' reset_load=' Enter reset load (default=1e-12): ' rise_delay=' Enter rise delay (default=1e-12): ' fall_delay=' Enter fall delay (default=1e-12): ' print "-----------------------------------------------------------" guimodelvalue.append([index,compline,compType,compName,Comment,Title,jk_delay,enable_delay,set_delay,reset_delay,ic,enable_load,set_load,reset_load,rise_delay,fall_delay]) elif compType=="d_dlatch": schematicInfo.append("a"+str(k)+" "+words[1]+" "+words[2]+" "+words[3]+" "+words[4]+" "+words[5]+" "+words[6]+" "+compName) k=k+1 #Insert comment at remove line schematicInfo.insert(index,"* "+compline) print "-----------------------------------------------------------\n" print "Adding D Latch" Comment='* D Latch '+compType Title= 'Add parameters for D Latch '+compName data_delay=' Enter input to data delay (default=1e-12): ' enable_delay=' Enter enable delay (default=1e-12): ' set_delay=' Enter set delay (default=1e-12): ' reset_delay=' Enter reset delay (default=1e-12): ' ic=' Enter initial condition on output (default=0): ' data_load=' Enter input to data load (default=1e-12): ' enable_load=' Enter enable load (default=1e-12): ' set_load=' Enter set load (default=1e-12): ' reset_load=' Enter reset load (default=1e-12): ' rise_delay=' Enter rise delay (default=1e-12): ' fall_delay=' Enter fall delay (default=1e-12): ' print "-----------------------------------------------------------" guimodelvalue.append([index,compline,compType,compName,Comment,Title,data_delay,enable_delay,set_delay,reset_delay,ic,data_load,enable_load,set_load,reset_load,rise_delay,fall_delay]) elif compType=="d_tlatch": schematicInfo.append("a"+str(k)+" "+words[1]+" "+words[2]+" "+words[3]+" "+words[4]+" "+words[5]+" "+words[6]+" "+compName) k=k+1 #Insert comment at remove line schematicInfo.insert(index,"* "+compline) print "-----------------------------------------------------------\n" print "Adding T Latch" Comment='* T Latch '+compType Title= 'Add parameters for T Latch '+compName t_delay=' Enter input to t delay (default=1e-12): ' enable_delay=' Enter enable delay (default=1e-12): ' set_delay=' Enter set delay (default=1e-12): ' reset_delay=' Enter reset delay (default=1e-12): ' ic=' Enter initial condition on output (default=0): ' t_load=' Enter input to t load (default=1e-12): ' enable_load=' Enter enable load (default=1e-12): ' set_load=' Enter set load (default=1e-12): ' reset_load=' Enter reset load (default=1e-12): ' rise_delay=' Enter rise delay (default=1e-12): ' fall_delay=' Enter fall delay (default=1e-12): ' print "-----------------------------------------------------------" guimodelvalue.append([index,compline,compType,compName,Comment,Title,t_delay,enable_delay,set_delay,reset_delay,ic,t_load,enable_load,set_load,reset_load,rise_delay,fall_delay]) elif compType=="d_srff": schematicInfo.append("a"+str(k)+" "+words[1]+" "+words[2]+" "+words[3]+" "+words[4]+" "+words[5]+" "+words[6]+" "+words[7]+" "+compName) k=k+1 #Insert comment at remove line schematicInfo.insert(index,"* "+compline) print "-----------------------------------------------------------\n" print "Adding SR Flip-Flop" Comment='* SR Flip-Flop '+compType Title='Add parameters for SR Flip-Flop '+compName clk_delay=' Enter clk delay (default=1e-12): ' set_delay=' Enter set delay (default=1e-12): ' reset_delay=' Enter reset delay (default=1e-12): ' ic=' Enter initial condition on output (default=0): ' sr_load=' Enter input to set-reset load (default=1e-12): ' clk_load=' Enter clk load (default=1e-12): ' set_load=' Enter set load (default=1e-12): ' reset_load=' Enter reset load (default=1e-12): ' rise_delay=' Enter rise delay (default=1e-12): ' fall_delay=' Enter fall delay (default=1e-12): ' print "-----------------------------------------------------------" guimodelvalue.append([index,compline,compType,compName,Comment,Title,clk_delay,set_delay,reset_delay,ic,sr_load,clk_load,set_load,reset_load,rise_delay,fall_delay]) elif compType=="d_jkff": schematicInfo.append("a"+str(k)+" "+words[1]+" "+words[2]+" "+words[3]+" "+words[4]+" "+words[5]+" "+words[6]+" "+words[7]+" "+compName) k=k+1 #Insert comment at remove line schematicInfo.insert(index,"* "+compline) print "-----------------------------------------------------------\n" print "Adding JK Flip-Flop" Comment='* JK Flip-Flop '+compType Title= 'Add parameters for JK Flip-Flop '+compName clk_delay=' Enter clk delay (default=1e-12): ' set_delay=' Enter set delay (default=1e-12): ' reset_delay=' Enter reset delay (default=1e-12): ' ic=' Enter initial condition on output (default=0): ' jk_load=' Enter input to j-k load (default=1e-12): ' clk_load=' Enter clk load (default=1e-12): ' set_load=' Enter set load (default=1e-12): ' reset_load=' Enter reset load (default=1e-12): ' rise_delay=' Enter rise delay (default=1e-12): ' fall_delay=' Enter fall delay (default=1e-12): ' print "-----------------------------------------------------------" guimodelvalue.append([index,compline,compType,compName,Comment,Title,clk_delay,set_delay,reset_delay,ic,jk_load,clk_load,set_load,reset_load,reset_load,rise_delay,fall_delay]) elif compType=="d_dff": schematicInfo.append("a"+str(k)+" "+words[1]+" "+words[2]+" "+words[3]+" "+words[4]+" "+words[5]+" "+words[6]+" "+compName) k=k+1 #Insert comment at remove line schematicInfo.insert(index,"* "+compline) print "-----------------------------------------------------------\n" print "Adding D Flip-Flop" Comment='* D Flip-Flop '+compType Title= 'Add parameters for D Flip-Flop '+compName clk_delay=' Enter clk delay (default=1e-12): ' set_delay=' Enter set delay (default=1e-12): ' reset_delay=' Enter reset delay (default=1e-12): ' ic=' Enter initial condition on output (default=0): ' data_load=' Enter input to data load (default=1e-12): ' clk_load=' Enter clk load (default=1e-12): ' set_load=' Enter set load (default=1e-12): ' reset_load=' Enter reset load (default=1e-12): ' rise_delay=' Enter rise delay (default=1e-12): ' fall_delay=' Enter fall delay (default=1e-12): ' print "-----------------------------------------------------------" guimodelvalue.append([index,compline,compType,compName,Comment,Title,clk_delay,set_delay,reset_delay,ic,data_load,clk_load,set_load,reset_load,rise_delay,fall_delay]) elif compType=="d_tff": schematicInfo.append("a"+str(k)+" "+words[1]+" "+words[2]+" "+words[3]+" "+words[4]+" "+words[5]+" "+words[6]+" "+compName) k=k+1 #Insert comment at remove line schematicInfo.insert(index,"* "+compline) print "-----------------------------------------------------------\n" print "Adding T Flip-Flop" Comment='* T Flip-Flop '+compType Title='Add parameters for T Flip-Flip '+compName clk_delay=' Enter clk delay (default=1e-12): ' set_delay=' Enter set delay (default=1e-12): ' reset_delay=' Enter reset delay (default=1e-12): ' ic=' Enter initial condition on output (default=0): ' t_load=' Enter input to t load (default=1e-12): ' clk_load=' Enter clk load (default=1e-12): ' set_load=' Enter set load (default=1e-12): ' reset_load=' Enter reset load (default=1e-12): ' rise_delay=' Enter rise delay (default=1e-12): ' fall_delay=' Enter fall delay (default=1e-12): ' print "-----------------------------------------------------------" guimodelvalue.append([index,compline,compType,compName,Comment,Title,clk_delay,set_delay,reset_delay,ic,t_load,clk_load,set_load,reset_load,rise_delay,fall_delay]) elif compType=="vplot1": outputOption.append("plot v("+words[1]+")\n") schematicInfo.insert(index,"* Plotting option "+compType) elif compType=="vplot8_1": outputOption.append("plot ") for i in range(1,len(words)-1): outputOption.append("v("+words[i]+") ") outputOption.append("\n") schematicInfo.insert(index,"* Plotting option "+compType) elif compType=="vdbplot8_1": outputOption.append("plot ") for i in range(1,len(words)-1): outputOption.append("db(v("+words[i]+")) ") outputOption.append("\n") schematicInfo.insert(index,"* Plotting option "+compType) elif compType=="vphase_plot8_1": outputOption.append("plot ") for i in range(1,len(words)-1): outputOption.append("ph(v("+words[i]+")) ") outputOption.append("\n") schematicInfo.insert(index,"* Plotting option "+compType) elif compType=="vprint1": outputOption.append("print v("+words[1]+")\n") schematicInfo.insert(index,"* Printing option "+compType) elif compType=="calc": outputOption.append("plot "+words[2]+"\n") schematicInfo.insert(index,"* Plotting option "+compType) elif compType=="vprint8_1": outputOption.append("print ") for i in range(1,len(words)-1): outputOption.append("v("+words[i]+") ") outputOption.append("\n") schematicInfo.insert(index,"* Printing option "+compType) elif compType=="vplot": outputOption.append("plot v("+words[1]+")-v("+words[2]+")\n") schematicInfo.insert(index,"* Plotting option "+compType) elif compType=="vplot8": outputOption.append("plot ") for i in range(0,len(words)/2-1): if words[i+1]=="0": outputOption.append("-v("+words[i+len(words)/2]+") ") elif words[i+len(words)/2]=="0": outputOption.append("v("+words[i+1]+") ") else: outputOption.append("v("+words[i+1]+")-v("+words[i+len(words)/2]+") ") outputOption.append("\n") elif compType=="vprint": outputOption.append("print v("+words[1]+")-v("+words[2]+")\n") schematicInfo.insert(index,"* Printting option "+compType) elif compType=="iplot": schematicInfo.insert(index,"V_"+words[0]+" "+words[1]+" "+words[2]+" 0") outputOption.append("plot i(V_"+words[0]+")\n") elif compType=="powerplot": outputOption.append("print ((v("+words[1]+")-v("+words[2]+"))^2)/("+words[3]+")\n") schematicInfo.insert(index,"* Printting option "+compType) elif compType=="ic": Comment='*Adding initial Condition '+compType Title=' Add initial condition ' +compName print "-----------------------------------------------------------" print "Adding initial condition" ic=' Enter initial condition on output (default=0): ' print "-----------------------------------------------------------" guimodelvalue.append([index,compline,compType,compName,Comment,Title,words[1],ic]) elif compType=="opamp1": f = open(OSCAD_HOME) data = f.read() schematicInfo.insert(index,data) elif compType=="transfo": schematicInfo.append("a"+str(k)+" ("+words[1]+" "+words[2]+") (2mmf "+words[2]+") "+compName+"_primary") k=k+1 schematicInfo.insert(index,"* "+compline) print "------------------------------------------------------------" Comment="*Adding transformer "+compType Title="Add parameters for primary and secondary "+compName num_turns="Enter the number of turns in primary (default=310):" schematicInfo.append("a"+str(k)+" (2mmf 3mmf) "+compName+"_iron_core") k=k+1 h1="Enter H value for B-H table seperated by spcae (default=blank)" b1="Enter corresponding B value seperated by space (default=blank)" area="Enter the cross-sectional area of the core: (default = 1)" length ="Enter the core length: (default = 0.01)" schematicInfo.append("a"+str(k)+" ("+words[4]+" "+words[3]+") (3mmf "+words[3]+") "+compName+"_secondary") k=k+1 num_turns2="Enter the number of turns in secondary (default=620):" guimodelvalue.append([index,compline,compType,compName,Comment,Title,num_turns,h1,b1,area,length,num_turns2]) else: schematicInfo.insert(index,compline) # Update option information return schematicInfo,outputOption,guimodelvalue def previous_file_open(filename): """Read Pspice netList""" # Open file if it exists if os.path.exists(filename): try: f = open(filename) global last_info last_info=f.read() f.close() return 1; except : print("Error in opening file") return 0; else: print filename + " does not exist" return 0; def readNetlist(filename): """Read Pspice netList""" # Open file if it exists if os.path.exists(filename): try: f = open(filename) except : print("Error in opening file") sys.exit() else: print filename + " does not exist" sys.exit() # Read the data from file data=f.read() # Close the file f.close() return data.splitlines() def readParamInfo(data): """Read Parameter information and store it into dictionary""" print "data " print data param={} for eachline in lines: print eachline eachline=eachline.strip() if len(eachline)>1: words=eachline.split(); option=words[0].lower() if option=='.param': for i in range(1, len(words), 1): paramList=words[i].split('=') param[paramList[0]]=paramList[1] return param def preprocessNetlist(lines,param): """Preprocess netlist (replace parameters)""" netlist=[] for eachline in lines: # Remove leading and trailing blanks spaces from line eachline=eachline.strip() # Remove special character $ eachline=eachline.replace('$','') # Replace parameter with values for subParam in eachline.split(): if '}' in subParam: key=subParam.split()[0] key=key.strip('{') key=key.strip('}') if key in param: eachline=eachline.replace('{'+key+'}',param[key]) else: print "Parameter " + key +" does not exists" value=raw_input('Enter parameter value: ') eachline=eachline.replace('{'+key+'}',value) # Convert netlist into lower case letter eachline=eachline.lower() # Construct netlist if len(eachline)>1: if eachline[0]=='+': netlist.append(netlist.pop()+eachline.replace('+',' ')) else: netlist.append(eachline) # Copy information line infoline=netlist[0] netlist.remove(netlist[0]) return netlist,infoline def separateNetlistInfo(netlist): optionInfo=[] schematicInfo=[] for eachline in netlist: if eachline[0]=='*': continue elif eachline[0]=='.': optionInfo.append(eachline) else: schematicInfo.append(eachline) return optionInfo,schematicInfo def addAnalysis(optionInfo): """Open file if it exists""" filename="analysis" if os.path.exists(filename): try: f = open(filename) except : print("Error in opening file") sys.exit() else: print filename + " does not exist" sys.exit() # Read the data from file data=f.read() # Close the file f.close() analysisData=data.splitlines() for eachline in analysisData: eachline=eachline.strip() if len(eachline)>1: if eachline[0]=='.': optionInfo.append(eachline) else: pass return optionInfo def findCurrent(schematicInfo,outputOption): #Find current through component by placing voltage source series with the component i=0 for eachline in outputOption: words=eachline.split() option=words[0] # Add voltage sources in series with component to find current if option=="print" or option=="plot": words.remove(option) updatedline=eachline for outputVar in words: # Find component name if output variable is current if outputVar[0]=='i': outputVar=outputVar.strip('i') outputVar=outputVar.strip('(') compName=outputVar.strip(')') # If component is voltage source, skip if compName[0]=='v': continue # Find the component from the circuit for compline in schematicInfo: compInfo=compline.split() if compInfo[0]==compName: # Construct dummy node dummyNode='dummy_'+str(i) i+=1 # Break the one node component and place zero value voltage source in between. index=schematicInfo.index(compline) schematicInfo.remove(compline) compline=compline.replace(compInfo[2],dummyNode) schematicInfo.insert(index,compline) schematicInfo.append('v'+compName+' '+dummyNode+' '+compInfo[2]+' 0') # Update option information updatedline=updatedline.replace('i('+compName+')','i(v'+compName+')') index=outputOption.index(eachline) outputOption.remove(eachline) outputOption.insert(index,updatedline) return schematicInfo, outputOption def insertSpecialSourceParam(schematicInfo,sourcelist): #Inser Special source parameter schematicInfo1=[] for compline in schematicInfo: words=compline.split() compName=words[0] # Ask for parameters of source if compName[0]=='v' or compName=='i': # Find the index component from circuit index=schematicInfo.index(compline) #schematicInfo.remove(compline) if words[3]=="pulse": Title="Add parameters for pulse source "+compName v1=' Enter initial value(Volts/Amps): ' v2=' Enter pulsed value(Volts/Amps): ' td=' Enter delay time (seconds): ' tr=' Enter rise time (seconds): ' tf=' Enter fall time (seconds): ' pw=' Enter pulse width (seconds): ' tp=' Enter period (seconds): ' sourcelist.append([index,compline,words[3],Title,v1,v2,td,tr,tf,pw,tp]) elif words[3]=="sine": Title="Add parameters for sine source "+compName vo=' Enter offset value (Volts/Amps): ' va=' Enter amplitude (Volts/Amps): ' freq=' Enter frequency (Hz): ' td=' Enter delay time (seconds): ' theta=' Enter damping factor (1/seconds): ' sourcelist.append([index,compline,words[3],Title,vo,va,freq,td,theta]) elif words[3]=="pwl": Title="Add parameters for pwl source"+compName t_v=' Enter in pwl format without bracket i.e t1 v1 t2 v2.... ' sourcelist.append([index,compline,words[3],Title,t_v]) elif words[3]=="ac": Title="Add parameters for ac source "+compName v_a=' Enter amplitude (Volts/Amps): ' sourcelist.append([index,compline,words[3],Title,v_a]) elif words[3]=="exp": Title="Add parameters for exponential source "+compName v1=' Enter initial value(Volts/Amps): ' v2=' Enter pulsed value(Volts/Amps): ' td1=' Enter rise delay time (seconds): ' tau1=' Enter rise time constant (seconds): ' td2=' Enter fall time (seconds): ' tau2=' Enter fall time constant (seconds): ' sourcelist.append([index,compline,words[3],Title,v1,v2,td1,tau1,td2,tau2]) elif words[3]=="dc": Title="Add parameters for DC source "+compName v1=' Enter value(Volts/Amps): ' v2=' Enter zero frequency: ' sourcelist.append([index,compline,words[3],Title,v1,v2]) #schematicInfo.insert(index,compline) elif compName[0]=='h' or compName[0]=='f': # Find the index component from the circuit index=schematicInfo.index(compline) schematicInfo.remove(compline) schematicInfo.insert(index,"* "+compName) schematicInfo1.append("V"+compName+" "+words[3]+" "+words[4]+" 0") schematicInfo1.append(compName+" "+words[1]+" "+words[2]+" "+"V"+compName+" "+words[5]) schematicInfo=schematicInfo+schematicInfo1 #print sourcelist #print schematicInfo return schematicInfo,sourcelist def main(): # Accept input file name from user if not provided global lines global firstwindow #for checking whether first window in closed global filename global infoline,backClicked,last_input_file global modelList,analysisOption global subcktList,finalNetlist,simulatorOption,initialCondOption firstwindow=1 if len(sys.argv) < 2: filename=raw_input('Enter file name: ') else: filename=sys.argv[1] if len(sys.argv) < 3: finalNetlist=int(raw_input('Do you want to create final file: ')) else: finalNetlist=int(sys.argv[2]) print "==================================" print "Kicad to Ngspice netlist converter " print "==================================" print "converting "+filename last_input_file=filename[:len(filename)-4] last_input_file=last_input_file+"_last_input.txt" print "input_file ",last_input_file global schematicInfo # Read the netlist lines=readNetlist(filename) # Construct parameter information param=readParamInfo(lines) # Replace parameter with values netlist, infoline=preprocessNetlist(lines,param) # Separate option and schematic information optionInfo, schematicInfo=separateNetlistInfo(netlist) if finalNetlist: """Insert analysis from file""" optionInfo=addAnalysis(optionInfo) #print optionInfo # Find the analysis option analysisOption=[] outputOption=[] initialCondOption=[] simulatorOption=[] includeOption=[] model=[] for eachline in optionInfo: words=eachline.split() option=words[0] if (option=='.ac' or option=='.dc' or option=='.disto' or option=='.noise' or option=='.op' or option=='.pz' or option=='.sens' or option=='.tf' or option=='.tran'): analysisOption.append(eachline+'\n') #print eachline elif (option=='.save' or option=='.print' or option=='.plot' or option=='.four'): eachline=eachline.strip('.') outputOption.append(eachline+'\n') elif (option=='.nodeset' or option=='.ic'): initialCondOption.append(eachline+'\n') elif option=='.option': simulatorOption.append(eachline+'\n') elif (option=='.include' or option=='.lib'): includeOption.append(eachline+'\n') elif (option=='.model'): model.append(eachline+'\n') elif option=='.end': continue; # Find the various model library required modelList=[] subcktList=[] for eachline in schematicInfo: words=eachline.split() if eachline[0]=='d': modelName=words[3] if modelName in modelList: continue modelList.append(modelName) elif eachline[0]=='q': modelName=words[4] index=schematicInfo.index(eachline) schematicInfo.remove(eachline) schematicInfo.insert(index,words[0]+" "+words[3]+" "+words[2]+" "+words[1]+" "+words[4]) if modelName in modelList: continue modelList.append(modelName) elif eachline[0]=='m': modelName=words[4] index=schematicInfo.index(eachline) schematicInfo.remove(eachline) width=raw_input(' Enter width of mosfet '+words[0]+'(default=100u):') length=raw_input(' Enter length of mosfet '+words[0]+'(default=100u):') multiplicative_factor=raw_input(' Enter multiplicative factor of mosfet '+words[0]+'(default=1):') if width=="": width="100u" if multiplicative_factor=="": multiplicative_factor="100u" if length=="": length="100u" schematicInfo.insert(index,words[0]+" "+words[1]+" "+words[2]+" "+words[3]+" "+words[3]+" "+words[4]+" "+'M='+multiplicative_factor+" "+'L='+length+" "+'W='+width) if modelName in modelList: continue modelList.append(modelName) elif eachline[0]=='j': modelName=words[4] index=schematicInfo.index(eachline) schematicInfo.remove(eachline) schematicInfo.insert(index,words[0]+" "+words[1]+" "+words[2]+" "+words[3]+" "+words[4]) if modelName in modelList: continue modelList.append(modelName) elif eachline[0]=='x': subcktName=words[len(words)-1] if subcktName in subcktList: continue subcktList.append(subcktName) # Find current through components schematicInfo,outputOption=findCurrent(schematicInfo,outputOption) #List for storing source and its value global sourcelisttrack sourcelist=[] sourcelisttrack=[] # Add parameter to sources schematicInfo,sourcelist=insertSpecialSourceParam(schematicInfo,sourcelist) sourcelist,sourcelisttrack=w.createrootwindow(sourcelist,sourcelisttrack) #print "Output Option",outputOption #print "Sch Info",schematicInfo #print "Src List",sourcelist #print "Src Track",sourcelisttrack if __name__=='__main__': app=QtGui.QApplication(sys.argv) global w global nw w=Window() nw=NewWindow() nw.close() main() sys.exit(app.exec_())