annotate Meerwald/cmp_kund2_sig.c @ 20:bd669312f068

suppress warnings, fix link errors
author Peter Meerwald-Stadler <pmeerw@pmeerw.net>
date Sat, 28 Jan 2023 23:54:58 +0100
parents ad1d224896c5
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1 #include "wm.h"
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2 #include "signature.h"
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
3
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
4 char *progname;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
5
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
6 void usage(void) {
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
7 fprintf(stderr, "usage: %s [-h] [-C] [-o file] [-v n] -s file file\n\n", progname);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
8 fprintf(stderr, "\t-C\t\toutput correlation only\n");
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
9 fprintf(stderr, "\t-h\t\tprint usage\n");
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
10 fprintf(stderr, "\t-o file\t\toutput file\n");
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
11 fprintf(stderr, "\t-s file\t\toriginal signature file\n");
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
12 fprintf(stderr, "\t-v n\t\tverbosity level\n");
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
13 exit(0);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
14 }
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
15
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
16 int main(int argc, char *argv[]) {
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
17
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
18 FILE *in = stdin;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
19 FILE *out = stdout;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
20 FILE *sig = NULL;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
21
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
22 char signature_name[MAXPATHLEN];
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
23 char output_name[MAXPATHLEN] = "(stdout)";
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
24 char input_name[MAXPATHLEN] = "(stdin)";
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
25
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
26 char *binstr;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
27
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
28 int correlation_only = 0;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
29
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
30 int c, i;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
31 int quality = 0;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
32 int blocksize = 0;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
33 int corr = 0, match = 0;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
34 int verbose = 0;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
35 int filter = 0;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
36 int method = 0;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
37 int level = 0;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
38 char filter_name[MAXPATHLEN] = "";
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
39 int k;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
40
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
41 int seed;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
42 char line[32];
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
43
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
44 progname = argv[0];
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
45
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
46 while ((c = getopt(argc, argv, "h?Co:s:v:")) != EOF) {
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
47 switch (c) {
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
48 case 'h':
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
49 case '?':
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
50 usage();
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
51 break;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
52 case 'C':
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
53 correlation_only = 1;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
54 break;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
55 case 'o':
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
56 if ((out = fopen(optarg, "w")) == NULL) {
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
57 fprintf(stderr, "%s: unable to open output file %s\n", progname, optarg);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
58 exit(1);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
59 }
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
60 strcpy(output_name, optarg);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
61 break;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
62 case 's':
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
63 if ((sig = fopen(optarg, "r")) == NULL) {
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
64 fprintf(stderr, "%s: unable to open signature file %s\n", progname, optarg);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
65 exit(1);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
66 }
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
67 strcpy(signature_name, optarg);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
68 break;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
69 case 'v':
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
70 verbose = atoi(optarg);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
71 if (verbose < 0) {
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
72 fprintf(stderr, "%s: verbosity level %d out of range\n", progname, verbose);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
73 exit(1);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
74 }
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
75 break;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
76 }
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
77 }
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
78
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
79 argc -= optind;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
80 argv += optind;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
81
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
82 if (argc > 1) {
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
83 usage();
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
84 exit(1);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
85 }
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
86
8
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 3
diff changeset
87 if (argc == 1 && *argv[0] != '-') {
3
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
88 if ((in = fopen(argv[0], "r")) == NULL) {
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
89 fprintf(stderr, "%s: unable to open input file %s\n", progname, argv[0]);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
90 exit(1);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
91 }
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
92 else
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
93 strcpy(input_name, argv[0]);
8
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 3
diff changeset
94 }
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 3
diff changeset
95
3
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
96 if (sig) {
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
97 fgets(line, sizeof(line), sig);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
98 if (strspn(line, "KD2SG") >= 5) {
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
99 fscanf(sig, "%d\n", &nbit_signature1);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
100 fscanf(sig, "%d\n", &quality);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
101 fscanf(sig, "%d\n", &blocksize);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
102 fscanf(sig, "%d\n", &method);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
103 fscanf(sig, "%d\n", &filter);
15
ad1d224896c5 fix scanf() warning
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 8
diff changeset
104 fscanf(sig, "%[^\n\r]\n", filter_name);
3
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
105 fscanf(sig, "%d\n", &level);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
106 fscanf(sig, "%d\n", &seed);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
107 srandom(seed);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
108 n_signature1 = NBITSTOBYTES(nbit_signature1);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
109
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
110 binstr = malloc((nbit_signature1 + 1) * sizeof(char));
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
111 fscanf(sig, "%[01]\n", binstr);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
112 binstr_to_sig1(binstr);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
113 free(binstr);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
114 }
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
115 else {
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
116 fprintf(stderr, "%s: invalid signature file %s\n", progname, signature_name);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
117 exit(1);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
118 }
8
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 3
diff changeset
119 fclose(sig);
3
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
120 }
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
121 else {
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
122 fprintf(stderr, "%s: original signature file not specified, use -s file option\n", progname);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
123 exit(1);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
124 }
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
125
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
126 fgets(line, sizeof(line), in);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
127 if (strspn(line, "KD2WM") >= 5) {
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
128 int max_nbit_signature;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
129 int min_nbit_signature = -1;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
130 double pe[100];
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
131 double pe_sum;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
132 double alpha[100];
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
133 char *w[100];
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
134
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
135 fscanf(in, "%d\n", &max_nbit_signature);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
136
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
137 k = 0;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
138 while (!feof(in) && k < 100) {
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
139 int e;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
140
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
141 fscanf(in, "%d\n", &nbit_signature2);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
142 w[k] = binstr = malloc(sizeof(char) * (nbit_signature2 + 1));
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
143 fscanf(in, "%[01]\n", binstr);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
144
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
145 binstr_to_sig2(binstr);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
146
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
147 if (nbit_signature2 < min_nbit_signature || min_nbit_signature == -1)
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
148 min_nbit_signature = nbit_signature2;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
149 e = 0;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
150 for (i = 0; i < nbit_signature2; i += 2) {
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
151 if (get_signature1_bit(i % nbit_signature1) != get_signature2_bit(i))
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
152 e++;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
153 }
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
154 if (e > 0)
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
155 pe[k++] = log( (1 - (e / (double) nbit_signature2)) / (e / (double) nbit_signature2));
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
156 else
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
157 pe[k++] = 0;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
158 }
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
159
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
160 pe_sum = 0.0;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
161 for (i = 0; i < k; i++) {
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
162 // fprintf(stderr, "XXX pe[%d] = %f\n", i, pe[i]);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
163 pe_sum += pe[i];
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
164 }
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
165
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
166 for (i = 0; i < k; i++) {
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
167 if (pe_sum != 0)
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
168 alpha[i] = pe[i] / pe_sum;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
169 else
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
170 alpha[i] = 1.0;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
171 }
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
172
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
173 nbit_signature = min_nbit_signature;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
174 for (i = 0; i < min_nbit_signature; i++) {
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
175 double s = 0.0;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
176 int j;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
177
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
178 for (j = 0; j < k; j++) {
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
179 int bit;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
180 //fprintf(stderr, "XXX %d %d\n", i, j);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
181 binstr_to_sig2(w[j]);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
182 bit = get_signature2_bit(i) ? 1 : -1;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
183 s += alpha[j] * bit;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
184 }
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
185 // fprintf(stderr, "YYY %d %f\n", i, s);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
186 set_signature_bit(i, s > 0 ? 1 : 0);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
187 }
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
188
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
189 free(binstr);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
190 }
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
191 else {
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
192 fprintf(stderr, "%s: invalid watermark file %s\n", progname, input_name);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
193 exit(1);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
194 }
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
195
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
196 if (verbose > 0) {
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
197 fprintf(stderr, "signature length: %d\n", nbit_signature1);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
198 fprintf(stderr, "watermark length: %d\n", nbit_signature);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
199 }
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
200
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
201 for (i = 0; i < nbit_signature; i++)
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
202 if (get_signature1_bit(i % nbit_signature1) == get_signature2_bit(i))
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
203 corr++, match++;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
204 else
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
205 corr--;
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
206
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
207 if (correlation_only)
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
208 fprintf(out, "%lf\n", (double) corr / nbit_signature2);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
209 else {
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
210 fprintf(stderr, "redundant blocks: %d\n", k);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
211 fprintf(out, "bit matches: %d/%d\n", match, nbit_signature2);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
212 fprintf(out, "correlation: %lf\n", (double) corr / nbit_signature2);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
213 }
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
214
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
215 exit(0);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
216 }

Repositories maintained by Peter Meerwald, pmeerw@pmeerw.net.