Method: CodeRunner::Run::FortranNamelist.add_variable_must_pass

Defined in:
lib/coderunner/fortran_namelist.rb

.add_variable_must_pass(namelist = nil, var, tst) ⇒ Object

Add a test which the variable must pass before being included in the input file. The parameter tst must be of the form: { test: test_string explanation: explanation_string } where test_string is a string such that variable_value.instance_eval(test_string) should be true when the variable_value passes the test. The explanation should be a string which explains what the test does. If variable_value fails the test, an error is raised.



425
426
427
428
429
430
431
432
433
434
# File 'lib/coderunner/fortran_namelist.rb', line 425

def self.add_variable_must_pass(namelist=nil, var, tst)
	unless namelist
		namelist = rcp.namelists.find{|n, nh| nh[:variables].keys.include? var}[0]
		eputs "Editing namelist #{namelist}"; STDIN.gets
	end
	rcp.namelists[namelist][:variables][var][:must_pass] ||= []
	rcp.namelists[namelist][:variables][var][:must_pass].push tst
	rcp.namelists[namelist][:variables][var][:must_pass].uniq!
	save_namelists
end