WavesImpl.mesa
Sweetsun Chen, November 25, 1985 11:13:49 pm PST
DIRECTORY
Commander USING [CommandProc, Register],
IO USING [int, PutFR],
Graph USING [GraphHandle, ValueList],
GraphOps USING [AddText, AddCurve, AppendValues, Black, Lock, NewGraph, SaveGraph, TimesRoman12B, Unlock],
RealFns USING [Sin];
WavesImpl: CEDAR PROGRAM
IMPORTS Commander, IO, GraphOps, RealFns =
BEGIN
Waves: Commander.CommandProc = { -- plot five sinusoidal curves.
-- some constants
numberOfCurves: INT = 5;
p : REAL = 3.14159;
PhaseShift: REAL = p/12.0;
timeIncrement: REAL = 4.0/100.0; -- 100 time increments in 4p
-- create the graph.
graphHandle: Graph.GraphHandle ← NIL;
groupId: INT;
[graphHandle, groupId] ← GraphOps.NewGraph[
fileName: "Waves.graph",
comment: "Waves.graph", -- will be displayed on controller table as group heading.
bounds: [xmin: 0.0, ymin: -1.0, xmax: 4.0, ymax: 1.0]
];
IF graphHandle # NIL THEN {
t, angle: REAL ← 0.0;
-- lock it
GraphOps.Lock[graphHandle];
-- put a title
[] ← GraphOps.AddText[handle: graphHandle, rope: "Waves",
place: [0.5, 1.1], fontIndex: GraphOps.TimesRoman12B, colorIndex: GraphOps.Black,
rotation: 0.0, justifX: center, justifY: bottom];
-- initialize curves.
FOR i: INT IN [1..numberOfCurves] DO
[] ← GraphOps.AddCurve[handle: graphHandle,
groupId: groupId, name: IO.PutFR["Wave # %g", IO.int[i]]];
ENDLOOP;
-- append x and y values.
WHILE t <= 4.0 DO
values: Graph.ValueList ← NIL; -- LIST OF REAL
angle ← t*p;
FOR i: INT IN [1..numberOfCurves] DO
values ← CONS[RealFns.Sin[angle], values];
angle ← angle - PhaseShift;
ENDLOOP;
GraphOps.AppendValues[handle: graphHandle, x: t, yvalues: values, groupId: groupId];
t ← t + timeIncrement;
ENDLOOP;
-- save and unlock it.
msg ← GraphOps.SaveGraph[graphHandle];
GraphOps.Unlock[graphHandle];
};
}; -- Waves
Commander.Register["Waves", Waves, "An application of the GraphOps interface."];
END.
LOG.
Chen, July 29, 1985 6:19:35 pm PDT, created.