This function takes a real number of seconds, converts it to the appropriate units, and returns a string with the unit for output.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=real64), | intent(in) | :: | lap_time |
function get_lap_time_in_appropriate_unit(lap_time) result(res) implicit none real(real64), intent(in) :: lap_time character(NUM_DIGIT_TIME) :: res character(3) :: unit real(real64) :: multiplied unit = 's' if (lap_time >= 6d1) then unit = 'm' multiplied = lap_time / 6d1 else if (lap_time >= 1d0) then unit = 's' multiplied = lap_time else if (lap_time >= 1d-3) then unit = 'ms' multiplied = lap_time * 1d3 else if (lap_time >= 1d-6) then if (get_os_type() == OS_WINDOWS) then unit = 'us' else unit = 'μs' end if multiplied = lap_time * 1d6 else unit = 'ns' multiplied = lap_time * 1d9 end if write(res, '(f10.1, a)') multiplied, unit end function get_lap_time_in_appropriate_unit