From 28b495318dc73ef1f6a7059e48cfa194e86a8b8a Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Thu, 28 Sep 2023 10:05:31 +0200 Subject: [PATCH] Update to command 'wrnodev': Prevent crash if tran is not (yet) run. Open output file only when data are available. Enhanced comment and warning message. --- src/frontend/com_wr_ic.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/frontend/com_wr_ic.c b/src/frontend/com_wr_ic.c index cad8454fa..db9ebf1b5 100644 --- a/src/frontend/com_wr_ic.c +++ b/src/frontend/com_wr_ic.c @@ -18,6 +18,8 @@ void com_wric(wordlist* wl); /* Print the current node status to a file with format .ic V(node) = value + during a transient simulation which has been stopped, + by command 'stop' and which may continue by 'resume'. */ void com_wric(wordlist* wl) { @@ -32,11 +34,6 @@ com_wric(wordlist* wl) { else file = "dot_ic_out.txt"; - if ((fp = fopen(file, "w")) == NULL) { - perror(file); - return; - } - if (!ft_curckt) { fprintf(cp_err, "Error: there aren't any circuits loaded.\n"); return; @@ -48,6 +45,17 @@ com_wric(wordlist* wl) { ckt = ft_curckt->ci_ckt; + if (!ckt->CKTrhsOld) { + fprintf(stderr, "\nWarning: Command wrnodev is ignored!\n"); + fprintf(stderr, " You need to execute stop ... tran ... resume\n\n"); + return; + } + + if ((fp = fopen(file, "w")) == NULL) { + perror(file); + return; + } + fprintf(fp, "* Intermediate Transient Solution\n"); fprintf(fp, "* Circuit: %s\n", ft_curckt->ci_name); fprintf(fp, "* Recorded at simulation time: %g\n", ckt->CKTtime);