1 ;;; gEDA - GPL Electronic Design Automation
2 ;;; gnetlist - gEDA Netlist
3 ;;; Copyright (C) 2007-2010 John P. Doty
5 ;;; This program is free software; you can redistribute it and/or modify
6 ;;; it under the terms of the GNU General Public License as published by
7 ;;; the Free Software Foundation; either version 2 of the License, or
8 ;;; (at your option) any later version.
10 ;;; This program is distributed in the hope that it will be useful,
11 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ;;; GNU General Public License for more details.
15 ;;; You should have received a copy of the GNU General Public License
16 ;;; along with this program; if not, write to the Free Software
17 ;;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 ;; Netlister for symbolic circuit analysis using Mathematica.
20 ;; See the Mathematica notebook gEDA.nb (obtainable at www.noqsi.com)
23 (define (mathematica:quoted thing port)
29 (define (mathematica:write-pin-voltages netname pins port)
30 (if (not (null? pins))
31 (let ((pin (car pins)))
33 (mathematica:quoted (car pin) port)
35 (mathematica:quoted (car (cdr pin)) port)
37 (mathematica:quoted netname port)
40 (mathematica:write-pin-voltages netname (cdr pins) port)
46 (define (mathematica:write-voltages netnames port)
47 (if (not (null? netnames))
48 (let ((netname (car netnames)))
49 (mathematica:write-pin-voltages netname
50 (gnetlist:get-all-connections netname) port)
51 (mathematica:write-voltages (cdr netnames) port))))
54 (define (mathematica:write-node-currents pins port)
55 (let ((pin (car pins)))
57 (mathematica:quoted (car pin) port)
59 (mathematica:quoted (car (cdr pin)) port)
61 (if (not (null? (cdr pins )))
64 (mathematica:write-node-currents (cdr pins) port)
70 (define (mathematica:,newline port)
76 (define (mathematica:write-currents netnames first port)
77 (if (not (null? netnames))
78 (let ((netname (car netnames)))
79 (if (not (equal? netname "GND"))
82 (mathematica:,newline port)
84 (mathematica:write-node-currents
85 (gnetlist:get-all-connections netname) port)
87 (mathematica:write-currents (cdr netnames) #f port)
89 (mathematica:write-currents (cdr netnames) first port)
95 (define (mathematica:write-device-value device value refdes port)
96 (display (string-downcase device) port)
97 (display "[value->" port)
100 (mathematica:quoted refdes port)
104 (define (mathematica:write-device-model model refdes port)
107 (mathematica:quoted refdes port)
112 (define (mathematica:write-model refdes port)
113 (let ((device (gnetlist:get-package-attribute refdes "device"))
114 (value (gnetlist:get-package-attribute refdes "value"))
115 (model (gnetlist:get-package-attribute refdes "model")))
116 (if (equal? model "unknown")
117 (if (equal? value "unknown")
118 (mathematica:write-device-value device (string-downcase refdes)
120 (mathematica:write-device-value device value refdes port)
122 (mathematica:write-device-model model refdes port)
127 (define (mathematica:write-models refdeses first port)
128 (if (not (null? refdeses))
129 (let ((refdes (car refdeses)))
131 (mathematica:,newline port)
133 (mathematica:write-model refdes port)
134 (mathematica:write-models (cdr refdeses) #f port)
139 (define (mathematica:list-voltages netnames first port)
140 (if (not (null? netnames))
141 (let ((netname (car netnames)))
142 (if (not (equal? netname "GND"))
145 (mathematica:,newline port)
148 (mathematica:quoted netname port)
150 (mathematica:list-voltages (cdr netnames) #f port)
152 (mathematica:list-voltages (cdr netnames) first port)
159 (define (mathematica:list-pin-currents pins port)
160 (if (not (null? pins))
161 (let ((pin (car pins)))
162 (mathematica:,newline port)
164 (mathematica:quoted (car pin) port)
166 (mathematica:quoted (car (cdr pin)) port)
168 (mathematica:list-pin-currents (cdr pins) port)
174 (define (mathematica:list-currents netnames port)
175 (if (not (null? netnames))
176 (let ((netname (car netnames)))
177 (mathematica:list-pin-currents
178 (gnetlist:get-all-connections netname) port)
179 (mathematica:list-currents (cdr netnames) port)
185 (define (mathematica output-filename)
186 (let ((port (open-output-file output-filename))
187 (nets (gnetlist:get-all-unique-nets "dummy")))
188 (mathematica:write-voltages nets port)
189 (display "nodeEquations={" port)
191 (mathematica:write-currents nets #t port)
194 (display "modelEquations={" port)
196 (mathematica:write-models packages #t port)
199 (display "variables={" port)
201 (mathematica:list-voltages nets #t port)
202 (mathematica:list-currents nets port)