ruby-pgplot 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README ADDED
@@ -0,0 +1,100 @@
1
+ Ruby/PGPLOT ver 0.1.4 by Masahiro TANAKA 2012-01-04
2
+
3
+ = Description
4
+
5
+ * Ruby interface to PGPLOT.
6
+ It provides PGPLOT functions as a Ruby module.
7
+
8
+ = Requirement
9
+
10
+ * PGPLOT ver 5.2.x
11
+ (http://astro.caltech.edu/~tjp/pgplot/)
12
+ * Libraries which PGPLOT drivers use:
13
+ ** X11 library
14
+ ** PNG library
15
+ ** GrWin Graphics Library for MS-Windows.
16
+ (http://spdg1.sci.shizuoka.ac.jp/grwinlib/english/)
17
+ * Ruby ver 1.8.x/1.9.x
18
+ * NArray ver 0.5.x/0.6.x
19
+ (http://www.ruby-lang.org/en/raa-list.rhtml?name=NArray)
20
+
21
+ = Installation
22
+
23
+ * install PGPLOT library
24
+
25
+ - FORTRAN77 compiler required for source-compile.
26
+ - C interface library (libcpgplot.a) is also required.
27
+
28
+ * install Ruby, NArray
29
+
30
+ * install Ruby/PGPLOT
31
+
32
+ - extract distribution.
33
+
34
+ - compile and install by:
35
+
36
+ ruby extconf.rb [options (see below)]
37
+ make
38
+ make site-install
39
+ (or make install)
40
+
41
+ - Options for `ruby extconf.rb':
42
+ --with-pgplot-include=path : path to cpgplot.h
43
+ --with-pgplot-lib=path : path to PGPLOT libraries.
44
+ --with-x11-dir=path : path to X11
45
+ --with-grwin : for using GrWin (cygwin/mingw).
46
+ --with-sunws : PGPLOT is compiled with Sun WorkShop f77.
47
+ gfortran is assumed without this option.
48
+
49
+ example:
50
+ ruby extconf.rb --with-x11-dir=/usr/X11R6 \
51
+ --with-pgplot-include=/usr/local/pgplot \
52
+ --with-pgplot-lib=/usr/local/pgplot
53
+
54
+ = Usage
55
+
56
+ * Environment variables for PGPLOT (csh):
57
+
58
+ setenv PGPLOT_DIR /usr/local/lib/pgplot/ # pgxwin_server, rgb.txt
59
+ setenv PGPLOT_FONT ${PGPLOT_DIR}/grfont.dat
60
+ setenv PGPLOT_DEV /xwin
61
+
62
+ * To load the Ruby/PGPLOT extension;
63
+
64
+ require "pgplot"
65
+
66
+ * Module name is `Pgplot'. If you want to omit the module name;
67
+
68
+ include Pgplot
69
+
70
+ * Pgplot module method names are lower case of corresponding
71
+ PGPLOT functions. To start plotting:
72
+
73
+ pgbeg('/xwin')
74
+
75
+ See PGPLOT manual for function usage.
76
+ Arguments are not always same as the FORTRAN PGPLOT.
77
+ "FuncUsage" file includes a list of functions with
78
+ different arguments.
79
+
80
+ = Platforms tested
81
+
82
+ * ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]
83
+ * ruby 1.8.7 (2011-02-18 patchlevel 334) [x86_64-linux]
84
+ * NArray 0.6.0.1
85
+ * gcc/gfortran version 4.5.1 20100924 (Red Hat 4.5.1-4) (GCC)
86
+
87
+ = License
88
+
89
+ This program is free software.
90
+ You can distribute/modify this program
91
+ under the same terms as Ruby itself.
92
+ NO WARRANTY.
93
+
94
+ = Acknowledgment
95
+
96
+ M.T. thanks to Tim Pearson for developing the useful PGPLOT library
97
+ and giving me the permission to distribute the Ruby version of pgdemos.
98
+ M.T. also thanks to the developers of the Ruby language
99
+ for providing the wonderful language.
100
+
data/README.ja ADDED
@@ -0,0 +1,91 @@
1
+ Ruby/PGPLOT ver 0.1.4 by Masahiro TANAKA 2012-01-04
2
+
3
+ = 概要
4
+
5
+ * PGPLOTをRubyから使うための拡張ライブラリ。
6
+
7
+ = 必要なもの
8
+
9
+ * PGPLOT ver 5.2.x
10
+ (http://astro.caltech.edu/~tjp/pgplot/)
11
+ * PGPLOTのドライバが使うライブラリ (必要に応じて):
12
+ ** X11ライブラリ
13
+ ** PNGライブラリ
14
+ ** GrWinグラフィクスライブラリ for MS-Windows (Cygwinでのみ動作確認)
15
+ (http://spdg1.sci.shizuoka.ac.jp/grwinlib/)
16
+ * Ruby ver 1.8.x/1.9.x
17
+ * NArray ver 0.5.x/0.6.x
18
+ (http://www.ruby-lang.org/en/raa-list.rhtml?name=NArray)
19
+
20
+ = インストール方法
21
+
22
+ * PGPLOT をインストール
23
+
24
+ - FORTRAN77が必要です (gfortranでもOK)。
25
+ - C言語インタフェースライブラリ(cpgplot)を作成する必要があります。
26
+
27
+ * Ruby, NArray をインストール
28
+
29
+ * Ruby/PGPLOT をインストール
30
+
31
+ - ソースを展開
32
+
33
+ - コンパイル・インストール:
34
+ ruby extconf.rb [オプション(下記参照)]
35
+ make
36
+ make site-install
37
+ (または make install)
38
+
39
+ - ruby extconf.rb のオプション:
40
+ --with-pgplot-include=path : cpgplot.hのディレクトリ。
41
+ --with-pgplot-lib=path : PGPLOTライブラリのディレクトリ。
42
+ --with-x11-dir=path : X11のpath
43
+ --with-grwin : for using GrWin (cygwin/mingw).
44
+ --with-sunws : PGPLOTをSun WorkShopのf77を使って
45
+ コンパイルした場合。指定しない時はg77。
46
+ 例:
47
+ ruby extconf.rb --with-x11-dir=/usr/X11R6 \
48
+ --with-pgplot-include=/usr/local/pgplot \
49
+ --with-pgplot-lib=/usr/local/pgplot
50
+
51
+ = 使用方法
52
+
53
+ * PGPLOTの環境変数設定(csh)
54
+
55
+ setenv PGPLOT_DIR /usr/local/lib/pgplot/ # pgxwin_server, rgb.txt
56
+ setenv PGPLOT_FONT ${PGPLOT_DIR}/grfont.dat
57
+ setenv PGPLOT_DEV /xwin
58
+
59
+ * 拡張ライブラリをロードするには:
60
+
61
+ require "pgplot"
62
+
63
+ * モジュール名は`Pgplot'です。モジュール名を省略したいときは:
64
+
65
+ include Pgplot
66
+
67
+ * Pgplotモジュールのメソッドは、PGPLOTの関数と同じ名前(小文字)です。
68
+ プロットを開始するには:
69
+
70
+ pgbeg('/xwin')
71
+
72
+ 詳細は PGPLOTのマニュアルを参照して下さい。
73
+ 引数は必ずしもFORTRAN版と同じではありません。
74
+ 引数が違う関数のリストは、"FuncUsage"というファイルにあります。
75
+
76
+ = 動作確認
77
+
78
+ * ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]
79
+ * ruby 1.8.7 (2011-02-18 patchlevel 334) [x86_64-linux]
80
+ * NArray 0.6.0.1
81
+ * gcc/gfortran version 4.5.1 20100924 (Red Hat 4.5.1-4) (GCC)
82
+
83
+ = 配布条件
84
+
85
+ Ruby本体と同じです。
86
+ 無保証です。
87
+
88
+ = 謝辞
89
+
90
+ PGPLOTを開発し、Ruby版pgdemoの配布許可を下さった Tim Pearson氏
91
+ に感謝します。Ruby開発に携わった皆様に感謝します。
data/cogen.rb ADDED
@@ -0,0 +1,157 @@
1
+ # cogen.rb : Code generation script for Ruby/PGPLOT
2
+ #
3
+ # Copyright (c) 2000,2001 Masahiro TANAKA <masa@ir.isas.ac.jp>
4
+ #
5
+ # This program is free software.
6
+ # You can distribute/modify this program
7
+ # under the same terms as Ruby itself.
8
+ # NO WARRANTY.
9
+
10
+ $pgfuncs = %w(
11
+
12
+ pgend::
13
+ pgbbuf::
14
+ pgebuf::
15
+ pgpage::
16
+ pgpap:1,1:
17
+ pgupdt::
18
+ pgpanl:1,1:
19
+ pgclos::
20
+
21
+ pgbox:2,1,0,2,1,0:
22
+ pgtbox:2,1,0,2,1,0:
23
+ pgvsiz:1,1,1,1:
24
+ pgvstd::
25
+ pgwnad:1,1,1,1:
26
+ pgsubp:0,0:
27
+
28
+ pgwedg:2,1,1,1,1,2:
29
+
30
+ # Draw Funcs
31
+ pgdraw:1,1:
32
+ pgmove:1,1:
33
+ pgrect:1,1,1,1:
34
+ pgarro:1,1,1,1:
35
+ pgcirc:1,1,1:
36
+ pgpt1:1,1,0:
37
+ pgerr1:0,1,1,1,1:
38
+ pglab:2,2,2:
39
+ pgptxt:1,1,1,1,2:
40
+ pgtext:1,1,2:
41
+ pgmtxt:2,1,1,1,2:
42
+ pgetxt::
43
+
44
+ pgiden::
45
+ pgldev::
46
+ pgsave::
47
+ pgunsa::
48
+ pgeras::
49
+
50
+ # Set Funcs
51
+ pgsch:1:
52
+ pgscf:0:
53
+ pgsci:0:
54
+ pgsfs:0:
55
+ pgsls:0:
56
+ pgslw:0:
57
+ pgsclp:0:
58
+ pgsitf:0:
59
+ pgslct:0:
60
+ pgstbg:0:
61
+ pgscr:0,1,1,1:
62
+ pgshls:0,1,1,1:
63
+ pgsah:0,1,1:
64
+ pgscrl:1,1:
65
+ pgscir:0,0:
66
+ pgscrn:0,2:0
67
+ pgshs:1,1,1:
68
+ pgsvp:1,1,1,1:
69
+ pgswin:1,1,1,1:
70
+
71
+ # Query Funcs
72
+ pgqch::1
73
+ pgqcf::0
74
+ pgqci::0
75
+ pgqfs::0
76
+ pgqls::0
77
+ pgqlw::0
78
+ pgqclp::0
79
+ pgqid::0
80
+ pgqitf::0
81
+ pgqndt::0
82
+ pgqtbg::0
83
+ pgqcr:0:1,1,1
84
+ pgqvp:0:1,1,1,1
85
+ pgqwin::1,1,1,1
86
+ pgqcol::0,0
87
+ pgqcir::0,0
88
+ pgqpos::1,1
89
+ pgqvsz:0:1,1,1,1
90
+
91
+ ).grep(/:.*:/).collect{|i| i.split(":",3)}
92
+
93
+
94
+ def pgfuncgen(name, inp, out)
95
+ inp = inp.split(",").collect{|i| i.to_i}
96
+ out = out.split(",").collect{|i| i.to_i}
97
+ ninp = inp.size
98
+ nout = out.size
99
+ # int->0, float->1
100
+ val2 = ["NUM2INT","NUM2DBL","StringValuePtr"]
101
+ type = ["int","float",nil]
102
+ conv = ["INT2NUM","rb_float_new",nil]
103
+ # Initialize Array
104
+ prot = ["VALUE obj"]
105
+ pass = []
106
+ vars = []
107
+ retn = []
108
+ inp.each_with_index { |i,x|
109
+ prot << "VALUE arg#{x}"
110
+ pass << "#{val2[i]}(arg#{x})"
111
+ }
112
+ out.each_with_index { |i,x|
113
+ vars << "#{type[i]} var#{x};"
114
+ pass << "&var#{x}"
115
+ retn << "#{conv[i]}(var#{x})"
116
+ }
117
+ if nout==0 then
118
+ retn = "Qtrue";
119
+ elsif nout>1 then
120
+ retn = "rb_ary_new3(#{nout},"+retn.join(",")+")"
121
+ else
122
+ retn = retn.join("")
123
+ end
124
+
125
+ vars = vars.join("")
126
+ prot = prot.join(",")
127
+ pass = pass.join(",")
128
+
129
+ return "
130
+ static VALUE
131
+ rb_pgplot_#{name}(#{prot})
132
+ {
133
+ #{vars}
134
+ c#{name}(#{pass});
135
+ return #{retn};
136
+ }
137
+ "
138
+ end
139
+
140
+
141
+ def cogen_pgplot
142
+ fin = open("rb_pgplot.c.in","r")
143
+ fout = open("rb_pgplot.c","w")
144
+ while l = fin.gets
145
+ if /--- auto-generated funcs will be placed here ---/ =~ l
146
+ $pgfuncs.each{|x| fout.print pgfuncgen(*x)}
147
+ elsif /--- auto-generated defs will be placed here ---/ =~ l
148
+ $pgfuncs.each{|x|
149
+ n = x[1].split(",").size
150
+ fout.print " rb_define_module_function(mPgplot,\"#{x[0]}\",rb_pgplot_#{x[0]},#{n});\n"}
151
+ else
152
+ fout.print
153
+ end
154
+ end
155
+ end
156
+
157
+ cogen_pgplot
data/demo/pgdemo1.rb ADDED
@@ -0,0 +1,414 @@
1
+ require 'narray'
2
+ require 'pgplot'
3
+ include Pgplot
4
+ include NMath
5
+ PI = Math::PI
6
+ TWOPI = PI*2
7
+ BLACK,WHITE,RED,GREEN,BLUE,CYAN,MAGENT,YELLOW = (0..7).to_a
8
+ FULL,DASH,DOTDSH,DOTTED,FANCY = (1..5).to_a
9
+ NORMAL,ROMAN,ITALIC,SCRIPT = (1..4).to_a
10
+ SOLID,HOLLOW = (1..2).to_a
11
+
12
+ # ====== Utility function ======
13
+
14
+ def indgen arg
15
+ if arg.kind_of?(Range)
16
+ return NArray.sfloat(arg.size).indgen!(arg.first)
17
+ elsif arg.kind_of?(Numeric)
18
+ return NArray.sfloat(arg).indgen!
19
+ else
20
+ raise ArgumentError, "invalid argument"
21
+ end
22
+ end
23
+
24
+ def randomn n=1
25
+ rr = NArray.sfloat(n)
26
+ xx = NArray.sfloat(n)
27
+ idx= NArray.int(n).indgen!
28
+ i = 0
29
+ while i<n
30
+ x = NArray.sfloat(n*4/3).random!(1) * 2 - 1
31
+ y = NArray.sfloat(n*4/3).random!(1) * 2 - 1
32
+ r = x**2 + y**2
33
+ idx = (r<1).where
34
+ siz = [n-i,idx.size-1].min
35
+ rr[i] = r[idx[0...siz]]
36
+ xx[i] = x[idx[0...siz]]
37
+ #printf "i=%d,siz=%d,idx.size=%d\n",i,siz,idx.size
38
+ i += siz
39
+ end
40
+ return xx * sqrt(-2*log(rr)/rr)
41
+ end
42
+
43
+ # ====== Demo function ======
44
+
45
+ def pgex0
46
+ %w(
47
+ version
48
+ state
49
+ user
50
+ now
51
+ device
52
+ file
53
+ type
54
+ dev/type
55
+ hardcopy
56
+ terminal
57
+ cursor
58
+ ).each{|i| print " ",i," = ",pgqinf(i),"\n"}
59
+
60
+ x1,x2,y1,y2 = pgqvsz(1)
61
+ x = x2-x1
62
+ y = y2-y1
63
+ printf " Plot dimensions (x,y; inches): %9.2f, %9.2f
64
+ (mm): %9.2f, %9.2f\n",x, y, x*25.4, y*25.4
65
+ end
66
+
67
+ def pgex1
68
+ pgenv 0, 10, 0, 20, 0, 1
69
+ pglab '(x)', '(y)', 'PGPLOT Example 1: y = x\u2'
70
+
71
+ xs = [1.0,2.0,3.0,4.0,5.0]
72
+ ys = [1.0,4.0,9.0,16.0,25.0]
73
+ pgpt xs,ys,9
74
+
75
+ n = 60
76
+ xr = indgen(n)*0.1
77
+ yr = xr**2
78
+ pgline xr, yr
79
+ end
80
+
81
+ def pgex2
82
+ pgenv -2.0,10.0,-0.4,1.2, 0,1
83
+ pglab '(x)', 'sin(x)/x', 'PGPLOT Example 2: Sinc Function'
84
+
85
+ xr = (indgen(100)-20.5)/6.0
86
+ yr = sin(xr)/xr
87
+ pgline xr, yr
88
+ end
89
+
90
+ def pgex3
91
+ pgenv 0.0,720.0,-2.0,2.0, 0,-2
92
+ pgsave
93
+ pgsci 14
94
+ pgbox 'G',30.0, 0,'G', 0.2, 0
95
+ pgsci 5
96
+ pgbox 'ABCTSN',90.0, 3,'ABCTSNV', 0.0,0
97
+ pgsci 3
98
+ pglab 'x (degrees)','f(x)','PGPLOT Example 3'
99
+
100
+ xr = indgen(360) * 2
101
+ arg= xr/180*PI
102
+ yr = sin(arg) + cos(arg*2)*0.5 + cos(arg*1.5+PI/3)*0.5
103
+
104
+ pgsci 6
105
+ pgsls 2
106
+ pgslw 3
107
+ pgline xr, yr
108
+ pgunsa
109
+ end
110
+
111
+ def pgex4
112
+ seed = -5678921
113
+ data = randomn(1000)
114
+ pgsave
115
+ pghist data, 31, -3.1..3.1, 0
116
+ data = randomn(200)*0.5 + 1
117
+ pgsci 15
118
+ pghist data, 31, -3.1..3.1, 3
119
+ pgsci 0
120
+ pghist data, 31, -3.1..3.1, 1
121
+ pgsci 1
122
+ pgbox 'BST', 0.0, 0, ' ', 0.0, 0
123
+
124
+ pglab 'Variate', ' ','PGPLOT Example 4: Histograms (Gaussian)'
125
+
126
+ x = indgen(620)*0.01 - 3.1
127
+ y = exp(-(x**2)*0.5) * (0.2*1000/sqrt(2*PI))
128
+
129
+ pgline x,y
130
+ pgunsa
131
+ end
132
+
133
+ def pgex5
134
+ np=15
135
+ freq = NArray[ 26.0, 38.0, 80.0, 160.0, 178.0, 318.0, 365.0, 408.0,
136
+ 750.0, 1400.0, 2695.0, 2700.0, 5000.0, 10695.0, 14900.0 ]
137
+ flux = NArray[ 38.0, 66.4, 89.0, 69.8, 55.9, 37.4, 46.8, 42.4, 27.0,
138
+ 15.8, 9.09, 9.17, 5.35, 2.56, 1.73 ]
139
+ err = NArray[ 6.0, 6.0, 13.0, 9.1, 2.9, 1.4, 2.7, 3.0, 0.34, 0.8,
140
+ 0.2, 0.46, 0.15, 0.08, 0.01 ]
141
+ pgsave
142
+ pgsci CYAN
143
+ pgenv -2.0,2.0,-0.5,2.5,1,30
144
+ pglab 'Frequency, \gn (GHz)',
145
+ 'Flux Density, S\d\gn\u (Jy)',
146
+ 'PGPLOT Example 5: Log-Log plot'
147
+ x = indgen(100)*0.03 + 1.3
148
+ xp = x-3
149
+ yp = -x*1.15 - exp(-x)*7.72 + 5.18
150
+ pgsci RED
151
+ pgline xp,yp
152
+
153
+ xp = log10(freq)-3.0
154
+ yp = log10(flux)
155
+ pgsci GREEN
156
+ pgpt xp,yp,17
157
+
158
+ yhi = log10(flux+2*err)
159
+ ylo = log10(flux-2*err)
160
+ pgerry xp,ylo,yhi
161
+ pgunsa
162
+ end
163
+
164
+ def pgex6
165
+ twopi = PI*2
166
+ npol = 6
167
+
168
+ n1 = [ 0, 3, 4, 5, 5, 6, 8 ] # index-0 is dummy
169
+ n2 = [ 0, 1, 1, 1, 2, 1, 3 ]
170
+ lab = [ '', 'Fill style 1 (solid)',
171
+ 'Fill style 2 (outline)',
172
+ 'Fill style 3 (hatched)',
173
+ 'Fill style 4 (cross-hatched)']
174
+ pgbbuf
175
+ pgsave
176
+ pgpage
177
+ pgsvp 0.0, 1.0, 0.0, 1.0
178
+ pgwnad 0.0, 10.0, 0.0, 10.0
179
+ pgsci 1
180
+ pgmtxt 'T', -2.0, 0.5, 0.5,
181
+ 'PGPLOT fill area: routines PGPOLY, PGCIRC, PGRECT'
182
+
183
+ for k in 1..4
184
+ pgsci 1
185
+ y0 = 10.0 - 2.0*k
186
+ pgtext 0.2, y0+0.6, lab[k]
187
+ pgsfs k
188
+ for i in 1..npol
189
+ pgsci i
190
+ angle = indgen(n1[i])*(n2[i]*twopi/n1[i])
191
+ x = cos(angle)*0.5 + i
192
+ y = sin(angle)*0.5 + y0
193
+ pgpoly x,y
194
+ end
195
+ pgsci 7
196
+ pgcirc 7.0, y0, 0.5
197
+ pgsci 8
198
+ pgrect 7.8, 9.5, y0-0.5, y0+0.5
199
+ end
200
+ pgunsa
201
+ pgebuf
202
+ end
203
+
204
+ def pgex7
205
+ pgbbuf
206
+ pgsave
207
+ pgsci 1
208
+ pgenv 0.0,5.0, -0.3,0.6, 0,1
209
+ pglab '\fix', '\fiy', 'PGPLOT Example 7: scatter plot'
210
+
211
+ xs = NArray.sfloat(300).random!(1.0)*5
212
+ ys = randomn(300)*0.05 + xs*exp(-xs)
213
+
214
+ pgsci 3
215
+ pgpt xs[0..99],ys[0..99], 3
216
+ pgpt xs[100..199],ys[100..199], 17
217
+ pgpt xs[200..299],ys[200..299], 21
218
+
219
+ xr = indgen(101)*0.05
220
+ yr = xr*exp(-xr)
221
+ pgsci 2
222
+ pgline xr,yr
223
+
224
+ xp = xs[100]
225
+ yp = ys[100]
226
+ xsig = 0.2
227
+ ysig = 0.1
228
+ pgsci 5
229
+ pgsch 3.0
230
+ pgerr1 5, xp, yp, xsig, 1.0
231
+ pgerr1 6, xp, yp, ysig, 1.0
232
+ pgpt1 xp,yp,21
233
+ pgunsa
234
+ pgebuf
235
+ end
236
+
237
+ def pgex8
238
+ pgpage
239
+ pgbbuf
240
+ pgsave
241
+ pgsvp(0.1,0.6,0.1,0.6)
242
+ pgswin(0.0, 630.0, -2.0, 2.0)
243
+ pgsci(CYAN)
244
+ pgbox('ABCTS', 90.0, 3, 'ABCTSV', 0.0, 0)
245
+ pgsci(RED)
246
+ pgbox('N',90.0, 3, 'VN', 0.0, 0)
247
+ xr = indgen(360)*2
248
+ yr = sin(xr/57.29577951)
249
+ pgsci(MAGENT)
250
+ pgsls(DASH)
251
+ pgline(xr,yr)
252
+ pgswin(90.0, 720.0, -2.0, 2.0)
253
+ pgsci(YELLOW)
254
+ pgsls(DOTTED)
255
+ pgline(xr,yr)
256
+ pgsls(FULL)
257
+ pgsvp(0.45,0.85,0.45,0.85)
258
+ pgswin(0.0, 180.0, -2.0, 2.0)
259
+ pgsci(0)
260
+ pgrect(0.0, 180.0, -2.0, 2.0)
261
+ pgsci(BLUE)
262
+ pgbox('ABCTSM', 60.0, 3, 'VABCTSM', 1.0, 2)
263
+ pgsci(WHITE)
264
+ pgsls(DASH)
265
+ pgline(xr,yr)
266
+ pgunsa
267
+ pgebuf
268
+ end
269
+
270
+ def pgex9
271
+ pgbbuf
272
+ pgsave
273
+ pgsci(5)
274
+ #pgfunt(fx,fy,360,0.0,TWOPI,0) # pgfunt is not implemented
275
+ t = indgen(361)/360*TWOPI
276
+ x = sin(t*5)
277
+ y = sin(t*4)
278
+ pgenv -1,1,-1,1
279
+ pgline x,y
280
+ pgsci(3)
281
+ pglab('x','y','PGPLOT Example 9: routine PGFUNT')
282
+ pgunsa
283
+ pgebuf
284
+ end
285
+
286
+ def bessel_j0 arg
287
+
288
+ r = NArray.sfloat(arg.size)
289
+ x = arg.abs
290
+ idx1,idx2 = (x<=3).where2
291
+ if idx1.size>0 then
292
+ xo3 = x[idx1]/3.0
293
+ t = xo3**2
294
+ r[idx1] = 1.0 +
295
+ t*(-2.2499997 +
296
+ t*( 1.2656208 +
297
+ t*(-0.3163866 +
298
+ t*( 0.0444479 +
299
+ t*(-0.0039444 +
300
+ t*( 0.0002100))))))
301
+ end
302
+ if idx2.size>0 then
303
+ xx = x[idx2]
304
+ t = 3.0/xx
305
+ f0 = 0.79788456 +
306
+ t*(-0.00000077 +
307
+ t*(-0.00552740 +
308
+ t*(-0.00009512 +
309
+ t*( 0.00137237 +
310
+ t*(-0.00072805 +
311
+ t*( 0.00014476))))))
312
+ theta0 = xx - 0.78539816 +
313
+ t*(-0.04166397 +
314
+ t*(-0.00003954 +
315
+ t*( 0.00262573 +
316
+ t*(-0.00054125 +
317
+ t*(-0.00029333 +
318
+ t*( 0.00013558))))))
319
+ r[idx2] = f0*cos(theta0)/sqrt(xx)
320
+ end
321
+ return r
322
+ end
323
+
324
+ def bessel_j1 arg
325
+ r = NArray.sfloat(arg.size)
326
+ x = arg.abs
327
+ idx1,idx2 = (x<=3).where2
328
+ if idx1.size>0 then
329
+ xo3 = x[idx1]/3.0
330
+ t = xo3**2
331
+ f = 0.5 + t*(-0.56249985 +
332
+ t*( 0.21093573 +
333
+ t*(-0.03954289 +
334
+ t*( 0.00443319 +
335
+ t*(-0.00031761 +
336
+ t*( 0.00001109))))))
337
+ r[idx1] = f * arg[idx1]
338
+ end
339
+ if idx2.size>0 then
340
+ xx = x[idx2]
341
+ t = 3.0/xx
342
+ f1 = 0.79788456 +
343
+ t*( 0.00000156 +
344
+ t*( 0.01659667 +
345
+ t*( 0.00017105 +
346
+ t*(-0.00249511 +
347
+ t*( 0.00113653 +
348
+ t*(-0.00020033))))))
349
+ theta1 = xx - 2.35619449 +
350
+ t*( 0.12499612 +
351
+ t*( 0.00005650 +
352
+ t*(-0.00637879 +
353
+ t*( 0.00074348 +
354
+ t*( 0.00079824 +
355
+ t*(-0.00029166))))))
356
+ r[idx2] = f1*cos(theta1)/sqrt(xx)
357
+ end
358
+ idx = (arg<0).where
359
+ #p idx
360
+ #p r[idx]
361
+ r[idx] = -r[idx] if idx.size>0
362
+ return r
363
+ end
364
+
365
+ def pgex10
366
+ pgbbuf
367
+ pgsave
368
+ pgsci(YELLOW)
369
+ # PGFUNX(PGBSJ0,500,0.0,10.0*PI,0)
370
+ x = indgen(500)/50*PI
371
+ y = bessel_j0(x)
372
+ pgenv 0,PI*10, y.min,y.max
373
+ pgline x,y
374
+ pgsci(RED)
375
+ pgsls(DASH)
376
+ # PGFUNX(PGBSJ1,500,0.0,10.0*PI,1)
377
+ pgline x, bessel_j1(x)
378
+ pgsci(GREEN)
379
+ pgsls(FULL)
380
+ pglab('\fix', '\fiy',
381
+ '\frPGPLOT Example 10: routine PGFUNX')
382
+ pgmtxt('T', -4.0, 0.5, 0.5,
383
+ '\frBessel Functions')
384
+ pgarro(8.0, 0.7, 1.0, bessel_j0(NArray[1.0])[0])
385
+ pgarro(12.0, 0.5, 9.0, bessel_j1(NArray[9.0])[0])
386
+ pgstbg(GREEN)
387
+ pgsci(0)
388
+ pgptxt(8.0, 0.7, 0.0, 0.0, ' \fiy = J\d0\u(x)')
389
+ pgptxt(12.0, 0.5, 0.0, 0.0, ' \fiy = J\d1\u(x)')
390
+ pgunsa
391
+ pgebuf
392
+ end
393
+
394
+ # ====== Demo start ======
395
+
396
+ raise "device not found" if pgopen<0
397
+
398
+ pgex0
399
+ pgex1
400
+ pgex2
401
+ pgex3
402
+ pgsubp 2,1
403
+ pgex4
404
+ pgex5
405
+ pgsubp 1,1
406
+ pgex6
407
+ pgex7
408
+ pgex8
409
+ pgex9
410
+ pgex10
411
+
412
+ pgclos
413
+ exit
414
+