subroutine get_interp_factor_linear(xc,xp,factor)
! get factor for linear interpolation
! multi-D method
double precision :: xc(0:1,0:1,0:1,1:ndim),xp(1:ndim),factor(0:1,0:1,0:1)
integer :: ix1,ix2,ix3
double precision :: dxc1,dxc2,dxc3,xd1,xd2,xd3
dxc1=xc(1,1,1,1)-xc(0,0,0,1)
dxc2=xc(1,1,1,2)-xc(0,0,0,2)
dxc3=xc(1,1,1,3)-xc(0,0,0,3)
xd1=(xp(1)-xc(0,0,0,1))/dxc1
xd2=(xp(2)-xc(0,0,0,2))/dxc2
xd3=(xp(3)-xc(0,0,0,3))/dxc3
! interpolation factor
do ix1=0,1
do ix2=0,1
do ix3=0,1
factor(ix1,ix2,ix3)=abs(1-ix1-xd1)*abs(1-ix2-xd2)*abs(1-ix3-xd3)
enddo
enddo
enddo
end subroutine get_interp_factor_linear