SHARE
TWEET

Generic interface test

starm100 May 2nd, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. program swapper
  2. implicit none
  3. .
  4. .
  5. .
  6. interface swap
  7.     procedure swap_int, swap_real, swap_char, swap_int_real
  8. end interface swap
  9. .
  10. .
  11. .
  12. call swap(a,b)
  13. pause
  14.     contains
  15.  
  16.     elemental subroutine swap_int(a,b) !elemental позволяет использовать
  17.     integer,intent(inout)::a,b         !процедуру со скалярами и массивами
  18.     integer::temp
  19.     temp=a
  20.     a=b
  21.     b=temp
  22.     end subroutine swap_int
  23.    
  24.     elemental subroutine swap_real(a,b)
  25.     real,intent(inout)::a,b
  26.     real::temp
  27.     temp=a
  28.     a=b
  29.     b=temp
  30.     end subroutine swap_real
  31.    
  32.     elemental subroutine swap_char(a,b)
  33.     character(len=*),intent(inout)::a,b
  34.     character(len=len(a))::temp
  35.     temp=a
  36.     a=b
  37.     b=temp
  38.     end subroutine swap_char
  39.    
  40.     elemental subroutine swap_int_real(a,b)
  41.     integer,intent(inout)::a
  42.     integer::temp
  43.     real,intent(inout)::b
  44.     temp=real(a)
  45.     a=int(b)
  46.     b=temp
  47.     end subroutine swap_int_real
  48.    
  49. end program swapper
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