Method: CodeRunner::Run::FortranNamelist.get_namelists_and_variables_from_source_code

Defined in:
lib/coderunner/fortran_namelist.rb

.get_namelists_and_variables_from_source_code(source) ⇒ Object

Find all input namelists and variables by scanning the source code



1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
# File 'lib/coderunner/fortran_namelist.rb', line 1095

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*\//i}(?<variables>#{FORTRAN_SINGLE_LINE})", Regexp::IGNORECASE)) 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 =  $~.to_s.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