| 
									
										
										
										
											2018-06-17 08:44:10 -05:00
										 |  |  | subroutine encode174_91(message77,codeword)
 | 
					
						
							| 
									
										
										
										
											2018-05-28 12:11:41 -05:00
										 |  |  | !
 | 
					
						
							| 
									
										
										
										
											2018-06-17 08:44:10 -05:00
										 |  |  | ! Add a 14-bit CRC to a 77-bit message and return a 174-bit codeword
 | 
					
						
							|  |  |  | !
 | 
					
						
							|  |  |  | use, intrinsic :: iso_c_binding
 | 
					
						
							|  |  |  | use iso_c_binding, only: c_loc,c_size_t
 | 
					
						
							|  |  |  | use crc
 | 
					
						
							| 
									
										
										
										
											2018-05-28 12:11:41 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-30 10:24:59 -05:00
										 |  |  | integer, parameter:: N=174, K=91, M=N-K
 | 
					
						
							| 
									
										
										
										
											2018-06-17 08:44:10 -05:00
										 |  |  | character*91 tmpchar
 | 
					
						
							| 
									
										
										
										
											2018-05-28 12:11:41 -05:00
										 |  |  | integer*1 codeword(N)
 | 
					
						
							|  |  |  | integer*1 gen(M,K)
 | 
					
						
							| 
									
										
										
										
											2018-06-17 08:44:10 -05:00
										 |  |  | integer*1 message77(77),message(K)
 | 
					
						
							| 
									
										
										
										
											2018-05-28 12:11:41 -05:00
										 |  |  | integer*1 pchecks(M)
 | 
					
						
							| 
									
										
										
										
											2018-06-17 08:44:10 -05:00
										 |  |  | integer*1, target :: i1MsgBytes(12)
 | 
					
						
							| 
									
										
										
										
											2018-05-31 21:11:31 -05:00
										 |  |  | include "ldpc_174_91_c_generator.f90"
 | 
					
						
							| 
									
										
										
										
											2018-05-28 12:11:41 -05:00
										 |  |  | logical first
 | 
					
						
							|  |  |  | data first/.true./
 | 
					
						
							|  |  |  | save first,gen
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if( first ) then ! fill the generator matrix
 | 
					
						
							|  |  |  |   gen=0
 | 
					
						
							|  |  |  |   do i=1,M
 | 
					
						
							|  |  |  |     do j=1,23
 | 
					
						
							|  |  |  |       read(g(i)(j:j),"(Z1)") istr
 | 
					
						
							|  |  |  |         ibmax=4
 | 
					
						
							|  |  |  |         if(j.eq.23) ibmax=3 
 | 
					
						
							|  |  |  |         do jj=1, ibmax 
 | 
					
						
							|  |  |  |           icol=(j-1)*4+jj
 | 
					
						
							|  |  |  |           if( btest(istr,4-jj) ) gen(i,icol)=1
 | 
					
						
							|  |  |  |         enddo
 | 
					
						
							|  |  |  |     enddo
 | 
					
						
							|  |  |  |   enddo
 | 
					
						
							|  |  |  | first=.false.
 | 
					
						
							|  |  |  | endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-17 08:44:10 -05:00
										 |  |  | ! Add 14-bit CRC to form 91-bit message+CRC14
 | 
					
						
							|  |  |  | write(tmpchar,'(77i1)') message77
 | 
					
						
							|  |  |  | tmpchar(78:80)='000'
 | 
					
						
							|  |  |  | i1MsgBytes=0
 | 
					
						
							|  |  |  | read(tmpchar,'(10b8)') i1MsgBytes(1:10)
 | 
					
						
							|  |  |  | ncrc14 = crc14 (c_loc (i1MsgBytes), 12)
 | 
					
						
							|  |  |  | write(tmpchar(78:91),'(b14)') ncrc14
 | 
					
						
							|  |  |  | read(tmpchar,'(91i1)') message
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-28 12:11:41 -05:00
										 |  |  | do i=1,M
 | 
					
						
							|  |  |  |   nsum=0
 | 
					
						
							|  |  |  |   do j=1,K 
 | 
					
						
							|  |  |  |     nsum=nsum+message(j)*gen(i,j)
 | 
					
						
							|  |  |  |   enddo
 | 
					
						
							|  |  |  |   pchecks(i)=mod(nsum,2)
 | 
					
						
							|  |  |  | enddo
 | 
					
						
							| 
									
										
										
										
											2018-06-09 13:05:11 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | codeword(1:K)=message
 | 
					
						
							|  |  |  | codeword(K+1:N)=pchecks
 | 
					
						
							| 
									
										
										
										
											2018-05-28 12:11:41 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | return
 | 
					
						
							|  |  |  | end subroutine encode174_91
 |