3621 """Set the units of the application of this operator.
3623 This mixin is used for the <times> and <divide> operators.
3624 There are 2 possible strategies here. One is to pick one of the
3625 operands and convert it so that the overall units match those
3626 required. The other is to pick units from the set of those
3627 possible for this application, and convert the result to the
3628 desired units. We go with the latter option, picking the units
3629 that are least in the sense that they have the least multipicative
3630 factor, but where possible that factor is no less than that on the
3633 app = self.xml_parent
3634 min_factor, best_factor =
None,
None
3635 least_units, best_units =
None,
None
3637 DEBUG(
'validator',
'>',self.localName,
':',desired_factor,
3638 desired_units.description())
3639 units_set = app.get_units().get_consistent_set(desired_units)
3640 for possible_units
in units_set:
3642 if min_factor
is None or f<min_factor:
3643 least_units, min_factor = possible_units, f
3644 if f >= desired_factor
and (best_factor
is None or f < best_factor):
3645 best_units, best_factor = possible_units, f
3646 if best_units
is None:
3651 DEBUG(
'validator',
'\t<-',
3653 units.description())
3655 app._add_units_conversion(app, units, desired_units, no_act)
3657 for src_units_set, src_units
in app.get_units()._get_sources(units):
3658 expr = src_units_set.get_expression()
3659 DEBUG(
'validator',
'#',self.localName,
':',
3660 src_units.description(),expr.localName)
3664 app._cml_units = units
return