Class: CodeRunner::Run::FortranNamelistC

Inherits:
FortranNamelist show all
Defined in:
lib/coderunner/fortran_namelist_c.rb

Direct Known Subclasses

Cubecalc

Constant Summary

Constants inherited from FortranNamelist

CodeRunner::Run::FortranNamelist::FORTRAN_SINGLE_LINE

Instance Attribute Summary

Attributes inherited from CodeRunner::Run

#code, #code_runner_version, #executable_name, #max_complete, #maxes, #naming_pars, #nprocs, #real_id, #run_test_flags, #runner, #sys, #version

Class Method Summary collapse

Methods inherited from FortranNamelist

add_code_variable_to_namelist, add_help_to_variable, add_namelist_must_pass, add_namelist_should_pass, add_variable_must_pass, add_variable_should_pass, correct_namelist_cases, correct_type_location, defaults_file_text_from_input_file, delete_old_variables, delete_variable, diff_input_files, edit_namelist_help, edit_variable_help, find_variable_hash, fortran_type, get_aggregated_source_code_text, get_variable_modules, help_input, help_variables, #input_file_text, known_code_variable?, #make_info_file, make_new_defaults_file, namelist_defaults_text, #namelist_text, parse_input_file, parse_old_website_docs, print_doxygen_documentation, print_doxygen_variable_documentation, process_synchronisation, read_mediawiki_documentation, save_deleted_variables, save_namelists, scan_text_for_variables, set_allowed_values, setup_namelists, sync_variable_help, synchronise_variables, synchronise_variables_from_input_file, update_folder_defaults, update_text_options, variable_exists?, write_mediawiki_documentation

Methods inherited from CodeRunner::Run

#analyse_input_file_text, #cache, check_and_update, #code_run_environment, #comment_line, #create_phantom, #data_string, #defaults_file_name, #defaults_location, #dup, #error, #evaluate_defaults_file, #executable_location, #execute_submission, finish_setting_up_class, #generate_combined_ids, #generate_phantom_runs, #generate_run_name, #gets, gets, #hard_cache, #info_file, #initialize, #inspect, #is_complete, #job_identifier, #learn_from, load, #logiv, #max, #min, modify_job_script, #p, #prepare_submission, #pretty_print, #print, #process_directory, #puts, #rcp, rcp, #read_info, #read_results, #recheck, #results_file, #run_heuristic_analysis, #save, set_modlet, #smax, #smin, #try_by_system, #try_to_find_job_output_ends, #try_to_get_error_file, #try_to_get_job_number, #try_to_get_output_file, #update_in_queue, update_status, #update_submission_parameters, #warning, #write_info, #write_results

Constructor Details

This class inherits a constructor from CodeRunner::Run

Class Method Details

.get_namelists_and_variables_from_source_code(source) ⇒ Object

Find all input namelists and variables by scanning the source code



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/coderunner/fortran_namelist_c.rb', line 11

def self.get_namelists_and_variables_from_source_code(source)
	nms = {}
	all_variables_in_source = {}
	namelist_declarations = {}
	#source.scan(/^\s*namelist\s*\/(?<namelist>\w+)\/(?<variables>(?:(?:&\s*[\n\r]+)|[^!\n\r])*)/) do 
	#source.scan(Regexp.new("#{/^\s*namelist\s*\/\s*(?<namelist>\w+)\s*\//}(?<variables>#{FORTRAN_SINGLE_LINE})")) do 
	source.scan(rcp.fortran_namelist_variable_match_regex) do
		namelist = $~[:namelist].to_s.downcase.to_sym
		#variables = $~[:variables].gsub(/!.*/, '')
		#eputs namelist, variables
		#namelist_declarations[namelist] = variables
		#gets # if namelist == :collisions_knobs

		#next if [:stuff, :ingen_knobs].include? namelist
		nms[namelist] ||= []
		all_variables_in_source[namelist] ||= []
# 		puts variables
		#variables.scan(/\w+/) do 
			var =  $~[:variable].to_sym
# 			(p variables, namelist; exit) if var == :following or var == :sou
			all_variables_in_source[namelist].push var
			next if known_code_variable?(namelist, var)
			nms[namelist].push var
		#end
		nms[namelist].uniq!
		all_variables_in_source[namelist].uniq!
	end
	return [nms, all_variables_in_source, namelist_declarations]
end

.get_sample_value(source, var) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/coderunner/fortran_namelist_c.rb', line 40

def self.get_sample_value(source, var)
	sample_val = nil
	source.scan(rcp.fortran_namelist_variable_match_regex) do
		#p $~
		
		next unless var == $~[:variable].to_sym
		sample_val = eval($~[:default].sub(/(\d\.)$/, '\10').sub(/^(\.\d)/, '0\1').sub(/(\d\.)[eE]/, '\10e'))
	end
	raise "Couldn't get a sample value for #{var.inspect}" unless sample_val
	return sample_val
end

.update_defaults_from_source_code(source_code_folder = ) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/coderunner/fortran_namelist_c.rb', line 51

def self.update_defaults_from_source_code(source_code_folder = ARGV[-1])
	source = get_aggregated_source_code_text(source_code_folder)
	rcp.namelists.each do |nml, nmlhash|
		nmlhash[:variables].each do |var, varhash|
			varhash[:autoscanned_defaults] = [get_sample_value(source, varhash[:code_name]||var)] rescue []
			save_namelists
		end
	end
end