forked from barak/LDPC-codes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextract_systematic.c
89 lines (68 loc) · 2.06 KB
/
extract_systematic.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* EXTRACT_SYSTEMATIC.C - Extract systematic positions. */
/* Copyright (c) 1995-2012 by Radford M. Neal.
*
* Permission is granted for anyone to copy, use, modify, and distribute
* these programs and accompanying documents for any purpose, provided
* this copyright notice is retained and prominently displayed, and note
* is made of any changes made to these programs. These 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 "blockio.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 *gen_file, *systematic_file;
FILE *systematicf;
int i;
/* Look at arguments. */
if (!(gen_file = argv[1])
|| !(systematic_file = argv[2])
|| argv[3])
{ usage();
}
if ((strcmp(gen_file,"-")==0) + (strcmp(systematic_file,"-")==0) > 1)
{ fprintf(stderr,"Can't read more than one stream from standard input\n");
exit(1);
}
/* Read generator matrix file, up to the point of finding out which
are the message bits. */
read_gen(gen_file,1,1);
/* Open file to write systematic positions to. */
systematicf = open_file_std(systematic_file,"w");
if (systematicf==NULL)
{ fprintf(stderr,"Can't create file for systematic positions: %s\n",systematic_file);
exit(1);
}
for (i = M; i<N; i++)
{ fprintf(systematicf,"%d\n",cols[i]);
}
if (ferror(systematicf) || fclose(systematicf)!=0)
{ fprintf(stderr,"Error writing systematic positions to %s\n",systematic_file);
exit(1);
}
return 0;
}
/* PRINT USAGE MESSAGE AND EXIT. */
void usage(void)
{ fprintf(stderr,
"Usage: extract gen-file systematic_file\n");
exit(1);
}