5
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Fortran で UTF-8

Last updated at Posted at 2020-03-02

追記:こういうページがあることを教えてもらいました。(SirBogmanさんより)
https://cyber.dabamos.de/programming/modernfortran/unicode.html
ISO 10646 は Unicode ではなく UTF-16 に近い代替物のようです。もう少し勉強する必要があるようです。

MFE §10.14 UTF-8 files

Modern Fortran Explained (MFE) 10.14 UTF-8 files

ifort 19.0 はファイルへの UFT-8 encoding に対応していたようです。絵文字が使えます。selected_char_kind の方では定数として定義されていないので (MFE §3.7.2) 出来ないものだと思っていました。

なお gfortran では selected_char_kind('ISO_10646') で 4 が出力されるので真面目に kind 定数が使えるようです。

ただコンソールの方はユニコード対応の powershell でもユニコード文字は出ないようです。よく分かりません。

program Hello
   implicit none
   integer, parameter :: iso10646 = selected_char_kind('ISO_10646')
 !  character(kind=iso10646):: q
   print *, iso10646
   
   
   open(19, file='unko.txt', encoding='utf-8')
   
   write(19, *) 'うんころな 😀 😁 😂🤟🤟🏻'

   write(19, *) '         オエーー鳥'
   write(19, *) '               ,, -―-、           '
   write(19, *) '           /     ヽ             '
   write(19, *) '       / ̄ ̄/  /i⌒ヽ、| オエーー!!!'
   write(19, *) '      /  (゜)/   / /       '
   write(19, *) '     /     ト、.,../ ,ー-、      '
   write(19, *) '    =彳      \\‘゚。、` ヽ。、o   '
   write(19, *) '    /          \\゚。、。、o   '
   write(19, *) '   /         /⌒ ヽ ヽU  o   '
   write(19, *) '   /         │   `ヽU ∴l   '
   write(19, *) '  │         │     U :l   '
   write(19, *) '                  |:!    '
   write(19, *) '                  U    '
   
   write(6, *) 'うんころな 😀 😁 😂🤟🤟🏻'
end program Hello

出力

コンソール

          -1
 縺・s縺薙m縺ェ縲€・ ・ ・、溟洟溟沛サ

unko.txt
絶滅危惧種 オエー鳥

 うんころな 😀 😁 😂🤟🤟🏻
          オエーー鳥
                ,, -―-、           
            /     ヽ             
        / ̄ ̄/  /i⌒ヽ、| オエーー!!!
       /  (゜)/   / /       
      /     ト、.,../ ,ー-、      
     =彳      \\‘゚。、` ヽ。、o   
     /          \\゚。、。、o   
    /         /⌒ ヽ ヽU  o   
    /         │   `ヽU ∴l   
   │         │     U :l   
                   |:!    
                  U    
5
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?