bufr2synop 0.24.0
bufr2tac_x10.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_x10.c
22 \brief decodes the descriptors with X = 10 (air pressure)
23 */
24#include "bufr2tac.h"
25
26/*!
27 \fn char * pascal_to_ppp ( char *target, double P )
28 \brief Converts pascal values (variation) into a ppp string
29 \param P the pressure variation in Pascal units
30 \param target string with the result
31*/
32char * pascal_to_ppp ( char *target, double P )
33{
34 int ic;
35 if ( P > 0 )
36 {
37 ic = ( int ) ( P * 0.1 );
38 }
39 else
40 {
41 ic = ( int ) ( -P * 0.1 );
42 }
43 sprintf ( target, "%03d", ic % 1000 );
44 return target;
45}
46
47char * pascal_to_pnpnpn ( char *target, double P )
48{
49 int ic;
50 if ( P > 10000.0 )
51 {
52 ic = ( int ) ( P * 0.01 + 0.5 );
53 }
54 else
55 {
56 ic = ( int ) ( P * 0.1 + 0.5 );
57 }
58 sprintf ( target, "%03d", ic % 1000 );
59 return target;
60}
61
62
63/*!
64 \fn char * pascal_to_PPPP ( char *target, double P )
65 \brief Converts pascal values into a PPPP string
66 \param P the pressure variation in Pascal units
67 \param target string with the result
68*/
69char * pascal_to_PPPP ( char *target, double P )
70{
71 int ic;
72 ic = ( int ) ( P * 0.1 );
73 sprintf ( target, "%04d", ic % 10000 );
74 return target;
75}
76
77/*!
78 \fn int syn_parse_x10 ( struct synop_chunks *syn, struct bufr2tac_subset_state *s )
79 \brief Parse a expanded descriptor with X = 10
80 \param syn pointer to a s if ( BUFR2TAC_DEBUG_LEVEL > 0 )
81 bufr2tac_set_error ( s, 0, "syn_parse_x08()", "Descriptor not parsed" );
82truct \ref synop_chunks where to set the results
83 \param s pointer to a struct \ref bufr2tac_subset_state where is stored needed information in sequential analysis
84
85 It returns 0 if success, 1 if problems when processing. If a descriptor is not processed returns 0 anyway
86*/
87int syn_parse_x10 ( struct synop_chunks *syn, struct bufr2tac_subset_state *s )
88{
89 char aux[16];
90
92 {
93 return 0;
94 }
95
96 switch ( s->a->desc.y )
97 {
98 case 4: // 0 10 004 . Pressure
99 pascal_to_PPPP ( aux, s->val );
100 strcpy ( syn->s1.PoPoPoPo, aux );
101 syn->mask |= SYNOP_SEC1;
102 break;
103
104 case 9: // 0 10 009. Geopotential at standard level
105 sprintf ( syn->s1.hhh, "%03d", abs(s->ival) % 1000 );
106 syn->mask |= SYNOP_SEC1;
107 break;
108
109 case 51: // 0 10 051 . Pressure reduced to mean sea level
110 pascal_to_PPPP ( aux, s->val );
111 memcpy ( syn->s1.PPPP, aux, 4 );
112 syn->s1.PPPP[4] = 0;
113 syn->mask |= SYNOP_SEC1;
114 break;
115
116 case 61: // 0 10 061 . 3-hour pressure change
117 pascal_to_ppp ( aux, s->val );
118 memcpy(syn->s1.ppp, aux, 3);
119 syn->s1.ppp[3] = 0;
120 syn->mask |= SYNOP_SEC1;
121 break;
122
123 case 62: // 0 10 062 . 24-hour pressure change
124 pascal_to_ppp ( aux, s->val );
125 memcpy ( syn->s3.ppp24, aux, 3 );
126 syn->s3.ppp24[3] = 0;
127 if ( s->val >= 0 )
128 {
129 strcpy ( syn->s3.snp24, "8" );
130 }
131 else
132 {
133 strcpy ( syn->s3.snp24, "9" );
134 }
135 syn->mask |= SYNOP_SEC3;
136 break;
137
138 case 63: // 0 10 063 . Characteristic of pressure tendency
139 if ( s->ival > 9 || s->ival < 0)
140 return 1;
141 sprintf ( syn->s1.a, "%1d",s->ival );
142 syn->mask |= SYNOP_SEC1;
143 break;
144
145 default:
146 if ( BUFR2TAC_DEBUG_LEVEL > 1 && (s->a->mask & DESCRIPTOR_VALUE_MISSING) == 0 )
147 bufr2tac_set_error ( s, 0, "syn_parse_x10()", "Descriptor not parsed" );
148 break;
149 }
150 return 0;
151}
152
153/*!
154 \fn int buoy_parse_x10 ( struct buoy_chunks *b, struct bufr2tac_subset_state *s )
155 \brief Parse a expanded descriptor with X = 10
156 \param b pointer to a struct \ref buoy_chunks where to set the results
157 \param s pointer to a struct \ref bufr2tac_subset_state where is stored needed information in sequential analysis
158
159 It returns 0 if success, 1 if problems when processing. If a descriptor is not processed returns 0 anyway
160*/
162{
163 char aux[16];
164
165 if ( s->a->mask & DESCRIPTOR_VALUE_MISSING )
166 {
167 return 0;
168 }
169
170 switch ( s->a->desc.y )
171 {
172
173 case 4: // 0 10 004 . Pressure
174 pascal_to_PPPP ( aux, s->val );
175 strcpy ( b->s1.PoPoPoPo, aux );
176 b->mask |= BUOY_SEC1;
177 break;
178
179 case 51: // 0 10 051 . Pressure reduced to mean sea level
180 pascal_to_PPPP ( aux, s->val );
181 strcpy ( b->s1.PPPP, aux );
182 b->mask |= BUOY_SEC1;
183 break;
184
185 case 63: // 0 10 063 . Characteristic of pressure tendency
186 sprintf ( b->s1.a, "%1d",s->ival );
187 b->mask |= BUOY_SEC1;
188 break;
189
190 case 61: // 0 10 061 . 3-hour pressure change
191 pascal_to_ppp ( aux, s->val );
192 memcpy( b->s1.ppp, aux, 3 );
193 b->s1.ppp[3] = 0;
194 b->mask |= BUOY_SEC1;
195 break;
196
197 default:
198 if ( BUFR2TAC_DEBUG_LEVEL > 1 && (s->a->mask & DESCRIPTOR_VALUE_MISSING) == 0 )
199 bufr2tac_set_error ( s, 0, "buoy_parse_x10()", "Descriptor not parsed" );
200 break;
201 }
202 return 0;
203}
204
205
206/*!
207 \fn int climat_parse_x10 ( struct climat_chunks *c, struct bufr2tac_subset_state *s )
208 \brief Parse a expanded descriptor with X = 10
209 \param c pointer to a struct \ref climat_chunks where to set the results
210 \param s pointer to a struct \ref bufr2tac_subset_state where is stored needed information in sequential analysis
211
212 It returns 0 if success, 1 if problems when processing. If a descriptor is not processed returns 0 anyway
213*/
215{
216 char aux[16];
217
218 if ( c == NULL || s == NULL )
219 {
220 return 1;
221 }
222
223 if ( s->a->mask & DESCRIPTOR_VALUE_MISSING )
224 {
225 return 0;
226 }
227
228 switch ( s->a->desc.y )
229 {
230 case 4: // 0 10 004 . Pressure
231 if ( s->isq_val == 4 )
232 {
233 pascal_to_PPPP ( aux, s->val );
234 if ( s->is_normal == 0 )
235 {
236 strcpy ( c->s1.PoPoPoPo, aux );
237 c->mask |= CLIMAT_SEC1;
238 }
239 else
240 {
241 strcpy ( c->s2.PoPoPoPo, aux );
242 c->mask |= CLIMAT_SEC2;
243 }
244 }
245 break;
246
247 case 9: // 0 10 009 . Heigh of geopotential
248 if ( s->isq_val == 4 )
249 {
250 if ( s->is_normal == 0 )
251 {
252 sprintf ( c->s1.PPPP, "%04d", s->ival );
253 c->mask |= CLIMAT_SEC1;
254 }
255 else
256 {
257 sprintf ( c->s1.PPPP, "%04d", s->ival );
258 c->mask |= CLIMAT_SEC2;
259 }
260 }
261 break;
262
263 case 51: // 0 10 051 . Pressure reduced to mean sea level
264 if ( s->isq_val == 4 )
265 {
266 pascal_to_PPPP ( aux, s->val );
267 if ( s->is_normal == 0 )
268 {
269 strcpy ( c->s1.PPPP, aux );
270 c->mask |= CLIMAT_SEC1;
271 }
272 else
273 {
274 strcpy ( c->s2.PPPP, aux );
275 c->mask |= CLIMAT_SEC2;
276 }
277 }
278 break;
279
280 default:
281 if ( BUFR2TAC_DEBUG_LEVEL > 1 && (s->a->mask & DESCRIPTOR_VALUE_MISSING) == 0 )
282 bufr2tac_set_error ( s, 0, "climat_parse_x10()", "Descriptor not parsed" );
283 break;
284
285 }
286 return 0;
287}
288
289/*!
290 \fn int temp_parse_x10 ( struct temp_chunks *t, struct bufr2tac_subset_state *s )
291 \brief Parse a expanded descriptor with X = 10
292 \param t pointer to a struct \ref temp_chunks where to set the results
293 \param s pointer to a struct \ref bufr2tac_subset_state where is stored needed information in sequential analysis
294
295 It returns 0 if success, 1 if problems when processing. If a descriptor is not processed returns 0 anyway
296*/
298{
299 if ( t == NULL || s == NULL )
300 {
301 return 1;
302 }
303
304 if ( s->a->mask & DESCRIPTOR_VALUE_MISSING )
305 {
306 return 0;
307 }
308
309 switch ( s->a->desc.y )
310 {
311 case 9: // 0 10 009. geopotential
312 if ( s->rep > 0 && s->r->n > 0 )
313 {
314 s->r->raw[s->r->n - 1].h = s->val;
315 }
316 break;
317
318 default:
319 if ( BUFR2TAC_DEBUG_LEVEL > 1 && (s->a->mask & DESCRIPTOR_VALUE_MISSING) == 0 )
320 bufr2tac_set_error ( s, 0, "temp_parse_x10()", "Descriptor not parsed" );
321 break;
322 }
323 return 0;
324}
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 * pascal_to_ppp(char *target, double P)
Converts pascal values (variation) into a ppp string.
Definition: bufr2tac_x10.c:32
char * pascal_to_pnpnpn(char *target, double P)
Definition: bufr2tac_x10.c:47
int climat_parse_x10(struct climat_chunks *c, struct bufr2tac_subset_state *s)
Parse a expanded descriptor with X = 10.
Definition: bufr2tac_x10.c:214
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
char * pascal_to_PPPP(char *target, double P)
Converts pascal values into a PPPP string.
Definition: bufr2tac_x10.c:69
int syn_parse_x10(struct synop_chunks *syn, struct bufr2tac_subset_state *s)
Parse a expanded descriptor with X = 10.
Definition: bufr2tac_x10.c:87
int temp_parse_x10(struct temp_chunks *t, struct bufr2tac_subset_state *s)
Parse a expanded descriptor with X = 10.
Definition: bufr2tac_x10.c:297
#define DESCRIPTOR_VALUE_MISSING
Bit mask for a missing value in a struct bufr_atom_data.
Definition: bufrdeco.h:140
#define BUOY_SEC1
mask bit meaning section 1 of buoy is solicited to or parsed with success
Definition: metbuoy.h:38
#define CLIMAT_SEC2
mask bit meaning section 2 of climat is solicited to or parsed with success
Definition: metclimat.h:42
#define CLIMAT_SEC1
mask bit meaning section 1 of climat is solicited to or parsed with success
Definition: metclimat.h:37
#define SYNOP_SEC1
mask bit meaning section 1 or synop is solicited to or parsed with success
Definition: metsynop.h:39
#define SYNOP_SEC3
mask bit meaning section 3 or synop is solicited to or parsed with success
Definition: metsynop.h:49
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
struct temp_raw_data * r
Definition: bufr2tac.h:285
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
int mask
Definition: metbuoy.h:198
struct buoy_sec1 s1
Definition: metbuoy.h:202
char a[2]
Definition: metbuoy.h:103
char PoPoPoPo[6]
Definition: metbuoy.h:101
char ppp[4]
Definition: metbuoy.h:104
char PPPP[6]
Definition: metbuoy.h:102
contains all possible substrings from a synop report is parsed with success
Definition: metclimat.h:213
struct climat_sec1 s1
Definition: metclimat.h:218
struct climat_sec2 s2
Definition: metclimat.h:219
char PoPoPoPo[8]
Definition: metclimat.h:82
char PPPP[8]
Definition: metclimat.h:83
char PPPP[8]
Definition: metclimat.h:114
char PoPoPoPo[8]
Definition: metclimat.h:113
contains all possible substrings from a synop report is parsed with success
Definition: metsynop.h:293
struct synop_sec1 s1
Definition: metsynop.h:298
struct synop_sec3 s3
Definition: metsynop.h:300
char PoPoPoPo[6]
Definition: metsynop.h:136
char hhh[4]
Definition: metsynop.h:139
char PPPP[6]
Definition: metsynop.h:137
char a[2]
Definition: metsynop.h:140
char ppp[4]
Definition: metsynop.h:141
char snp24[2]
Definition: metsynop.h:253
char ppp24[4]
Definition: metsynop.h:254
Store the whole TEMP report.
Definition: mettemp.h:511
struct temp_raw_point_data raw[TEMP_NMAX_POINTS *4]
Definition: mettemp.h:215
size_t n
Definition: mettemp.h:214