gpt4 book ai didi

c - gnuplot 无法读取 .dat 文件

转载 作者:行者123 更新时间:2023-11-30 19:44:25 24 4
gpt4 key购买 nike

我已经被这个错误“gnuplot:unable to read data.dat”困扰了两天。

我也输入了文件路径,但仍然出现错误。我搜索了互联网,但没有得到它。

谢谢

void plotgraph(float *xvals, float *yvals, float *x1vals, int NUM_POINTS)
{

int NUM_COMMANDS = 4;
//char * commandsForGnuplot[] = { "set title \"Concatenated Coding+OFDM[QPSK]\"", "set ylabel 'BER'", "set xlabel 'SNR'", "plot '\C:\\Users\\shreyasn\\Documents\\Visual Studio 2013\\Projects\\Project1\\Project1\\data.temp\' with lines" };
//FILE * temp = fopen_s(&temp, "%temp%\\data.temp", "w");
//char *commandsForGnuplot[] = { "set title \"Concatenated Coding+OFDM[QPSK]\"", "set ylabel 'BER'", "set xlabel 'SNR'", "set logscale y", "set nologscale x", "plot 'data.temp' with lines title 'After coding' , \ 'data.temp1' with lines title 'Before coding'" };
// double xvals[NUM_POINTS] = {1.0, 2.0, 3.0, 4.0, 5.0};
//double yvals[NUM_POINTS] = {5.0 ,3.0, 1.0, 3.0, 5.0};
int i;
for (i = 0; i < NUM_POINTS; i++)
{
printf("time: %f decod: %f encod: %f \n", xvals[i], x1vals[i], yvals[i]); //Write the data to a temporary file
}

errno_t err;
FILE *pipe;
FILE *temp9;
if ((err = fopen_s(&temp9, "data.dat", "w+")) != 0)
printf("File not opened\n");
if (temp9 == NULL) {
printf("Error\n");
}

char * commandsForGnuplot[] = { "set title \"Concatenated Coding+OFDM[QPSK]\"", "set ylabel 'BER'", "set xlabel 'SNR'","plot '\C:\\Users\\shreyasn\\Documents\\Visual Studio 2013\\Projects\\Project1\\Project1\\data.dat\' using 1:2 with lines" };
//char * commandsForGnuplot[] = { "set title \"Concatenated Coding+OFDM[QPSK]\"", "set ylabel 'BER'", "set xlabel 'SNR'", "plot 'data.dat' with lines" };
//FILE * temp1 = fopen_s(&temp1,"data.temp1", "w");
//char *path = "C:\\Program Files (x86)\\gnuplot\\bin";
pipe = _popen("\"C:\\gnuplot\\binary\\gnuplot.exe\" -persistent", "w");
//Opens an interface that one can use to send commands as if they were typing into the
// gnuplot command line. "The -persistent" keeps the plot open even after your
// C program terminates.
//




for (i = 0; i < NUM_POINTS; i++)
{
fprintf(temp9, "%f %f \n", xvals[i], yvals[i]); //Write the data to a temporary file
//fprintf(temp1, "%lf %lf \n", xvals[i], x1vals[i]); //Write the data to a temporary file
}

fclose(temp9);
fflush(temp9);

for (i = 0; i < NUM_COMMANDS; i++)
{
fprintf(pipe, "%s \n", commandsForGnuplot[i]); //Send commands to gnuplot one by one.
}
fflush(pipe);

}

最佳答案

the following information, copied from elsewhere, 
it shows how to open a pipe.

prototype:
int pipe(intfd[2]);
RETURNS: 0 success
-1 on error: and set errno

注意:fd[0] 设置为读取,fd[1] 设置为写入

数组中的第一个整数(元素 0)被设置并打开以供读取,而第二个整数(元素 1)被设置并打开以供写入。直观地说,fd1 的输出成为 fd0 的输入。再次,所有通过管道传输的数据都会通过内核。

    #include <stdio.h>
#include <unistd.h>
#include <sys/types.h>

main()
{
int fd[2];

pipe(fd);
.
.
}

关于c - gnuplot 无法读取 .dat 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28260232/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com