forked from uafgeotools/capuaf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrap.c
More file actions
41 lines (33 loc) · 803 Bytes
/
trap.c
File metadata and controls
41 lines (33 loc) · 803 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
/* unit sum trapzoid from convolution of two boxes (durations t1 and t2) */
float *trap(float t1, float t2, float dt, int *n) {
int i, n1, n2;
float slope, *s;
n1 = rint(t1/dt);
if (n1<1) n1 = 1;
n2 = rint(t2/dt);
if (n2<1) n2 = 1;
if (n1 > n2) {
i = n1;
n1 = n2;
n2 = i;
}
*n = n1+n2;
s = (float *) malloc((*n)*sizeof(float));
if ( s == NULL ) return s;
slope = 1./(n1*n2);
s[0] = 0;
for(i=1;i<=n1;i++) {
s[*n-i] = s[i]=s[i-1] + slope;
}
for(;i<n2;i++) {
s[i]=s[i-1];
}
/*
fprintf(stderr,"%d %d \n",n1,n2);
slope = 0;for(i=0;i<*n;i++) {slope+=s[i];fprintf(stderr,"%d %f %f\n",i,s[i],slope);}
*/
return s;
}