annotate Meerwald/cmp_dugad_sig.c @ 22:d8551fb39a5e default tip

Added tag v0.6 for changeset 1c4ccd635a68
author Peter Meerwald-Stadler <pmeerw@pmeerw.net>
date Sat, 28 Jan 2023 23:57:51 +0100
parents f83ef905a63d
children
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
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
3 char *progname;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
4
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
5 void usage(void) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
6 fprintf(stderr, "usage: %s [-h] [-s file] [-C] [-o file] [-v] file\n\n", progname);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
7 fprintf(stderr, "\t-C\t\toutput correlation only\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
8 fprintf(stderr, "\t-h\t\tprint usage\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
9 fprintf(stderr, "\t-o file\t\toutput file\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
10 fprintf(stderr, "\t-s file\t\tignored\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
11 exit(0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
12 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
13
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
14 int main(int argc, char *argv[]) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
15
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
16 FILE *in = stdin;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
17 FILE *out = stdout;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
18
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
19 char output_name[MAXPATHLEN] = "(stdout)";
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
20 char input_name[MAXPATHLEN] = "(stdin)";
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
21
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
22 int c, i, n, ok;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
23 int levels;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
24 double alpha;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
25 double diff;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
26 char line[32];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
27
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
28 int correlation_only = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
29 int verbose = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
30
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
31 progname = argv[0];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
32
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
33 while ((c = getopt(argc, argv, "h?Co:v:s:")) != EOF) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
34 switch (c) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
35 case 'h':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
36 case '?':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
37 usage();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
38 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
39 case 'C':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
40 correlation_only = 1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
41 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
42 case 's':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
43 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
44 case 'o':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
45 if ((out = fopen(optarg, "w")) == NULL) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
46 fprintf(stderr, "%s: unable to open output file %s\n", progname, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
47 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
48 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
49 strcpy(output_name, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
50 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
51 case 'v':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
52 verbose = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
53 if (verbose < 0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
54 fprintf(stderr, "%s: verbosity level %d out of range\n", progname, verbose);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
55 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
56 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
57 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
58 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
59 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
60
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
61 argc -= optind;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
62 argv += optind;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
63
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
64 if (argc > 1) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
65 usage();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
66 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
67 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
68
8
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
69 if (argc == 1 && *argv[0] != '-') {
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
70 if ((in = fopen(argv[0], "r")) == NULL) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
71 fprintf(stderr, "%s: unable to open input file %s\n", progname, argv[0]);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
72 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
73 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
74 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
75 strcpy(input_name, argv[0]);
8
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
76 }
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
77
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
78 fgets(line, sizeof(line), in);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
79 if (strspn(line, "DGWM") < 4) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
80 fprintf(stderr, "%s: watermark file %s invalid\n", progname, input_name);
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
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
84 fscanf(in, "%d\n", &levels);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
85 fscanf(in, "%lf\n", &alpha);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
86
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
87 n = 3 * levels;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
88 ok = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
89 diff = 0.0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
90 for (i = 0; i < levels; i++) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
91 int m;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
92 double z, v;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
93
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
94 // HL subband
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
95 fscanf(in, "%d %lf %lf\n", &m, &z, &v);
8
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
96 if (verbose && !correlation_only) {
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
97 if (m)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
98 fprintf(out, "%f %f\n", z / (double) m, (v * alpha) / (double) (1.0 * m));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
99 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
100 fprintf(out, "0.0 0.0\n");
8
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
101 }
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
102 if (m) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
103 ok += (z > v * alpha / (double) 1.0) ? 1 : 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
104 diff += ((z - v * alpha) / (double) (1.0 * m));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
105 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
106 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
107 n--;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
108
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
109 // LH subband
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
110 fscanf(in, "%d %lf %lf\n", &m, &z, &v);
8
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
111 if (verbose && !correlation_only) {
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
112 if (m)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
113 fprintf(out, "%f %f\n", z / (double) m, (v * alpha) / (double) (1.0 * m));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
114 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
115 fprintf(out, "0.0 0.0\n");
8
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
116 }
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
117 if (m) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
118 ok += (z > v * alpha / (double) 1.0) ? 1 : 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
119 diff += ((z - v * alpha) / (double) (1.0 * m));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
120 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
121 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
122 n--;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
123
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
124 // HH subband
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
125 fscanf(in, "%d %lf %lf\n", &m, &z, &v);
8
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
126 if (verbose && !correlation_only) {
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
127 if (m)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
128 fprintf(out, "%f %f\n", z / (double) m, (v * alpha) / (double) (1.0 * m));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
129 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
130 fprintf(out, "0.0 0.0\n");
8
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
131 }
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
132
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
133 if (m) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
134 ok += (z > v * alpha / (double) 1.0) ? 1 : 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
135 diff += ((z - v * alpha) / (double) (1.0 * m));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
136 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
137 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
138 n--;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
139 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
140
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
141 if (!correlation_only)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
142 fprintf(out, "%d/%d, diff %f\n", ok, n, diff);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
143 fprintf(out, "%f\n", (double) ok / (double) n);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
144
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
145 fclose(out);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
146 fclose(in);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
147
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
148 exit(0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
149 }

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