program add
  use sep
  integer :: i1,i2,i3,esize,n1,n2,n3
  real   , allocatable,dimension(:,:)  :: data1,data2
  complex, allocatable,dimension(:,:)  :: cdata1,cdata2

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

  call from_aux('file1',n1)
  call from_aux('file1',n2)
  call from_aux('file1',n3)
  call from_aux('file1',esize)
  
  if (esize==4) then
     allocate(data1(n1,n2),data2(n1,n2))
     do i3=1,n3
        call sep_read(data1,'file1')
        call sep_read(data2,'file2')
        do i2=1,n2
           do i1=1,n1
              data1(i1,i2)=data1(i1,i2)+data2(i1,i2)
           end do
        end do
        call sep_write(data1,'file1')
     end do
  deallocate(data1,data2)
  else
     allocate(cdata1(n1,n2),cdata2(n1,n2))
     do i3=1,n3
        call sep_read(cdata1,'file1')
        call sep_read(cdata2,'file2')
        do i2=1,n2
           do i1=1,n1
              cdata1(i1,i2)=cdata1(i1,i2)+cdata2(i1,i2)
           end do
        end do
        call sep_write(cdata1,'file1')
     end do
     deallocate(cdata1,cdata2)
  end if
end program add
