📄 find_weights.c
字号:
// ------------------------------------------------------------------------
// Name: find_weights.c
// Author: R.H. Morelos-Zaragoza
// Date: February, 1996
//
// Description: Direct computation of the weight distribution of a linear
// block code given its generator matrix
//
// ------------------------------------------------------------------------
// This program is complementary material for the book:
//
// R.H. Morelos-Zaragoza, The Art of Error Correcting Coding, Wiley, 2002.
//
// ISBN 0471 49581 6
//
// This and other programs are available at http://the-art-of-ecc.com
//
// You may use this program for academic and personal purposes only.
// If this program is used to perform simulations whose results are
// published in a journal or book, please refer to the book above.
//
// The use of this program in a commercial product requires explicit
// written permission from the author. The author is not responsible or
// liable for damage or loss that may be caused by the use of this program.
//
// Copyright (c) 2002. Robert H. Morelos-Zaragoza. All rights reserved.
// ------------------------------------------------------------------------
#include <stdio.h>
#include <math.h>
main(argc,argv)
int argc;
char **argv;
{
int i1,i2,i3,i4,i5,i6,i7,i8;
int i,j,tot,n,k,l,d_H,sum;
double ii,jj,kk,nn;
int g[1000][1000];
int weight[1000];
int c[1000];
char fileG[100],fileH[100];
FILE *fp1,*fp2,*fopen();
void disp_matrix(),disp_array();
void int_to_bin();
if (argc != 4)
{
printf("Usage: %s n k file\n", argv[0]);
exit(1);
}
n = atoi(argv[1]);
k = atoi(argv[2]);
strcpy(fileG,argv[3]);
nn = (double) n;
kk = (double) k;
fp1 = fopen(fileG,"r");
for (i=0; i < n; i++)
weight[i] = 0;
for (i=0; i < k; i++)
{
for (j=0; j < n; j++)
fscanf(fp1,"%1d",&(g[i][j]));
fscanf(fp1,"\n");
}
fclose(fp1);
for (ii=0.0;ii<pow(2.0,kk);ii=ii+1.0)
{
int_to_bin(ii,c); /* Taking ii in increasing order clears c[] automatically */
sum = 0;
for (j=0; j<n; j++)
{
tot = 0;
for (l=0; l<k; l++)
{
tot = tot + c[l]*g[l][j];
}
tot = tot%2;
sum = sum + tot;
}
weight[sum]++;
}
disp_array(weight,n);
}
void int_to_bin(ii,c)
double ii;
int c[];
{
int i,j,q,r;
q = (int) ii;
j = 0;
while (q>0)
{
r = q%2;
q = q/2;
c[j] = r;
j++;
}
}
void disp_array(array,n)
int array[250];
int n;
{
int i;
printf("i \tA[i]\n");
for (i=0; i <= n; i++)
{
if (array[i] != 0)
{
printf("%d\t%d\n", i,array[i]);
}
}
}
void disp_matrix(matrix,n,k)
int matrix[250][250];
int n,k;
{
int i,j;
for (i=0; i < k; i++)
{
for (j=0; j < n; j++)
{
printf("%d ", matrix[i][j]);
}
printf("\n");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -