📄 pchk-to-alist.c
字号:
/* ALIST-TO-PCHK.C - Convert a parity check matrix to alist format. *//* Copyright (c) 2006 by Radford M. Neal * * Permission is granted for anyone to copy, use, modify, or distribute this * program and accompanying programs and documents for any purpose, provided * this copyright notice is retained and prominently displayed, along with * a note saying that the original programs are available from Radford Neal's * web page, and note is made of any changes made to the programs. The * programs and documents are distributed without any warranty, express or * implied. As the programs were written for research purposes only, they have * not been tested to the degree that would be advisable in any important * application. All use of these programs is entirely at the user's own risk. */#include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>#include "alloc.h"#include "open.h"#include "mod2sparse.h"#include "mod2dense.h"#include "mod2convert.h"#include "rcode.h"void usage(void);/* MAIN PROGRAM. */int main( int argc, char **argv){ char *alist_file, *pchk_file; FILE *af, *pf; int mxrw, mxcw; int *rw, *cw; int i, j, k; mod2entry *e; int trans; trans = 0; for (;;) { if (argc>1 && strcmp(argv[1],"-t")==0) { trans = 1; argc -= 1; argv += 1; } else { break; } } if (argc!=3) { usage(); } pchk_file = argv[1]; alist_file = argv[2]; read_pchk(pchk_file); if (trans) { mod2sparse *HT; HT = H; H = mod2sparse_allocate(N,M); mod2sparse_transpose(HT,H); } af = open_file_std(alist_file,"wb"); if (af==NULL) { fprintf(stderr,"Can't create alist file: %s\n",alist_file); exit(1); } fprintf(af,"%d %d\n",M,N); rw = (int *) chk_alloc (M, sizeof *rw); mxrw = 0; for (i = 0; i<M; i++) { rw[i] = mod2sparse_count_row(H,i); if (rw[i]>mxrw) { mxrw = rw[i]; } } cw = (int *) chk_alloc (N, sizeof *cw); mxcw = 0; for (j = 0; j<N; j++) { cw[j] = mod2sparse_count_col(H,j); if (cw[j]>mxcw) { mxcw = cw[j]; } } fprintf(af,"%d %d\n",mxrw,mxcw); for (i = 0; i<M; i++) { fprintf(af,"%d%c",rw[i],i==M-1?'\n':' '); } for (j = 0; j<N; j++) { fprintf(af,"%d%c",cw[j],j==N-1?'\n':' '); } for (i = 0; i<M; i++) { e = mod2sparse_first_in_row(H,i); for (k = 0; k<mxrw; k++) { fprintf (af, "%d%c", mod2sparse_at_end(e)?0:mod2sparse_col(e)+1, k==mxrw-1?'\n':' '); if (!mod2sparse_at_end(e)) { e = mod2sparse_next_in_row(e); } } } for (j = 0; j<N; j++) { e = mod2sparse_first_in_col(H,j); for (k = 0; k<mxcw; k++) { fprintf (af, "%d%c", mod2sparse_at_end(e)?0:mod2sparse_row(e)+1, k==mxcw-1?'\n':' '); if (!mod2sparse_at_end(e)) { e = mod2sparse_next_in_col(e); } } } if (ferror(af) || fclose(af)!=0) { fprintf(stderr,"Error writing to alist file %s\n",alist_file); exit(1); } return 0;}/* PRINT USAGE MESSAGE AND EXIT. */void usage(void){ fprintf(stderr,"Usage: pchk-to-alist [ -t ] pchk-file alist-file\n"); exit(1);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -