comparison Meerwald/param_stuff.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
children f83ef905a63d
comparison
equal deleted inserted replaced
2:b92f06d9a967 3:acb6967ee76d
1 #ifdef PARAM_STUFF
2 {
3 #define MAXNALPHA 32
4
5 double alpha[MAXNALPHA];
6 char *alpha_str = getenv("PARAM_ALPHA");
7 double alpha_value;
8 int alpha_len = 0;
9
10 int param_len[MAXNALPHA];
11 char *param_len_str = getenv("PARAM_LEN");
12 int param_len_value;
13 int param_len_len = 0;
14 int param_len_sum = 0;
15
16 char buf[1024] = "";
17 char *v;
18
19
20 if (alpha_str && strlen(alpha_str) < sizeof(buf)
21 && strcmp(alpha_str, "") ) {
22
23 strcpy(buf, alpha_str);
24
25 v = strtok(buf, "\",; ");
26 do {
27
28 alpha_value = atof(v);
29
30 if (alpha_value < -M_PI || alpha_value >= M_PI) {
31 fprintf(stderr, "%s: parametric - alpha %f out of range\n",
32 progname, alpha_value);
33 exit(1);
34 }
35
36 alpha[alpha_len] = alpha_value;
37 alpha_len++;
38 } while (v = strtok(NULL, "\",; "));
39
40
41 if( param_len_str && strlen(param_len_str) < sizeof(buf)
42 && strcmp(param_len_str, "") ) {
43 /* There was an parameter length environment variable. */
44
45 strcpy(buf, param_len_str);
46
47 v = strtok(buf, "\",; ");
48 do {
49
50 param_len_value = atoi(v);
51
52 if (param_len_value <= 0) {
53 fprintf(stderr, "%s: parameter length %d out of range\n",
54 progname, param_len_value);
55 exit(1);
56 }
57
58 param_len[param_len_len] = param_len_value;
59 param_len_len++;
60 param_len_sum += param_len_value;
61
62 } while (v = strtok(NULL, "\",; "));
63
64 } else {
65 /* No length variable given.
66 For backward compatability we use all parameters for
67 one filter and therefore for all levels.
68 */
69
70 param_len[0] = alpha_len;
71 param_len_len = 1;
72 param_len_sum = alpha_len;
73 }
74
75
76 /* If we do not get a parameter length value for every
77 decomposition level then we reuse the last supplied value
78 for the remaining levels.
79 */
80 if (param_len_len < level+1) {
81 int last_param_len = param_len[ param_len_len - 1 ];
82
83 for(; param_len_len < level+1; param_len_len++ ) {
84 param_len[ param_len_len ] = last_param_len;
85 param_len_sum += last_param_len;
86 }
87 }
88
89
90 /* If the number of supplied alphas is lower than is required
91 for by param_len then copy the last filter
92 parameters to the remaining levels.
93 */
94 if( alpha_len < param_len_sum ) {
95 int i;
96 int last_param_len = param_len[ param_len_len - 1 ];
97 int last_start = alpha_len - last_param_len;
98
99 for( i=0; alpha_len < param_len_sum; alpha_len++, i++ ) {
100 alpha[ alpha_len ] = alpha[ last_start + (i % last_param_len) ];
101 }
102 }
103
104 if (verbose > 1) {
105 int i, j;
106 int cur_sum = 0;
107
108 fprintf(stderr, "%s: parametric, number of levels: %d\n",
109 progname, level);
110
111 for (i = 0; i < level+1; i++) {
112
113 fprintf(stderr, " %d filter parameters for level %d: ",
114 param_len[i], i);
115
116 for (j = 0; j < param_len[i]; j++) {
117 fprintf(stderr, "%f ", alpha[cur_sum + j]);
118 }
119
120 fprintf(stderr, "\n");
121
122 cur_sum += param_len[i];
123 }
124 }
125
126
127 dwt_param_filter(alpha, param_len);
128
129
130 } /* if( alpha_str... */
131 }
132 #endif
133

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