ReadCad:
PUBLIC PROC [in:
IO.
STREAM]
RETURNS [out:
QET.Cad] ~ {
token: Rope.ROPE;
dimension: CARDINAL;
inputVariables, projVariables, minPolyVariable, fieldElementVariable: VARS.VariableSeq;
inputPolynomialRing, projPolynomialRing, minPolyRing, formulaAlgebra: AC.Structure;
inputPolynomials, basis: POL.PolynomialSeq ← NIL;
contents, projection: POL.PolynomialSeq ← NIL;
regions: QET.SignedRegionSeq ← NIL;
cells: QET.CellSeq ← NIL;
cellIndexStructure, inputSignatureStructure: AC.Structure;
inducedCad: QET.Cad ← NIL;
token ← in.GetID[];
IF NOT Rope.Equal[token, "BEGINCAD"] THEN ERROR;
token ← in.GetID[];
IF NOT Rope.Equal[token, "DIMENSION"] THEN ERROR;
dimension ← in.GetCard[];
cellIndexStructure ← PTS.MakePointStructure[Ints.Ints, dimension];
token ← in.GetID[];
IF NOT Rope.Equal[token, "INPUTVARIABLES"] THEN ERROR;
inputVariables ← VARS.ReadVariableSeq[in];
inputPolynomialRing ← POL.MakePolynomialStructure[BR.BigRats, inputVariables];
token ← in.GetID[];
IF NOT Rope.Equal[token, "MINPOLYVARIABLE"] THEN ERROR;
minPolyVariable ← VARS.ReadVariableSeq[in];
minPolyRing ← POL.MakePolynomialStructure[BR.BigRats, minPolyVariable];
token ← in.GetID[];
IF NOT Rope.Equal[token, "FIELDELEMENTVARIABLE"] THEN ERROR;
fieldElementVariable ← VARS.ReadVariableSeq[in];
IF NOT Rope.Equal[fieldElementVariable[1], minPolyVariable[1] ] THEN ERROR; -- quick fix; the entire use of fieldElementVariable should be removed
token ← in.GetID[];
IF Rope.Equal[token, "INPUTPOLYNOMIALS"]
THEN {
inputPolynomials ← POL.ReadPolySeq[in, inputPolynomialRing];
inputSignatureStructure ← PTS.MakePointStructure[FormulaOperators.Operators, inputPolynomials.lengthPlus1-1];
token ← in.GetID[];
}
ELSE inputSignatureStructure ← NIL;
IF Rope.Equal[token, "BASIS"]
THEN {
basis ← POL.ReadPolySeq[in, inputPolynomialRing];
token ← in.GetID[];
};
projVariables ← VARS.RemoveMainVariable[inputVariables];
projPolynomialRing ← POL.MakePolynomialStructure[BR.BigRats, projVariables];
IF Rope.Equal[token, "CONTENTS"]
THEN {
contents ← POL.ReadPolySeq[in, projPolynomialRing];
token ← in.GetID[];
};
IF Rope.Equal[token, "PROJECTION"]
THEN {
projection ← POL.ReadPolySeq[in, projPolynomialRing];
token ← in.GetID[];
};
formulaAlgebra ← QFF.MakeFormulaAlgebra[inputPolynomialRing];
IF Rope.Equal[token, "CELLS"] THEN [cells, token] ← ReadCellSeq[in, cellIndexStructure, inputPolynomialRing, inputSignatureStructure, minPolyRing, formulaAlgebra];
IF Rope.Equal[token, "CLUSTERS"] THEN [regions, token] ← ReadSignedRegionSeq[in, cellIndexStructure, inputPolynomialRing, minPolyRing, inputSignatureStructure];
IF Rope.Equal[token, "INDUCEDCAD"]
THEN {
inducedCad ← ReadCad[in];
token ← in.GetID[];
};
IF NOT Rope.Equal[token, "ENDCAD"] THEN ERROR;
out ←
NEW[
QET.CadRec ← [
dimension: dimension,
inputVariables: inputVariables,
minPolyVariable: minPolyVariable,
fieldElementVariable: fieldElementVariable,
inputPolynomials: inputPolynomials,
basis: basis,
contents: contents,
basisProjection: projection,
cells: cells,
clusters: regions,
inducedCad: inducedCad
] ];
FOR i:
NAT
IN [1..cells.lengthPlus1 - 1]
DO
cells[i].cad ← out;
ENDLOOP;
out.abstractGraph ←
NEW [Graphs.GraphPrivate ← [
class: cadGraphClass,
rep: out
]];
RETURN;
};
CadToRope:
PUBLIC
PROC [in:
QET.Cad]
RETURNS [out: Rope.
ROPE] ~ {
projVariables: VARS.VariableSeq;
out ← "BEGINCAD\n";
out ← Rope.Concat[out, "DIMENSION\n"];
out ← Rope.Cat[out, Convert.RopeFromCard[in.dimension], "\n"];
out ← Rope.Concat[out, "INPUTVARIABLES\n"];
out ← Rope.Cat[out, VARS.VariableSeqToRope[in.inputVariables], "\n"];
out ← Rope.Concat[out, "MINPOLYVARIABLE\n"];
out ← Rope.Cat[out, VARS.VariableSeqToRope[in.minPolyVariable], "\n"];
out ← Rope.Concat[out, "FIELDELEMENTVARIABLE\n"];
out ← Rope.Cat[out, VARS.VariableSeqToRope[in.fieldElementVariable], "\n"];
IF in.inputPolynomials#
NIL
THEN {
out ← Rope.Concat[out, "INPUTPOLYNOMIALS\n"];
out ← Rope.Cat[out, POL.PolySeqToRope[in.inputPolynomials], "\n"];
};
IF in.basis#
NIL
THEN {
out ← Rope.Concat[out, "BASIS\n"];
out ← Rope.Cat[out, POL.PolySeqToRope[in.basis], "\n"];
};
projVariables ← VARS.RemoveMainVariable[in.inputVariables];
IF in.contents#
NIL
THEN {
out ← Rope.Concat[out, "CONTENTS\n"];
out ← Rope.Cat[out, POL.PolySeqToRope[in.contents], "\n"];
};
IF in.basisProjection#
NIL
THEN {
out ← Rope.Concat[out, "PROJECTION\n"];
out ← Rope.Cat[out, POL.PolySeqToRope[in.basisProjection], "\n"];
};
IF in.cells#
NIL
THEN {
out ← Rope.Concat[out, "CELLS\n"];
out ← Rope.Cat[out, CellSeqToRope[in.cells], "\n"];
};
IF in.clusters#
NIL
THEN {
out ← Rope.Concat[out, "CLUSTERS\n"];
out ← Rope.Cat[out, SignedRegionSeqToRope[in.clusters], "\n"];
};
IF in.inducedCad#
NIL
THEN {
out ← Rope.Concat[out, "INDUCEDCAD\n"];
out ← Rope.Cat[out, CadToRope[in.inducedCad], "\n"];
};
out ← Rope.Concat[out, "ENDCAD\n"];
};