DIRECTORY
BSimModel,
FS USING [StreamOpen],
IO USING [Backup, char, Close, GetChar, GetLineRope, GetReal, Put, PutF, real, RIS, rope, STREAM],
Rope USING [Cat, Equal, Fetch, Find, Length, ROPE, Substr];
BSimModelImplInput:
CEDAR
PROGRAM
IMPORTS
FS,
IO, Rope
EXPORTS BSimModel =
BEGIN
ReadProcessFile:
PUBLIC
PROC [ fileName: Rope.
ROPE ]
RETURNS [ p:
REF BSimModel.ProcessParams ] = {
s: IO.STREAM = FS.StreamOpen[fileName];
ReadReal:
PROC [ s:
IO.
STREAM ]
RETURNS [ r:
REAL ] =
BEGIN
DO
SELECT (c ← s.GetChar[])
FROM
',, ' , '/, '\n => NULL;
ENDCASE => {s.Backup[c]; RETURN[s.GetReal[]]};
ENDLOOP;
END;
c: CHAR;
p ← NEW[BSimModel.ProcessParams];
p.info ← NIL;
WHILE (c ← s.GetChar[]) = '*
DO
line: Rope.ROPE = s.GetLineRope[];
eqPos: INT = line.Find["="];
p.info ← Rope.Cat[p.info, "*", line, "\n"];
IF line.Length>1
AND line.Fetch[0]#'
AND eqPos>0
THEN {
label: Rope.ROPE = line.Substr[len: eqPos];
rest: IO.STREAM = IO.RIS[line.Substr[start: eqPos+1]];
SELECT
TRUE
FROM
label.Equal["W/L",
FALSE] => {
p.dutW ← ReadReal[rest]; p.dutL ← ReadReal[rest]};
label.Equal["BetaFudgeFactor",
FALSE] =>
p.betaFudgeFactor ← ReadReal[rest];
ENDCASE => NULL;
};
ENDLOOP;
s.Backup[c];
FOR i:
INT
IN [0..BSimModel.nBasicBSimParams)
DO
FOR j:
INT
IN [1..6]
DO
p.params[i][j] ← ReadReal[s];
ENDLOOP;
ENDLOOP;
p.toxMicrons ← ReadReal[s];
p.tempC ← ReadReal[s];
p.vddVolts ← ReadReal[s];
s.Close[];
};
WriteProcessFile:
PUBLIC
PROC [ fileName: Rope.
ROPE, p:
REF BSimModel.ProcessParams ] = {
s: IO.STREAM = FS.StreamOpen[fileName, $create];
s.Put[IO.rope[p.info]];
FOR i:
INT
IN [0..BSimModel.nBasicBSimParams)
DO
FOR j:
INT
IN [1..6]
DO
s.Put[IO.real[p.params[i][j]], IO.char[IF j<6 THEN ', ELSE '\n]];
ENDLOOP;
ENDLOOP;
s.PutF["%g,%g,%g\n", IO.real[p.toxMicrons], IO.real[p.tempC], IO.real[p.vddVolts]];
s.Close[];
};
END.