ruby-gdsii 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/LICENSE.txt +20 -0
  2. data/README.txt +113 -0
  3. data/bin/rgds-debug +43 -0
  4. data/bin/rgds-dump +38 -0
  5. data/bin/rgds-join +98 -0
  6. data/bin/rgds-layers +53 -0
  7. data/bin/rgds-sremove +135 -0
  8. data/bin/rgds-ssplit +113 -0
  9. data/bin/rgds-stats +134 -0
  10. data/bin/rgds-structs +41 -0
  11. data/bin/rgds-tree +166 -0
  12. data/bin/rgds2rb +99 -0
  13. data/lib/gdsii.rb +137 -0
  14. data/lib/gdsii/aref.rb +243 -0
  15. data/lib/gdsii/bnf.rb +309 -0
  16. data/lib/gdsii/boundary.rb +53 -0
  17. data/lib/gdsii/box.rb +65 -0
  18. data/lib/gdsii/byte_order.rb +36 -0
  19. data/lib/gdsii/element.rb +172 -0
  20. data/lib/gdsii/group.rb +98 -0
  21. data/lib/gdsii/library.rb +518 -0
  22. data/lib/gdsii/mixins.rb +378 -0
  23. data/lib/gdsii/node.rb +65 -0
  24. data/lib/gdsii/path.rb +169 -0
  25. data/lib/gdsii/property.rb +108 -0
  26. data/lib/gdsii/record.rb +606 -0
  27. data/lib/gdsii/record/consts.rb +384 -0
  28. data/lib/gdsii/record/datatypes/ascii.rb +145 -0
  29. data/lib/gdsii/record/datatypes/bitarray.rb +101 -0
  30. data/lib/gdsii/record/datatypes/data.rb +111 -0
  31. data/lib/gdsii/record/datatypes/int2.rb +67 -0
  32. data/lib/gdsii/record/datatypes/int4.rb +65 -0
  33. data/lib/gdsii/record/datatypes/nodata.rb +60 -0
  34. data/lib/gdsii/record/datatypes/real4.rb +51 -0
  35. data/lib/gdsii/record/datatypes/real8.rb +120 -0
  36. data/lib/gdsii/sref.rb +61 -0
  37. data/lib/gdsii/strans.rb +133 -0
  38. data/lib/gdsii/structure.rb +352 -0
  39. data/lib/gdsii/text.rb +203 -0
  40. data/pkg/ruby-gdsii.gem +23 -0
  41. data/samples/hello.gds +0 -0
  42. data/samples/hello.out.rb +84 -0
  43. data/samples/hello.rb +94 -0
  44. data/test/baseline/dcp1.gds +0 -0
  45. data/test/baseline/h_write.gds +0 -0
  46. data/test/h_pthru.rb +22 -0
  47. data/test/h_write.rb +117 -0
  48. data/test/hs_pthru.rb +31 -0
  49. data/test/l_pthru.rb +23 -0
  50. data/test/test_gds_group.rb +379 -0
  51. data/test/test_gds_record.rb +99 -0
  52. metadata +118 -0
@@ -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.
@@ -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.
@@ -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: gdsdebug.rb <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
+
@@ -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: gdsdump.rb <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
+
@@ -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: gdssjoin.rb [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
@@ -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: gdslayers.rb <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
+
@@ -0,0 +1,135 @@
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
+ usage = "
25
+ Removes structures and/or structure references from a GDSII file.
26
+
27
+ Usage: gdssremove.rb [options] -s <structs...> <in-gds-file> <out-gds-file>
28
+
29
+ Options:
30
+
31
+ -s, --structs Specify structure(s) in a space separated list to remove.
32
+ -f, --force Force overwritting of the output GDSII file if it already
33
+ exists.
34
+ -k, --keep-refs Keeps SRef and ARef references (only removes structures).
35
+ -j, --keep-structs Keeps structure definitions (only removes SRef and ARef).
36
+ -h, --help Displays this usage message.
37
+
38
+ Examples:
39
+
40
+ ruby gdssremove.rb -s 'TOP SUB1' mydesign.gds outdesign.gds
41
+ ruby gdssremove.rb -k -s 'SUB1'
42
+
43
+ "
44
+
45
+ # Get command-line arguments
46
+ force = false
47
+ structs = nil
48
+ keep_refs = false
49
+ keep_structs = false
50
+
51
+ opts = GetoptLong.new(
52
+ ['--structs', '-s', GetoptLong::REQUIRED_ARGUMENT],
53
+ ['--force', '-f', GetoptLong::OPTIONAL_ARGUMENT|GetoptLong::NO_ARGUMENT],
54
+ ['--keep-refs', '-k', GetoptLong::OPTIONAL_ARGUMENT|GetoptLong::NO_ARGUMENT],
55
+ ['--keep-structs', '-j', GetoptLong::OPTIONAL_ARGUMENT|GetoptLong::NO_ARGUMENT],
56
+ ['--help', '-h', GetoptLong::OPTIONAL_ARGUMENT|GetoptLong::NO_ARGUMENT]
57
+ )
58
+
59
+ opts.each do |option, argument|
60
+ case option
61
+ when '--structs' : structs = argument.split(/\s+/)
62
+ when '--force' : force = true
63
+ when '--keep-refs' : keep_refs = true
64
+ when '--keep-structs' : keep_structs = true
65
+ when '--help' : abort usage
66
+ end
67
+ end
68
+
69
+ # Get GDSII file and output directory from command line
70
+ in_gds, out_gds = ARGV
71
+ unless in_gds and out_gds
72
+ abort usage
73
+ end
74
+
75
+ # Check to see if structs list was not set
76
+ unless structs
77
+ abort "\nNo structures specified (-s or --structs)\n\n" + usage
78
+ end
79
+
80
+ # Check that GDSII file is readable
81
+ unless File.readable? in_gds
82
+ abort "\nGDSII file does not exist or is not readable: #{in_gds}\n\n"
83
+ end
84
+
85
+ # Check to see if the output GDSII file already exists
86
+ if File.exists? out_gds and not force
87
+ abort "\nOutput GDSII file exists: #{out_gds} (use -f or --force to override)\n\n"
88
+ end
89
+
90
+
91
+ # Read the GDSII file and write out resulting GDSII file
92
+ File.open(in_gds, 'rb') do |inf|
93
+ File.open(out_gds, 'wb') do |outf|
94
+
95
+ # set r/w flags
96
+ remove_struct = false
97
+ remove_ref = false
98
+
99
+ # Read each record in the GDSII file
100
+ Record.read_each(inf) do |record|
101
+
102
+ case record.type
103
+ when GRT_BGNSTR
104
+ # read structure name and determine if this should be removed or not
105
+ if structs.member?(Record.peek(inf).data_value) and not keep_structs
106
+ remove_struct = true
107
+ next
108
+ end
109
+ when GRT_SREF, GRT_AREF
110
+ # read referenced name and determine if this should be removed or not
111
+ if structs.member?(Record.peek(inf).data_value) and not keep_refs
112
+ remove_ref = true
113
+ next
114
+ end
115
+ when GRT_ENDEL
116
+ # reset removal flag at the end of a reference definition
117
+ if remove_ref
118
+ remove_ref = false
119
+ next
120
+ end
121
+ when GRT_ENDSTR
122
+ # reset removal flag at the end of a structure definition
123
+ if remove_struct
124
+ remove_struct = false
125
+ next
126
+ end
127
+ end
128
+
129
+ # write the record if desired...
130
+ record.write(outf) unless remove_struct or remove_ref
131
+
132
+ end
133
+
134
+ end
135
+ end