module deriv ! ======================================================================= ! Helper Function - get derivative data ! ======================================================================= contains subroutine get_deriv_data(tt, yy, dd, mode) use typedef, only: & int32, real64 use integrate, only: & template use deriv_data, only: & MODE_DIRECT, MODE_SECULAR, & MODE_DIRECT3H, MODE_DIRECT3F, & MODE_DIRECT4P, MODE_DIRECT4H, MODE_DIRECT4F, & MODE_N_CONST, & local_data, local_store use binary, only: & direct, secular use ternary, only: & direct3h, direct3f use quaternary, only: & direct4p, direct4h, direct4f implicit none real(kind=real64), intent(in), dimension(:) :: & tt real(kind=real64), intent(in), dimension(:,:) :: & yy real(kind=real64), intent(out), dimension(:,:) :: & dd integer(kind=int32), intent(in) :: & mode real(kind=real64), dimension(:), allocatable :: & tmp integer(kind=int32) :: & i, mdata, nt, nd, md, ny, my logical :: & save_store procedure(template), pointer :: & f mdata = MODE_N_CONST(mode) select case(mode) case (MODE_DIRECT) f => direct case (MODE_SECULAR) f => secular case(MODE_DIRECT3H) f => direct3h case(MODE_DIRECT3F) f => direct3f case(MODE_DIRECT4P) f => direct4p case(MODE_DIRECT4H) f => direct4h case(MODE_DIRECT4F) f => direct4f case default stop '[get_deriv_data] unknown mode' end select nt = size(tt, 1) nd = size(dd, 2) md = size(dd, 1) ny = size(yy, 2) my = size(yy, 1) if (nt /= ny) stop '[get_deriv_data] mismatch dimension tt, yy' if (md /= mdata) stop '[get_deriv_data] dd data dimensiontoo mismatch' if (nd /= nt) stop '[get_deriv_data] dd time dimensiontoo mismatch' allocate(tmp(my)) save_store = local_store local_store = .True. do i=1, nt tmp(:) = f(tt(i),yy(:,i)) dd(1:mdata, i) = local_data(1:mdata) enddo local_store = save_store deallocate(tmp) end subroutine get_deriv_data end module deriv