!=============================================== ! dotprod.f90 ! calculate dot product and write result to ! a file !=============================================== program dotprod !------------------------------------------- ! module containing precision parameter !------------------------------------------- use prec_mod, only: rk !------------------------------------------- ! module containing derived type !------------------------------------------- use rvec3_mod, only: rvec3 implicit none integer :: i real(rk) :: c type(rvec3) :: a, b !------------------------------------------- ! set nvals for each vector !------------------------------------------- a%nvals = 3 b%nvals = 3 !---------------------------- ! input vectors !---------------------------- print*,'Enter first vector' read*, a%x print*,'Enter second vector' read*, b%x !---------------------------- ! calculate dot product !---------------------------- call dp(a%x, b%x, c) !---------------------------- ! check magnitude !---------------------------- if(abs(c) < 1.0e-6) then print*,'---------------------------------------------------' print*,'Warning: magnitude of dot product is less than 1e-6' print*,'---------------------------------------------------' endif !---------------------------- ! write result to file !---------------------------- open(21, file='dot.d') write(21, '(a, f6.3)') 'dot product = ', c close(21) print*,' ' print*,'Output written to file dot.d' end program dotprod