Put a value into the cache.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(function_cache), | intent(inout) | :: | me | |||
integer, | intent(in) | :: | i |
index in the hash table |
||
real(kind=wp), | intent(in), | dimension(:) | :: | x |
independant variable vector (dimension |
|
real(kind=wp), | intent(in), | dimension(:) | :: | f |
function vector |
|
integer, | intent(in), | dimension(:) | :: | ifs |
elements of |
subroutine put_in_cache(me,i,x,f,ifs) implicit none class(function_cache),intent(inout) :: me integer,intent(in) :: i !! index in the hash table real(wp),dimension(:),intent(in) :: x !! independant variable vector (dimension `n`) real(wp),dimension(:),intent(in) :: f !! function vector `f(x)` (dimension `m`) integer,dimension(:),intent(in) :: ifs !! elements of `f` to add (should all be `>0, <=m`) real(wp),parameter :: null = huge(1.0_wp) !! an unusual value to initialize arrays if (allocated(me%c)) then if (i<=size(me%c)) then if (allocated(me%c(i)%x)) then ! we need to check if there is an x already there, ! which may already have some function indices present. ! if same x, then add the new indices to them. ! if a different x, then replace indices. if (all(me%c(i)%x==x)) then ! this x is already present in this location. ! so merge the new f,ifs into what is already there. if (allocated(me%c(i)%f)) then me%c(i)%ifs = unique([me%c(i)%ifs,ifs],& chunk_size=me%chunk_size) else allocate(me%c(i)%f(me%m)) me%c(i)%f = null ! initialize to an unusual value me%c(i)%ifs = ifs end if me%c(i)%f(ifs) = f(ifs) else ! replace existing x and f. me%c(i)%x = x me%c(i)%ifs = ifs if (allocated(me%c(i)%f)) deallocate(me%c(i)%f) allocate(me%c(i)%f(me%m)) me%c(i)%f = null ! initialize to an unusual value me%c(i)%f(ifs) = f(ifs) end if else ! new entry in the cache: me%c(i)%x = x allocate(me%c(i)%f(me%m)) me%c(i)%f = null ! initialize to an unusual value me%c(i)%ifs = ifs me%c(i)%f(ifs) = f(ifs) end if else error stop 'Error: invalid index in hash table.' end if else error stop 'Error: the cache has not been initialized.' end if end subroutine put_in_cache