annotate Meerwald/cmp_frid2_sig.c @ 8:f83ef905a63d

fixing many warnings increase capacity for coordinates in bruyn fix some uninit. variables
author Peter Meerwald <pmeerw@cosy.sbg.ac.at>
date Tue, 22 Apr 2008 13:36:05 +0200
parents be303a3f5ea8
children 4987db85cfae
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1 #include "wm.h"
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2 #include "signature.h"
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
3
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
4 char *progname;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
6 void usage(void) {
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);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
8 fprintf(stderr, "\t-C\t\toutput correlation only\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
9 fprintf(stderr, "\t-h\t\tprint usage\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
10 fprintf(stderr, "\t-o file\t\toutput file\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
11 fprintf(stderr, "\t-s file\t\toriginal signature file\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
12 fprintf(stderr, "\t-v n\t\tverbosity level\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
13 exit(0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
14 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
15
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
16 int main(int argc, char *argv[]) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
17
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
18 FILE *in = stdin;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
19 FILE *out = stdout;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
20 FILE *sig = NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
21
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
22 char signature_name[MAXPATHLEN];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
23 char output_name[MAXPATHLEN] = "(stdout)";
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
24 char input_name[MAXPATHLEN] = "(stdin)";
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
25
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
26 int correlation_only = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
27
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
28 int c, i;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
29 int corr1 = 0, match1 = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
30 int corr2 = 0, match2 = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
31 int verbose = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
32
8
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
33 char line[1024];
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
34
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
35 progname = argv[0];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
36
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
37 while ((c = getopt(argc, argv, "h?Co:s:v:")) != EOF) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
38 switch (c) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
39 case 'h':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
40 case '?':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
41 usage();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
42 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
43 case 'C':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
44 correlation_only = 1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
45 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
46 case 'o':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
47 if ((out = fopen(optarg, "w")) == NULL) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
48 fprintf(stderr, "%s: unable to open output file %s\n", progname, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
49 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
50 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
51 strcpy(output_name, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
52 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
53 case 's':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
54 if ((sig = fopen(optarg, "r")) == NULL) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
55 fprintf(stderr, "%s: unable to open signature file %s\n", progname, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
56 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
57 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
58 strcpy(signature_name, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
59 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
60 case 'v':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
61 verbose = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
62 if (verbose < 0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
63 fprintf(stderr, "%s: verbosity level %d out of range\n", progname, verbose);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
64 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
65 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
66 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
67 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
68 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
69
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
70 argc -= optind;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
71 argv += optind;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
72
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
73 if (argc > 1) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
74 usage();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
75 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
76 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
77
8
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
78 if (argc == 1 && *argv[0] != '-') {
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
79 if ((in = fopen(argv[0], "r")) == NULL) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
80 fprintf(stderr, "%s: unable to open input file %s\n", progname, argv[0]);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
81 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
82 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
83 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
84 strcpy(input_name, argv[0]);
8
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
85 }
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
86
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
87 if (sig) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
88 fgets(line, sizeof(line), sig);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
89 if (strspn(line, "FR2SG") >= 5) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
90 fscanf(sig, "%d\n", &nbit_signature);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
91 fscanf(sig, "%*lf\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
92 fscanf(sig, "%*lf\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
93 fscanf(sig, "%*d\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
94 n_signature = NBITSTOBYTES(nbit_signature);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
95 fread(signature, sizeof(char), n_signature, sig);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
96 fscanf(sig, "\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
97 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
98 else {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
99 fprintf(stderr, "%s: invalid signature file %s\n", progname, signature_name);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
100 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
101 }
8
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
102 fclose(sig);
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
103 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
104 else {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
105 fprintf(stderr, "%s: original signature file not specified, use -s file option\n", progname);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
106 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
107 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
108
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
109 fgets(line, sizeof(line), in);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
110 if (strspn(line, "FR2WM") >= 5) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
111 fscanf(in, "%d\n", &nbit_signature1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
112 n_signature1 = NBITSTOBYTES(nbit_signature1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
113 fread(signature1, sizeof(char), n_signature1, in);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
114 // fscanf(in, "\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
115 fscanf(in, "%d\n", &nbit_signature2);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
116 n_signature2 = NBITSTOBYTES(nbit_signature2);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
117 fread(signature2, sizeof(char), n_signature2, in);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
118 fscanf(in, "\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
119 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
120 else {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
121 fprintf(stderr, "%s: invalid watermark file %s\n", progname, input_name);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
122 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
123 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
124
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
125 if (verbose > 0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
126 fprintf(stderr, "signature length: %d\n", nbit_signature);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
127 fprintf(stderr, "watermark length (low. freq.): %d\n", nbit_signature1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
128 fprintf(stderr, "watermark length (med. freq.): %d\n", nbit_signature2);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
129 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
130
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
131 for (i = 0; i < nbit_signature; i++) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
132 if (get_signature_bit(i) == get_signature1_bit(i))
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
133 corr1++, match1++;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
134 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
135 corr1--;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
136 if (get_signature_bit(i) == get_signature2_bit(i))
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
137 corr2++, match2++;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
138 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
139 corr2--;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
140 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
141
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
142 if (correlation_only)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
143 fprintf(out, "%lf\n", (double) (corr1 + corr2) / (nbit_signature1 + nbit_signature2));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
144 else {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
145 fprintf(out, "bit matches (low freq.): %d/%d\n", match1, nbit_signature1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
146 fprintf(out, "correlation (low. freq.): %lf\n", (double) corr1 / nbit_signature1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
147 fprintf(out, "bit matches (med. freq.): %d/%d\n", match2, nbit_signature2);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
148 fprintf(out, "correlation (med. freq.): %lf\n", (double) corr2 / nbit_signature2);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
149 fprintf(out, "total correlation: %lf\n", (double) (corr1 + corr2) / (nbit_signature1 + nbit_signature2));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
150 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
151
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
152 exit(0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
153 }

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