WSJT-X/lib/ft4/genft4.f90

74 lines
1.7 KiB
Fortran
Raw Normal View History

subroutine genft4(msg0,ichk,msgsent,i4tone)
! s12 + 64symbols = 76 channel symbols 2.027s message duration
!
! Encode an FT4 message
! Input:
! - msg0 requested message to be transmitted
! - ichk if ichk=1, return only msgsent
! - msgsent message as it will be decoded
! - i4tone array of audio tone values, {0,1,2,3}
use iso_c_binding, only: c_loc,c_size_t
use packjt77
character*37 msg0
character*37 message !Message to be generated
character*37 msgsent !Message as it will be received
character*77 c77
2019-01-25 17:01:34 -05:00
integer*4 i4tone(76),itmp(64)
integer*1 codeword(128)
integer*1 msgbits(77)
integer*1 s12(12)
2019-01-25 17:01:34 -05:00
integer icos4(4)
real*8 xi(864),xq(864),pi,twopi
2019-01-25 17:01:34 -05:00
data icos4/0,1,3,2/
logical unpk77_success
twopi=8.*atan(1.0)
pi=twopi/2.0
message=msg0
do i=1, 37
if(ichar(message(i:i)).eq.0) then
message(i:37)=' '
exit
endif
enddo
do i=1,37 !Strip leading blanks
if(message(1:1).ne.' ') exit
message=message(i+1:)
enddo
i3=-1
n3=-1
call pack77(message,i3,n3,c77)
call unpack77(c77,0,msgsent,unpk77_success) !Unpack to get msgsent
if(ichk.eq.1) go to 999
read(c77,"(77i1)") msgbits
call encode_128_90(msgbits,codeword)
! Grayscale mapping:
! bits tone
! 00 0
! 01 1
! 11 2
! 10 3
!Create 144-bit channel vector:
do i=1,64
2019-01-22 12:01:28 -05:00
is=codeword(2*i)+2*codeword(2*i-1)
2019-01-25 17:01:34 -05:00
if(is.le.1) itmp(i)=is
if(is.eq.2) itmp(i)=3
if(is.eq.3) itmp(i)=2
enddo
2019-01-25 17:01:34 -05:00
i4tone(1:4)=icos4
i4tone(5:36)=itmp(1:32)
i4tone(37:40)=icos4
i4tone(41:72)=itmp(33:64)
i4tone(73:76)=icos4
999 return
end subroutine genft4