View previous topic :: View next topic |
Author |
Message |
Zach
Joined: 13 Mar 2023 Posts: 85 Location: Groningen, Netherlands
|
Posted: Mon May 22, 2023 3:10 am Post subject: Country coding in Fortran |
|
|
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. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8037 Location: Salford, UK
|
Posted: Mon May 22, 2023 7:43 am Post subject: |
|
|
Please see http://forums.silverfrost.com/viewtopic.php?t=3937&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. |
|
Back to top |
|
|
Zach
Joined: 13 Mar 2023 Posts: 85 Location: Groningen, Netherlands
|
Posted: Tue May 23, 2023 5:39 pm Post subject: |
|
|
Re your reference
"File does not exist"
And if one does not use ClearWin+ ? Live with the squiggles? |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8037 Location: Salford, UK
|
Posted: Tue May 23, 2023 7:03 pm Post subject: |
|
|
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. |
|
Back to top |
|
|
Zach
Joined: 13 Mar 2023 Posts: 85 Location: Groningen, Netherlands
|
Posted: Mon Jun 05, 2023 6:35 pm Post subject: |
|
|
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. |
|
Back to top |
|
|
Kenneth_Smith
Joined: 18 May 2012 Posts: 726 Location: Hamilton, Lanarkshire, Scotland.
|
Posted: Mon Jun 05, 2023 10:37 pm Post subject: |
|
|
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:
Code: | 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. |
|
Back to top |
|
|
mecej4
Joined: 31 Oct 2006 Posts: 1897
|
Posted: Mon Jun 05, 2023 11:18 pm Post subject: |
|
|
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:
Code: | 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:
Code: | 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 .
Last edited by mecej4 on Wed Jun 07, 2023 2:30 pm; edited 2 times in total |
|
Back to top |
|
|
Kenneth_Smith
Joined: 18 May 2012 Posts: 726 Location: Hamilton, Lanarkshire, Scotland.
|
Posted: Mon Jun 05, 2023 11:59 pm Post subject: |
|
|
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.
Code: | program show_utf8_str
use clrwin
character(len=110):: sentence
call enable_utf8@(1)
sentence = 'Βίβλος γενέσεως Ἰησοῦ Χριστοῦ υἱοῦ Δαυὶδ υἱοῦ Ἀβραάμ.'
i = winio@('%ws', sentence)
end program
|
|
|
Back to top |
|
|
mecej4
Joined: 31 Oct 2006 Posts: 1897
|
Posted: Tue Jun 06, 2023 12:40 am Post subject: |
|
|
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. |
|
Back to top |
|
|
Zach
Joined: 13 Mar 2023 Posts: 85 Location: Groningen, Netherlands
|
Posted: Wed Jun 07, 2023 10:10 am Post subject: |
|
|
Compiling in Gfortran shows errors.
3 | call enable_utf8@(1)
| 1
Error: Syntax error in CALL statement at (1) |
|
Back to top |
|
|
Kenneth_Smith
Joined: 18 May 2012 Posts: 726 Location: Hamilton, Lanarkshire, Scotland.
|
Posted: Wed Jun 07, 2023 1:09 pm Post subject: |
|
|
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. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8037 Location: Salford, UK
|
Posted: Thu Jun 08, 2023 6:26 am Post subject: |
|
|
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. |
|
Back to top |
|
|
|