annotate Meerwald/param_stuff.c @ 23:71dd4b96221b

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

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