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 

Cyrillic characters

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



Joined: 05 Jul 2006
Posts: 268

PostPosted: Tue Jan 22, 2019 9:15 pm    Post subject: Cyrillic characters Reply with quote

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



Joined: 31 Oct 2006
Posts: 1885

PostPosted: Wed Jan 23, 2019 2:01 am    Post subject: Reply with quote

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


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

PostPosted: Wed Jan 23, 2019 8:19 am    Post subject: Reply with quote

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



Joined: 30 Jul 2013
Posts: 1520
Location: Aerospace Valley

PostPosted: Wed Jan 23, 2019 10:57 am    Post subject: Reply with quote

Quote:
We collected all the systems to determine the best. Therefore, before you, probably, the most complete list of site designers in Runet. If you know the site builder, which is not in this list, you can add it through the form.


what's all that about when it's at home in Vladivostok ?

Surely something like this would be more appropriate ? ...

Quote:
«Серебряный мороз» - самый полный и фантастический компилятор в мире, включая Москву.
Возможности прямого построения графиков можно сделать более надежными, но мы уверены, что это будет исправлено в ближайшее время.
Apar от этого правила Clear Win ок. !

_________________
''Computers (HAL and MARVIN excepted) are incredibly rigid. They question nothing. Especially input data.Human beings are incredibly trusting of computers and don't check input data. Together cocking up even the simplest calculation ... Smile "
Back to top
View user's profile Send private message
simon



Joined: 05 Jul 2006
Posts: 268

PostPosted: Fri Jan 25, 2019 3:15 am    Post subject: Reply with quote

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


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

PostPosted: Fri Jan 25, 2019 9:15 am    Post subject: Reply with quote

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



Joined: 31 Oct 2006
Posts: 1885

PostPosted: Fri Jan 25, 2019 5:34 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support 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