2015-02-01 3 views
-1

Я застрял в этой ошибке «gnuplot: не удалось прочитать data.dat» с 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[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); 

} 
+0

«труба» представляет собой системный вызов в C, используйте другое имя – user3629249

+0

, если файл не открыт, то я подозреваю, что эта программа должна выйти, а не продолжать последующие заявления – user3629249

+0

не может очистить файл после него закрыто. (и закрытие выполняет флеш в любом случае) – user3629249

ответ

0
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); 
      . 
      . 
    } 
0

документация по fopen_s состояний это о строке режима: (есть и другие разрешенные строки режима, но следующие, кажется наиболее полезными)

«г +» открывает для чтения и письмо. (Файл должен существовать.)

«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. 
+0

Затем, как получить разрешение – shreyas

Смежные вопросы