Skip to content

Instantly share code, notes, and snippets.

@jhrmnn
Last active August 27, 2018 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhrmnn/9552865d78180effd2770dfda64b958e to your computer and use it in GitHub Desktop.
Save jhrmnn/9552865d78180effd2770dfda64b958e to your computer and use it in GitHub Desktop.
Real/complex polymorphism with a vanilla Fortran compiler
#ifndef INCLUDED
module mymod
implicit none
interface add_one
module procedure add_one_real
module procedure add_one_complex
end interface
contains
#endif
#ifndef TYPE
#define TYPE 0
#endif
#if TYPE == 0
subroutine add_one_real(x)
real(8), intent(inout) :: x
#elif TYPE == 1
subroutine add_one_complex(x)
complex(8), intent(inout) :: x
#endif
x = x + 1
end subroutine
#ifndef INCLUDED
#define INCLUDED
#undef TYPE
#define TYPE 1
#include "test.F90"
end module
program main
use mymod
implicit none
real(8) :: x
complex(8) :: z
call add_one(x)
call add_one(z)
end program
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment