!------------------------------------
program model_build


use sep
implicit none
!-------------------------------------
integer					:: n1=1024, n2=1, n3=2048, n4=210, n5=1, i1, i2, i3, i4, i5
real 					:: alpha, pi, z0, d1=0.0025, d4=0.002
real, dimension(:,:,:,:,:), allocatable :: model  


!--------------------------------

call sep_init(SOURCE)

!call sep_init()

call to_history( "n1", n1)
call to_history( "n2", n2)
call to_history( "n3", n3)
call to_history( "n4", n4)
call to_history( "n5", n5)
call to_history( "d1", d1)
call to_history( "d4", d4)
call sep_close()

!n1=1024
!d1=0.0025
!n2=1
!n3=2048
!n4=210
!d4=0.002
!n5=1

allocate(model(n1,n2,n3,n4,n5)) 

z0=0.4                     ! Depth at m_x=0
alpha= 10                  ! Dipping angle (in degrees) 
pi=3.141592653

! Check that the dipping reflector is entirely in the model
!if (z0+tan(alpha/180*pi)<n4*d4 && z0-tan(alpha/180*pi)>0)

model=0;

do i1=1,n1
   i4=(z0-tan(alpha)*(n1/2-i1)*d1)/d4
   if (i4>0 .AND. i4<n4) model(i1,:,n3/2,i4,:)=1
end do

! call srite("out",model, n1*n2*n3*n4*n5*4)
call sep_write(model)
! write(0,*) "A"

deallocate(model)
call exit(0)

end program model_build
