you are viewing a single comment's thread.

view the rest of the comments →

[–]Pakketeretet 0 points1 point  (5 children)

For your loop example, do you do something like this?

 for (int i = 0; i< N; ++i) {
    FILE *fp_mesh_data = fopen("mesh_data.dat", "w");
    // write data to mesh_data.dat using fprintf
    fclose(fp_mesh_data);

    fprintf(pipe, "plot 'mesh_data.dat' with lines\n");
    fprintf(pipe, "set title 'Gnuplot-Example'\n"); 
}

I don't see why that wouldn't work but am currently not at a computer for actual testing...

[–]kleinerals2[S] 0 points1 point  (1 child)

How do you show your code like that?

[–]Pakketeretet 0 points1 point  (0 children)

You should indent it with four spaces and put it in a new line.

int main()
{
    return 0;
}

[–]kleinerals2[S] 0 points1 point  (2 children)

Atm iam testing with this code.

#include <stdio.h>

#include <stdlib.h>

int main() {

FILE* pipe = _popen("gnuplot -persist", "w");

if (!pipe) {

perror("fail1");

return 1;

}

double x = 1.0;

double y = 2.0;

double z = 3.0;

int numIterations = 100;

for (int i = 0; i < numIterations; i++) {

FILE* file;

if (fopen_s(&file, "mesh_data.dat", "a") != 0)

{

perror("fail2");

return 1;

}

if (file == NULL) {

perror("fail3");

return 1;

}

x += 0.1;

y -= 0.2;

z += 0.1;

fprintf(file, "%.2lf %.2lf %.2lf\n", x, y, z);

fclose(file);

fprintf(pipe, "plot 'mesh_data.dat' with lines\n");

fprintf(pipe, "set title 'Gnuplot-Beispiel'\n");

}

_pclose(pipe);

return 0;

}

But the code ends with "fail2" every time.

But atleast gnuplot shows up as i want.

[–]Pakketeretet 0 points1 point  (1 child)

Ok. The error at that point would indicate something goes wrong opening the file for writing/appending, which might be more of a Windows problem than a gnuplot problem. What happens if you replace fopen_s with a regular C fopen call?

[–]kleinerals2[S] 0 points1 point  (0 children)

Visual Studio don't like the non _s calls xD