SUBROUTINE SETUMATCACHEFLAG(NEWFLAG)
! Change caching mode of UMatCache,
! In:
! NewFlag [0,1]: new value for UMatCacheFlag.
! flag=1: Storing just the <ik|u|jk> integrals in order they arrive
! in (and only have room to do so).
! flag=0: Distribute integrals throughout the cache in the scheme
! described at the top.
INTEGER NEWFLAG
SELECT CASE (UMATCACHEFLAG)
CASE (1)
! We were in direct cache mode where values were distributed correctly throughout the cache.
IF (NEWFLAG == 0 .AND. .NOT. tSmallUMat) THEN
! We need to fill the cache properly with values from the small cache.
CALL FILLUPCACHE()
end if
END SELECT
UMATCACHEFLAG = NEWFLAG
SELECT CASE (NEWFLAG)
CASE (1)
IF (NSLOTS == NPAIRS) THEN ! we're storing every element, so we don't need to deal with different cacheing
UMATCACHEFLAG = 0
ELSE
UMATLABELS(1:NSLOTS, 1:NPAIRS) = 0
!Turn on the direct caching, and clear the cache.
end if
END SELECT
RETURN
END SUBROUTINE SETUMATCACHEFLAG