subroutine read_cube(filename, cube)
implicit none
integer :: ios=0, i
integer :: v, y, x
real(xp) :: val
integer :: nv, ny, nx !cube dimension
integer :: nl
character(len=512), intent(in) :: filename
real(xp), intent(inout), dimension(:,:,:), allocatable :: cube
open(unit=11, file=filename, action="read", status="old", iostat=ios)
if (ios /= 0) stop "opening file error"
read(11,fmt=*) nv, ny, nx
nl = nv*ny*nx
allocate(cube(nv,ny,nx))
do i=1,nl
read(11,fmt=*) v, y, x, val
cube(v+1,y+1,x+1) = val
enddo
close(11)
end subroutine read_cube