// ------------------------------------------------------------------------ // File: WD_linear_code.c // // Compute the weight distribution of a linear block code // from 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 #include main() { int i, j, l, n, k, g[63][64]; long ii, iifinal, weight[64], sum, tot; char name1[40],name2[40]; FILE *fp1,*fp2; printf("Compute the weight distribution of a linear code\n"); printf(" by Robert H. Morelos-Zaragoza (c) 1997\n"); printf("------------------------------------------------\n"); printf("INPUT file name, N, K and OUTPUT file name?\n"); scanf("%s %d %d %s", name1, &n, &k, name2); fp1 = fopen(name1,"r"); printf("\nGenerator matrix of (%d,%d) code:\n",n,k); for (i=0; i < k; i++) { for (j=0; j < n; j++) { fscanf(fp1,"%1d",&g[i][j]); printf("%1d",g[i][j]); } printf("\n"); } printf("\n"); fclose(fp1); fp2 = fopen(name2,"w"); fprintf(fp2,"%d\n",k); for (i=0; i<=n; i++) weight[i] = 0; iifinal = 1; for (i=0; i>l) & g[l][j]); tot = tot % 2; sum = sum + tot; } weight[sum]++; } printf("\n i \tW[i]\n"); printf("-------------\n"); for (i=0; i <= n; i++) if (weight[i] != 0) { fprintf(fp2,"%d\t%ld\n", i,weight[i]); printf("%3d\t%ld\n", i,weight[i]); } fclose(fp2); }