fortran66のブログ

fortran について書きます。

【メモ帳】アニメ gif

animated gif テスト

先人の馴らしてくれた道を進んで、実行例を作ることができました。
GIFフォーマットの詳細

次は LZW 部分に進みたいと思います。

実行結果

f:id:fortran66:20180422021827g:plain

ソース・プログラム

    program gif
      use, intrinsic :: iso_fortran_env 
      implicit none
      integer :: iw
      integer(int16) :: m
      integer(int16), parameter :: nx = 20, ny = 20
      type :: t_gif_header
        sequence  
        character(3) :: signature = 'GIF'
        character(3) :: version   = '89a' ! '87a'
        integer(int16) :: width  = nx
        integer(int16) :: height = ny
        integer(int8)  :: pck   = int(B'10001001', int8) 
        integer(int8)  :: background_color_index = 0
        integer(int8)  :: pixel_aspect_ratio     = 0
      end type  
      integer(int8), allocatable :: global_color_table(:)
      type (t_gif_header) :: head
      
      type :: t_image_block
        sequence
        integer(int8) :: image_separator = Z'2C'
        integer(int16) :: image_left_position = 00
        integer(int16) :: image_top_position  = 00
        integer(int16) :: image_width  = nx 
        integer(int16) :: image_height = ny
        integer(int8) :: pck = int(B'00000000', int8)
        ! local color table
        !integer(int8) :: LZW_minimum_code_size 
        !integer(int8) :: block_size  
        !integer(int8) :: image_data
        !integer(int8) :: block_terminator = Z'00'  
      end type t_image_block
      
      type :: t_graphic_control_extension
        sequence  
        integer(int8) :: extention_introducer  = Z'21'
        integer(int8) :: graphic_control_label = Z'F9'
        integer(int8) :: lock_size = Z'04'
        integer(int8) :: pck = Z'00'
        integer(int16) :: delay_time = 50 ! msec?
        integer(int8) :: transparent_color_index = 0
        integer(int8) :: block_terminator = Z'00'
      end type t_graphic_control_extension
      
      type :: t_application_extension ! for animation gif
        sequence  
        integer(int8) :: extension_intrducer = Z'21'
        integer(int8) :: extension_label = Z'FF'
        integer(int8) :: block_size_01 = Z'0B'
        character(len = 8) :: application_identifier = 'NETSCAPE'
        character(len = 3) :: application_authentication_code = '2.0'
        integer(int8) :: block_size_02 = Z'03' ! 0:block terminator
        integer(int8) :: n = Z'01' !application_data
        integer(int16) :: nloop = 0 ! 0:unlimited 
        integer(int8) :: block_terminator = Z'00'
      end type t_application_extension   
      
      type (t_image_block) :: img   
      type (t_graphic_control_extension) :: ext
      type (t_application_extension) :: anime
      integer :: nbits = 3
      integer, allocatable :: ipattern(:)
!
      open(newunit = iw, file = 'test.gif', access = 'stream')
!      
      allocate(global_color_table(3 * 2**nbits)) ! 
      global_color_table = 0
      global_color_table = int([0,0,0,255, 0, 0, 0,255,0, 0,0,255], int8) ! RGB
      write(iw) head      
      write(iw) global_color_table
!
      write(iw) anime
! Frame 1
      ipattern = [Z'11', Z'21', Z'22', Z'38', Z'33', Z'82']
      write(iw) ext 
      write(iw) img     
      write(iw) achar([nbits, 240])          
      write(iw) achar(spread(ipattern, 2, 40))
      write(iw) achar(00) ! block_terminator
! Frame 2
      ipattern = [Z'22', Z'32', Z'33', Z'18', Z'11', Z'83']
      write(iw) ext 
      write(iw) img     
      write(iw) achar([nbits, 240])          
      write(iw) achar(spread(ipattern, 2, 40))
      write(iw) achar(00) ! block_terminator
! Frame 3
      ipattern = [Z'33', Z'13', Z'11', Z'28', Z'22', Z'81']
      write(iw) ext 
      write(iw) img     
      write(iw) achar([nbits, 240])          
      write(iw) achar(spread(ipattern, 2, 40))
      write(iw) achar(00) ! block_terminator
!
      write(iw) achar(int(Z'3B'))    
    end program gif

【乞食速報】 インテル Parallel Studio XE 2019 ベータプログラム始まる!

Intel Fortran Ver. 19 beta

毎年、春先に始まり秋口に終わるベータプログラムが今年も始まりました。今年は十月十一日迄の模様です。

software.intel.com

F1 HELP が復活

手動で設定が必要です。ver.18 用も準備中のようです。
software.intel.com

新文法

coarray 方面では reduction 演算は入らず、event が入ったようです。

