program main
  use sep
  implicit none

  real   , dimension(:), allocatable :: dat1, dat2
  real   , dimension(:), allocatable :: mod1, mod2
  complex, dimension(:), allocatable :: cdat1, cdat2
  complex, dimension(:), allocatable :: cmod1, cmod2
  real                               :: dot(2)
  complex                            :: cdot(2)
  integer                            :: nd1, nd2, nd3, nd4, nd5
  integer                            :: nm1, nm2, nm3, nm4, nm5
  integer                            :: ndat, nmod, esize_dat, esize_mod


  call sep_init(SOURCE)
  call getch_add_string("head=/dev/null")
  call getch_add_string("noheader=y")
  call set_no_putch()
  call sep_begin_prog()

  call from_aux("dat1", "n1", nd1)
  call from_aux("dat1", "n2", nd2)
  call from_aux("dat1", "n3", nd3)
  call from_aux("dat1", "n4", nd4)
  call from_aux("dat1", "n5", nd5) 
  call from_aux("dat1", "esize", esize_dat)

  call from_aux("mod1", "n1", nm1)
  call from_aux("mod1", "n2", nm2)
  call from_aux("mod1", "n3", nm3)
  call from_aux("mod1", "n4", nm4)
  call from_aux("mod1", "n5", nm5)
  call from_aux("mod1", "esize", esize_mod)

  ndat = nd1*nd2*nd3*nd4*nd5
  nmod = nm1*nm2*nm3*nm4*nm5

  if (esize_dat == 4) then
     allocate(dat1(ndat), dat2(ndat))
     call sep_read(dat1, "dat1")
     call sep_read(dat2, "dat2")
     dot(1) = sum(dat1*dat2)
     write(0,*)"dot(1)=", dot(1)
  else
     allocate(cdat1(ndat), cdat2(ndat))
     call sep_read(cdat1, "dat1")
     call sep_read(cdat2, "dat2")
     cdot(1) = sum(cdat1*conjg(cdat2))
     write(0,*)"cdot(1)=", cdot(1)
  end if

  if (esize_mod == 4) then
     allocate(mod1(nmod), mod2(nmod))
     call sep_read(mod1, "mod1")
     call sep_read(mod2, "mod2")
     dot(2) = sum(mod1*mod2)
     write(0,*)"dot(2)=", dot(2)
  else
     allocate(cmod1(nmod), cmod2(nmod))
     call sep_read(cmod1, "mod1")
     call sep_read(cmod2, "mod2")
     cdot(2) = sum(cmod1*conjg(cmod2))
     write(0,*)"cdot(2)=", cdot(2)
  end if


end program
