Common Lisp GDSII Library

Download

github
Dependency: ieee-floats

Support

github pull request

GDSII Records

GDSII format
(defstruct propvalue ascii)
(defstruct propattr i)
(defstruct datatype i)
(defstruct pathtype i)
(defstruct texttype i)
(defstruct boxtype i)
(defstruct width i)
(defstruct strng ascii)
(defstruct layer i)
(defstruct sname ascii)
(defstruct strans uvec)
(defstruct colrow uvec)
(defstruct presentation uvec)
(defstruct angle r64)
(defstruct mag r64)
(defstruct xy ivec)
(defstruct box 
  layer 
  strans angle xy       
  boxtype          
  propattr propvalue)
(defstruct text     
  layer strng
  strans angle xy mag 
  texttype presentation 
  propattr propvalue)
(defstruct asref     
  sname 
  strans angle xy colrow 
  propattr propvalue)
(defstruct sref     
  sname 
  strans angle xy 
  propattr propvalue)
(defstruct path     
  layer 
  strans angle xy width 
  datatype pathtype 
  propattr propvalue)
(defstruct boundary 
  layer 
  strans angle xy       
  (datatype (make-datatype :i 0))
  propattr propvalue)
(defstruct timestamp 
  (year   (nth 0 (cdddr(reverse(multiple-value-list(decode-universal-time(get-universal-time)))))))
  (month  (nth 1 (cdddr(reverse(multiple-value-list(decode-universal-time(get-universal-time)))))))
  (day    (nth 2 (cdddr(reverse(multiple-value-list(decode-universal-time(get-universal-time)))))))
  (hour   (nth 3 (cdddr(reverse(multiple-value-list(decode-universal-time(get-universal-time)))))))
  (minute (nth 4 (cdddr(reverse(multiple-value-list(decode-universal-time(get-universal-time)))))))
  (sec    (nth 5 (cdddr(reverse(multiple-value-list(decode-universal-time(get-universal-time))))))))
(defstruct endel)
(defstruct endstr)
(defstruct strname ascii)
(defstruct str 
  (times (list (make-timestamp) (make-timestamp)))
  name elms)
