Last active
August 27, 2018 13:30
-
-
Save jhrmnn/9552865d78180effd2770dfda64b958e to your computer and use it in GitHub Desktop.
Real/complex polymorphism with a vanilla Fortran compiler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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