-- File: ManntoCIF.mesa
-- Written by Martin Newell February 1981
-- Last edited: April 15, 1981 1:28 PM
DIRECTORY
IODefs: FROM "IODefs" USING [SP, CR, TAB, NUL, WriteChar, WriteString,
WriteLine, WriteDecimal, GetOutputStream, SetOutputStream],
JaMFnsDefs: FROM "JaMFnsDefs" USING [Register, PopString, PopInteger],
Real: FROM "Real" USING [Float, RoundLI],
RealFns: FROM "RealFns" USING [CosDeg, SinDeg],
StreamDefs: FROM "StreamDefs" USING [StreamHandle, NewByteStream,
Read, Write, Append],
StringDefs: FROM "StringDefs" USING [AppendString, AppendChar,
AppendLongDecimal];
ManntoCIF: PROGRAM
IMPORTS IODefs, JaMFnsDefs, Real, RealFns, StreamDefs, StringDefs =
BEGIN
OPEN IODefs, JaMFnsDefs, Real, RealFns, StreamDefs, StringDefs;
CallTranslate: PROCEDURE =
BEGIN --expects <filename,layerNumber>
fileName: STRING ← [40];
inFileName: STRING ← [40];
outFileName: STRING ← [40];
layerNumber: INTEGER ← PopInteger[];
PopString[fileName];
AppendString[inFileName,fileName];
AppendString[inFileName,".mann"];
AppendString[outFileName,fileName];
AppendString[outFileName,".cif"];
Translate[inFileName,outFileName, layerNumber];
WriteString[inFileName]; WriteString[" to "];
WriteLine[outFileName];
END;
Translate: PROCEDURE[inFile,outFile: STRING, layerNumber: INTEGER] =
BEGIN
end: BOOLEAN;
x,y,w,h,a: LONG INTEGER;
saveOut ← GetOutputStream[];
inStream ← NewByteStream[inFile,Read];
outStream ← NewByteStream[outFile,Write+Append];
SetOutputStream[outStream];
InitReader[];
WriteString["(Translated from Mann file "];
WriteString[inFile];
WriteLine[");"];
WriteString["DS "];
WriteDecimal[layerNumber+1]; -- +1 to avoid symbol 0
WriteLine[";"];
WriteString["L N"];
WriteChar[LayerChar[layerNumber]];
WriteLine[";"];
UNTIL inStream.endof[inStream] DO
[end,x,y,w,h,a] ← ReadBox[inStream];
IF end THEN EXIT;
WriteChar[’B];
WriteChar[SP]; WriteLongDecimal[w];
WriteChar[SP]; WriteLongDecimal[h];
WriteChar[SP]; WriteLongDecimal[-x];
WriteChar[SP]; WriteLongDecimal[y];
IF a#0 THEN
{angle: REAL ← -Float[a]/10;
WriteChar[SP]; WriteLongDecimal[RoundLI[CosDeg[angle]*32768]];
WriteChar[SP]; WriteLongDecimal[RoundLI[SinDeg[angle]*32768]];
};
WriteLine[";"];
ENDLOOP;
WriteLine["DF;"];
WriteString["C "];
WriteDecimal[layerNumber+1]; -- +1 to avoid symbol 0
WriteLine[";"];
WriteLine["End"];
SetOutputStream[saveOut];
inStream.destroy[inStream];
outStream.destroy[outStream];
END;
inStream: StreamHandle;
saveOut: StreamHandle;
outStream: StreamHandle;
Message: PROCEDURE[line: STRING] =
BEGIN
SetOutputStream[saveOut];
WriteLine[line];
SetOutputStream[outStream];
END;
X,Y,W,H,A: LONG INTEGER;
InitReader: PROCEDURE[] =
BEGIN
X ← 0;
Y ← 0;
W ← 0;
H ← 0;
A ← 0;
END;
ReadBox: PROCEDURE[s: StreamHandle]
RETURNS[end: BOOLEAN, x,y,w,h,a: LONG INTEGER] =
BEGIN
ch: CHARACTER;
IF s.endof[s] THEN RETURN[TRUE,0,0,0,0,0];
ch ← s.get[s];
DO
IF ch=SP OR ch=CR OR ch=TAB OR ch=NUL THEN
{IF s.endof[s] THEN EXIT;
ch ← s.get[s];
LOOP;
};
SELECT ch FROM
’X => [X,ch] ← ReadN[s];
’Y => [Y,ch] ← ReadN[s];
’W => [W,ch] ← ReadN[s];
’H => [H,ch] ← ReadN[s];
’A => [A,ch] ← ReadN[s];
’;=> RETURN[FALSE, X,Y,W,H,A];
’$=> RETURN[TRUE, 0,0,0,0,0];
ENDCASE =>
{line: STRING ← [100];
AppendString[line,"Unknown keyword in Mann file: "];
AppendChar[line,ch];
Message[line];
RETURN[FALSE, X,Y,W,H,A];
};
ENDLOOP;
RETURN[TRUE,0,0,0,0,0];
END;
ReadN: PROCEDURE[s: StreamHandle]
RETURNS[n: LONG INTEGER, delimiter: CHARACTER] =
--n always positive
BEGIN
ch: CHARACTER;
n ← 0;
UNTIL s.endof[s] DO
ch ← s.get[s];
IF ’0<=ch AND ch<=’9 THEN n ← n*10 + (ch-’0)
ELSE RETURN[n,ch];
ENDLOOP;
RETURN[n,NUL];
END;
WriteLongDecimal: PROCEDURE[n: LONG INTEGER] =
BEGIN
s: STRING ← [30];
AppendLongDecimal[s,n];
WriteString[s];
END;
LayerChar: ARRAY [0..15] OF CHARACTER ← ALL[’X];
--START code
--Set up CIF Layer names
LayerChar[0] ← ’I;--implant
LayerChar[1] ← ’D;--diffusion
LayerChar[2] ← ’P;--poly
LayerChar[3] ← ’C;--contact
LayerChar[4] ← ’M;--metal
LayerChar[5] ← ’B;--buried
LayerChar[6] ← ’G;--glass
LayerChar[7] ← ’X;--undef
Register["mtoc",CallTranslate];
END.