-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathver.c
126 lines (109 loc) · 4.29 KB
/
ver.c
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include <stdio.h>
#include <assert.h>
#include <sacio.h>
int
main() {
int nerr = 0;
sac *s = sac_read("t/test_io_small.sac", &nerr);
assert(nerr == 0);
assert(s->h->nvhdr == 6);
sac_set_v7(s);
assert(s->h->nvhdr == 7);
sac_set_v6(s);
assert(s->h->nvhdr == 6);
sac_set_v7(s);
assert(s->h->nvhdr == 7);
sac_write(s, "t/test_io_small_v7.sac.tmp", &nerr);
sac *s7 = sac_read("t/test_io_small_v7.sac.tmp", &nerr);
assert(nerr == 0);
assert(s->h->nvhdr == 7);
assert(s->h->_delta == 1.0);
assert(s->z->_delta == 1.0);
sac_set_float(s, SAC_T0, 1.0/3.0);
assert(s->z->_t0 == 1.0/3.0);
assert(s->h->_t0 == (float)(1.0/3.0));
sac_write(s, "t/test_io_small_v7.sac.tmp", &nerr);
s7 = sac_read("t/test_io_small_v7.sac.tmp", &nerr);
assert(s->z->_t0 == 1.0/3.0);
assert(s->h->_t0 == (float)(1.0/3.0));
assert(s->h->_delta == 1.0);
assert(s->z->_delta == 1.0);
sac_set_float(s, SAC_DELTA, 1.0/3.0);
assert(s->h->_delta != s->z->_delta);
sac_set_float(s, SAC_B, 0.0);
sac_be(s);
sac_write(s,"t/test_io_small_v7.sac.tmp", &nerr);
s7 = sac_read("t/test_io_small_v7.sac.tmp", &nerr);
assert(s->z->_e == 0.0 + (1.0/3.0) * (double)(s->h->npts - 1));
assert(s->h->_e == 0.0 + (1.0/3.0) * (double)(s->h->npts - 1));
printf("%.15e %.15e\n", s->h->_e, s->z->_e);
sac_set_v6(s7);
assert(s7->h->nvhdr == 6);
sac_be(s);
assert(s->h->_e == 0.0 + (1.0/3.0) * (float)(s->h->npts - 1));
sac_write(s7,"t/test_io_small_v6.sac.tmp", &nerr);
sac *s6 = sac_read("t/test_io_small_v6.sac.tmp", &nerr);
assert(nerr == 0);
assert(s6->z->_delta = (1.0/3.0));
printf("ver: %d\n", s6->h->nvhdr);
assert(s6->h->nvhdr == 6);
assert(s6->h->_e == 0.0 + (1.0/3.0) * (float)(s6->h->npts - 1));
assert(s6->h->_e == 0.0 + s6->h->_delta * (float)(s6->h->npts - 1));
// Setting a value and computation of End Value: Version 7
double e;
printf("Version 6\n");
sac_set_v6(s6);
sac_set_float(s6, SAC_B, 1.0/3.0);
sac_be(s6);
printf("t: %.15e %.15e\n", s6->h->_delta, s6->z->_delta);
printf("b: %.15e %.15e\n", s6->h->_b, s6->z->_b);
printf("e: %.15e %.15e (h, z)\n", s6->h->_e, s6->z->_e);
/// Simplistic manner of computing end time, mising floats
e = (float) (1.0/3.0) + s6->h->_delta * (float) (s6->h->npts - 1);
printf("e: %.15e %.15e (mix)\n", s6->h->_e, e);
assert(s6->h->_e != e);
// Values are promoted to double then back to float
e = (float)((double)s6->h->_b + (double)s6->h->_delta * (double)(s6->h->npts - 1));
printf("e: %.15e %.15e (64->32)\n", s6->h->_e, e);
assert(s6->h->_e == e);
// Values are promoted to double
e = (double)s6->h->_b + (double)s6->h->_delta * (double)(s6->h->npts - 1);
printf("e: %.15e %.15e (64)\n", s6->z->_e, e);
assert(s6->z->_e == e);
// Setting a value and computation of End Value: Version 7
printf("Version 7\n");
sac_set_v7(s6);
sac_set_float(s6, SAC_B, 1.0/3.0);
sac_be(s6);
printf("t: %.15e %.15e\n", s6->h->_delta, s6->z->_delta);
printf("b: %.15e %.15e\n", s6->h->_b, s6->z->_b);
printf("e: %.15e %.15e (h, z)\n", s6->h->_e, s6->z->_e);
// Simplistic manner of computing end time, mixing floats
e = (1.0/3.0) + s6->h->_delta * (float) (s6->h->npts - 1);
printf("e: %.15e %.15e (mix)\n", s6->h->_e, e);
assert(s6->h->_e != e);
// Values are promoted to double then back to float
e = (float)((double)s6->z->_b + (double)s6->z->_delta * (double)(s6->h->npts - 1));
printf("e: %.15e %.15e (64->32)\n", s6->h->_e, e);
assert(s6->h->_e == e);
// Values are promoted to double
e = s6->z->_b + s6->z->_delta * (double)(s6->h->npts - 1);
printf("e: %.15e %.15e (64)\n", s6->z->_e, e);
assert(s6->z->_e == e);
double v;
// Setting and getting a value: Version 6
sac_set_v6(s6);
sac_set_float(s6, SAC_T0, 1.0/3.0);
sac_get_float(s6, SAC_T0, &v);
assert(s6->h->_t0 == v);
assert(s6->h->_t0 == (float)(1.0/3.0));
assert(s6->z->_t0 == 1.0/3.0);
// Setting and getting a value: Version 7
sac_set_v7(s6);
sac_set_float(s6, SAC_T0, 1.0/3.0);
sac_get_float(s6, SAC_T0, &v);
assert(s6->h->_t0 == (float)(1.0/3.0));
assert(s6->h->_t0 != 1.0/3.0);
assert(s6->z->_t0 == v);
return 0;
}