topas-tools 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 987df3ec3a644e10544cc624319256d6cae2db0d
4
- data.tar.gz: 452e747ae4ab2be232b55c68b6d11582341f5046
3
+ metadata.gz: ebd3b0096d76533b4ad2b3b29d13e9c0fb440ec2
4
+ data.tar.gz: 3f9822ab33d2135dda7593b0d7fcea801feef74f
5
5
  SHA512:
6
- metadata.gz: f9ab976c9b4e1118b8ea2d49e547e58d8fee48f3bf23bac7b4de838191d739e0eaba5db9c2ffac090fe1e9daa2102cf3257a9d3b342400ae9dbe616ff1301fe3
7
- data.tar.gz: cb1b3808929fd8e51f68abe5d6ae90fa805aadae4ff3b50042ab1673d898263ef57b8f2f7ba12238552e3dbb836d569b886c7721e60cfced5c0ad14e35217b87
6
+ metadata.gz: 391701df3da48ef07f27893af04a5aa73deaad6bfc4782b5691d9e2991e861fb1da4b153ecdab7d5be71448f7f61a1eb8976ab29b7d94ba691277dc89b35fdd1
7
+ data.tar.gz: 2175813c9d94dcd5593b8796d4229607a63aedb09bc3e5adf280e0256651b80dedb7d820e6b9bf2bebc6d2d1a8db2209cb0b8ba69190700354f672931e5937fb
data/bin/toparunGUI CHANGED
@@ -18,7 +18,7 @@ Shoes.app :width => 400, :height => 800 do
18
18
  #big stack
19
19
  stack do
20
20
  caption 'Your system:'
21
- @systemlist = list_box items:['wine','windows','dummy'], choose:'wine'
21
+ @systemlist = list_box items:['wine','windows','dummy'], choose:'windows'
22
22
 
23
23
  caption 'Your Topas4-2 directory:'
24
24
 
@@ -39,7 +39,7 @@ Shoes.app :width => 400, :height => 800 do
39
39
  end
40
40
 
41
41
  flow do
42
- para "Points:"
42
+ para "Stepss:"
43
43
  @stepsline = edit_line
44
44
  @stepsline.text = "4,1"
45
45
  end
@@ -51,26 +51,25 @@ Shoes.app :width => 400, :height => 800 do
51
51
  end
52
52
  end
53
53
 
54
- button 'Mf button!' do
55
- begin
56
- points = @pointline.text.split(/[,\s]+/).map(&:to_f)
57
- steps = @stepsline.text.split(/[,\s]+/).map(&:to_f)
58
- rescue alert("Some issues with steps'n'points!")
59
- end
60
-
61
- Thread.new(points, steps, @log ) do |points, steps|
62
- inp = @inpline.text
63
- TopasEngine.system = @systemlist.text.to_sym
64
- TopasEngine.topasdir = @topasdir.text
65
- runner = TopasEngine.new File.dirname(inp)
66
- input = TopasInput.new IO.read(inp, :encoding => "UTF-8"), inp
67
- runner.refine input, points, steps, BaseAnalyzer.new(@log)
68
- @clear = button 'Clear' do
69
- @log = StringIO.new
70
- @clear.clear
71
- end
54
+ button 'Go!' do
55
+ begin
56
+ points = @pointline.text.split(/[,\s]+/).map(&:to_f)
57
+ steps = @stepsline.text.split(/[,\s]+/).map(&:to_f)
58
+ rescue alert("Some issues with steps'n'points!")
59
+ end
60
+
61
+ Thread.new(points, steps, @log ) do |points, steps|
62
+ inp = @inpline.text
63
+ engine = TopasEngine.create @systemlist.text.to_sym, @topasdir.text
64
+ input = TopasInput.new IO.read(inp, :encoding => "UTF-8"), inp
65
+ runner = Metarefine.new engine, input, File.dirname(inp), Steps.new(points, steps)
66
+ runner.toparun BaseAnalyzer.new(@log)
67
+ @clear = button 'Clear' do
68
+ @log = StringIO.new
69
+ @clear.clear
72
70
  end
73
71
  end
72
+ end
74
73
 
75
74
  para self
76
75
  caption "Log:"
data/lib/topas-tools.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  require 'topas-tools/TopasEngine.rb'
2
2
  require 'topas-tools/TopasInput.rb'
3
3
  require 'topas-tools/Analyzers.rb'
4
+ require 'topas-tools/Metarefine.rb'
@@ -0,0 +1,36 @@
1
+ class Steps
2
+ def initialize ps, ss
3
+ ss.empty? && raise("Empty steps!")
4
+ (ps.size == (ss.size + 1) ) || raise("Inconsistent points and steps: #{ps}, #{ss}")
5
+ @k1s = get_k1s ps, ss
6
+ end
7
+ attr_reader :k1s
8
+ def get_k1s points, stepsizes
9
+ stepsizes.reduce([]){|result, stepsize|
10
+ a = result +
11
+ points[0].step(points[1] ,-stepsize.to_f).to_a +
12
+ [points[1].to_f]
13
+ points.shift
14
+ a}.uniq
15
+ end
16
+ end
17
+
18
+ class Metarefine
19
+ def initialize engine, input, basedir, steps
20
+ @engine = engine
21
+ @input = input
22
+ @basedir = basedir
23
+ @steps = steps
24
+ Dir.chdir @basedir
25
+ end
26
+
27
+ def toparun analyzer, work_dir = File.expand_path(@input.base_name)
28
+ Dir.mkdir(work_dir) unless Dir.exists? work_dir
29
+ @steps.k1s.reduce(@input) do |inp, k1|
30
+ out = @engine.tc work_dir inp.set_k1(k1)
31
+ analyzer.analyze(out) ? out : break
32
+ end
33
+ Dir.chdir @base_dir
34
+ analyzer.report
35
+ end
36
+ end
@@ -1,79 +1,56 @@
1
1
  class TopasEngine
