/*
 * simpleGNUPlotinput.c
 *
 *  Created on: Oct 7, 2011
 *      Author: wlm
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define LEN_FILENAAM    1000        /* maximale lengte van filenaam */
#define MAXPOINTS       25

float functie(float x, int type) {
	switch (type) {
	case 0:
		return (x * x);
		break;
	case 1:
		return (-0.1*x*x*x + x * x + 10 * x - 50 );
		break;
	}
	return (0);
}

int main() {
	FILE *fout;                /* file identifier van outputfile */
	char filnam[LEN_FILENAAM]; /* naam van input- en outputfile */
	int i, type = 0;
	float interval, x, y, step;

	for (type=0;type<2;type++) {
		sprintf(filnam,"n:/college-programmeren/gnuplot/leo/simpleplot%d.dat",type); /* Vul hier je eigen directory in*/
		if ((fout = fopen(filnam, "w")) == NULL) {
			printf("Output file '%s' kan niet geopend worden!\n", filnam);
			return (1);
		}
		interval = 30.;
		step = interval / (float) (MAXPOINTS + 1);
		x = -interval / 2.;
		for (i = 0; i < MAXPOINTS; i++) {
			x += step;
			y = functie(x, type);
			fprintf(fout, "%f  %f \n", x, y);
		}
		fclose(fout);
	}
	return (0);
}
