module inicia

 implicit none

 integer, private			:: nw,nx,nz,nwind,nreal,dados

contains

!=======================================
subroutine genmodel(m0)
real	:: m0(:)
real	:: time,pi
integer	:: time0(8),seed(2)

  pi=4*atan(1.)
  time=0. 
  call date_and_time(values=time0)
  time = time0 (5) * 3600 + time0 (6) * 60 + time0 (7) + 0.001 * time0 (8)
  seed(1)=time
  seed(2)=int(log(time))
  call random_seed(put=seed)
  call random_number(m0)
  m0=2*(m0-0.5)*pi
end subroutine
!=======================================
subroutine gendata_init(nw_in,nx_in,nz_in,nwind_in,nreal_in,dados_in)
integer	:: nw_in,nx_in,nz_in,nwind_in,nreal_in,dados_in

nw=nw_in
nx=nx_in
nz=nz_in
nwind=nwind_in
nreal=nreal_in
dados=dados_in
write(0,*) nw,nx,nz,nwind,nreal,dados
end subroutine
!=======================================
subroutine gendata(data)
real	:: data(:),pi
integer	:: i,j,k

  pi=4*atan(1.)

do i=1,nx*nz
    j=(i-1)*nx*nz
    do k=1,nwind
        if (j+k+i-1 <= j+nx*nz .and. k < nz) then
            data(j+k+i-1)=(1-cos(pi*real(nwind-k+1)/real(nwind)))/2;
!            data(j+k+i-1)=(nwind-(k-1))/nwind;
!            data(j+k+i-1)=1.;
        end if
        if (j-k+i+1 > j .and. k < nz) then
            data(j-k+i+1)=(1-cos(pi*real(nwind-k+1)/real(nwind)))/2;
!            data(j-k+i+1)=(nwind-(k-1))/nwind;
!            data(j-k+i+1)=1.;
        end if
    end do
end do

!  do i=1,nx*nz
!     j=(i-1)*nx*nz
!     do k=1,nwind
!        if (j+k+i-1 <= j+nx*nz .and. k < nz) then
!           select case (dados)
!              case (1) ! cosine
!                 data(j+k+i-1)=(1-cos(pi*real(nwind-k+1)/real(nwind)))/2
!              case (2) ! triangular
!                 data(j+k+i-1)=(nwind-(k-1))/nwind
!              case (3) ! uniform
!                 data(j+k+i-1)=1.
!           end select
!        end if
!        if (j-k+i-1 > j .and. k < nz) then
!           select case (dados)
!              case (1) ! cosine
!                 data(j-k+i+1)=(1-cos(pi*real(nwind-k+1)/real(nwind)))/2
!              case (2) ! triangular
!                 data(j-k+i+1)=(nwind-(k-1))/nwind
!              case (3) ! uniform
!                 data(j-k+i+1)=1.
!           end select
!        end if
!     end do
!  end do
end subroutine

end module
