From b692c010f9ccf0b89ff1ad653ff1c5a812887cc3 Mon Sep 17 00:00:00 2001 From: Ales Hvezda Date: Thu, 5 Jul 2007 01:43:47 -0400 Subject: [PATCH] Added new gnetlist backend by John P. Doty --- gnetlist/scheme/Makefile.am | 3 +- gnetlist/scheme/gnet-mathematica.scm | 206 +++++++++++++++++++++++++++++++++++ 2 files changed, 208 insertions(+), 1 deletion(-) create mode 100644 gnetlist/scheme/gnet-mathematica.scm diff --git a/gnetlist/scheme/Makefile.am b/gnetlist/scheme/Makefile.am index b1fd79d5e..43f2b96b8 100644 --- a/gnetlist/scheme/Makefile.am +++ b/gnetlist/scheme/Makefile.am @@ -18,7 +18,8 @@ DIST_SCM = gnet-PCB.scm gnet-allegro.scm gnet-bom.scm gnet-geda.scm \ gnet-switcap.scm gnet-spice-sdb.scm gnet-drc2.scm \ gnet-futurenet2.scm gnet-cascade.scm \ gnet-redac.scm gnet-systemc.scm gnet-eagle.scm \ - gnet-pcbpins.scm gnet-calay.scm gnet-osmond.scm + gnet-pcbpins.scm gnet-calay.scm gnet-osmond.scm \ + gnet-mathematica.scm EXTRA_DIST = $(DIST_SCM) $(SCM_SRCS) diff --git a/gnetlist/scheme/gnet-mathematica.scm b/gnetlist/scheme/gnet-mathematica.scm new file mode 100644 index 000000000..381d89c21 --- /dev/null +++ b/gnetlist/scheme/gnet-mathematica.scm @@ -0,0 +1,206 @@ +;;; gEDA - GPL Electronic Design Automation +;;; gnetlist - gEDA Netlist +;;; Copyright (C) 2007 John P. Doty +;;; +;;; This program is free software; you can redistribute it and/or modify +;;; it under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 2 of the License, or +;;; (at your option) any later version. +;;; +;;; This program is distributed in the hope that it will be useful, +;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with this program; if not, write to the Free Software +;;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +;; Netlister for symbolic circuit analysis using Mathematica. +;; See the Mathematica notebook gEDA.nb (obtainable at www.noqsi.com) +;; for usage. + +(define (mathematica:quoted thing port) + (write-char #\" port) + (display thing port) + (write-char #\" port) +) + +(define (mathematica:write-pin-voltages netname pins port) + (if (not (null? pins)) + (let ((pin (car pins))) + (display "v[" port) + (mathematica:quoted (car pin) port) + (display "," port) + (mathematica:quoted (car (cdr pin)) port) + (display "]=v[" port) + (mathematica:quoted netname port) + (display "];" port) + (newline port) + (mathematica:write-pin-voltages netname (cdr pins) port) + ) + ) +) + + +(define (mathematica:write-voltages netnames port) + (if (not (null? netnames)) + (let ((netname (car netnames))) + (mathematica:write-pin-voltages netname + (gnetlist:get-all-connections netname) port) + (mathematica:write-voltages (cdr netnames) port)))) + + +(define (mathematica:write-node-currents pins port) + (let ((pin (car pins))) + (display "i[" port) + (mathematica:quoted (car pin) port) + (display "," port) + (mathematica:quoted (car (cdr pin)) port) + (display "]" port) + (if (not (null? (cdr pins ))) + (begin + (display "+" port) + (mathematica:write-node-currents (cdr pins) port) + ) + ) + ) +) + +(define (mathematica:,newline port) + (display "," port) + (newline port) +) + + +(define (mathematica:write-currents netnames first port) + (if (not (null? netnames)) + (let ((netname (car netnames))) + (if (not (equal? netname "GND")) + (begin + (if (not first) + (mathematica:,newline port) + ) + (mathematica:write-node-currents + (gnetlist:get-all-connections netname) port) + (display "==0" port) + (mathematica:write-currents (cdr netnames) #f port) + ) + (mathematica:write-currents (cdr netnames) first port) + ) + ) + ) +) + +(define (mathematica:write-device-value device value refdes port) + (display (string-downcase device) port) + (display "[value->" port) + (display value port) + (display "][" port) + (mathematica:quoted refdes port) + (display "]" port) +) + +(define (mathematica:write-device-model model refdes port) + (display model port) + (display "[" port) + (mathematica:quoted refdes port) + (display "]" port) + ) + + +(define (mathematica:write-model refdes port) + (let ((device (gnetlist:get-package-attribute refdes "device")) + (value (gnetlist:get-package-attribute refdes "value")) + (model (gnetlist:get-package-attribute refdes "model"))) + (if (equal? model "unknown") + (if (equal? value "unknown") + (mathematica:write-device-value device (string-downcase refdes) + refdes port) + (mathematica:write-device-value device value refdes port) + ) + (mathematica:write-device-model model refdes port) + ) + ) +) + +(define (mathematica:write-models refdeses first port) + (if (not (null? refdeses)) + (let ((refdes (car refdeses))) + (if (not first) + (mathematica:,newline port) + ) + (mathematica:write-model refdes port) + (mathematica:write-models (cdr refdeses) #f port) + ) + ) +) + +(define (mathematica:list-voltages netnames first port) + (if (not (null? netnames)) + (let ((netname (car netnames))) + (if (not (equal? netname "GND")) + (begin + (if (not first) + (mathematica:,newline port) + ) + (display "v[" port) + (mathematica:quoted netname port) + (display "]" port) + (mathematica:list-voltages (cdr netnames) #f port) + ) + (mathematica:list-voltages (cdr netnames) first port) + ) + ) + ) +) + + +(define (mathematica:list-pin-currents pins port) + (if (not (null? pins)) + (let ((pin (car pins))) + (mathematica:,newline port) + (display "i[" port) + (mathematica:quoted (car pin) port) + (display "," port) + (mathematica:quoted (car (cdr pin)) port) + (display "]" port) + (mathematica:list-pin-currents (cdr pins) port) + ) + ) +) + + +(define (mathematica:list-currents netnames port) + (if (not (null? netnames)) + (let ((netname (car netnames))) + (mathematica:list-pin-currents + (gnetlist:get-all-connections netname) port) + (mathematica:list-currents (cdr netnames) port) + ) + ) +) + + +(define (mathematica output-filename) + (let ((port (open-output-file output-filename)) + (nets (gnetlist:get-all-unique-nets "dummy"))) + (mathematica:write-voltages nets port) + (display "nodeEquations={" port) + (newline port) + (mathematica:write-currents nets #t port) + (display "};" port) + (newline port) + (display "modelEquations={" port) + (newline port) + (mathematica:write-models packages #t port) + (display "};" port) + (newline port) + (display "variables={" port) + (newline port) + (mathematica:list-voltages nets #t port) + (mathematica:list-currents nets port) + (display "};" port) + (newline port) + ) +) -- 2.11.4.GIT