Unicode

Modern Fortran language standards have no intrinsic support for Unicode I/O. To bypass this limitation, the Universal Coded Character Set defined in ISO 10646 can be used instead, which is mostly identical to UTF-32. All code points of the Basic Multilingual Plane can be accessed, while the Supplementary Multilingual Plane is not supported.

The following example prints the Unicode block element ▓ (dark shade), with code point U+2593. The compiled binary must be executed in a terminal with Unicode support, like xterm or rxvt-unicode.

! unicode.f90
program unicode
    use, intrinsic :: iso_fortran_env
    implicit none
    integer, parameter :: u = selected_char_kind('ISO_10646')
    character(kind=u, len=:), allocatable :: string

    string = u_'unicode character: \u2593'

    open (output_unit, encoding='utf-8')
    print '(a)', string
end program unicode

Build the executable with:

$ gfortran8 -Wl,-rpath=/usr/local/lib/gcc8/ -fbackslash -o unicode unicode.f90

The source code does not compile with Flang 5, as it has no support for ISO 10646. The -fbackslash compiler flag is required for escaped Unicode characters. Otherwise, the type conversion has to be done manually using BOZ literals, for instance:

string = u_'unicode_character: ' // char(int(z'2593'), kind=u)