bufr2synop 0.24.0
bufr2tac_x22.c
Go to the documentation of this file.
1/***************************************************************************
2 * Copyright (C) 2013-2022 by Guillermo Ballester Valor *
3 * gbv@ogimet.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20/*!
21 \file bufr2tac_x22.c
22 \brief decodes the descriptors with X = 22 (oceanographic data)
23*/
24#include "bufr2tac.h"
25
26
27/*!
28 \fn int syn_parse_x22 ( struct synop_chunks *syn, struct bufr2tac_subset_state *s )
29 \brief Parse a expanded descriptor with X = 01
30 \param syn pointer to a struct \ref synop_chunks where to set the results
31 \param s pointer to a struct \ref bufr2tac_subset_state where is stored needed information in sequential analysis
32
33 It returns 0 if success, 1 if problems when processing. If a descriptor is not processed returns 0 anyway
34*/
35int syn_parse_x22 ( struct synop_chunks *syn, struct bufr2tac_subset_state *s )
36{
37 char aux[16];
38
40 return 0;
41
42 switch ( s->a->desc.y )
43 {
44 case 1: // 0 22 001 Direction of waves
45 case 3: // 0 22 003 Direction of swell waves
46 if ( syn->s2.dw1dw1[0] == 0 )
47 {
48 sprintf ( syn->s2.dw1dw1, "%02d", abs(( s->ival + 5 ) /10) % 100 );
49 }
50 else if ( syn->s2.dw2dw2[0] == 0 )
51 {
52 sprintf ( syn->s2.dw2dw2, "%02d", abs(( s->ival + 5 ) /10) % 100 );
53 }
54 syn->mask |= SYNOP_SEC2; // have sec2 data
55 break;
56
57 case 11: // 0 22 011 wind period in seconds
58 if ( syn->s2.PwPw[0] == 0 )
59 {
60 sprintf ( syn->s2.PwPw, "%02d", ( int ) ( s->val ) );
61 syn->mask |= SYNOP_SEC2; // have sec2 data
62 }
63 break;
64
65 case 12: // 0 22 012 wind wave period in seconds
66 if ( syn->s2.PwaPwa[0] == 0 )
67 {
68 sprintf ( syn->s2.PwaPwa, "%02d", ( int ) ( s->val ) );
69 syn->mask |= SYNOP_SEC2; // have sec2 data
70 }
71 break;
72
73 case 13: // 0 22 013 swell wave period in seconds
74 if ( syn->s2.Pw1Pw1[0] == 0 )
75 {
76 sprintf ( syn->s2.Pw1Pw1, "%02d", ( int ) ( s->val ) );
77 }
78 else if ( syn->s2.Pw2Pw2[0] == 0 )
79 {
80 sprintf ( syn->s2.Pw2Pw2, "%02d", ( int ) ( s->val ) );
81 }
82 syn->mask |= SYNOP_SEC2; // have sec2 data
83 break;
84
85 case 21: // 0 22 021 wind wave heigh in m
86 if ( syn->s2.HwHw[0] == 0 )
87 {
88 sprintf ( syn->s2.HwHw, "%02d", ( int ) ( s->val * 2.0 + 0.01 ) );
89 syn->mask |= SYNOP_SEC2; // have sec2 data
90 }
91 break;
92
93 case 22: // 0 22 022 wind wave heigh in meters
94 if ( syn->s2.HwaHwa[0] == 0 )
95 {
96 sprintf ( syn->s2.HwaHwa, "%02d", ( int ) ( s->val * 2.0 + 0.01 ) ); // 0.5 m units
97 syn->mask |= SYNOP_SEC2; // have sec2 data
98 }
99 if ( syn->s2.HwaHwaHwa[0] == 0 )
100 {
101 sprintf ( syn->s2.HwaHwaHwa, "%03d", ( int ) ( s->val * 10.0 + 0.5 ) ); // 0.1 m units
102 syn->mask |= SYNOP_SEC2; // have sec2 data
103 }
104 break;
105
106 case 23: // 0 22 023 swell wave heigh in meters
107 if ( syn->s2.Hw1Hw1[0] == 0 )
108 {
109 sprintf ( syn->s2.Hw1Hw1, "%02d", ( int ) ( s->val * 2.0 + 0.01 ) );
110 }
111 else if ( syn->s2.Hw2Hw2[0] == 0 )
112 {
113 sprintf ( syn->s2.Hw2Hw2, "%02d", ( int ) ( s->val * 2.0 + 0.01 ) );
114 }
115 syn->mask |= SYNOP_SEC2; // have sec2 data
116 break;
117
118 case 42:
119 case 43:
120 case 45:
121 case 49: // 0 22 049 Sea surface temperature
122 if ( syn->s2.TwTwTw[0] == 0 )
123 {
124 if ( kelvin_to_snTTT ( aux, s->val ) )
125 {
126 syn->s2.ss[0] = aux[0];
127 strcpy ( syn->s2.TwTwTw, aux + 1 );
128 syn->mask |= SYNOP_SEC2; // have sec2 data
129 }
130 }
131 break;
132 default:
133 if ( BUFR2TAC_DEBUG_LEVEL > 1 && (s->a->mask & DESCRIPTOR_VALUE_MISSING) == 0 )
134 bufr2tac_set_error ( s, 0, "syn_parse_x22()", "Descriptor not parsed" );
135 break;
136 }
137 return 0;
138}
139
140/*!
141 \fn int buoy_parse_x22 ( struct buoy_chunks *b, struct bufr2tac_subset_state *s )
142 \brief Parse a expanded descriptor with X = 22
143 \param b pointer to a struct \ref buoy_chunks where to set the results
144 \param s pointer to a struct \ref bufr2tac_subset_state where is stored needed information in sequential analysis
145
146 It returns 0 if success, 1 if problems when processing. If a descriptor is not processed returns 0 anyway
147*/
149{
150 char aux[16];
151
152 if ( s->a->mask & DESCRIPTOR_VALUE_MISSING )
153 return 0;
154
155 switch ( s->a->desc.y )
156 {
157 case 4: // 0 22 004 Direction of current
158 if ( s->layer < 32 ) // only 32 max layers
159 {
160 if ( b->s3.l2[s->layer].dd[0] == 0 )
161 {
162 sprintf ( b->s3.l2[s->layer].dd, "%02d", ( int ) ( s->val + 5.0 ) / 10 ) ;
163 b->mask |= BUOY_SEC3;
164 }
165 if ( b->s3.l2[s->layer].zzzz[0] == 0 ) // also stores pendent deep
166 {
167 sprintf ( b->s3.l2[s->layer].zzzz, "%04d", s->deep );
168 b->mask |= BUOY_SEC3;
169 }
170 }
171 break;
172
173 case 12: // 0 22 012 wind wave period in seconds
174 case 74: // 0 22 074 significant wave period in seconds
175 if ( b->s2.PwaPwa[0] == 0 )
176 {
177 sprintf ( b->s2.PwaPwa, "%02d", ( int ) ( s->val ) );
178 b->mask |= BUOY_SEC2; // have sec2 data
179 if ( b->s2.PwaPwaPwa[0] == 0 )
180 sprintf ( b->s2.PwaPwaPwa, "%03d", ( int ) ( s->val * 10 + 0.5 ) );
181
182 }
183 break;
184
185 case 22: // 0 22 022 wind wave heigh in meters
186 case 70: // 0 22 070 significant wave height in meters
187 if ( b->s2.HwaHwa[0] == 0 )
188 {
189 sprintf ( b->s2.HwaHwa, "%02d", ( int ) ( s->val * 2.0 + 0.01 ) ); // 0.5 m units
190 b->mask |= BUOY_SEC2; // have sec2 data
191 }
192 if ( b->s2.HwaHwaHwa[0] == 0 )
193 {
194 sprintf ( b->s2.HwaHwaHwa, "%03d", ( int ) ( s->val * 10.0 + 0.01 ) ); // 0.1 m units
195 b->mask |= BUOY_SEC2; // have sec2 data
196 }
197 break;
198
199 case 31: // 0 22 033 current speed
200 if ( s->layer < 32 ) // only 32 max layers
201 {
202 if ( b->s3.l2[s->layer].dd[0] == 0 )
203 {
204 sprintf ( b->s3.l2[s->layer].dd, "%03d", ( int ) ( s->val * 100.0 + 0.5 ) ) ;
205 b->mask |= BUOY_SEC3;
206 }
207 if ( b->s3.l2[s->layer].zzzz[0] == 0 ) // also stores pendent deep
208 {
209 sprintf ( b->s3.l2[s->layer].zzzz, "%04d", s->deep );
210 b->mask |= BUOY_SEC3;
211 }
212 }
213 break;
214
215 case 42:
216 case 43:
217 if ( s->deep == 0 )
218 {
219 if ( b->s2.TwTwTw[0] == 0 )
220 {
221 if ( kelvin_to_snTTT ( aux, s->val ) )
222 {
223 b->s2.sn[0] = aux[0];
224 strcpy ( b->s2.TwTwTw, aux + 1 );
225 b->mask |= BUOY_SEC2; // have sec2 data
226 }
227 }
228 }
229 if ( s->layer < 32 ) // only 32 max layers
230 {
231 if ( b->s3.l1[s->layer].TTTT[0] == 0 )
232 {
233 kelvin_to_TTTT ( b->s3.l1[s->layer].TTTT, s->val );
234 b->mask |= BUOY_SEC3;
235 }
236 if ( b->s3.l1[s->layer].zzzz[0] == 0 ) // also stores pendent deep
237 {
238 sprintf ( b->s3.l1[s->layer].zzzz, "%04d", s->deep );
239 b->mask |= BUOY_SEC3;
240 }
241 }
242 break;
243
244 case 45:
245 case 49: // 0 22 049 Sea surface temperature
246 if ( b->s2.TwTwTw[0] == 0 )
247 {
248 if ( kelvin_to_snTTT ( aux, s->val ) )
249 {
250 b->s2.sn[0] = aux[0];
251 strcpy ( b->s2.TwTwTw, aux + 1 );
252 b->mask |= BUOY_SEC2; // have sec2 data
253 }
254 }
255 break;
256
257 case 62: // 0 22 062 Salinity
258 if ( s->layer < 32 ) // only 32 max layers
259 {
260 if ( b->s3.l1[s->layer].SSSS[0] == 0 )
261 {
262 sprintf ( b->s3.l1[s->layer].SSSS, "%04d", ( int ) ( s->val * 100.0 + 0.5 ) );
263 b->mask |= BUOY_SEC3;
264 }
265 if ( b->s3.l1[s->layer].zzzz[0] == 0 ) // also stores pendent deep
266 {
267 sprintf ( b->s3.l1[s->layer].zzzz, "%04d", s->deep );
268 b->mask |= BUOY_SEC3;
269 }
270 }
271 break;
272
273 default:
274 if ( BUFR2TAC_DEBUG_LEVEL > 1 && (s->a->mask & DESCRIPTOR_VALUE_MISSING) == 0 )
275 bufr2tac_set_error ( s, 0, "buoy_parse_x22()", "Descriptor not parsed" );
276 break;
277 }
278 return 0;
279}
280
281/*!
282 \fn int temp_parse_x22 ( struct temp_chunks *t, struct bufr2tac_subset_state *s )
283 \brief Parse a expanded descriptor with X = 22
284 \param t pointer to a struct \ref temp_chunks where to set the results
285 \param s pointer to a struct \ref bufr2tac_subset_state where is stored needed information in sequential analysis
286
287 It returns 0 if success, 1 if problems when processing. If a descriptor is not processed returns 0 anyway
288*/
290{
291 char aux[16];
292
293 if ( s->a->mask & DESCRIPTOR_VALUE_MISSING )
294 return 0;
295
296 switch ( s->a->desc.y )
297 {
298 case 43:
299 if ( kelvin_to_snTTT ( aux, s->val ) )
300 {
301 t->a.s7.sn[0] = aux[0];
302 t->b.s7.sn[0] = aux[0];
303 t->c.s7.sn[0] = aux[0];
304 t->d.s7.sn[0] = aux[0];
305 strcpy ( t->a.s7.TwTwTw, aux + 1 );
306 strcpy ( t->b.s7.TwTwTw, aux + 1 );
307 strcpy ( t->c.s7.TwTwTw, aux + 1 );
308 strcpy ( t->d.s7.TwTwTw, aux + 1 );
309 t->a.mask |= TEMP_SEC_7; // have sec7 data
310 }
311 break;
312
313 default:
314 if ( BUFR2TAC_DEBUG_LEVEL > 1 && (s->a->mask & DESCRIPTOR_VALUE_MISSING) == 0 )
315 bufr2tac_set_error ( s, 0, "temp_parse_x22()", "Descriptor not parsed" );
316 break;
317 }
318
319 return 0;
320}
int BUFR2TAC_DEBUG_LEVEL
Definition: bufr2tac.c:31
Include header file for binary bufr2tac.
int bufr2tac_set_error(struct bufr2tac_subset_state *s, int severity, char *origin, char *explanation)
char * kelvin_to_TTTT(char *target, double T)
converts a kelvin temperature value into a TTTT string
Definition: bufr2tac_x12.c:123
char * kelvin_to_snTTT(char *target, double T)
converts a kelvin temperature value into a snTTT string
Definition: bufr2tac_x12.c:32
int buoy_parse_x22(struct buoy_chunks *b, struct bufr2tac_subset_state *s)
Parse a expanded descriptor with X = 22.
Definition: bufr2tac_x22.c:148
int syn_parse_x22(struct synop_chunks *syn, struct bufr2tac_subset_state *s)
Parse a expanded descriptor with X = 01.
Definition: bufr2tac_x22.c:35
int temp_parse_x22(struct temp_chunks *t, struct bufr2tac_subset_state *s)
Parse a expanded descriptor with X = 22.
Definition: bufr2tac_x22.c:289
#define DESCRIPTOR_VALUE_MISSING
Bit mask for a missing value in a struct bufr_atom_data.
Definition: bufrdeco.h:140
#define BUOY_SEC3
mask bit meaning section 3 of buoy is solicited to or parsed with success
Definition: metbuoy.h:48
#define BUOY_SEC2
mask bit meaning section 2 of buoy is solicited to or parsed with success
Definition: metbuoy.h:43
#define SYNOP_SEC2
mask bit meaning section 2 or synop is solicited to or parsed with success
Definition: metsynop.h:44
#define TEMP_SEC_7
mask bit meaning sec 7 of a part of TEMP report parsed with success
Definition: mettemp.h:95
char zzzz[6]
Definition: metbuoy.h:128
char TTTT[6]
Definition: metbuoy.h:129
char SSSS[6]
Definition: metbuoy.h:130
char dd[4]
Definition: metbuoy.h:140
char zzzz[6]
Definition: metbuoy.h:139
stores information needed to parse a sequential list of expanded descriptors for a subset
Definition: bufr2tac.h:246
struct bufr_atom_data * a
Definition: bufr2tac.h:249
uint32_t mask
Definition: bufrdeco.h:437
struct bufr_descriptor desc
Definition: bufrdeco.h:436
contains all possible substrings from a synop report is parsed with success
Definition: metbuoy.h:197
struct buoy_sec3 s3
Definition: metbuoy.h:204
struct buoy_sec2 s2
Definition: metbuoy.h:203
int mask
Definition: metbuoy.h:198
char PwaPwaPwa[6]
Definition: metbuoy.h:118
char HwaHwa[4]
Definition: metbuoy.h:117
char TwTwTw[4]
Definition: metbuoy.h:115
char HwaHwaHwa[6]
Definition: metbuoy.h:119
char sn[2]
Definition: metbuoy.h:114
char PwaPwa[4]
Definition: metbuoy.h:116
struct b_sec3_layer2 l2[32]
Definition: metbuoy.h:155
struct b_sec3_layer1 l1[32]
Definition: metbuoy.h:154
contains all possible substrings from a synop report is parsed with success
Definition: metsynop.h:293
struct synop_sec2 s2
Definition: metsynop.h:299
char TwTwTw[6]
Definition: metsynop.h:168
char HwaHwaHwa[6]
Definition: metsynop.h:180
char Hw1Hw1[4]
Definition: metsynop.h:176
char Pw2Pw2[4]
Definition: metsynop.h:177
char PwaPwa[4]
Definition: metsynop.h:169
char dw2dw2[4]
Definition: metsynop.h:174
char HwHw[4]
Definition: metsynop.h:172
char HwaHwa[4]
Definition: metsynop.h:170
char dw1dw1[4]
Definition: metsynop.h:173
char ss[2]
Definition: metsynop.h:167
char PwPw[4]
Definition: metsynop.h:171
char Hw2Hw2[4]
Definition: metsynop.h:178
char Pw1Pw1[4]
Definition: metsynop.h:175
int mask
Definition: mettemp.h:453
struct temp_sec7 s7
Definition: mettemp.h:459
struct temp_sec7 s7
Definition: mettemp.h:473
struct temp_sec7 s7
Definition: mettemp.h:489
Store the whole TEMP report.
Definition: mettemp.h:511
struct temp_c c
Definition: mettemp.h:517
struct temp_d d
Definition: mettemp.h:518
struct temp_b b
Definition: mettemp.h:516
struct temp_a a
Definition: mettemp.h:515
struct temp_sec7 s7
Definition: mettemp.h:503
char sn[2]
Definition: mettemp.h:410
char TwTwTw[4]
Definition: mettemp.h:411