zoukankan      html  css  js  c++  java
  • PGPLOT Examples using fortran and c language.

    PGPLOT Examples

    PGPLOT is designed to make it easy to generate simple graphs, while providing full capability for more complex graphs. As an example of a simple graph, here is a graph of the function y = x� exp(-x), which was drawn with six PGPLOT subroutine calls. [graphics] This figure is a GIF file. With no change to the source code, the program can also generate files in other formats, such as PostScript. Here is the Fortran code required to draw this graph, with comments to explain the purpose of each subroutine call. The question mark as an argument to PGOPENallows the user to specify a file name and file format at run time.
          PROGRAM EX1
          INTEGER PGOPEN, I
          REAL XS(9), YS(9), XR(101), YR(101)
    
    C Compute numbers to be plotted.
    
          DO 10 I=1,101
              XR(I) = 0.1*(I-1)
              YR(I) = XR(I)**2*EXP(-XR(I))
     10   CONTINUE
          DO 20 I=1,9
              XS(I) = I
              YS(I) = XS(I)**2*EXP(-XS(I))
     20   CONTINUE
    
    C Open graphics device.
    
          IF (PGOPEN('?') .LT. 1) STOP
    
    C Define coordinate range of graph (0 < x < 10, 0 < y < 0.65),
    C and draw axes.
    
          CALL PGENV(0., 10., 0., 0.65,  0,  0)
    
    C Label the axes (note use of \u and \d for raising exponent).
    
          CALL PGLAB('x', 'y', 'PGPLOT Graph: y = x\u2\dexp(-x)')
    
    C Plot the line graph.
    
          CALL PGLINE(101, XR, YR)
    
    C Plot symbols at selected points.
    
          CALL PGPT(9, XS, YS, 18)
    
    C Close the graphics device.
    
          CALL PGCLOS
    
          END
    The same program can be written in C, using the cpgplot library.
    #include "cpgplot.h"
    #include "math.h"
    
    int main()
    {
       int i;
       float xs[9], ys[9];
       float xr[101], yr[101];
    
       /* Compute numbers to be plotted. */
    
       for (i=0; i<101; i++) {
         xr[i] = 0.1*i;
         yr[i] = xr[i]*xr[i]*exp(-xr[i]);
       }
       for (i=0; i<9; i++) {
         xs[i] = i+1;
         ys[i] = xs[i]*xs[i]*exp(-xs[i]);
       }
    
       /* Open graphics device. */
    
       if (cpgopen("?") < 1)
         return 1;
    
       /* Define coordinate range of graph (0 < x < 10, 0 < y < 0.65),
          and draw axes. */
    
       cpgenv(0., 10., 0., 0.65, 0, 0);
    
       /* Label the axes (note use of \\u and \\d for raising exponent). */
    
       cpglab("x", "y", "PGPLOT Graph: y = x\\u2\\dexp(-x)");
    
       /*  Plot the line graph. */
    
       cpgline(101, xr, yr);
    
       /* Plot symbols at selected points. */
    
       cpgpt(9, xs, ys, 18);
    
       /* Close the graphics device */
    
       cpgclos();
       return 0;
    }
  • 相关阅读:
    查看电脑保存的wifi密码
    数据仓库
    nodejs 中国汉字模糊查询简单(很low)实现
    nodejs express 框架 上传文件
    async样例
    mongodb Map/reduce测试代码
    未释放资源的教训,开发MongoDB连接一定要关闭连接
    采集系统优化:大家接手过的最烂的项目,最坑爹的项目是哪个?
    Android的HttpClient调用,冲突的解决办法
    MongoDBcrud操作,采集部分代码
  • 原文地址:https://www.cnblogs.com/shaoguangleo/p/2806063.html
Copyright © 2011-2022 走看看