Format a training metric with a configurable number of decimal places.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=real32), | intent(in) | :: | value |
Value to format |
||
| integer, | intent(in) | :: | decimals |
Number of decimal places |
||
| logical, | intent(in) | :: | scientific |
Whether to use scientific notation |
Formatted string
function format_training_real(value, decimals, scientific) result(formatted) !! Format a training metric with a configurable number of decimal places. implicit none ! Arguments real(real32), intent(in) :: value !! Value to format integer, intent(in) :: decimals !! Number of decimal places logical, intent(in) :: scientific !! Whether to use scientific notation character(len=64) :: formatted !! Formatted string ! Local variables character(len=16) :: fmt !! Internal write format integer :: width_ !! Field width for scientific formatting integer :: decimals_ !! Clamped decimal count decimals_ = min(max(decimals, 0), 30) if(scientific)then width_ = max(decimals_ + 8, 14) write(fmt,'("(ES",I0,".",I0,"E2)")') width_, decimals_ else write(fmt,'("(F0.",I0,")")') decimals_ end if write(formatted, fmt) value formatted = adjustl(formatted) end function format_training_real