<> <> <<>> 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; PhaseShift: REAL = timeIncrement: REAL = 4.0/100.0; -- 100 time increments in 4 <<-- 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* 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.