program main !主プログラム implicit none integer :: f1=11, f2=12, i, j, k open(f1, file = 'data1.dat') open(f2, file = 'data2.dat') call read_file(f1, i) !外部サブルーチンの呼び出し call read_file(f1, j) !同上 call read_file(f1, k) !同上 ! ... 処理演算 end program main subroutine read_file(fno,n) !外部サブルーチン implicit none integer fno, n read(fno, *) n write(*,*) n if ( n< 0 ) then write(*,*) 'error negative value' stop endif end subroutine read_file