How to write a Tcl script which will create a list of models and subcircuit names

拜拜、爱过 提交于 2020-12-15 05:12:25

问题


I got stuck in a Tcl script which will create a list of models and subcircuit names contained within a Spice .lib file: The name of the .lib file should be given on the command line . the file looks like the following:

.model Q2N2222  NPN(Is=14.34f Xti=3 Eg=1.11 Vaf=74.03 Bf=255.9 Ne=1.307
+       Ise=14.34f Ikf=.2847 Xtb=1.5 Br=6.092 Nc=2 Isc=0 Ikr=0 Rc=1
+       Cjc=7.306p Mjc=.3416 Vjc=.75 Fc=.5 Cje=22.01p Mje=.377 Vje=.75
+       Tr=46.91n Tf=411.1p Itf=.6 Vtf=1.7 Xtf=3 Rb=10)
*       National    pid=19      case=TO18
*       88-09-07 bam    creation
*$

.model Q2N3904  NPN(Is=6.734f Xti=3 Eg=1.11 Vaf=74.03 Bf=416.4 Ne=1.259
+       Ise=6.734f Ikf=66.78m Xtb=1.5 Br=.7371 Nc=2 Isc=0 Ikr=0 Rc=1
+       Cjc=3.638p Mjc=.3085 Vjc=.75 Fc=.5 Cje=4.493p Mje=.2593 Vje=.75
+       Tr=239.5n Tf=301.2p Itf=.4 Vtf=4 Xtf=2 Rb=10)
*       National    pid=23      case=TO92
*       88-09-08 bam    creation
*$

.model Q2N3906  PNP(Is=1.41f Xti=3 Eg=1.11 Vaf=18.7 Bf=180.7 Ne=1.5 Ise=0
+       Ikf=80m Xtb=1.5 Br=4.977 Nc=2 Isc=0 Ikr=0 Rc=2.5 Cjc=9.728p
+       Mjc=.5776 Vjc=.75 Fc=.5 Cje=8.063p Mje=.3677 Vje=.75 Tr=33.42n
+       Tf=179.3p Itf=.4 Vtf=4 Xtf=6 Rb=10)
*       National    pid=66      case=TO92
*       88-09-09 bam    creation
*$

And here is the code i develop but confused how to proceed next:

proc find_lib_parts {ece476} {

    set value [string first ".lib" $ece476]
#open the file 

    if {$value = -1} {
#set filename $ece476
        if {[catch {set fid [ open $ece476 "r"]} error_message]}  {
        puts $error_message
        exit
        }

#read a line

set infos [split [read $fid] "\n"]
#close $fid

set data  [string trim $infos "\n"]

#get an empty list
set res {}
append res "MODEL FOUND:\n"

foreach line $data {

# match every line that has more than three columns
# match every line where the first element is "model"
# or match every line where the first element is "MODEL"

    if{[llength $line] > 3 && [lindex $line 0] eq {model}} {
    lappend res [lindex $line 0] \n
        }
    
    if{[llength $line] > 3 && [lindex $line 0] eq {MODEL}} {
    lappend res [lindex $line 0] \n
        }
    }
}
close $fid
}

来源:https://stackoverflow.com/questions/65173624/how-to-write-a-tcl-script-which-will-create-a-list-of-models-and-subcircuit-name

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!