Hello,
what is the best way to implement a scalar and a vectorized version of a
function?
My code:
const Z_REF = 10.0 # reference height for wind profile law
const ALPHA = 0.23375 # exponent of the wind profile law for Cabauw
"""
calcWindAtHeight(v_wind_gnd, z)
Calculate the average wind speed for the given ground wind speed
`v_wind_gnd` at a given height `z`.
The ground wind speed is measured at the height `Z_REF`, a constant, that
must have been defined
before. The exponential wind profile law is used in combination with the
exponent `ALPHA`, that must
have been defined before, too.
"""
function calcWindAtHeight(v_wind_gnd, z::AbstractFloat)
v_wind_gnd * (z / Z_REF)^ALPHA
end
"""
calcWindAtHeight(v_wind_gnd, Z)
Calculate the average wind speed for the given ground wind speed
`v_wind_gnd` at a given height `Z`.
The ground wind speed is measured at the height `Z_REF`, a constant, that
must have been defined
before. The exponential wind profile law is used in combination with the
exponent `ALPHA`, that must
have been defined before, too. If `Z` is an array, the function will return
an array.
"""
function calcWindAtHeight(v_wind_gnd, Z::AbstractArray)
result = similar(Z)
for i in eachindex(Z)
result[i] = calcWindAtHeight(v_wind_gnd, Z[i])
end
result
end
Is this good programming style? Could it be improved?
Regards:
Uwe Fechner