! ------------------------------- ! Example program ! ! A simple user-defined data type ! with operator overloading ! ------------------------------- module structures type rational integer :: numer,denom end type rational interface operator (+) module procedure addrats end interface contains function addrats(rat1,rat2) result (sumrat) type(rational), intent(in):: rat1,rat2 type(rational):: sumrat integer:: a,b,c,d a = rat1%numer b = rat1%denom c = rat2%numer d = rat2%denom sumrat%numer = a*d+c*b sumrat%denom = b*d end function addrats end module structures program test use structures implicit none type(rational):: rat1,rat2 real(kind(1.d0)):: decimal rat1%numer = 2 rat1%denom = 3 rat2%numer = 1 rat2%denom = 5 write(*,'(i0,"/",i0)') rat1,rat2,rat1+rat2 end program test