Updated copyright text/header in most source files.
[geda-gaf.git] / gnetlist / scheme / gnet-vipec.scm
blob6b4ce821b1a5bff10d4e43b3da2461f53512ef21
1 ;;; gEDA - GPL Electronic Design Automation
2 ;;; gnetlist - gEDA Netlist
3 ;;; Copyright (C) 1998-2010 Ales Hvezda
4 ;;; Copyright (C) 1998-2010 gEDA Contributors (see ChangeLog for details)
5 ;;;
6 ;;; This program is free software; you can redistribute it and/or modify
7 ;;; it under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 2 of the License, or
9 ;;; (at your option) any later version.
10 ;;;
11 ;;; This program is distributed in the hope that it will be useful,
12 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 ;;; GNU General Public License for more details.
15 ;;;
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with this program; if not, write to the Free Software
18 ;;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 (define vipec:analysis-templates
21    (list
22       (cons
23          (cons "VIPEC" " ")
24          (list
25             (list "value" "R=" #t)))
28 (define vipec:component-templates
29    (list
30       (cons 
31          (cons "RESISTOR" "RES")
32          (list 
33             (list "value" "R=" #t "use value attrib for resistance")))
34       (cons
35          (cons "INDUCTOR" "IND")
36          (list
37             (list "value" "L=" #t "use value attrib for inductance")
38             (list "Q" "Q=" #f)))
39       (cons
40          (cons "CAPACITOR" "CAP")
41          (list
42             (list "value" "C=" #t "use value attrib for capacitance")))
43       (cons
44          (cons "TLIN" "TLIN")
45          (list
46             (list "Z" "Z=" #t 50)
47             (list "length" "E=" #t "length attrib for length")
48             (list "F" "F=" #t "F attrib for frequency")))
49       (cons
50          (cons "CLIN" "CLIN")
51          (list
52             (list "ZE" "ZE=" #t)
53             (list "ZO" "ZO=" #t)
54             (list "E" "E=" #t)
55             (list "F" "F=" #t)))
56       (cons
57          (cons "SPARAMBLOCK" "BLOCK")
58          (list
59             (list "filename" "" #t "filename attrib for sparams")))            
62 (define vipec:get-template
63    (lambda (templates device)
64       (if (not (null? templates))
65          (if (string=? device (car (car (car templates))))
66             (car templates)
67             (vipec:get-template (cdr templates) device))
68          (begin
69             (display "Template not found   ")
70             (display device)
71             (newline)
72             (cons (cons device "error") '())))))
74 (define vipec:write-net-name-of-node 
75    (lambda (uref number-of-pin netnumbers port)
76       (if (> number-of-pin 0)
77          (begin          
78             (vipec:write-net-name-of-node uref (- number-of-pin 1) netnumbers port)
79             (let ((pin-name (number->string number-of-pin)))
80                (display (get-net-number (car (gnetlist:get-nets uref (gnetlist:get-attribute-by-pinseq uref pin-name "pinnumber"))) netnumbers) port)
81                (write-char #\space port))))))
83 (define vipec:write-attribs
84    (lambda (package attribs port term)
85       (if (not (null? attribs))
86          (let ((attrib (car attribs))
87                (value (gnetlist:get-package-attribute package (car(car attribs)))))
88             (if (not (string=? value "unknown"))
89                (begin
90                   (display (cadr attrib) port)
91                   (display value port)
92                   (display term port))
93                (if (and (caddr attrib)(not (null? (cdddr attrib))))
94                   (begin
95                      (display (cadr attrib) port)
96                      (display (cadddr attrib) port)
97                      (display term port))))
98          (vipec:write-attribs package (cdr attribs) port term)))))
100 (define vipec:write-gen-component
101    (lambda (package port netnumbers)
102       (let ((template (vipec:get-template vipec:component-templates (get-device package))))
103          (display "\t" port)
104          (display (cdr (car template)) port)
105          (display "\t" port)
106          (vipec:write-net-name-of-node package
107             (length (gnetlist:get-pins package)) netnumbers port)
108          (vipec:write-attribs package (cdr template) port "\t")
109          (display (string-append "\t% " package) port)
110          (newline port))))
112 (define vipec:component-writing
113    (lambda (port ls netnumbers)
114       (if (not (null? ls))
115          (let ((package (car ls))
116                (device (get-device (car ls))))
117             (cond
118                ((string=? device "VIPEC") #t)
119                ((string=? device "SMITH") #t)
120                ((string=? device "GRID") #t)
121                (else (vipec:write-gen-component package port netnumbers)))
122             (vipec:component-writing port (cdr ls) netnumbers)))))
124 (define vipec:misc-components
125    (lambda (netnumbers port)
126 ;;      (display "\tRES\t0 " port)
127 ;;      (display (get-net-number "GND" netnumbers) port)
128 ;;      (display " R=0.00001\t% Assign ground net\n" port)
129       (display "\tDEF2P\t" port)
130       (display (get-net-number "PORT1" netnumbers) port)
131       (display "  " port)
132       (display (get-net-number "PORT2" netnumbers) port)
133       (display "\n\tTERM\t50 50\n" port)))
135 (define vipec:header
136    (lambda (port)
137       (display "% ViPEC RF Netlister\n" port)  
138       (display "% Written by Matthew Ettus\n" port)
139       (display "% Based on code by Bas Gieltjes\n" port)))
141 (define vipec:analysis-block
142    (lambda (packages port)
143       (if (not (null? packages))
144          (begin
145             (if (string=? (get-device (car packages)) "VIPEC")
146                (let ((template (vipec:get-template vipec:analysis-templates "VIPEC")))
147                   (vipec:write-attribs (car packages) (cdr template) port "\n")
148                   (newline port)))
149             (vipec:analysis-block (cdr packages) port)))))
151 (define vipec
152    (lambda (output-filename)
153       (let ((port (open-output-file output-filename))
154             (netnumbers (number-nets all-unique-nets 1)))
155          (vipec:header port)
156          (display "CKT\n" port)
157          (vipec:component-writing port packages netnumbers)
158          (vipec:misc-components netnumbers port)
159          (newline port)
160          (vipec:analysis-block packages port)
161          (close-output-port port))))