1subroutine gen_q65_cwave(msg,ntxfreq,ntone_spacing,msgsent,cwave,nwave)
2
3! Encodes a Q65 message to yield complex cwave() at fsample = 96000 Hz
4
5  use packjt
6  use q65_encoding
7  parameter (NMAX=60*96000)
8  character*22 msg
9  character*22 msgsent          !Message as it will be received
10  character*37 msg37
11  real*8 t,dt,phi,f,f0,dfgen,dphi,twopi,tsym
12  complex cwave(NMAX)
13  integer codeword(65),itone(85)
14  integer icos7(0:6)
15  data icos7/2,5,6,0,4,1,3/     !Defines a 7x7 Costas array
16  data twopi/6.283185307179586476d0/
17  save
18
19  msgsent=msg
20  msg37=''
21  msg37(1:22)=msg
22  call get_q65_tones(msg37,codeword,itone)
23
24! Set up necessary constants
25  nsym=85
26  tsym=7200.d0/12000.d0
27  dt=1.d0/96000.d0
28  f0=ntxfreq
29  dfgen=ntone_spacing*12000.d0/7200.d0
30  phi=0.d0
31  dphi=twopi*dt*f0
32  i=0
33  nwave=85*7200*96000.d0/12000.d0
34  t=0.d0
35  j0=0
36  do i=1,nwave
37     t=t+dt
38     j=t/tsym + 1
39     if(j.gt.85) exit
40     if(j.ne.j0) then
41        f=f0 + itone(j)*dfgen
42        dphi=twopi*dt*f
43        j0=j
44     endif
45     phi=phi+dphi
46     if(phi.gt.twopi) phi=phi-twopi
47     xphi=phi
48     cwave(i)=cmplx(cos(xphi),-sin(xphi))
49  enddo
50
51999  return
52end subroutine gen_q65_cwave
53