Method: CodeRunner::Run::FortranNamelist.setup_namelists

Defined in:
lib/coderunner/fortran_namelist.rb

.setup_namelists(folder) ⇒ Object

Read the database of namelists and generate the four run class properties

* variables_with_help
* variables_with_autoscanned_defaults
* variables_with_hashes
* variables

The full namelist database itself is assigned to the run class property

* namelists

(Reminder: run class properties are accessed with the rcp call)



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/coderunner/fortran_namelist.rb', line 36

def self.setup_namelists(folder)
  #    folder = File.dirname(__FILE__)


    namelist_file = folder + '/namelists.rb'
    unless FileTest.exist?(namelist_file)
      File.open(namelist_file, 'w'){|file| file.puts '{}'}
    end
    @namelists = eval(File.read(folder + '/namelists.rb'), binding, folder + '/namelists.rb') 

    @variables_with_help = (@namelists.inject({}) do |hash, (namelist, namelist_hash)|
      namelist_hash[:variables].each{|var, var_hash| hash[var] = var_hash[:help] if var_hash[:help]}
      hash
    end) 

    @variables_with_autoscanned_defaults = (@namelists.inject({}) do |hash, (namelist, namelist_hash)|
      namelist_hash[:variables].each{|var, var_hash| hash[var] = var_hash[:autoscanned_defaults] if var_hash[:autoscanned_defaults]}
      hash
    end)

    @variables_with_hashes = @namelists.inject({}) do |hash, (namelist, namelist_hash)|
      namelist_hash[:variables].each{|var, var_hash| hash[var] = var_hash unless hash[var] and hash[var][:help]} # If there are duplicates, take the one with help
      hash
    end

  @variables = @namelists.inject([]) do |arr, (namelist, namelist_hash)|
    if en = namelist_hash[:enumerator]
      en[:estimated_value].times do |i|
        namelist_hash[:variables].each{|var, var_hash| arr.push var + "_#{i+1}".to_sym}
      end
    else
      namelist_hash[:variables].each{|var, var_hash| arr.push var}
    end
    arr
  end
  
  @variable_names_from_code_names = @variables_with_hashes.inject({}) do |hash, (var, var_hash)|
    hash[(var_hash[:code_name] || var)] = var
     hash
  end
    


  # VARIABLES = VARIABLES_WITH_HELP.keys
  @variables.each{|var| attr_accessor var}

  # Needed for backwards compatibility with old simulation data - variables that
  # are no longer input parameters for the current version of the 
  # simulation code.
  #
  

  begin
    @deleted_variables = eval(File.read(folder + '/deleted_variables.rb'), binding, folder + '/deleted_variables.rb')
  rescue Errno::ENOENT
    @deleted_variables = {}
    #save_deleted_variables
  end

  @deleted_variables.keys.each{|var| attr_accessor var}
  

end