mesa_cli 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +11 -0
  3. data/bin/mesa +107 -1
  4. metadata +3 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8a87a95b5be58fbec4ee71ba7063bfa8dc140a9c
4
- data.tar.gz: bea773bce1823aa9bc9b5f148d37709a453fed51
3
+ metadata.gz: 24acf53efdea5f730721936a3e65e7fb29eb7418
4
+ data.tar.gz: 2d2ae1dcd9246f44e7023aa7289d4fa94370f2ec
5
5
  SHA512:
6
- metadata.gz: 0682d0de88e26690fea63946a399f55dd54f245a711c295027ccec0437c9f42f66f1884fd11f900ed77be5899ea30016733cf44348b4021ff5f2f066de15057c
7
- data.tar.gz: 17fc655ea15f24b797ad0d2de79e34e2160f52c7ae02bfc30d86e69acf60c1dfc7c9f0b7c7c9acfffbcedd08da4b30e3a5de19fdadce83633dfe20453adaa23d
6
+ metadata.gz: 2e9afe5c45473b6d4d57ecf0f24ebf32462919093b7f1c2fb8f723b709facaef4816533e29e7eb19ef6b5dc62a852e333c61cb81b762bdf693e77a61afb8490c
7
+ data.tar.gz: 6f0c15eb122a8508109f344af0fe7b48eaf55ad772517658de2ffb69ea4f90a35e3b5a5680bd6e760a1d6e659f2236d016cbf7be67e598036bbeb96226be508f
data/README.md CHANGED
@@ -144,6 +144,17 @@ where `INLIST_TO_POINT_TO` is the name of an inlist that you would like your loc
144
144
  The `-p` or `--pgstar` option will also point the main `inlist` file to the
145
145
  `INLIST_TO_POINT_TO` file for the `pgstar` namelist.
146
146
 
147
+
148
+ ### rates
149
+
150
+ To use, just type
151
+
152
+ mesa rates REACTION_NAME OUTFILE
153
+
154
+ where `REACTION_NAME` is the name of a reaction found in `$MESA_DIR/data/rates_data/cache`, without the preceding `r_` and optionally specifying `_1`, `_2`, or whatever other option is available. For instance, `c12_pg_n13` is a valid `REACTION_NAME`, as is `c12_pg_n13_1`. If no ending number is specified, `_1` is assumed.
155
+
156
+ `OUTFILE` is an optional argument that specifies a file name where the rate data will be written to. If it is omitted, the data is simply written to the standard output.
157
+
147
158
  ### test
148
159
 
149
160
  To use, just type
data/bin/mesa CHANGED
@@ -270,6 +270,95 @@ class MyCLI < Thor
270
270
  end
271
271
  end
272
272
 
