module inicia
 implicit none
 integer, private			:: nw,nx,nz,nwind,nreal,dados
 contains
!=======================================
subroutine genmodel(m0)
real	:: m0(:)
real	:: time
integer	:: time0(8),seed(2)
  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)
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,*) "================="
write(0,1) " nw =    ",nw
write(0,1) " nx =    ",nx
write(0,1) " nz =    ",nz
write(0,1) " nwind = ",nwind
write(0,1) " nreal = ",nreal
if (dados==1) write(0,*) "shape = cosine"
if (dados==2) write(0,*) "shape = triangle"
if (dados==3) write(0,*) "shape = uniform"
write(0,*) "================="
1 format(a9,i5)
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
           if (dados.eq.1) data(j+k+i-1)=(1-cos(pi*real(nwind-k+1)/real(nwind)))/2;
           if (dados.eq.2) data(j+k+i-1)=(nwind-(k-1))/nwind;
           if (dados.eq.3) data(j+k+i-1)=1.;
        end if
        if (j-k+i+1 > j .and. k < nz) then
           if (dados.eq.1) data(j-k+i+1)=(1-cos(pi*real(nwind-k+1)/real(nwind)))/2;
           if (dados.eq.2) data(j-k+i+1)=(nwind-(k-1))/nwind;
           if (dados.eq.3) data(j-k+i+1)=1.;
        end if
    end do
end do
data=data*nw*0.333
end subroutine
!=======================================
subroutine gendataw(data)
real	:: data(:),pi
integer	:: i,k
pi=4*atan(1.)
do k=1,nwind
   if (dados.eq.1)  data(nwind+k)=(1-cos(pi*real(nwind-k+1)/real(nwind)))/2
   if (dados.eq.2)  data(nwind+k)=(nwind-(k-1))/nwind
   if (dados.eq.3)  data(nwind+k)=1.
end do
do k=1,nwind
   data(k)=data(2*nwind-k+2)
end do

end subroutine
!=======================================
end module
