PROCEDURE WriteCoords( name: TEXT; READONLY top: Topology; e: MixedEnergy.T; READONLY r: EvalRec; cpuTime: CPUTime.T; totEvals: CARDINAL; step: CARDINAL; comments: TEXT; ) = (* Writes only coords values to file "name.vtx" *) <* FATAL Wr.Failure, Thread.Alerted, OSError.E *> PROCEDURE WritePoint(wr: Wr.T; READONLY p: LR3.T) = PROCEDURE WriteCoord(x: LONGREAL) = BEGIN Wr.PutText(wr, Fmt.LongReal(x*10.0d0, prec := 5)) END WriteCoord; BEGIN WriteCoord(p[0]); Wr.PutText(wr, " "); WriteCoord(p[1]); Wr.PutText(wr, " "); WriteCoord(p[2]); END WritePoint; CONST CommentPrefix: CHAR = '|'; PROCEDURE WriteComments(wr: Wr.T; comments: TEXT) = (* Writes the given "comments" text to "wr", with a CommentPrefix in front of every line. Supplies a final '\n' if the text is non-empty but does not end with newline. *) VAR rd: Rd.T := TextRd.New(comments); PROCEDURE CopyLine() RAISES {Rd.EndOfFile} = (* Copy one line from "rd" to "wr", prefixed by CommentPrefix. Supplies a final '\n' if the next line exists but does NOT end with newline. Raises Rd.EndOfFile if there are no more lines in "rd". *) <* FATAL Rd.Failure, Wr.Failure, Thread.Alerted *> VAR c: CHAR; BEGIN c := Rd.GetChar(rd); (* If EOF here, propagate to caller *) Wr.PutChar(wr, CommentPrefix); Wr.PutChar(wr, c); WHILE c # '\n' DO TRY c := Rd.GetChar(rd) EXCEPT Rd.EndOfFile => c := '\n' END; Wr.PutChar(wr, c) END END CopyLine; BEGIN TRY LOOP CopyLine() END EXCEPT Rd.EndOfFile => (* Ok *) END; END WriteComments; BEGIN WITH c = r.c^, NV = NUMBER(c), wr = FileWr.Open(name & ".vtx") DO Wr.PutText(wr, "vertices " & Fmt.Int(NV)); WriteComments Wr.PutText(wr, "\n\n"); FOR i := 0 TO LAST(c) DO WritePoint(wr, c[i]); Wr.PutText(wr, "\n"); Wr.Flush(wr); END; Wr.Close(wr); END; END WriteCoords;