From 4e03efacb7c72a22337438a34535cc36423212c4 Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Tue, 16 Jun 2020 15:51:07 +0200 Subject: [PATCH] Use InpEvaluate() instead of strtod to enable ngspice numbers with scale factors Meg k m u n p f etc. --- examples/optran/F5TurboV2thermal-optran.cir | 60 ++++++++++++--------- examples/optran/script-optran.txt | 15 +++--- src/spicelib/analysis/optran.c | 16 +++--- 3 files changed, 53 insertions(+), 38 deletions(-) diff --git a/examples/optran/F5TurboV2thermal-optran.cir b/examples/optran/F5TurboV2thermal-optran.cir index 56fd412b0..521dd9d38 100644 --- a/examples/optran/F5TurboV2thermal-optran.cir +++ b/examples/optran/F5TurboV2thermal-optran.cir @@ -5,12 +5,12 @@ R2 in 0 47.5k R1 Net-_Q1-Pad2_ in 1k R5 +32 Net-_P1-Pad1_ 1k R3 Net-_P3-Pad1_ 0 10 -R4 0 Net-_P3-Pad1_ 10 +R4 0 Net-_P3-Pad3_ 10 R6 Net-_P2-Pad1_ -32 1k R7 out Net-_P3-Pad1_ 220 R8 out Net-_P3-Pad1_ 220 -R9 out Net-_P3-Pad1_ 220 -R10 out Net-_P3-Pad1_ 220 +R9 out Net-_P3-Pad3_ 220 +R10 out Net-_P3-Pad3_ 220 R11 Net-_R11-Pad1_ Net-_P1-Pad1_ 2.2k R13 Net-_Q3-Pad2_ Net-_P1-Pad1_ 47.5 R15 Net-_Q5-Pad2_ Net-_P2-Pad1_ 47.5 @@ -25,7 +25,7 @@ R19 +32 Net-_D4a1-Pad1_ 1 R23 Net-_D2a1-Pad2_ -32 1 R20 +32 Net-_D4a1-Pad1_ 1 R24 Net-_D2a1-Pad2_ -32 1 -Rl1 out 0 4 +Ra2 Net-_Ra1-Pad2_ 0 4 D3a1 +32 Net-_D3a1-Pad1_ DMOD D1a1 Net-_D1a1-Pad2_ -32 DMOD D3b1 +32 Net-_D3a1-Pad1_ DMOD @@ -34,12 +34,12 @@ D4a1 +32 Net-_D4a1-Pad1_ DMOD D2a1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40 -Cc1 Q3hs 0 1 -Cc2 Q4hs 0 1 -Cc3 Q5hs 0 1 -Cc4 Q6hs 0 1 -V1 +32 0 32 ; pulse(0 32 1m 1m 1m 100 200) -V2 -32 0 -32 ; pulse(0 -32 1m 1m 1m 100 200) +Rc2 Q3hs Net-_Rc2-Pad2_ {hs} +Rc4 Q4hs Net-_Rc2-Pad2_ {hs} +Rc6 Q5hs Net-_Rc2-Pad2_ {hs} +Rc8 Q6hs Net-_Rc2-Pad2_ {hs} +Rc1 Q3tc Q3hs {chs} +Rc3 Q4tc Q4hs {chs} +Rc5 Q5tc Q5hs {chs} +Rc7 Q6tc Q6hs {chs} +Vt1 Net-_Rc2-Pad2_ 0 {envtemp} +Cc1 Q3hs 0 {hscc} +Cc3 Q5hs 0 {hscc} +Cc4 Q6hs 0 {hscc} +V1 +32 0 dc 32 ; pulse(0 32 0.4m 2m 2m 100 200) +V2 -32 0 dc -32 ; pulse(0 -32 0.4m 2m 2m 100 200) XTH2 Net-_D1a1-Pad2_ Q5hs Net-_R12-Pad1_ th R25=4.7k XTH1 Net-_D3a1-Pad1_ Q3hs Net-_R11-Pad1_ th R25=4.7k MQ3 out Net-_Q3-Pad2_ Net-_D3a1-Pad1_ Q3tj Q3tc IRFP9240 thermal -*.tran 20u 5 +Vs1 Net-_S1-Pad3_ 0 dc 0 pulse(0 5 6 1m 1m 20 20) +XS1 Net-_Ra1-Pad2_ 0 Net-_S1-Pad3_ 0 genrelay +Cc2 Q4hs 0 {hscc} +Ra1 out Net-_Ra1-Pad2_ 4 +.tran 20u 5 +.param envtemp=40 +.param chs=1 +.param hs=1.2 +.param hscc=1 +.param rp2=0.21 +.param rp1=0.36 +.param rp3=0.505 .end diff --git a/examples/optran/script-optran.txt b/examples/optran/script-optran.txt index d58092225..d71003fa5 100644 --- a/examples/optran/script-optran.txt +++ b/examples/optran/script-optran.txt @@ -12,27 +12,28 @@ else * Start optran without first iteration, * without gmin stepping and without src stepping * optran step size 10 ms, duration 40s, -optran 1 0 0 1e-2 4 0 +optran 1 0 0 10m 40 0 +* check the first 10 ms, input is switched on after 5 ms tran 1u 10m echo * output power -let po = @rl1[i] * v(out) +let po = @ra1[i] * v(out) meas tran power_rms rms po from=5m to=10m echo rusage * temperature transistor Q6 set xbrushwidth=4 settype temperature q6tj q6tc q6hs -plot q6tj q6tc q6hs ylimit 0 150 -set xbrushwidth=1 +plot q6tj q6tc q6hs q3tj q3tc q3hs ylimit 40 140 +set xbrushwidth=2 * input and output voltages plot in out * power supply currents *plot V1#branch V2#branch ylimit -50 50 -plot V1#branch V2#branch ylimit -15 15 +plot V1#branch V2#branch ylimit -10 10 * output current -plot @rl1[i] -*plot @rl1[i] xlimit 0 5m ylimit -0.3 0.3 +plot @ra1[i] +*plot @ra1[i] xlimit 0 5m ylimit -0.3 0.3 * resistance of thermistor2 TH1, TH2 let rth1 = (v("net-_d3a1-pad1_") - v("net-_r11-pad1_")) / (@b.xth1.brtherm[i] + 1n) let rth2 = (v("net-_d1a1-pad2_") - v("net-_r12-pad1_")) / (@b.xth2.brtherm[i] + 1n) diff --git a/src/spicelib/analysis/optran.c b/src/spicelib/analysis/optran.c index 85106aa40..731eec099 100644 --- a/src/spicelib/analysis/optran.c +++ b/src/spicelib/analysis/optran.c @@ -62,6 +62,7 @@ static double opramptime = 0.; void com_optran(wordlist* wl) { wordlist* wltmp = wl; char* stpstr; + int err; /* current circuit */ if (!ft_curckt) { fprintf(cp_err, "Error: no circuit loaded\n"); @@ -80,16 +81,19 @@ void com_optran(wordlist* wl) { if ((errno == ERANGE) || (*stpstr != '\0')) goto bugquit; wltmp = wltmp->wl_next; - opstepsize = strtod(wltmp->wl_word, &stpstr); - if ((errno == ERANGE) || (*stpstr != '\0')) + stpstr = wltmp->wl_word; + opstepsize = INPevaluate(&stpstr, &err, 1); + if (err || (*stpstr != '\0')) goto bugquit; wltmp = wltmp->wl_next; - opfinaltime = strtod(wltmp->wl_word, &stpstr); - if ((errno == ERANGE) || (*stpstr != '\0')) + stpstr = wltmp->wl_word; + opfinaltime = INPevaluate(&stpstr, &err, 1); + if (err || (*stpstr != '\0')) goto bugquit; wltmp = wltmp->wl_next; - opramptime = strtod(wltmp->wl_word, &stpstr); - if ((errno == ERANGE) || (*stpstr != '\0')) + stpstr = wltmp->wl_word; + opramptime = INPevaluate(&stpstr, &err, 1); + if (err || (*stpstr != '\0')) goto bugquit; if (opstepsize > opfinaltime) { fprintf(stderr, "Error: Step size larger than final time.\n");