mesa_cli 0.1.0
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 +7 -0
- data/README.md +133 -0
- data/bin/mesa +211 -0
- metadata +82 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2908874ec54278806e2984d1e0f60076bbb94e6d
|
4
|
+
data.tar.gz: 7fdc828dbc702fc9bd3ce850db318f1f4300a49f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 09c4ef4e454b92891033436bb9e8625c3a2f4ac52fd8cd52573c9dc0b72625bedc6abd60920d518d2759655e703e31c1d3458e8c3a55218e4352152bf6846096
|
7
|
+
data.tar.gz: 1cee8d38e282cc546c626fae00500dc66fd6fad9762f47f0b68f810715dfc4548d865d48a97f1b4dd33b23ae95e343c45d20beebfc6cfb418ee7e11f4c95292d
|
data/README.md
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
mesa_cli
|
2
|
+
========
|
3
|
+
|
4
|
+
Command line tools for use with open source MESA stellar evolution code.
|
5
|
+
|
6
|
+
I don't think this tool is done yet, but I wanted to get it out there. So far
|
7
|
+
requires ruby, MesaScript, thor, and a working mesa directory accessed by
|
8
|
+
`$MESA_DIR`.
|
9
|
+
|
10
|
+
## Installation ##
|
11
|
+
|
12
|
+
### Rubygems Installation
|
13
|
+
|
14
|
+
Enter
|
15
|
+
|
16
|
+
gem install mesa_cli
|
17
|
+
|
18
|
+
or if that doesn't work, enter
|
19
|
+
|
20
|
+
sudo gem install mesa_cli
|
21
|
+
|
22
|
+
into your terminal. You should be done now!
|
23
|
+
|
24
|
+
### Manual Installation
|
25
|
+
|
26
|
+
If, for some reason, the rubygems installation doesn't work, you may clone this
|
27
|
+
repository and install the single file `mesa` (located in `mesa_cli/bin/mesa`)
|
28
|
+
as detailed below.
|
29
|
+
|
30
|
+
1. Make sure you have Ruby 1.8.7 or higher (1.9.3 recommended)
|
31
|
+
2. Install [mesascript](http://wmwolf.github.io/MesaScript/).
|
32
|
+
3. Install the Thor gem via
|
33
|
+
|
34
|
+
sudo gem install thor
|
35
|
+
|
36
|
+
4. Place `mesa` file in your path
|
37
|
+
|
38
|
+
|
39
|
+
## Usage
|
40
|
+
|
41
|
+
To get quick information, type `mesa help` to list the commands and see what
|
42
|
+
they do. For detailed information on a particular command, type `mesa help
|
43
|
+
command` to learn about an individual command (replacing the word "command" with the actual subcommand name). Brief summaries of commands are below.
|
44
|
+
|
45
|
+
### default
|
46
|
+
|
47
|
+
To use, just type
|
48
|
+
|
49
|
+
mesa default NAMELIST_NAME
|
50
|
+
|
51
|
+
where namelist name is the name of a MESA star namelist, like `star_job`,
|
52
|
+
`controls`, or `pgstar`.
|
53
|
+
|
54
|
+
This command will open the proper defaults file for the corresponding namelist
|
55
|
+
using whatever editor your system has set in the `EDITOR` variable. For
|
56
|
+
instance,
|
57
|
+
|
58
|
+
mesa default star_job
|
59
|
+
|
60
|
+
will open `$MESA_DIR/star/defaults/star_job.defaults` in vim or whatever default editor you've set up.
|
61
|
+
|
62
|
+
### new
|
63
|
+
|
64
|
+
To use, just type
|
65
|
+
|
66
|
+
mesa new DIR_NAME
|
67
|
+
|
68
|
+
where `DIR_NAME` is the name of a new MESA work directory.
|
69
|
+
|
70
|
+
This makes a copy of `$MESA_DIR/star/work` into a directory with the name
|
71
|
+
chosen. With no name (i.e. just typing `mesa new`), the directory will just be
|
72
|
+
called work. The `inlist_project` will be renamed to `inlist_DIR_NAME`. If
|
73
|
+
MesaScript is available, the main `inlist` file will be pointed to the newly-
|
74
|
+
renamed `inlist_project`, and a MesaScript version of the new `inlist_project`
|
75
|
+
will be made that compiles to `inlist_project`.
|
76
|
+
|
77
|
+
The `-s` or `--simple` option will just copy the work directory and rename the
|
78
|
+
directory only. No renaming of inlists or creation of MesaScript files will be
|
79
|
+
done.
|
80
|
+
|
81
|
+
The `-p` or `--pgstar` option will also point the main `inlist` file to the
|
82
|
+
newly-named `inlist_project` file for the `pgstar` namelist instead of the
|
83
|
+
default `inlist_pgstar`.
|
84
|
+
|
85
|
+
### point
|
86
|
+
|
87
|
+
To use, just type
|
88
|
+
|
89
|
+
mesa point INLIST_TO_POINT_TO
|
90
|
+
|
91
|
+
where `INLIST_TO_POINT_TO` is the name of an inlist that you would like your local `inlist` file to point to. Currently this can only allow you to point to one inlist. By default, this will not point to the new inlist for the `pgstar` namelist, but it will for both of the `star_job` and `controls` namelists.
|
92
|
+
|
93
|
+
The `-p` or `--pgstar` option will also point the main `inlist` file to the
|
94
|
+
`INLIST_TO_POINT_TO` file for the `pgstar` namelist.
|
95
|
+
|
96
|
+
### test
|
97
|
+
|
98
|
+
To use, just type
|
99
|
+
|
100
|
+
mesa test TEST_CASE DIR_NAME
|
101
|
+
|
102
|
+
where `TEST_CASE` is the name of a test case in `$MESA_DIR/star/test_suite` and `DIR_NAME` is the name of a directory to be created that will contain a copy of the proper test suite case.
|
103
|
+
|
104
|
+
The second argument is optional, and if omitted, the new directory will have
|
105
|
+
the same name as the original test suite case. If neither argument is given, a
|
106
|
+
list of every file in `$MESA_DIR/star/test_suite` is output. The listing
|
107
|
+
behavior can also be forced by adding the `-l` or `--list` option to the call.
|
108
|
+
|
109
|
+
Work directories made in this way are "de-test-suited" in that calls back to
|
110
|
+
`inlist_test_suite` are deleted along with any other attempts to change the value of `mesa_dir`. All local path definitions (ones using `../../` or the
|
111
|
+
like) will be made fully qualified. For example, `../../../` will be turned
|
112
|
+
into `$MESA_DIR/`. Thus, references to other inlists, like
|
113
|
+
`inlist_massive_defaults` or models, like those found in
|
114
|
+
`$MESA_DIR/data/star_data`, should remain intact. IF THESE EXTERNAL REFERENCES
|
115
|
+
CONTAIN LOCAL PATHS, THINGS WILL BREAK. The only inlist that is strictly barred
|
116
|
+
from this process is `inlist_test_suite` which currently only serves to set
|
117
|
+
the `mesa_dir` via a local path, so references to this inlist are always
|
118
|
+
deleted.
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
|
data/bin/mesa
ADDED
@@ -0,0 +1,211 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
require "thor"
|
3
|
+
require "fileutils"
|
4
|
+
begin
|
5
|
+
require "mesa_script"
|
6
|
+
$use_mesascript = true
|
7
|
+
rescue LoadError
|
8
|
+
$use_mesascript = false
|
9
|
+
end
|
10
|
+
|
11
|
+
class MyCLI < Thor
|
12
|
+
option :simple, :type => :boolean, :aliases => :s,
|
13
|
+
:desc => "Just copy work directory and rename it. Nothing done with " +
|
14
|
+
"MesaScript."
|
15
|
+
option :pgstar, :type => :boolean, :aliases => [:p, :pgstar],
|
16
|
+
:desc => "Point `inlist` to main inlist for pgstar in addition to star_job " +
|
17
|
+
"and controls (default points to `inlist_pgstar`)."
|
18
|
+
|
19
|
+
desc "new [NEW_DIR]", "Create MESA work dir called NEW_DIR (default 'work')."
|
20
|
+
long_desc <<-LONGDESC
|
21
|
+
|
22
|
+
`mesa new` will create a new work directory generated from your current
|
23
|
+
$MESA_DIR/star/work. The argument specifies the name of the new directory,
|
24
|
+
and the base name of the directory will be used to rename `inlist_project`
|
25
|
+
to `inlist_BASENAME_OF_ARGUMENT`. Finally, it uses MesaScript to point the
|
26
|
+
base `inlist` to the new one and converts the new inlist to MesaScript for
|
27
|
+
easy automation. This is only done if MesaScript is available.
|
28
|
+
|
29
|
+
LONGDESC
|
30
|
+
def new(new_dir="work")
|
31
|
+
return unless check_for_mesa_dir
|
32
|
+
work_dir = File.join(ENV['MESA_DIR'], 'star', 'work')
|
33
|
+
new_loc = new_dir
|
34
|
+
basename = File.basename(new_loc)
|
35
|
+
FileUtils.cp_r(work_dir, new_loc, :verbose => true)
|
36
|
+
unless options[:simple]
|
37
|
+
old_inlist_name = File.join(new_loc, "inlist_project")
|
38
|
+
short_name = "inlist_#{basename}"
|
39
|
+
new_inlist_name = File.join(new_loc, short_name)
|
40
|
+
File.rename(old_inlist_name, new_inlist_name)
|
41
|
+
if options[:pgstar]
|
42
|
+
create_control_inlist(new_loc, short_name, short_name, short_name)
|
43
|
+
else
|
44
|
+
create_control_inlist(new_loc, short_name, short_name)
|
45
|
+
end
|
46
|
+
create_ms_file(new_inlist_name, File.join(new_loc, basename + '.rb'))
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
desc "point INLIST", "Point main `inlist` to INLIST."
|
51
|
+
option :pgstar, :type => :boolean, :aliases => [:p, :pgstar],
|
52
|
+
:desc => "Point `inlist` to INLIST for pgstar in addition to star_job " +
|
53
|
+
"and controls (default points to `inlist_pgstar`)."
|
54
|
+
def point(inlist)
|
55
|
+
if options[:pgstar]
|
56
|
+
create_control_inlist(Dir.pwd, inlist, inlist, inlist)
|
57
|
+
else
|
58
|
+
create_control_inlist(Dir.pwd, inlist, inlist)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
desc "test [TEST_SUITE_CASE] [NEW_DIR]", "Copy test suite case work " +
|
63
|
+
"directory with name TEST_SUITE_CASE to location NEW_DIR."
|
64
|
+
long_desc <<-LONGDESC
|
65
|
+
`mesa test` will primarily create a new work directory based on an existing
|
66
|
+
test case located in $MESA_DIR/star/test_suite. Since the structure of
|
67
|
+
these directories varies wildly, no MesaScript or renaming niceties are
|
68
|
+
done as in the standard `mesa new` command. The first argument is the name
|
69
|
+
of the test suite case to be copied. The second argument, if provided, will
|
70
|
+
be the name of the new directory. If this is omitted, the name remains the
|
71
|
+
same. If no arguments are given a list of available test suite cases are
|
72
|
+
printed out and no directories are copied.
|
73
|
+
|
74
|
+
The resulting directory will have all references to custom values of
|
75
|
+
MESA_DIR removed and any local paths (like ../../inlist_massive_defaults)
|
76
|
+
will be converted to fully-qualified paths (like
|
77
|
+
$MESA_DIR/star/inlist_massive_defaults). The resulting work directory should
|
78
|
+
be ready to make and run immediately as if it were in the test suite
|
79
|
+
directory.
|
80
|
+
LONGDESC
|
81
|
+
option :list, :type => :boolean, :aliases => :l,
|
82
|
+
:desc => "lists available test suite cases"
|
83
|
+
|
84
|
+
def test(test_case=nil, new_dir=nil)
|
85
|
+
return unless check_for_mesa_dir
|
86
|
+
|
87
|
+
test_suite_dir = File.join(ENV['MESA_DIR'], 'star', 'test_suite')
|
88
|
+
if options[:list] or test_case.nil?
|
89
|
+
puts "test cases in #{test_suite_dir}:"
|
90
|
+
puts Dir.entries(test_suite_dir).select { |entry| entry[0] != '.' }
|
91
|
+
return
|
92
|
+
end
|
93
|
+
|
94
|
+
work_dir = File.join(test_suite_dir, test_case)
|
95
|
+
unless File.directory?(work_dir)
|
96
|
+
puts "Unable to locate test suite case #{test_case} in directory " +
|
97
|
+
test_suite_dir + ". Exiting."
|
98
|
+
return
|
99
|
+
end
|
100
|
+
new_dir ||= File.join(FileUtils::pwd, test_case)
|
101
|
+
FileUtils.cp_r(work_dir, new_dir, :verbose => true)
|
102
|
+
inlist_files = Dir.glob(File.join(new_dir,"inlist*"))
|
103
|
+
inlist_files.each do |inlist_file|
|
104
|
+
|
105
|
+
# remove references to a new MESA_DIR
|
106
|
+
inlist_lines = IO.readlines(inlist_file).reject do |line|
|
107
|
+
line.downcase =~ /mesa_dir/
|
108
|
+
end
|
109
|
+
|
110
|
+
# remove references to inlist_test_suite
|
111
|
+
bad_numbers = []
|
112
|
+
bad_namelists = []
|
113
|
+
inlist_lines.each do |line|
|
114
|
+
if line =~ /inlist_test_suite/
|
115
|
+
line =~ /extra_(.+)_inlist(\d)/
|
116
|
+
bad_namelists << $1
|
117
|
+
bad_numbers << $2
|
118
|
+
end
|
119
|
+
end
|
120
|
+
bad_combos = bad_namelists.zip(bad_numbers)
|
121
|
+
bad_words = []
|
122
|
+
bad_combos.each do |namelist, number|
|
123
|
+
bad_words << "read_extra_#{namelist}_inlist#{number}"
|
124
|
+
bad_words << "extra_#{namelist}_inlist#{number}_name"
|
125
|
+
end
|
126
|
+
inlist_lines.reject! do |line|
|
127
|
+
any_found = false
|
128
|
+
bad_words.each do |bad_word|
|
129
|
+
if line.include?(bad_word)
|
130
|
+
any_found = true
|
131
|
+
break
|
132
|
+
end
|
133
|
+
end
|
134
|
+
any_found
|
135
|
+
end
|
136
|
+
|
137
|
+
# make local paths fully-qualified
|
138
|
+
new_inlist_lines = inlist_lines.map do |line|
|
139
|
+
if line =~ /((\.\.\/)+)/
|
140
|
+
line.sub(/((\.\.\/)+)/, File.expand_path(File.join(work_dir, $1))+'/')
|
141
|
+
else
|
142
|
+
line
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
# write out cleaned up inlist
|
147
|
+
IO.write(inlist_file, new_inlist_lines.join)
|
148
|
+
end
|
149
|
+
|
150
|
+
# Clean up makefule
|
151
|
+
makefile = File.join(new_dir, 'make', 'makefile')
|
152
|
+
make_lines = IO.readlines(makefile)
|
153
|
+
|
154
|
+
# Make sure MESA_DIR is not set in makefile
|
155
|
+
make_lines.reject! { |line| line =~ /\A\s*MESA_DIR/ }
|
156
|
+
|
157
|
+
# Make sure no local references to files in mesa tree are made
|
158
|
+
make_lines.reject! { |line| line =~ /\.\./ }
|
159
|
+
make_lines.reject! { |line| line.empty? }
|
160
|
+
IO.write(makefile, make_lines.join)
|
161
|
+
end
|
162
|
+
|
163
|
+
desc "default FILE_NAME", "Open defaults file for namelist FILE_NAME."
|
164
|
+
def default(filename)
|
165
|
+
return unless check_for_mesa_dir
|
166
|
+
defaults_dir = File.join(ENV['MESA_DIR'], 'star', 'defaults')
|
167
|
+
suffix = case
|
168
|
+
when %w{star_job controls pgstar}.include?(filename) then '.defaults'
|
169
|
+
when %w{profile_columns history_columns}.include?(filename) then '.list'
|
170
|
+
else
|
171
|
+
puts <<-BAD_NAME
|
172
|
+
Invalid file name: #{filename}. Must use 'star_job', 'controls', 'pgstar',
|
173
|
+
'profile_columns', or 'history_columns'.
|
174
|
+
BAD_NAME
|
175
|
+
return
|
176
|
+
end
|
177
|
+
editor = ENV['EDITOR'] || 'less'
|
178
|
+
system("#{editor} #{File.join(defaults_dir, filename)}#{suffix}")
|
179
|
+
end
|
180
|
+
|
181
|
+
|
182
|
+
private
|
183
|
+
def create_ms_file(inlist_name, ms_name)
|
184
|
+
ms_name += '.rb' unless ms_name[-3..-1] == '.rb'
|
185
|
+
source = File.join(inlist_name)
|
186
|
+
output = File.join(ms_name)
|
187
|
+
Inlist.inlist_to_mesascript(source, output) if $use_mesascript
|
188
|
+
end
|
189
|
+
|
190
|
+
def check_for_mesa_dir
|
191
|
+
return true if ENV['MESA_DIR']
|
192
|
+
|
193
|
+
puts "WARNING: No environment variable $MESA_DIR found. Exiting."
|
194
|
+
return false
|
195
|
+
end
|
196
|
+
|
197
|
+
def create_control_inlist(dir, star_job, controls, pgstar = "inlist_pgstar")
|
198
|
+
Inlist.make_inlist(File.join(dir, 'inlist')) do
|
199
|
+
read_extra_star_job_inlist1 true
|
200
|
+
extra_star_job_inlist1_name star_job
|
201
|
+
|
202
|
+
read_extra_controls_inlist1 true
|
203
|
+
extra_controls_inlist1_name controls
|
204
|
+
|
205
|
+
read_extra_pgstar_inlist1 true
|
206
|
+
extra_pgstar_inlist1_name pgstar
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
MyCLI.start(ARGV)
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mesa_cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- William Wolf
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.19'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.19'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mesa_script
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.1.2
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.1.2
|
41
|
+
description: " MESA CLI is a command-line interface for doing several tasks with
|
42
|
+
Modules\n for Experiments in Stellar Astrophysics (MESA; mesa.sourceforge.net).
|
43
|
+
This\n package includes one executable, `mesa`. Actions are performed by entering\n
|
44
|
+
\ `mesa` followed by various subcommands. A list of available subcommands can\n
|
45
|
+
\ be displayed by entering\n\n mesa help\n\n Any individual subcommand is
|
46
|
+
documented by typing `mesa help` followed by\n the name of the subcommand, for
|
47
|
+
instance,\n\n mesa help new\n\n will give information about what the `new`
|
48
|
+
command does. For detailed\n instructions, see the readme on the github page
|
49
|
+
at \n\n https://github.com/wmwolf/mesa_cli\n"
|
50
|
+
email: wmwolf@physics.ucsb.edu
|
51
|
+
executables:
|
52
|
+
- mesa
|
53
|
+
extensions: []
|
54
|
+
extra_rdoc_files: []
|
55
|
+
files:
|
56
|
+
- README.md
|
57
|
+
- bin/mesa
|
58
|
+
homepage: https://wmwolf.github.io
|
59
|
+
licenses:
|
60
|
+
- MIT
|
61
|
+
metadata: {}
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 2.4.3
|
79
|
+
signing_key:
|
80
|
+
specification_version: 4
|
81
|
+
summary: Mesa CLI - a command line interface for simple MESA tasks.
|
82
|
+
test_files: []
|