NAME
GDS2 - GDS2 stream module
SYNOPSIS
This is GDS2, a module for creating programs to read and/or write GDS2 files.
Send feedback/suggestions to perl -le '$_=q(Zpbhgnpe@pvnt.uxa);$_=~tr/n-sa-gt-zh-mZ/a-zS/;print;'
COPYRIGHT
Author: Ken Schumack (c) 1999-2017. All rights reserved. This module is free software. It may be used, redistributed and/or modified under the terms of the Perl Artistic License. ( see http://www.perl.com/pub/a/language/misc/Artistic.html ) Have fun, Ken
Schumack@cpan.org
DESCRIPTION
GDS2 allows you to read and write GDS2 files record by record in a stream fashion which inherently uses little memory. It is capable but not fast. If you have large files you may be happier using the C/C++ http://sourceforge.net/projects/gds2/ which can easily be used by Perl.
Examples
Layer change:
here's a bare bones script to change all layer 59 to 66 given a file to
read and a new file to create.
my $fileName1 = $ARGV [0];
my $fileName2 = $ARGV [1];
my $gds2File1 = new GDS2( -fileName => $fileName1 );
my $gds2File2 = new GDS2( -fileName => ">$fileName2" );
while ( my $record = $gds2File1 -> readGds2Record)
{
if ( $gds2File1 -> returnLayer == 59)
{
$gds2File2 -> printLayer( -num =>66);
}
else
{
$gds2File2 -> printRecord( -data => $record );
}
}
Gds2 dump :
here's a complete program to dump the contents of a stream file.
$\= "\n" ;
my $gds2File = new GDS2( -fileName => $ARGV [0]);
while ( $gds2File -> readGds2Record)
{
print $gds2File -> returnRecordAsString;
}
my $gds2File = new GDS2( -fileName => $ARGV [0]);
while ( $gds2File -> readGds2Record)
{
print $gds2File -> returnRecordAsString( -compact =>1);
}
Dump from the command line of a bzip2 compressed file:
perl -MGDS2 -MFileHandle -MIPC::Open3 -e '$f1=new FileHandle;$f0=new FileHandle;open3($f0,$f1,$f1,"bzcat test.gds.bz2");$gds=new GDS2(-fileHandle=>$f1);while($gds->readGds2Record){print $gds->returnRecordAsString(-compact=>1)}'
Create a complete GDS2 stream file from scratch:
my $gds2File = new GDS2( -fileName => '>test.gds' );
$gds2File -> printInitLib( -name => 'testlib' );
$gds2File -> printBgnstr( -name => 'test' );
$gds2File -> printPath(
-layer =>6,
-pathType =>0,
-width =>2.4,
-xy =>[0,0, 10.5,0, 10.5,3.3],
);
$gds2File -> printSref(
-name => 'contact' ,
-xy =>[4,5.5],
);
$gds2File -> printAref(
-name => 'contact' ,
-columns =>2,
-rows =>3,
-xy =>[0,0, 10,0, 0,15],
);
$gds2File -> printEndstr;
$gds2File -> printBgnstr( -name => 'contact' );
$gds2File -> printBoundary(
-layer =>10,
-xy =>[0,0, 1,0, 1,1, 0,1],
);
$gds2File -> printEndstr;
$gds2File -> printEndlib();
|
################################################################################
METHODS
new - open gds2 file
usage:
my $gds2File = new GDS2( -fileName => "filename.gds2" );
my $gds2File2 = new GDS2( -fileName => ">filename.gds2" );
-or- provide your own fileHandle:
my $gds2File = new GDS2( -fileHandle => $fh );
|
fileNum - file number...
close - close gds2 file
usage:
$gds2File -> close ;
-or-
$gds2File -> close ( -markEnd =>1);
$gds2File -> close ( -pad =>2048);
|
High Level Write Methods
printInitLib() - Does all the things needed to start a library, writes HEADER,BGNLIB,LIBNAME,and UNITS records
The default is to create a library with a default unit of 1 micron that has a resolution of 1000. To get this set uUnit to 0.001 (1/1000) and the dbUnit to 1/1000th of a micron (1e-9). usage: $gds2File -> printInitLib(-name => "testlib", ## required -isoDate => 0|1 ## (optional) use ISO 4 digit date 2001 vs 101 -uUnit => real number ## (optional) default is 0.001 -dbUnit => real number ## (optional) default is 1e-9 );
note:
remember to close library with printEndlib()
|
printBgnstr - Does all the things needed to start a structure definition
usage:
$gds2File -> printBgnstr( -name => "nand3"
-isoDate => 1|0
);
note:
remember to close with printEndstr()
|
printPath - prints a gds2 path
usage:
$gds2File -> printPath(
-layer =>
-dataType =>
-pathType =>
-width =>
-unitWidth =>
-xy =>\ @array ,
-xyInt =>\ @array ,
);
note:
layer defaults to 0 if -layer not used
pathType defaults to 0 if -pathType not used
pathType 0 = square end
1 = round end
2 = square - extended 1/2 width
4 = custom plus variable path extension...
width defaults to 0.0 if -width not used
|
printBoundary - prints a gds2 boundary
usage:
$gds2File -> printBoundary(
-layer =>
-dataType =>
-xy =>\ @array ,
-xyInt =>\ @array ,
);
note:
layer defaults to 0 if -layer not used
dataType defaults to 0 if -dataType not used
|
printSref - prints a gds2 Structure REFerence
usage:
$gds2File -> printSref(
-name =>string,
-xy =>\ @array ,
-xyInt =>\ @array ,
-angle =>
-mag =>
-reflect =>0|1
);
note:
best not to specify angle or mag if not needed
|
printAref - prints a gds2 Array REFerence
usage:
$gds2File -> printAref(
-name =>string,
-columns =>
-rows =>
-xy =>\ @array ,
-xyInt =>\ @array ,
-angle =>
-mag =>
-reflect =>0|1
);
note:
best not to specify angle or mag if not needed
xyList: 1st coord: origin, 2nd coord: X of col * xSpacing + origin, 3rd coord: Y of row * ySpacing + origin
|
printText - prints a gds2 Text
usage:
$gds2File -> printText(
-string =>string,
-layer =>
-textType =>
-font =>
-top, or -middle, -bottom,
-left, or -center, or -right,
-xy =>\ @array ,
-xyInt =>\ @array ,
-x =>
-y =>
-angle =>
-mag =>
-reflect =>
);
note:
best not to specify reflect, angle or mag if not needed
|
Low Level Generic Write Methods
saveGds2Record() - low level method to create a gds2 record given record type and data (if required). Data of more than one item should be given as a list.
NOTE: THIS ONLY USES GDS2 OBJECT TO GET RESOLUTION
usage:
saveGds2Record(
-type =>string,
-data =>data_If_Needed,
-scale =>
-snap =>
);
examples:
my $gds2File = new GDS2( -fileName => ">$fileName" );
my $record = $gds2File -> saveGds2Record( -type => 'header' , -data =>3);
$gds2FileOut -> printGds2Record( -type => 'record' , -data => $record );
|
printGds2Record() - low level method to print a gds2 record given record type and data (if required). Data of more than one item should be given as a list.
usage:
printGds2Record(
-type =>string,
-data =>data_If_Needed,
-scale =>
-snap =>
);
examples:
my $gds2File = new GDS2( -fileName => ">$fileName" );
$gds2File -> printGds2Record( -type => 'header' , -data =>3);
$gds2File -> printGds2Record( -type => 'bgnlib' , -data =>[99,12,1,22,33,0,99,12,1,22,33,9]);
$gds2File -> printGds2Record( -type => 'libname' , -data => "testlib" );
$gds2File -> printGds2Record( -type => 'units' , -data =>[0.001, 1e-9]);
$gds2File -> printGds2Record( -type => 'bgnstr' , -data =>[99,12,1,22,33,0,99,12,1,22,33,9]);
...
$gds2File -> printGds2Record( -type => 'endstr' );
$gds2File -> printGds2Record( -type => 'endlib' );
Note: the special record type of 'record' can be used to copy a complete record
just read in:
while ( my $record = $gds2FileIn -> readGds2Record())
{
$gds2FileOut -> printGds2Record( -type => 'record' , -data => $record );
}
|
printRecord - prints a record just read
usage:
$gds2File -> printRecord(
-data => $record
);
|
Low Level Generic Read Methods
readGds2Record - reads record header and data section
usage:
while ( $gds2File -> readGds2Record)
{
if ( $gds2File -> returnRecordTypeString eq 'LAYER' )
{
$layersFound [ $gds2File -> layer] = 1;
}
}
|
slightly faster if you just want a certain thing...
usage:
while ( $gds2File -> readGds2RecordHeader)
{
if ( $gds2File -> returnRecordTypeString eq 'LAYER' )
{
$gds2File -> readGds2RecordData;
$layersFound [ $gds2File -> returnLayer] = 1;
}
}
|
readGds2RecordData - only reads record data section
slightly faster if you just want a certain thing...
usage:
while ( $gds2File -> readGds2RecordHeader)
{
if ( $gds2File -> returnRecordTypeString eq 'LAYER' )
{
$gds2File -> readGds2RecordData;
$layersFound [ $gds2File -> returnLayer] = 1;
}
}
|
Low Level Generic Evaluation Methods
returnRecordType - returns current (read) record type as integer
usage:
if ( $gds2File -> returnRecordType == 6)
{
print "found STRNAME" ;
}
|
returnRecordTypeString - returns current (read) record type as string
usage:
if ( $gds2File -> returnRecordTypeString eq 'LAYER' )
{
code goes here...
}
|
returnRecordAsString - returns current (read) record as a string
usage:
while ( $gds2File -> readGds2Record)
{
print $gds2File -> returnRecordAsString( -compact =>1);
}
|
returnXyAsArray - returns current (read) XY record as an array
usage:
$gds2File -> returnXyAsArray(
-asInteger => 0|1
-withClosure => 0|1
);
example:
while ( $gds2File -> readGds2Record)
{
my @xy = $gds2File -> returnXyAsArray if ( $gds2File -> isXy);
}
|
returnRecordAsPerl - returns current (read) record as a perl command to facilitate the creation of parameterized gds2 data with perl.
usage:
my $gds2File = new GDS2( -fileName => "test.gds" );
while ( $gds2File -> readGds2Record)
{
print $gds2File -> returnRecordAsPerl;
}
|
Low Level Specific Write Methods
printAngle - prints ANGLE record
usage:
$gds2File -> printAngle( -num =>
|
printAttrtable - prints ATTRTABLE record
usage:
$gds2File -> printAttrtable( -string => $string );
|
printBgnextn - prints BGNEXTN record
usage:
$gds2File -> printBgnextn( -num =>
|
printBgnlib - prints BGNLIB record
usage:
$gds2File -> printBgnlib(
-isoDate => 0|1
);
|
printBox - prints BOX record
usage:
$gds2File -> printBox;
|
printBoxtype - prints BOXTYPE record
usage:
$gds2File -> printBoxtype( -num =>
|
printColrow - prints COLROW record
usage:
$gds2File -> printBoxtype( -columns =>
|
printDatatype - prints DATATYPE record
usage:
$gds2File -> printDatatype( -num =>
|
printElkey - prints ELKEY record
usage:
$gds2File -> printElkey( -num =>
|
printEndel - closes an element definition
printEndextn - prints path end extension record
usage:
$gds2File printEndextn -> ( -num =>
|
printEndlib - closes a library definition
printEndstr - closes a structure definition
printEndmasks - prints a ENDMASKS
printFonts - prints a FONTS record
usage:
$gds2File -> printFonts( -string => 'names_of_font_files' );
|
usage:
$gds2File -> printHeader(
-num =>
);
|
printLayer - prints a LAYER number
usage:
$gds2File -> printLayer(
-num =>
);
|
printLibname - Prints library name
usage:
printLibname( -name => $name );
|
printPathtype - prints a PATHTYPE number
usage:
$gds2File -> printPathtype(
-num =>
);
|
printMag - prints a MAG number
usage:
$gds2File -> printMag(
-num =>
);
|
printNodetype - prints a NODETYPE number
usage:
$gds2File -> printNodetype(
-num =>
);
|
printPresentation - prints a text presentation record
usage:
$gds2File -> printPresentation(
-font =>
-top, ||-middle, || -bottom,
-left, ||-center, || -right,
);
example:
gds2File -> printPresentation( -font =>0,-top,-left);
|
printPropattr - prints a property id number
usage:
$gds2File -> printPropattr( -num =>
|
printPropvalue - prints a property value string
usage:
$gds2File -> printPropvalue( -string => $string );
|
printSname - prints a SNAME string
usage:
$gds2File -> printSname( -name => $cellName );
|
printStrans - prints a STRANS record
usage:
$gds2File -> printStrans( -reflect );
|
printString - prints a STRING record
usage:
$gds2File -> printSname( -string => $text );
|
printStrname - prints a structure name string
usage:
$gds2File -> printStrname( -name => $cellName );
|
printTexttype - prints a text type number
usage:
$gds2File -> printTexttype( -num =>
|
printUnits - Prints units record.
options:
-uUnit => real number
-dbUnit => real number
|
printWidth - prints a width number
usage:
$gds2File -> printWidth( -num =>
|
printXy - prints an XY array
usage:
$gds2File -> printXy( -xyInt => \ @arrayGds2Ints );
-or-
$gds2File -> printXy( -xy => \ @arrayReals );
-xyInt most useful if reading and modifying... -xy if creating from scratch
|
Low Level Specific Evaluation Methods
returnFilePosition - return current byte position (NOT zero based)
usage:
my $position = $gds2File -> returnFilePosition;
|
returnBgnextn - returns bgnextn if record is BGNEXTN else returns 0
returnDatatype - returns datatype # if record is DATATYPE else returns -1
usage:
$dataTypesFound [ $gds2File -> returnDatatype] = 1;
|
returnEndextn- returns endextn if record is ENDEXTN else returns 0
returnLayer - returns layer # if record is LAYER else returns -1
usage:
$layersFound [ $gds2File -> returnLayer] = 1;
|
returnPathtype - returns pathtype # if record is PATHTYPE else returns -1
returnPropattr - returns propattr # if record is PROPATTR else returns -1
returnPropvalue - returns propvalue string if record is PROPVALUE else returns ''
returnSname - return string if record type is SNAME else ''
returnString - return string if record type is STRING else ''
returnStrname - return string if record type is STRNAME else ''
returnTexttype - returns texttype # if record is TEXTTYPE else returns -1
usage:
$TextTypesFound [ $gds2File -> returnTexttype] = 1;
|
returnWidth - returns width # if record is WIDTH else returns -1
Low Level Specific Boolean Methods
isAref - return 0 or 1 depending on whether current record is an aref
isBgnlib - return 0 or 1 depending on whether current record is a bgnlib
isBgnstr - return 0 or 1 depending on whether current record is a bgnstr
isBoundary - return 0 or 1 depending on whether current record is a boundary
isDatatype - return 0 or 1 depending on whether current record is datatype
isEndlib - return 0 or 1 depending on whether current record is endlib
isEndel - return 0 or 1 depending on whether current record is endel
isEndstr - return 0 or 1 depending on whether current record is endstr
isLibname - return 0 or 1 depending on whether current record is a libname
isPath - return 0 or 1 depending on whether current record is a path
isSref - return 0 or 1 depending on whether current record is an sref
isSrfname - return 0 or 1 depending on whether current record is an srfname
isText - return 0 or 1 depending on whether current record is a text
isUnits - return 0 or 1 depending on whether current record is units
isLayer - return 0 or 1 depending on whether current record is layer
isStrname - return 0 or 1 depending on whether current record is strname
isWidth - return 0 or 1 depending on whether current record is width
isXy - return 0 or 1 depending on whether current record is xy
isSname - return 0 or 1 depending on whether current record is sname
isColrow - return 0 or 1 depending on whether current record is colrow
isTextnode - return 0 or 1 depending on whether current record is a textnode
isNode - return 0 or 1 depending on whether current record is a node
isTexttype - return 0 or 1 depending on whether current record is a texttype
isPresentation - return 0 or 1 depending on whether current record is a presentation
isSpacing - return 0 or 1 depending on whether current record is a spacing
isString - return 0 or 1 depending on whether current record is a string
isStrans - return 0 or 1 depending on whether current record is a strans
isMag - return 0 or 1 depending on whether current record is a mag
isAngle - return 0 or 1 depending on whether current record is a angle
isUinteger - return 0 or 1 depending on whether current record is a uinteger
isUstring - return 0 or 1 depending on whether current record is a ustring
isReflibs - return 0 or 1 depending on whether current record is a reflibs
isFonts - return 0 or 1 depending on whether current record is a fonts
isPathtype - return 0 or 1 depending on whether current record is a pathtype
isGenerations - return 0 or 1 depending on whether current record is a generations
isAttrtable - return 0 or 1 depending on whether current record is a attrtable
isStyptable - return 0 or 1 depending on whether current record is a styptable
isStrtype - return 0 or 1 depending on whether current record is a strtype
isEflags - return 0 or 1 depending on whether current record is a eflags
isElkey - return 0 or 1 depending on whether current record is a elkey
isLinktype - return 0 or 1 depending on whether current record is a linktype
isLinkkeys - return 0 or 1 depending on whether current record is a linkkeys
isNodetype - return 0 or 1 depending on whether current record is a nodetype
isPropattr - return 0 or 1 depending on whether current record is a propattr
isPropvalue - return 0 or 1 depending on whether current record is a propvalue
isBox - return 0 or 1 depending on whether current record is a box
isBoxtype - return 0 or 1 depending on whether current record is a boxtype
isPlex - return 0 or 1 depending on whether current record is a plex
isBgnextn - return 0 or 1 depending on whether current record is a bgnextn
isEndextn - return 0 or 1 depending on whether current record is a endextn
isTapenum - return 0 or 1 depending on whether current record is a tapenum
isTapecode - return 0 or 1 depending on whether current record is a tapecode
isStrclass - return 0 or 1 depending on whether current record is a strclass
isReserved - return 0 or 1 depending on whether current record is a reserved
isMask - return 0 or 1 depending on whether current record is a mask
isEndmasks - return 0 or 1 depending on whether current record is a endmasks
isLibdirsize - return 0 or 1 depending on whether current record is a libdirsize
isLibsecur - return 0 or 1 depending on whether current record is a libsecur
recordSize - return current record size
usage:
my $len = $gds2File -> recordSize;
|
dataSize - return current record size - 4 (length of data)
usage:
my $dataLen = $gds2File -> dataSize;
|
returnUnitsAsArray - return user units and database units as a 2 element array
usage:
my ( $uu , $dbu ) = $gds2File -> returnUnitsAsArray;
|
version - return GDS2 module version string
version - return GDS2 module revision string
Backus-naur representation of GDS2 Stream Syntax
GDS2 Stream Record Datatypes
NO_REC_DATA = 0;
BIT_ARRAY = 1;
INTEGER_2 = 2;
INTEGER_4 = 3;
REAL_4 = 4;
REAL_8 = 5;
ACSII_STRING = 6;
|
GDS2 Stream Record Types
HEADER = 0;
BGNLIB = 1;
LIBNAME = 2;
UNITS = 3;
ENDLIB = 4;
BGNSTR = 5;
STRNAME = 6;
ENDSTR = 7;
BOUNDARY = 8;
PATH = 9;
SREF = 10;
AREF = 11;
TEXT = 12;
LAYER = 13;
DATATYPE = 14;
WIDTH = 15;
XY = 16;
ENDEL = 17;
SNAME = 18;
COLROW = 19;
TEXTNODE = 20;
NODE = 21;
TEXTTYPE = 22;
PRESENTATION = 23;
SPACING = 24;
STRING = 25;
STRANS = 26;
MAG = 27;
ANGLE = 28;
UINTEGER = 29;
USTRING = 30;
REFLIBS = 31;
FONTS = 32;
PATHTYPE = 33;
GENERATIONS = 34;
ATTRTABLE = 35;
STYPTABLE = 36;
STRTYPE = 37;
EFLAGS = 38;
ELKEY = 39;
LINKTYPE = 40;
LINKKEYS = 41;
NODETYPE = 42;
PROPATTR = 43;
PROPVALUE = 44;
BOX = 45;
BOXTYPE = 46;
PLEX = 47;
BGNEXTN = 48;
ENDEXTN = 49;
TAPENUM = 50;
TAPECODE = 51;
STRCLASS = 52;
RESERVED = 53;
FORMAT = 54;
MASK = 55;
ENDMASKS = 56;
LIBDIRSIZE = 57;
SRFNAME = 58;
LIBSECUR = 59;
|