Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
certik committed Jan 3, 2012
1 parent 8544de9 commit 38da35d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
1 change: 1 addition & 0 deletions fortran/compile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

set -e
FFLAGS="-Wall -Wextra -Wimplicit-interface -fPIC -Werror -fmax-errors=1 -g -fbounds-check -fcheck-array-temporaries -fbacktrace"
gfortran $FFLAGS -c types.f90 -o types.o
gfortran $FFLAGS -c compute.f90 -o compute.o
gfortran $FFLAGS -c a.f90 -o a.o
gfortran $FFLAGS -o a a.o compute.o
25 changes: 16 additions & 9 deletions fortran/compute.f90
Original file line number Diff line number Diff line change
@@ -1,46 +1,53 @@
module compute

use types, only: dp
implicit none
private
public init, register_func, run
public init, register_func, run, dp

abstract interface
function derivs(x) result(y)
use types, only: dp
real(dp), intent(in) :: x(2)
real(dp) :: y(2)
end function
end interface

type eq
integer :: i
procedure(derivs) :: func
procedure(derivs), nopass, pointer :: func
end type

contains

subroutine init(d)
type(eq), intent(inout) :: d
d%func = NULL;
d%func => NULL()
end subroutine

subroutine register_func(d, func)
type(eq), intent(inout) :: d
procedure(derivs), intent(in) :: func
d%func => func;
procedure(derivs), pointer, intent(in) :: func
d%func => func
end subroutine

subroutine (d, x0, dt, n_steps)
subroutine run(d, x0, dt, n_steps)
type(eq), intent(in) :: d
real(dp), intent(in) :: x0(2), dt
integer, intent(in) :: n_steps

real(dp) :: x(2), dx(2), t
integer :: i
if (.not. associated(d%func)) then
print *, "d%func is not associated"
end if
x = x0
t = 0
do i = 1, n_steps
dx = d%func(x)
print *, x
x += dx * dt
t += dt
x = x + dx * dt
t = t + dt
end do
end subroutine

end module
9 changes: 9 additions & 0 deletions fortran/types.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module types

implicit none
private
public dp

integer, parameter :: dp=kind(0.d0)

end module

0 comments on commit 38da35d

Please sign in to comment.