diff --git a/src/ngspice_backannotate.tcl b/src/ngspice_backannotate.tcl index d6d52243..1346002d 100644 --- a/src/ngspice_backannotate.tcl +++ b/src/ngspice_backannotate.tcl @@ -52,11 +52,11 @@ proc ngspice::read_ngspice_raw {arr fp} { } if {$variables} { if { $n_points == 1} { - set bindata [read $fp [expr 8 * $n_vars * $n_points]] - binary scan $bindata d[expr $n_vars * $n_points] data + set bindata [read $fp [expr {8 * $n_vars * $n_points}]] + binary scan $bindata d[expr {$n_vars * $n_points}] data for {set p 0} {$p < $n_points} { incr p} { for {set v 0} {$v < $n_vars} { incr v} { - lappend var($idx($v)) [lindex $data [expr $p * $n_vars + $v]] + lappend var($idx($v)) [lindex $data [expr {$p * $n_vars + $v}]] # puts "-->|$idx($v)|$var($idx($v))|" } } @@ -90,7 +90,7 @@ proc ngspice::get_diff_probe {arr p m } { if { ! [info exists var([string tolower $mm])] } { set mm $m } - return [format %.4g [expr $var([string tolower $pp]) - $var([string tolower $mm]) ] ] + return [format %.4g [expr {$var([string tolower $pp]) - $var([string tolower $mm])} ] ] # return DELETE } @@ -124,12 +124,12 @@ proc ngspice::get_current {n} { } } set n i($n) - puts "ngspice::get_current --> $n" + # puts "ngspice::get_current --> $n" set err [catch {set ::ngspice::ngspice_data($n)} res] if { $err } { set res {?} } else { - if { abs($res) <1e-3} { + if { abs($res) <1e-3 && $res != 0.0} { set res [ format %.4e $res ] } else { set res [ format %.4g $res ] @@ -148,7 +148,7 @@ proc ngspice::get_voltage {n} { # puts "get_ngspice_node: $res" set res {?} } else { - if { abs($res) <1e-3} { + if { abs($res) <1e-3 && $res != 0.0} { set res [ format %.4e $res ] } else { set res [ format %.4g $res ] @@ -166,7 +166,7 @@ proc ngspice::get_node {n} { if { $err } { set res {?} } else { - if { abs($res) <1e-3} { + if { abs($res) <1e-3 && $res != 0.0} { set res [ format %.4e $res ] } else { set res [ format %.4g $res ] diff --git a/src/token.c b/src/token.c index 611fadc3..49870d6b 100644 --- a/src/token.c +++ b/src/token.c @@ -2815,7 +2815,7 @@ const char *translate(int inst, const char* s) int level; Lcc *lcc; char *value1 = NULL; - + int sim_is_xyce; s_pnetname = tclgetboolvar("show_pin_net_names"); sp_prefix = tclgetboolvar("spiceprefix"); @@ -2824,6 +2824,7 @@ const char *translate(int inst, const char* s) return empty; } + sim_is_xyce = tcleval("sim_is_xyce")[0] == '1' ? 1 : 0; level = xctx->currsch; lcc = xctx->hier_attr; size=CADCHUNKALLOC; @@ -3020,8 +3021,96 @@ const char *translate(int inst, const char* s) if(xctx->graph_values && xctx->graph_backannotate_p>=0) { int multip; int no_of_pins= (xctx->inst[inst].ptr + xctx->sym)->rects[PINLAYER]; - if(no_of_pins>0) { - dbg(0, "inst %d, net=%s\n",inst, net_name(inst,0, &multip, 0, 0)); + if(no_of_pins == 1) { + char *fqnet = NULL; + const char *path = xctx->sch_path[xctx->currsch] + 1; + const char *net; + size_t len; + int idx; + double val; + char valstr[120]; + if(path) { + prepare_netlist_structs(0); + net = net_name(inst,0, &multip, 0, 0); + len = strlen(path) + strlen(net) + 1; + dbg(1, "net=%s\n", net); + fqnet = my_malloc(1548, len); + my_snprintf(fqnet, len, "%s%s", path, net); + strtolower(fqnet); + idx = get_raw_index(fqnet); + if(idx >= 0) { + val = xctx->graph_values[idx][xctx->graph_backannotate_p]; + } + if(idx < 0) { + my_snprintf(valstr, S(valstr), "?"); + } else if( fabs(val) < 1.0e-3 && val != 0.0) { + my_snprintf(valstr, S(valstr), "%.4e", val); + } else { + my_snprintf(valstr, S(valstr), "%.4g", val); + } + len = strlen(valstr); + if(len) { + STR_ALLOC(&result, len + result_pos, &size); + memcpy(result+result_pos, valstr, len+1); + result_pos += len; + } + dbg(1, "inst %d, net=%s, fqnet=%s idx=%d valstr=%s\n", inst, net, fqnet, idx, valstr); + my_free(1549, &fqnet); + } + } + } + } + else if(strcmp(token,"@spice_get_current")==0 ) + { + if(xctx->graph_values && xctx->graph_backannotate_p>=0) { + char *fqdev = NULL; + const char *path = xctx->sch_path[xctx->currsch] + 1; + char *dev = NULL; + size_t len; + int idx; + double val; + char valstr[120]; + if(path) { + my_strdup2(1550, &dev, xctx->inst[inst].instname); + strtolower(dev); + len = strlen(path) + strlen(dev) + 11; /* some extra chars for i(..) wrapper */ + dbg(1, "dev=%s\n", dev); + fqdev = my_malloc(1548, len); + if(!sim_is_xyce) { + int prefix=dev[0]; + int vsource = (prefix == 'v') || (prefix == 'e'); + if(path[0]) { + if(vsource) my_snprintf(fqdev, len, "i(%c.%s%s)", prefix, path, dev); + else my_snprintf(fqdev, len, "i(@%c.%s%s)", prefix, path, dev); + } else { + if(vsource) my_snprintf(fqdev, len, "i(%s)", dev); + else my_snprintf(fqdev, len, "i(@%s)", dev); + } + } else { + my_snprintf(fqdev, len, "i(%s%s)", path, dev); + } + dbg(1, "fqdev=%s\n", fqdev); + strtolower(fqdev); + idx = get_raw_index(fqdev); + if(idx >= 0) { + val = xctx->graph_values[idx][xctx->graph_backannotate_p]; + } + if(idx < 0) { + my_snprintf(valstr, S(valstr), "?"); + } else if( fabs(val) < 1.0e-3 && val != 0.0) { + my_snprintf(valstr, S(valstr), "%.4e", val); + } else { + my_snprintf(valstr, S(valstr), "%.4g", val); + } + len = strlen(valstr); + if(len) { + STR_ALLOC(&result, len + result_pos, &size); + memcpy(result+result_pos, valstr, len+1); + result_pos += len; + } + dbg(1, "inst %d, dev=%s, fqdev=%s idx=%d valstr=%s\n", inst, dev, fqdev, idx, valstr); + my_free(1549, &fqdev); + my_free(1551, &dev); } } } diff --git a/tests/xschemtest.tcl b/tests/xschemtest.tcl index ef3c0140..7f3b28f1 100644 --- a/tests/xschemtest.tcl +++ b/tests/xschemtest.tcl @@ -190,13 +190,13 @@ proc test_xschem_simulation {{f simulate_ff.sch}} { proc netlist_test {} { global netlist_dir foreach {f t h} { - rom8k.sch spice 2248266091 + rom8k.sch spice 2922365852 greycnt.sch verilog 3378316826 autozero_comp.sch spice 2275498269 loading.sch vhdl 584526899 mos_power_ampli.sch spice 1004049459 hierarchical_tedax.sch tedax 998070173 - LCC_instances.sch spice 3904804413 + LCC_instances.sch spice 1046024056 pcb_test1.sch tedax 1925087189 simulate_ff.sch spice 1321596936 } { diff --git a/xschem_library/devices/ammeter.sym b/xschem_library/devices/ammeter.sym index 17731543..b2748a71 100644 --- a/xschem_library/devices/ammeter.sym +++ b/xschem_library/devices/ammeter.sym @@ -16,5 +16,5 @@ B 5 -2.5 27.5 2.5 32.5 {name=minus dir=inout propag=0} T {@name} 15 -18.75 0 0 0.2 0.2 {} T {@#0:net_name} 10 -28.75 0 0 0.15 0.15 {layer=15} T {@#1:net_name} 10 20 0 0 0.15 0.15 {layer=15} -T {tcleval(i=[ ngspice::get_current @name ])} 12.5 0 0 0 0.2 0.2 {layer=15 +T {@spice_get_current} 12.5 0 0 0 0.2 0.2 {layer=15 hide=true} diff --git a/xschem_library/devices/lab_pin.sym b/xschem_library/devices/lab_pin.sym index a1bb548d..d85cc28a 100644 --- a/xschem_library/devices/lab_pin.sym +++ b/xschem_library/devices/lab_pin.sym @@ -9,4 +9,4 @@ S {} E {} B 5 -1.25 -1.25 1.25 1.25 {name=p dir=in} T {@lab} -7.5 -8.125 0 1 0.33 0.33 {} -T {tcleval( [ ngspice::get_voltage @@p ] )} -16.875 11.40625 0 1 0.2 0.2 {layer=15 hide=true} +T {@spice_get_voltage} -16.875 11.40625 0 1 0.2 0.2 {layer=15 hide=true} diff --git a/xschem_library/devices/lab_wire.sym b/xschem_library/devices/lab_wire.sym index 59c852f4..5278f59b 100644 --- a/xschem_library/devices/lab_wire.sym +++ b/xschem_library/devices/lab_wire.sym @@ -9,4 +9,4 @@ S {} E {} B 5 -1.25 -1.25 1.25 1.25 {name=p dir=in} T {@lab} -2.5 -1.25 2 0 0.27 0.27 {} -T {tcleval( [ ngspice::get_voltage @@p ] )} -1.875 -24.84375 0 1 0.2 0.2 {vcenter=true layer=15 hide=true} +T {@spice_get_voltage} -1.875 -24.84375 0 1 0.2 0.2 {vcenter=true layer=15 hide=true} diff --git a/xschem_library/devices/spice_probe.sym b/xschem_library/devices/spice_probe.sym index 4c58768b..74191b79 100644 --- a/xschem_library/devices/spice_probe.sym +++ b/xschem_library/devices/spice_probe.sym @@ -23,4 +23,4 @@ L 15 21.25 -20 25 -20 {} L 15 25 -23.75 25 -20 {} L 15 25 -23.75 27.8125 -23.75 {} B 5 -0.46875 -0.46875 0.46875 0.46875 {name=p dir=xxx} -T {tcleval( [ ngspice::get_voltage @@p ] )} 11.875 -34.84375 0 0 0.2 0.2 {vcenter=true layer=15 hide=true} +T {@spice_get_voltage} 11.875 -34.84375 0 0 0.2 0.2 {vcenter=true layer=15 hide=true} diff --git a/xschem_library/devices/vsource.sym b/xschem_library/devices/vsource.sym index 9bf6cb61..dbb05e9e 100644 --- a/xschem_library/devices/vsource.sym +++ b/xschem_library/devices/vsource.sym @@ -18,5 +18,5 @@ T {@name} 20 -18.75 0 0 0.2 0.2 {} T {@value} 20 6.25 0 0 0.2 0.2 {} T {@#0:net_name} 10 -28.75 0 0 0.15 0.15 {layer=15} T {@#1:net_name} 10 20 0 0 0.15 0.15 {layer=15} -T {tcleval(i=[ ngspice::get_current @name ])} 20 -6.25 0 0 0.2 0.2 {layer=15 +T {@spice_get_current} 20 -6.25 0 0 0.2 0.2 {layer=15 hide=true} diff --git a/xschem_library/ngspice/autozero_comp.sch b/xschem_library/ngspice/autozero_comp.sch index ac58e6c3..3ade1b78 100644 --- a/xschem_library/ngspice/autozero_comp.sch +++ b/xschem_library/ngspice/autozero_comp.sch @@ -23,8 +23,8 @@ B 2 260 -1080 720 -920 {flags=graph y1 = 0 y2 = 0.93 divy = 5 -x1=1.28193e-07 -x2=4.48192e-07 +x1=8.50726e-08 +x2=4.38966e-07 divx=5 subdivx=4 unitx=n @@ -36,8 +36,8 @@ B 2 260 -1220 720 -1090 {flags=graph y1 = 0.647319 y2 = 0.652563 divy = 5 -x1=1.28193e-07 -x2=4.48192e-07 +x1=8.50726e-08 +x2=4.38966e-07 unitx=n divx=5 subdivx=4 @@ -396,12 +396,12 @@ C {ngspice_probe.sym} 1260 -710 0 0 {name=r1} C {ngspice_probe.sym} 1600 -710 0 0 {name=r1} C {ngspice_probe.sym} 2100 -710 0 0 {name=r1} C {ngspice_probe.sym} 1610 -1390 0 0 {name=r1} -C {ngspice_probe.sym} 1920 -1260 0 0 {name=r1} -C {ngspice_probe.sym} 1430 -1260 0 0 {name=r1} -C {ngspice_probe.sym} 920 -1260 0 0 {name=r1} +C {ngspice_probe.sym} 1470 -1200 0 0 {name=r1} +C {ngspice_probe.sym} 980 -1200 0 0 {name=r1} C {ngspice_probe.sym} 1040 -860 0 0 {name=r1} C {ngspice_probe.sym} 530 -860 0 0 {name=r1} C {ngspice_probe.sym} 200 -570 0 0 {name=r1} C {ngspice_probe.sym} 120 -570 0 1 {name=r1} C {ngspice_probe.sym} 200 -700 0 0 {name=r1} C {ngspice_probe.sym} 120 -470 0 0 {name=r1} +C {ngspice_probe.sym} 1960 -1200 0 0 {name=r1}