LuaJIT FFI to Fortran iso_c_binding example
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

verlet.f90 551B

12345678910111213141516171819202122
  1. module verlet
  2. use, intrinsic :: iso_c_binding
  3. implicit none
  4. type, bind(c) :: particle
  5. integer(c_int) :: n
  6. type(c_ptr) :: pos
  7. type(c_ptr) :: vel
  8. end type
  9. contains
  10. subroutine integrate(part, dt) bind(c)
  11. implicit none
  12. type(particle) :: part
  13. real(c_double), value :: dt
  14. real(c_double), pointer :: pos(:, :)
  15. real(c_double), pointer :: vel(:, :)
  16. call c_f_pointer(part%pos, pos, [3, part%n])
  17. call c_f_pointer(part%vel, vel, [3, part%n])
  18. pos(:, :) = pos(:, :) + vel(:, :)*dt
  19. end subroutine
  20. end module