はじめに
大学のFortranの講義の予習として、ブログでメモ代わりに記録しておく。直感的な理解を優先するため、厳密な内容は避けます。
Fortranとは
Fortranは、汎用で命令型のコンパイラ言語です。1950年代にIBMによって開発され、科学分野において広く使われてきました。Fortranは、数値気象予報、計算流体力学、地球物理学などの分野で活躍しています。
Fortranの予習内容
- 標準入出力(standard input/output)
条件分岐(conditional branch)反復処理(loop)- 組み込み関数(built-in function)
- 多重ループ(multi-loop)
条件付き反復処理(conditional loop)配列(array)- 書式指定(format specification)
- 多次元配列(multidimensional array)
- ファイル操作(file handling)
- 副プログラム(subprogram)
- 外部ルーチン・外部関数(external routine, function)
- 内部ルーチン・内部関数(internal routine, function)
- モジュール(module)
変数
今回は第0回として、変数を扱います。
以下の具体例を参照しながら解説します。まずimplicit noneですべての変数を明示的に宣言すると定めます(意図しない方の変数が生まれることを防ぐ)。
そのあとに、(型) :: (変数名)のように宣言します。ほかのプログラミング言語と流れはほぼ同じですね。
具体例(変数を宣言、値を代入、表示)
program example implicit none integer :: count real :: temperature character(len=10) :: name logical :: isTrue count = 10 temperature = 25.6 name = 'John Doe' isTrue = .true. print *, 'Count: ', count print *, 'Temperature: ', temperature print *, 'Name: ', name print *, 'Is True: ', isTrue end program example
まとめ
今回はFortranの概要と変数について解説しました。内容を進めていくうちにFortranの長所を感じていけるとよいですね。
次回の第1回は標準入出力です。
注意
このページは大学のFortranの授業の予習で書いています。
直観的な理解をメモしているだけなので、厳密なところでは誤りがあるかもしれません。
→第1回 標準入出力