From 82e563b1b1df3c953ea7bc74b271edcccb98b741 Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Fri, 23 Jan 2026 19:50:26 +0100 Subject: [PATCH] New analogue and digital device models from TI contain the token GND in their subcircuit. Up to now ngspice has declared GND as global and replaced it by 0. Now, if PS is selected as compat mode, GND is not declared as global, and is not replaced inside of a subcircuit. --- src/frontend/inpcom.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/frontend/inpcom.c b/src/frontend/inpcom.c index c388d667e..4cf3b2edf 100644 --- a/src/frontend/inpcom.c +++ b/src/frontend/inpcom.c @@ -1860,11 +1860,13 @@ static struct inp_read_t inp_read(FILE* fp, int call_depth, const char* dir_name comfile = TRUE; if (call_depth == 0 && !comfile) { - if (!cp_getvar("no_auto_gnd", CP_BOOL, NULL, 0)) + if (!cp_getvar("no_auto_gnd", CP_BOOL, NULL, 0) && !newcompat.ps) insert_new_line(cc, copy(".global gnd"), 1, 0, "internal"); - else + else { insert_new_line( - cc, copy("* gnd is not set to 0 automatically "), 1, 0, "internal"); + cc, copy("* gnd is not set to 0 automatically "), 1, 0, "internal"); + fprintf(stdout, "Note: gnd in a subcircuit is not set to 0 automatically\n"); + } if (!newcompat.lt && !newcompat.ps && !newcompat.s3) { /* process all library section references */ @@ -2295,12 +2297,20 @@ static char *readline(FILE *fd) static void inp_fix_gnd_name(struct card *c) { + bool found_subckt = FALSE; for (; c; c = c->nextcard) { - char *gnd = c->line; + // if inside of a subcircuit, and compatmode is ps, don't replace gnd + if (newcompat.ps) { + if (ciprefix(".subckt", c->line)) + found_subckt = TRUE; + if (ciprefix(".ends", c->line)) + found_subckt = FALSE; + } + // if there is a comment or no gnd, go to next line - if ((*gnd == '*') || !strstr(gnd, "gnd")) + if (found_subckt || (*gnd == '*') || !strstr(gnd, "gnd")) continue; // replace "?gnd?" by "? 0 ?", ? being a ' ' ',' '(' ')'.