program wei_test
        use sep
        use sparse_matmult_fly_sym 

        implicit none
        real, dimension (:),       pointer   :: Hcube
        integer                              :: stat
        logical                              :: adj,add,value
        integer                              :: niter,na,np  ! iterations
        integer                              :: n1,n2,n3,n4,n5,n6,n7,n8,n9,n10 !nhx,nhy,naz,nax,nay,nhx,nhy,nz,nx,ny 
        integer(kind=8)                      :: bn1,bn2,bn3,bn4,bn5,bn6,bn7,bn8,bn9,bn10 !nhx,nhy,naz,nax,nay,nhx,nhy,nz,nx,ny
        real                                 :: o1,o2,o3,o4,o5,o6,o7,o8,o9,o10 
        real                                 :: d1,d2,d3,d4,d5,d6,d7,d8,d9,d10
        real                                 :: maxi 
        integer                              :: esize,i
!        integer, external                    :: sreed
        integer(kind=8)                      :: block
        integer, external                    :: fetch

        call initpar()
        call sep_begin_prog()

        if (exist_file("hess"))then
                call from_aux('hess','n1',n1); call from_aux('hess','d1',d1); call from_aux('hess','o1',o1)
                call from_aux('hess','n2',n2); call from_aux('hess','d2',d2); call from_aux('hess','o2',o2)
                call from_aux('hess','n3',n3); call from_aux('hess','d3',d3); call from_aux('hess','o3',o3)
                call from_aux('hess','n4',n4); call from_aux('hess','d4',d4); call from_aux('hess','o4',o4)
                call from_aux('hess','n5',n5); call from_aux('hess','d5',d5); call from_aux('hess','o5',o5)
                call from_aux('hess','n6',n6); call from_aux('hess','d6',d6); call from_aux('hess','o6',o6)
                call from_aux('hess','n7',n7); call from_aux('hess','d7',d7); call from_aux('hess','o7',o7)
                call from_aux('hess','n8',n8); call from_aux('hess','d8',d8); call from_aux('hess','o8',o8)
                call from_aux('hess','n9',n9); call from_aux('hess','d9',d9); call from_aux('hess','o9',o9)
                call from_aux('hess','n10',n10); call from_aux('hess','d10',d10); call from_aux('hess','o10',o10)
                call from_aux('hess',"esize",esize)
        else
            write(0,*)'Hey: you are very funny - You provided no Hessian Matrix'
                STOP
        endif

        bn1=n1;bn2=n2;bn3=n3;bn4=n4;bn5=n5;bn6=n6;bn7=n7;bn8=n8;bn9=n9;bn10=n10
        block=bn1*bn2*bn3*bn4*bn5*bn6*bn7*bn8*bn9*bn10
        write(0,*)"n1,n2,n3,n4,n5",n1,n2,n3,n4,n5
        write(0,*)"n6,n7,n8,n9,n10",n6,n7,n8,n9,n10
        write(0,*)"memory allocation";
        write(0,*)"block",block
        write(0,*)"Hcube",(4*block/1024/1024),"MB"

        allocate(Hcube(block))
! Sep format Hessian matrix
        do i=1,n6*n7*n8*n9*n10 
                write(0,*)'i, 1+(i-1)*n1*n2*n3*n4*n5,i*n1*n2*n3*n4*n5, 4*n1*n2*n3*n4*n5'
                write(0,*)i, 1+(i-1)*n1*n2*n3*n4*n5,i*n1*n2*n3*n4*n5, 4*n1*n2*n3*n4*n5
                call sreed("in",Hcube(1+(i-1)*n1*n2*n3*n4*n5:i*n1*n2*n3*n4*n5),4*n1*n2*n3*n4*n5) ; STOP
                !if  (sreed("in",Hcube(1+(i-1)*n1*n2*n3*n4*n5:i*n1*n2*n3*n4*n5),4*n1*n2*n3*n4*n5) /= 4*n1*n2*n3*n4*n5) then 
                        STOP
                !        call seperr("Error reading Hessian...")
                !endif
        enddo
STOP
        maxi=maxval(Hcube)
        write(0,*)"LtL max", maxi
        Hcube=(Hcube)
        call smatmult_init (Hcube,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10)

call sep_end_prog()

end program
