 |
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
simon
Joined: 05 Jul 2006 Posts: 295
|
Posted: Tue Jan 22, 2019 9:15 pm Post subject: Cyrillic characters |
|
|
Does anyone have a simple example of a Fortran program that reads and writes files containing Cyrillic characters? In addition, is it possible to include Cyrillic characters in a character string within a Fortran program? As soon as I try the latter, Plato indicates it wants to save the file in Unicode and then will not compile it. |
|
Back to top |
|
 |
mecej4
Joined: 31 Oct 2006 Posts: 1899
|
Posted: Wed Jan 23, 2019 2:01 am Post subject: |
|
|
Fortran compilers lag behind C compilers in regard to their support for multi-byte and Unicode characters. Without such support (i.e., character types with more than just one KIND), what you can do in Fortran is quite limited. Using a library such as ICU, see http://site.icu-project.org/home , you can call C routines from your Fortran code.
The following code works with FTN95 and illustrates how to count the number of "words" in Cyrillic text and to separate the input text and print one word per line into an output file.
Code: | ! count words in UTF-8 file as count of space characters + 1
program readcyr
implicit none
character(500) lin
integer i,ls,nw
!
open(10,file='cyr.ut8',status='old')
read(10,'(A)')lin
close(10)
nw=1
ls=len_trim(lin)
do i=1,ls
if(lin(i:i) == ' ')then
nw=nw+1
lin(i:i) = char(10)
endif
end do
open(10,file='cyrw.ut8',status='replace')
write(10,'(A)')lin
close(10)
print *,nw ,' words'
end program |
You may use the following as the contents of cyr.ut8:
Мы собрали все системы, чтобы определить лучших. Поэтому перед вами, наверное, самый полный список конструкторов сайтов в рунете. Если вы знаете конструктор сайтов, которого нет в этому списке - можете добавить его через форму.
You can see from the output file that the program counts '-' as a word, and it probably has other such bugs that need to be fixed, but you get the idea, I hope. |
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8167 Location: Salford, UK
|
Posted: Wed Jan 23, 2019 8:19 am Post subject: |
|
|
Literal Cyrillic character strings can be inserted into an FTN95 program using Plato provided that the file is saved using the Advanced Save options and then the encoding "UTF8 (without signature)". A file that already has this encoding will automatically be saved in this way,
ClearWin+ can also use UTF8 characters if a prior call is made to ENABLE_UTF8@. Details can be found in the enhancements file "clrwin.enh" and item 334. |
|
Back to top |
|
 |
simon
Joined: 05 Jul 2006 Posts: 295
|
Posted: Fri Jan 25, 2019 3:15 am Post subject: |
|
|
Thank you.
FTN95 apparently does not support KIND parameters for CHARACTER variables. In the simple programme below, FTN95 complains about the string length in the parameter declaration:
Code: | Module m
Character(Len=*), Dimension(2), Parameter :: cjan = &
(/'Jan', 'Янв'/)
End Module m |
Would this problem be potentially resolvable if a different kind parameter could be used?[/code] |
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8167 Location: Salford, UK
|
Posted: Fri Jan 25, 2019 9:15 am Post subject: |
|
|
Simon
The quick fix is to add three spaces to Jan....
Code: | winapp
Module m
Character(Len=*), Dimension(2), Parameter :: cjan = &
(/'Jan ', 'Янв'/)
End Module m
program main
use m
use clrwin
call ENABLE_UTF8@(1)
i = winio@("%ws", cjan(2))
end |
|
|
Back to top |
|
 |
mecej4
Joined: 31 Oct 2006 Posts: 1899
|
Posted: Fri Jan 25, 2019 5:34 pm Post subject: |
|
|
Paul's work-around succeeds if the Fortran source file is saved as UTF-8 without BOM (byte order mark).
I tried with UTF-8 + BOM and with UTF-16 LE, and the compiler rejected these versions.
Similarly, I expect that the lexical intrinsics LGT, LGE, etc., will not work correctly with Cyrillic characters, so more elaborate coding will be needed to do such comparisons, sorting of words, etc. Therefore, before writing a lot of code, it would be necessary to make a full assessment of what kinds of processing will be performed. |
|
Back to top |
|
 |
|
|
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
|