Method: CodeRunner::Run::FortranNamelist.parse_input_file
- Defined in:
- lib/coderunner/fortran_namelist.rb
.parse_input_file(input_file, strict = true) ⇒ Object Also known as: generate_simple_namelist_hash
Parses a Fortran namelist input file into a hash of { :namelist => { :variable => value } }
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 |
# File 'lib/coderunner/fortran_namelist.rb', line 546 def self.parse_input_file(input_file, strict=true) if FileTest.file? input_file text = File.read(input_file) else text = input_file end namelist_hash = {} regex = Regexp.new("#{rcp.matching_regex.to_s}\\s*(?:\\!(?<comment>.*))?\\n") #ep input_file text.scan(/(?:(?:^|\A)\s*\!\s*(?<namelist_comment>[^\n]+)\n)?(?:^|\A)\&(?<namelist>\S+).*?^\//m) do namelist = $~[:namelist].downcase.to_sym hash = namelist_hash[namelist] = {} #p $~ scan_text_for_variables($~.to_s).each do |var, val| #ep ['Varval', var, val] add_code_variable_to_namelist(namelist, var, val) if @strict hash[var] = val end end #pp 'inputfile', namelist_hash namelist_hash end |