Method: CodeRunner::Run::FortranNamelist.get_sample_value

Defined in:
lib/coderunner/fortran_namelist.rb

.get_sample_value(source, var) ⇒ Object

Try to get a sample value of the



1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
# File 'lib/coderunner/fortran_namelist.rb', line 1125

def self.get_sample_value(source, var)
      ep var
      values_text = source.scan(Regexp.new("\\W#{var}\\s*=\\s*.+", Regexp::IGNORECASE)).join("\n") 
      ep values_text
      values = scan_text_for_variables(values_text.sub(/_RKIND/, '')).map{|(v,val)| val} 
      values.uniq!
#       ep values if var == :nbeta
      values.delete_if{|val| val.kind_of? String} if values.find{|val| val.kind_of? Numeric}
      values.delete_if{|val| val.kind_of? String and not String::FORTRAN_BOOLS.include? val} if values.find{|val| val.kind_of? String and String::FORTRAN_BOOLS.include? val}
#       values.sort!
#       ep var
#       ep values
      sample_val = values[0]
      if not values[0] or ( values[0].kind_of? String and not String::FORTRAN_BOOLS.include? values[0])
        p source.scan(Regexp.new("^\s*(?<type>integer|float|character|logical|real|double|complex)(?:&[\\n\\r]|.)*\\W#{var}\\W", Regexp::IGNORECASE)).uniq
        p var unless $~

        case $~[:type]
        when /logical/
          sample_val = '.false.'
        when /int/
          sample_val = 0
        when 'real', 'float', 'double'
          sample_val = 0.0
        when /character/
          sample_val = ""
        when /complex/
          sample_val = Complex(0.0, 0.0)
        end
#         type = Feedback.get_choice("Found the following possible values for '#{var}' in namelist '#{namelist}': #{values.inspect} but cannot determine its type. Please choose its type", ['Float', 'Integer', 'String', 'Unknown' ])
#         ep type
        #n +=1
        
      end
      return sample_val
end