Last active
February 15, 2017 12:31
-
-
Save 0ncorhynchus/3d9fce8bd00349f6158503fe7bfd8ca9 to your computer and use it in GitHub Desktop.
Give a submodule as an argument in Fortran code
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
program main | |
use ops | |
implicit none | |
call exec(add) | |
call exec(sub) | |
end program main | |
subroutine exec(routine) | |
implicit none | |
interface | |
subroutine routine(ans, a, b) | |
implicit none | |
integer, intent(out) :: ans | |
integer, intent(in) :: a, b | |
end subroutine routine | |
end interface | |
integer :: ans, a, b | |
a = 7 | |
b = 3 | |
call routine(ans, a, b) | |
write(*, "('routine(',i3,',',i3,') = ',i3)") a, b, ans | |
end subroutine exec |
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
FC = gfortran | |
%.mod: %.f90 %.o | |
@: | |
%.o: %.f90 | |
$(COMPILE.f) $< | |
### PROJECT UNIQUE ### | |
TARGET = main | |
.PHONY: all | |
all: $(TARGET) | |
.PHONY: clean | |
clean: | |
rm -f *.o *.mod $(TARGET) | |
$(TARGET): main.o ops.o | |
$(LINK.f) -o $@ $^ | |
main.o: ops.mod |
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
module ops | |
implicit none | |
contains | |
subroutine add(ans, lhs, rhs) | |
implicit none | |
integer, intent(out) :: ans | |
integer, intent(in) :: lhs, rhs | |
ans = lhs + rhs | |
return | |
end subroutine add | |
subroutine sub(ans, lhs, rhs) | |
implicit none | |
integer, intent(out) :: ans | |
integer, intent(in) :: lhs, rhs | |
ans = lhs - rhs | |
return | |
end subroutine sub | |
end module ops |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment