!!
!! The routine subtracts dado1-dado2
!!
!!

  program Subtract

  use sep

  implicit none
  
  integer                           :: i1,i2,i3,n1,n2,n3
  real                              :: o1,o2,o3,d1,d2,d3
  real,dimension(:,:),allocatable   :: dado1, dado2, diff

  call sep_init()
  call sep_begin_prog()

  call from_param("n1",n1)
  call from_param("n2",n2)
  call from_param("n3",n3)
  call from_param("d1",d1)
  call from_param("d2",d2)
  call from_param("d3",d3)
  call from_param("o1",o1)
  call from_param("o2",o2)
  call from_param("o3",o3)


  !! write info out to history file
  call to_history("n1",n1)
  call to_history("n2",1)
  call to_history("n3",n3)
  call to_history("d1",d1)
  call to_history("d2",d2)
  call to_history("d3",d3)
  call to_history("o1",o1)
  call to_history("o2",o2)
  call to_history("o3",o3)

!
!! allocate working space
  allocate(dado1(n1,n2),dado2(n1,n2),diff(n1,n2))
 
!!
!! 
!!
  call sreed("in",dado1)
  call sreed(dado2,"dado2")

!  do i3=1,n3
!	call sreed_window("in",3,(/n1,n2,n3/),(/n1,n2,1/),(/0,0,i3-1/),(/1,1,1/),4,cdp)
!  	if (mod(i3,10).eq.1) write(0,*) "CMP  ", i3, " of ", n3
  	do i1=1,n1
		do i2=1,n2
			diff(i1,i2)=dado1(i1,i2)+dado2(i1,i2)
		end do
  	end do
!  end do
!!  call srite_window("out",2,(/n1,n3/),(/n1,1/),(/0,i3-1/),(/1,1/),4,dado)
  call srite("diff",diff,n1*n2*4)


!! clean up
  deallocate(dado1,dado2)

  call sep_end_prog()
  end program Subtract
