#import <Foundation/Foundation.h>
#import <aquaterm/AQTAdapter.h>;
#include "plplot/plplot.h";

int main(int argc, char *argv[])
{
	int i;
	char ver[80];
	char *plotmem;
	NSAutoreleasePool *arpool;   // Objective-C autorelease pool
	id adapter;					// Adapter object

	arpool = [[NSAutoreleasePool alloc] init];
	adapter = [[AQTAdapter alloc] init];

	[adapter openPlotWithIndex:1];
	[adapter setPlotSize:NSMakeSize(200, 200)];
	[adapter setLinewidth:1.0];
	[adapter setColorRed:1.0
				   green:1.0
				    blue:1.0];

	plgver(ver);
	fprintf(stderr, "PLplot library version: %s\n", ver);

	plspage(0, 0, 400, 300, 0, 0);
	plotmem = (char *)malloc(200 * 200 * 3 * sizeof(char));
	plsmem(200, 200, plotmem);
	for(i=0;i<(200*200*3);i++) { plotmem[i] = 0; }
	plinit();
	plenv(0, 10.0, 0, 10.0, 0, 0);
	pljoin(1.0, 2.0, 7.0, 8.0);	
	plend();
	
	[adapter addImageWithBitmap:(const void *)plotmem 
	                       size:NSMakeSize(200, 200) 
	                     bounds:NSMakeRect(0, 0, 199, 199)];
	[adapter moveToPoint:NSMakePoint(10,10)];
	[adapter addLineToPoint:NSMakePoint(190,150)];
	[adapter renderPlot];
	[adapter closePlot];
	
	free(plotmem);
}
