Method: CodeRunner::Run::FortranNamelist.update_folder_defaults
- Defined in:
- lib/coderunner/fortran_namelist.rb
.update_folder_defaults ⇒ Object
This method doesn’t quite work. It is supposed to edit a local copy of a defaults file and update it to reflect any changes made to the central defaults file, without overriding any changes made to the local defaults file.
724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 |
# File 'lib/coderunner/fortran_namelist.rb', line 724 def self.update_folder_defaults #updates the defaults file in the current folder to add any new defaults settings from the given modlet. Does NOT change exist settings current = File.read((defaults_file = rcp.modlet + '_defaults.rb')) updated = File.read("#{rcp.modlet_location}/#{defaults_file}") hash = current.scan(/(^\s*\@(\w+).*)/).inject({}) do |hash, (all, name)| hash[name] = all unless name.to_s =~ /iphi00/ hash end # new_hash = {} updated.scan(/(^\s*\@(\w+).*)/).each do |all, name| next if name.to_s =~ /iphi00/ unless SPECIES_DEPENDENT_VARIABLES.include? name.sub(/_\d+$/, '').to_sym hash[name] = all unless hash[name] else # puts name name.sub(/_1$/, '') if hash[name.sub(/_1$/, '_i').sub(/_2$/, '_e')] hash[name] = hash[name.sub(/_1$/, '_i').sub(/_2$/, '_e')].sub(/_i\b/, '_1').sub(/_e\b/, '_2') hash.delete(name.sub(/_1$/, '_i').sub(/_2$/, '_e')) elsif hash[name.sub(/_1$/, '')] ep name hash[name] = hash[name.sub(/_1$/, '')].sub(/(^\@\w+)/, '\1_1') hash.delete(name.sub(/_1$/, '')) else hash[name] = all end end end # eputs hash.pretty_inspect # puts hash.values hash['adiabatic_option'] ||= %[@adiabatic_option = "iphi00=2"] puts hash.values # File.open(defaults_file, 'w'){|file| file.puts hash.values} end |