| 
									
										
										
										
											2016-07-02 12:15:41 +00:00
										 |  |  | program QRA64code
 | 
					
						
							| 
									
										
										
										
											2016-06-22 20:45:29 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! Provides examples of message packing, bit and symbol ordering,
 | 
					
						
							| 
									
										
										
										
											2016-07-02 12:15:41 +00:00
										 |  |  | ! QRA (63,12) encoding, and other necessary details of the QRA64
 | 
					
						
							| 
									
										
										
										
											2016-06-23 17:40:56 +00:00
										 |  |  | ! protocol.  Also permits simple simulations to measure performance
 | 
					
						
							|  |  |  | ! on an AWGN channel with secure time and frequency synchronization.
 | 
					
						
							| 
									
										
										
										
											2016-06-22 20:45:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-02 12:15:41 +00:00
										 |  |  | ! Return codes from qra64_dec:
 | 
					
						
							| 
									
										
										
										
											2016-06-23 13:58:18 +00:00
										 |  |  | !  irc=0    [?    ?    ?] AP0	(decoding with no a-priori information)
 | 
					
						
							|  |  |  | !  irc=1    [CQ   ?    ?] AP27
 | 
					
						
							| 
									
										
										
										
											2016-06-24 14:36:03 +00:00
										 |  |  | !  irc=2    [CQ   ?     ] AP42
 | 
					
						
							| 
									
										
										
										
											2016-06-23 13:58:18 +00:00
										 |  |  | !  irc=3    [CALL ?    ?] AP29
 | 
					
						
							| 
									
										
										
										
											2016-06-24 14:36:03 +00:00
										 |  |  | !  irc=4    [CALL ?     ] AP44
 | 
					
						
							| 
									
										
										
										
											2016-06-23 13:58:18 +00:00
										 |  |  | !  irc=5    [CALL CALL ?] AP57
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-22 20:45:29 +00:00
										 |  |  |   use packjt
 | 
					
						
							| 
									
										
										
										
											2016-06-29 19:12:46 +00:00
										 |  |  |   character*22 msg,msg0,msg1,decoded,cok*3,msgtype*10,arg*12
 | 
					
						
							|  |  |  |   character*6 mycall
 | 
					
						
							|  |  |  |   logical ltext
 | 
					
						
							| 
									
										
										
										
											2016-06-22 20:45:29 +00:00
										 |  |  |   integer dgen(12),sent(63),dec(12)
 | 
					
						
							|  |  |  |   real s3(0:63,1:63)
 | 
					
						
							|  |  |  |   include 'testmsg.f90'
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   nargs=iargc()
 | 
					
						
							| 
									
										
										
										
											2016-06-23 13:58:18 +00:00
										 |  |  |   if(nargs.lt.1) then
 | 
					
						
							| 
									
										
										
										
											2016-07-02 12:15:41 +00:00
										 |  |  |      print*,'Usage: qra64code "message" [snr2500] [Nrpt]'
 | 
					
						
							|  |  |  |      print*,'       qra64code -t [snr2500]'
 | 
					
						
							| 
									
										
										
										
											2016-06-22 20:45:29 +00:00
										 |  |  |      go to 999
 | 
					
						
							|  |  |  |   endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   call getarg(1,msg)                     !Get message from command line
 | 
					
						
							| 
									
										
										
										
											2016-06-23 13:58:18 +00:00
										 |  |  |   snr2500=10.0
 | 
					
						
							|  |  |  |   if(nargs.ge.2) then
 | 
					
						
							|  |  |  |      call getarg(2,arg)
 | 
					
						
							|  |  |  |      read(arg,*) snr2500
 | 
					
						
							|  |  |  |   endif
 | 
					
						
							|  |  |  |   sig=sqrt(2.0)*10.0**(0.05*(snr2500+29.7))
 | 
					
						
							| 
									
										
										
										
											2016-06-22 20:45:29 +00:00
										 |  |  |   nmsg=1
 | 
					
						
							| 
									
										
										
										
											2016-06-23 13:58:18 +00:00
										 |  |  |   nrpt=1
 | 
					
						
							|  |  |  |   if(msg(1:2).eq."-t") then
 | 
					
						
							|  |  |  |      nmsg=NTEST
 | 
					
						
							|  |  |  |   else
 | 
					
						
							|  |  |  |      if(nargs.ge.3) then
 | 
					
						
							|  |  |  |         call getarg(3,arg)
 | 
					
						
							|  |  |  |         read(arg,*) nrpt
 | 
					
						
							|  |  |  |      endif
 | 
					
						
							|  |  |  |   endif
 | 
					
						
							| 
									
										
										
										
											2016-06-22 20:45:29 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   write(*,1010)
 | 
					
						
							|  |  |  | 1010 format("     Message                 Decoded                Err? Type             rc"/77("-"))
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-23 13:58:18 +00:00
										 |  |  |   ngood=0
 | 
					
						
							|  |  |  |   nbad=0
 | 
					
						
							|  |  |  |   do nn=1,nrpt
 | 
					
						
							|  |  |  |      do imsg=1,nmsg
 | 
					
						
							|  |  |  |         if(nmsg.gt.1) msg=testmsg(imsg)
 | 
					
						
							|  |  |  |         call fmtmsg(msg,iz)                    !To upper, collapse mult blanks
 | 
					
						
							|  |  |  |         msg0=msg                               !Input message
 | 
					
						
							|  |  |  |         call chkmsg(msg,cok,nspecial,flip)     !See if it includes "OOO" report
 | 
					
						
							|  |  |  |         msg1=msg                               !Message without "OOO"
 | 
					
						
							|  |  |  |         call packmsg(msg1,dgen,itype)          !Pack message into 12 six-bit bytes
 | 
					
						
							|  |  |  |         msgtype=""
 | 
					
						
							|  |  |  |         if(itype.eq.1) msgtype="Std Msg"
 | 
					
						
							|  |  |  |         if(itype.eq.2) msgtype="Type 1 pfx"
 | 
					
						
							|  |  |  |         if(itype.eq.3) msgtype="Type 1 sfx"
 | 
					
						
							|  |  |  |         if(itype.eq.4) msgtype="Type 2 pfx"
 | 
					
						
							|  |  |  |         if(itype.eq.5) msgtype="Type 2 sfx"
 | 
					
						
							|  |  |  |         if(itype.eq.6) msgtype="Free text"
 | 
					
						
							| 
									
										
										
										
											2016-06-22 20:45:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-02 12:15:41 +00:00
										 |  |  |         call qra64_enc(dgen,sent)              !Encode using QRA64
 | 
					
						
							| 
									
										
										
										
											2016-06-22 20:45:29 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! Generate a simulated s3() array with moderately high S/N
 | 
					
						
							| 
									
										
										
										
											2016-06-23 13:58:18 +00:00
										 |  |  |         do j=1,63
 | 
					
						
							|  |  |  |            do i=0,63
 | 
					
						
							|  |  |  |               x=gran()
 | 
					
						
							|  |  |  |               y=gran()
 | 
					
						
							|  |  |  |               s3(i,j)=x*x + y*y
 | 
					
						
							|  |  |  |            enddo
 | 
					
						
							|  |  |  |            k=sent(j)
 | 
					
						
							|  |  |  |            x=gran() + sig
 | 
					
						
							|  |  |  |            y=gran()
 | 
					
						
							|  |  |  |            s3(k,j)=x*x + y*y
 | 
					
						
							| 
									
										
										
										
											2016-06-22 20:45:29 +00:00
										 |  |  |         enddo
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-29 19:12:46 +00:00
										 |  |  |         i1=index(msg1,' ')
 | 
					
						
							|  |  |  |         mycall='      '
 | 
					
						
							|  |  |  |         if(i1.ge.4) mycall=msg(1:i1-1)
 | 
					
						
							|  |  |  |         call packcall(mycall,nmycall,ltext)
 | 
					
						
							| 
									
										
										
										
											2016-07-19 13:16:10 +00:00
										 |  |  |         call qra64_dec(s3,nmycall,dec,snr,irc)            !Decode
 | 
					
						
							| 
									
										
										
										
											2016-06-29 19:12:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-23 13:58:18 +00:00
										 |  |  |         decoded="                      "
 | 
					
						
							|  |  |  |         if(irc.ge.0) then
 | 
					
						
							|  |  |  |            call unpackmsg(dec,decoded)           !Unpack the user message
 | 
					
						
							|  |  |  |            call fmtmsg(decoded,iz)
 | 
					
						
							|  |  |  |         else
 | 
					
						
							|  |  |  |            dec=0
 | 
					
						
							|  |  |  |         endif
 | 
					
						
							| 
									
										
										
										
											2016-06-22 20:45:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-23 13:58:18 +00:00
										 |  |  |         if(decoded.eq.msg0) then
 | 
					
						
							|  |  |  |            ngood=ngood+1
 | 
					
						
							|  |  |  |         else
 | 
					
						
							|  |  |  |            if(irc.ge.0) nbad=nbad+1
 | 
					
						
							|  |  |  |         endif
 | 
					
						
							|  |  |  |         ii=imsg
 | 
					
						
							|  |  |  |         if(nrpt.gt.1) ii=nn
 | 
					
						
							|  |  |  |         write(*,1020) ii,msg0,decoded,itype,msgtype,irc
 | 
					
						
							| 
									
										
										
										
											2016-06-23 15:50:59 +00:00
										 |  |  | 1020    format(i4,1x,a22,2x,a22,4x,i3,": ",a13,i3)
 | 
					
						
							| 
									
										
										
										
											2016-06-23 13:58:18 +00:00
										 |  |  |      enddo
 | 
					
						
							| 
									
										
										
										
											2016-06-22 20:45:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-23 13:58:18 +00:00
										 |  |  |      if(nmsg.eq.1 .and.nrpt.eq.1) then
 | 
					
						
							|  |  |  |         write(*,1030) dgen
 | 
					
						
							|  |  |  | 1030    format(/'Packed message, 6-bit symbols ',12i3) !Display packed symbols
 | 
					
						
							| 
									
										
										
										
											2016-06-22 20:45:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-23 13:58:18 +00:00
										 |  |  |         write(*,1040) sent
 | 
					
						
							|  |  |  | 1040    format(/'Information-carrying channel symbols'/(i5,20i3))
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         write(*,1050) dec
 | 
					
						
							|  |  |  | 1050    format(/'Received message, 6-bit symbols ',12i3) !Display packed symbols
 | 
					
						
							|  |  |  |      endif
 | 
					
						
							|  |  |  |   enddo
 | 
					
						
							| 
									
										
										
										
											2016-06-22 20:45:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-23 13:58:18 +00:00
										 |  |  |   if(nrpt.gt.1) then
 | 
					
						
							|  |  |  |      write(*,1060) ngood,nrpt,nbad
 | 
					
						
							| 
									
										
										
										
											2016-06-23 15:50:59 +00:00
										 |  |  | 1060 format('Decoded messages:',i5,'/',i4,'   Undetected errors:',i5)
 | 
					
						
							| 
									
										
										
										
											2016-06-22 20:45:29 +00:00
										 |  |  |   endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-02 12:15:41 +00:00
										 |  |  | 999 end program QRA64code
 |