Skip to content

Instantly share code, notes, and snippets.

@0ncorhynchus
Last active February 15, 2017 12:31
Show Gist options
  • Save 0ncorhynchus/3d9fce8bd00349f6158503fe7bfd8ca9 to your computer and use it in GitHub Desktop.
Save 0ncorhynchus/3d9fce8bd00349f6158503fe7bfd8ca9 to your computer and use it in GitHub Desktop.
Give a submodule as an argument in Fortran code
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
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
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