!------------------------------------------------------------------------------
!
!  Module name:
!
!    swap_module
!
!  Purpose:
!
!    This module defines a generic procedure for swapping reals, integers, 
!    logicals and points, where the type 'point' is defined with two real 
!    variables as components.
!
!------------------------------------------------------------------------------

MODULE swap_module

  IMPLICIT NONE

  TYPE point                    ! define type point
    REAL :: x, y
  END TYPE point

  INTERFACE swap                ! generic name
    MODULE PROCEDURE swapreal, swapint, swaplog, swappoint
  END INTERFACE

CONTAINS  

  SUBROUTINE swapreal(u,v)      ! module procedure to swap two reals

    REAL, INTENT(INOUT) :: u, v
    REAL :: temp

    temp = u
    u = v
    v = temp

  END SUBROUTINE swapreal

  SUBROUTINE swapint(u,v)       ! module procedure to swap two integers

    INTEGER, INTENT(INOUT) :: u, v
    INTEGER :: temp

    temp = u
    u = v
    v = temp

  END SUBROUTINE swapint

  SUBROUTINE swaplog(u,v)       ! module procedure to swap two logicals

    LOGICAL, INTENT(INOUT) :: u, v
    LOGICAL :: temp

    temp = u
    u = v
    v = temp

  END SUBROUTINE swaplog

  SUBROUTINE swappoint(u,v)     ! module procedure to swap two points

    TYPE(point), INTENT(INOUT) :: u, v
    TYPE(point) :: temp

    temp = u
    u = v
    v = temp

  END SUBROUTINE swappoint

END MODULE swap_module