Fortran 2008 and Fortran 2018 Feature Summary
The Intel® Fortran Compiler now supports all features from the Fortran 2008 standard. The Intel® Fortran Compiler also supports features from the proposed draft Fortran 2018 standard. Additional features will be supported in future releases. Features from the proposed Fortran 2018 standard supported by the current version include:
Assumed type (TYPE(*))
Assumed rank (DIMENSION(..))
Relaxed restrictions on interoperable dummy arguments
C include file ISO_Fortran_binding.h for use by C code manipulating “C descriptors” used by Fortran
Coarray events
Intrinsic function coshape
Default accessibility for entities accessed from a module
Import Enhancements
All standard procedures in ISO_C_BINDING other than C_F_POINTER are now PURE

少し I/O に寄せた Modern Fortran 入門

独逸国 The Cyber Vanguard の Modern Fortran

cyber.dabamos.de

UNIX 系ですが key capture など、I/O 周りの小ネタが集められています。




また blog には Fortran がらみのネタが結構あります。
Lazy Reading | The Cyber Vanguard
Fortran2008 で書かれた FORTRAN I を C 言語に直すtranspiler
GitHub - bbohrer/fif: Fortran In Fortran (Fortran 57 compiler in Fortran 08)
など。

【メモ帳】gif 画像出力

アニメ gif が作りたくなって

なんとなくアニメ gif が出来るとうれしいなと思い立って、少し調べてみました。

以下のサイト、およびそこからリンクされているサイトをアニメを見ながら眺めること1時間。
最小サイズのgif画像とアニメーションgif – ソフトウェア開発日記

どうもデータ長を 8bit にすると、バイト単位で扱えるようになって楽な気がしたので実験してみることにしてみました。まずは静的な画像から。

実行結果

f:id:fortran66:20180421015217g:plain
f:id:fortran66:20180421014645g:plain

ソースプログラム

    program gif
      use, intrinsic :: iso_fortran_env 
      implicit none
      integer :: iw
      integer(int16) :: m, nx = 15, ny = 10
      type :: t_gif_header
        sequence  
        character(3) :: signature = 'GIF'
        character(3) :: version   = '89a' ! '87a'
        integer(int16) :: width
        integer(int16) :: height 
        integer(int8)  :: pck   = int(B'10001001', int8) 
        integer(int8)  :: background_color_index = 0
        integer(int8)  :: pixel_aspect_ratio     = 0
      end type  
      integer(int8), allocatable :: global_color_table(:)
      type (t_gif_header) :: head
      
      type :: t_image_block
        sequence
        integer(int8) :: image_separator = Z'2C'
        integer(int16) :: image_left_position = 00
        integer(int16) :: image_top_position  = 00
        integer(int16) :: image_width 
        integer(int16) :: image_height
        integer(int8) :: pck = int(B'00000000', int8)
        ! local color table
        !integer(int8) :: LZW_minimum_code_size 
        !integer(int8) :: block_size = 
        !integer(int8) :: image_data
        !integer(int8) :: block_terminator = Z'00'  
      end type t_image_block
      type (t_image_block) :: img    
      integer, allocatable :: ipattern(:)
!
!      open(newunit = iw, file = 'test.bin', access = 'stream')
      open(newunit = iw, file = 'test.gif', access = 'stream')
      head%width  = nx
      head%height = ny
      img%image_width  = nx
      img%image_height = ny
!      
      allocate(global_color_table(3 * 128)) ! 128?
      global_color_table = 0
      global_color_table = int([0,0,0,255, 0, 0, 0,255,0, 0,0,255], int8) ! RGB
      write(iw) head      
      write(iw) global_color_table
!
      ipattern = [01, 01, 01, 01, 01, 02, 02, 02, 02, 02, 03, 03, 03, 03, 03] ! RGB
!
      write(iw) img     
      write(iw) achar([07, 152])            ! 7+1 bit ~ 128 color, 152 data (150 RGB + 2 clear)
      write(iw) achar([ipattern, ipattern])
      write(iw) achar([ipattern, ipattern])
      write(iw) achar([ipattern, ipattern])
      write(iw) achar([ipattern, ipattern])
      write(iw) achar([128]) ! clear dictionary ?
      write(iw) achar([ipattern, ipattern])
      write(iw) achar([128]) ! clear dictionary ?
      write(iw) achar(00) ! block_terminator
      write(iw) achar(int(Z'3B'))    
    end program gif

データ 4bit 単位 8色

データ単位が 4bit なら2ピクセルで 1byte になるので分かりやすいはず。

実行結果

f:id:fortran66:20180421124217g:plain
f:id:fortran66:20180421124745p:plain

ソースプログラム

バイト内のオーダーが逆っぽいのが謎??勘違いしている?下位ビットから読む?

    program gif
      use, intrinsic :: iso_fortran_env 
      implicit none
      integer :: iw
      integer(int16) :: m, nx = 10, ny = 10
      type :: t_gif_header
        sequence  
        character(3) :: signature = 'GIF'
        character(3) :: version   = '89a' ! '87a'
        integer(int16) :: width
        integer(int16) :: height 
        integer(int8)  :: pck   = int(B'10001001', int8) 
        integer(int8)  :: background_color_index = 0
        integer(int8)  :: pixel_aspect_ratio     = 0
      end type  
      integer(int8), allocatable :: global_color_table(:)
      type (t_gif_header) :: head
      
      type :: t_image_block
        sequence
        integer(int8) :: image_separator = Z'2C'
        integer(int16) :: image_left_position = 00
        integer(int16) :: image_top_position  = 00
        integer(int16) :: image_width 
        integer(int16) :: image_height
        integer(int8) :: pck = int(B'00000000', int8)
        ! local color table
      end type t_image_block
      type (t_image_block) :: img    
