program ENE
  !! Compute energy
  !! Paul Sava (paul@sep.stanford.edu)
  !! 05/28/02

  !! output: energy

  use sep
  implicit none

  real, dimension(:,:),   allocatable :: data
  real, dimension(:),     allocatable :: ener
  integer :: n1,n2,n3,i3
  integer :: norm

  call sep_init()

  call from_history("n1",n1)
  call from_history("n2",n2)
  call from_history("n3",n3)

  call to_history("n1",n3); call to_history("d1",1)
  call to_history("n2",1)
  call to_history("n3",1)

  call from_param("norm",norm,2)
  write(0,*) "norm",norm
  call sep_close()

  allocate(data(n1,n2)); data=0.
  allocate(ener(n3));    ener=0

  select case(norm)
  case(1)
     do i3=1,n3
        call sep_read(data)
        ener(i3) = sum(abs(data))
        write (0,*) i3, ener(i3)
     end do
  case(2)
     do i3=1,n3
        call sep_read(data)
        ener(i3) = sum(data*data)
        write (0,*) i3, ener(i3)
     end do
  end select

  call sep_write(ener)
  call exit(0)
end program ENE













