From 14a61590fb5e50ea55911c653c6289c14a7e3b51 Mon Sep 17 00:00:00 2001 From: winddevil <1160712160@qq.com> Date: Thu, 7 Dec 2023 12:20:21 +0800 Subject: [PATCH 1/4] fixed up the class Parser can not parser subckt by a mistake,that mistakely use isinstance to compare 'SubCircuitStatement' and 'SubCircuit' --- PySpice/Spice/Parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PySpice/Spice/Parser.py b/PySpice/Spice/Parser.py index 3fcfda71..94e523a5 100644 --- a/PySpice/Spice/Parser.py +++ b/PySpice/Spice/Parser.py @@ -1005,7 +1005,7 @@ def _build_circuit(circuit, statements, ground): statement.build(circuit, ground) elif isinstance(statement, Model): statement.build(circuit) - elif isinstance(statement, SubCircuit): + elif isinstance(statement, SubCircuitStatement): subcircuit = statement.build(ground) # Fixme: ok ??? circuit.subcircuit(subcircuit) From 4cd3fb5c5d8e51334755e402402123dc85768d32 Mon Sep 17 00:00:00 2001 From: winddevil <1160712160@qq.com> Date: Mon, 11 Dec 2023 13:55:02 +0800 Subject: [PATCH 2/4] let parser support 'inc' and 'include' --- PySpice/Spice/Parser.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/PySpice/Spice/Parser.py b/PySpice/Spice/Parser.py index 94e523a5..37f85bdb 100644 --- a/PySpice/Spice/Parser.py +++ b/PySpice/Spice/Parser.py @@ -263,9 +263,13 @@ class Include(Statement): ############################################## def __init__(self, line): + if str(line).lower().startswith('.include'): + super().__init__(line, statement='include') + self._include = self._line.right_of('.include').strip('"') + else: + super().__init__(line, statement='inc') + self._include = self._line.right_of('.inc').strip('"') - super().__init__(line, statement='include') - self._include = self._line.right_of('.include').strip('"') ############################################## @@ -927,12 +931,12 @@ def _parse(self, lines, recurse=False, section=None): elif lower_case_text.startswith('model'): model = Model(line) scope.append(model) - elif lower_case_text.startswith('include'): + elif lower_case_text.startswith('include') or lower_case_text.startswith('inc'): incl = Include(line) scope.append(incl) if recurse: from .Library import SpiceLibrary - incl_path = os.path.join(str(self._path.directory_part()), str(incl)) + incl_path = os.path.join(str(os.path.dirname(self._path)), str(incl)) self.incl_libs.append(SpiceLibrary(root_path=incl_path, recurse=recurse)) elif lower_case_text.startswith('lib'): lib = Lib(line) From 05d8ce30fe814e4d4440424daa45e4875c9eb120 Mon Sep 17 00:00:00 2001 From: winddevil <1160712160@qq.com> Date: Fri, 15 Dec 2023 20:31:10 +0800 Subject: [PATCH 3/4] fix up if include a reletive path,set work dictionary --- PySpice/Spice/Parser.py | 1 + 1 file changed, 1 insertion(+) diff --git a/PySpice/Spice/Parser.py b/PySpice/Spice/Parser.py index 37f85bdb..6b0bd5f9 100644 --- a/PySpice/Spice/Parser.py +++ b/PySpice/Spice/Parser.py @@ -825,6 +825,7 @@ def __init__(self, path=None, source=None, end_of_line_comment=('$', '//', ';'), # Fixme: empty source self._path = path # For use by _parse() when recursing through files. + os.chdir(os.path.dirname(self._path)) if path is not None: with open(str(path), 'r') as f: From b87d41c025b2e6415ec3d076759eb137b6fbfc8c Mon Sep 17 00:00:00 2001 From: winddevil <1160712160@qq.com> Date: Sat, 16 Dec 2023 15:26:09 +0800 Subject: [PATCH 4/4] There is another problem that ngspice not only print --- PySpice/Spice/NgSpice/Shared.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PySpice/Spice/NgSpice/Shared.py b/PySpice/Spice/NgSpice/Shared.py index 183c08a4..e99a65c6 100644 --- a/PySpice/Spice/NgSpice/Shared.py +++ b/PySpice/Spice/NgSpice/Shared.py @@ -618,7 +618,7 @@ def _send_char(message_c, ngspice_id, user_data): prefix, _, content = message.partition(' ') if prefix == 'stderr': self._stderr.append(content) - if content.startswith('Warning:'): + if content.startswith('Warning:') or content.startswith('Note:') or content.startswith('Trying gmin'): func = self._logger.warning # elif content.startswith('Warning:'): else: @@ -847,7 +847,7 @@ def exec_command(self, command, join_lines=True): if rc: # Fixme: when not 0 ??? raise NameError("ngSpice_Command '{}' returned {}".format(command, rc)) - if self._error_in_stdout or self._error_in_stderr: + if self._error_in_stdout or self._error_in_stderr: #when run _error_in_stderr have been set raise NgSpiceCommandError("Command '{}' failed".format(command)) if join_lines: