C gnuplot无法读取.dat文件
2天以来,我一直被这个错误“gnuplot:无法读取数据.dat”所困扰 我已经把文件路径也,但仍然是错误的到来。我搜索了互联网,我没有得到它 多谢各位C gnuplot无法读取.dat文件,c,windows,visual-studio-2012,gnuplot,C,Windows,Visual Studio 2012,Gnuplot,2天以来,我一直被这个错误“gnuplot:无法读取数据.dat”所困扰 我已经把文件路径也,但仍然是错误的到来。我搜索了互联网,我没有得到它 多谢各位 void plotgraph(float *xvals, float *yvals, float *x1vals, int NUM_POINTS) { int NUM_COMMANDS = 4; //char * commandsForGnuplot[] = { "set title \"Concatenated Coding+OFDM[Q
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);
}
void绘图仪(浮点*xVAL、浮点*yVAL、浮点*x1VAL、整数点)
{
int NUM_命令=4;
//char*commandsForGnuplot[]={“set title\”级联编码+OFDM[QPSK]\,“set ylabel'BER',“set xlabel'SNR',“plot'\C:\\Users\\shryasn\\Documents\\visualstudio 2013\\Projects\\Project1\\Project1\\data.temp\'带行“};
//文件*temp=fopen_s(&temp,“%temp%\\data.temp”,“w”);
//char*commandsForGnuplot[]={“set title\”级联编码+OFDM[QPSK]\”,“set ylabel'BER'”,“set xlabel'SNR'”,“set logscale y y”,“set nologscale x”,“plot'data.temp'带有行标题'After Coding',“data.temp1'带有行标题'Before Coding'”;
//双xvals[NUM_POINTS]={1.0,2.0,3.0,4.0,5.0};
//双yvals[NUM_POINTS]={5.0,3.0,1.0,3.0,5.0};
int i;
对于(i=0;i
注:fd[0]设置为读取,fd[1]设置为写入
数组中的第一个整数(元素0)被设置并打开以进行读取,而第二个整数(元素1)被设置并打开以进行写入。从视觉上讲,fd1的输出成为fd0的输入。同样,通过管道传输的所有数据都会通过内核
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
main()
{
int fd[2];
pipe(fd);
.
.
}
#包括
#包括
#包括
main()
{
int-fd[2];
管道(fd);
.
.
}
fopen上的文档说明了有关模式字符串的以下内容:
(还有其他允许的模式字符串,但以下内容似乎是
(最有用)
“r+”
为阅读和写作打开。(文件必须存在。)
“w+”
打开一个空文件进行读取和写入。
如果文件存在,其内容将被销毁
So I suggest using the "r+" mode string rather than the "w+" mode string
the failure to open suggests that the user does not have
permission to overwrite the file.
“pipe”是C中的一个系统调用,请使用不同的名称如果文件没有打开,那么我怀疑程序应该退出,而不是继续下一个语句在文件关闭后不能刷新文件。(并且关闭会执行刷新)此线段:“char*commandsForGnuplot[]”可能应该是:“char**commandsForGnuplot[][]”,并且实际的命令应该相应地格式化。即{“command1”}、{“command2”}、…};文件名中的第一个字符是错误的反斜杠,不需要转义单引号。应该是
“plot'C:\\Users…”
。然后如何获得权限
So I suggest using the "r+" mode string rather than the "w+" mode string
the failure to open suggests that the user does not have
permission to overwrite the file.