program test;

	uses
		EZPlot;

	var
		dat1, dat2: datPtr;
		np1, np2: integer;
		F1, F2, F3: frame;
		myFrameFormat: frameType;
		plotRect: rect;
		useGivenExtrema: boolean;

	procedure InitData;  { initializes the globals myData, numPts, plotRect }
		const
			numCycles = 123;
		var
			i: integer;
	begin
		np1 := 57;
		np2 := 57;
		dat1 := datPtr(NewPtr(2 * np1 * sizeOf(real)));
		dat2 := datPtr(NewPtr(2 * np2 * sizeOf(real)));

		if (dat1 = nil) or (dat2 = nil) then
			begin
				writeln('Error - couldn''t allocate memory for data!');
				halt;
			end;

		for i := 1 to np1 do
			begin
				dat1^[i].x := i - np1 div 2;
				dat1^[i].y := 1.67e2 * sin(2 * pi * numCycles / np1 * (i - np1 div 2));
			end;

		for i := 1 to np2 do
			begin
				dat2^[i].x := i - np2 div 2;
				dat2^[i].y := sqr(i - np2 div 2);
			end;

		plotRect.left := 10;
		plotRect.top := 10;
		plotRect.right := 460;
		plotRect.bottom := 260;
	end;

begin { main }
	InitData;
	ShowDrawing;
	findExtremes(dat1, np1, f1);
	findExtremes(dat2, np2, f2);
	ExtremaOr(f1, f2, f3);
	useGivenExtrema := true;
	myFrameFormat := [box, numbers, majorGrid];
	ChooseFrame(dat1, np1, plotRect, 'x', 'y', f3, myFrameFormat, useGivenExtrema);
	PlotFrame(f3, myFrameFormat, plotRect);
	plotData(dat1, np1, f3, [circle, points, lines], solid);
	plotData(dat2, np2, f3, [hist], solid);
	Dispose(dat1);
	Dispose(dat2);
end.