Unit test for the complex_step module.
subroutine complex_step_test() implicit none integer :: i complex(wp) :: x real(wp) :: h,dfdx,dfdx2,dfdx3,dfdx4,err,err2,err3,err4 write(*,*) '' write(*,*) '---------------' write(*,*) ' complex_step_test' write(*,*) '---------------' write(*,*) '' x = cmplx(2.0_wp,0.0_wp,wp) h = 1.0e-10_wp call complex_step_derivative(test_func,x,h,dfdx) !write(*,*) '' !write(*,*) 'x :',x !write(*,*) 'dfdx :',dfdx !write(*,*) 'error :',real(test_deriv(x),wp) - dfdx !write(*,*) '' write(*,'(*(A30))') 'h', 'forward diff err', 'central diff err', 'central diff 4 err', 'complex step err' do i=1,200 h = 10.0_wp**(-i/10.0_wp) call complex_step_derivative(test_func,x,h,dfdx) call forward_diff(test_func,x,h,dfdx2) call central_diff(test_func,x,h,dfdx3) call central_diff_4(test_func,x,h,dfdx4) err = real(test_deriv(x),wp) - dfdx err2 = real(test_deriv(x),wp) - dfdx2 err3 = real(test_deriv(x),wp) - dfdx3 err4 = real(test_deriv(x),wp) - dfdx4 write(*,'(*(E30.16,1X))') h, err2, err3, err4, err end do contains !***************************************************************************************** !**************************************** function test_func(x) result(f) implicit none complex(wp),intent(in) :: x complex(wp) :: f f = exp(x) + sin(x) end function test_func !**************************************** !**************************************** function test_deriv(x) result(f) implicit none complex(wp),intent(in) :: x complex(wp) :: f f = exp(x) + cos(x) end function test_deriv !**************************************** end subroutine complex_step_test