#include "cpgplot.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define DIV 100
main(int argc, char *argv[])
{
char *devname = "?";
int i;
float x[DIV], y[DIV];
/* if(cpgbeg(0, "?", 1, 1) != 1)
exit(EXIT_FAILURE); */
cpgask(1);
if (argc == 2)
devname = argv[1];
if(cpgopen(devname) != 1)
exit(1);
cpgpap(6, 0.75); /* 6inch, aspect ratio =1.0 (aquare) */
cpgscr(0, 1, 1, 1); /* 0: background (default is black) */
cpgscr(1, 0, 0, 0); /* 0: foreground (default is white) */
cpgscf(1); /* 1:normal, 2:roman, 3:italic, 4:script */
cpgsch(1.2);
cpgslw(2); /* unit in 0.005 inch = 0.13 mm */
cpgenv(-2*M_PI, 2*M_PI, -1, 1, 0, 0);
cpglab("\\frRoman", "\\fiItalic", "PGPLOT Plot2d");
for (i=0; i < DIV; i++) {
x[i]=(i-DIV/2)*4*M_PI/DIV;
y[i]=cos(x[i]);
}
cpgslw(8);
cpgsci(2);
cpgline(DIV, x, y);
for (i=0; i < DIV; i++) {
x[i]=(i-DIV/2)*4*M_PI/DIV;
y[i]=sin(x[i]);
}
cpgslw(2); /* unit in 0.005 inch = 0.13 mm */
cpgsci(3); /* green */
cpgsls(4); /* 4:dotted */
cpgpt(DIV, x, y, 23); /* 23:medium open circle */
cpgclos();
return 0;
}
#
# ソースのコンパイル
#
g77 -o plot2d plot2d.c -lcpgplot -lpgplot -L/usr/X11R6/lib
-lX11 -lm -lpng
#
# 環境変数の設定
#
export PGPLOT_DIR=/usr/local/pgplot
export PGPLOT_DEV=/xwin
#
# 実行
#
./plot2d /xwin (Xで描画)
./plot2d plot2d.ps/cps (カラーP S の作成)
./plot2d plot2d.png/tpng (透明 PNG の作成)
|
# PGPLOT には残念ながら 3dプロットの標準ルーチンはありません.
# 自分で,隠線処理等を含めたソースを書かなければなりません.
# ところで pgdemo7 は 3dプロットのデモですから,
# その部分(FREDDY)だけを取り出して
#
# g77 -c freddy.f
#
# により,オブジェクトファイルを作成しておき,リンクして使うこ
# とができます.ただし,これは生の FORTRAN オブジェクトですから,
#
# 変数の呼び出し時は参照渡し
#
# にすることと,関数の名前は後ろにアンダーをつけて
#
# freddy_
#
# となることに注意して,C 言語から呼び出します.
#include "cpgplot.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define DIV 51
int
main(int argc, char **argv)
{
char *devname = "?";
int i, j, k, div=DIV;
float *z, size = 1.0, angle=25.0;
double x, y;
z = malloc(DIV*DIV*sizeof(float));
cpgask(1);
if (argc == 2)
devname = argv[1];
if(cpgopen(devname) != 1)
exit(1);
for(i=1; i<=DIV; i++){
for(j=1; j<=DIV; j++){
k = (i-1)*DIV + (j-1);
x = -2*M_PI+(i-1)*4*M_PI/DIV;
y = -2*M_PI+(j-1)*4*M_PI/DIV;
z[k] = sin(x)*sin(y)/x/y;
}
}
cpgpap(6,1);
cpgscr(0, 1, 1, 1);
cpgscr(1, 0, 0, 0);
cpgsch(1.4);
cpgscf(2);
cpgslw(4);
cpgenv(0.0, 1.0, 0.0, 1.0, 1, -2);
cpglab("", "", "PGPLOT Plot3d");
cpgsci(11); /* dark blue */
cpgslw(1); /* line width 1 */
freddy_(z, &div, &div, &size, &angle);
cpgclos();
free(z);
return 0;
}
#
# コンパイル
#
g77 -o plot3d plot3d.c freddy.o -lcpgplot -lpgplot -lX11
-lpng -lm -L/usr/X11R6/lib
#
# 実行
#
./plo3d /xwin
./plot3d plot3d.ps/cps
|
#include "cpgplot.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define DIV 50
main(int argc, char *argv[])
{
char *devname = "?";
int i, j, k, ls, ci;
float *z, zmin, zmax, zlevel;
float tr[6]={-10.0, 0.4, 0.0, -10.0, 0.0, 0.4};
double x,y;
cpgask(1);
if (argc == 2)
devname = argv[1];
if(cpgopen(devname) != 1)
exit(1);
z = malloc(DIV*DIV*sizeof(float));
zmin = zmax = 0.0;
for (j=1; j<=DIV; j++){
for (i=1; i<=DIV; i++){
k = (j-1)*DIV+(i-1);
x = tr[0]+ tr[1]*i + tr[2]*j;
y = tr[3]+ tr[4]*i + tr[5]*j;
z[k] = sin(x)*sin(y)/x/y;
if (z[k] < zmin) zmin = z[k];
if (z[k] > zmax) zmax = z[k];
}
}
cpgpap(6,1); /* 6inch, aspect ratio = 1 (square) */
cpgscr(0, 1, 1, 1);
cpgscr(1, 0, 0, 0);
cpgsch(1.2);
cpgenv(-10, 10, -10, 10, 0, 0);
cpglab("\\frRoman", "\\fiItalic", "PGPLOT Contour");
for (i=0; i<14; i++) {
zlevel = -0.5 + i*0.1;
ls = (zlevel < 0) ? 2 : 1;
if ( zlevel < 0.0) {
ci = 4;
} else if ( zlevel < 0.5 ) {
ci = 3;
} else ci = 2;
cpgsls(ls);
cpgsci(ci);
cpgcont(z,DIV,DIV,1,DIV,1,DIV, &zlevel, -1, tr);
}
cpgclos();
free(z);
return 0;
}
|
#
# パネルを Nx X Ny に分割する関数を使います.
# [c]pgpage() あるいは [c]pgenv() でパネルが移動します.
#
#include "cpgplot.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define DIV 100
#define N 51
#define N3 31
main(int argc, char *argv[])
{
char *devname = "?";
int i, j, k, ls, ci, div;
float *z, zmin, zmax, zlevel ;
float x[DIV], y[DIV], angle, size;
float tr[6]={-10.0, 0.4, 0.0, -10.0, 0.0, 0.4};
double xx, yy;
if (argc == 2)
devname = argv[1];
if(cpgopen(devname) != 1)
exit(1);
cpgpap(6, 1); /* 6inch, aspect ratio = 3/4 */
cpgscr(0, 1, 1, 1); /* 0: background (default is black) */
cpgscr(1, 0, 0, 0); /* 0: foreground (default is white) */
cpgsubp(2,2); /* 2x2 に分割 */
/* 2dplot */
cpgenv(-2*M_PI, 2*M_PI, -1, 1, 0, 0);
cpglab("\\frRoman", "\\fiItalic", "PGPLOT Plot2d");
for (i=0; i |