fortran

ファイルの読み書き

テキストファイルの書き込み

テキストファイルの読み込み(namelistなし)

real :: x open(10, file = 'hoge.txt') write(10, *) x close(10)

real :: x open(10, file = 'hoge.txt') read(10, *) x close(10)

テキストファイルの読み込み(namelistあり)

以下のような namelist を作成する (namelist.input)

以下のように読み込む (main.f90)

&param text = hoge lon = 140 x = 2d3

... character(10) :: text integer :: lon real(8) :: x namelist /param/ text, lon, x read(5, param) ...

実行

$ ./a.out < namelist.input

Tips

2重ループなどを抜ける時

    • goto 文を使う(他によい方法ある?)

        • do i = 1, 3 do j = 1, 3 do k = 1, 3 if k >=2 then goto 1 end end 1 continue end