module subprog !モジュールの宣言 implicit none !この宣言は必ず行う contains !この後にサブルーチンや関数を記述する subroutine swap(a, b) !サブルーチンの開始行 !implicit none !上記のimplicit文でモジュール内を設定 integer a,b integer tmp !主プログラムのtmpとは実態違う tmp = a a = b b = tmp end subtoutine swap !サブルーチンの終了行 end module subprog !モジュールの終了行 program exchange !主プログラム use subprog !モジュールsubprogの使用宣言 implicit none !この宣言は必ず行う integer :: x=77, y=9095, tmp=0 !初期値設定と整数型変数を宣言 write(*,*) 'x, y, tmp = ',x, y, tmp !確認のための出力 call swap(x, y) !モジュールサブルーチンを呼ぶ(x,yは実引数) write(*,*) 'x, y, tmp = ',x, y, tmp !確認のための出力 end program exchange !主プログラムの終了行