%s' % [$1,$1.downcase]
} << "\n"
end
def methoddoc(x)
s=''
if String===x
x = [x]
end
line = x.shift
if line =~ /\(/
while line !~ /\(.*\)/m
line << x.shift
end
end
if line =~ /^---\s*(pg.*)/m
@stream << "%s\n--- Ruby notes ---\n"
x.each{|i| @stream<\n"
end
end
@stream << "\n"
end
def docbegin
#@stream << "\n"
end
def docend
@stream << "\n
\n"
end
end
class PgDoc
def autofunclist
pgfunc_auto = %w(
pgend::
pgbbuf::
pgebuf::
pgpage::
pgpap:1,1:
pgupdt::
pgpanl:1,1:
pgclos::
pgbox:2,1,0,2,1,0:
pgtbox:2,1,0,2,1,0:
pgvsiz:1,1,1,1:
pgvstd::
pgwnad:1,1,1,1:
pgsubp:0,0:
pgwedg:2,1,1,1,1,2:
# Draw Funcs
pgdraw:1,1:
pgmove:1,1:
pgrect:1,1,1,1:
pgarro:1,1,1,1:
pgcirc:1,1,1:
pgpt1:1,1,0:
pgerr1:0,1,1,1,1:
pglab:2,2,2:
pgptxt:1,1,1,1,2:
pgtext:1,1,2:
pgmtxt:2,1,1,1,2:
pgetxt::
pgiden::
pgldev::
pgsave::
pgunsa::
pgeras::
# Set Funcs
pgsch:1:
pgscf:0:
pgsci:0:
pgsfs:0:
pgsls:0:
pgslw:0:
pgsclp:0:
pgsitf:0:
pgslct:0:
pgstbg:0:
pgscr:0,1,1,1:
pgshls:0,1,1,1:
pgsah:0,1,1:
pgscrl:1,1:
pgscir:0,0:
pgscrn:0,2:0
pgshs:1,1,1:
pgsvp:1,1,1,1:
pgswin:1,1,1,1:
# Query Funcs
pgqch::1
pgqcf::0
pgqci::0
pgqfs::0
pgqls::0
pgqlw::0
pgqclp::0
pgqid::0
pgqitf::0
pgqndt::0
pgqtbg::0
pgqcr:0:1,1,1
pgqvp:0:1,1,1,1
pgqwin::1,1,1,1
pgqcol::0,0
pgqcir::0,0
pgqpos::1,1
pgqvsz:0:1,1,1,1
).grep(/:.*:/).collect{|i| i.split(":",3)}
@autofunc={}
pgfunc_auto.each do |x|
@autofunc[x[0]] = x[1..2].collect{|i| i.split(",").size}
end
end
def manualfunclist
@manualfunc={}
curfunc=nil
File.open("../rb_pgplot.c.in").each do |line|
case line
when %r'^/\* (PG\w+)'
curfunc = $1.downcase
@manualfunc[curfunc] = []
line.sub!(%r'^/\*\s*','')
when %r'^\*/'
curfunc = nil
else
if h = @manualfunc[curfunc]
h << line
end
end
end
end
def mergefunclist
@mergefunc = @manualfunc.keys
@autofunc.each_key do |x|
@mergefunc << x
end
@mergefunc.sort!
end
def initialize(formatter)
autofunclist
manualfunclist
mergefunclist
@indx = formatter.new('')
@head = formatter.new('')
@body = formatter.new('')
@tail = formatter.new('')
end
def defmode()
funcdef=''
while @doc[0] !~ /^C/
line = @doc.shift
line.chomp!
if line.sub!(/^\s+SUBROUTINE /,'--- ') ||
line.sub!(/^\s+[A-Z0-9\s]+ FUNCTION /,'--- ') ||
line.sub!(/^ [^ ]\s*/,' ')
funcdef << line.downcase
end
end
#p [funcdef,@doc[0]]
if @manualfunc[@name]
# Definded in rb_pgplot.c.in
@body.methoddoc(@manualfunc[@name])
else
# Automatically generated
#p [@name,@autofunc[@name]]
nin = @autofunc[@name][0]
nout = @autofunc[@name][1]
funcdef =~ /\(\s*(\w+\s*(?:,\s*\w+\s*)*)\s*\)/
if s = $1
a = s.split(/\s*,\s*/)
funcdef = "--- #{@name}"
b = a[0,nin].join(', ')
funcdef << "( " << b << " )" if b.size>0
b = a[nin,nout]
funcdef << " #=> " << b.join(', ') if b.size>0
end
@body.methoddoc(funcdef)
end
end
def docmode()
while line = @doc.shift
case line
when /^C%/
# C definition
when /^C\+/
defmode()
while @doc[0] =~ /^C\s*$/
@doc.shift
end
when /^C/
line.sub!(/^( :)/, ' \1')
line.sub!(/^C.?/,'')
@body << line << "\n"
end
end
end
def docextr(fin)
@doc = []
fin.each do |line|
return @doc if line =~ /^C--/
@doc << line.chomp
end
@doc
end
def doit
dir='/home/masa/src/plot/pgplot/src/'
@head.printhead
@mergefunc.each do |f|
if name = f[/(pg\w+)/]
begin
fin = open(dir+name+'.f')
rescue
fin = nil
end
if fin
fin.each do |line|
if line.sub!(/^C\*/,'')
@indx.printindex(line)
@name = @body.subject(line)
@body.docbegin
@doc = docextr(fin)
docmode()
@body.docend
end
end
end
@body << "\n\n"
end
end
@tail.printtrail
b = @head.stream
b << "\n" << @indx.stream <<
"
\nDescriptions
\n" <<
@body.stream << @tail.stream
b
end
end
#PgDoc.new(FormatterRD.new(File.open(ARGV[0],"w"))).doit
#PgDoc.new(FormatterHTML.new(File.open(ARGV[0],"w"))).doit
File.open(ARGV[0],"w") << PgDoc.new(FormatterHTML).doit
rb_pgplot-0.1.3/doc/mkind.rb 0000664 0000764 0000764 00000001627 07441420100 014333 0 ustar masa masa funcs = %w[
pgopen
pgbeg
pgask
pgenv
pgline
pgpt
pgpnts
pgbin
pghist
pgerrb
pgerrx
pgerry
pgcont
pgcons
pgconb
pgconf
pgconl
pgimag
pggray
pgctab
pgpixl
pgvect
pgband
pgolin
pgncur
pglcur
pgtick
pgaxis
]
rbpg={}
funcs.each{|f| rbpg[f.upcase]=true }
fin=open(ARGV[0])
fout=open(ARGV[1],"w")
fout.print "
=begin
= Ruby/PGPLOT categorized method index
"
fin.each do |line|
line.chomp!
name = line[/(^PG[A-Z0-9]+)/]
#line.sub!(/^# /, "===")
line.sub!(/^(PG[A-Z0-9]+)/, '* (({\1}))')
#if rbpg[name]
# line.gsub!(/\b(PG(?!PLOT)[A-Z0-9]+)/) do |x|
# '((<%s|URL:rbpg-doc.html#%s>))' % [x.downcase,x]
# end
# line << ' ( (()) )' % name
#else
line.gsub!(/\b(PG(?!PLOT)[A-Z0-9]+)/) do |x|
'((<%s|URL:rbpgplot.html#%s>))' % [x.downcase,x]
end
#end
fout.puts(line)
end
fout.print "
<<< trailer
=end
"
rb_pgplot-0.1.3/doc/pgcont.rd 0000664 0000764 0000764 00000001110 07441417241 014524 0 ustar masa masa =begin
= Ruby/PGPLOT example: pgcont
=== code
require "narray"
require "pgplot"
include Pgplot
# Preparing data
x = NArray.sfloat(40,1).indgen!(1)
y = NArray.sfloat(1,40).indgen!(1)
map = NMath.cos( NMath.sqrt(x*2)*0.3 - y*0.4/3 ) * NMath.cos( x*0.4/3 ) \
+ (x-y)/40
n = 21
level = NArray.sfloat(n).indgen! * (map.max-map.min)/n + map.min
# Draw contour map
pgopen
pgenv(1,40,1,40) # set "Plotter Environment" and draw box.
pgsci(3) # set Color Index to Green.
pgcont map, level
=== output
<<< pgcont.png
<<< trailer
=end
rb_pgplot-0.1.3/doc/pghist.rd 0000664 0000764 0000764 00000001401 07441417241 014533 0 ustar masa masa =begin
= Ruby/PGPLOT example: pghist
=== code
require 'narray'
require 'pgplot'
include Pgplot
pgopen
srand(1)
# draw main Histogram of Normal distribution
data = NArray.sfloat(1000).randomn!
pghist(data, 31, -3.1..3.1, 0)
# draw sub Histogram of Normal distribution with gray bars
data = NArray.sfloat(200).randomn!*0.5 + 1
pgsci(15)
pghist(data, 31, -3.1..3.1, 3)
pgsci(0) # draw black frame
pghist(data, 31, -3.1..3.1, 1)
pgsci(1)
pgbox('BST', 0.0, 0, ' ', 0.0, 0)
pglab('Variate', ' ','PGPLOT Example 4: Histograms (Gaussian)')
# draw Gaussian Curve
x = NArray.sfloat(620).indgen!*0.01 - 3.1
y = NMath.exp(-(x**2)*0.5) * (0.2*1000/NMath.sqrt(2*Math::PI))
pgline(x,y)
=== output
<<< pghist.png
<<< trailer
=end
rb_pgplot-0.1.3/doc/pgimag.rd 0000664 0000764 0000764 00000002045 07441417241 014506 0 ustar masa masa =begin
= Ruby/PGPLOT example: pgimag
=== code
require 'narray'
require 'pgplot'
include Pgplot
# set color table
def palett
rl = [-0.5, 0.0, 0.17, 0.33, 0.50, 0.67, 0.83, 1.0, 1.7]
rr = [ 0.0, 0.0, 0.0, 0.0, 0.6, 1.0, 1.0, 1.0, 1.0]
rg = [ 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.6, 0.0, 1.0]
rb = [ 0.0, 0.3, 0.8, 1.0, 0.3, 0.0, 0.0, 0.0, 1.0]
pgctab(rl, rr, rg, rb)
end
# prepare Data
nx = 64
ny = 64
x = NArray.sfloat(nx,1).indgen!(1)
y = NArray.sfloat(1,ny).indgen!(1)
f = NMath.cos( NMath.sqrt(x*(80.0/nx))*0.6 - y*16.0/(3.0*ny) ) *
NMath.cos( x*16.0/(3.0*nx) ) +
(x/nx - y/ny) + NMath.sin(NMath.sqrt(x**2+y**2))*0.05
# draw Image Map
pgopen
pgwnad(0.0, 1.0+nx, 0.0, 1.0+ny)
palett
pgimag(f)
pgmtxt('t',1.0,0.0,0.0,'PGIMAG, PGWEDG, and PGCTAB')
# draw Color Bar at bottom
pgsch(0.6)
pgbox('bcntsi',0.0,0,'bcntsiv',0.0,0)
pgmtxt('b',3.0,1.0,1.0,'pixel number')
pgwedg('RI', 4.0, 5.0, f.min,f.max, 'pixel value')
=== output
<<< pgimag.png
<<< trailer
=end
rb_pgplot-0.1.3/doc/pgline.rd 0000664 0000764 0000764 00000000777 07441417241 014532 0 ustar masa masa =begin
= Ruby/PGPLOT example: pgline
=== code
require 'narray'
require 'pgplot'
include Pgplot
n = 100
x = NArray.sfloat(n).indgen!/10
y = NMath.sin(x)
pgopen # open PGPLOT session
pgenv 0, n/10, -1, 1 # set "Plotter Environment" and draw box.
pglab "x", "y", "PGPLOT Example: y = sin(x)"
pgsci 2 # set Color Index = Red.
pgslw 5 # set Line Width.
pgline x, y # plot Line.
=== output
<<< pgline.png
<<< trailer
=end
rb_pgplot-0.1.3/doc/rbpg-ind.rd 0000664 0000764 0000764 00000025507 07441417241 014754 0 ustar masa masa
=begin
= Ruby/PGPLOT categorized method index
=== Drawing primitives
* (({(())})) -- draw a polyline (curve defined by line-segments)
* (({(())})) -- draw a polygon, using fill-area attributes
* (({(())})) -- draw one graph marker
* (({(())})) -- draw several graph markers
* (({(())})) -- draw several graph markers, not all the same
* (({(())})) -- draw an arrow
* (({(())})) -- draw a circle, using fill-area attributes
* (({(())})) -- draw a rectangle, using fill-area attributes
* (({(())})) -- move pen (change current pen position)
* (({(())})) -- draw a line from the current pen position to a point
=== Axis
* (({(())})) -- draw an axis
* (({(())})) -- draw labeled frame around viewport
* (({(())})) -- draw a single tick mark on an axis
* (({(())})) -- draw frame and write (DD) HH MM SS.S labelling
=== Text
* (({(())})) -- write labels for x-axis, y-axis, and top of plot
* (({(())})) -- write text (horizontal, left-justified)
* (({(())})) -- write text at position relative to viewport
* (({(())})) -- write text at arbitrary position and angle
* (({(())})) -- erase text from graphics display
* (({(())})) -- write username, date, and time at bottom of plot
* (({(())})) -- find length of a string in a variety of units
* (({(())})) -- find bounding box of text string
=== Histgram
* (({(())})) -- histogram of binned data
* (({(())})) -- histogram of unbinned data
=== Error bar
* (({(())})) -- horizontal or vertical error bar
* (({(())})) -- horizontal or vertical error bar
* (({(())})) -- horizontal error bar
* (({(())})) -- vertical error bar
=== 2D drawing
* (({(())})) -- contour map of a 2D data array (contour-following)
* (({(())})) -- contour map of a 2D data array (fast algorithm)
* (({(())})) -- contour map of a 2D data array, with blanking
* (({(())})) -- fill between two contours
* (({(())})) -- label contour map of a 2D data array
* (({(())})) -- contour map of a 2D data array (non rectangular) (not implemented in Ruby/PGPLOT)
* (({(())})) -- color image from a 2D data array
* (({(())})) -- install the color table to be used by (())
* (({(())})) -- gray-scale map of a 2D data array
* (({(())})) -- draw pixels
* (({(())})) -- vector map of a 2D data array, with blanking
* (({(())})) -- annotate an image plot with a wedge
* (({(())})) -- cross-sections through a 2D data array
=== Cursor
* (({(())})) -- read cursor position, with anchor
* (({(())})) -- read cursor position
* (({(())})) -- draw a line using the cursor
* (({(())})) -- mark a set of points using the cursor
* (({(())})) -- mark a set of points using the cursor
=== Control
* (({(())})) -- open a graphics device
* (({(())})) -- open a graphics device
* (({(())})) -- close the selected graphics device
* (({(())})) -- close all open graphics devices
* (({(())})) -- set window and viewport and draw labeled frame
* (({(())})) -- control new page prompting
* (({(())})) -- advance to new page
* (({(())})) -- erase all graphics from current page
* (({(())})) -- begin batch of output (buffer)
* (({(())})) -- end batch of output (buffer)
* (({(())})) -- switch to a different panel on the view surface
* (({(())})) -- change the size of the view surface
* (({(())})) -- choose axis limits
* (({(())})) -- save PGPLOT attributes
* (({(())})) -- restore PGPLOT attributes
* (({(())})) -- scroll window
* (({(())})) -- subdivide view surface into panels
* (({(())})) -- update display
=== Set attributes
* (({(())})) -- set arrow-head style
* (({(())})) -- set character font
* (({(())})) -- set character height
* (({(())})) -- set color index
* (({(())})) -- set color index range
* (({(())})) -- enable or disable clipping at edge of viewport
* (({(())})) -- set color representation
* (({(())})) -- set color representation by name
* (({(())})) -- set fill-area style
* (({(())})) -- set color representation using HLS system
* (({(())})) -- set hatching style
* (({(())})) -- set image transfer function
* (({(())})) -- select an open graphics device
* (({(())})) -- set line style
* (({(())})) -- set line width
* (({(())})) -- set text background color index
* (({(())})) -- set viewport (normalized device coordinates)
* (({(())})) -- set window
* (({(())})) -- set viewport (inches)
* (({(())})) -- set standard (default) viewport
* (({(())})) -- set window and adjust viewport to same aspect ratio
=== Inquire attributes
* (({(())})) -- list available device types on standard output
* (({(())})) -- inquire arrow-head style
* (({(())})) -- inquire character font
* (({(())})) -- inquire character height
* (({(())})) -- inquire color index
* (({(())})) -- inquire color index range
* (({(())})) -- inquire clipping status
* (({(())})) -- inquire color capability
* (({(())})) -- inquire color representation
* (({(())})) -- inquire character height in a variety of units
* (({(())})) -- inquire name of nth available device type
* (({(())})) -- inquire fill-area style
* (({(())})) -- inquire hatching style
* (({(())})) -- inquire current device identifier
* (({(())})) -- inquire PGPLOT general information
* (({(())})) -- inquire image transfer function
* (({(())})) -- inquire line style
* (({(())})) -- inquire line width
* (({(())})) -- inquire number of available device types
* (({(())})) -- inquire current pen position
* (({(())})) -- inquire text background color index
* (({(())})) -- inquire viewport size and position
* (({(())})) -- inquire size of view surface
* (({(())})) -- inquire window boundary coordinates
==== Hereafter not implemented in Ruby/PGPLOT
=== Utility
* (({(())})) -- convert a number into a plottable character string
* (({(())})) -- find the smallest `round' number greater than x
=== Drawing function
* (({(())})) -- function defined by X = F(T), Y = G(T)
* (({(())})) -- function defined by Y = F(X)
* (({(())})) -- function defined by X = F(Y)
=== Alias
* (({(())})) -- non-standard alias for (())
* (({(())})) -- non-standard alias for (())
* (({(())})) -- non-standard alias for (())
* (({(())})) -- non-standard alias for (())
* (({(())})) -- non-standard alias for (())
* (({(())})) -- non-standard alias for (())
* (({(())})) -- non-standard alias for (())
* (({(())})) -- non-standard alias for (())
* (({(())})) -- non-standard alias for (())
* (({(())})) -- non-standard alias for (())
* (({(())})) -- non-standard alias for (())
* (({(())})) -- non-standard alias for (())
* (({(())})) -- non-standard alias for (())
<<< trailer
=end
rb_pgplot-0.1.3/doc/rbpg-ind.txt 0000664 0000764 0000764 00000013023 07441417241 015154 0 ustar masa masa === Drawing primitives
PGLINE -- draw a polyline (curve defined by line-segments)
PGPOLY -- draw a polygon, using fill-area attributes
PGPT1 -- draw one graph marker
PGPT -- draw several graph markers
PGPNTS -- draw several graph markers, not all the same
PGARRO -- draw an arrow
PGCIRC -- draw a circle, using fill-area attributes
PGRECT -- draw a rectangle, using fill-area attributes
PGMOVE -- move pen (change current pen position)
PGDRAW -- draw a line from the current pen position to a point
=== Axis
PGAXIS -- draw an axis
PGBOX -- draw labeled frame around viewport
PGTICK -- draw a single tick mark on an axis
PGTBOX -- draw frame and write (DD) HH MM SS.S labelling
=== Text
PGLAB -- write labels for x-axis, y-axis, and top of plot
PGTEXT -- write text (horizontal, left-justified)
PGMTXT -- write text at position relative to viewport
PGPTXT -- write text at arbitrary position and angle
PGETXT -- erase text from graphics display
PGIDEN -- write username, date, and time at bottom of plot
PGLEN -- find length of a string in a variety of units
PGQTXT -- find bounding box of text string
=== Histgram
PGBIN -- histogram of binned data
PGHIST -- histogram of unbinned data
=== Error bar
PGERR1 -- horizontal or vertical error bar
PGERRB -- horizontal or vertical error bar
PGERRX -- horizontal error bar
PGERRY -- vertical error bar
=== 2D drawing
PGCONT -- contour map of a 2D data array (contour-following)
PGCONS -- contour map of a 2D data array (fast algorithm)
PGCONB -- contour map of a 2D data array, with blanking
PGCONF -- fill between two contours
PGCONL -- label contour map of a 2D data array
PGCONX -- contour map of a 2D data array (non rectangular) (not implemented in Ruby/PGPLOT)
PGIMAG -- color image from a 2D data array
PGCTAB -- install the color table to be used by PGIMAG
PGGRAY -- gray-scale map of a 2D data array
PGPIXL -- draw pixels
PGVECT -- vector map of a 2D data array, with blanking
PGWEDG -- annotate an image plot with a wedge
PGHI2D -- cross-sections through a 2D data array
=== Cursor
PGBAND -- read cursor position, with anchor
PGCURS -- read cursor position
PGLCUR -- draw a line using the cursor
PGNCUR -- mark a set of points using the cursor
PGOLIN -- mark a set of points using the cursor
=== Control
PGOPEN -- open a graphics device
PGBEG -- open a graphics device
PGCLOS -- close the selected graphics device
PGEND -- close all open graphics devices
PGENV -- set window and viewport and draw labeled frame
PGASK -- control new page prompting
PGPAGE -- advance to new page
PGERAS -- erase all graphics from current page
PGBBUF -- begin batch of output (buffer)
PGEBUF -- end batch of output (buffer)
PGPANL -- switch to a different panel on the view surface
PGPAP -- change the size of the view surface
PGRNGE -- choose axis limits
PGSAVE -- save PGPLOT attributes
PGUNSA -- restore PGPLOT attributes
PGSCRL -- scroll window
PGSUBP -- subdivide view surface into panels
PGUPDT -- update display
=== Set attributes
PGSAH -- set arrow-head style
PGSCF -- set character font
PGSCH -- set character height
PGSCI -- set color index
PGSCIR -- set color index range
PGSCLP -- enable or disable clipping at edge of viewport
PGSCR -- set color representation
PGSCRN -- set color representation by name
PGSFS -- set fill-area style
PGSHLS -- set color representation using HLS system
PGSHS -- set hatching style
PGSITF -- set image transfer function
PGSLCT -- select an open graphics device
PGSLS -- set line style
PGSLW -- set line width
PGSTBG -- set text background color index
PGSVP -- set viewport (normalized device coordinates)
PGSWIN -- set window
PGVSIZ -- set viewport (inches)
PGVSTD -- set standard (default) viewport
PGWNAD -- set window and adjust viewport to same aspect ratio
=== Inquire attributes
PGLDEV -- list available device types on standard output
PGQAH -- inquire arrow-head style
PGQCF -- inquire character font
PGQCH -- inquire character height
PGQCI -- inquire color index
PGQCIR -- inquire color index range
PGQCLP -- inquire clipping status
PGQCOL -- inquire color capability
PGQCR -- inquire color representation
PGQCS -- inquire character height in a variety of units
PGQDT -- inquire name of nth available device type
PGQFS -- inquire fill-area style
PGQHS -- inquire hatching style
PGQID -- inquire current device identifier
PGQINF -- inquire PGPLOT general information
PGQITF -- inquire image transfer function
PGQLS -- inquire line style
PGQLW -- inquire line width
PGQNDT -- inquire number of available device types
PGQPOS -- inquire current pen position
PGQTBG -- inquire text background color index
PGQVP -- inquire viewport size and position
PGQVSZ -- inquire size of view surface
PGQWIN -- inquire window boundary coordinates
==== Hereafter not implemented in Ruby/PGPLOT
=== Utility
PGNUMB -- convert a number into a plottable character string
PGRND -- find the smallest `round' number greater than x
=== Drawing function
PGFUNT -- function defined by X = F(T), Y = G(T)
PGFUNX -- function defined by Y = F(X)
PGFUNY -- function defined by X = F(Y)
=== Alias
PGADVANCE -- non-standard alias for PGPAGE
PGBEGIN -- non-standard alias for PGBEG
PGCURSE -- non-standard alias for PGCURS
PGLABEL -- non-standard alias for PGLAB
PGMTEXT -- non-standard alias for PGMTXT
PGNCURSE -- non-standard alias for PGNCUR
PGPAPER -- non-standard alias for PGPAP
PGPOINT -- non-standard alias for PGPT
PGPTEXT -- non-standard alias for PGPTXT
PGVPORT -- non-standard alias for PGSVP
PGVSIZE -- non-standard alias for PGVSIZ
PGVSTAND -- non-standard alias for PGVSTD
PGWINDOW -- non-standard alias for PGSWIN
rb_pgplot-0.1.3/doc/rbpg-relabel.rb 0000664 0000764 0000764 00000000220 07441420100 015553 0 ustar masa masa #ARGF.each do |line|
gsub!(/name="(.+?)"/, %Q[name="#{$1.upcase}"]) if $_=~/^(pg\w+?)<\/em>/
# end
# print line
#end
rb_pgplot-0.1.3/doc/rd2html-img-lib.rb 0000664 0000764 0000764 00000000516 10537712457 016142 0 ustar masa masa require "rd/rd2html-lib"
module RD
class RD2HTMLVisitor
# RDVisitor#apply_to_Include
def apply_to_Include(content)
if /^(.+\.(?:png|gif|jpg))(?::(.+))?$/ === content.filename
m = %Q[
\n]
m
else
super
end
end
end
end
rb_pgplot-0.1.3/doc/trailer.html 0000664 0000764 0000764 00000000066 10537712457 015253 0 ustar masa masa
Ruby/PGPLOT
by Masahiro Tanaka
rb_pgplot-0.1.3/doc/tutorial-01.ja.rd 0000664 0000764 0000764 00000004625 07441417241 015722 0 ustar masa masa =begin
= Ruby/PGPLOT 導入編
== 折れ線グラフを描く
Ruby/PGPLOTで折れ線グラフを描く最小限のスクリプトは、以下のようになります。
require 'narray'
require 'pgplot'
include Pgplot
pgopen # デバイスを開く
pgenv( 0, 5, 0, 5 ) # 枠の設定と描画
pgline( [1,2,3,4], [1,4,1,4] ) # 折れ線の描画
以下このスクリプトについて詳しく説明します。
1行目、2行目で拡張ライブラリをロードします。
3行目では Pgplotモジュールをインクルードしています。
これをしないと Pgplotのメソッドを呼ぶとき、``Pgplot.pgopen'' というように
モジュール名をメソッドの前に省略しないで書かなければなりません。
インクルードするかどうかは場合によります。
Pgplotモジュールのメソッド名は(今のところ)皆 ``pg'' で始まっているので、
気をつければ名前がぶつかる確率は低いと思いますが、
確実を期すならインクルードしない方がよいかもしれません。
4行目の pgopen で PGPLOT のグラフィクスデバイスを開きます。
ここで引数を書かないと使用するデバイスを聞いてきます。
Graphics device/type (? to see list, default /xwin):
デフォルトのままで良ければ単にリターンキーを押します。
デフォルトのデバイスは環境変数 PGPLOT_DEV で設定したものになっています。
`?'とリターンを打ち込むと、使用できるデバイスの一覧が表示されるので、
その中から別のデバイスを選択することもできます。
例えば、PNGとしてファイルに書き出したいときは、
``plot1.png/png'' のように「ファイル名/デバイス名」というように指定します。
5行目の
pgenv( 0, 5, 0, 5 )
により、グラフの軸を決定し、枠と目盛を描画します。
引数は x-min, x-max, y-min, y-max の順です。
ここではX軸が0から5、Y軸が0から5までの範囲の枠を描きます。
以降はここで設定された座標をもとに描画します。
そしていよいよ、6行目の
pgline( [1,2,3,4], [1,4,1,4] )
で、折れ線グラフを描きます。
引数には線を結ぶ点のX座標とY座標をそれぞれ配列で渡します。
ここまで成功すれば、このようなグラフが描かれているはずです。
<<< plot1.png
以上が折れ線グラフを描くのに最低限必要なメソッドです。
ところで、このスクリプトにはデバイスを閉じるメソッドがありません。
CかFORTRAN版のPGPLOTであれば、
ここで最後に pgend を呼んでデバイスを閉じる必要があります。
そうしないと、デバイスが Postscript などのとき、
終了処理がされないので、不完全なファイルができてしまいます。
しかし Ruby/PGPLOTでは、Rubyインタプリタ終了時に
pgend を自動的に呼ぶようになっているので、
必ずしも最後に pgend を呼ぶ必要はありません。
ただしRubyの実行途中でPGPLOTを終了したいときのために
Ruby版でも pgend メソッドは用意してあります。
以下続く(かもしれない)
<<< trailer
=end
rb_pgplot-0.1.3/test/ 0000775 0000764 0000764 00000000000 10537715162 013127 5 ustar masa masa rb_pgplot-0.1.3/test/pgband.rb 0000664 0000764 0000764 00000000552 07271376751 014721 0 ustar masa masa require 'narray'
require 'pgplot'
include Pgplot
pgbeg
pgenv 0, 1, 0, 1
pglab '','','Demo of PGBAND'
c = PgCursor.new(0,0)
for mode in 0..7
puts 'Mode %d: Enter key or click on the window'%mode
c = pgband(mode, c.x, c.y)
p c
end
x = y = 0
for mode in 0..7
puts 'Mode %d: Enter key or click on the window'%mode
x,y = pgband(mode, x, y)
p [x,y]
end
rb_pgplot-0.1.3/test/pgcurs.rb 0000664 0000764 0000764 00000000352 07271376751 014767 0 ustar masa masa require 'narray'
require 'pgplot'
include Pgplot
pgbeg
pgenv 0, 1, 0, 1
pglab '','','Demo of PGCURS'
c = PgCursor.new(0,0)
for mode in 0..7
puts 'Enter a key on the window:'
c = pgcurs(c.x, c.y)
pgpt1(c.x, c.y, c.char[0])
end
rb_pgplot-0.1.3/test/pggray.rb 0000664 0000764 0000764 00000001007 07271376751 014753 0 ustar masa masa require 'narray'
require 'pgplot'
include Pgplot
n = 100
x = NArray.sfloat(n,1).indgen!/10
y = NArray.sfloat(1,n).indgen!/10
a = NMath.sin(x) * NMath.cos(y)
pgbeg
pgenv 0,(n+1)/10.0, 0,(n+1)/10.0, 1 # scales of X and Y are equal
pglab "(x)", "(y)", "PGGRAY Demo: sin(x)*cos(y)"
pgscir 16,64
pggray a, -1..1, [0,0.1,0,0,0,0.1]
pgenv 0,(n+1)/10.0, 0,(n+1)/10.0 # independent scales
pglab "(x)", "(y)", "PGIMAG Demo: sin(x)*cos(y)"
pgscir 16,64
pgctab [0,1],[0,1],[0,1],[0,1]
pgimag a, -1..1, [0,0.1,0,0,0,0.1]
rb_pgplot-0.1.3/test/pglcur.rb 0000664 0000764 0000764 00000000345 07271376751 014762 0 ustar masa masa require 'narray'
require 'pgplot'
include Pgplot
n = 10
x = NArray.sfloat(n).indgen!
y = NMath.sin(NArray.sfloat(n).indgen!)*3+n/2
pgbeg
pgenv 0, 10, 0, 10
pglab '','','Demo of PGLCUR'
n = pglcur(x,y,n/2)
p x[0...n], y[0...n]
rb_pgplot-0.1.3/test/pgline.rb 0000664 0000764 0000764 00000000313 10537712457 014733 0 ustar masa masa require 'narray'
require 'pgplot'
include Pgplot
n = 100
x = NArray.sfloat(n).indgen!/10
y = NMath.sin(x)
pgbeg()
pgenv 0, n/10, -1, 1
pglab "(x)", "(y)", "PGPLOT Example 1: y = x\\u2\\d"
pgline x, y
rb_pgplot-0.1.3/test/pgncur.rb 0000664 0000764 0000764 00000000326 07271376751 014763 0 ustar masa masa require 'narray'
require 'pgplot'
include Pgplot
n = 10
x = NArray.sfloat(n).indgen!
y = NArray.sfloat(n).indgen!
pgbeg
pgenv 0, 10, 0, 10
pglab '','','Demo of PGNCUR'
n = pgncur(x,y,2,n/2)
p x[0...n], y[0...n]
rb_pgplot-0.1.3/test/pgolin.rb 0000664 0000764 0000764 00000000326 07271376751 014755 0 ustar masa masa require 'narray'
require 'pgplot'
include Pgplot
n = 10
x = NArray.sfloat(n).indgen!
y = NArray.sfloat(n).indgen!
pgbeg
pgenv 0, 10, 0, 10
pglab '','','Demo of PGOLIN'
n = pgolin(x,y,2,n/2)
p x[0...n], y[0...n]
rb_pgplot-0.1.3/test/pgtick.rb 0000664 0000764 0000764 00000000477 07421473436 014750 0 ustar masa masa require 'narray'
require 'pgplot'
include Pgplot
pgbeg
pgenv 0,10, 0,10
pgtick( 0, 7, 10, 7, 0.25, "quarter" )
pgtick( 0, 7, 10, 7, 0.5, "half", "tickr"=>1, "disp"=>2, "orient"=>90 )
pgtick( 0, 7, 10, 7, 0.75, "3quarter", "tickl"=>1, "disp"=>-2, "orient"=>180 )
pgaxis( 1, 1, 9, 5, 0, 3, "tickl"=>1, "opt"=>"NL2" )
rb_pgplot-0.1.3/FuncUsage 0000664 0000764 0000764 00000002122 07352475140 013750 0 ustar masa masa stat = pgopen([device])
stat = pgbeg([device, [nxsub, [nysub]]])
pgask [true|false]
pgenv xmin,xmax,ymin,ymax [,just, axis]
pgline xarray, yarray
pgpt xarray, yarray [,symbol]
pgpnts xarray, yarray, symarray
pgbin xarray, yarray [,center]
pghist data, nbin [,range, flag]
pgerrb dir, x, y, err [,tlen]
pgerrx x1, x2, y [,tlen]
pgerry x, y1, y2 [,tlen]
pgcont map, cont [,tr]
pgcons map, cont [,tr]
pgconb map, cont [,blank, tr]
pgconf map, cont_range [,tr]
pgconl map, cont, label [,intval, minint, tr]
pgimag array [,range, tr]
pggray array [,range, tr]
pgctab l, r,g,b [,contra,bright]
pgpixl, array [,x1,x2,y1,y2]
pgvect x, y [,scale, pos, tr, blank]
value = pgqinf(item)
type, descr, inter = pgqdt([ndev])
curs = pgband( mode, [ xref, yref, [x, y, [posn]]])
n = pgolin( x, y, [sym, [npt]] )
n = pgncur( x, y, [sym, [npt]] )
n = pglcur( x, y, [npt] )
pgtick x1, y1, x2, y2, v, [str], {"tickl", "tickr", "disp", "orient"}
pgaxis x1, y1, x2, y2, v1, v2,
{"opt", "step", "nsub", "tickl", "tickr", "frac", "disp", "orient"}
rb_pgplot-0.1.3/MANIFEST 0000664 0000764 0000764 00000001027 10537714753 013306 0 ustar masa masa FuncUsage
MANIFEST
README.en
README.ja
cogen.rb
depend
extconf.rb
kwarg.c
pgdemo1.rb
pgdemo15.rb
pgdemo3.rb
pgdemo4.rb
pgdemo9.rb
rb_pgplot.c.in
test/pgband.rb
test/pgcurs.rb
test/pggray.rb
test/pglcur.rb
test/pgline.rb
test/pgncur.rb
test/pgolin.rb
test/pgtick.rb
doc/Makefile
doc/css.css
doc/index.rd
doc/install.ja.rd
doc/method.ja.rd
doc/mkdoc.rb
doc/mkind.rb
doc/pgcont.rd
doc/pghist.rd
doc/pgimag.rd
doc/pgline.rd
doc/rbpg-ind.rd
doc/rbpg-ind.txt
doc/rbpg-relabel.rb
doc/rd2html-img-lib.rb
doc/trailer.html
doc/tutorial-01.ja.rd
rb_pgplot-0.1.3/README.en 0000664 0000764 0000764 00000005077 10537712457 013446 0 ustar masa masa Ruby/PGPLOT ver 0.1.3 by Masahiro TANAKA 2006-12-13
= Description
* Ruby interface to PGPLOT.
It provides PGPLOT functions as a Ruby module.
= Requirement
* PGPLOT ver 5.2.x
(http://astro.caltech.edu/~tjp/pgplot/)
* Libraries which PGPLOT drivers use:
** X11 library
** PNG library
** GrWin Graphics Library for MS-Windows.
(http://spdg1.sci.shizuoka.ac.jp/grwinlib/english/)
* Ruby ver 1.8.x
* NArray Extension library ver 0.5.9
(http://www.ruby-lang.org/en/raa-list.rhtml?name=NArray)
= Installation
* install PGPLOT library
- FORTRAN77 compiler required for source-compile.
- C interface library (libcpgplot.a) is also required.
* install Ruby, NArray
* install Ruby/PGPLOT
- extract distribution.
- compile and install by:
ruby extconf.rb [options (see below)]
make
make site-install
(or make install)
- Options for `ruby extconf.rb':
--with-pgplot-include=path : path to cpgplot.h
--with-pgplot-lib=path : path to PGPLOT libraries.
--with-x11-dir=path : path to X11
--with-grwin : for using GrWin (cygwin/mingw).
--with-sunws : PGPLOT is compiled with Sun WorkShop f77.
gfortran is assumed without this option.
example:
ruby extconf.rb --with-x11-dir=/usr/X11R6 \
--with-pgplot-include=/usr/local/pgplot \
--with-pgplot-lib=/usr/local/pgplot
= Usage
* Environment variables for PGPLOT (csh):
setenv PGPLOT_DIR /usr/local/lib/pgplot/ # pgxwin_server, rgb.txt
setenv PGPLOT_FONT ${PGPLOT_DIR}/grfont.dat
setenv PGPLOT_DEV /xwin
* To load the Ruby/PGPLOT extension;
require "pgplot"
* Module name is `Pgplot'. If you want to omit the module name;
include Pgplot
* Pgplot module method names are lower case of corresponding
PGPLOT functions. To start plotting:
pgbeg('/xwin')
See PGPLOT manual for function usage.
Arguments are not always same as the FORTRAN PGPLOT.
"FuncUsage" file includes a list of functions with
different arguments.
= Platforms tested
* Ruby 1.8.5 (2006-08-25) [i686-linux]
* NArray 0.5.9
* gcc/gfortran 4.1.1 20060525 (Red Hat 4.1.1-1)
= License
This program is free software.
You can distribute/modify this program
under the same terms as Ruby itself.
NO WARRANTY.
= Acknowledgment
M.T. thanks to Tim Pearson for developing the useful PGPLOT library
and giving me the permission to distribute the Ruby version of pgdemos.
M.T. also thanks to the developers of the Ruby language
for providing the wonderful language.
rb_pgplot-0.1.3/README.ja 0000664 0000764 0000764 00000004450 10537714753 013431 0 ustar masa masa Ruby/PGPLOT ver 0.1.3 by Masahiro TANAKA 2006-12-13
= 概要
* PGPLOTをRubyから使うための拡張ライブラリ。
= 必要なもの
* PGPLOT ver 5.2.x
(http://astro.caltech.edu/~tjp/pgplot/)
* PGPLOTのドライバが使うライブラリ (必要に応じて):
** X11ライブラリ
** PNGライブラリ
** GrWinグラフィクスライブラリ for MS-Windows (Cygwinでのみ動作確認)
(http://spdg1.sci.shizuoka.ac.jp/grwinlib/)
* Ruby ver 1.8.x
* NArray ver 0.5.9
(http://www.ruby-lang.org/en/raa-list.rhtml?name=NArray)
= インストール方法
* PGPLOT をインストール
- FORTRAN77が必要です (gfortranでもOK)。
- C言語インタフェースライブラリ(cpgplot)を作成する必要があります。
* Ruby, NArray をインストール
* Ruby/PGPLOT をインストール
- ソースを展開
- コンパイル・インストール:
ruby extconf.rb [オプション(下記参照)]
make
make site-install
(または make install)
- ruby extconf.rb のオプション:
--with-pgplot-include=path : cpgplot.hのディレクトリ。
--with-pgplot-lib=path : PGPLOTライブラリのディレクトリ。
--with-x11-dir=path : X11のpath
--with-grwin : for using GrWin (cygwin/mingw).
--with-sunws : PGPLOTをSun WorkShopのf77を使って
コンパイルした場合。指定しない時はg77。
例:
ruby extconf.rb --with-x11-dir=/usr/X11R6 \
--with-pgplot-include=/usr/local/pgplot \
--with-pgplot-lib=/usr/local/pgplot
= 使用方法
* PGPLOTの環境変数設定(csh)
setenv PGPLOT_DIR /usr/local/lib/pgplot/ # pgxwin_server, rgb.txt
setenv PGPLOT_FONT ${PGPLOT_DIR}/grfont.dat
setenv PGPLOT_DEV /xwin
* 拡張ライブラリをロードするには:
require "pgplot"
* モジュール名は`Pgplot'です。モジュール名を省略したいときは:
include Pgplot
* Pgplotモジュールのメソッドは、PGPLOTの関数と同じ名前(小文字)です。
プロットを開始するには:
pgbeg('/xwin')
詳細は PGPLOTのマニュアルを参照して下さい。
引数は必ずしもFORTRAN版と同じではありません。
引数が違う関数のリストは、"FuncUsage"というファイルにあります。
= 動作確認
* Ruby 1.8.5 (2006-08-25) [i686-linux]
* NArray 0.5.9
* gcc/gfortran 4.1.1 20060525 (Red Hat 4.1.1-1)
= 配布条件
Ruby本体と同じです。
無保証です。
= 謝辞
PGPLOTを開発し、Ruby版pgdemoの配布許可を下さった Tim Pearson氏
に感謝します。Ruby開発に携わった皆様に感謝します。
rb_pgplot-0.1.3/cogen.rb 0000664 0000764 0000764 00000004761 10537712457 013604 0 ustar masa masa # cogen.rb : Code generation script for Ruby/PGPLOT
#
# Copyright (c) 2000,2001 Masahiro TANAKA
#
# This program is free software.
# You can distribute/modify this program
# under the same terms as Ruby itself.
# NO WARRANTY.
$pgfuncs = %w(
pgend::
pgbbuf::
pgebuf::
pgpage::
pgpap:1,1:
pgupdt::
pgpanl:1,1:
pgclos::
pgbox:2,1,0,2,1,0:
pgtbox:2,1,0,2,1,0:
pgvsiz:1,1,1,1:
pgvstd::
pgwnad:1,1,1,1:
pgsubp:0,0:
pgwedg:2,1,1,1,1,2:
# Draw Funcs
pgdraw:1,1:
pgmove:1,1:
pgrect:1,1,1,1:
pgarro:1,1,1,1:
pgcirc:1,1,1:
pgpt1:1,1,0:
pgerr1:0,1,1,1,1:
pglab:2,2,2:
pgptxt:1,1,1,1,2:
pgtext:1,1,2:
pgmtxt:2,1,1,1,2:
pgetxt::
pgiden::
pgldev::
pgsave::
pgunsa::
pgeras::
# Set Funcs
pgsch:1:
pgscf:0:
pgsci:0:
pgsfs:0:
pgsls:0:
pgslw:0:
pgsclp:0:
pgsitf:0:
pgslct:0:
pgstbg:0:
pgscr:0,1,1,1:
pgshls:0,1,1,1:
pgsah:0,1,1:
pgscrl:1,1:
pgscir:0,0:
pgscrn:0,2:0
pgshs:1,1,1:
pgsvp:1,1,1,1:
pgswin:1,1,1,1:
# Query Funcs
pgqch::1
pgqcf::0
pgqci::0
pgqfs::0
pgqls::0
pgqlw::0
pgqclp::0
pgqid::0
pgqitf::0
pgqndt::0
pgqtbg::0
pgqcr:0:1,1,1
pgqvp:0:1,1,1,1
pgqwin::1,1,1,1
pgqcol::0,0
pgqcir::0,0
pgqpos::1,1
pgqvsz:0:1,1,1,1
).grep(/:.*:/).collect{|i| i.split(":",3)}
def pgfuncgen(name, inp, out)
inp = inp.split(",").collect{|i| i.to_i}
out = out.split(",").collect{|i| i.to_i}
ninp = inp.size
nout = out.size
# int->0, float->1
val2 = ["NUM2INT","NUM2DBL","STR2CSTR"]
type = ["int","float",nil]
conv = ["INT2NUM","rb_float_new",nil]
# Initialize Array
prot = ["VALUE obj"]
pass = []
vars = []
retn = []
inp.each_with_index { |i,x|
prot << "VALUE arg#{x}"
pass << "#{val2[i]}(arg#{x})"
}
out.each_with_index { |i,x|
vars << "#{type[i]} var#{x};"
pass << "&var#{x}"
retn << "#{conv[i]}(var#{x})"
}
if nout==0 then
retn = "Qtrue";
elsif nout>1 then
retn = "rb_ary_new3(#{nout},"+retn.join(",")+")"
end
prot = prot.join(",")
pass = pass.join(",")
return "
static VALUE
rb_pgplot_#{name}(#{prot})
{
#{vars}
c#{name}(#{pass});
return #{retn};
}
"
end
def cogen_pgplot
fin = open("rb_pgplot.c.in","r")
fout = open("rb_pgplot.c","w")
while l = fin.gets
if /--- auto-generated funcs will be placed here ---/ =~ l
$pgfuncs.each{|x| fout.print pgfuncgen(*x)}
elsif /--- auto-generated defs will be placed here ---/ =~ l
$pgfuncs.each{|x|
n = x[1].split(",").size
fout.print " rb_define_module_function(mPgplot,\"#{x[0]}\",rb_pgplot_#{x[0]},#{n});\n"}
else
fout.print
end
end
end
cogen_pgplot
rb_pgplot-0.1.3/depend 0000664 0000764 0000764 00000000142 07414746000 013322 0 ustar masa masa rb_pgplot.c: rb_pgplot.c.in cogen.rb
$(RUBY) cogen.rb
rb_pgplot.o: rb_pgplot.c $(hdrdir)/ruby.h
rb_pgplot-0.1.3/extconf.rb 0000664 0000764 0000764 00000004264 10537712457 014155 0 ustar masa masa # extconf.rb : Configure script for Ruby/PGPLOT
#
# Copyright (c) 2000,2001 Masahiro TANAKA
#
# This program is free software.
# You can distribute/modify this program
# under the same terms as Ruby itself.
# NO WARRANTY.
#
# usage: ruby extconf.rb [configure options]
require "mkmf"
#$DEBUG = true
# configure options:
# --with-x11-dir=path
# --with-x11-include=path
# --with-x11-lib=path
dir_config("x11")
# configure options:
# --with-pgplot-dir=path
# --with-pgplot-include=path
# --with-pgplot-lib=path
dir_config("pgplot")
# Otherwise you can also specify:
# --with-opt-dir=path
# --with-opt-include=path
# --with-opt-lib=path
# Check PGPLOT Header
exit unless have_header("cpgplot.h")
# Check NArray
$CPPFLAGS = " -I#{CONFIG['sitearchdir']} "+$CPPFLAGS
exit unless have_header("narray.h")
if RUBY_PLATFORM =~ /cygwin|mingw/
$LDFLAGS = " -L#{CONFIG['sitearchdir']} "+$LDFLAGS
exit unless have_library("narray","na_make_object")
end
# Check FORTRAN Libraries
#
# SUN WorkShop FORTRAN 77 compiler ver5.0
# configure options: --with-sunws
if with_config("sunws")
$libs = "-lM77 -lsunmath "+$libs
exit unless find_library("F77", "f77_init", "/opt/SUNWspro/lib")
$defs.push "-DSPARC_FORTRAN"
#
# GNU FORTRAN v4
elsif have_library("gfortran")
$CFLAGS = "-Wall "+$CFLAGS
$defs.push "-DGNU_FORTRAN"
#
# GNU FORTRAN v3
elsif have_library("g77")
$CFLAGS = "-Wall "+$CFLAGS
$defs.push "-DGNU_FORTRAN"
else
puts "failed"
exit
end
# Check GrWin Library (for cygwin (and mingw32?))
# configure options: --with-grwin
if with_config("grwin")
#$LDFLAGS = "-Wl,--subsystem,console "+$LDFLAGS
if RUBY_PLATFORM =~ /cygwin|mingw/
$libs += " -mwindows"
end
exit unless have_library("GrWin", "GWinit")
end
#
# Check X11 Library
have_library("X11", "XOpenDisplay")
# Check PNG Library
libs_save = $libs
$libs = append_library($libs, "z")
if !have_library("png","png_create_write_struct")
$libs = libs_save
end
# Check PGPLOT Library
$libs = append_library($libs, "pgplot")
exit unless find_library( "cpgplot", "cpgbeg", "/usr/lib",
"/usr/local/lib", "/usr/local/pgplot" )
$objs = %w(rb_pgplot.o kwarg.o)
# Generate Makefile
create_makefile("pgplot")
rb_pgplot-0.1.3/kwarg.c 0000664 0000764 0000764 00000003251 07352475141 013431 0 ustar masa masa /*
kwarg.c : Process keyword arguments for Ruby
Copyright (c) 2001 Masahiro TANAKA
This program is free software.
You can distribute/modify this program
under the same terms as Ruby itself.
NO WARRANTY.
*/
#include
/* void rb_scan_kw_args __((VALUE, ...)); */
static VALUE
kw_hash_i(i, tmp)
VALUE i, tmp;
{
VALUE key;
key = RARRAY(i)->ptr[0];
if (TYPE(key)==T_SYMBOL) {
key = rb_funcall(key, rb_intern("id2name"), 0);
} else
if (TYPE(key)!=T_STRING) {
rb_raise(rb_eArgError, "keywords must be String or Symbol");
}
rb_hash_aset(tmp, key, RARRAY(i)->ptr[1]);
return Qnil;
}
#ifdef HAVE_STDARG_PROTOTYPES
#include
#define va_init_list(a,b) va_start(a,b)
#else
#include
#define va_init_list(a,b) va_start(a)
#endif
void
#ifdef HAVE_STDARG_PROTOTYPES
rb_scan_kw_args(VALUE hash, ...)
#else
rb_scan_kw_args(hash, va_alist)
VALUE hash;
va_dcl
#endif
{
char *key;
VALUE *var, val, str, tmp;
va_list vargs;
va_init_list(vargs, hash);
tmp = rb_hash_new();
if (TYPE(hash) == T_HASH)
rb_iterate(rb_each, hash, kw_hash_i, tmp);
else if (hash != Qnil)
rb_fatal("rb_san_kw_args: non-hash arg passed");
for (;;) {
key = va_arg(vargs, char*);
if (!key) break;
var = va_arg(vargs, VALUE*);
str = rb_str_new2(key);
val = rb_funcall(tmp, rb_intern("delete"), 1, str);
if (var) *var = val;
}
if (rb_funcall(tmp, rb_intern("empty?"), 0)==Qfalse) {
val = rb_funcall(tmp, rb_intern("keys"), 0);
val = rb_funcall(val, rb_intern("join"), 1, rb_str_new2(","));
rb_raise(rb_eArgError, "unknown keywords: %s",STR2CSTR(val));
}
va_end(vargs);
}
rb_pgplot-0.1.3/pgdemo1.rb 0000664 0000764 0000764 00000017572 10537712457 014051 0 ustar masa masa require 'narray'
require 'pgplot'
include Pgplot
include NMath
PI = Math::PI
TWOPI = PI*2
BLACK,WHITE,RED,GREEN,BLUE,CYAN,MAGENT,YELLOW = (0..7).to_a
FULL,DASH,DOTDSH,DOTTED,FANCY = (1..5).to_a
NORMAL,ROMAN,ITALIC,SCRIPT = (1..4).to_a
SOLID,HOLLOW = (1..2).to_a
# ====== Utility function ======
def indgen arg
if arg.kind_of?(Range)
return NArray.sfloat(arg.size).indgen!(arg.first)
elsif arg.kind_of?(Numeric)
return NArray.sfloat(arg).indgen!
else
raise ArgumentError, "invalid argument"
end
end
def randomn n=1
rr = NArray.sfloat(n)
xx = NArray.sfloat(n)
idx= NArray.int(n).indgen!
i = 0
while i0 then
xo3 = x[idx1]/3.0
t = xo3**2
r[idx1] = 1.0 +
t*(-2.2499997 +
t*( 1.2656208 +
t*(-0.3163866 +
t*( 0.0444479 +
t*(-0.0039444 +
t*( 0.0002100))))))
end
if idx2.size>0 then
xx = x[idx2]
t = 3.0/xx
f0 = 0.79788456 +
t*(-0.00000077 +
t*(-0.00552740 +
t*(-0.00009512 +
t*( 0.00137237 +
t*(-0.00072805 +
t*( 0.00014476))))))
theta0 = xx - 0.78539816 +
t*(-0.04166397 +
t*(-0.00003954 +
t*( 0.00262573 +
t*(-0.00054125 +
t*(-0.00029333 +
t*( 0.00013558))))))
r[idx2] = f0*cos(theta0)/sqrt(xx)
end
return r
end
def bessel_j1 arg
r = NArray.sfloat(arg.size)
x = arg.abs
idx1,idx2 = (x<=3).where2
if idx1.size>0 then
xo3 = x[idx1]/3.0
t = xo3**2
f = 0.5 + t*(-0.56249985 +
t*( 0.21093573 +
t*(-0.03954289 +
t*( 0.00443319 +
t*(-0.00031761 +
t*( 0.00001109))))))
r[idx1] = f * arg[idx1]
end
if idx2.size>0 then
xx = x[idx2]
t = 3.0/xx
f1 = 0.79788456 +
t*( 0.00000156 +
t*( 0.01659667 +
t*( 0.00017105 +
t*(-0.00249511 +
t*( 0.00113653 +
t*(-0.00020033))))))
theta1 = xx - 2.35619449 +
t*( 0.12499612 +
t*( 0.00005650 +
t*(-0.00637879 +
t*( 0.00074348 +
t*( 0.00079824 +
t*(-0.00029166))))))
r[idx2] = f1*cos(theta1)/sqrt(xx)
end
idx = (arg<0).where
#p idx
#p r[idx]
r[idx] = -r[idx] if idx.size>0
return r
end
def pgex10
pgbbuf
pgsave
pgsci(YELLOW)
# PGFUNX(PGBSJ0,500,0.0,10.0*PI,0)
x = indgen(500)/50*PI
y = bessel_j0(x)
pgenv 0,PI*10, y.min,y.max
pgline x,y
pgsci(RED)
pgsls(DASH)
# PGFUNX(PGBSJ1,500,0.0,10.0*PI,1)
pgline x, bessel_j1(x)
pgsci(GREEN)
pgsls(FULL)
pglab('\fix', '\fiy',
'\frPGPLOT Example 10: routine PGFUNX')
pgmtxt('T', -4.0, 0.5, 0.5,
'\frBessel Functions')
pgarro(8.0, 0.7, 1.0, bessel_j0(NArray[1.0])[0])
pgarro(12.0, 0.5, 9.0, bessel_j1(NArray[9.0])[0])
pgstbg(GREEN)
pgsci(0)
pgptxt(8.0, 0.7, 0.0, 0.0, ' \fiy = J\d0\u(x)')
pgptxt(12.0, 0.5, 0.0, 0.0, ' \fiy = J\d1\u(x)')
pgunsa
pgebuf
end
# ====== Demo start ======
raise "device not found" if pgopen<0
pgex0
pgex1
pgex2
pgex3
pgsubp 2,1
pgex4
pgex5
pgsubp 1,1
pgex6
pgex7
pgex8
pgex9
pgex10
pgclos
exit
rb_pgplot-0.1.3/pgdemo15.rb 0000664 0000764 0000764 00000003757 07352476356 014144 0 ustar masa masa require 'narray'
require 'pgplot'
include NMath
include Pgplot
#-----------------------------------------------------------------------
# Demonstration program for PGPLOT vector field plot.
#
# Program to demonstrate the use of PGVECT along with
# PGCONB by illustrating the flow around a cylinder with circulation.
#-----------------------------------------------------------------------
twopi = 2*Math::PI
blank = -1.0e10
# number of points in the x and y directions
nx = 31
ny = 31
# cylinder radius
a = 1.0
# circulation strength
gamma = 2.0
# freestream velocity
vinf = 1.0
# max and min x and y
xmax = 3.0*a
xmin = -3.0*a
ymax = 3.0*a
ymin = -3.0*a
# point spacing
dx = (xmax-xmin)/(nx-1)
dy = (ymax-ymin)/(ny-1)
# compute the stream function, Cp, and u and v velocities
a2 = a**2
x = NArray.sfloat(nx,1).indgen!*dx + xmin
y = NArray.sfloat(1,ny).indgen!*dy + ymin
r2 = x**2 + y**2
r2[(r2.eq 0).where] = 1e-10
psi = vinf * y * (1-a2/r2) + gamma/twopi*0.5*log(r2/a)
u = vinf * (1 + a2/r2 - 2*a2*(x/r2)**2) + gamma/twopi * y/r2
v = vinf * x * (-2*a2*y/r2**2) + gamma/twopi * x/r2
cp = 1 - (u**2+v**2)/vinf**2
idx = (r2 < a2).where
u[idx] =
v[idx] = blank
#
# start drawing
#
pgbeg
pgenv( x[0], x[-1], y[0], y[-1], 1 )
pgiden
pglab('X','Y','Flow About a Cylinder with Circulation')
#
# contour plot of the stream function (streamlines)
#
tr = [ x[0]-dx, dx, 0.0, y[0]-dy, 0.0, dy ]
level = [ 1.0, 0.5, 0.0, -0.5, -1.0 ]
pgcont( psi, level, tr )
#
# draw cylinder
#
pgbbuf
pgsci(0)
pgsfs(1)
pgcirc(0.0, 0.0, a*1.1)
pgsfs(2)
pgsci(14)
pgcirc(0.0, 0.0, a)
pgsci(1)
pgebuf
#
# vector plot
#
pgsah(2, 45.0, 0.7)
pgsch(0.3)
tr = [ x[0], dx, 0.0, y[0], 0.0, dy ]
pgvect( u[1..-2,1..-2], v[1..-2,1..-2], 0.0, 0, tr, -1.0e10 )
pgsch(1.0)
#
# finish
#
rb_pgplot-0.1.3/pgdemo3.rb 0000664 0000764 0000764 00000007354 07271376750 014053 0 ustar masa masa require 'narray'
require 'pgplot'
include Pgplot
include NMath
def main
exit unless pgbeg('?',1,1)
print " Routine PGCONT\n"
pgex31
print " Routine PGCONS\n"
pgex32
print " Routine PGCONB\n"
pgex33
print " Routine PGCONT with PGCONL labels\n"
pgex36
#print " Routine PGCONX with arrow labels\n"
#pgex37
#print " Routine PGCONX\n"
#pgex34
print " Routine PGCONF\n"
pgexx1
pgend
end
# ====== Utility ======
class PgLinestyle
attr_accessor :width
attr_accessor :color
attr_accessor :style
def initialize(opt=nil)
@width = 1
@color = 1
@style = 1
if opt.is_a?(Hash)
@width = opt[:width] || @width
@width = opt['width'] || @width
@color = opt[:color] || @color
@color = opt['color'] || @color
@style = opt[:style] || @style
@style = opt['style'] || @style
end
end
def set
pgslw @width
pgsci @color
pgsls @style
end
end # class PgLinestyle
NC=21
Pgline_default = PgLinestyle.new
$sty = (1..NC).collect{|i|
if i<10
x = PgLinestyle.new(:width =>1, :color =>2, :style =>2)
else
x = PgLinestyle.new(:width =>1, :color =>3, :style =>1)
end
if i%5==0
x.width = 5
end
x
}
i = NArray.sfloat(40,1).indgen!(1)
j = NArray.sfloat(1,40).indgen!(1)
$f = cos( 0.3*sqrt(i*2)-0.4*j/3 ) * cos( 0.4*i/3 ) + (i-j)/40.0
$lv = NArray.sfloat(NC).indgen!*($f.max-$f.min)/NC+$f.min
#NArray.span($f.minmax,NC)
# ====== Exsample routine ======
def pgex31
pgpage
pgsvp(0.05,0.95,0.05,0.95)
pgswin(1.0,40.0,1.0,40.0)
pgbox('bcts',0.0,0,'bcts',0.0,0)
pgmtxt('t',1.0,0.0,0.0,'Contouring using PGCONT')
pgbbuf
for i in 0...NC
$sty[i].set
pgcont $f, $lv[i]
end
Pgline_default.set
pgebuf
end
def pgex32
pgpage
pgsvp(0.05,0.95,0.05,0.95)
pgswin(1.0,40.0,1.0,40.0)
pgbox('bcts',0.0,0,'bcts',0.0,0)
pgmtxt('t',1.0,0.0,0.0,'Contouring using PGCONS')
pgbbuf
for i in 0...NC
$sty[i].set
pgcons $f, $lv[i]
end
Pgline_default.set
pgebuf
end
def pgex33
pgpage
pgsvp(0.05,0.95,0.05,0.95)
pgswin(1.0,40.0,1.0,40.0)
pgbox('bcts',0.0,0,'bcts',0.0,0)
pgmtxt('t',1.0,0.0,0.0,'Contouring using PGCONB')
pgbbuf
blank = -65536.0
f = $f.dup
i = NArray.sfloat(40,1).indgen!(1)
j = NArray.sfloat(1,40).indgen!(1)
r = sqrt((i-20.5)**2 + (j-20.5)**2)
idx = ((r>20).or(r<3.0)).where
f[idx] = blank
pgsci 1
pgpt( (i+NArray.int(1,40))[idx], (j+NArray.int(40,1))[idx], 1 )
for i in 0...NC
$sty[i].set
pgconb f, $lv[i], blank
end
Pgline_default.set
pgebuf
end
def pgex36
pgpage
pgsvp(0.05,0.95,0.05,0.95)
pgswin(1.0,40.0,1.0,40.0)
pgbox('bcts',0.0,0,'bcts',0.0,0)
pgmtxt('t',1.0,0.0,0.0,'Contouring using PGCONT and PGCONL labels')
pgbbuf
for i in 0...NC
$sty[i].set
pgcons $f, $lv[i]
end
pgslw 1
pgsls 1
1.step(20,2) {|i|
pgsci $sty[i].color
pgconl $f,$lv[i],"%2i"%(i+1),16,8
}
Pgline_default.set
pgebuf
end
def pgexx1
nx=ny=51
c = [3.0, 3.2, 3.5, 3.6, 3.766413, 4.0 ,5.0, 10.0, 100.0]
xmin =-2.0
xmax = 2.0
ymin =-2.0
ymax = 2.0
mu = 0.3
dx = (xmax-xmin)/(nx-1)
dy = (ymax-ymin)/(ny-1)
tr = [xmin-dx, dx, 0.0, ymin-dy, 0.0, dy]
x = tr[0] + NArray.sfloat(nx,1).indgen!(1)*tr[1]
y = tr[3] + NArray.sfloat(1,ny).indgen!(1)*tr[5]
z = (1.0-mu)*(2.0/sqrt((x-mu)**2+y**2)+(x-mu)**2+y**2) +
mu*(2.0/sqrt((x+1.0-mu)**2+y**2)+(x+1.0-mu)**2+y**2)
pgpage
pgvstd
pgwnad(xmin, xmax, ymin, ymax)
pgsfs(1)
for i in 0..c.size-2
r = 0.5+0.5*(i-1)/(c.size-1)
pgscr(i+10, r, r, r)
pgsci(i+10)
pgconf(z,c[i]..c[i+1],tr)
end
pgsci(3)
pgcont(z,c,tr)
pgsci(1)
pgsch(0.6)
pgbox('bctsin',1.0,10,'bctsinv',1.0,10)
pgsch(1.0)
pgmtxt('t',1.0,0.0,0.0,'Contour filling using PGCONF')
end
main
rb_pgplot-0.1.3/pgdemo4.rb 0000664 0000764 0000764 00000003450 07271376750 014045 0 ustar masa masa require 'narray'
require 'pgplot'
include Pgplot
include NMath
def setvp
pgsvp(0.0, 1.0, 0.0, 1.0)
vpx1, vpx2, vpy1, vpy2 = pgqvp(1)
d = [vpx2-vpx1, vpy2-vpy1].min/40.0
vpx1 = vpx1 + 5.0*d
vpx2 = vpx2 - 2.0*d
vpy1 = vpy1 + 8.0*d
vpy2 = vpy2 - 2.0*d
pgvsiz(vpx1, vpx2, vpy1, vpy2)
end
def palett contra,bright
rl =[-0.5, 0.0, 0.17, 0.33, 0.50, 0.67, 0.83, 1.0, 1.7]
rr =[ 0.0, 0.0, 0.0, 0.0, 0.6, 1.0, 1.0, 1.0, 1.0]
rg =[ 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.6, 0.0, 1.0]
rb =[ 0.0, 0.3, 0.8, 1.0, 0.3, 0.0, 0.0, 0.0, 1.0]
pgctab(rl, rr, rg, rb)
end
exit if pgopen('?') < 1
printf "PGPLOT device type: %s\n", pgqinf('TYPE')
c1,c2 = pgqcir()
printf "Number of color indices used for image: %d\n", nc=[0,c2-c1+1].max
exit if nc<8
nx = 64
ny = 64
x = NArray.sfloat(nx,1).indgen!(1)
y = NArray.sfloat(1,ny).indgen!(1)
f = cos( sqrt(x*(80.0/nx))*0.6 - y*16.0/(3.0*ny) ) *
cos( x*16.0/(3.0*nx) ) +
(x/nx - y/ny) + sin(sqrt(x**2+y**2))*0.05
pgpage
setvp
pgwnad(0.0, 1.0+nx, 0.0, 1.0+ny)
bright = 0.5
contra = 1.0
palett(contra, bright)
pgimag(f)
pgmtxt('t',1.0,0.0,0.0,'PGIMAG, PGWEDG, and PGCTAB')
pgsch(0.6)
pgbox('bcntsi',0.0,0,'bcntsiv',0.0,0)
pgmtxt('b',3.0,1.0,1.0,'pixel number')
pgwedg('BI', 4.0, 5.0, f.min,f.max, 'pixel value')
pgsch(1.0)
angle = 120.0/57.29578
c = cos(angle)
s = sin(angle)
tr = NArray[ -c-s, 2.0*c/nx, 2.0*s/ny,
-c+s, -2.0*s/nx, 2.0*c/ny ]
pgpage
setvp
pgwnad(-1.0, 1.0, -1.0, 1.0)
pgsci(1)
bright = 0.5
contra = 1.0
palett(contra, bright)
pgimag(f,nil,tr)
pgsci(1)
pgcont(f,NArray.sfloat(21).indgen!*(f.max-f.min)/21+f.min, tr)
pgsls(1)
pgslw(1)
pgsci(1)
#outlin(1,mxi,1,mxj,tr)
pgmtxt('t',1.0,0.0,0.0,'PGIMAG, PGCONT and PGWEDG')
pgsch(0.6)
pgbox('bctsn',0.0,0,'bctsn',0.0,0)
pgwedg('BI', 4.0, 5.0, f.min, f.max, 'pixel value')
pgsch(1.0)
pgclos
rb_pgplot-0.1.3/pgdemo9.rb 0000664 0000764 0000764 00000001536 07271376750 014055 0 ustar masa masa require 'narray'
require 'pgplot'
include Pgplot
include NMath
n=64
ncol=32
nlev=9
pgbeg
i = NArray.sfloat(n,1).indgen!(1)
j = NArray.sfloat(1,n).indgen!(1)
f = cos(0.6*sqrt(i*2)-(0.4/3)*j) * cos((0.4/3)*i) + (i-j)/n
fmin = f.min
fmax = f.max
ia = (f-fmin)/(fmax-fmin)*(ncol-1)+16
ci1,ci2 = pgqcol
if ci2 < 15+ncol
raise 'This program requires a device with at least %d colors'%(15+ncol)
end
pgpage
pgscr(0, 0.0, 0.3, 0.2)
pgsvp(0.05,0.95,0.05,0.95)
pgwnad(0.0, 1.0, 0.0, 1.0)
for i in 1..ncol
r = 0.8*(i-1)/(ncol-1) + 0.2
g = 2.0*(i-1-ncol/2)/(ncol-1)
g = 0 if g<0
b = 0.2 + 0.4*(ncol-i)/ncol
pgscr(i+15, r, g, b)
end
pgpixl(ia,0,1,0,1)
pgsci(1)
pgmtxt('t',1.0,0.0,0.0,'Test of PGPIXL')
pgbox('bcnts',0.0,0,'bcnts',0.0,0)
clev = NArray.sfloat(nlev).indgen!(1) * ((fmax-fmin)/nlev) + fmin
pgcont(f, clev, NArray[-1.0, 1, 0, -1, 0, 1]/(n-1))
rb_pgplot-0.1.3/rb_pgplot.c.in 0000664 0000764 0000764 00000110606 10537712457 014721 0 ustar masa masa /*
rb_pgplot.c : Ruby/PGPLOT extension library
Copyright (c) 2000,2001 Masahiro TANAKA
This program is free software.
You can distribute/modify this program
under the same terms as Ruby itself.
NO WARRANTY.
*/
#include
#include
#include
#include "narray.h"
#define min(a,b) (((a)<(b))?(a):(b))
#define rb_pgplot_fltary(obj) na_cast_object(obj,NA_SFLOAT)
#define rb_pgplot_intary(obj) na_cast_object(obj,NA_LINT)
#define rb_pgplot_newary(rank,shape) na_make_object(NA_SFLOAT,rank,shape,cNArray)
#define NA_PTR_FLT(dta) (float*)(((struct NARRAY*)DATA_PTR(dta))->ptr)
#define NA_PTR_INT(dta) (int*)(((struct NARRAY*)DATA_PTR(dta))->ptr)
#ifndef NA_RANK
#define NA_RANK(dta) (((struct NARRAY*)DATA_PTR(dta))->rank)
#endif
#ifndef NA_TYPE
#define NA_TYPE(dta) (((struct NARRAY*)DATA_PTR(dta))->type)
#endif
#ifndef NA_TOTAL
#define NA_TOTAL(dta) (((struct NARRAY*)DATA_PTR(dta))->total)
#endif
#ifndef NA_SHAPE0
#define NA_SHAPE0(dta) (((struct NARRAY*)DATA_PTR(dta))->shape[0])
#endif
#ifndef NA_SHAPE1
#define NA_SHAPE1(dta) (((struct NARRAY*)DATA_PTR(dta))->shape[1])
#endif
static VALUE mPgplot;
static VALUE cPgCursor;
static VALUE ePgCursorError;
static ID id_beg, id_end, id_x, id_y, id_char;
#ifdef GNU_FORTRAN
void MAIN__() {} /* Ruby has no 'MAIN__'! ; How should I handle this??? */
#endif
/* Search Minimum and Maximum values of array */
static void
rb_pgplot_minmax(VALUE na, float range[])
{
int i;
float *ptr = NA_PTR_FLT(na);
range[0] = range[1] = *ptr;
ptr++;
for (i=NA_TOTAL(na)-1; i>0; i--,ptr++) {
if (*ptrrange[1]) range[1] = *ptr; /* max */
}
}
/* PGASK -- control new page prompting
pgask [true|false]
*/
static VALUE
rb_pgplot_pgask( int argc, VALUE *argv, VALUE self)
{
VALUE vflag;
rb_scan_args(argc, argv, "01", &vflag);
if (RTEST(vflag))
cpgask(1);
else
cpgask(0);
return Qnil;
}
/* PGOPEN -- open a graphics device
stat = pgopen [device]
*/
static VALUE
rb_pgplot_pgopen( int argc, VALUE *argv, VALUE self )
{
VALUE vdev;
char *dev="?";
rb_scan_args(argc,argv, "01", &vdev);
if (vdev!=Qnil) dev = STR2CSTR(vdev);
return INT2NUM(cpgopen(dev));
}
/* PGBEG -- open a graphics device */
static VALUE
rb_pgplot_pgbeg( int argc, VALUE *argv, VALUE self )
{
VALUE vdev, vnxs, vnys;
int nxsub=1, nysub=1;
char *dev="?";
rb_scan_args(argc, argv, "03", &vdev,&vnxs,&vnys);
if (vdev!=Qnil) dev = STR2CSTR(vdev);
if (vnxs!=Qnil) nxsub = NUM2INT(vnxs);
if (vnys!=Qnil) nysub = NUM2INT(vnys);
if (cpgbeg(0, dev, nxsub, nysub) != 1)
return Qnil;
else
return Qtrue;
}
/* PGENV -- set window and viewport and draw labeled frame
pgenv xmin,xmax,ymin,ymax [, just [, axis]]
xmin: the left of the viewport.
xmax: the right of the viewport.
ymin: the bottom of the viewport.
ymax: the top of the viewport
just: if just=1, the x and y axes is scaled equally,
otherwise scaled independently.
axis: controls of axes.
*/
static VALUE
rb_pgplot_pgenv( int argc, VALUE *argv, VALUE self )
{
VALUE x0, x1, y0, y1, vjust, vaxis;
int just=0, axis=0;
rb_scan_args(argc, argv, "42", &x0,&x1,&y0,&y1,&vjust,&vaxis);
if (vjust!=Qnil) just = NUM2INT(vjust);
if (vaxis!=Qnil) axis = NUM2INT(vaxis);
cpgenv( NUM2DBL(x0), NUM2DBL(x1), NUM2DBL(y0), NUM2DBL(y1), just, axis );
return Qtrue;
}
/* PGLINE -- draw a polyline (curve defined by line-segments)
pgline xarray, yarray
*/
static VALUE
rb_pgplot_pgline(VALUE obj, VALUE v1, VALUE v2)
{
VALUE x, y;
x = rb_pgplot_fltary( v1 );
y = rb_pgplot_fltary( v2 );
cpgline( min(NA_TOTAL(x),NA_TOTAL(y)), NA_PTR_FLT(x), NA_PTR_FLT(y) );
return Qtrue;
}
/* PGPOLY -- draw a polygon, using fill-area attributes
pgpoly xarray, yarray
*/
static VALUE
rb_pgplot_pgpoly(VALUE obj, VALUE v1, VALUE v2)
{
VALUE x, y;
x = rb_pgplot_fltary( v1 );
y = rb_pgplot_fltary( v2 );
cpgpoly( min(NA_TOTAL(x),NA_TOTAL(y)), NA_PTR_FLT(x), NA_PTR_FLT(y) );
return Qtrue;
}
/* PGPT -- draw several graph markers
pgpt xarray, yarray [,symbol]
*/
static VALUE
rb_pgplot_pgpt( int argc, VALUE *argv, VALUE self )
{
VALUE vx, vy, vsym;
VALUE x, y;
int sym=0;
rb_scan_args(argc,argv, "21", &vx,&vy,&vsym);
if (vsym!=Qnil) sym = NUM2INT(vsym);
x = rb_pgplot_fltary( vx );
y = rb_pgplot_fltary( vy );
cpgpt( min(NA_TOTAL(x),NA_TOTAL(y)), NA_PTR_FLT(x), NA_PTR_FLT(y), sym );
return Qtrue;
}
/* PGPNTS -- draw several graph markers, not all the same
pgpnts xarray, yarray, symarray
*/
static VALUE
rb_pgplot_pgpnts( VALUE obj, VALUE vx, VALUE vy, VALUE vs )
{
VALUE x, y, s;
x = rb_pgplot_fltary( vx );
y = rb_pgplot_fltary( vy );
s = rb_pgplot_intary( vs );
cpgpnts( min(NA_TOTAL(x),NA_TOTAL(y)), NA_PTR_FLT(x), NA_PTR_FLT(y),
NA_PTR_INT(s), NA_TOTAL(s) );
return Qtrue;
}
/* PGBIN -- histogram of binned data
pgbin xarray, yarray [,center]
x : abscissae of bins.
y : data values of bins.
center : if true, the X values denote the center of the bin;
if false, the X values denote the lower edge (in X) of the bin.
*/
static VALUE
rb_pgplot_pgbin( int argc, VALUE *argv, VALUE self )
{
VALUE vx, vy, vcent;
VALUE x, y;
int cent;
rb_scan_args(argc,argv, "21", &vx,&vy,&vcent);
if (RTEST(vcent)) cent=1; else cent=0;
x = rb_pgplot_fltary( vx );
y = rb_pgplot_fltary( vy );
cpgbin( min(NA_TOTAL(x),NA_TOTAL(y)), NA_PTR_FLT(x), NA_PTR_FLT(y), cent );
return Qtrue;
}
/* PGHIST -- histogram of unbinned data
pghist, data, nbin [,range, flag]
data : the data values. NBIN may not exceed 200.
nbin : the number of bins to use
range : the range for the histogram.
flag : = 0 PGENV is called automatically
= 1 the histogram is plotted in the current window.
= 2,3 with a filled area style.
= 4,5 simple line.
*/
static VALUE
rb_pgplot_pghist( int argc, VALUE *argv, VALUE self )
{
VALUE vdat,vnbin,vrange,vflag;
VALUE na_dat;
int flag=0;
float range[2];
rb_scan_args(argc,argv, "22", &vdat,&vnbin,&vrange,&vflag);
na_dat = rb_pgplot_fltary( vdat );
/* Data Range */
if (vrange!=Qnil) {
range[0] = NUM2DBL(rb_ivar_get(vrange, id_beg));
range[1] = NUM2DBL(rb_ivar_get(vrange, id_end));
} else {
rb_pgplot_minmax(na_dat,range);
}
/* PGFLAG */
if (vflag!=Qnil) flag = NUM2INT(vflag);
cpghist( NA_TOTAL(na_dat), NA_PTR_FLT(na_dat),
range[0], range[1], NUM2INT(vnbin), flag );
return Qtrue;
}
/* Collection of Error bars
*/
static void
rb_pgplot_errorbar( int argc, VALUE *argv, int callid, int dir )
{
VALUE v1,v2,v3,vt;
VALUE a1,a2,a3;
int size;
float tlen=1;
rb_scan_args(argc,argv, "31", &v1,&v2,&v3,&vt);
a1 = rb_pgplot_fltary( v1 );
a2 = rb_pgplot_fltary( v2 );
a3 = rb_pgplot_fltary( v3 );
size = min(NA_TOTAL(a1),NA_TOTAL(a2));
size = min(size,NA_TOTAL(a3));
if (vt!=Qnil) tlen = NUM2DBL(vt);
if (callid==1)
cpgerrx( size,
NA_PTR_FLT(a1), NA_PTR_FLT(a2), NA_PTR_FLT(a3),
tlen );
else if (callid==2)
cpgerry( size,
NA_PTR_FLT(a1), NA_PTR_FLT(a2), NA_PTR_FLT(a3),
tlen );
else
cpgerrb( dir, size,
NA_PTR_FLT(a1), NA_PTR_FLT(a2), NA_PTR_FLT(a3),
tlen );
}
/* PGERRB -- horizontal or vertical error bar
pgerrb, dir, x, y, err [,tlen]
dir : direction to plot the error bar relative to the data point.
One-sided error bar:
DIR is 1 for +X (X to X+E);
2 for +Y (Y to Y+E);
3 for -X (X to X-E);
4 for -Y (Y to Y-E).
Two-sided error bar:
DIR is 5 for +/-X (X-E to X+E);
6 for +/-Y (Y-E to Y+E).
x : world x-coordinates of the data.
y : world y-coordinates of the data.
err : value of error bar distance to be added to the
data position in world coordinates.
tlen: length of terminals to be drawn at the ends of the error bar,
as a multiple of the default length.
*/
static VALUE
rb_pgplot_pgerrb( int argc, VALUE *argv, VALUE self )
{
rb_pgplot_errorbar( argc-1, argv+1, 0, NUM2INT(argv[0]) );
return Qtrue;
}
/* PGERRX -- horizontal error bar
pgerrx, x1, x2, y [,tlen]
x1 : world x-coordinates of lower end of the error bars.
x2 : world x-coordinates of upper end of the error bars.
*/
static VALUE
rb_pgplot_pgerrx( int argc, VALUE *argv, VALUE self )
{
rb_pgplot_errorbar( argc, argv, 1, 0 );
return Qtrue;
}
/* PGERRY -- vertical error bar
pgerry, x, y1, y2 [,tlen]
y1 : world y-coordinates of top end of the error bars.
y2 : world y-coordinates of bottom end of the error bars.
*/
static VALUE
rb_pgplot_pgerry( int argc, VALUE *argv, VALUE self )
{
rb_pgplot_errorbar( argc, argv, 2, 0 );
return Qtrue;
}
static float *
rb_pgplot_transform( VALUE val_tr )
{
static float tr_default[6] = {0.0, 1.0, 0.0, 0.0, 0.0, 1.0};
static float tr[6] = {0.0, 1.0, 0.0, 0.0, 0.0, 1.0};
VALUE na_tr;
/* Transform */
if (val_tr!=Qnil) {
na_tr = rb_pgplot_fltary( val_tr );
if (NA_TOTAL(na_tr) != 6)
rb_raise(rb_eArgError, "TR argument must be 6-elm (N)Array");
MEMCPY(tr, NA_PTR_FLT(na_tr), float, 6);
return tr;
} else {
return tr_default;
}
}
static void
rb_pgplot_find_range(VALUE na, VALUE vrange, float range[])
{
/* if Range class is set, extrant begin&end */
if (vrange!=Qnil) {
range[0] = NUM2DBL(rb_ivar_get(vrange, id_beg));
range[1] = NUM2DBL(rb_ivar_get(vrange, id_end));
} else {
/* if Range is not set, search min&max of array */
rb_pgplot_minmax(na,range);
}
}
/* contour routine collection */
static void
rb_pgplot_contour( int argc, VALUE *argv, int callid )
{
VALUE vmap, vtr, vcont, vblank, vtmp;
VALUE na_map, na_cont;
float blank=0, *tr;
rb_scan_args(argc, argv, "22", &vmap, &vcont, &vtr, &vblank );
if (callid==2) { /* for PGCONB */
/* Exchange */
vtmp=vblank; vblank=vtr; vtr=vtmp;
/* Blanking */
if (vblank!=Qnil) blank=NUM2DBL(vblank);
}
/* Map Data */
na_map = rb_pgplot_fltary( vmap );
if (NA_RANK(na_map) != 2)
rb_raise(rb_eArgError, "Image must be 2-D (N)Array");
/* Contour levels */
na_cont = rb_pgplot_fltary( vcont );
/* Transform */
tr = rb_pgplot_transform( vtr );
/* Show Contour */
if (callid==1)
cpgcons( NA_PTR_FLT(na_map), NA_SHAPE0(na_map), NA_SHAPE1(na_map),
1, NA_SHAPE0(na_map), 1, NA_SHAPE1(na_map),
NA_PTR_FLT(na_cont), NA_TOTAL(na_cont), tr );
else if (callid==2)
cpgconb( NA_PTR_FLT(na_map), NA_SHAPE0(na_map), NA_SHAPE1(na_map),
1, NA_SHAPE0(na_map), 1, NA_SHAPE1(na_map),
NA_PTR_FLT(na_cont), NA_TOTAL(na_cont), tr, blank );
else
cpgcont( NA_PTR_FLT(na_map), NA_SHAPE0(na_map), NA_SHAPE1(na_map),
1, NA_SHAPE0(na_map), 1, NA_SHAPE1(na_map),
NA_PTR_FLT(na_cont), NA_TOTAL(na_cont), tr );
}
/* PGCONT -- contour map of a 2D data array (contour-following)
pgcont, map, cont [,tr]
map : 2-D array of map data
cont : array of contour levels
tr : transformation matrix between array grid and world coordinates.
*/
static VALUE
rb_pgplot_pgcont( int argc, VALUE *argv, VALUE self )
{
rb_pgplot_contour( argc, argv, 0 );
return Qtrue;
}
/* PGCONS -- contour map of a 2D data array (fast algorithm)
pgcons, map, cont [,tr]
map : 2-D array of map data
cont : array of contour levels
tr : transformation matrix
*/
static VALUE
rb_pgplot_pgcons( int argc, VALUE *argv, VALUE self )
{
rb_pgplot_contour( argc, argv, 1 );
return Qtrue;
}
/* PGCONB -- contour map of a 2D data array, with blanking
pgconb, map, cont [, blank, tr]
map : 2-D array of map data
cont : array of contour levels
tr : transformation matrix
blank : elements of array A that are equal to this value are blanked.
*/
static VALUE
rb_pgplot_pgconb( int argc, VALUE *argv, VALUE self )
{
rb_pgplot_contour( argc, argv, 2 );
return Qtrue;
}
/* PGCONF -- fill between two contours
pgconf, map, cont_range [,tr]
map : 2-D array of map data
cont_range : range of two contour levels
tr : transformation matrix
*/
static VALUE
rb_pgplot_pgconf( int argc, VALUE *argv, VALUE self )
{
VALUE vmap, vtr, vcont;
VALUE na_map;
float crange[2], *tr;
rb_scan_args(argc, argv, "21", &vmap, &vcont, &vtr );
/* Map Data */
na_map = rb_pgplot_fltary( vmap );
if (NA_RANK(na_map) != 2)
rb_raise(rb_eArgError, "Image must be 2-D (N)Array");
/* Contour range */
rb_pgplot_find_range( na_map, vcont, crange );
/* Transform */
tr = rb_pgplot_transform( vtr );
/* Show Contour */
cpgconf( NA_PTR_FLT(na_map), NA_SHAPE0(na_map), NA_SHAPE1(na_map),
1, NA_SHAPE0(na_map), 1, NA_SHAPE1(na_map),
crange[0], crange[1], tr );
return Qtrue;
}
/* PGCONL -- label contour map of a 2D data array
pgconl, map, cont, label [,intval, minint, tr]
map : 2-D array of map data
cont : contour level tobe labeld
label : label string
intval : spacing along the contour between labels, in grid cells.
minint : contours that cross less than MININT cells will not be labelled.
tr : transformation matrix
*/
static VALUE
rb_pgplot_pgconl( int argc, VALUE *argv, VALUE self )
{
VALUE vmap, vcnt, vlab, vint, vmin, vtr;
VALUE na_map;
float *tr;
int intval=20, minint=10; /* recomended default */
rb_scan_args(argc, argv, "33", &vmap,&vcnt,&vlab,&vint,&vmin,&vtr );
/* Map Data */
na_map = rb_pgplot_fltary( vmap );
if (NA_RANK(na_map) != 2)
rb_raise(rb_eArgError, "Image must be 2-D (N)Array");
/* spacing of labels */
if (vint!=Qnil) intval = NUM2INT(vint);
if (vmin!=Qnil) minint = NUM2INT(vmin);
/* Transform */
tr = rb_pgplot_transform( vtr );
/* Show Contour */
cpgconl( NA_PTR_FLT(na_map), NA_SHAPE0(na_map), NA_SHAPE1(na_map),
1, NA_SHAPE0(na_map), 1, NA_SHAPE1(na_map),
NUM2DBL(vcnt), tr, STR2CSTR(vlab), intval, minint);
return Qtrue;
}
/* PGVECT -- vector map of a 2D data array, with blanking
pgvect, x, y [, scale, pos, tr, blank ]
x : horizontal component data array.
y : vertical component data array.
scale : scale factor for vector lengths, if 0.0, C will be
set so that the longest vector is equal to the
smaller of TR(2)+TR(3) and TR(5)+TR(6).
pos : vector positioning code.
<0 vector head positioned on coordinates
>0 vector base positioned on coordinates
=0 vector centered on the coordinates
tr : transformation matrix
blank : elements of arrays A or B that are exactly equal to
this value are ignored (blanked).
*/
static VALUE
rb_pgplot_pgvect( int argc, VALUE *argv, VALUE self )
{
VALUE vx,vy,vscl,vpos,vtr,vblank;
VALUE na_x, na_y;
int pos=0;
float scale=0, blank=0, *tr;
rb_scan_args(argc, argv, "24", &vx,&vy,&vscl,&vpos,&vtr,&vblank);
/* Vector Data */
na_x = rb_pgplot_fltary( vx );
na_y = rb_pgplot_fltary( vy );
if (NA_RANK(na_x) != 2 || NA_RANK(na_y) != 2 )
rb_raise(rb_eArgError, "Vector arrays must be 2-D (N)Array");
if (NA_SHAPE0(na_x) != NA_SHAPE0(na_y) || NA_SHAPE1(na_x) != NA_SHAPE1(na_y) )
rb_raise(rb_eArgError, "Vector array sizes must be same");
/* Options */
if (vscl!=Qnil) scale = NUM2DBL(vscl);
if (vpos!=Qnil) pos = NUM2INT(vpos);
if (vblank!=Qnil) blank = NUM2DBL(vblank);
/* Transform */
tr = rb_pgplot_transform( vtr );
/* Show Contour */
cpgvect( NA_PTR_FLT(na_x), NA_PTR_FLT(na_y),
NA_SHAPE0(na_x), NA_SHAPE1(na_x),
1, NA_SHAPE0(na_x), 1, NA_SHAPE1(na_x),
scale, pos, tr, blank );
return Qtrue;
}
/*
static void
rb_pgplot_palett()
{
float gl[2]={0.,1.};
float gr[2]={0.,1.};
float gg[2]={0.,1.};
float gb[2]={0.,1.};
float contra=1.0, bright=0.5;
cpgctab(gl, gr, gg, gb, 2, contra, bright);
}
*/
/* collection of PGIMAG and PGGRAY
*/
static VALUE
rb_pgplot_mapimage( int argc, VALUE *argv, VALUE self, int callid )
{
VALUE vimage, vtr, vrange;
VALUE na;
float range[2], *tr;
rb_scan_args(argc,argv, "12", &vimage, &vrange, &vtr );
/* Image */
na = rb_pgplot_fltary( vimage );
if (NA_RANK(na) != 2)
rb_raise(rb_eArgError, "Image must be 2-D (N)Array");
/* Transform */
tr = rb_pgplot_transform( vtr );
/* Range */
rb_pgplot_find_range(na, vrange, range);
/* Show Image */
/*rb_pgplot_palett();*/
if (callid==0)
cpgimag( NA_PTR_FLT(na), NA_SHAPE0(na), NA_SHAPE1(na),
1, NA_SHAPE0(na), 1, NA_SHAPE1(na),
range[0], range[1], tr );
else
cpggray( NA_PTR_FLT(na), NA_SHAPE0(na), NA_SHAPE1(na),
1, NA_SHAPE0(na), 1, NA_SHAPE1(na),
range[0], range[1], tr );
return Qtrue;
}
/* PGIMAG -- color image from a 2D data array
pgimag, array [,range ,tr]
range : range of array value to be drawn
TR : transformation matrix.
*/
static VALUE
rb_pgplot_pgimag( int argc, VALUE *argv, VALUE self )
{
rb_pgplot_mapimage( argc, argv, self, 0 );
return Qtrue;
}
/* PGGRAY -- gray-scale map of a 2D data array
pggray, array [, range, tr]
range : range of array value to be drawn
TR : transformation matrix.
*/
static VALUE
rb_pgplot_pggray( int argc, VALUE *argv, VALUE self )
{
rb_pgplot_mapimage( argc, argv, self, 1 );
return Qtrue;
}
/* PGCTAB -- install the color table to be used by PGIMAG
pgctab, l,r,g,b [,contra,bright]
l : An array of NC normalized ramp-intensity levels
corresponding to the RGB primary color intensities
in R(),G(),B(). Colors on the ramp are linearly
interpolated from neighbouring levels.
Levels must be sorted in increasing order.
0.0 places a color at the beginning of the ramp.
1.0 places a color at the end of the ramp.
Colors outside these limits are legal, but will
not be visible if CONTRA=1.0 and BRIGHT=0.5.
r,g,b : array of normalized red,green,blue intensities.
contra : The contrast of the color ramp (normally 1.0).
Negative values reverse the direction of the ramp.
bright : The brightness of the color ramp. This is normally 0.5
but can sensibly hold any value between 0.0 and 1.0.
*/
static VALUE
rb_pgplot_pgctab( int argc, VALUE *argv, VALUE self )
{
VALUE vl, vr, vg, vb, vcnt, vbrt;
VALUE l, r, g, b;
float contra=1.0, bright=0.5;
int n;
rb_scan_args(argc,argv, "42", &vl,&vr,&vg,&vb,&vcnt,&vbrt);
l = rb_pgplot_fltary( vl );
r = rb_pgplot_fltary( vr );
g = rb_pgplot_fltary( vg );
b = rb_pgplot_fltary( vb );
/* Optional Args */
if (vcnt!=Qnil) contra = NUM2INT(vcnt);
if (vbrt!=Qnil) bright = NUM2INT(vbrt);
n = min(NA_TOTAL(l),NA_TOTAL(r));
n = min(NA_TOTAL(g),n);
n = min(NA_TOTAL(b),n);
cpgctab( NA_PTR_FLT(l), NA_PTR_FLT(r), NA_PTR_FLT(g), NA_PTR_FLT(b),
n, contra, bright);
return Qtrue;
}
/* PGWEDG -- annotate an image plot with a wedge
pgwedg side, disp, width, fg, bg, label
side : The first character must be one of the characters
'B', 'L', 'T', or 'R' signifying the Bottom, Left,
Top, or Right edge of the viewport.
The second character should be 'I' to use PGIMAG
to draw the wedge, or 'G' to use PGGRAY.
disp : the displacement of the wedge from the specified
edge of the viewport, measured outwards from the
viewport in units of the character height. Use a
negative value to write inside the viewport, a
positive value to write outside.
width : The total width of the wedge including annotation,
in units of the character height.
fg : The value which is to appear with shade
1 ("foreground"). Use the values of FG and BG
that were supplied to PGGRAY or PGIMAG.
bg : the value which is to appear with shade
0 ("background").
label : Optional units label.
*/
/*
PGPIXL -- draw pixels
pgpixl, array [,x1,x2,y1,y2]
x1, y1 : world coordinates of one corner of the output region
x2, y2 : world coordinates of the opposite corner of the output region
*/
static VALUE
rb_pgplot_pgpixl( int argc, VALUE *argv, VALUE self )
{
VALUE na;
float x1, x2, y1, y2;
if (argc<1)
rb_raise(rb_eArgError, "wrong # of arguments (%d for 1 or 5)", argc);
na = rb_pgplot_intary(argv[0]);
if (NA_RANK(na) != 2)
rb_raise(rb_eArgError, "Image must be 2-D (N)Array");
if (argc==5) {
x1 = NUM2DBL(argv[1]);
x2 = NUM2DBL(argv[2]);
y1 = NUM2DBL(argv[3]);
y2 = NUM2DBL(argv[4]);
} else if (argc==1) {
x1 = 0;
x2 = NA_SHAPE0(na);
y1 = 0;
y2 = NA_SHAPE1(na);
} else
rb_raise(rb_eArgError, "wrong # of arguments (%d for 1 or 5)", argc);
cpgpixl( NA_PTR_INT(na), NA_SHAPE0(na), NA_SHAPE1(na),
1, NA_SHAPE0(na), 1, NA_SHAPE1(na),
x1, x2, y1, y2 );
return Qtrue;
}
/* PGQINF -- inquire PGPLOT general information
value = pgqinf item
item : character string defining the information
value : character string containing the requested information.
*/
static VALUE
rb_pgplot_pgqinf( VALUE obj, VALUE vitem )
{
int value_len=20;
char *item, *value;
item = STR2CSTR(vitem);
value = ALLOCA_N(char,value_len);
cpgqinf( item, value, &value_len );
return rb_str_new(value,value_len);
}
/* PGQDT -- inquire name of nth available device type
type, descr, inter = pgqdt [,ndev]
ndev : the number of the device type (1..maximum).
type : receives the character device-type code of the
Nth device type.
descr : receives a description of the device type.
inter : receives 1 if the device type is an interactive
one, 0 otherwise.
*/
static VALUE
rb_pgplot_pgqdt( int argc, VALUE *argv, VALUE self )
{
VALUE vdev;
int ndev=1, type_len=9, descr_len=65, inter;
char *type, *descr;
type = ALLOCA_N(char,type_len);
descr = ALLOCA_N(char,descr_len);
rb_scan_args(argc, argv, "01", &vdev);
if (vdev!=Qnil) ndev = NUM2INT(vdev);
cpgqdt( ndev, type, &type_len, descr, &descr_len, &inter );
return rb_ary_new3( 3, rb_str_new(type,type_len),
rb_str_new(descr,descr_len),
INT2NUM(inter) );
}
/* PGQTXT -- find bounding box of text string
xbox, ybox = pgqtxt(x,y,angle,fjust,text)
*/
static VALUE
rb_pgplot_pgqtxt(VALUE obj, VALUE x, VALUE y,
VALUE ang, VALUE fjust, VALUE text)
{
VALUE vx,vy;
int i;
float xbox[4], ybox[4];
char *txt = STR2CSTR(text);
cpgqtxt( NUM2DBL(x),NUM2DBL(y),NUM2DBL(ang),NUM2DBL(fjust),txt,
xbox, ybox );
vx = rb_ary_new2(4);
vy = rb_ary_new2(4);
for (i=0;i<4;i++) {
rb_ary_push(vx, rb_float_new(xbox[i]));
rb_ary_push(vy, rb_float_new(ybox[i]));
}
return rb_ary_new3(2,vx,vy);
}
/* Construct PgCursor-class instance */
static void pgcursor_init(VALUE obj, VALUE x, VALUE y, VALUE ch)
{
rb_ivar_set(obj, id_x, x);
rb_ivar_set(obj, id_y, y);
rb_ivar_set(obj, id_char, ch);
}
static VALUE pgcursor_initialize(int argc, VALUE *argv, VALUE obj)
{
VALUE x, y, ch;
rb_scan_args(argc,argv, "21", &x,&y,&ch);
pgcursor_init(obj,x,y,ch);
return Qnil;
}
static VALUE pgcursor_new(VALUE x, VALUE y, VALUE ch)
{
VALUE obj;
obj = rb_obj_alloc(cPgCursor);
pgcursor_init(obj,x,y,ch);
return obj;
}
static VALUE pgcursor_to_ary(VALUE obj)
{
return rb_ary_new3( 3, rb_ivar_get(obj, id_x),
rb_ivar_get(obj, id_y),
rb_ivar_get(obj, id_char) );
}
/*
PGCURS -- read cursor position
result = pgcurs([x,y])
PgCursorError is raised if some error occurs.
result : instance of PgCursor-class. Attrs are;
x : the world x-coordinate of the cursor.
y : the world y-coordinate of the cursor.
char : the character typed by the user;
nil if the device has no cursor or if some other error occurs.
*/
static VALUE
rb_pgplot_pgcurs( int argc, VALUE *argv, VALUE self )
{
float x, y, x2, y2;
char ch[2] = " ";
switch (argc) {
case 0:
cpgqwin(&x,&x2,&y,&y2);
x = (x+x2)/2;
y = (y+y2)/2;
break;
case 2:
x = NUM2DBL(argv[0]);
y = NUM2DBL(argv[1]);
break;
default:
rb_raise(rb_eArgError, "wrong # of arguments (%d for 0 or 2)", argc);
}
if (!cpgcurs(&x, &y, ch))
rb_raise(ePgCursorError, "failure in getting cursor position");
return pgcursor_new( rb_float_new(x), rb_float_new(y),
(ch==0) ? Qnil : rb_str_new(ch,1) );
}
/*
PGBAND -- read cursor position, with anchor
result = pgband( mode, [xref, yref, [x, y, [posn]]] )
PgCursorError is raised if some error occurs.
result : instance of PgCursor-class. see pgcurs.
*/
static VALUE
rb_pgplot_pgband( int argc, VALUE *argv, VALUE self )
{
int mode=0, posn=0;
float x, y, xr, yr;
char ch[2] = " ";
if (argc<5) {
cpgqwin(&x,&xr,&y,&yr);
xr = x = (x+xr)/2;
yr = y = (y+yr)/2;
}
switch (argc) {
case 6:
if (RTEST(argv[5])) {
if (argv[5]==Qtrue)
posn = 1;
else
posn = NUM2INT(argv[5]);
}
case 5:
x = NUM2DBL(argv[3]);
y = NUM2DBL(argv[4]);
case 3:
xr = NUM2DBL(argv[1]);
yr = NUM2DBL(argv[2]);
case 1:
mode = NUM2INT(argv[0]);
break;
default:
rb_raise(rb_eArgError, "wrong # of arguments (%d for 1/3/5)", argc);
}
if (!cpgband(mode, posn, xr, yr, &x, &y, ch))
rb_raise(ePgCursorError, "failure in getting cursor position");
return pgcursor_new( rb_float_new(x), rb_float_new(y),
(ch==0) ? Qnil : rb_str_new(ch,1) );
}
/*
PGOLIN -- mark a set of points using the cursor
result = pgolin( x, y, [sym, [npt]] )
x : NArray.sfloat of x-coordinates.
y : NArray.sfloat of y-coordinates.
sym : code number of symbol to use for marking entered points (see PGPT).
npt : number of points entered; should be zero on first call.
result: number of points entered.
*/
static VALUE
rb_pgplot_pgolin( int argc, VALUE *argv, VALUE self )
{
VALUE x, y, vsym, vnpt;
int sym=0, npt=0;
rb_scan_args(argc,argv, "22", &x,&y,&vsym,&vnpt);
if (vsym!=Qnil) sym = NUM2INT(vsym);
if (vnpt!=Qnil) npt = NUM2INT(vnpt);
if (NA_TYPE(x)!=NA_SFLOAT || NA_TYPE(y)!=NA_SFLOAT)
rb_raise(rb_eArgError, "Array must NArray.sfloat");
cpgolin( min(NA_TOTAL(x),NA_TOTAL(y)), &npt,
NA_PTR_FLT(x), NA_PTR_FLT(y), sym );
return INT2NUM(npt);
}
/*
PGNCUR -- mark a set of points using the cursor
result = pgncur( x, y, [sym, [npt]] )
x : NArray.sfloat of x-coordinates.
y : NArray.sfloat of y-coordinates.
sym : code number of symbol to use for marking entered points (see PGPT).
npt : number of points entered; should be zero on first call.
result: number of points entered.
*/
static VALUE
rb_pgplot_pgncur( int argc, VALUE *argv, VALUE self )
{
VALUE x, y, vsym, vnpt;
int sym=0, npt=0;
rb_scan_args(argc,argv, "22", &x,&y,&vsym,&vnpt);
if (vsym!=Qnil) sym = NUM2INT(vsym);
if (vnpt!=Qnil) npt = NUM2INT(vnpt);
if (NA_TYPE(x)!=NA_SFLOAT || NA_TYPE(y)!=NA_SFLOAT)
rb_raise(rb_eArgError, "Array must NArray.sfloat");
cpgncur( min(NA_TOTAL(x),NA_TOTAL(y)), &npt,
NA_PTR_FLT(x), NA_PTR_FLT(y), sym );
return INT2NUM(npt);
}
/*
PGLCUR -- PGLCUR -- draw a line using the cursor
result = pglcur( x, y, [npt] )
x : NArray.sfloat of x-coordinates.
y : NArray.sfloat of y-coordinates.
npt : number of points entered; should be zero on first call.
result: number of points entered.
*/
static VALUE
rb_pgplot_pglcur( int argc, VALUE *argv, VALUE self )
{
VALUE x, y, vnpt;
int npt=0;
rb_scan_args(argc,argv, "21", &x,&y,&vnpt);
if (vnpt!=Qnil) npt = NUM2INT(vnpt);
if (NA_TYPE(x)!=NA_SFLOAT || NA_TYPE(y)!=NA_SFLOAT)
rb_raise(rb_eArgError, "Array must NArray.sfloat");
cpglcur( min(NA_TOTAL(x),NA_TOTAL(y)), &npt,
NA_PTR_FLT(x), NA_PTR_FLT(y) );
return INT2NUM(npt);
}
void rb_scan_kw_args __((VALUE, ...));
/* PGTICK -- draw a single tick mark on an axis
pgtick( x1, y1, x2, y2, v, [str], {"tickl", "tickr", "disp", "orient"})
Example:
pgtick( 0,0,0,1, 0.5, "half", "tickr"=>1, "disp"=>2, "orient"=>90 )
Draw and label single tick mark on a graph axis. The tick mark is
a short line perpendicular to the direction of the axis (which is not
drawn by this routine). The optional text label is drawn with its
baseline parallel to the axis and reading in the same direction as
the axis (from point 1 to point 2). Current line and text attributes
are used.
Arguments:
X1, Y1 : world coordinates of one endpoint of the axis.
X2, Y2 : world coordinates of the other endpoint of the axis.
V : draw the tick mark at fraction V (0<=V<=1) along
the line from (X1,Y1) to (X2,Y2).
STR : text of label (may be blank).
Keyword Arguments:
TICKL : length of tick mark drawn to left of axis
(as seen looking from first endpoint to second), in
units of the character height.
TICKR : length of major tick marks drawn to right of axis,
in units of the character height.
DISP : displacement of label text to
right of axis, in units of the character height.
ORIENT : orientation of label text, in degrees; angle between
baseline of text and direction of axis (0-360 deg)
*/
static VALUE
rb_pgplot_pgtick( int argc, VALUE *argv, VALUE self )
{
char *str="";
VALUE val=Qnil;
VALUE x1, y1, x2, y2, v, vstr;
VALUE tickl, tickr, disp, orient;
if (argc>0 && TYPE(argv[argc-1]) == T_HASH)
val = argv[--argc];
rb_scan_kw_args( val, "tickl", &tickl, "tickr", &tickr,
"disp", &disp, "orient", &orient, 0);
rb_scan_args(argc,argv, "51", &x1,&y1, &x2,&y2, &v, &vstr);
if (tickl ==Qnil) tickl = INT2FIX(0);
if (tickr ==Qnil) tickr = INT2FIX(0);
if (disp ==Qnil) disp = INT2FIX(1);
if (orient==Qnil) orient= INT2FIX(0);
if (vstr !=Qnil) str = STR2CSTR(vstr);
cpgtick( NUM2DBL(x1),NUM2DBL(y1),NUM2DBL(x2),NUM2DBL(y2),
NUM2DBL(v), NUM2DBL(tickl),NUM2DBL(tickr),
NUM2DBL(disp), NUM2DBL(orient), str );
return Qnil;
}
/*
PGAXIS -- draw an axis
pgaxis( x1, y1, x2, y2, v1, v2,
{opt, step, nsub, tickl, tickr, frac, disp, orient} )
Example:
pgaxis( 1, 1, 9, 5, 0, 3, "tickl"=>1, "opt"=>"NL2" )
Draw a labelled graph axis from world-coordinate position (X1,Y1) to
(X2,Y2).
Normally, this routine draws a standard LINEAR axis with equal
subdivisions. The quantity described by the axis runs from V1 to V2;
this may be, but need not be, the same as X or Y.
If the 'L' option is specified, the routine draws a LOGARITHMIC axis.
In this case, the quantity described by the axis runs from 10**V1 to
10**V2. A logarithmic axis always has major, labeled, tick marks
spaced by one or more decades. If the major tick marks are spaced
by one decade (as specified by the STEP argument), then minor
tick marks are placed at 2, 3, .., 9 times each power of 10;
otherwise minor tick marks are spaced by one decade. If the axis
spans less than two decades, numeric labels are placed at 1, 2, and
5 times each power of ten.
If the axis spans less than one decade, or if it spans many decades,
it is preferable to use a linear axis labeled with the logarithm of
the quantity of interest.
Arguments:
x1, y1 : world coordinates of one endpoint of the axis.
x2, y2 : world coordinates of the other endpoint of the axis.
v1 : axis value at first endpoint.
v2 : axis value at second endpoint.
Keyword Argnuments:
opt : a string containing single-letter codes for
various options. The options currently
recognized are:
L : draw a logarithmic axis
N : write numeric labels
1 : force decimal labelling, instead of automatic
choice (see PGNUMB).
2 : force exponential labelling, instead of
automatic.
step : major tick marks are drawn at axis value 0.0 plus
or minus integer multiples of STEP. If STEP=0.0,
a value is chosen automatically.
nsub : minor tick marks are drawn to divide the major
divisions into NSUB equal subdivisions (ignored if
STEP=0.0). If NSUB <= 1, no minor tick marks are
drawn. NSUB is ignored for a logarithmic axis.
tickl : length of major tick marks drawn to left of axis
(as seen looking from first endpoint to second), in
units of the character height.
tickr : length of major tick marks drawn to right of axis,
in units of the character height.
frac : length of minor tick marks, as fraction of major.
disp : displacement of baseline of tick labels to
right of axis, in units of the character height.
orient : orientation of label text, in degrees; angle between
baseline of text and direction of axis (0-360
*/
static VALUE
rb_pgplot_pgaxis( int argc, VALUE *argv, VALUE self )
{
char *opt="";
float frac=0.5;
VALUE val=Qnil;
VALUE x1, y1, x2, y2, v1, v2;
VALUE vopt, step, nsub, tickl, tickr, vfrac, disp, orient;
if (argc>0 && TYPE(argv[argc-1]) == T_HASH)
val = argv[--argc];
rb_scan_kw_args( val,
"opt",&vopt, "step",&step, "nsub",&nsub,
"tickl",&tickl, "tickr",&tickr,
"frac",&vfrac, "disp",&disp, "orient",&orient, 0);
rb_scan_args(argc,argv, "60", &x1,&y1, &x2,&y2, &v1,&v2);
if (step ==Qnil) step = INT2FIX(0);
if (nsub ==Qnil) nsub = INT2FIX(0);
if (tickl ==Qnil) tickl = INT2FIX(0);
if (tickr ==Qnil) tickr = INT2FIX(0);
if (disp ==Qnil) disp = INT2FIX(1);
if (orient==Qnil) orient= INT2FIX(0);
if (vopt !=Qnil) opt = STR2CSTR(vopt);
if (vfrac !=Qnil) frac = NUM2DBL(vfrac);
cpgaxis( opt, NUM2DBL(x1),NUM2DBL(y1),NUM2DBL(x2),NUM2DBL(y2),
NUM2DBL(v1),NUM2DBL(v2),NUM2DBL(step),NUM2INT(nsub),
NUM2DBL(tickl),NUM2DBL(tickr), frac,
NUM2DBL(disp), NUM2DBL(orient) );
return Qnil;
}
/*--- auto-generated funcs will be placed here ---*/
void
Init_pgplot()
{
mPgplot = rb_define_module("Pgplot");
/* The C application programming interface */
rb_define_module_function(mPgplot, "pgopen", rb_pgplot_pgopen,-1);
rb_define_module_function(mPgplot, "pgbeg", rb_pgplot_pgbeg, -1);
rb_define_module_function(mPgplot, "pgenv", rb_pgplot_pgenv, -1);
rb_define_module_function(mPgplot, "pgask", rb_pgplot_pgask, -1);
rb_define_module_function(mPgplot, "pgline", rb_pgplot_pgline, 2);
rb_define_module_function(mPgplot, "pgpoly", rb_pgplot_pgpoly, 2);
rb_define_module_function(mPgplot, "pgpt", rb_pgplot_pgpt, -1);
rb_define_module_function(mPgplot, "pgpnts", rb_pgplot_pgpnts, 3);
rb_define_module_function(mPgplot, "pgbin", rb_pgplot_pgbin, -1);
rb_define_module_function(mPgplot, "pghist", rb_pgplot_pghist, -1);
rb_define_module_function(mPgplot, "pgerrb", rb_pgplot_pgerrb, -1);
rb_define_module_function(mPgplot, "pgerrx", rb_pgplot_pgerrx, -1);
rb_define_module_function(mPgplot, "pgerry", rb_pgplot_pgerry, -1);
rb_define_module_function(mPgplot, "pgcont", rb_pgplot_pgcont, -1);
rb_define_module_function(mPgplot, "pgcons", rb_pgplot_pgcons, -1);
rb_define_module_function(mPgplot, "pgconb", rb_pgplot_pgconb, -1);
rb_define_module_function(mPgplot, "pgconf", rb_pgplot_pgconf, -1);
rb_define_module_function(mPgplot, "pgconl", rb_pgplot_pgconl, -1);
rb_define_module_function(mPgplot, "pgvect", rb_pgplot_pgvect, -1);
rb_define_module_function(mPgplot, "pgimag", rb_pgplot_pgimag, -1);
rb_define_module_function(mPgplot, "pggray", rb_pgplot_pggray, -1);
rb_define_module_function(mPgplot, "pgctab", rb_pgplot_pgctab, -1);
rb_define_module_function(mPgplot, "pgpixl", rb_pgplot_pgpixl, -1);
rb_define_module_function(mPgplot, "pgqinf", rb_pgplot_pgqinf, 1);
rb_define_module_function(mPgplot, "pgqdt", rb_pgplot_pgqdt, -1);
rb_define_module_function(mPgplot, "pgqtxt", rb_pgplot_pgqtxt, 5);
rb_define_module_function(mPgplot, "pgcurs", rb_pgplot_pgcurs, -1);
rb_define_module_function(mPgplot, "pgband", rb_pgplot_pgband, -1);
rb_define_module_function(mPgplot, "pgolin", rb_pgplot_pgolin, -1);
rb_define_module_function(mPgplot, "pgncur", rb_pgplot_pgncur, -1);
rb_define_module_function(mPgplot, "pglcur", rb_pgplot_pglcur, -1);
rb_define_module_function(mPgplot, "pgtick", rb_pgplot_pgtick, -1);
rb_define_module_function(mPgplot, "pgaxis", rb_pgplot_pgaxis, -1);
/*--- auto-generated defs will be placed here ---*/
rb_set_end_proc((void(*)(VALUE))(cpgend), Qnil);
id_beg = rb_intern("begin");
id_end = rb_intern("end");
id_x = rb_intern("@x");
id_y = rb_intern("@y");
id_char = rb_intern("@char");
/*--- PgCursor ---*/
cPgCursor = rb_define_class_under(mPgplot, "PgCursor", rb_cObject);
rb_define_method(cPgCursor, "initialize", pgcursor_initialize, -1);
rb_define_method(cPgCursor, "to_ary", pgcursor_to_ary, 0);
rb_attr(cPgCursor, rb_intern("x"), 1, 0, Qtrue);
rb_attr(cPgCursor, rb_intern("y"), 1, 0, Qtrue);
rb_attr(cPgCursor, rb_intern("char"), 1, 0, Qtrue);
ePgCursorError = rb_define_class("PgCursorError", rb_eStandardError);
}