forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Country coding in Fortran

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General
View previous topic :: View next topic  
Author Message
Zach



Joined: 13 Mar 2023
Posts: 85
Location: Groningen, Netherlands

PostPosted: Mon May 22, 2023 3:10 am    Post subject: Country coding in Fortran Reply with quote

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
View user's profile Send private message Send e-mail
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7884
Location: Salford, UK

PostPosted: Mon May 22, 2023 7:43 am    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
Zach



Joined: 13 Mar 2023
Posts: 85
Location: Groningen, Netherlands

PostPosted: Tue May 23, 2023 5:39 pm    Post subject: Reply with quote

Re your reference
"File does not exist"
And if one does not use ClearWin+ ? Live with the squiggles?
Back to top
View user's profile Send private message Send e-mail
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7884
Location: Salford, UK

PostPosted: Tue May 23, 2023 7:03 pm    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
Zach



Joined: 13 Mar 2023
Posts: 85
Location: Groningen, Netherlands

PostPosted: Mon Jun 05, 2023 6:35 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Kenneth_Smith



Joined: 18 May 2012
Posts: 696
Location: Hamilton, Lanarkshire, Scotland.

PostPosted: Mon Jun 05, 2023 10:37 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
mecej4



Joined: 31 Oct 2006
Posts: 1878

PostPosted: Mon Jun 05, 2023 11:18 pm    Post subject: Reply with quote

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
View user's profile Send private message
Kenneth_Smith



Joined: 18 May 2012
Posts: 696
Location: Hamilton, Lanarkshire, Scotland.

PostPosted: Mon Jun 05, 2023 11:59 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
mecej4



Joined: 31 Oct 2006
Posts: 1878

PostPosted: Tue Jun 06, 2023 12:40 am    Post subject: Reply with quote

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
View user's profile Send private message
Zach



Joined: 13 Mar 2023
Posts: 85
Location: Groningen, Netherlands

PostPosted: Wed Jun 07, 2023 10:10 am    Post subject: Reply with quote

Compiling in Gfortran shows errors.

3 | call enable_utf8@(1)
| 1
Error: Syntax error in CALL statement at (1)
Back to top
View user's profile Send private message Send e-mail
Kenneth_Smith



Joined: 18 May 2012
Posts: 696
Location: Hamilton, Lanarkshire, Scotland.

PostPosted: Wed Jun 07, 2023 1:09 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7884
Location: Salford, UK

PostPosted: Thu Jun 08, 2023 6:26 am    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group