2
-
3
- Systems = [:windows, :wine, :dummy]
4
-
5
- @@topasdir = "/home/dmitrienka/.wine/drive_c/TOPAS4-2/" #Depends!
6
- @@system = :dummy #[:wine, : :windows, :dummy]
7
-
8
-
9
- def self.system=(system)
10
- if Systems.any?{|sys| sys = system}
11
- @@system = system
2
+ def self.create system, topasdir
3
+ case system
4
+ when :wine
5
+ WineTopasEngine.new topasdir
6
+ when :windows
7
+ WindowsTopasEngine.new topasdir
8
+ when :dummy
9
+ TopasEngine.new topasdir
12
10
  else
13
- raise "Unknown system!"
11
+ raise "Bad system: #{system}"
14
12
  end
15
13
  end
16
-
17
- def self.topasdir=(topasdir)
14
+
15
+ def initialize topasdir
16
+ @enc = 'UTF-8'
18
17
  Dir.exists?(topasdir) || raise("Non-existing directory!")
19
18
  Dir.entries(topasdir).any?{|f| f == 'tc.exe'} || raise("Where is my tc.exe?!")
20
- @@topasdir = topasdir
21
- end
22
-
23
-
24
- def initialize dir = Dir.getwd
25
- @base_dir = dir
26
- Dir.chdir @base_dir
27
- @enc = "UTF-8"
19
+ @topasdir = topasdir
28
20
  end
29
21
 
30
- def tc input
22
+ def tc dir, input
31
23
  infile = "#{input.name}.inp"
24
+ Dir.chdir dir
32
25
  File.open(infile, mode:'w'){|f| f.write input.text}
33
- case @@system
34
- when :wine
35
- path = `winepath -w #{infile}`.gsub('\\', '\\\\\\').gsub("\n", "")
36
- command = "wine tc.exe #{path}"
37
- go_n_do command
38
- when :windows
39
- command = "tc.exe #{File.expand_path(infile)}"
40
- go_n_do command
41
- when :dummy
42
- outfile = "#{input.name}.out"
43
- p "Say hello to #{outfile} with k1 = #{input.k1}"
44
- File.open(outfile , mode:'w'){|f| f.write input.text}
45
- end
26
+ cmd = command infile
27
+ Dir.chdir @topasdir
28
+ system(cmd)
29
+ Dir.chdir dir
46
30
  TopasInput.new IO.read("#{input.name}.out", :encoding => @enc)
47
31
  end
48
-
49
32
 
50
- def refine input, ps, ss, analyzer = BaseAnalyzer.new
51
- k1s = get_k1s ps, ss
52
- name = input.base_name
53
- Dir.mkdir(name) unless Dir.exists? name
54
- @work_dir = File.expand_path(name)
55
- Dir.chdir @work_dir
56
- k1s.reduce(input) do |inp, k1|
57
- out = tc inp.set_k1(k1)
58
- analyzer.analyze(out) ? out : break
59
- end
60
- Dir.chdir @base_dir
61
- analyzer.report
33
+ private
34
+
35
+ def command filename
36
+ filepath = File.expand_path filename
37
+ dirpath = File.dirname filepath
38
+ outfile = File.join dirpath, filename.sub(/\..{2,3}$/ , '.out')
39
+ "cp #{filepath} #{outfile}"
62
40
  end
41
+ end
63
42
 
43
+ class WindowsTopasEngine < TopasEngine
64
44
  private
65
-
66
- def go_n_do command
67
- Dir.chdir @@topasdir
68
- system(command)
69
- Dir.chdir @work_dir
45
+ def command infile
46
+ "tc.exe #{File.expand_path(infile)}"
70
47
  end
48
+ end
71
49
 
72
- def get_k1s points, stepsizes
73
- stepsizes.inject([]){|result, stepsize|
74
- a = result + points[0].step(points[1] ,-stepsize).to_a
75
- points.shift
76
- a}.uniq
50
+ class WineTopasEngine < TopasEngine
51
+ private
52
+ def command infile
53
+ path = `winepath -w #{infile}`.gsub('\\', '\\\\\\').gsub("\n", "")
54
+ "wine tc.exe #{path}"
77
55
  end
78
-
79
56
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: topas-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artem Dmitrienko
@@ -42,6 +42,7 @@ files:
42
42
  - bin/toparunGUI
43
43
  - lib/topas-tools.rb
44
44
  - lib/topas-tools/Analyzers.rb
45
+ - lib/topas-tools/Metarefine.rb
45
46
  - lib/topas-tools/TopasEngine.rb
46
47
  - lib/topas-tools/TopasInput.rb
47
48
  homepage: https://github.com/dmitrienka/topas-tools