WavesImpl.mesa
Sweetsun Chen, November 21, 1985 10:57:12 pm PST
DIRECTORY
Commander USING [CommandProc, Register],
IO USING [int, PutFR],
Graph USING [GraphHandle, ValueList],
GraphOps USING [AddCrossSection, EnlistEntity, Lock, NewGraph, SaveGraph, 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",
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];
-- initialize curves.
FOR i: INT IN [1..numberOfCurves] DO
[] ← GraphOps.EnlistEntity[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.AddCrossSection[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.