module Rongo
Public Instance Methods
angle(x)
click to toggle source
# File lib/rongo.rb, line 520 def angle(x) @@textangle = x.to_f end
arraydata(id, a)
click to toggle source
# File lib/rongo.rb, line 217 def arraydata(id, a) @@coldata[id] = a end
box(*args)
click to toggle source
BOX commmad – box XOPT YOPT works as wrapper for PGPLOT PGBOX. The arguments are different from that of MONGO box command.
Options (for parameters XOPT and YOPT): A : draw Axis (X axis is horizontal line Y=0, Y axis is vertical line X=0). B : draw bottom (X) or left (Y) edge of frame. C : draw top (X) or right (Y) edge of frame. G : draw Grid of vertical (X) or horizontal (Y) lines. I : Invert the tick marks; ie draw them outside the viewport instead of inside. L : label axis Logarithmically (see below). N : write Numeric labels in the conventional location below the viewport (X) or to the left of the viewport (Y). P : extend ("Project") major tick marks outside the box (ignored if option I is specified). M : write numeric labels in the unconventional location above the viewport (X) or to the right of the viewport (Y). T : draw major Tick marks at the major coordinate interval. S : draw minor tick marks (Subticks). V : orient numeric labels Vertically. This is only applicable to Y. The default is to write Y-labels parallel to the axis. 1 : force decimal labelling, instead of automatic choice (see PGNUMB). 2 : force exponential labelling, instead of automatic.
# File lib/rongo.rb, line 383 def box(*args) print "box called\n" if $DEBUG p @@limitval if $DEBUG if args.size == 2 @@limitval[4] = args[0] @@limitval[5] = args[1] end p @@limitval if $DEBUG # pgenv(@@limitval[0],@@limitval[1],@@limitval[2], # @@limitval[3],@@limitval[4],@@limitval[5]) pgswin @@limitval[0],@@limitval[1],@@limitval[2],@@limitval[3] p @@limitval[4], 0, 0, @@limitval[5], 0, 0 if $DEBUG pgbox @@limitval[4], 0, 0, @@limitval[5], 0, 0 setvwscalesbase setvwscales end
btype(xopt, yopt)
click to toggle source
# File lib/rongo.rb, line 353 def btype (xopt, yopt) @@limitval[4] = xopt @@limitval[5] = yopt end
col(name, colloc)
click to toggle source
# File lib/rongo.rb, line 143 def col(name, colloc) colloc -= 1 loc = @@validcolnames.index(name) if loc == nil senderror("Col name #{name} not valid for col") else infile = open(@@datafilename, "r") line = 0 if @@rongolines0 > 0 while (line < @@rongolines0-1) && (infile.gets) line += 1 end end @@coldata[loc].clear while (s = infile.gets) && ((@@rongolines1 <0)||(line < @@rongolines1)) val = s.split[colloc] p val if $DEBUG @@coldata[loc].push(val.to_f) if val line += 1 end end end
color(c)
click to toggle source
# File lib/rongo.rb, line 505 def color(c) pgsci c end
connect()
click to toggle source
MONGO connect
# File lib/rongo.rb, line 402 def connect pgline @@coldata[0], @@coldata[1] end
convert_to_good_ruby(filename)
click to toggle source
translate rongo script file to ruby script file.
# File lib/rongo.rb, line 339 def convert_to_good_ruby(filename) ruby_filename = get_tmpdir + "/." +File.basename(filename); print "Tmp file name = ", ruby_filename, "\n" if $DEBUG infile=open(filename, "r") outfile=open(ruby_filename, "w+") while s = infile.gets outfile.print convert_to_good_ruby_string(s) end infile.close outfile.close system("cat "+ ruby_filename) if $DEBUG ruby_filename end
convert_to_good_ruby_string(s)
click to toggle source
translate rongo script line to ruby script line
# File lib/rongo.rb, line 298 def convert_to_good_ruby_string(s) print "convert_to_good_ruby_string input: ", s, "\n" if $DEBUG a = s.split commandname = a[0] candidate = [] return s if a.size == 0 @@rongocommands.each do |x| candidate.push(x) if x.index(commandname) == 0 and commandname.size > 1 end if candidate.size > 1 x = candidate.join(", ") ss = "command \"#{commandname}\" ambiguous, possible name = \"#{x}\"" senderror ss elsif candidate.size == 1 commandname = candidate[0] end if @@rongospecialcommandsmultiargs.index(commandname) joinseperater = '", "' firstandend = '"' elsif @@rongospecialcommands.index(commandname) joinseperater = ' ' firstandend = '"' elsif @@rongocommands.index(commandname) joinseperater = ', ' firstandend = '' end if @@rongocommands.index(commandname) unless a[1] =~ /^"/ s = commandname s += " "+firstandend + a[1..a.size].join(joinseperater) + firstandend if a.size >1 s += "\n" end end print "convert_to_good_ruby_string result: ", s, "\n" if $DEBUG s end
data(x)
click to toggle source
# File lib/rongo.rb, line 118 def data (x) if File.exist?(x) @@datafilename = x print "data file name set to ", @@datafilename, "\n" if $DEBUG else senderror "data command requested non-existing file #{x}" end end
dot()
click to toggle source
MONGO dot
# File lib/rongo.rb, line 440 def dot # Rongo.setvwscales putregularpolygon @@cposx, @@cposy, 1.0, @@rongopointtype[0],@@rongopointtype[1] # pgpt1 @@cposx, @@cposy, @@rongopointtype end
draw(x,y)
click to toggle source
# File lib/rongo.rb, line 527 def draw (x,y) pgdraw x, y @@cposx = x @@cposy = y end
dumpdata()
click to toggle source
# File lib/rongo.rb, line 237 def dumpdata p @@coldata p @@limitval end
erase()
click to toggle source
# File lib/rongo.rb, line 454 def erase pgeras end
expand(x)
click to toggle source
MONGO expand
# File lib/rongo.rb, line 477 def expand(x) Pgplot.pgsch x setvwscales end
fcolumn(name, expression)
click to toggle source
# File lib/rongo.rb, line 166 def fcolumn(name, expression) loc = @@validcolnames.index(name) if loc == nil senderror("Col name #{name} not valid for col") else infile = open(@@datafilename, "r") line = 0 if @@rongolines0 > 0 while (line < @@rongolines0-1) && (infile.gets) line += 1 end end @@coldata[loc].clear while (s = infile.gets) && ((@@rongolines1 <0)||(line < @@rongolines1)) a=s.split if a[0]!= '#' string="" a.each_index{|i| string += "c#{i+1}=#{a[i].to_f};" } @@coldata[loc].push(eval(string+expression)) end line += 1 end end end
fformula(name, expression)
click to toggle source
# File lib/rongo.rb, line 192 def fformula(name, expression) loc = @@validcolnames.index(name) if loc == nil senderror("Col name #{name} not valid for col") else a=[]; @@coldata[loc].each_index{|i| x=@@coldata[0][i]; y=@@coldata[1][i]; a.push(eval(expression)); } @@coldata[loc]=a; end end
get_tmpdir()
click to toggle source
# File lib/rongo.rb, line 136 def get_tmpdir tmpdir = ENV["TMP"] tmpdir = ENV["TMPDIR"] unless tmpdir tmpdir = "/tmp" unless tmpdir tmpdir end
justification(s)
click to toggle source
# File lib/rongo.rb, line 508 def justification(s) if s == "center" then @@justification = 0.5 elsif s == "left" then @@justification = 0.0 elsif s == "right" then @@justification = 1.0 else @@justification = s.to_f end end
label(s)
click to toggle source
# File lib/rongo.rb, line 523 def label(s) pgptxt @@cposx, @@cposy, @@textangle, @@justification, s end
limits(*xyval)
click to toggle source
# File lib/rongo.rb, line 244 def limits(*xyval) if xyval.size < 4 if xyval.size > 0 print "limit: only #{xyval.size} args specified, all ignored \n" end xyval[0]=@@coldata[0].min xyval[1]=@@coldata[0].max xyval[2]=@@coldata[1].min xyval[3]=@@coldata[1].max end @@limitval[0..3] = xyval end
lines(*minmax)
click to toggle source
# File lib/rongo.rb, line 257 def lines(*minmax) @@rongolines0 = minmax[0] if minmax.size>0 @@rongolines1 = minmax[1] if minmax.size>1 end
logarithm(id)
click to toggle source
# File lib/rongo.rb, line 207 def logarithm(id) @@coldata[id].collect!{ |x| x=Math.log10(x)} end
ltype(t)
click to toggle source
# File lib/rongo.rb, line 498 def ltype(t) pgsls t end
lwidth(w)
click to toggle source
# File lib/rongo.rb, line 502 def lwidth(w) pgslw w end
points()
click to toggle source
MONGO points this function calls putregularpolygon for each
coordinates point to draw points, to achive the compatibility with MONGO. PGPLOT pgpt works differently, but may be faster in some cases.
# File lib/rongo.rb, line 428 def points # Rongo.setvwscales pgbbuf for i in 0...@@coldata[0].size putregularpolygon @@coldata[0][i], @@coldata[1][i], 1.0, @@rongopointtype[0],@@rongopointtype[1] end pgebuf # pgpt @@coldata[0], @@coldata[1], @@rongopointtype end
printer(pp = "pgplot.ps/vcps")
click to toggle source
# File lib/rongo.rb, line 485 def printer(pp = "pgplot.ps/vcps") # Removing the next line and writing pgopen pp resulted # in the following internal error message #: [BUG] unknown node type 0 #ruby 1.8.1 (2003-12-25) [i686-linux] # #Abort xx = pp @@rongoprinterfilename=xx.split("/")[0] print @@rongoprinterfilename pgopen xx end
psfix(filename = nil)
click to toggle source
# File lib/rongo.rb, line 533 def psfix(filename = nil) filename = @@rongoprinterfilename unless filename f = open(filename, "r") text = f.gets(nil) f.close bbox = nil text.each{ |s| bbox = s if s =~ /^%%BoundingBox/} p bbox if $DEBUG f=open(filename, "w+") text.each do |s| if s =~ /^%%BoundingBox/ f.print bbox else f.print s end end f.close end
ptype(*x)
click to toggle source
MONGO ptype
# File lib/rongo.rb, line 407 def ptype(*x) if x.size == 2 @@rongopointtype = x elsif x.size == 1 @@rongopointtype[0] = (x[0]/10).to_i @@rongopointtype[1] = x[0]%10 else p x.size if $DEBUG p x.join(" ") if $DEBUG if x.size > 2 senderror "ptype: too many args #{x}" else senderror "ptype: no args given. Two required" end end end
putregularpolygon(x,y,rview,n,type)
click to toggle source
# File lib/rongo.rb, line 70 def putregularpolygon(x,y,rview,n,type) # # type is mongo point type # 0 = open # 1 = skeletal (center connected to vertices) # 2 = starred # 3 = solid px=[] py=[] if $DEBUG print "polygon " print x, " " print y, " " print rview, " ",n, " ", type, "\n" end theta = (@@textangle+90)/360*2* Math::PI dt = 2* Math::PI/n for i in 0..n if type == 1 px.push(x); py.push(y); elsif type == 2 thetah = theta-dt/2 scale = rview*@@rongostarscale px.push( x+Math.cos(thetah)*scale*@@rongovwscales[0]) py.push( y+Math.sin(thetah)*scale*@@rongovwscales[1]) end px.push(x+Math.cos(theta)*rview*@@rongovwscales[0]) py.push(y+Math.sin(theta)*rview*@@rongovwscales[1]) theta += dt end if type == 3 pgpoly px, py else pgline px, py end end
quit()
click to toggle source
quit – replacement for MONGO end
# File lib/rongo.rb, line 449 def quit pgend exit end
relocate(x,y)
click to toggle source
MONGO relocate
# File lib/rongo.rb, line 469 def relocate(x,y) @@cposx = x @@cposy = y pgmove x, y end
rongo(fname)
click to toggle source
# File lib/rongo.rb, line 586 def rongo(fname) if fname @@rongo_batch_mode = 1 s = convert_to_good_ruby(fname) system("cat "+s) if $DEBUG load s, false File.delete(s) else rongo_interactive end end
rongo_interactive()
click to toggle source
# File lib/rongo.rb, line 568 def rongo_interactive print "Entering interactive mode\n" stty_save = %x`stty -g`.chomp begin while s = Readline.readline("* ",true) s= convert_to_good_ruby_string(s) begin eval s rescue rongo_interactive_showerror(s,$!) end end rescue Interrupt system("stty", stty_save) exit end end
rongo_interactive_showerror(s,x)
click to toggle source
# File lib/rongo.rb, line 553 def rongo_interactive_showerror(s,x) p x if $DEBUG if x.kind_of? NameError print 'Unknown command "', s.chomp, "\"\n" elsif x.kind_of? ArgumentError errm = x.to_s errm = errm[errm.index("'")+1,errm.size] print'Command "', s.chomp, '"', " failed, ", errm, "\n" else print 'Command "', s.chomp, '"', " failed, ",x , "\n" end end
senderror(str)
click to toggle source
# File lib/rongo.rb, line 109 def senderror(str) if @@rongo_batch_mode == 1 raise str else print str, "\n" end end
setnormalcommands()
click to toggle source
# File lib/rongo.rb, line 46 def setnormalcommands @@rongocommands = @@rongospecialcommandsmultiargs + @@rongospecialcommands + @@rongonormalcommands end
setvwscales()
click to toggle source
# File lib/rongo.rb, line 61 def setvwscales x = pgqch/40.0 for i in 0..1 j=i*2 k=j+1 @@rongovwscales[i] = @@rongovwscalesbase[i]*x end end
setvwscalesbase()
click to toggle source
# File lib/rongo.rb, line 51 def setvwscalesbase v = pgqvp(1) w = pgqwin for i in 0..1 j=i*2 k=j+1 @@rongovwscalesbase[i] = (w[j]-w[k])/(v[j]-v[k]) @@rongovwscales[i]= - @@rongovwscalesbase[i] end end
squareview()
click to toggle source
# File lib/rongo.rb, line 264 def squareview x= pgqvp(1) p x if $DEBUG dx = x[1]-x[0] dy = x[3]-x[2] x[0]=x[2]=[x[0],x[2]].max x[1]=x[3]=[x[1],x[3]].min p x if $DEBUG pgvsiz x[0], x[1], x[2], x[3] end
terminal(x = "/xserve")
click to toggle source
# File lib/rongo.rb, line 482 def terminal(x = "/xserve") pgopen x end
viewport(*args)
click to toggle source
# File lib/rongo.rb, line 275 def viewport(*args) print "box called with ", args.join(" "), "\n" if $DEBUG if args.size == 4 xold = Pgplot.pgqvp(1) print "old viewport = " if $DEBUG p xold if $DEBUG x= [] x[0] = xold[0]+ args[0]*(xold[1]-xold[0]) x[1] = xold[0]+ args[1]*(xold[1]-xold[0]) x[2] = xold[2]+ args[2]*(xold[3]-xold[2]) x[3] = xold[2]+ args[3]*(xold[3]-xold[2]) Pgplot.pgvsiz x[0], x[1], x[2], x[3] print "new viewport = " if $DEBUG xold = Pgplot.pgqvp(1) if $DEBUG p xold if $DEBUG else senderror "viewport requres 4 args, #{args.size} supplied" end end
writebuffer(x = "tmprongo.rb")
click to toggle source
# File lib/rongo.rb, line 128 def writebuffer (x = "tmprongo.rb") if File.exist?(x) senderror "writebuffer: file #{x} exists" end f=open(x,"w+") f.print Readline::HISTORY.to_a.join("\n"), "\n" f.close end
xcolumn(c)
click to toggle source
# File lib/rongo.rb, line 231 def xcolumn(c) col "x", c end
xdata(a)
click to toggle source
# File lib/rongo.rb, line 220 def xdata(a) arraydata(0,a) end
xlabel(s)
click to toggle source
MONGO xlabel
# File lib/rongo.rb, line 459 def xlabel(s) pglab s, "", "" end
xlogarithm()
click to toggle source
# File lib/rongo.rb, line 210 def xlogarithm logarithm(0) end
ycolumn(c)
click to toggle source
# File lib/rongo.rb, line 234 def ycolumn(c) col "y", c end
ydata(a)
click to toggle source
# File lib/rongo.rb, line 223 def ydata(a) arraydata(1,a) end
ylabel(s)
click to toggle source
MONGO ylabel
# File lib/rongo.rb, line 464 def ylabel(s) pglab "", s, "" end
ylogarithm()
click to toggle source
# File lib/rongo.rb, line 213 def ylogarithm logarithm(1) end