29 lines
648 B
C++
Executable File
29 lines
648 B
C++
Executable File
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <math.h>
|
|
#define NUM_POINTS 100
|
|
#define NUM_COMMANDS 2
|
|
|
|
int main()
|
|
{
|
|
char* commandsForGnuplot[] = {"set title \"EXEMPLE\"", "plot 'data.temp'"};
|
|
double xvals[NUM_POINTS];
|
|
double yvals[NUM_POINTS];
|
|
FILE * temp = fopen("data.temp", "w");
|
|
FILE * gnuplotPipe = popen ("gnuplot -persistent", "w");
|
|
int i;
|
|
|
|
for (i=0; i < NUM_POINTS; i++)
|
|
{
|
|
xvals[i]= i*3,1415/50;
|
|
yvals[i]= cos(xvals[i]);
|
|
fprintf(temp, "%lf %lf \n", xvals[i], yvals[i]);
|
|
}
|
|
|
|
for (i=0; i < NUM_COMMANDS; i++)
|
|
{
|
|
fprintf(gnuplotPipe, "%s \n", commandsForGnuplot[i]);
|
|
}
|
|
return 0;
|
|
}
|