• gunplot demo


     1 //author : Leon yangli0534@gmail.com
     2 
     3 #include <stdlib.h>
     4 #include <stdio.h>
     5 #include <math.h>
     6 #define NUM_POINTS 500
     7 #define NUM_COMMANDS 2
     8 
     9 int main()
    10 {
    11     char * commandsForGnuplot[] = {"set title "gunplot demo"", "plot 'data.temp'"};
    12     double fs = 1000000.0;
    13     double f0 = 10000.0;
    14     double xvals[NUM_POINTS] = {1.0, 2.0, 3.0, 4.0, 5.0};
    15     double yvals[NUM_POINTS] = {5.0 ,3.0, 1.0, 3.0, 5.0};
    16     FILE * temp = fopen("data.temp", "w");
    17     /*Opens an interface that one can use to send commands as if they were typing into the
    18      *     gnuplot command line.  "The -persistent" keeps the plot open even after your
    19      *     C program terminates.
    20      */
    21     FILE * gnuplotPipe = popen ("gnuplot -persistent", "w");
    22     int i;
    23     for (i=0; i < NUM_POINTS; i++)
    24     {
    25     xvals[i] = i/fs;
    26     yvals[i] = sin(2*M_PI*f0*xvals[i]);
    27     }
    28     for (i=0; i < NUM_POINTS; i++)
    29     {
    30     fprintf(temp, "%lf %lf 
    ", xvals[i], yvals[i]); //Write the data to a temporary file
    31     }
    32 
    33     for (i=0; i < NUM_COMMANDS; i++)
    34     {
    35     fprintf(gnuplotPipe, "%s 
    ", commandsForGnuplot[i]); //Send commands to gnuplot one by one.
    36     }
    37     return 0;
    38 }

    OPTIMISM, PASSION & HARDWORK
  • 相关阅读:
    类的多重继承
    实例属性和类属性
    协程
    nginx安装与配置
    Linux系统优化及状态监控
    MongoDb安全配置:简单的身份认证
    MongoDB YAML格式的配置文件
    yum使用,使用rpm指令安装rpm,使用dpkg指令安装deb
    MongoDB默认配置
    被锐速加防火墙坑了一下。。。
  • 原文地址:https://www.cnblogs.com/hiramlee0534/p/5792232.html
Copyright © 2020-2023  润新知