Top Level Namespace

Defined Under Namespace

Modules: Pgplot Classes: PgCursorError

Instance Method Summary collapse

Instance Method Details

#cogen_pgplotObject



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'ext/cogen.rb', line 142

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

#find_cmd(a) ⇒ Object



23
24
25
26
27
28
29
30
# File 'ext/build_lib/makefile.rb', line 23

def find_cmd(a)
  a.each do |cmd|
    if system("which #{cmd}")
      return cmd
    end
  end
  raise "No FORTRAN compiler found in: [#{a.join(' ')}]"
end

#find_dir_in_gemspecObject



40
41
42
43
44
45
46
47
48
49
# File 'ext/extconf.rb', line 40

def find_dir_in_gemspec
  begin
    require 'rubygems'
    if gemspec=Gem::Specification.find_by_path('narray')
      return File.join(gemspec.full_gem_path, gemspec.require_path)
    end
  rescue
  end
  nil
end

#find_dir_w_file(d, h) ⇒ Object

Otherwise you can also specify:

--with-opt-dir=path
--with-opt-include=path
--with-opt-lib=path


35
36
37
38
# File 'ext/extconf.rb', line 35

def find_dir_w_file(d,h)
  g = Dir.glob(RbConfig.expand(d+"/"+h))
  File.dirname(g.last) if g and !g.empty?
end

#pgfuncgen(name, inp, out) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'ext/cogen.rb', line 95

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","StringValuePtr"]
  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(",")+")"
  else
    retn = retn.join("")
  end

  vars = vars.join("")
  prot = prot.join(",")
  pass = pass.join(",")

  return "
static VALUE
  rb_pgplot_#{name}(#{prot})
{
  #{vars}
  c#{name}(#{pass});
  return #{retn};
}
"
end