Class: CMORizer::Step::AUTO_CONVERT_UNIT
- Inherits:
-
IndividualBaseStep
- Object
- BaseStep
- IndividualBaseStep
- CMORizer::Step::AUTO_CONVERT_UNIT
- Defined in:
- lib/step.rb
Instance Attribute Summary
Attributes inherited from BaseStep
#forbid_inplace, #initial_prefix, #needs_to_run, #resultpath
Class Method Summary collapse
- .auto_convert_unit_possible?(from_unit, to_unit) ⇒ Boolean
- .convert_unit_commands(from_unit, to_unit) ⇒ Object
Instance Method Summary collapse
Methods inherited from IndividualBaseStep
Methods inherited from BaseStep
#add_input, #create_outpath, #initialize, #set_info, #truncate_string
Constructor Details
This class inherits a constructor from CMORizer::Step::BaseStep
Class Method Details
.auto_convert_unit_possible?(from_unit, to_unit) ⇒ Boolean
191 192 193 194 195 196 197 198 199 |
# File 'lib/step.rb', line 191 def self.auto_convert_unit_possible?(from_unit, to_unit) begin AUTO_CONVERT_UNIT.convert_unit_commands(from_unit, to_unit) rescue RuntimeError => e return false end return true end |
.convert_unit_commands(from_unit, to_unit) ⇒ Object
[View source]
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/step.rb', line 202 def self.convert_unit_commands(from_unit, to_unit) cmds = [] if(from_unit != to_unit) case [from_unit, to_unit] when ["psu", "0.001"] # noop when ["psu2", "1e-06"] # noop when ["W/m^2", "W m-2"] # noop when ["1.0", "1"] # noop when ["1", "%"] cmds << CDO_MULC_cmd.new(100) when ["1.0", "%"] cmds << CDO_MULC_cmd.new(100) when ["K", "degC"] cmds << CDO_SUBC_cmd.new(-273.15) else raise "can not automatically convert unit from '#{from_unit}' to '#{to_unit}'" end end cmds end |
Instance Method Details
#file_commands ⇒ Object
[View source]
226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/step.rb', line 226 def file_commands cmds = AUTO_CONVERT_UNIT.convert_unit_commands(@fesom_unit, @out_unit) unless cmds.empty? # apply unit # assume the APPLY_LOCAL_ATTRIBUTES Step will be executed later # and thus our variable has still the original name (@fesom_variable_name) cmds << NCATTED_SET_VARIABLE_UNITS_cmd.new(@fesom_variable_name, @out_unit) end cmds end |