Change format specifier for reals
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in), | optional | :: | d | ||
integer, | intent(in), | optional | :: | e | ||
character, | intent(in), | optional | :: | f |
subroutine chfmt(d, e, f)
!< Change format specifier for reals
!-----------------------------------------------------------
! Change format specifier for reals
!
! Inputs:
! d -> integer, optional
! digits after decimal
! e -> integer, optional
! digits in exponent
! When this is set to -1, the exponent part is dropped
! f -> character, optional
! form
! Valid options: 'F' (decimal), 'E' (exponential),
! 'S' (scientific), 'N' (engineering)
! If 'F' is specified, then the value for e is
! overridden and set to -1.
!
! If no arguments are passed, this function resets all the
! parameters to their default values (as provided in the
! following table. Else, only the passed arguments will be
! updated (the others will be left unchanged).
!
! This function is sticky; a format once set will continue
! to apply till either it is changed or the program ends.
!
! Default values:
! d (digits after decimal) --> 6
! e (digits in exponent) --> -1
! f (form) --> 'F' (decimal)
!
!TODO: Add support for width also?
!http://www.cs.mtu.edu/~shene/COURSES/cs201/NOTES/chap05/format.html
!-----------------------------------------------------------
implicit none
integer, intent(in), optional :: d
integer, intent(in), optional :: e
character, intent(in), optional :: f
if (.not. (present(d) .or. present(e) .or. present(f))) then
dec_ = 6
exp_ = 0
form_ = 'F'
else
if (present(d)) dec_ = d
if (present(e)) exp_ = e
if (present(f)) then
if (.not. (f .eq. 'F' .or. f .eq. 'E' .or. &
f .eq. 'S' .or. f .eq. 'N')) then
print *, 'Error: Unknown kind specified.'
stop
end if
form_ = f
if (form_ .eq. 'F') exp_ = -1
end if
end if
end subroutine chfmt