bufr2synop 0.24.0
Functions
bufr2tac_buoy.c File Reference

file with the code to parse buoy FM-18 sequences More...

#include "bufr2tac.h"
Include dependency graph for bufr2tac_buoy.c:

Go to the source code of this file.

Functions

int buoy_YYYYMMDDHHmm_to_JMMYYGGgg (struct buoy_chunks *b)
 Sets YYGG from YYYYMMDDHHmm extended group. More...
 
int parse_subset_as_buoy (struct metreport *m, struct bufr2tac_subset_state *s, struct bufr_subset_sequence_data *sq, char *err)
 

Detailed Description

file with the code to parse buoy FM-18 sequences

Definition in file bufr2tac_buoy.c.

Function Documentation

◆ buoy_YYYYMMDDHHmm_to_JMMYYGGgg()

int buoy_YYYYMMDDHHmm_to_JMMYYGGgg ( struct buoy_chunks b)

Sets YYGG from YYYYMMDDHHmm extended group.

Parameters
bpointer to the target struct buoy_chunks

Definition at line 31 of file bufr2tac_buoy.c.

32{
33 char aux[20];
34 time_t t;
35 struct tm tim;
36
37 if ( strlen ( b->e.YYYY ) &&
38 strlen ( b->e.MM ) &&
39 strlen ( b->e.DD ) &&
40 strlen ( b->e.HH ) &&
41 strlen ( b->e.MM ) )
42 {
43 sprintf ( aux,"%s%s%s%s%s", b->e.YYYY, b->e.MM, b->e.DD, b->e.HH, b->e.mm );
44 }
45
46 if ( strlen ( aux ) != 12 )
47 {
48 return 1;
49 }
50
51 memset ( &tim, 0, sizeof ( struct tm ) );
52 strptime ( aux, "%Y%m%d%H%M", &tim );
53
54 t = mktime ( &tim );
55 gmtime_r ( &t, &tim );
56 sprintf ( b->s0.YY, "%02d", tim.tm_mday );
57 sprintf ( b->s0.GG, "%02d", tim.tm_hour );
58 sprintf ( b->s0.MM, "%02d", (tim.tm_mon + 1) % 100 );
59 sprintf ( b->s0.J, "%d", tim.tm_year % 10 );
60 sprintf ( b->s0.gg, "%02d", tim.tm_min );
61
62 return 0;
63}
struct report_date_ext e
Definition: metbuoy.h:199
struct buoy_sec0 s0
Definition: metbuoy.h:201
char YY[4]
Definition: metbuoy.h:72
char J[4]
Definition: metbuoy.h:74
char gg[4]
Definition: metbuoy.h:76
char MM[4]
Definition: metbuoy.h:73
char GG[4]
Definition: metbuoy.h:75
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

References report_date_ext::DD, buoy_chunks::e, buoy_sec0::GG, buoy_sec0::gg, report_date_ext::HH, buoy_sec0::J, buoy_sec0::MM, report_date_ext::MM, report_date_ext::mm, buoy_chunks::s0, buoy_sec0::YY, and report_date_ext::YYYY.

Referenced by parse_subset_as_buoy().

Here is the caller graph for this function:

◆ parse_subset_as_buoy()

int parse_subset_as_buoy ( struct metreport m,
struct bufr2tac_subset_state s,
struct bufr_subset_sequence_data sq,
char *  err 
)

Definition at line 74 of file bufr2tac_buoy.c.

