How to inoculate text-writing to enable it to deal with special language dependant characters, like those used in the French language? I believe it is called text culture setting. Without it, text in some spoken languages, gets invested by funny unwanted squiggles.
Country coding in Fortran
Please see https://forums.silverfrost.com/Forum/Topic/3503&highlight=utf8 on this forum.
Also search for UTF-8 in the FTN95 help file where you will find...
ClearWin+ can display UTF-8 multi-byte characters. Fortran programs use standard CHARACTER variables to hold the UTF-8 encoded character strings. These should be written into files that are saved using Code Page 65001 'UNICODE (UTF-8 without signature)'. See for example 'Advanced Save Options' in Plato. It is important to omit the signature otherwise FTN95 will not compile the file.
A new subroutine informs the ClearWin+ library that UTF-8 characters may be included.
SUBROUTINE ENABLE_UTF8@(enable) INTEGER enable
'enable' is an input value set to a non-zero value to enable UTF-8 encoding or zero to disable. The default state is OFF.
Re your reference 'File does not exist' And if one does not use ClearWin+ ? Live with the squiggles?
Zach
You should be able to just click on the link.
It will take you to code that does not use ClearWin+.
Alternatively search for the word 'Cyrillic' on this forum.
I have not found a way to avoid getting squiggles in text displayed on screen. What is remarkable is that ' - ' in the text also causes display problems. So my conclusion is that compiled Fortran cannot deal with anything but simple text.
This is not a Fortran issue, it is related to the windows settings on your machine.
If the following program does not run correctly on your machine:
CHARACTER(len=2) :: text(2) = ['a ','α'] !Note len=2 and extra space in text(1)
print*, text(1)
print*, text(2)
end
Then in windows go to the system's Language settings, selecting Administrative language settings, clicking Change system locale... and checking the Beta: Use Unicode UTF-8 for worldwide language support box. On my machine there is no need to restart after this.
Rerunning the program after this change, the program should run correctly.
Here is what I tried and found, without changing any settings on my Windows-11 PC.
I created a program file in Notepad and saved the file as a UTF-8 file, with these lines:
program show_utf8_str
character(len=110):: sentence
sentence = 'Βίβλος γενέσεως Ἰησοῦ Χριστοῦ υἱοῦ Δαυὶδ υἱοῦ Ἀβραάμ.'
print '(1x,i4,/,A120)',len_trim(sentence),sentence
end program
I built and ran the program using FTN95, redirecting the output to a file. When I opened that file in Notepad, here is what I saw:
110
Βίβλος γενέσεως Ἰησοῦ Χριστοῦ υἱοῦ Δαυὶδ υἱοῦ Ἀβραάμ.
This program works just as well with Gfortran (version 11.3 under Cygwin). (The FTN95 output contains CR+LF whereas the Gfortran output contains only LF at end-of-line).
The sentence that I used is at the top of the page in an old papyrus, see https://en.wikipedia.org/wiki/Papyrus_1 .
Mecej4, Interesting. With my approach printing to the terminal, about a dozen of the characters in you example are not printed correctly (FTN95, gFortran and Ifort)
Clearwin+ has no problems displaying the text.
program show_utf8_str
use clrwin
character(len=110):: sentence
call enable_utf8@(1)
sentence = 'Βίβλος γενέσεως Ἰησοῦ Χριστοῦ υἱοῦ Δαυὶδ υἱοῦ Ἀβραάμ.'
i = winio@('%ws', sentence)
end program
As long as one keeps a Unicode string as a whole entity and moves it around, no problems may be encountered.
However, if one tries to measure the length of the string (53 glyphs, many embellished with diacritical marks, in contrast to 110 bytes to represent those characters, for the example sentence that I used), or parse the sentence into words, etc., one would need a text processing library with support for the natural language being manipulated.
Compiling in Gfortran shows errors.
3 | call enable_utf8@(1)
| 1
Error: Syntax error in CALL statement at (1)
Enable_utf8@ is a Silverfrost library routine i.e. not a Fortran intrinsic. The error reported by gFortran is correct.
The Silverfrost library can be accessed via a program complied using a third party compiler. This usage requires an FTN95 licence from Silverfrost. If this is of interest, the details can be found in the documentation.
When using the ClearWin+ library for gFortran, winio@ must be changed to winio$. Likewise for other ClearWin+ library routines (like enable_utf8@) that end with the @ symbol.
Also 'use clrwin' becomes 'use clrwin$'.
The $ forms may also be used with FTN95.