273
+ desc "rates REACTION [OUTFILE]", "Calculate and output out reaction rates"
274
+
275
+ long_desc <<-LONGDESC
276
+ Calls the `show_rates' executable from $MESA_DIR/rates/test for a REACTION
277
+ found in $MESA_DIR/data/rates_data/cache. The reaction is whatever comes
278
+ after "r" or "r_" in the .bin file in the cache directory. You may also
279
+ include the number at the end if you'd like to specify which rate to use, but
280
+ if none is provided, the "_1" option will be used.
281
+
282
+ If OUTFILE is provided, the output is redirected to a text file with the name
283
+ indicated by OUTFILE. Otherwise it is simply written to the screen.
284
+
285
+ For example,\n
286
+
287
+ >>> mesa rates c12_pg_n13
288
+
289
+ will spit 10,000 lines of rate data to the terminal, while
290
+
291
+ >>> mesa rates c12_pg_n13 c12_pg_n13.data
292
+
293
+ will save the same data to a file, c12_pg_n13.data.
294
+ LONGDESC
295
+
296
+ def rates(reaction, outfile = '')
297
+ return unless check_for_mesa_dir
298
+ cache_dir = File.join(ENV['MESA_DIR'], 'data', 'rates_data', 'cache')
299
+
300
+ # set up regular expressions; allow for specific ending number (first case)
301
+ # or leave it ambiguous (second case)
302
+ if reaction =~ /_\d$/
303
+ matcher = /r_?#{reaction}\.bin/
304
+ else
305
+ matcher = /r_?#{reaction}_(\d)\.bin/
306
+ end
307
+
308
+ # search for matching cache files. Return if none are found and find lowest
309
+ # "number" cache file if multiple matches are found
310
+ rate_files = Dir.entries(cache_dir).select { |f| f =~ matcher }
311
+ case rate_files.length
312
+ when 0
313
+ puts "No reactions matching #{reaction} found in #{cache_dir}. Exiting."
314
+ return
315
+ when 1
316
+ rate_file = File.join(cache_dir, reactions[0])
317
+ else
318
+ min_num = nil
319
+ rate_file = nil
320
+ rate_files.each do |f|
321
+ if min_num.nil? or matcher.match(f).captures.first.to_i < min_num
322
+ min_num = matcher.match(f).captures.first.to_i
323
+ rate_file = File.join(cache_dir, f)
324
+ end
325
+ end
326
+ end
327
+
328
+ data = ''
329
+ # Execute the `show_rates` function and capture the output
330
+ visit File.join(ENV['MESA_DIR'], 'rates', 'test') do
331
+ data = `./show_rates #{rate_file}`
332
+ end
333
+
334
+ # scrub the output for poorly formatted floats
335
+
336
+ lines = data.split("\n")[4..-1]
337
+ t8 = []
338
+ sigv = []
339
+ float_matcher = /(\d\.\d+)D?(\-|\+)(\d+)/i
340
+ lines.each do |line|
341
+ new_t8, new_sigv = line.split
342
+ new_t8 =~ float_matcher
343
+ t8 << $1.to_f * (10**(exp_sign($2) * $3.to_i))
344
+ new_sigv =~ float_matcher
345
+ sigv << $1.to_f * (10**(exp_sign($2) * $3.to_i))
346
+ end
347
+ lines = t8.zip(sigv).map do |pair|
348
+ sprintf("%-26.16e", pair[0]) + sprintf("%-26.16e", pair[1])
349
+ end
350
+ data = lines.join("\n")
351
+
352
+ # save output to screen or to file
353
+ if outfile.empty?
354
+ puts data
355
+ else
356
+ File.open(outfile, 'w') do |f|
357
+ f.puts data
358
+ end
359
+ end
360
+ end
361
+
273
362
  private
274
363
  def create_ms_file(inlist_name, ms_name)
275
364
  ms_name += '.rb' unless ms_name[-3..-1] == '.rb'
@@ -326,7 +415,6 @@ class MyCLI < Thor
326
415
 
327
416
  # adjust MESA_DIR location and document changes
328
417
  lines_to_fix.reverse.each do |i|
329
- have_fixed = true
330
418
  line = contents[i]
331
419
  contents[i].sub!(/=.*/, "=#{dir_name}")
332
420
  contents.insert(i, '# ' + "Changed MESA_DIR to #{dir_name} on " +
@@ -363,6 +451,24 @@ class MyCLI < Thor
363
451
  "not a supported shell."
364
452
  end
365
453
  end
454
+
455
+ def visit(new_dir)
456
+ old_dir = Dir.pwd
457
+ Dir.chdir(new_dir)
458
+ yield
459
+ Dir.chdir(old_dir)
460
+ end
461
+
462
+ def exp_sign(str)
463
+ case str
464
+ when '-'
465
+ return -1
466
+ when '+'
467
+ return 1
468
+ else
469
+ raise "invalid sign: #{exp_sign}"
470
+ end
471
+ end
366
472
  end
367
473
 
368
474
  MyCLI.start(ARGV)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mesa_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Wolf
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-10 00:00:00.000000000 Z
11
+ date: 2017-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -91,9 +91,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
91
  version: '0'
92
92
  requirements: []
93
93
  rubyforge_project:
94
- rubygems_version: 2.4.6
94
+ rubygems_version: 2.6.8
95
95
  signing_key:
96
96
  specification_version: 4
97
97
  summary: Mesa CLI - a command line interface for simple MESA tasks.
98
98
  test_files: []
99
- has_rdoc: false