/
lookup.c
239 lines (229 loc) · 5.8 KB
/
lookup.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/***************************************************************************
* Generic lookup routines for miniSEED information.
*
* This file is part of the miniSEED Library.
*
* Copyright (c) 2024 Chad Trabant, EarthScope Data Services
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include <string.h>
#include "libmseed.h"
/**********************************************************************/ /**
* @brief Determine data sample size for each type
*
* @param[in] sampletype Library sample type code:
* @parblock
* - \c 't' - Text data type
* - \c 'i' - 32-bit integer data type
* - \c 'f' - 32-bit float data type
* - \c 'd' - 64-bit float (double) data type
* @endparblock
*
* @returns The sample size based on type code or 0 for unknown.
***************************************************************************/
uint8_t
ms_samplesize (char sampletype)
{
switch (sampletype)
{
case 't':
case 'a':
return 1;
break;
case 'i':
case 'f':
return 4;
break;
case 'd':
return 8;
break;
default:
return 0;
}
} /* End of ms_samplesize() */
/**********************************************************************/ /**
* @brief Return sample size and/or type for given encoding value
*
* Determine the decoded sample size and/or type based on data
* encoding. The \a samplesize and \a sampletype values will only be
* set if not NULL, allowing lookup of either value or both.
*
* @param[in] encoding Data sample encoding code
* @param[out] samplesize Size of sample, pointer that will be set
* @param[out] sampletype Sample type, pointer to \c char that will be set
*
* @returns 0 on success, -1 on error
***************************************************************************/
int
ms_encoding_sizetype (uint8_t encoding, uint8_t *samplesize, char *sampletype)
{
switch (encoding)
{
case DE_TEXT:
if (samplesize)
*samplesize = 1;
if (sampletype)
*sampletype = 't';
break;
case DE_INT16:
case DE_INT32:
case DE_STEIM1:
case DE_STEIM2:
case DE_CDSN:
case DE_SRO:
case DE_DWWSSN:
if (samplesize)
*samplesize = 4;
if (sampletype)
*sampletype = 'i';
break;
case DE_FLOAT32:
case DE_GEOSCOPE24:
case DE_GEOSCOPE163:
case DE_GEOSCOPE164:
if (samplesize)
*samplesize = 4;
if (sampletype)
*sampletype = 'f';
break;
case DE_FLOAT64:
if (samplesize)
*samplesize = 8;
if (sampletype)
*sampletype = 'd';
break;
default:
return -1;
}
return 0;
} /* End of ms_encodingstr_sizetype() */
/**********************************************************************/ /**
* @brief Descriptive string for data encodings
*
* @param[in] encoding Data sample encoding code
*
* @returns a string describing a data encoding format
***************************************************************************/
const char *
ms_encodingstr (uint8_t encoding)
{
switch (encoding)
{
case 0:
return "Text";
break;
case 1:
return "16-bit integer";
break;
case 2:
return "24-bit integer";
break;
case 3:
return "32-bit integer";
break;
case 4:
return "32-bit float (IEEE single)";
break;
case 5:
return "64-bit float (IEEE double)";
break;
case 10:
return "STEIM-1 integer compression";
break;
case 11:
return "STEIM-2 integer compression";
break;
case 12:
return "GEOSCOPE Muxed 24-bit integer";
break;
case 13:
return "GEOSCOPE Muxed 16/3-bit gain/exp";
break;
case 14:
return "GEOSCOPE Muxed 16/4-bit gain/exp";
break;
case 15:
return "US National Network compression";
break;
case 16:
return "CDSN 16-bit gain ranged";
break;
case 17:
return "Graefenberg 16-bit gain ranged";
break;
case 18:
return "IPG - Strasbourg 16-bit gain";
break;
case 19:
return "STEIM-3 integer compression";
break;
case 30:
return "SRO gain ranged";
break;
case 31:
return "HGLP";
break;
case 32:
return "DWWSSN";
break;
case 33:
return "RSTN 16 bit gain ranged";
break;
default:
return "Unknown";
}
} /* End of ms_encodingstr() */
/**********************************************************************/ /**
* @brief Descriptive string for library @ref return-values
*
* @param[in] errorcode Library error code
*
* @returns a string describing the library error code or NULL if the
* code is unknown.
***************************************************************************/
const char *
ms_errorstr (int errorcode)
{
switch (errorcode)
{
case MS_ENDOFFILE:
return "End of file reached";
break;
case MS_NOERROR:
return "No error";
break;
case MS_GENERROR:
return "Generic error";
break;
case MS_NOTSEED:
return "No miniSEED data detected";
break;
case MS_WRONGLENGTH:
return "Length of data read does not match record length";
break;
case MS_OUTOFRANGE:
return "SEED record length out of range";
break;
case MS_UNKNOWNFORMAT:
return "Unknown data encoding format";
break;
case MS_STBADCOMPFLAG:
return "Bad Steim compression flag(s) detected";
break;
case MS_INVALIDCRC:
return "Invalid CRC detected";
break;
}
return NULL;
} /* End of ms_errorstr() */