lib/coderunner/class_methods.rb in coderunner-0.17.1 vs lib/coderunner/class_methods.rb in coderunner-0.17.2
- old
+ new
@@ -16,11 +16,10 @@
set(var, CLASS_OPTIONS[var])
end
end
# List the available modlets for the given code (copts[:C] or -C on the command line).
-
def self.available_modlets(copts={})
process_command_options(copts)
puts "\nAvailable modlets for #{copts[:C]}:"
entries = []
begin
@@ -35,11 +34,10 @@
puts "\t" + File.basename(modlet, '.rb') unless ['.', '..', '.svn', '.directory'].include? modlet or modlet=~ /defaults/
end
end
# List the available defaults files for the given code (copts[:C] or -C on the command line).
-
def self.available_defaults_files(copts={})
process_command_options(copts)
entries = []
#begin
##entries += Dir.entries(SCRIPT_FOLDER + "/code_modules/#{copts[:C]}/my_defaults_files")
@@ -59,12 +57,13 @@
#puts "\t" + File.basename(defaults_file, '.rb').sub(/_defaults/, '') unless ['.', '..', '.svn', '.directory'].include? defaults_file
puts "\t" + File.basename(defaults_file, '.rb').sub(/_defaults/, '')
end
end
- # Cancel the job with the given id. The user is asked interactively for confirmation and whether they would like to delete the folder for that job as well.
-
+ # Cancel the job with the given id. The user is asked interactively for
+ # confirmation and whether they would like to delete the folder for that job
+ # as well.
def self.cancel(id, copts={})
runner = fetch_runner(copts)
runner.cancel_job(id.to_i)
end
@@ -76,10 +75,33 @@
end
runner.continue_in_new_folder(folder, options)
end
+ # Method which concatenates NetCDF output files
+ def self.concat(name, copts={})
+ begin
+ require "numru/netcdf"
+ rescue LoadError
+ eputs "Error: No Ruby NetCDF library (was it installed correctly?): "\
+ "concatenation for netcdf files not possible."
+ return
+ end
+
+ runner = fetch_runner(copts)
+ runs = runner.filtered_ids.map{|id| runner.combined_run_list[id]}
+
+ concat_string = 'ncrcat '
+ runs.each do |r|
+ concat_string += r.directory + '/' + r.run_name + '.out.nc '
+ end
+
+ concat_string += runner.root_folder + '/' + name
+
+ exec "#{concat_string}"
+ end
+
# This section defines the report report writing function in. The latex header is defined in run.rb. It is a run method and can be redefined in a particular CRMOD.
# The function is simply called as follows:
#
# interactively: wr j:<run no.>
# command line: coderunner write_report -j <run no>
@@ -108,15 +130,17 @@
file.puts r.latex_report_header
file.puts <<-EOF.gsub(/^ {14}/, "")
\\begin{itemize}
EOF
- #Need to call some methods here which reads the graphs we want from gs2crmod, generates the graphs
- #then generates the latex code to display graphs.
+ # Need to call some methods here which reads the graphs we want
+ # from gs2crmod, generates the graphs then generates the latex code
+ # to display graphs.
latex_code = r.latex_graphs.inject("") do |tmp_latex_code, (kit, latexstring)|
kit.gnuplot_write(kit.file_name) #write the graph
- tmp_latex_code += "\\item " + latexstring + " \n\n\\newfig{#{kit.file_name}}"
+ tmp_latex_code += "\\item " + latexstring +
+ " \n\n\\newfig{#{kit.file_name}}"
tmp_latex_code += "\n\n"
tmp_latex_code
end
file.puts <<-EOF.gsub(/^ {14}/, "")
@@ -133,10 +157,11 @@
def self.delete(copts={})
runner = fetch_runner(copts)
runner.destroy
end
+
def self.differences_between(copts = {})
runner = fetch_runner(copts)
runs = runner.filtered_ids.map{|id| runner.combined_run_list[id]}
rcp_fetcher = (runs[0] || runner.run_class).rcp
vars = rcp_fetcher.variables.dup + rcp_fetcher.run_info.dup
@@ -178,18 +203,12 @@
kit = runner.graphkit_from_lists(copts[:G], copts[:g], index_name => index)
kit.gp.term = term
kit.gnuplot(eval: string_to_eval)
sleep(copts[:F][:fr] ? 1.0/copts[:F][:fr] : 0.1)
end
- end
-# def self.executable_name # :nodoc:
-# ""
-# end
-#
-# def self.rcp # :nodoc:
-# @rcp ||= KitHash.new
-# end
+ end
+
def self.netcdf_plot(netcdf_file, vars, indices, copts={})
process_command_options(copts)
begin
require "numru/netcdf"
rescue LoadError
@@ -212,12 +231,10 @@
kit.gnuplot
STDIN.gets
kit.close
end
-
-
def self.print_queue_status(copts={})
begin
eputs queue_status
rescue => _err
eputs "General queue status doesn't work on this system; showing queue status for this folder"
@@ -225,14 +242,10 @@
runner = fetch_runner(copts)
eputs runner.queue_status
end
end
-
-
-
-
def self.reference(class_or_method, copts={})
code_folders = Dir.recursive_entries(SCRIPT_FOLDER + '/code_modules').grep(/\/ri$/).map{|fold| ['-d', fold]}.flatten
# ep code_folders
# require 'rdoc/ri/driver'
@@ -249,15 +262,15 @@
eputs "Unknown class or method or no help available: #{err}"
end
# trap(1){}
end
-
def self.directory(id, copts={})
runner = fetch_runner(copts)
puts runner.run_list[id.to_i].directory
end
+
def self.film(copts={})
runner = fetch_runner(copts)
copts[:F][:graphkit_modify] = copts[:w]
runner.make_film_from_lists(copts[:G], copts[:g], copts[:F])
end
@@ -307,11 +320,10 @@
puts string
exec string
end
-
def self.generate_cubecalc(copts={})
#return
File.open('cubecalc.cc', 'w') do |file|
file.puts <<EOF
#include <stdio.h>
@@ -370,13 +382,15 @@
EOF
end
end
+
def self.launcher_directory
ENV['HOME'] + "/.coderunner/to_launch/#{ENV['CODE_RUNNER_LAUNCHER']}"
end
+
def self.start_launcher(refresh, max_queue, copts={})
#eputs "Starting launcher!"
raise "Raise refresh is #{refresh}: it must be >= 0.1" if refresh.to_f < 0.1
raise "Raise max_queue is #{max_queue}: it must be >= 5" if max_queue.to_i < 5
#raise "Launcher already running" if %x[ps -e -o cmd].split("\n").grep(/coderunner\s+launch/).size > 0
@@ -475,19 +489,20 @@
end
end
end
-
def self.code_runner_execute(ruby_fragment, copts={})
#eval(ruby_fragment, GLOBAL_BINDING)
eval(ruby_fragment)
end
+
def self.execute(ruby_fragment, copts={})
eval(ruby_fragment, GLOBAL_BINDING)
#eval(ruby_fragment)
end
+
def self.load_file(files, copts={})
process_command_options(copts)
# begin
files.split(/\s*,\s*/).each do |file|
# p file
@@ -517,10 +532,11 @@
end
end
@@psppipe.finish
@@psppipe = nil
end
+
def self.plot_graph(copts = {})
# process_copts(copts)
runner = fetch_runner(copts)
string_to_eval = copts[:w]
#options = (options and options =~ /\S/) ? eval(options): {}
@@ -528,21 +544,22 @@
kit = runner.graphkit_from_lists(copts[:G], copts[:g])
kit.gnuplot(eval: string_to_eval)
gets
kit.close
end
+
def self.readout(copts={})
-# process_copts(copts)
runner = fetch_runner(copts)
puts runner.readout
end
+
def self.recheck(id, copts={})
-# process_copts(copts)
runner = fetch_runner(copts)
runner.run_list[copts[:R]].recheck
runner.respond_to_requests
end
+
def self.run_class(copts={})
process_command_options(copts)
copts[:no_update] = true
unless copts[:C]
if FileTest.exist? file=Dir.pwd + '/.code_runner_script_defaults.rb'
@@ -555,16 +572,18 @@
end
#ep ['code', 'modlet is', copts[:C], copts[:m]]
return setup_run_class(copts[:C], modlet: copts[:m])
end
+
def self.code_command(string, copts = {})
run_class(copts).class_eval(string)
# runner = fetch_runner(copts)
# runner.run_class.class_eval(string)
end
+
def self.run_command(string, copts={})
# process_copts(copts)
runner = fetch_runner(copts)
eputs "Calling run_commmand..."
@@ -604,10 +623,11 @@
end
# Process.waitall
runner.respond_to_requests
end
+
def self.runner_eval(string, copts = {})
# process_copts(copts)
runner = fetch_runner(copts)
#ep ['server string is', string]
@@ -619,15 +639,17 @@
else
return return_val
end
end
+
def self.scan(scan_string, copts={})
# process_copts(copts)
runner = fetch_runner(copts)
runner.simple_scan(scan_string, nprocs: copts[:n], version: copts[:v], skip: copts[:k], parameters: copts[:p][0])
end
+
def self.submit(copts = {})
# process_copts(copts)
runner = get_submit_runner(copts)
# raise "something is already submitting" if FileTest.exist? "submitting"
runs = []
@@ -646,10 +668,11 @@
# exit
end
runner.submit(runs, nprocs: copts[:n], version: copts[:v], skip: copts[:k], job_chain: copts[:J], no_update_before_submit: copts[:no_update_before_submit])
#exit(0)
end
+
# Fetch a runner appropriate for submitting simulations. In
# all usual cases this is just the default runner for the command
# but where several folders have been specified and we are dealing
# with a merged runner, a single runner is chosen from the merged
# runners using submit_runner_index
@@ -663,14 +686,13 @@
else
return runner.runners[copts[:submit_runner_index]]
end
end
end
+
def self.resubmit(copts = {})
runner = get_submit_runner(copts)
-# process_copts(copts)
-# raise "something is already submitting" if FileTest.exist? "submitting"
runs = []
raise "Parameters must be an array of inspected hashes" unless copts[:p].kind_of? Array
Dir.chdir(runner.root_folder) do
runs = runner.filtered_ids.map do |id|
eputs id
@@ -686,16 +708,16 @@
run.update_submission_parameters(copts[:p][0], false)
run.run_name = nil unless copts[:rerun]
run
end
end
- #throw(:here)
runner.submit(runs, nprocs: copts[:n], version: copts[:v], skip: copts[:k], job_chain: copts[:J], no_update_before_submit: copts[:no_update_before_submit], replace_existing: copts[:replace_existing], smart_resubmit_name: copts[:smart_resubmit_name], rerun: copts[:rerun])
end
- # This method allows the straightforward submission of a single command using the batch queue on any system.
+ # This method allows the straightforward submission of a single command using
+ # the batch queue on any system.
def self.submit_command(jid, comm, copts={})
process_command_options(copts)
submitter = Object.new
submitter.instance_variable_set(:@command, comm)
submitter.instance_variable_set(:@jid, jid)
@@ -715,29 +737,31 @@
end
end
submitter.execute
end
-
-
def self.readout(copts={})
runner = fetch_runner(copts)
runner.readout
end
+
def self.show_values_of(expression, copts={})
runner = fetch_runner(copts)
p runner.filtered_ids.map{|id| runner.combined_run_list[id].instance_eval(expression)}.uniq.sort
end
+
def self.status_with_comments(copts={})
copts[:with_comments] = true
status(copts)
end
+
def self.status(copts={})
# process_copts(copts)
runner = fetch_runner(copts)
runner.print_out(0, with_comments: copts[:with_comments]) unless copts[:interactive_start] or copts[:Z] or copts[:no_print_out]
end
+
def self.status_loop(copts={})
# process_copts(copts)
runner = fetch_runner(copts)
runner.print_out(0, with_comments: copts[:with_comments]) unless copts[:interactive_start] or copts[:Z] or copts[:no_print_out]
break_out = false
@@ -756,18 +780,20 @@
#ep "sleep"
sleep 3
#ep "end sleep"
end
end
+
def self.status_loop_running(copts={})
copts[:f] = "@running"
runner = fetch_runner(copts)
ids = runner.filtered_ids
copts[:f] = "#{ids.inspect}.include? id"
copts[:j] = nil
status_loop(copts)
end
+
def self.status_loop(copts={})
# process_copts(copts)
runner = fetch_runner(copts)
runner.print_out(0, with_comments: copts[:with_comments]) unless copts[:interactive_start] or copts[:Z] or copts[:no_print_out]
break_out = false
@@ -786,10 +812,11 @@
#ep "sleep"
sleep 3
#ep "end sleep"
end
end
+
def self.write_graph(name, copts={})
# process_copts(copts)
runner = fetch_runner(copts)
eputs 'Starting Graph'
kit = runner.graphkit_from_lists(copts[:G], copts[:g])
@@ -806,15 +833,17 @@
name = name.sub(/%d/, (max + 1).to_s)
end
raise "kit doesn't have a file_name and no filename specified; can't write graph" unless name or (kit.file_name.class == String and kit.file_name =~ /\S/)
Dir.chdir(COMMAND_FOLDER){kit.gnuplot_write((name or kit.file_name), {eval: copts[:w]})}
end
+
def self.read_default_command_options(copts)
DEFAULT_COMMAND_OPTIONS.each do |key, value|
copts[key] ||= value
end
end
+
def self.process_command_options(copts)
if copts[:true]
copts[:true].to_s.split(//).each do |letter|
copts[letter.to_sym] = true
end
@@ -867,12 +896,12 @@
end
end
- # Analyse copts[:Y], the choice of the root folder for the runner, and make appropriate
- # modifications to the command options for running remotely, etc.
+ # Analyse copts[:Y], the choice of the root folder for the runner, and make
+ # appropriate modifications to the command options for running remotely, etc.
def self.process_root_folder(copts)
copts[:Y] ||= DEFAULT_COMMAND_OPTIONS[:Y] if DEFAULT_COMMAND_OPTIONS[:Y]
if copts[:Y] and copts[:Y].kind_of? Array
eputs "Warning: ignoring additional folders... selecting folder: #{copts[:Y]=copts[:Y][0]}"
end
@@ -888,12 +917,12 @@
end
end
CODE_OPTIONS={}
- # Retrieve the runner with the folder (and possibly server) given in copts[:Y]. If no runner has been loaded for that folder, load one.
-
+ # Retrieve the runner with the folder (and possibly server) given in
+ # copts[:Y]. If no runner has been loaded for that folder, load one.
def self.fetch_runner(copts={})
# ep copts
#read_default_command_options(copts)
process_command_options(copts)
# If copts(:Y) is an array of locations, return a merged runner of those locations
@@ -941,26 +970,25 @@
end
# ep copts
return runner
# @r.read_defaults
end
+
def self.update_runners
@runners ||= {}
@runners.each{|runner| runner.update}
end
-
def self.runner
@runners ||={}
@runners.values[0]
end
+ def self.manual(copts={})
+ help = <<EOF
- def self.manual(copts={})
- help = <<EOF
-
-------------CodeRunner Manual---------------
Written by Edmund Highcock (2009)
NAME
@@ -1016,14 +1044,6 @@
EOF
#help.gsub(/(.{63,73} |.{73})/){"#$1\n\t"}.paginate
help.paginate
end
-
-
-
-
end
-
-
-
-