作者MasterChang (我爱ASM)
看板C_and_CPP
标题Re: [问题] 关於用c或是c++画讯号波形图
时间Fri Jan 13 01:28:43 2006
※ 引述《kyohung (哀..可悲...)》之铭言:
: 我想请问各位的大大,我现在想透过c或是c++来写一个画简单波形图的程式
: 我已经把读档和把里面有用的资讯转成txt的部份写好,现在我必须写一个
: 能够在读入txt资料後画出一张波形图来,但是其中我可以设定横轴的时间刻度
: 我不知道这该参考哪些函式,请各位大大给我一些建议,谢谢!!
产生一个process执行gnuplot,使用popen建立一个对gnuplot的指令通道
c的部份只是单纯产生一对数值给暂存档,依据这暂存档画出图形
下面这范例产生3d点的顺序有点问题,只是在这做个示范.....
[原码取自gnuplot使用手册]
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
using namespace std;
#define PANIC(a) do { perror(a);\
if (temp) unlink (temp);\
exit(1);\
}while(0);
int main()
{
char *temp;
FILE *command,*data;
double x,y,f;
int ix;
if((temp = tmpnam((char*)0))==0) PANIC("tmpnam failed");
if(mkfifo(temp, S_IRUSR | S_IWUSR)!=0) PANIC("mkfifo failed");
command = popen("gnuplot","w");
fprintf(command,"splot \"%s\" with lines\n",temp);fflush(command);
data = fopen(temp,"w");
for(ix=-35 ; ix<35 ; ix++)
{
for(int iy=-35;iy<35;iy++)
{
x=ix/10.0;
y=iy/10.0;
f=sin(3*x+4*y);
fprintf(data,"%f %f %f\n",x,y,f);
}
}
fclose(data);
fprintf(stderr,"press enter to continue...");fflush(stderr);
getchar();
fclose(command);
unlink(temp);
return 0;
}
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.132.23.74