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 ☻ (black smiling face), with code point U+263B. The compiled binary must be executed in a terminal with Unicode support, like xterm or sakura.

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

    string = u_'unicode character: \u263B'

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

Build the executable with:

$ gfortran9 -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'263B'), kind=u)