SHARE
TWEET

module

starm100 May 15th, 2019 (edited) 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module swapp
  2. type derived
  3.     integer::index
  4.     real::value
  5. end type derived
  6. interface swap
  7.     module procedure swap_int,swap_real,swap_char,swap_int_real,swap_derived
  8. end interface
  9.     contains
  10.  
  11.     elemental subroutine swap_int(a,b)
  12.     integer,intent(inout)::a,b        
  13.     integer::temp
  14.     temp=a
  15.     a=b
  16.     b=temp
  17.     end subroutine swap_int
  18.    
  19.     elemental subroutine swap_real(a,b)
  20.     real,intent(inout)::a,b
  21.     real::temp
  22.     temp=a
  23.     a=b
  24.     b=temp
  25.     end subroutine swap_real
  26.    
  27.     elemental subroutine swap_char(a,b)
  28.     character(len=*),intent(inout)::a,b
  29.     character(len=len(a))::temp
  30.     temp=a
  31.     a=b
  32.     b=temp
  33.     end subroutine swap_char
  34.    
  35.     elemental subroutine swap_int_real(a,b)
  36.     integer,intent(inout)::a
  37.     integer::temp
  38.     real,intent(inout)::b
  39.     temp=real(a)
  40.     a=int(b)
  41.     b=temp
  42.     end subroutine swap_int_real
  43.    
  44.     elemental subroutine swap_derived(a,b)
  45.     type(derived),intent(inout)::a,b
  46.     type(derived),allocatable::temp
  47.     allocate (temp,source=a)
  48.     a=b
  49.     b=temp
  50.     end subroutine swap_derived
  51.    
  52. end module swapp
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top