Returns a centered-difference of a 1-d array, with first order
differencing applied for the boundary points. This procedure is overloaded
by the generic procedure diff
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=rk), | intent(in), | dimension(:) | :: | x | Input array |
Nodes of different colours represent the following:
Solid arrows point from a procedure to one which it calls. Dashed arrows point from an interface to procedures which implement that interface. This could include the module procedures in a generic interface or the implementation in a submodule of an interface in a parent module.
pure function diff_1d(x) result(dx)
!! Returns a centered-difference of a 1-d array, with first order
!! differencing applied for the boundary points. This procedure is overloaded
!! by the generic procedure `diff`.
real(kind=rk),dimension(:),intent(in) :: x !! Input array
real(kind=rk),dimension(:),allocatable :: dx
integer(kind=ik) :: idm
idm = size(x)
allocate(dx(idm))
if(idm == 0)then
return
elseif(idm == 1)then
dx = 0
return
endif
dx(2:idm-1) = 0.5_rk*(x(3:idm)-x(1:idm-2))
dx(1) = x(2)-x(1)
dx(idm) = x(idm)-x(idm-1)
endfunction diff_1d