ASCII only identifiers?

Is it correct that Fortran only supports ASCII identifiers (for variable / function / module names)? It looks like gfortran and ifx both complain about “Invalid character” or “Unrecognized token” when compiling something like:

program unicode
    implicit none

    real, parameter :: π = 3.14159
    real, parameter :: ß = 1.23
    real, parameter :: µ₀ = 4 * π * 1e-7
    integer :: i

    real :: Δt, ω
    real :: t(4)
    real :: ϕ(4)
    real :: Aₙ(100)

    Δt = 0.1
    ω = 2.0

    t = [(Δt*real(i), i = 1, 4)]
    ϕ = [π/4, π/2, 3*π/4, π]
    print *, µ₀*cos(ω*t + ϕ) - ß 

end program unicode

I suppose things could get carried away, and might be hard for maintenance if you don’t have a setup to type these easily (I use vim, and have imap mappings from Latex-like modifiers, so \omega becomes ω, etc… Just making sure I’m not missing some command-line option.

Thanks!

(speaking of getting carried away…)

    ℝ :: ω, ℓ, k, E₁
    ℤ :: n

    ω = √(k/ℓ)
    if (n ≥ 4) then
        E₁ = ½·m·v²
        !∇⨉B = µ₀·(J + ε₀·∂E/∂t)
    end if

The fortran standard defines a fortran character set, and then all of the language is defined in terms of those characters. It does not define the binary representation of those characters, so each compiler is free to map its native characters to the fortran character set however it wants.

2 Likes

From the 2023 draft standard:

image

2 Likes
Here are some working examples of Greek Maths symbols in gfortran

iian@ian-Latitude-E7440:~$ nano mathsy2.f08
ian@ian-Latitude-E7440:~$ gfortran mathsy2.f08
ian@ian-Latitude-E7440:~$ ./a.out
 Omega symbol: Ω
ian@ian-Latitude-E7440:~$ cat mathsy2.f08
program print_omega
  implicit none
  write(*,*) 'Omega symbol: Ω'
end program print_omega
ian@ian-Latitude-E7440:~$ nano mathsy3.f08
ian@ian-Latitude-E7440:~$ gfortran  mathsy3.f08
ian@ian-Latitude-E7440:~$ ./a.out
>Hello<
>Hello and 你好<
ian@ian-Latitude-E7440:~$ cat mathsy3.f08
use iso_fortran_env
implicit none
integer, parameter :: wc = selected_char_kind('ISO_10646')
integer, parameter :: ac = selected_char_kind('ASCII')

character(kind=wc,len=20) :: hello4
character(kind=ac,len=20) :: hello1

hello1 = ac_'Hello'
hello4 = wc_'Hello and '//char(int(z'4F60'),wc)//char(int(z'597D'),wc)
open(output_unit,encoding='utf-8')
write(*,'(5a)') '>',trim(hello1),'<'
write(*,'(3a)') '>',trim(hello4),'<'
end
ian@ian-Latitude-E7440:~$