! ========================================================
! How to define New operators (with name .MyOp.) in F90
! ========================================================

! --------------------------------------------------------
! (1) Write an ordinary function
! --------------------------------------------------------
  real function ComputeAvg(x, y)
   implicit none

   real, INTENT(IN) :: x
   real, INTENT(IN) :: y

   ComputeAvg = (x + y)/2.0
  end function


  PROGRAM Main
   implicit none

! -------------------------------------------------------------------------
! (2) Define interface for new operator function 
! -------------------------------------------------------------------------
   interface operator (.avg.)
    function ComputeAvg(x, y)
      real, INTENT(IN) :: x
      real, INTENT(IN) :: y
      real :: ComputeAvg
    end function
   end interface 

   REAL a, b, c

   a = 4; b = 8
   c = a .avg. b

   print *, "a = ", a, "   b = ", b, "c = a .avg. b = ", c
   print *

  END PROGRAM

