bufr2synop 0.24.0
bufr2tac_print_buoy.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_print_buoy.c
22 \brief file with the code to print the results for buoy reports
23 */
24#include "bufr2tac.h"
25
26/*!
27 \fn size_t print_buoy_sec0 (char **sec0, size_t lmax, struct buoy_chunks *b)
28 \brief Prints the buoy section 1
29 \param sec0 the pointer where to print section
30 \param lmax max length permited
31 \param b pointer to s atruct \ref buoy_chunks where the parse results are set
32*/
33size_t print_buoy_sec0 ( char **sec0, size_t lmax, struct buoy_chunks *b )
34{
35 size_t used = 0;
36 char *c = *sec0;
37
38 used += snprintf ( c + used, lmax - used, "%s%s%s%s%s", b->e.YYYY, b->e.MM, b->e.DD, b->e.HH, b->e.mm );
39
40 // Print type
41 used += snprintf ( c + used, lmax - used, " %s%s", b->s0.MiMi, b->s0.MjMj );
42
43 if ( b->s0.A1[0] && b->s0.bw[0] && b->s0.nbnbnb[0] )
44 {
45 used += snprintf ( c + used, lmax - used, " %s%s%s", b->s0.A1, b->s0.bw, b->s0.nbnbnb );
46 }
47 else if ( b->s0.D_D[0] )
48 {
49 used += snprintf ( c + used, lmax - used, " %s", b->s0.D_D );
50 }
51
52
53 used += snprintf ( c + used, lmax - used, " %s%s%s", b->s0.YY, b->s0.MM, b->s0.J );
54
55 if ( b->s0.iw[0] )
56 {
57 used += snprintf ( c + used, lmax - used, " %s%s%s", b->s0.GG, b->s0.gg, b->s0.iw );
58 }
59 else
60 {
61 used += snprintf ( c + used, lmax - used, " %s%s/", b->s0.GG, b->s0.gg );
62 }
63
64 used += snprintf ( c + used, lmax - used, " %s%s", b->s0.Qc, b->s0.LaLaLaLaLa );
65
66
67 used += snprintf ( c + used, lmax - used, " %s", b->s0.LoLoLoLoLoLo );
68
69 if ( b->s0.QA[0] || b->s0.Ql[0] || b->s0.Qt[0] )
70 {
71 if ( b->s0.Ql[0] )
72 {
73 used += snprintf ( c + used, lmax - used, " 6%s", b->s0.Ql );
74 }
75 else
76 {
77 used += snprintf ( c + used, lmax - used, " 6/" );
78 }
79
80 if ( b->s0.Qt[0] )
81 {
82 used +=snprintf ( c + used, lmax - used, "%s", b->s0.Qt );
83 }
84 else
85 {
86 used += snprintf ( c + used, lmax - used, "/" );
87 }
88
89 if ( b->s0.QA[0] )
90 {
91 used += snprintf ( c + used, lmax - used, "%s/", b->s0.QA );
92 }
93 else
94 {
95 used += snprintf ( c + used, lmax - used, "//" );
96 }
97 }
98
99 *sec0 = c + used;
100 return used;
101}
102
103
104/*!
105 \fn size_t print_buoy_sec1 (char **sec1, size_t lmax, struct buoy_chunks *b)
106 \brief Prints the buoy section 1
107 \param sec1 the pointer where to print section
108 \param lmax max length permited
109 \param b pointer to s atruct \ref buoy_chunks where the parse results are set
110*/
111size_t print_buoy_sec1 ( char **sec1, size_t lmax, struct buoy_chunks *b )
112{
113 size_t used = 0;
114 char *c = *sec1;
115
116 if ( b->mask & BUOY_SEC1 )
117 {
118 // 111QdQx
119 used += snprintf ( c + used, lmax - used," 111" );
120
121 if ( b->s1.Qd[0] )
122 {
123 used += snprintf ( c + used, lmax - used,"%s", b->s1.Qd );
124 }
125 else
126 {
127 used += snprintf ( c + used, lmax - used,"/" );
128 }
129
130 if ( b->s1.Qx[0] )
131 {
132 used += snprintf ( c + used, lmax - used,"%s", b->s1.Qx );
133 }
134 else
135 {
136 used += snprintf ( c + used, lmax - used,"/" );
137 }
138
139 // 0ddff
140 if ( b->s1.dd[0] || b->s1.ff[0] )
141 {
142 used += snprintf ( c + used, lmax - used, " 0" );
143 if ( b->s1.dd[0] )
144 {
145 used += snprintf ( c + used, lmax - used, "%s", b->s1.dd );
146 }
147 else
148 {
149 used += snprintf ( c + used, lmax - used, "//" );
150 }
151
152 if ( b->s1.ff[0] )
153 {
154 used += snprintf ( c + used, lmax - used, "%s", b->s1.ff );
155 }
156 else
157 {
158 used += snprintf ( c + used, lmax - used, "//" );
159 }
160 }
161
162 // 1snTTT
163 if ( b->s1.TTT[0] )
164 {
165 used += snprintf ( c + used, lmax - used, " 1%s%s", b->s1.sn1, b->s1.TTT );
166 }
167
168 // 2snTdTdTd
169 if ( b->s1.TdTdTd[0] )
170 {
171 used += snprintf ( c + used, lmax - used, " 2%s%s", b->s1.sn2, b->s1.TdTdTd );
172 }
173
174 // 3PoPoPoPo
175 if ( b->s1.PoPoPoPo[0] )
176 {
177 used += snprintf ( c + used, lmax - used, " 3%s", b->s1.PoPoPoPo );
178 }
179
180 // printf 4PPPP
181 if ( b->s1.PPPP[0] )
182 {
183 used += snprintf ( c + used, lmax - used, " 4%s", b->s1.PPPP );
184 }
185
186 // printf 5appp
187 if ( b->s1.a[0] || b->s1.ppp[0] )
188 {
189 if ( b->s1.a[0] == 0 )
190 {
191 b->s1.a[0] = '/';
192 }
193 if ( b->s1.ppp[0] == 0 )
194 {
195 strcpy ( b->s1.ppp, "///" );
196 }
197 used += snprintf ( c + used, lmax - used, " 5%s%s", b->s1.a, b->s1.ppp );
198 }
199 }
200
201 *sec1 = c + used;
202 return used;
203}
204
205/*!
206 \fn size_t print_buoy_sec2 (char **sec2, size_t lmax, struct buoy_chunks *b)
207 \brief Prints the buoy section 1
208 \param sec2 the pointer where to print section
209 \param lmax max length permited
210 \param b pointer to s atruct \ref buoy_chunks where the parse results are set
211*/
212size_t print_buoy_sec2 ( char **sec2, size_t lmax, struct buoy_chunks *b )
213{
214 size_t used = 0;
215 char *c = *sec2;
216
217 if ( b->mask & BUOY_SEC2 )
218 {
219 // 222QdQx
220 used += snprintf ( c + used, lmax - used," 222" );
221
222 if ( b->s2.Qd[0] )
223 {
224 used += snprintf ( c + used, lmax - used,"%s", b->s2.Qd );
225 }
226 else
227 {
228 used += snprintf ( c + used, lmax - used,"/" );
229 }
230
231 if ( b->s2.Qx[0] )
232 {
233 used += snprintf ( c + used, lmax - used,"%s", b->s2.Qx );
234 }
235 else
236 {
237 used += snprintf ( c + used, lmax - used,"/" );
238 }
239
240 // 0snTwTwTw
241 if ( b->s2.TwTwTw[0] )
242 {
243 used += snprintf ( c + used, lmax - used, " 0%s%s", b->s2.sn, b->s2.TwTwTw );
244 }
245
246 // 1PwaPwaHwaHwa
247 if ( b->s2.PwaPwa[0] || b->s2.HwaHwa[0] )
248 {
249 used += snprintf ( c + used, lmax - used, " 1" );
250 if ( b->s2.PwaPwa[0] )
251 {
252 used += snprintf ( c + used, lmax - used,"%s", b->s2.PwaPwa );
253 }
254 else
255 {
256 used += snprintf ( c + used, lmax - used,"//" );
257 }
258
259 if ( b->s2.HwaHwa[0] )
260 {
261 used += snprintf ( c + used, lmax - used,"%s", b->s2.HwaHwa );
262 }
263 else
264 {
265 used += snprintf ( c + used, lmax - used,"//" );
266 }
267 }
268
269 // 20PwaPwaPwa
270 if ( b->s2.PwaPwaPwa[0] )
271 {
272 used += snprintf ( c + used, lmax - used, " 20%s", b->s2.PwaPwaPwa );
273 }
274
275 // 21HwaHwaHwa
276 if ( b->s2.HwaHwaHwa[0] )
277 {
278 used += snprintf ( c + used, lmax - used, " 21%s", b->s2.HwaHwaHwa );
279 }
280
281
282 }
283
284 *sec2 = c + used;
285 return used;
286}
287
288/*!
289 \fn size_t print_buoy_sec3 (char **sec3, size_t lmax, struct buoy_chunks *b)
290 \brief Prints the buoy section 3
291 \param sec3 the pointer where to print section
292 \param lmax max length permited
293 \param b pointer to s atruct \ref buoy_chunks where the parse results are set
294*/
295size_t print_buoy_sec3 ( char **sec3, size_t lmax, struct buoy_chunks *b )
296{
297 size_t used = 0;
298 char *c = *sec3;
299 size_t l;
300
301 if ( b->mask & BUOY_SEC3 )
302 {
303 used += snprintf ( c + used, lmax - used, " 333%s%s", b->s3.Qd1, b->s3.Qd2 );
304
305 // check if has 8887k2
306 l = 0;
307 while ( b->s3.l1[l].zzzz[0] && l < 32 )
308 {
309 if ( l == 0 )
310 {
311 used += snprintf ( c + used, lmax - used, " 8887%s", b->s3.k2 );
312 }
313 used += snprintf ( c + used, lmax - used, " 2%s", b->s3.l1[l].zzzz );
314
315 if ( b->s3.l1[l].TTTT[0] )
316 {
317 used += snprintf ( c + used, lmax - used, " 3%s", b->s3.l1[l].TTTT );
318 }
319
320 if ( b->s3.l1[l].SSSS[0] )
321 {
322 used += snprintf ( c + used, lmax - used, " 4%s", b->s3.l1[l].SSSS );
323 }
324 l++;
325 }
326
327 l = 0;
328 while ( b->s3.l2[l].zzzz[0] && l < 32 )
329 {
330 if ( l == 0 )
331 {
332 used += snprintf ( c + used, lmax - used, " 66%s9%s", b->s3.k6, b->s3.k3 );
333 }
334 used += snprintf ( c + used, lmax - used, " 2%s", b->s3.l2[l].zzzz );
335
336 if ( b->s3.l2[l].dd[0] || b->s3.l2[l].ccc[0] )
337 {
338 if ( b->s3.l2[l].dd[0] )
339 {
340 used += snprintf ( c + used, lmax - used, " %s", b->s3.l2[l].dd );
341 }
342 else
343 {
344 used += snprintf ( c + used, lmax - used, " //" );
345 }
346 if ( b->s3.l2[l].ccc[0] )
347 {
348 used += snprintf ( c + used, lmax - used, "%s", b->s3.l2[l].ccc );
349 }
350 else
351 {
352 used += snprintf ( c + used, lmax - used, "///" );
353 }
354 }
355 l++;
356 }
357 }
358
359 *sec3 = c + used;
360 return used;
361}
362
363/*!
364 * \fn size_t print_synop_wigos_id ( char **wid, size_t lmax, struct buoy_chunks *b )
365 * \brief Prints a WIGOS identifier in a buoy report
366 */
367size_t print_buoy_wigos_id ( char **wid, size_t lmax, struct buoy_chunks *b )
368{
369 char aux[40];
370 size_t used = 0;
371 char sep = '|';
372
373 if ( b->wid.series == 0 && b->wid.issuer == 0 && b->wid.issue == 0 && b->wid.local_id[0] == '\0' )
374 sprintf ( aux,"0-0-0-MISSING" );
375 else
376 sprintf ( aux,"%d-%d-%d-%s", b->wid.series, b->wid.issuer, b->wid.issue, b->wid.local_id );
377
378 used = snprintf ( *wid, lmax, "%-32s%c", aux, sep );
379 *wid += used;
380 return used;
381}
382
383
384/*!
385 \fn int print_buoy_report(struct metreport *m )
386 \brief prints a buoy into a string
387 \param m pointer to struct \ref metreport where are both target and source
388
389
390 If OK returns 0, otherwise 1
391*/
393{
394 char *c = & ( m->alphanum[0] );
395 size_t used = 0;
396 size_t lmax = sizeof ( m->alphanum );
397 struct buoy_chunks *b = &m->buoy;
398
399 // Needs time extension
400 if ( b->e.YYYY[0] == 0 || b->e.YYYY[0] == '0' )
401 {
402 return 1;
403 }
404
406 {
407 used += print_wigos_id ( &c, lmax, m );
408 }
409
410 if ( m->print_mask & PRINT_BITMASK_GEO )
411 {
412 used += print_geo ( &c, lmax, m );
413 }
414
415 print_buoy_sec0 ( &c, lmax, b );
416
417 if ( b->mask & ( BUOY_SEC1 | BUOY_SEC2 | BUOY_SEC3 ) )
418 {
419 used += print_buoy_sec1 ( &c, lmax - used, b );
420
421 used += print_buoy_sec2 ( &c, lmax - used, b );
422
423 used += print_buoy_sec3 ( &c, lmax - used, b );
424 }
425 else
426 {
427 c += snprintf ( c, lmax - used, " NIL" );
428 }
429 snprintf ( c, lmax - used - 1, "=" );
430
431 return 0;
432}
433
434
Include header file for binary bufr2tac.
size_t print_wigos_id(char **wid, size_t lmax, struct metreport *m)
#define PRINT_BITMASK_WIGOS
Bit mask to member print_mask in struct metreport to print WIGOS Identifier.
Definition: bufr2tac.h:208
size_t print_geo(char **geo, size_t lmax, struct metreport *m)
#define PRINT_BITMASK_GEO
Bit mask to member print_mask in struct metreport to print geographic position.
Definition: bufr2tac.h:214
size_t print_buoy_sec1(char **sec1, size_t lmax, struct buoy_chunks *b)
Prints the buoy section 1.
size_t print_buoy_sec0(char **sec0, size_t lmax, struct buoy_chunks *b)
Prints the buoy section 1.
size_t print_buoy_sec2(char **sec2, size_t lmax, struct buoy_chunks *b)
Prints the buoy section 1.
int print_buoy_report(struct metreport *m)
prints a buoy into a string
size_t print_buoy_wigos_id(char **wid, size_t lmax, struct buoy_chunks *b)
size_t print_buoy_sec3(char **sec3, size_t lmax, struct buoy_chunks *b)
Prints the buoy section 3.
#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 BUOY_SEC1
mask bit meaning section 1 of buoy is solicited to or parsed with success
Definition: metbuoy.h:38
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 ccc[6]
Definition: metbuoy.h:141
char zzzz[6]
Definition: metbuoy.h:139
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 wigos_id wid
Definition: metbuoy.h:200
struct buoy_sec2 s2
Definition: metbuoy.h:203
struct report_date_ext e
Definition: metbuoy.h:199
int mask
Definition: metbuoy.h:198
struct buoy_sec1 s1
Definition: metbuoy.h:202
struct buoy_sec0 s0
Definition: metbuoy.h:201
char LoLoLoLoLoLo[8]
Definition: metbuoy.h:80
char Ql[2]
Definition: metbuoy.h:81
char Qt[2]
Definition: metbuoy.h:82
char MjMj[4]
Definition: metbuoy.h:67
char YY[4]
Definition: metbuoy.h:72
char nbnbnb[8]
Definition: metbuoy.h:70
char MiMi[4]
Definition: metbuoy.h:66
char LaLaLaLaLa[8]
Definition: metbuoy.h:79
char Qc[2]
Definition: metbuoy.h:78
char A1[2]
Definition: metbuoy.h:68
char D_D[8]
Definition: metbuoy.h:71
char J[4]
Definition: metbuoy.h:74
char QA[2]
Definition: metbuoy.h:83
char iw[2]
Definition: metbuoy.h:77
char bw[2]
Definition: metbuoy.h:69
char gg[4]
Definition: metbuoy.h:76
char MM[4]
Definition: metbuoy.h:73
char GG[4]
Definition: metbuoy.h:75
char a[2]
Definition: metbuoy.h:103
char PoPoPoPo[6]
Definition: metbuoy.h:101
char Qx[2]
Definition: metbuoy.h:92
char dd[4]
Definition: metbuoy.h:93
char ppp[4]
Definition: metbuoy.h:104
char sn2[2]
Definition: metbuoy.h:98
char TTT[4]
Definition: metbuoy.h:97
char PPPP[6]
Definition: metbuoy.h:102
char ff[4]
Definition: metbuoy.h:94
char TdTdTd[4]
Definition: metbuoy.h:99
char Qd[2]
Definition: metbuoy.h:91
char sn1[2]
Definition: metbuoy.h:96
char PwaPwaPwa[6]
Definition: metbuoy.h:118
char Qd[2]
Definition: metbuoy.h:112
char Qx[2]
Definition: metbuoy.h:113
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
char k2[2]
Definition: metbuoy.h:151
struct b_sec3_layer2 l2[32]
Definition: metbuoy.h:155
char k6[2]
Definition: metbuoy.h:153
char Qd2[2]
Definition: metbuoy.h:150
char k3[2]
Definition: metbuoy.h:152
struct b_sec3_layer1 l1[32]
Definition: metbuoy.h:154
char Qd1[2]
Definition: metbuoy.h:149
all the information for a meteorological report in WMO text format from a BUFR file
Definition: bufr2tac.h:309
char alphanum[REPORT_LENGTH]
Definition: bufr2tac.h:321
int print_mask
Definition: bufr2tac.h:312
struct buoy_chunks buoy
Definition: bufr2tac.h:317
char mm[4]
Definition: metcommon.h:37
char HH[4]
Definition: metcommon.h:36
char DD[4]
Definition: metcommon.h:35
char MM[4]
Definition: metcommon.h:34
char YYYY[6]
Definition: metcommon.h:33
uint16_t issue
Definition: metcommon.h:49
uint16_t issuer
Definition: metcommon.h:48
uint8_t series
Definition: metcommon.h:47
char local_id[24]
Definition: metcommon.h:50