jfreeze-ruby-gdsii 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.txt +6 -0
- data/LICENSE.txt +20 -0
- data/README.txt +113 -0
- data/Rakefile +30 -0
- data/bin/rgds-debug +43 -0
- data/bin/rgds-dump +38 -0
- data/bin/rgds-join +98 -0
- data/bin/rgds-layers +53 -0
- data/bin/rgds-sremove +136 -0
- data/bin/rgds-ssplit +113 -0
- data/bin/rgds-stats +134 -0
- data/bin/rgds-structs +41 -0
- data/bin/rgds-tree +167 -0
- data/bin/rgds2rb +99 -0
- data/lib/gdsii.rb +137 -0
- data/lib/gdsii/aref.rb +243 -0
- data/lib/gdsii/bnf.rb +309 -0
- data/lib/gdsii/boundary.rb +53 -0
- data/lib/gdsii/box.rb +65 -0
- data/lib/gdsii/byte_order.rb +36 -0
- data/lib/gdsii/element.rb +172 -0
- data/lib/gdsii/group.rb +98 -0
- data/lib/gdsii/library.rb +518 -0
- data/lib/gdsii/mixins.rb +378 -0
- data/lib/gdsii/node.rb +65 -0
- data/lib/gdsii/path.rb +169 -0
- data/lib/gdsii/property.rb +108 -0
- data/lib/gdsii/record.rb +606 -0
- data/lib/gdsii/record/consts.rb +384 -0
- data/lib/gdsii/record/datatypes/ascii.rb +145 -0
- data/lib/gdsii/record/datatypes/bitarray.rb +101 -0
- data/lib/gdsii/record/datatypes/data.rb +111 -0
- data/lib/gdsii/record/datatypes/int2.rb +67 -0
- data/lib/gdsii/record/datatypes/int4.rb +65 -0
- data/lib/gdsii/record/datatypes/nodata.rb +60 -0
- data/lib/gdsii/record/datatypes/real4.rb +51 -0
- data/lib/gdsii/record/datatypes/real8.rb +120 -0
- data/lib/gdsii/sref.rb +61 -0
- data/lib/gdsii/strans.rb +133 -0
- data/lib/gdsii/structure.rb +352 -0
- data/lib/gdsii/text.rb +203 -0
- data/pkg/ruby-gdsii.gem +46 -0
- data/samples/hello.gds +0 -0
- data/samples/hello.out.rb +84 -0
- data/samples/hello.rb +94 -0
- data/test/baseline/dcp1.gds +0 -0
- data/test/baseline/h_write.gds +0 -0
- data/test/h_pthru.rb +22 -0
- data/test/h_write.rb +117 -0
- data/test/hs_pthru.rb +31 -0
- data/test/l_pthru.rb +23 -0
- data/test/test_gds_group.rb +379 -0
- data/test/test_gds_record.rb +99 -0
- metadata +117 -0
data/CHANGELOG.txt
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2007 Jim Freeze & Dan White
|
2
|
+
Copyright (c) 2007 Intel Corporation
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
6
|
+
in the Software without restriction, including without limitation the rights
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
9
|
+
furnished to do so, subject to the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be included in
|
12
|
+
all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
THE SOFTWARE.
|
data/README.txt
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
|
2
|
+
=== Overview =================================================================
|
3
|
+
|
4
|
+
The GDSII Ruby Library provides an easy-to-use interface using Ruby to reading
|
5
|
+
and writing GDSII files. Details may be found in the "doc" directory or by
|
6
|
+
running "rdoc" on the "lib" directory.
|
7
|
+
|
8
|
+
Contributors:
|
9
|
+
|
10
|
+
- Jim Freeze
|
11
|
+
- Ben Hoefer
|
12
|
+
- James Masters
|
13
|
+
- Matt Welland
|
14
|
+
- Dan White
|
15
|
+
|
16
|
+
Project webspace:
|
17
|
+
|
18
|
+
http://rubyforge.org/projects/gdsii/
|
19
|
+
|
20
|
+
This library is released under the MIT License (see LICENSE.txt)
|
21
|
+
|
22
|
+
=== Installation =============================================================
|
23
|
+
|
24
|
+
The "installation" is easy - simply add the contents in the "lib" directory
|
25
|
+
in this package to a directory where Ruby is installed or set the $RUBYLIB
|
26
|
+
environment variable to include the "lib" directory.
|
27
|
+
|
28
|
+
|
29
|
+
=== Testing ==================================================================
|
30
|
+
|
31
|
+
The GDSII library has been tested on Windows XP, SuSE Linux, SunOS, and HP-UX.
|
32
|
+
To test the library on your own platform and configuration, a number of test
|
33
|
+
suites are located in the "test" directory of this installation package:
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
* test_gds_group.rb
|
38
|
+
|
39
|
+
A unit test of the high-level GDSII methods.
|
40
|
+
|
41
|
+
* test_gds_record.rb
|
42
|
+
|
43
|
+
A unit test of the low-level GDSII methods.
|
44
|
+
|
45
|
+
* h_pthru.rb
|
46
|
+
|
47
|
+
Uses the GDSII high-level methods to read in a GDSII file and then write out
|
48
|
+
the same GDSII file. The file should be identical - or at least just have
|
49
|
+
just EOF null-padding differences.
|
50
|
+
|
51
|
+
* l_pthru.rb
|
52
|
+
|
53
|
+
Uses the GDSII low-level methods to read in a GDSII file and then write out
|
54
|
+
the same GDSII file. The file should be identical - or at least just have
|
55
|
+
just EOF null-padding differences.
|
56
|
+
|
57
|
+
* h_write.rb
|
58
|
+
|
59
|
+
Uses high-level GDSII methods to write out a number of GDSII records using
|
60
|
+
many of the available method calls. This can be useful to verify that the
|
61
|
+
GDSII library is working and the output file can be compared against the
|
62
|
+
file found in ./test/baseline/h_write.gds to ensure that the platform is
|
63
|
+
reading and writing GDSII properly.
|
64
|
+
|
65
|
+
|
66
|
+
=== Utility Scripts ==========================================================
|
67
|
+
|
68
|
+
A few utility scripts have been included in the "bin" directory for general
|
69
|
+
purpose use and/or for reference in using the Ruby GDSII library:
|
70
|
+
|
71
|
+
* gds2rb
|
72
|
+
|
73
|
+
Translates a GDSII file into a Ruby script containing commands to recreate the
|
74
|
+
GDSII file. This might make custom edits to a GDSII file easy by post-
|
75
|
+
processing the script through automation or by hand before running the script
|
76
|
+
to produce an output GDSII file.
|
77
|
+
|
78
|
+
* gdsdebug
|
79
|
+
|
80
|
+
A detailed GDSII "dump" program that can be used to debug issues with a GDSII
|
81
|
+
file that may be somehow corrupt or may be causing the GDSII Ruby file read
|
82
|
+
methods to fail.
|
83
|
+
|
84
|
+
* gdsdump
|
85
|
+
|
86
|
+
A conversion of GDSII data to the "L" file format (ASCII). This can make
|
87
|
+
quickly reviewing GDSII file contents through text very easy.
|
88
|
+
|
89
|
+
* gdslayers
|
90
|
+
|
91
|
+
Lists all layer and data types in the GDSII file.
|
92
|
+
|
93
|
+
* gdssremove
|
94
|
+
|
95
|
+
Removes the specified structure(s) from the GDSII file.
|
96
|
+
|
97
|
+
* gdsssplit
|
98
|
+
|
99
|
+
Extracts the specified structure(s) from the GDSII file and creates separate
|
100
|
+
files for each of the extracted structures.
|
101
|
+
|
102
|
+
* gdsstats
|
103
|
+
|
104
|
+
Reads a GDSII file and produces a statistical summary of the contents of each
|
105
|
+
structure in the file.
|
106
|
+
|
107
|
+
* gdsstructs
|
108
|
+
|
109
|
+
Lists all structure names found in the GDSII file.
|
110
|
+
|
111
|
+
* gdstree
|
112
|
+
|
113
|
+
Prints a hierarchical tree of structures in a GDSII file.
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
begin
|
3
|
+
require 'rake'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'This script should only be accessed via the "rake" command.'
|
6
|
+
puts 'Installation: gem install rake -y'
|
7
|
+
exit
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'rake/testtask'
|
11
|
+
require 'spec/rake/spectask'
|
12
|
+
require 'fileutils'
|
13
|
+
|
14
|
+
task :default => 'test'
|
15
|
+
|
16
|
+
desc 'Run all tests'
|
17
|
+
Rake::TestTask.new('test') do |t|
|
18
|
+
t.libs << 'test'
|
19
|
+
t.pattern = 'test/**/test_*.rb'
|
20
|
+
t.verbose = true
|
21
|
+
end
|
22
|
+
|
23
|
+
desc "RCov"
|
24
|
+
Spec::Rake::SpecTask.new('rcov') do |t|
|
25
|
+
t.spec_opts = ["--format", "specdoc", "--colour"]
|
26
|
+
t.spec_files = Dir['test/test_*.rb'].sort
|
27
|
+
t.libs = ['lib' ]
|
28
|
+
t.rcov = true
|
29
|
+
end
|
30
|
+
|
data/bin/rgds-debug
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
##############################################################################
|
3
|
+
#
|
4
|
+
# == gdsdebug.rb
|
5
|
+
#
|
6
|
+
# Reads a GDSII file and provides record-by-record details as the file is
|
7
|
+
# read. This is useful for debugging any GDSII read issues either by this
|
8
|
+
# library or by another application.
|
9
|
+
#
|
10
|
+
# === Author
|
11
|
+
#
|
12
|
+
# James D. Masters (james.d.masters@gmail.com)
|
13
|
+
#
|
14
|
+
# === History
|
15
|
+
#
|
16
|
+
# * 03/26/2007 (jdm): Initial version
|
17
|
+
#
|
18
|
+
##############################################################################
|
19
|
+
|
20
|
+
|
21
|
+
require 'gdsii/record.rb'
|
22
|
+
include Gdsii
|
23
|
+
|
24
|
+
# usage...
|
25
|
+
if (file_name = ARGV[0]).nil? then
|
26
|
+
abort "
|
27
|
+
Reads a GDSII file and provides record-by-record details as the file is read.
|
28
|
+
This is useful for debugging any GDSII read issues either by this library or
|
29
|
+
by another application.
|
30
|
+
|
31
|
+
Usage: #{File.basename($PROGRAM_NAME)} <gds-file>
|
32
|
+
|
33
|
+
"
|
34
|
+
end
|
35
|
+
|
36
|
+
# display the string representation for each record
|
37
|
+
File.open(file_name, 'rb') do |file|
|
38
|
+
Record.read_debug = true
|
39
|
+
while (rec = Record.read(file)) do
|
40
|
+
# nothing additional required; debug messages will be printed
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
data/bin/rgds-dump
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
##############################################################################
|
3
|
+
#
|
4
|
+
# == gdsdump.rb
|
5
|
+
#
|
6
|
+
# Dumps a GDSII file contents into a text-readable format.
|
7
|
+
#
|
8
|
+
# === Author
|
9
|
+
#
|
10
|
+
# James D. Masters (james.d.masters@gmail.com)
|
11
|
+
#
|
12
|
+
# === History
|
13
|
+
#
|
14
|
+
# * 03/26/2007 (jdm): Initial version
|
15
|
+
#
|
16
|
+
##############################################################################
|
17
|
+
|
18
|
+
|
19
|
+
require 'gdsii/record.rb'
|
20
|
+
include Gdsii
|
21
|
+
|
22
|
+
# usage...
|
23
|
+
if (file_name = ARGV[0]).nil? then
|
24
|
+
abort "
|
25
|
+
Dumps a GDSII file contents into a text-readable format.
|
26
|
+
|
27
|
+
Usage: #{File.basename($PROGRAM_NAME)} <gds-file>
|
28
|
+
|
29
|
+
"
|
30
|
+
end
|
31
|
+
|
32
|
+
# display the string representation for each record
|
33
|
+
File.open(file_name, 'rb') do |file|
|
34
|
+
while (rec = Record.read(file)) do
|
35
|
+
puts rec.to_s
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
data/bin/rgds-join
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
##############################################################################
|
3
|
+
#
|
4
|
+
# == gdssjoin.rb
|
5
|
+
#
|
6
|
+
#
|
7
|
+
# === Author
|
8
|
+
#
|
9
|
+
# James D. Masters (james.d.masters@gmail.com)
|
10
|
+
#
|
11
|
+
# === History
|
12
|
+
#
|
13
|
+
# * 04/04/2007 (jdm): Initial version
|
14
|
+
#
|
15
|
+
##############################################################################
|
16
|
+
|
17
|
+
|
18
|
+
require 'getoptlong'
|
19
|
+
require 'gdsii'
|
20
|
+
include Gdsii
|
21
|
+
|
22
|
+
# Build usage message
|
23
|
+
usage = "
|
24
|
+
Joins structures from multiple GDSII files into a new GDSII file.
|
25
|
+
|
26
|
+
Usage: #{File.basename($PROGRAM_NAME)} [options] <new-gds-file> <other-gds-files...>
|
27
|
+
|
28
|
+
Options:
|
29
|
+
|
30
|
+
-s, --structs Specify structure(s) in a space separated list to join.
|
31
|
+
-f, --force Force overwritting of new GDSII file if it already exists.
|
32
|
+
-h, --help Displays this usage message.
|
33
|
+
|
34
|
+
"
|
35
|
+
|
36
|
+
# Get command-line arguments
|
37
|
+
force = false
|
38
|
+
structs = []
|
39
|
+
|
40
|
+
opts = GetoptLong.new(
|
41
|
+
['--structs', '-s', GetoptLong::OPTIONAL_ARGUMENT],
|
42
|
+
['--force', '-f', GetoptLong::OPTIONAL_ARGUMENT|GetoptLong::NO_ARGUMENT],
|
43
|
+
['--help', '-h', GetoptLong::OPTIONAL_ARGUMENT|GetoptLong::NO_ARGUMENT]
|
44
|
+
)
|
45
|
+
|
46
|
+
opts.each do |option, argument|
|
47
|
+
case option
|
48
|
+
when '--help' : abort usage
|
49
|
+
when '--structs' : structs = argument.split(/\s+/)
|
50
|
+
when '--force' : force = true
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Get GDSII file and output directory from command line
|
55
|
+
new_gds_file, other_gds_files = ARGV[0], ARGV[1..-1]
|
56
|
+
unless new_gds_file and other_gds_files
|
57
|
+
abort usage
|
58
|
+
end
|
59
|
+
|
60
|
+
# Check that output file does not exist (or force is set)
|
61
|
+
if File.exists?(new_gds_file) and not force
|
62
|
+
abort "Output GDSII exists #{new_gds_file} use --force to overwrite"
|
63
|
+
end
|
64
|
+
|
65
|
+
# Open output GDSII file for write
|
66
|
+
File.open(new_gds_file, 'wb') do |outf|
|
67
|
+
|
68
|
+
# Create library header
|
69
|
+
new_lib = Library.new('JOINED.DB')
|
70
|
+
new_lib.write_header(outf)
|
71
|
+
|
72
|
+
# Loop through existing GDSII files and their structures; add to new
|
73
|
+
added_structs = {}
|
74
|
+
other_gds_files.each do |in_gds_file|
|
75
|
+
File.open(in_gds_file, 'rb') do |inf|
|
76
|
+
Library.read_header(inf)
|
77
|
+
Structure.read_each_header(inf) do |struct|
|
78
|
+
if added_structs[struct.name]
|
79
|
+
# already added; flag warning
|
80
|
+
warn "WARNING: Struct #{struct.name} in file #{in_gds_file} already added from file #{added_structs[struct.name]}; ignoring"
|
81
|
+
elsif structs.empty? or structs.member?(struct.name)
|
82
|
+
# no struct list given; or stuct on list
|
83
|
+
struct.write_header(outf)
|
84
|
+
Element.read_each(inf) {|element| element.write(outf)}
|
85
|
+
struct.write_footer(outf)
|
86
|
+
added_structs[struct.name] = in_gds_file
|
87
|
+
else
|
88
|
+
# not on provided list; skip this structure
|
89
|
+
Structure.seek_next(inf)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# Create library footer
|
96
|
+
new_lib.write_footer(outf)
|
97
|
+
|
98
|
+
end
|
data/bin/rgds-layers
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
##############################################################################
|
3
|
+
#
|
4
|
+
# == gdslayers.rb
|
5
|
+
#
|
6
|
+
# Dumps a unique list of layers and their respective datatypes used in this
|
7
|
+
# GDSII file. Each layer/datatype pair is in the form 'LAYER DTYPE' with
|
8
|
+
# a layer on each line.
|
9
|
+
#
|
10
|
+
# === Author
|
11
|
+
#
|
12
|
+
# James D. Masters (james.d.masters@gmail.com)
|
13
|
+
#
|
14
|
+
# === History
|
15
|
+
#
|
16
|
+
# * 03/26/2007 (jdm): Initial version
|
17
|
+
#
|
18
|
+
##############################################################################
|
19
|
+
|
20
|
+
|
21
|
+
require 'getoptlong'
|
22
|
+
require 'gdsii/record.rb'
|
23
|
+
include Gdsii
|
24
|
+
|
25
|
+
# Build usage message
|
26
|
+
if (file_name = ARGV[0]).nil? then
|
27
|
+
abort "
|
28
|
+
Dumps a unique list of layers and their respective datatypes used in this
|
29
|
+
GDSII file. Each layer/datatype pair is in the form 'LAYER DTYPE' with
|
30
|
+
a layer on each line.
|
31
|
+
|
32
|
+
Usage: #{File.basename($PROGRAM_NAME)} <gds-file>
|
33
|
+
|
34
|
+
"
|
35
|
+
end
|
36
|
+
|
37
|
+
# Extract the layer numbers from the GDSII file
|
38
|
+
listed = {}
|
39
|
+
File.open(file_name, 'rb') do |file|
|
40
|
+
layer = nil
|
41
|
+
while (record = Record.read(file)) do
|
42
|
+
case record.type
|
43
|
+
when GRT_LAYER
|
44
|
+
layer = record.data_value
|
45
|
+
when GRT_DATATYPE, GRT_TEXTTYPE, GRT_NODETYPE, GRT_BOXTYPE
|
46
|
+
key = [layer, datatype = record.data_value]
|
47
|
+
puts "#{layer} #{datatype}" unless listed[key]
|
48
|
+
listed[key] = true
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
|
data/bin/rgds-sremove
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
##############################################################################
|
3
|
+
#
|
4
|
+
# == gdssremove.rb
|
5
|
+
#
|
6
|
+
# Removes structures and/or structure references from a GDSII file.
|
7
|
+
#
|
8
|
+
# === Author
|
9
|
+
#
|
10
|
+
# James D. Masters (james.d.masters@gmail.com)
|
11
|
+
#
|
12
|
+
# === History
|
13
|
+
#
|
14
|
+
# * 03/26/2007 (jdm): Initial version
|
15
|
+
#
|
16
|
+
##############################################################################
|
17
|
+
|
18
|
+
|
19
|
+
require 'getoptlong'
|
20
|
+
require 'gdsii/record.rb'
|
21
|
+
include Gdsii
|
22
|
+
|
23
|
+
# Build usage message
|
24
|
+
program = File.basename($PROGRAM_NAME)
|
25
|
+
usage = "
|
26
|
+
Removes structures and/or structure references from a GDSII file.
|
27
|
+
|
28
|
+
Usage: #{File.basename($PROGRAM_NAME)} [options] -s <structs...> <in-gds-file> <out-gds-file>
|
29
|
+
|
30
|
+
Options:
|
31
|
+
|
32
|
+
-s, --structs Specify structure(s) in a space separated list to remove.
|
33
|
+
-f, --force Force overwritting of the output GDSII file if it already
|
34
|
+
exists.
|
35
|
+
-k, --keep-refs Keeps SRef and ARef references (only removes structures).
|
36
|
+
-j, --keep-structs Keeps structure definitions (only removes SRef and ARef).
|
37
|
+
-h, --help Displays this usage message.
|
38
|
+
|
39
|
+
Examples:
|
40
|
+
|
41
|
+
ruby #{program} -s 'TOP SUB1' mydesign.gds outdesign.gds
|
42
|
+
ruby #{program} -k -s 'SUB1'
|
43
|
+
|
44
|
+
"
|
45
|
+
|
46
|
+
# Get command-line arguments
|
47
|
+
force = false
|
48
|
+
structs = nil
|
49
|
+
keep_refs = false
|
50
|
+
keep_structs = false
|
51
|
+
|
52
|
+
opts = GetoptLong.new(
|
53
|
+
['--structs', '-s', GetoptLong::REQUIRED_ARGUMENT],
|
54
|
+
['--force', '-f', GetoptLong::OPTIONAL_ARGUMENT|GetoptLong::NO_ARGUMENT],
|
55
|
+
['--keep-refs', '-k', GetoptLong::OPTIONAL_ARGUMENT|GetoptLong::NO_ARGUMENT],
|
56
|
+
['--keep-structs', '-j', GetoptLong::OPTIONAL_ARGUMENT|GetoptLong::NO_ARGUMENT],
|
57
|
+
['--help', '-h', GetoptLong::OPTIONAL_ARGUMENT|GetoptLong::NO_ARGUMENT]
|
58
|
+
)
|
59
|
+
|
60
|
+
opts.each do |option, argument|
|
61
|
+
case option
|
62
|
+
when '--structs' : structs = argument.split(/\s+/)
|
63
|
+
when '--force' : force = true
|
64
|
+
when '--keep-refs' : keep_refs = true
|
65
|
+
when '--keep-structs' : keep_structs = true
|
66
|
+
when '--help' : abort usage
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# Get GDSII file and output directory from command line
|
71
|
+
in_gds, out_gds = ARGV
|
72
|
+
unless in_gds and out_gds
|
73
|
+
abort usage
|
74
|
+
end
|
75
|
+
|
76
|
+
# Check to see if structs list was not set
|
77
|
+
unless structs
|
78
|
+
abort "\nNo structures specified (-s or --structs)\n\n" + usage
|
79
|
+
end
|
80
|
+
|
81
|
+
# Check that GDSII file is readable
|
82
|
+
unless File.readable? in_gds
|
83
|
+
abort "\nGDSII file does not exist or is not readable: #{in_gds}\n\n"
|
84
|
+
end
|
85
|
+
|
86
|
+
# Check to see if the output GDSII file already exists
|
87
|
+
if File.exists? out_gds and not force
|
88
|
+
abort "\nOutput GDSII file exists: #{out_gds} (use -f or --force to override)\n\n"
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
# Read the GDSII file and write out resulting GDSII file
|
93
|
+
File.open(in_gds, 'rb') do |inf|
|
94
|
+
File.open(out_gds, 'wb') do |outf|
|
95
|
+
|
96
|
+
# set r/w flags
|
97
|
+
remove_struct = false
|
98
|
+
remove_ref = false
|
99
|
+
|
100
|
+
# Read each record in the GDSII file
|
101
|
+
Record.read_each(inf) do |record|
|
102
|
+
|
103
|
+
case record.type
|
104
|
+
when GRT_BGNSTR
|
105
|
+
# read structure name and determine if this should be removed or not
|
106
|
+
if structs.member?(Record.peek(inf).data_value) and not keep_structs
|
107
|
+
remove_struct = true
|
108
|
+
next
|
109
|
+
end
|
110
|
+
when GRT_SREF, GRT_AREF
|
111
|
+
# read referenced name and determine if this should be removed or not
|
112
|
+
if structs.member?(Record.peek(inf).data_value) and not keep_refs
|
113
|
+
remove_ref = true
|
114
|
+
next
|
115
|
+
end
|
116
|
+
when GRT_ENDEL
|
117
|
+
# reset removal flag at the end of a reference definition
|
118
|
+
if remove_ref
|
119
|
+
remove_ref = false
|
120
|
+
next
|
121
|
+
end
|
122
|
+
when GRT_ENDSTR
|
123
|
+
# reset removal flag at the end of a structure definition
|
124
|
+
if remove_struct
|
125
|
+
remove_struct = false
|
126
|
+
next
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
# write the record if desired...
|
131
|
+
record.write(outf) unless remove_struct or remove_ref
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
136
|
+
end
|