Ejemplo n.º 1
0
int main
( int argc,
  char **argv
)
{
  mod2dense *D,*Z,*G;
  mod2sparse *T;
	int *a_col,*a_row;
	int *cols2;
  char *pchk_file;
 	char fn[128];
 	char *code;
 	FILE *fp;
 	
 	int i,j,n;
 	int a,b,c;
 	
 	int codeLen,checkLen;
 	
 	pchk_file = argv[3];
	
	sscanf(argv[1],"%ld",&codeLen);
	sscanf(argv[2],"%ld",&checkLen);
	
  sprintf(fn,"data/code%dX%d.bin",codeLen,checkLen);
  
  
  D = mod2dense_allocate( checkLen, codeLen );
  
  code=malloc(codeLen*checkLen);
	
	printf(" read from %s\n",fn);
	fp=fopen(fn,"rb");
	if( fp==NULL )
	{
		printf("open file error\n");
		return -1;
	}
	fread(code,codeLen*checkLen,1,fp);
	fclose(fp);

  mod2dense_clear( D );
  for( i=0;i<checkLen;i++ )
  	for( j=0;j<codeLen;j++ )
  	{
  		if( code[i*codeLen+j] )
  			mod2dense_set( D, i, j, 1 );
  	}
  
  
  T = mod2sparse_allocate( checkLen, codeLen );
  mod2dense_to_sparse( D , T );	
  
  fp = open_file_std(pchk_file,"wb");
  if (fp==NULL) 
  { fprintf(stderr,"Can't create parity check file: %s\n",pchk_file);
    exit(1);
  }

  intio_write(fp,('P'<<8)+0x80);
  
  if (ferror(fp) || !mod2sparse_write(fp,T) || fclose(fp)!=0)
  { fprintf(stderr,"Error writing to parity check file %s\n",pchk_file);
    exit(1);
  }
  
  free(code);
  
  return 0;
}
Ejemplo n.º 2
0
int main
( int argc,
  char **argv
)
{
  char *gen_file;
  int dprint;
  int i, j;

  dprint = 0;
  if (argc>1 && strcmp(argv[1],"-d")==0)
  { dprint = 1;
    argc -= 1;
    argv += 1;
  }

  if (!(gen_file = argv[1]) || argv[2])
  { usage();
  }

  read_gen(gen_file,0,1);

  switch (type)
  {
    case 's': 
    { 
      printf("\nGenerator matrix in %s (sparse representation):\n\n",gen_file);

      printf("Column order (message bits at end):\n");
      for (j = 0; j<N; j++) 
      { if (j%20==0) printf("\n");
        printf(" %3d",cols[j]);
      }
      printf("\n\n");

      printf("Row order:\n");
      for (i = 0; i<M; i++) 
      { if (i%20==0) printf("\n");
        printf(" %3d",rows[i]); 
      }
      printf("\n\n");

      if (dprint)
      { mod2dense *Ld, *Ud;
        Ld = mod2dense_allocate(M,M);
        Ud = mod2dense_allocate(M,N);
        mod2sparse_to_dense(L,Ld);
        mod2sparse_to_dense(U,Ud);
        printf("L:\n\n");
        mod2dense_print(stdout,Ld);
        printf("\n");
        printf("U:\n\n");
        mod2dense_print(stdout,Ud);
        printf("\n");
      }
      else
      { printf("L:\n\n");
        mod2sparse_print(stdout,L);
        printf("\n");
        printf("U:\n\n");
        mod2sparse_print(stdout,U);
        printf("\n");
      }
     
      break;
    }

    case 'd': case 'm':
    {
      if (type=='d')
      { printf("\nGenerator matrix in %s (dense representation):\n\n",gen_file);
      }
      if (type=='m')
      { printf("\nGenerator matrix in %s (mixed representation):\n\n",gen_file);
      }

      printf("Column order (message bits at end):\n");
      for (j = 0; j<N; j++) 
      { if (j%20==0) printf("\n");
        printf(" %3d",cols[j]);
      }
      printf("\n\n");

      printf (type=='d' ? "Inv(A) X B:\n\n" : "Inv(A):\n\n");
      mod2dense_print(stdout,G);
      printf("\n");

      break;
    }

    default: 
    { fprintf(stderr,"Unknown type of generator matrix file\n");
      exit(1);
    }
  }

  return 0;
}
Ejemplo n.º 3
0
int main
( int argc,
  char **argv
)
{
  mod2dense *D;
  mod2sparse *T;

  char *pchk_file;
  int dprint, trans;

  dprint = 0;
  trans = 0;

  for (;;)
  {
    if (argc>1 && strcmp(argv[1],"-d")==0)
    { dprint = 1;
      argc -= 1;
      argv += 1;
    }
    else if (argc>1 && strcmp(argv[1],"-t")==0)
    { trans = 1;
      argc -= 1;
      argv += 1;
    }
    else
    { break;
    }
  }

  if (!(pchk_file = argv[1]) || argv[2])
  { usage();
  }

  read_pchk(pchk_file);

  if (trans)
  { T = mod2sparse_allocate(N,M);
    mod2sparse_transpose(H,T);
  }

  if (dprint)
  { if (trans)
    { D = mod2dense_allocate(N,M);
      mod2sparse_to_dense(T,D);
      printf("\nTranspose of parity check matrix in %s (dense format):\n\n",
             pchk_file);
      mod2dense_print(stdout,D);
    }
    else
    { D = mod2dense_allocate(M,N);
      mod2sparse_to_dense(H,D);
      printf("\nParity check matrix in %s (dense format):\n\n",pchk_file);
      mod2dense_print(stdout,D);
    }
  }
  else /* sparse */
  { if (trans)
    { printf("\nTranspose of parity check matrix in %s (sparse format):\n\n",
             pchk_file);
      mod2sparse_print(stdout,T);
    }
    else
    { printf("\nParity check matrix in %s (sparse format):\n\n",pchk_file);
      mod2sparse_print(stdout,H);
    }
  }

  printf("\n");

  return 0;
}