75{
76 size_t is;
77 char aux[32];
78 struct buoy_chunks *b;
79
80 //
81 b = &m->buoy;
82
83 // clean data
85
86 // reject if still not coded type
87 if ( strcmp ( s->type_report,"ZZYY" ) )
88 {
89 sprintf ( err,"bufr2tac: '%s' report still not decoded in this software", s->type_report );
90 return 1;
91 }
92
93 strcpy ( b->s0.MiMi, "ZZ" );
94 strcpy ( b->s0.MjMj, "YY" );
95
96 b->mask = BUOY_SEC0;
97
98 /**** First pass, sequential analysis *****/
99 for ( is = 0; is < sq->nd; is++ )
100 {
101 // check if is a significance qualifier
102 if ( sq->sequence[is].desc.x == 8 )
103 {
104 s->i = is;
105 s->a = &sq->sequence[is];
106 buoy_parse_x08 ( b, s );
107 }
108
109 if ( sq->sequence[is].mask & DESCRIPTOR_VALUE_MISSING ||
110 s->isq // case of an significance qualifier
111 )
112 {
113 continue;
114 }
115
116 s->i = is;
117 s->ival = ( int ) sq->sequence[is].val;
118 s->val = sq->sequence[is].val;
119 s->a = &sq->sequence[is];
120 if ( is > 0 )
121 {
122 s->a1 = &sq->sequence[is - 1];
123 }
124
125 switch ( sq->sequence[is].desc.x )
126 {
127
128 case 1: //localization descriptors
129 buoy_parse_x01 ( b, s );
130 break;
131
132 case 2: //Date time descriptors
133 buoy_parse_x02 ( b, s );
134 break;
135
136 case 4: //Date time descriptors
137 buoy_parse_x04 ( b, s );
138 break;
139
140 case 5: //Position
141 buoy_parse_x05 ( b, s );
142 break;
143
144 case 6: // Horizontal Position -2
145 buoy_parse_x06 ( b, s );
146 break;
147
148 case 7: // Vertical Position
149 buoy_parse_x07 ( b, s );
150 break;
151
152 case 10: // Air Pressure descriptors
153 buoy_parse_x10 ( b, s );
154 break;
155
156 case 11: // wind data
157 buoy_parse_x11 ( b, s );
158 break;
159
160 case 12: //Temperature descriptors
161 buoy_parse_x12 ( b, s );
162 break;
163
164 case 13: // Humidity and precipitation data
165 buoy_parse_x13 ( b, s );
166 break;
167
168 case 14: // Radiation
169 buoy_parse_x14 ( b, s );
170 break;
171
172 case 20: // Cloud data
173 buoy_parse_x20 ( b, s );
174 break;
175
176 case 22: // Oceanographic data
177 buoy_parse_x22 ( b, s );
178 break;
179
180 case 31: // Replicators
181 buoy_parse_x31 ( b, s );
182 break;
183
184
185 case 33: // Quality data
186 buoy_parse_x33 ( b, s );
187 break;
188
189
190 default:
191 break;
192 }
193
194 }
195
196 if ( ( ( s->mask & SUBSET_MASK_HAVE_LATITUDE ) == 0 ) ||
197 ( ( s->mask & SUBSET_MASK_HAVE_LONGITUDE ) == 0 ) ||
198 ( ( s->mask & SUBSET_MASK_HAVE_YEAR ) == 0 ) ||
199 ( ( s->mask & SUBSET_MASK_HAVE_MONTH ) == 0 ) ||
200 ( ( s->mask & SUBSET_MASK_HAVE_DAY ) == 0 ) ||
201 ( ( s->mask & SUBSET_MASK_HAVE_HOUR ) == 0 ) )
202 {
203 sprintf ( err,"bufr2tac: parse_subset_as_buoy(): lack of mandatory descriptor in sequence" );
204 return 1;
205 }
206
207 // copy WIGOS ID, if any
208 memcpy(&m->g.wid, &m->buoy.wid, sizeof (struct wigos_id) );
209
210 /****** Second pass. Global results and consistence analysis ************/
211
212 // adjust iw
213 if ( b->s0.iw[0] == '/' && b->s1.ff[0] != '/' )
214 {
215 b->s0.iw[0] = '1';
216 }
217
218 // fill date fields YYYYMMDDHHmm
220 b->mask |= BUOY_EXT;
221
222 // Fill some metreport fields
224 {
225 if ( fabs ( s->lat ) <= 90.0 )
226 {
227 m->g.lat = s->lat;
228 }
229 else
230 {
231 return 1; // Bad latitude. Fatal error
232 }
233 }
235 {
236 if ( fabs ( s->lon ) <= 180.0 )
237 {
238 m->g.lon = s->lon;
239 }
240 else
241 {
242 return 1; // bad longitude. Fatal error
243 }
244 }
246 {
247 m->g.alt = s->alt;
248 }
249 if ( s->mask & SUBSET_MASK_HAVE_NAME )
250 {
251 strcpy ( m->g.name, s->name );
252 }
253 sprintf ( aux,"%s%s%s%s%s", b->e.YYYY, b->e.MM, b->e.DD, b->e.HH, b->e.mm );
254 YYYYMMDDHHmm_to_met_datetime ( &m->t, aux );
255
256 // Fill some metreport fields
257 if ( b->s0.A1[0] && b->s0.bw[0] && b->s0.nbnbnb[0] )
258 {
259 sprintf ( m->g.index, "%s%s%s", b->s0.A1, b->s0.bw, b->s0.nbnbnb );
260 }
261
262 // check if set both LaLaLa and LoLoLoLo to set Qc
263 if ( ( b->s0.Qc[0] == 0 ) && b->s0.LaLaLaLaLa[0] && b->s0.LoLoLoLoLoLo[0] )
264 {
266 {
268 {
269 strcpy ( b->s0.Qc, "5" );
270 }
271 else
272 {
273 strcpy ( b->s0.Qc, "3" );
274 }
275 }
276 else
277 {
279 {
280 strcpy ( b->s0.Qc, "7" );
281 }
282 else
283 {
284 strcpy ( b->s0.Qc, "1" );
285 }
286 }
287 }
288
289 // check Qx
290 if ( b->s2.Qd[0] == 0 )
291 {
292 b->s2.Qd[0] = '0';
293 }
294 if ( b->s3.k2[0] == 0 )
295 {
296 b->s3.k2[0] = '0';
297 }
298 if ( b->s1.Qx[0] == 0 && b->s1.Qd[0] )
299 {
300 b->s1.Qx[0] = '9';
301 }
302 if ( b->s2.Qx[0] == 0 && b->s2.Qd[0] )
303 {
304 b->s2.Qx[0] = '9';
305 }
306
307 if ( b->s3.Qd1[0] == 0 )
308 {
309 b->s3.Qd1[0] = '0';
310 }
311 if ( b->s3.Qd2[0] == 0 )
312 {
313 b->s3.Qd2[0] = '0';
314 }
315
316 if ( b->s3.k3[0] == 0 )
317 {
318 b->s3.k3[0] = '/';
319 }
320 if ( b->s3.k6[0] == 0 )
321 {
322 b->s3.k6[0] = '/';
323 }
324
325 return 0;
326}
int buoy_parse_x33(struct buoy_chunks *b, struct bufr2tac_subset_state *s)
Parse a expanded descriptor with X = 33.
Definition: bufr2tac_x33.c:34
#define SUBSET_MASK_HAVE_MONTH
Bit mask to mark a struct bufr_subset_sequence_data having observation month.
Definition: bufr2tac.h:146
int buoy_parse_x07(struct buoy_chunks *b, struct bufr2tac_subset_state *s)
Parse a expanded descriptor with X = 07.
Definition: bufr2tac_x07.c:164
int buoy_parse_x05(struct buoy_chunks *b, struct bufr2tac_subset_state *s)
Parse a expanded descriptor with X = 05.
Definition: bufr2tac_x05.c:134
#define SUBSET_MASK_HAVE_NAME
Bit mask to mark a struct bufr_subset_sequence_data having station name.
Definition: bufr2tac.h:128
int buoy_parse_x14(struct buoy_chunks *b, struct bufr2tac_subset_state *s)
Parse a expanded descriptor with X = 14.
Definition: bufr2tac_x14.c:467
int buoy_parse_x01(struct buoy_chunks *b, struct bufr2tac_subset_state *s)
Parse a expanded descriptor with X = 01.
Definition: bufr2tac_x01.c:205
int buoy_parse_x13(struct buoy_chunks *b, struct bufr2tac_subset_state *s)
Parse a expanded descriptor with X = 13.
Definition: bufr2tac_x13.c:877
#define SUBSET_MASK_LATITUDE_SOUTH
Bit mask to mark a struct bufr_subset_sequence_data with south latitude.
Definition: bufr2tac.h:74
int buoy_parse_x11(struct buoy_chunks *b, struct bufr2tac_subset_state *s)
Parse a expanded descriptor with X = 11.
Definition: bufr2tac_x11.c:387
#define SUBSET_MASK_LONGITUDE_WEST
Bit mask to mark a struct bufr_subset_sequence_data with west longitude.
Definition: bufr2tac.h:80
#define SUBSET_MASK_HAVE_ALTITUDE
Bit mask to mark a struct bufr_subset_sequence_data having altitude.
Definition: bufr2tac.h:122
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 buoy_parse_x10(struct buoy_chunks *b, struct bufr2tac_subset_state *s)
Parse a expanded descriptor with X = 10.
Definition: bufr2tac_x10.c:161
int buoy_parse_x06(struct buoy_chunks *b, struct bufr2tac_subset_state *s)
Parse a expanded descriptor with X = 06.
Definition: bufr2tac_x06.c:129
int buoy_parse_x02(struct buoy_chunks *b, struct bufr2tac_subset_state *s)
Parse a expanded descriptor with X = 02.
Definition: bufr2tac_x02.c:83
#define SUBSET_MASK_HAVE_YEAR
Bit mask to mark a struct bufr_subset_sequence_data having observation year.
Definition: bufr2tac.h:140
int YYYYMMDDHHmm_to_met_datetime(struct met_datetime *t, const char *source)
Parse the string YYYYMMDDHHmm[ss] and set a struct met_datetime.
int buoy_parse_x31(struct buoy_chunks *b, struct bufr2tac_subset_state *s)
Parse a expanded descriptor with X = 31.
Definition: bufr2tac_x31.c:81
int buoy_parse_x04(struct buoy_chunks *b, struct bufr2tac_subset_state *s)
Parse a expanded descriptor with X = 04.
Definition: bufr2tac_x04.c:254
int buoy_parse_x12(struct buoy_chunks *b, struct bufr2tac_subset_state *s)
Parse a expanded descriptor with X = 12.
Definition: bufr2tac_x12.c:466
#define SUBSET_MASK_HAVE_LONGITUDE
Bit mask to mark a struct bufr_subset_sequence_data having longitude.
Definition: bufr2tac.h:116
int buoy_parse_x08(struct buoy_chunks *b, struct bufr2tac_subset_state *s)
Parse a expanded descriptor with X = 08.
Definition: bufr2tac_x08.c:121
#define SUBSET_MASK_HAVE_LATITUDE
Bit mask to mark a struct bufr_subset_sequence_data having latitude.
Definition: bufr2tac.h:110
void bufr2tac_clean_buoy_chunks(struct buoy_chunks *b)
cleans a buoy_chunks struct
int buoy_parse_x20(struct buoy_chunks *b, struct bufr2tac_subset_state *s)
Parse a expanded descriptor with X = 20.
#define SUBSET_MASK_HAVE_DAY
Bit mask to mark a struct bufr_subset_sequence_data having observation day in a month.
Definition: bufr2tac.h:152
#define SUBSET_MASK_HAVE_HOUR
Bit mask to mark a struct bufr_subset_sequence_data having observation hour.
Definition: bufr2tac.h:158
int buoy_YYYYMMDDHHmm_to_JMMYYGGgg(struct buoy_chunks *b)
Sets YYGG from YYYYMMDDHHmm extended group.
Definition: bufr2tac_buoy.c:31
#define DESCRIPTOR_VALUE_MISSING
Bit mask for a missing value in a struct bufr_atom_data.
Definition: bufrdeco.h:140
#define BUOY_EXT
mask bit meaning date extension is parsed with success
Definition: metbuoy.h:58
#define BUOY_SEC0
mask bit meaning section 0 of buoy is solicited to or parsed with success
Definition: metbuoy.h:33
struct bufr_atom_data * a1
Definition: bufr2tac.h:250
struct bufr_atom_data * a
Definition: bufr2tac.h:249
char type_report[16]
Definition: bufr2tac.h:247
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
int mask
Definition: metbuoy.h:198
struct buoy_sec1 s1
Definition: metbuoy.h:202
char LoLoLoLoLoLo[8]
Definition: metbuoy.h:80
char MjMj[4]
Definition: metbuoy.h:67
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 iw[2]
Definition: metbuoy.h:77
char bw[2]
Definition: metbuoy.h:69
char Qx[2]
Definition: metbuoy.h:92
char ff[4]
Definition: metbuoy.h:94
char Qd[2]
Definition: metbuoy.h:91
char Qd[2]
Definition: metbuoy.h:112
char Qx[2]
Definition: metbuoy.h:113
char k2[2]
Definition: metbuoy.h:151
char k6[2]
Definition: metbuoy.h:153
char Qd2[2]
Definition: metbuoy.h:150
char k3[2]
Definition: metbuoy.h:152
char Qd1[2]
Definition: metbuoy.h:149
double lat
Definition: bufr2tac.h:299
double lon
Definition: bufr2tac.h:300
double alt
Definition: bufr2tac.h:301
struct wigos_id wid
Definition: bufr2tac.h:295
char index[16]
Definition: bufr2tac.h:296
char name[80]
Definition: bufr2tac.h:297
struct buoy_chunks buoy
Definition: bufr2tac.h:317
struct met_datetime t
Definition: bufr2tac.h:314
struct met_geo g
Definition: bufr2tac.h:315
WIGOS station identifier.
Definition: metcommon.h:46

