test1.f90 Source File


This file depends on

sourcefile~~test1.f90~~EfferentGraph sourcefile~test1.f90 test1.f90 sourcefile~fordiff.f90 fordiff.f90 sourcefile~test1.f90->sourcefile~fordiff.f90

Source Code

!===============================================================================
module mod_func1

   use kinds
   implicit none

contains

   function func1(x) result(f)
      complex(rk), intent(in)  :: x
      complex(rk)              :: f

      f = x**2 + 2.0_rk*x

   end function func1

end module mod_func1
!===============================================================================



!===============================================================================
program test1

   use fordiff
   use mod_func1
   use forunittest

   implicit none

   real(rk) :: dfdx, expected_dfdx
   type(unit_test) :: ut

   ! compute derivative
   dfdx = derivative(f=func1, x=1.0_rk, h=tiny(0.0_rk))

   ! reference value
   expected_dfdx = 2.0_rk*(1.0_rk) + 2.0_rk

   ! check if derivative is correct
   call ut%check(dfdx, expected_dfdx, 1.0e-6_rk, 'test1' )

end program test1
!===============================================================================