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