References bufr2tac_subset_state::a, bufr2tac_subset_state::a1, buoy_sec0::A1, bufr2tac_subset_state::alt, met_geo::alt, bufr2tac_clean_buoy_chunks(), metreport::buoy, BUOY_EXT, buoy_parse_x01(), buoy_parse_x02(), buoy_parse_x04(), buoy_parse_x05(), buoy_parse_x06(), buoy_parse_x07(), buoy_parse_x08(), buoy_parse_x10(), buoy_parse_x11(), buoy_parse_x12(), buoy_parse_x13(), buoy_parse_x14(), buoy_parse_x20(), buoy_parse_x22(), buoy_parse_x31(), buoy_parse_x33(), BUOY_SEC0, buoy_YYYYMMDDHHmm_to_JMMYYGGgg(), buoy_sec0::bw, report_date_ext::DD, DESCRIPTOR_VALUE_MISSING, buoy_chunks::e, buoy_sec1::ff, metreport::g, report_date_ext::HH, bufr2tac_subset_state::i, met_geo::index, bufr2tac_subset_state::isq, bufr2tac_subset_state::ival, buoy_sec0::iw, buoy_sec3::k2, buoy_sec3::k3, buoy_sec3::k6, buoy_sec0::LaLaLaLaLa, bufr2tac_subset_state::lat, met_geo::lat, buoy_sec0::LoLoLoLoLoLo, bufr2tac_subset_state::lon, met_geo::lon, bufr2tac_subset_state::mask, buoy_chunks::mask, buoy_sec0::MiMi, buoy_sec0::MjMj, report_date_ext::MM, report_date_ext::mm, bufr2tac_subset_state::name, met_geo::name, buoy_sec0::nbnbnb, buoy_sec0::Qc, buoy_sec1::Qd, buoy_sec2::Qd, buoy_sec3::Qd1, buoy_sec3::Qd2, buoy_sec1::Qx, buoy_sec2::Qx, buoy_chunks::s0, buoy_chunks::s1, buoy_chunks::s2, buoy_chunks::s3, SUBSET_MASK_HAVE_ALTITUDE, SUBSET_MASK_HAVE_DAY, SUBSET_MASK_HAVE_HOUR, SUBSET_MASK_HAVE_LATITUDE, SUBSET_MASK_HAVE_LONGITUDE, SUBSET_MASK_HAVE_MONTH, SUBSET_MASK_HAVE_NAME, SUBSET_MASK_HAVE_YEAR, SUBSET_MASK_LATITUDE_SOUTH, SUBSET_MASK_LONGITUDE_WEST, metreport::t, bufr2tac_subset_state::type_report, bufr2tac_subset_state::val, met_geo::wid, buoy_chunks::wid, report_date_ext::YYYY, and YYYYMMDDHHmm_to_met_datetime().

Referenced by parse_subset_sequence().

Here is the call graph for this function:
Here is the caller graph for this function: