CGX File Format
IC Design Software for Unix/Linux and Windows
Whiteley Research Inc., 456 Flora Vista Avenue, Sunnyvale CA 94086    wrcad.com

The Computer Graphics eXchange (CGX) format is a simple binary data format somewhat similar to GDSII, but designed to be more compact and efficient. This format, developed by Whiteley Research, is hereby placed in the public domain without restriction.

Like GDSII, files consist of a sequential list of variable-length records. It has simplified record structure, but extensions in data flexibility. If is more compact than GDSII and is more efficient to read and write. The advantages of CGX are smaller files and potentially faster read/write than GDSII.

CGX Format Identifier

The first three bytes of a CGX file are 'c', 'g', and 'x'. The fourth byte is an integer format level. A parser designed to handle a certain level will accept that level and any value lower. Presently, the only existing level is 0, thus this byte should be set to 0.

CGX Data Types

CGX uses the same long (4-byte) and short (2-byte) integer formats as GDSII, and the same 8-byte floating point format. These are the only numerical data types defined.

A date is stored as 8 bytes, as shown in the following table. These are the same numerical fields as used in GDSII, though the format is different (bytes are used where possible, rather than shorts). The third column gives the value in terms of the members of the tm structure from the C library.

short year tm_year + 1900
byte month tm_mon + 1
byte day tm_mday
byte hour tm_hour
byte minute tm_min
byte second tm_sec
byte 0  

As in GDSII, string data are terminated with a null byte, with an additional null byte added if necessary to make the total length even.

CGX Data Records

The four-byte file header is followed by any number of data records, the last of which signals the end of data. There are 11 defined record types. Each record begins with a 4-byte header:

short recsize
byte rectype
byte flags

The recsize field is a short integer giving the total record size, including the header. Thus, as in GDSII, records are limited to 64K bytes in length. The record size will always be an even number. The rectype byte is set to a small integer to define the type of record. The flags byte is used in some of the record types, otherwise it is ignored.

The defined record types are given in the table below.

rectype name
0 LIBRARY
1 STRUCT
2 CPRPTY
3 PROPERTY
4 LAYER
5 BOX
6 POLY
7 WIRE
8 TEXT
9 SREF
10 ENDLIB

It is allowable to define additional record types for local or proprietary purposes. If a parser encounters an unknown record type, it may skip over the record, ignoring it.

LIBRARY record

The LIBRARY record should be the first data record in the file, and can appear once only.

The flags byte of the record header can be used for a version number, which identifies in some way the remaining data in the file.

The LIBRARY record contains the following fields:

bytes field name purpose
8 munit machine units
8 uunit user units
8 cdate library creation date
8 mdate library modification date
? libname library name string

The first two fields are double-precision numbers that define the scale factors for the data in the file. These are interpreted in the same way as the similar fields in the header of a GDSII file.

The second two fields represent creation and modification dates for the file content.

A name string for the library follows. Strings are null-byte terminated, and an additional null byte is added if necessary so that the total length is even.

STRUCT record

The STRUCT record opens a cell structure. Records that follow will be assigned to that cell, until another STRUCT record is seen.

The header flags byte is not used.

The STRUCT record contains the following fields:

bytes field name purpose
8 cdate creation date
8 mdate modification date
? strname structure name string

The first two fields provide creation and modification dates for the structure. These are followed by a string giving a name for the structure. This name should be unique in the file.

CPRPTY record

Zero or more CPRPTY records can appear following a STRUCT record. These are properties that are applied to the cell.

The header flags byte is not used.

The CPRPTY record contains the following fields:

bytes field name purpose
4 number property number
? string property string

Any number or string is allowed.

PROPERTY record

Zero or more PROPERTY records can appear ahead of BOX, POLY, WIRE, TEXT, and SREF records. It assigns a property to the object that follows.

The header flags byte is not used.

The PROPERTY record contains the following fields:

bytes field name purpose
4 number property number
? string property string

Any number or string is allowed.

LAYER record

A LAYER record can appear after a STRUCT, and must appear before any of BOX, POLY, WIRE, TEXT in the STRUCT. The layer context will persist until the next LAYER or STRUCT record.

The header flags byte is not used.

The LAYER record contains the following fields:

bytes field name purpose
2 number layer number
2 datatype data type
? [lname] optional layer name

The layer number and data type are sufficient, and have the same interpretation as in GDSII. Alternatively or in addition, a string giving a layer name can be supplied.

BOX record

A BOX record can appear after a LAYER record has been issued. The BOX record defines one or more rectangular data objects.

The header flags byte is not used.

The BOX record contains the following fields:

bytes field name purpose
4 left left value
4 bottom bottom value
4 right right value
4 top top value
? [repeat]repeat for multiple boxes

The first four integers define a box, and a record can contain multiple box definitions (four integers per box). Each box is given the properties currently in effect, and is assigned to the layer currently in effect.

POLY record

A POLY record can appear after a LAYER record has been issued. The POLY record defines a polygon object.

The header flags byte is not used.

The POLY record contains the following fields:

bytes field name purpose
? xy coordinate pairs, path must be closed

Coordinates use four-byte integers. The first and last coordinate pair (x-y values) must be the same. There must be at least four coordinate pairs.

WIRE record

A WIRE record can appear after a LAYER record has been issued. A WIRE record specifies a single wire (path) data object.

The header flags field contains a value in the range 0-2 which sets the end style of the wire:

0 flush ends
1 rounded ends
2 extended square ends

This is the same as the pathtype in GDSII.

The WIRE record contains the following fields:

bytes field name purpose
4 width path width
? xy coordinate pairs (1 pair or more)

TEXT record

A TEXT record can appear after a LAYER record has been issued. A TEXT record specifies a non-physical text object.

The header flags byte is an orientation code:

bits 0-1 rotate the text about the anchor
00 no rotation
01 90 degrees
10 180 degrees
11 270 degrees
bit 2 mirror y after rotation
bit 3 shift rotations to 45, 135, 225, 315 degrees
bits 4-5 horizontal justification, 00, 11 left, 01 center, 10 right
bits 6-7 vertical justification, 00, 11 bottom, 01 center, 10 top

The TEXT record contains the following fields:

bytes field name purpose
4 x x position
4 y y position
4 widthfield width
? labellabel text

The width gives the physical equivalent width of the text. The height is determined by the font used for rendering.

SREF record

The SREF record describes an instance, or an array of instances.

The header flags byte can have any of the following bits set.

ANGLE 0x1
MAGN 0x2
REFLECT 0x4
ARRAY 0x8

The SREF record contains the following fields:

bytes field name purpose
4 x x coordinate
4 y y coordinate
8 angle rotation angle, if ANGLE flag only
8 magnifmagnification, if MAGN flag only
4 cols array columns, if ARRAY flag only
4 rows array rows, if ARRAY flag only
16 xy[4]aref points (like GDSII), if ARRAY flag only
? sname referenced structure name

If the ANGLE flag is set, the cell is to be rotated by an angle, in degrees, found in the record. If the MAGN bit is set, the cell is scaled by a value found in the record. If the REFLECT bit is set, the instance will be reflected about the x-axis, as in GDSII. If the ARRAY bit is set, the instance is arrayed, as in GDSII, where x, y, and xy give the three orientation points, as in a GDSII AREF record. Unless the corresponding bit is set, the corresponding data is not in the record.

ENDLIB record

The ENDLIB record must be the last record of the file. It contains no data.

Copyright © Whiteley Research Inc. 2014