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

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