annotate Meerwald/gen_kim_sig.c @ 3:acb6967ee76d

update to 0.5
author Peter Meerwald <pmeerw@cosy.sbg.ac.at>
date Tue, 14 Aug 2007 21:11:21 +0200
parents be303a3f5ea8
children f83ef905a63d
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 [-a n] [-A n] [-d n] [-e n] [-f n] [-F file] [-l n] [-m n] [-n n] [-o file] [-s file] [-S n]\n\n", progname);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
7 fprintf(stderr, "\t-a n\t\talpha factor for detail subbands (default 0.1)\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
8 fprintf(stderr, "\t-A n\t\talpha factor for approximation subband (default 0.02)\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
9 fprintf(stderr, "\t-d n\t\tdeviation (default 1.0)\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
10 fprintf(stderr, "\t-e n\t\twavelet filtering method (default 2)\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
11 fprintf(stderr, "\t-f n\t\tfilter number (default 1)\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
12 fprintf(stderr, "\t-F file\t\tfilter definition file (default 'filter.dat')\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
13 fprintf(stderr, "\t-h\t\tprint usage\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
14 fprintf(stderr, "\t-l n\t\tdecomposition level (default 4)\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
15 fprintf(stderr, "\t-m n \t\tmean value (default 0.0)\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
16 fprintf(stderr, "\t-n n\t\twatermark length (default 1000)\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
17 fprintf(stderr, "\t-o file\t\toutput file\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
18 fprintf(stderr, "\t-s file\t\tuse signature file's embedding information\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
19 fprintf(stderr, "\t-S n\t\tseed\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
20 exit(0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
21 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
22
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
23 int main(int argc, char *argv[]) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
24 FILE *out = stdout;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
25 FILE *sig = NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
26
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
27 char output_name[MAXPATHLEN] = "(stdout)";
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
28 char signature_name[MAXPATHLEN];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
29
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
30 int c;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
31 int i;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
32 int n = 1000;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
33 int s = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
34 int e = 2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
35 int f = 1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
36 char F[MAXPATHLEN] = "filter.dat";
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
37 double a = 0.1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
38 double A = 0.02;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
39 int l = 4;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
40 double m = 0.0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
41 double d = 1.0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
42
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
43 progname = argv[0];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
44
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
45 while ((c = getopt(argc, argv, "a:A:l:d:e:f:F:h?m:n:o:s:S:")) != EOF) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
46 switch (c) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
47 case 'a':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
48 a = atof(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
49 if (a <= 0.0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
50 fprintf(stderr, "%s: alpha factor %f out of range\n", progname, a);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
51 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
52 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
53 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
54 case 'A':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
55 A = atof(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
56 if (A <= 0.0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
57 fprintf(stderr, "%s: alpha factor %f out of range\n", progname, a);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
58 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
59 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
60 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
61 case 'l':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
62 l = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
63 if (l <= 0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
64 fprintf(stderr, "%s: decomposition level %d out of range\n", progname, l);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
65 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
66 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
67 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
68 case 'd':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
69 d = atof(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
70 if (d <= 0.0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
71 fprintf(stderr, "%s: deviation %f out of range\n", progname, d);
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 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
75 case 'e':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
76 e = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
77 if (e < 0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
78 fprintf(stderr, "%s: wavelet filtering method %d out of range\n", progname, e);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
79 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
80 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
81 case 'f':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
82 f = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
83 if (f <= 0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
84 fprintf(stderr, "%s: filter number %d out of range\n", progname, f);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
85 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
86 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
87 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
88 case 'F':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
89 strcpy(F, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
90 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
91 case 'h':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
92 case '?':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
93 usage();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
94 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
95 case 'm':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
96 m = atof(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
97 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
98 case 'n':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
99 n = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
100 if (n < 1 || n > 32000) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
101 fprintf(stderr, "%s: watermark length %d out of range\n", progname, n);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
102 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
103 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
104 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
105 case 'o':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
106 if ((out = fopen(optarg, "w")) == NULL) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
107 fprintf(stderr, "%s: unable to open output file %s\n", progname, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
108 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
109 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
110 strcpy(output_name, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
111 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
112 case 's':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
113 if ((sig = fopen(optarg, "r")) == NULL) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
114 fprintf(stderr, "%s: unable to open signature file %s\n", progname, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
115 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
116 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
117 strcpy(signature_name, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
118 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
119 case 'S':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
120 s = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
121 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
122 }
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 argc -= optind;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
126 argv += optind;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
127
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
128 if (argc > 0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
129 usage();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
130 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
131 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
132
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
133 if (sig) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
134 char line[32];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
135 fgets(line, sizeof(line), sig);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
136 if (strspn(line, "KISG") >= 4) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
137 if (n == 0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
138 fscanf(sig, "%d\n", &n);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
139 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
140 fscanf(sig, "%*d\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
141 if (a == 0.0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
142 fscanf(sig, "%lf\n", &a);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
143 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
144 fscanf(sig, "%*lf\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
145 if (A == 0.0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
146 fscanf(sig, "%lf\n", &A);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
147 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
148 fscanf(sig, "%*lf\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
149 if (l == 0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
150 fscanf(sig, "%d\n", &l);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
151 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
152 fscanf(sig, "%*d\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
153 if (e < 0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
154 fscanf(sig, "%d\n", &e);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
155 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
156 fscanf(sig, "%*d\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
157 if (f == 0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
158 fscanf(sig, "%d\n", &f);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
159 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
160 fscanf(sig, "%*d\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
161 if (!strcmp(F, ""))
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
162 fscanf(sig, "%[^\n\r]\n", &F);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
163 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
164 fscanf(sig, "%*[^\n\r]\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
165 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
166 else {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
167 fprintf(stderr, "%s: invalid signature file %s\n", progname, signature_name);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
168 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
169 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
170 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
171
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
172 if (s)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
173 srandom(s);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
174 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
175 srandom(time(NULL) * getpid());
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
176
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
177 fprintf(out, "KISG\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
178 fprintf(out, "%d\n", n);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
179 fprintf(out, "%f\n", a);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
180 fprintf(out, "%f\n", A);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
181 fprintf(out, "%d\n", l);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
182 fprintf(out, "%d\n", e);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
183 fprintf(out, "%d\n", f);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
184 fprintf(out, "%s\n", F);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
185
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
186 n >>= 1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
187 while (n > 0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
188 double x;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
189 double x1, x2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
190
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
191 /*
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
192 * Algorithm P (Polar method for normal deviates),
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
193 * Knuth, D., "The Art of Computer Programming", Vol. 2, 3rd Edition, p. 122
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
194 */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
195 do {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
196 x1 = 2.0 * ((random() & RAND_MAX) / ((double) RAND_MAX + 1.0)) - 1.0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
197 x2 = 2.0 * ((random() & RAND_MAX) / ((double) RAND_MAX + 1.0)) - 1.0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
198 x = x1 * x1 + x2 * x2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
199 } while (x >= 1.0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
200 x1 *= sqrt((-2.0) * log(x) / x);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
201 x2 *= sqrt((-2.0) * log(x) / x);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
202
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
203 fprintf(out, "%f\n", m + d * x1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
204 fprintf(out, "%f\n", m + d * x2);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
205
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
206 n--;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
207 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
208
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
209 fclose(out);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
210
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
211 exit(0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
212 }

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