!=============================================== ! 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) :: c1, c2 type(rvec3) :: a(2), b(2) !------------------------------------------- ! set nvals for each vector !------------------------------------------- a(1)%nvals = 2 a(2)%nvals = 3 b(1)%nvals = 20 b(2)%nvals = 30 !---------------------------- ! input vectors !---------------------------- a(1)%x = (/ 1,2,3 /) a(2)%x = (/ 1,2,3 /) b(1)%x = (/ 4,5,6 /) b(2)%x = (/ 4,5,6 /) !---------------------------- ! calculate dot product !---------------------------- call dp(a(1)%x, b(1)%x, c1) call dp(a(2)%x, b(2)%x, c2) print*,a print*,b !---------------------------- ! check magnitude !---------------------------- if(abs(c2) < 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, e9.3)') 'dot product = ', c2 write(21, '(a, es9.3)') 'dot product = ', c2 close(21) print*,' ' print*,'Output written to file dot.d' end program dotprod