(defstruct units 
  (sizes '(0.001d0 1.0d-9)) 
  strs)
(defstruct generations 
  (copies 3))
(defstruct endlib)
(defstruct libname ascii)
(defstruct lib 
  (times (list (make-timestamp) (make-timestamp)))
  name elms)
(defstruct header 
  (version 5))
(defstruct gds 
  (header (make-header)) 
  libs)

Fucntion and variable reference

[Function]
read-gds stream -> struct

[Function]
write-gds struct -> stream

Example1

(let ((e (list)))
  (with-open-file
    (s "link_joint_loop_smic55.gds"
       :direction :input
       :element-type '(unsigned-byte 8))
    (setf e (read-gds s)))
  (with-open-file
    (s "130.gds"
       :direction :output
       :if-does-not-exist :create
       :if-exists :supersede
       :element-type '(unsigned-byte 8))
    (write-gds s e)))

Example2

(defun chopline (line n)
  (let*((l1 line)
        (p0 (list (pop l1) (pop l1)))
        (p1 (subseq l1 0 2))
        (dx (round(float(/ (- (nth 0 p1) (nth 0 p0)) n))))
        (dy (round(float(/ (- (nth 1 p1) (nth 1 p0)) n)))))
    (do ((k (1- n) (1- k))
         (x (- (nth 0 p1) dx) (- x dx))
         (y (- (nth 1 p1) dy) (- y dy)))
      ((<= k 0) 
       (let ()
         (push (nth 1 p0) l1)
         (push (nth 0 p0) l1)
         ))
      (push y l1)
      (push x l1))
    l1))
(defun rotate (l a)
  (let*((x (- (nth 2 l) (nth 0 l)))
        (y (- (nth 3 l) (nth 1 l))))
    (list
      (nth 0 l)
      (nth 1 l)
      (+ (nth 0 l) (round(float(- (* x (cos a)) (* y (sin a))))))
      (+ (nth 1 l) (round(float(+ (* x (sin a)) (* y (cos a))))))
      )))
(defun scale (l a)
  (let*((x (- (nth 2 l) (nth 0 l)))
        (y (- (nth 3 l) (nth 1 l))))
    (list
      (nth 0 l)
      (nth 1 l)
      (+ (nth 0 l) (round(float(* a x))))
      (+ (nth 1 l) (round(float(* a y))))
      )))
(defun chop3rotatescale (l ra sa)
  (let*((l1 (chopline (subseq l 0 4) 3))
        (l2 (scale (rotate (subseq l1 2 6) ra) sa))
        (l3 (append (subseq l1 0 2) l2 (subseq l1 4))))
    l3))
(defun chop3rotatescalelines (l ra sa)
  (let ((l1 l)
        (l2 (list)))
    (do ((l3 (let ((p4 (list)))
               (dotimes (k 4) (push (pop l1) p4))
               (reverse p4))
             (let ((p4 (list)))
               (dotimes (k 2) (push (pop l1) p4))
               (append (subseq l3 2) (reverse p4)))))
      ((< (length l1) 2) (append (append l2 (chop3rotatescale l3 ra sa)) l1))
      (setf l2 (append l2 (chop3rotatescale l3 ra sa))))))
(defun chop3rotatescalelinesloop (l ra sa k)
  (do ((r l (chop3rotatescalelines r ra sa))
       (j k (- j 1)))
    ((< j 0) r)))
(defun move (l p)
  (let ((k -1))
    (map 'list
         (lambda (li)
           (+ li (nth (rem (incf k) 2) p)))
         l)))
(let*((k 3)
	  (ivec1 
        (chop3rotatescalelinesloop 
          (append
            (rotate '(0 0 50000 0) (* pi 1/3))
            '(50000 0)
            '(0 0)
            )
          (* pi 1/3) 1 k))
      (ivec2 
        (chop3rotatescalelinesloop 
          (append
            (rotate '(0 0 0 50000) (* pi -1/3))
            '(0 50000)
            '(0 0)
            )
          (* pi 1/3) 1 k))
      (ivec3 
        (chop3rotatescalelinesloop 
          (append
            (rotate '(0 0 50000 50000) (* pi 1/3))
            '(50000 50000)
            '(0 0)
            )
          (* pi 1/3) 1 k))
      (ivec4 
        (chop3rotatescalelinesloop 
          '(0 0
            50000 0
            50000 50000
            0 50000
            0 0)
          (* pi 1/4) (/ 1 (expt 2 0.5)) k))
      (ivec5 
        (chop3rotatescalelinesloop 
          '(0 0
            0 50000
            50000 50000
            50000 0
            0 0)
          (* pi 1/4) (/ 1 (expt 2 0.5)) k))
      (ivec6 
        (chop3rotatescalelinesloop 
          '(0 0
            50000 50000
            0 100000
            -50000 50000
            0 0)
          (* pi -1/4) (/ 1 (expt 2 0.5)) k))
	   (ivec7 
        (chop3rotatescalelinesloop 
          '(0 0
            50000 0
            50000 25000
            0 25000
            0 0)
          (* pi -1/4) (/ 1 (expt 2 0.5)) k))
	   (ivec8 
        (chop3rotatescalelinesloop 
          '(0 0
            0 50000 
            25000 50000
            25000 0
            0 0)
          (* pi -1/4) (/ 1 (expt 2 0.5)) k))
	  (p0 '(75000 25000))
      (cell1 (make-str 
               :name (make-strname :ascii "cell1")
               :elms (list 
                       (make-path 
                         :layer (make-layer :i 61) 
                         :width (make-width :i 100) 
                         :xy (make-xy :ivec (move ivec1 p0)))
                       (make-path 
                         :layer (make-layer :i 62) 
                         :width (make-width :i 110) 
                         :xy (make-xy :ivec (move ivec2 p0)))
                       (make-path 
                         :layer (make-layer :i 63) 
                         :width (make-width :i 120) 
                         :xy (make-xy :ivec (move ivec3 p0)))
                       (make-path 
                         :layer (make-layer :i 64) 
                         :width (make-width :i 130) 
                         :xy (make-xy :ivec (move ivec4 p0)))
                       (make-path 
                         :layer (make-layer :i 65) 
                         :width (make-width :i 140) 
                         :xy (make-xy :ivec (move ivec5 p0)))
                       (make-path 
                         :layer (make-layer :i 66) 
                         :width (make-width :i 150) 
                         :xy (make-xy :ivec (move ivec6 p0)))
					   (make-path 
                         :layer (make-layer :i 67) 
                         :width (make-width :i 160) 
                         :xy (make-xy :ivec (move ivec7 p0)))
					   (make-path 
                         :layer (make-layer :i 68) 
                         :width (make-width :i 170) 
                         :xy (make-xy :ivec (move ivec8 p0)))
                       )))
      (units1 (make-units :strs (list cell1)))
      (lib1 (make-lib :name (make-libname :ascii "shit") :elms (list units1)))
      (gds1 (make-gds :libs (list lib1))))
  (with-open-file
    (s "130_2.gds"
       :direction :output
       :if-does-not-exist :create
       :if-exists :supersede
       :element-type '(unsigned-byte 8))
    (write-gds s gds1)))

email: bah4ie@outlook.com or bahie694@gmail.com
Thu Mar 27 01:01:14 JST 2025