7. Extended techniques
The normal usage of the Raith_GDSII toolbox is explained in the foregoing sections of this documentation. In this section, we describe extended techniques which may be used to save time and/or memory—two concerns which can become limiting factors when generating patterns consisting of very large numbers of elements. The cost of these extended techniques includes the loss of Raith_element
, Raith_structure
, and Raith_library
data checking and all plotting functionality, so they are best used in the final stages of the design process.
7.1. Disabling data checking
By default, the properties of Raith_element
, Raith_structure
, and Raith_library
objects are checked for correctness (typing, allowed values, size) before being assigned or altered, ensuring that the resulting objects may be plotted and used to generate GDSII and positionlist files without subsequent errors. By disabling data checking, Raith_element
, Raith_structure
, and Raith_library
objects may be created more quickly, at the risk of encountering more cryptic error messages downstream.
Data checking may be disabled by declaring a global variable checkdata
and assigning it a value of logical zero (Boolean false
).
Example
Creating a series of random Raith_element
'path'
objects with and without data checking:
% With data checking
tic;
for k=1:1000
E=Raith_element('path',0,rand(2,1000),0,1);
end;
t_Check=toc;
% Without data checking
global checkdata;
checkdata=false;
tic;
for k=1:1000
E=Raith_element('path',0,rand(2,1000),0,1);
end;
t_noCheck=toc;
Without data checking, there is typically a greater than 4× reduction in computation time:
>> t_Check/t_noCheck
ans =
4.4510
Note
As a global variable, checkdata
will remain accessible to any functions declaring it as global, even if a clear
command is issued in the current workspace. To remove checkdata
completely (i.e., restoring the default state of enabled data checking), use clear global checkdata
.
7.2. Defining patterns using MATLAB structures
The time and memory overhead associated with creating Raith_element
and Raith_structure
objects can be further reduced—at the expense of losing all plotting functionality—by using MATLAB structures (i.e., instances of the built-in struct
class) with fields that match the Raith_element
and Raith_structure
properties, both in name and in type. Raith “elements” and “structures” defined in this way can be used by Raith_library
and Raith_positionlist
objects to generate .csf and .pls files, provided data checking is disabled (see §7.1, above). Refer to the Raith_element
and Raith_structure
documentation for descriptions of their class properties.
Example
Creating an array of microrings with varying widths:
% Cell array of ring widths (µm)
w=num2cell(0.1:0.05:0.5)';
% Cell array of disk centres: 15 µm spacing in u, v=0
uv_c=num2cell(15*(0:length(w)-1)'*[1 0],2);
% 'circle' Raith_element objects have properties 'type', and 'data', the
% latter having fields 'layer', 'uv_c', 'r', 'w', 'N', and 'DF', so we create
% a struct object with these fields
data=struct('layer',0,'uv_c',uv_c,'r',5,'w',w,'N',100,'DF',1.3);
E=struct('type','circle','data',num2cell(data));
% Raith_structure objects have properties 'name', 'elements', and 'reflist'
S.name='rings';
S.elements=E;
S.reflist=[];
global checkdata;
checkdata=false;
L=Raith_library('ringarray',S);
L.writegds;
Running the above yields the following output:
Skipping all data checking.
Writing /Users/Public/Documents/ringarray.csf...
Header information
Structure 1/1: rings
GDSII library ringarray.csf successfully written.
Note
In the above Example, the data
and E
variables were created using MATLAB’s struct function, which yields a structure array if any of the value inputs are cell arrays; the same result could have been produced using a for
loop.
7.3. “On-the-fly” GDSII writing
In situations where the number of elements in the pattern is so large that there is insufficient memory to keep them all in the MATLAB workspace simultaneously, it is still possible to output a GDSII file by generating elements and writing them sequentially; this procedure uses the static Raith_library
methods writerec
, writehead
, writebeginstruct
, writeelement
, writeendstruct
, and writeendlib
to write GDSII records directly.[1] The following general format must be observed:
Raith_library.writehead()
— Header informationRaith_library.writebeginstruct()
— Begin first structure in libraryRaith_library.writeelement()
— First element in structureRaith_library.writeelement()
— Last element in structureRaith_library.writeendstruct()
— End first structureRaith_library.writebeginstruct()
— Begin last structure in libraryRaith_library.writeelement()
— First element in structureRaith_library.writeelement()
— Last element in structureRaith_library.writeendstruct()
— End last structureRaith_library.writeendlib()
— End libraryWhen writing GDSII files “on the fly”, the user is responsible for ensuring that all structures referenced by 'sref'
and 'aref'
elements are in fact present in the library.
Example
Creating the same array of microrings as in the above Example §7.2 “on the fly”:
% Vector of ring widths (µm)
w=0.1:0.05:0.5;
% Matrix of disk centres: 15 µm spacing in u, v=0
uv_c=15*(0:length(w)-1)'*[1 0];
% Open file for writing binary data
FileID=fopen('/Users/Public/Documents/ringarray.csf','W');
Raith_library.writehead(FileID,'ringarray');
Raith_library.writebeginstruct(FileID,'rings');
% Loop through all elements in structure; only one Raith_element object
% is in memory at any given time.
for k=1:length(w)
E=Raith_element('circle',0,uv_c(k,:),5,w(k),100,1.3);
Raith_library.writeelement(FileID,E);
end
Raith_library.writeendstruct(FileID);
Raith_library.writeendlib(FileID);
fclose(FileID);