#include #include #include #include #include #include #define ENVELOP "envelop.txt" void moveFromLeft2Right(FILE * sd, char shape[], double fps); int main(int argc, char* argv[]) { pid_t pid; int pfd[2]; int i, status; FILE * sd; /* * Create a pipe. */ if (pipe(pfd) < 0) { perror("pipe"); exit(1); } /* * Create a child process. */ if ((pid = fork()) < 0) { perror("fork"); exit(1); } /* * The child process executes "gnuplot". */ if (pid == 0) { /* * Attach standard input of this child process to read from the pipe. */ dup2(pfd[0], 0); close(pfd[1]); /* close the write end off the pipe */ execlp("gnuplot", "gnuplot", 0); perror("exec"); _exit(127); } /* * We won't be reading from the pipe. */ close(pfd[0]); sd = fdopen(pfd[1], "w"); moveFromLeft2Right(sd, ENVELOP, atof(argv[1])); /*getchar();*/ fprintf(sd, "\n exit"); fflush(sd); /* * Close the pipe and wait for the child * to exit. */ fclose(sd); waitpid(pid, &status, 0); /* * Exit with a status of 0, indicating that * everything went fine. */ exit(0); } static void keepGoing(int signal) { return; } #define scanTime 20 /* in seconds*/ #define boardWidth 1000 void moveFromLeft2Right(FILE * sd, char* shape, double fps) { struct itimerval it_val; int x, delta_x; it_val.it_interval.tv_sec=(int)(1/fps); it_val.it_interval.tv_usec= 1000000*(1/fps - (int)(1/fps)); it_val.it_value=it_val.it_interval; setitimer(ITIMER_REAL, &it_val, NULL); signal(SIGALRM, keepGoing); delta_x= (boardWidth-10)/(scanTime*fps); /*assume shape`s width = 10*/ fprintf(sd, "set xrange [0:%i]\n set yrange[0:20]\n", boardWidth); /* fprintf(sd, "plot \"%s\" using ($1):($2) with lines lt 1\n", shape); fflush(sd); printf("Ajuste tamaņo de ventana y presione enter\n"); fflush(stdout); getchar(); */ for (x=0 ; x< boardWidth; x+=delta_x) { pause(); fprintf(sd, "plot \"%s\" using ($1+%i):($2+%i) with lines lt 1\n", shape, x, 5); fflush(sd); } }