!
      open(newunit = iw, file = 'test.gif', access = 'stream')
      head%width  = nx
      head%height = ny
      img%image_width  = nx
      img%image_height = ny
!      
      allocate(global_color_table(3 * 8)) ! 8?
      global_color_table = 0
      global_color_table = int([0,0,0,255, 0, 0, 0,255,0, 0,0,255], int8) ! RGB
      write(iw) head      
      write(iw) global_color_table
!
      write(iw) img     
      write(iw) achar([03, 60])            ! 3+1 bit ~ 8 color, 60 byte (100 RGB + 20 clear)
      write(iw) achar([Z'21', Z'13', Z'32', Z'18', Z'32', Z'81'])
      write(iw) achar([Z'21', Z'13', Z'32', Z'18', Z'32', Z'81'])
      write(iw) achar([Z'21', Z'13', Z'32', Z'18', Z'32', Z'81'])
      write(iw) achar([Z'21', Z'13', Z'32', Z'18', Z'32', Z'81'])
      write(iw) achar([Z'21', Z'13', Z'32', Z'18', Z'32', Z'81'])
      write(iw) achar([Z'21', Z'13', Z'32', Z'18', Z'32', Z'81'])
      write(iw) achar([Z'21', Z'13', Z'32', Z'18', Z'32', Z'81'])
      write(iw) achar([Z'21', Z'13', Z'32', Z'18', Z'32', Z'81'])
      write(iw) achar([Z'21', Z'13', Z'32', Z'18', Z'32', Z'81'])
      write(iw) achar([Z'21', Z'13', Z'32', Z'18', Z'32', Z'81'])
      write(iw) achar(00) ! block_terminator
      write(iw) achar(int(Z'3B'))    
    end program gif

fortran infograph 成立事情

"The various FORTRANs" by H. Oswald

fortran infograph 1964年頃
f:id:fortran66:20180418152932j:plain

archive.org
この後にある Oswald 氏による記事が fortran infograph 製作時に直面した FORTRAN 方言間の差異の問題と各種 FORTRAN 方言調査のまとめの表になっています。

コンピュータ博物館に実物が飾られているようです。
www.computerhistory.org

John Reid 氏による  2017 Fortran 六十歳

Fortran at 60

西暦2017年は、Fortran 誕生60年の年でした。英国人 John Reid 氏が歴史と展望を簡潔にまとめて語っています。

無料記事
academic.oup.com

A downside of the continued support of old
features is that Fortran is perceived as old and
outmoded. This is unfair to a language that
has evolved steadily.

Just as English has evolved to cope with
changed requirements, so has Fortran. It was
the first to consider incorporating parallel
programming into the heart of the language.

この文身した蛮族のような写真は如何なものかw 西夷英人伝か!
f:id:fortran66:20180417202526p:plain


1980アイコ十六歳 (河出文庫)

1980アイコ十六歳 (河出文庫)

IT NOW の Fortran 記事

academic.oup.com

academic.oup.com

academic.oup.com

academic.oup.com

academic.oup.com

FORTRAN II appeared for the 704 in June 1958 and later in the year for the 709 and 650. FORTRAN II introduced subroutines and the common block, amongst other things.
The first FORTRAN system on a non-IBM machine was ALTAC, an extended FORTRAN II, on
the Philco 2000 in 1960.The first system called FORTRAN on a non-IBM machine was FORTRAN I on a Univac SS80 in 1961. By 1961 IBM had eight different compilers on different systems and already language variations were causing such problems that IBM issued a manual contrasting the facilities in the eight compilers. A paper in Datamation in 1964 noted that 43 compilers existed in total. Fortran compilers are now available for computers of all sizes, from home PCs and Macs to supercomputers.

1964年 datamation 誌の FORTRAN 互換性の記事 (internet archive より)

archive.org

chapel 開発責任者が julia について言及

Cray の chapel 1.17 出る

年二回犬の毛が抜け替わる頃に、chapel の更新が出ます。言語上の変化はあまり無いような気がします。

インタビュー記事

www.nextplatform.com

Julia とのアプローチの違いについて

Chamberlain says. “We are both trying to be the ‘Python for HPC’ but Julia takes the approach of, ‘you’re already a Python programmer? Let’s bring you into our world of HPC,’ whereas Chapel is designed from the bottom up to talk to that base of existing HPC parallel programmers that see what they need to control in terms of a machine’s resources and how to map efficiently and want to build from higher level abstractions from there,”

セクシー言語 python
"The Sin" Franz von Stuck (1893)
f:id:fortran66:20180415005324j:plain