FMT(3f) - [M_unicode:CONVERSION] convert any intrinsic to a string using specified format (LICENSE:MIT)
Synopsis
Description
Options
Returns
Examples
Author
License
function fmt(value,format) result(string)
class(*),intent(in),optional :: valuecharacter(len=*),intent(in),optional :: format or type(unicode_type),intent(in),optional :: format
type(unicode_type) :: string
FMT(3f) converts any standard intrinsic value to a string using the specified format.
value value to print the value of. May be of type INTEGER, LOGICAL, REAL, DOUBLEPRECISION, COMPLEX, or CHARACTER as well as TYPE(UNICODE_TYPE). format format to use to print value. It is up to the user to use an appropriate format. The format does not require being surrounded by parenthesis. If not present a default is selected similar to what would be produced with free format, with trailing zeros removed.
string A string value
Sample program:
program demo_fmt use :: M_unicode, only : fmt, assignment(=) use :: M_unicode, only : ut=>unicode_type, ch=>character implicit none character(len=:),allocatable :: Astr, Aformat type(ut) :: Ustr ! format can be CHARACTER Aformat="([,i0,])" Astr=fmt(10,Aformat) write(*,*)result is ,Astr ! format can be string Astr=fmt(10.0/3.0,ut("[,g0.5,]")) write(*,*)result is ,Astr ! Output is a string, so use ch() write(*,*)result is , ch(fmt(.true.,"The answer is [,g0,]")) ! OOP Ustr=A B C Ustr=Ustr%fmt("[,g0,]") write(*,*)result is ,ch(Ustr) end program demo_fmtResults:
> result is [10] > result is [3.3333] > result is The final answer is [T] > result is [A B C]
John S. Urban
