module data implicit none save type coord real*8 :: x,y,z end type coord end module data program example2 use data implicit none type (coord) :: p1,p2 real*8 :: d p1%x=1.d0 p1%y=2.d0 p1%z=0.d0 p2%x=3.d0 p2%y=0.d0 p2%z=1.d0 call sub(p1,p2,d) write(*,*) 'Distance between points p1 and p2 is', d stop end program example2 subroutine sub(p1,p2,d) use data implicit none type (coord), intent(in) :: p1,p2 real*8 , intent(out) :: d d=dsqrt( (p1%x - p2%x)**2 + (p1%y - p2%y)**2 + (p1%z - p2%z)**2 ) return end subroutine sub