"Fossies" - the Fresh Open Source Software Archive

Member "fityk-1.3.1/samples/hello.rb" (13 May 2016, 1014 Bytes) of package /linux/misc/fityk-1.3.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Ruby source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/usr/bin/env ruby
    2 
    3 # Example of using libfityk from ruby.
    4 # To run this example, you need fityk extension for Ruby: after compiling
    5 # fityk go to src/, run "make ruby" and copy swig/fityk.so.
    6 
    7 require 'fityk'
    8 
    9 class GaussianFitter < Fityk::Fityk
   10     def initialize(filename)
   11         super()
   12         raise "File `#{filename}' not found." unless File::exists? filename
   13         @filename = filename
   14         execute("@0 < '#{filename}'")
   15         puts "Data info: " + get_info("data", 0)
   16     end
   17 
   18     def run()
   19         execute("guess %gauss = Gaussian")
   20         puts "Fitting #{@filename}..."
   21         execute("fit")
   22         puts "WSSR=%g" % get_wssr()
   23         puts "Gaussian center: %.5g" % calculate_expr("%gauss.center")
   24     end
   25 
   26     def save_session(filename)
   27         execute("info state >'%s'" % filename)
   28     end
   29 end
   30 
   31 f = Fityk::Fityk.new
   32 puts f.get_info("version")
   33 puts "ln(2) = %.9f" % f.calculate_expr("ln(2)")
   34 f = nil
   35 
   36 gauss = GaussianFitter.new("nacl01.dat")
   37 gauss.run()
   38 gauss.save_session("tmp_save.fit")
   39