js8call/lib/ldpc/peg/peg2alist

38 lines
926 B
Plaintext
Raw Normal View History

2018-02-08 21:28:33 -05:00
#!/opt/local/bin/octave -qf
# read a parity check matrix produced by the peg algorithm and
# convert to alist format so that it can be read using alist_to_pcheck
arg_list=argv();
filename=arg_list{1};
fid=fopen(filename,"r");
N=fscanf(fid,"%d",[1]);
M=fscanf(fid,"%d",[1]);
pcheck=zeros(M,N);
max_bits_in_check=fscanf(fid,"%d",[1]);
for i=1:M
vec=fscanf(fid,"%d",[max_bits_in_check]);
pcheck(i,vec(vec>0))=1;
endfor
max_bits_in_check2=max(sum(pcheck'));
max_checks_per_bit=max(sum(pcheck));
printf("%d %d\n",M,N);
printf("%d %d\n",max_bits_in_check2,max_checks_per_bit);
printf("%d ",sum(pcheck'));
printf("\n");
printf("%d ",sum(pcheck));
printf("\n");
for i=1:M
vec=find(pcheck(i,:)>0);
pr=zeros(1,max_bits_in_check2);
pr(1:size(vec)(2))=vec;
printf("%d ",pr);
printf("\n");
endfor
for i=1:N
vec=find(pcheck(:,i)>0);
pr=zeros(1,max_checks_per_bit);
pr(1:size(vec)(1))=vec;
printf("%d ",pr)
printf("\n");
endfor