Manual Reference Pages  - fmt (3m_unicode)

NAME

FMT(3f) - [M_unicode:CONVERSION] convert any intrinsic to a string using specified format (LICENSE:MIT)

CONTENTS

Synopsis
Description
Options
Returns
Examples
Author
License

SYNOPSIS

function fmt(value,format) result(string)

     class(*),intent(in),optional           :: value

character(len=*),intent(in),optional :: format or type(unicode_type),intent(in),optional :: format

type(unicode_type) :: string

DESCRIPTION

FMT(3f) converts any standard intrinsic value to a string using the specified format.

OPTIONS

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.

RETURNS

string A string value

EXAMPLES

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_fmt

Results:

    > result is [10]
    > result is [3.3333]
    > result is The final answer is [T]
    > result is [A B C]

AUTHOR

John S. Urban

LICENSE

    MIT