bufr2synop 0.24.0
bufr2tac_x07.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_x07.c
22 \brief decodes the descriptors with X = 07 (Vertical Position)
23 */
24#include "bufr2tac.h"
25
26/*!
27 \fn char * grad_to_ec ( char *target, double grad )
28 \brief Converts elevation in grads to ec (code table 1004)
29 \param grad the elevation angle (degrees)
30 \param target the resulting code
31*/
32char * grad_to_ec ( char *target, double grad )
33{
34 if ( grad < 5.0 )
35 strcpy ( target, "9" );
36 else if ( grad < 6.5 )
37 strcpy ( target, "8" );
38 else if ( grad < 8.0 )
39 strcpy ( target, "7" );
40 else if ( grad < 10.5 )
41 strcpy ( target, "6" );
42 else if ( grad < 13.5 )
43 strcpy ( target, "5" );
44 else if ( grad < 17.5 )
45 strcpy ( target, "4" );
46 else if ( grad < 25.0 )
47 strcpy ( target, "3" );
48 else if ( grad < 40.0 )
49 strcpy ( target, "2" );
50 else if ( grad >= 45.0 )
51 strcpy ( target, "1" );
52 else
53 strcpy ( target, "0" );
54 return target;
55}
56
57/*!
58 \fn int syn_parse_x07 ( struct synop_chunks *syn, struct bufr2tac_subset_state *s )
59 \brief Parse a expanded descriptor with X = 07
60 \param syn pointer to a struct \ref synop_chunks where to set the results
61 \param s pointer to a struct \ref bufr2tac_subset_state where is stored needed information in sequential analysis
62
63 It returns 0 if success, 1 if problems when processing. If a descriptor is not processed returns 0 anyway
64*/
65int syn_parse_x07 ( struct synop_chunks *syn, struct bufr2tac_subset_state *s )
66{
67 // this is to avoid warning
68 if ( syn == NULL )
69 {
70 return 1;
71 }
72
73 switch ( s->a->desc.y )
74 {
75 case 1: // 0 07 001 . Heigh of station
76 case 30: // 0 07 030 . Height of station ground above msl
77 case 31: // 0 07 031 . Height of barometer above msl
79 {
80 return 0;
81 }
82 if ( syn->s0.h0h0h0h0[0] == 0 )
83 {
84 if (s->ival > 9999 || s->ival < -9999)
85 return 1;
86 sprintf ( syn->s0.h0h0h0h0, "%04d", s->ival );
87 syn->s0.im[0] = '1';// set unit as m
89 }
90 s->alt = s->val;
91 break;
92
93 case 4: // 0 07 004 . Pressure at standard level
95 {
96 return 0;
97 }
98 if ( s->ival == 100000 )
99 {
100 strcpy ( syn->s1.a3, "1" );
101 }
102 else if ( s->ival == 92500 )
103 {
104 strcpy ( syn->s1.a3, "2" );
105 }
106 else if ( s->ival == 85000 )
107 {
108 strcpy ( syn->s1.a3, "8" );
109 }
110 else if ( s->ival == 70000 )
111 {
112 strcpy ( syn->s1.a3, "7" );
113 }
114 else if ( s->ival == 50000 )
115 {
116 strcpy ( syn->s1.a3, "5" );
117 }
118 break;
119
120 case 21: // 0 07 021 . Elevation angle
121 if ( s->a->mask & DESCRIPTOR_VALUE_MISSING )
122 {
123 return 0;
124 }
125 grad_to_ec ( syn->s3.ec, s->val );
126 syn->mask |= SYNOP_SEC3;
127 break;
128
129 case 32: // 0 07 032 Height of sensor above local ground
130 if ( s->a->mask & DESCRIPTOR_VALUE_MISSING )
131 {
132 s->hsensor = -999.9; // clean value
133 return 0;
134 }
135 s->hsensor = s->val;
136 break;
137
138 case 33: // 0 07 033 Height of sensor above water surface
139 if ( s->a->mask & DESCRIPTOR_VALUE_MISSING )
140 {
141 s->hwsensor = -999.9; // clean value
142 return 0;
143 }
144 s->hwsensor = s->val;
145 break;
146
147 default:
148 if ( BUFR2TAC_DEBUG_LEVEL > 1 && (s->a->mask & DESCRIPTOR_VALUE_MISSING) == 0 )
149 bufr2tac_set_error ( s, 0, "syn_parse_x07()", "Descriptor not parsed" );
150 break;
151 }
152
153 return 0;
154}
155
156/*!
157 \fn int buoy_parse_x07 ( struct buoy_chunks *b, struct bufr2tac_subset_state *s )
158 \brief Parse a expanded descriptor with X = 07
159 \param b pointer to a struct \ref buoy_chunks where to set the results
160 \param s pointer to a struct \ref bufr2tac_subset_state where is stored needed information in sequential analysis
161
162 It returns 0 if success, 1 if problems when processing. If a descriptor is not processed returns 0 anyway
163*/
165{
166
167 if ( s->a->mask & DESCRIPTOR_VALUE_MISSING )
168 {
169 return 0;
170 }
171
172 if ( b == NULL )
173 {
174 return 1;
175 }
176
177 switch ( s->a->desc.y )
178 {
179 case 62: // 0 07 062 Depth below sea/water surface
180 case 63: // 0 07 063 Profundity below sea/water level
181 if ( s->k_rep == ( s->i - 1 ) ) // Case of first layer after a replicator
182 {
183 s->layer = 0;
184 }
185 else
186 {
187 ( s->layer ) ++;
188 }
189 s->deep = ( int ) ( s->val + 0.5 );
190 break;
191
192 default:
193 if ( BUFR2TAC_DEBUG_LEVEL > 1 && (s->a->mask & DESCRIPTOR_VALUE_MISSING) == 0 )
194 bufr2tac_set_error ( s, 0, "buoy_parse_x07()", "Descriptor not parsed" );
195 break;
196 }
197 return 0;
198}
199
200/*!
201 \fn int climat_parse_x07 ( struct synop_chunks *c, struct bufr2tac_subset_state *s )
202 \brief Parse a expanded descriptor with X = 07
203 \param c pointer to a struct \ref climat_chunks where to set the results
204 \param s pointer to a struct \ref bufr2tac_subset_state where is stored needed information in sequential analysis
205
206 It returns 0 if success, 1 if problems when processing. If a descriptor is not processed returns 0 anyway
207*/
209{
210 if ( s->a->mask & DESCRIPTOR_VALUE_MISSING )
211 {
212 return 0;
213 }
214
215 // this is to avoid warning
216 if ( c == NULL )
217 {
218 return 1;
219 }
220
221 switch ( s->a->desc.y )
222 {
223 case 1: // 0 07 001 . Heigh of station
224 case 30: // 0 07 030 . Height of station ground above msl
225 case 31: // 0 07 031 . Height of barometer above msl
226 s->alt = s->val;
227 break;
228
229 case 32: // 0 07 032 . Pressure of standard level
230 // Not a useful value for alphanumeric climat
231 if ( BUFR2TAC_DEBUG_LEVEL > 0 )
232 bufr2tac_set_error ( s, 0, "climat_parse_x07()", "Descriptor not parsed" );
233 break;
234
235 case 4: // Pressure of standard level
236 // Not a useful value for alphanumeric climat
237 if ( BUFR2TAC_DEBUG_LEVEL > 0 )
238 bufr2tac_set_error ( s, 0, "climat_parse_x07()", "Descriptor not parsed" );
239 break;
240
241 default:
242 if ( BUFR2TAC_DEBUG_LEVEL > 1 && (s->a->mask & DESCRIPTOR_VALUE_MISSING) == 0 )
243 bufr2tac_set_error ( s, 0, "climat_parse_x07()", "Descriptor not parsed" );
244 break;
245 }
246
247 return 0;
248}
249
250/*!
251 \fn int temp_parse_x07 ( struct synop_chunks *c, struct bufr2tac_subset_state *s )
252 \brief Parse a expanded descriptor with X = 07
253 \param c pointer to a struct \ref temp_chunks where to set the results
254 \param s pointer to a struct \ref bufr2tac_subset_state where is stored needed information in sequential analysis
255
256 It returns 0 if success, 1 if problems when processing. If a descriptor is not processed returns 0 anyway
257*/
259{
260 if ( s->a->mask & DESCRIPTOR_VALUE_MISSING )
261 {
262 return 0;
263 }
264
265// this is to avoid warning
266 if ( t == NULL )
267 {
268 return 1;
269 }
270
271 switch ( s->a->desc.y )
272 {
273 case 4: // 0 07 004 . Pressure
274 if ( s->rep > 0 && s->r->n > 0 )
275 {
276 s->r->raw[s->r->n - 1].p = s->val;
277 }
278 else if ( s->w->n > 0 )
279 {
280 s->w->raw[s->w->n - 1].p = s->val;
281 }
282 break;
283
284 case 30: // 0 07 030 . Height of station ground above msl
285 sprintf ( t->a.s1.h0h0h0h0, "%04.0lf" , s->val );
286 sprintf ( t->b.s1.h0h0h0h0, "%04.0lf" , s->val );
287 sprintf ( t->c.s1.h0h0h0h0, "%04.0lf" , s->val );
288 sprintf ( t->d.s1.h0h0h0h0, "%04.0lf" , s->val );
289 break;
290
291 case 31: // 0 07 031 . Height of barometer above msl
292 s->alt = s->val;
293 break;
294
295 default:
296 if ( BUFR2TAC_DEBUG_LEVEL > 1 && (s->a->mask & DESCRIPTOR_VALUE_MISSING) == 0 )
297 bufr2tac_set_error ( s, 0, "temp_parse_x07()", "Descriptor not parsed" );
298 break;
299 }
300
301 return 0;
302}
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)
#define SUBSET_MASK_HAVE_ALTITUDE
Bit mask to mark a struct bufr_subset_sequence_data having altitude.
Definition: bufr2tac.h:122
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
char * grad_to_ec(char *target, double grad)
Converts elevation in grads to ec (code table 1004)
Definition: bufr2tac_x07.c:32
int temp_parse_x07(struct temp_chunks *t, struct bufr2tac_subset_state *s)
Definition: bufr2tac_x07.c:258
int syn_parse_x07(struct synop_chunks *syn, struct bufr2tac_subset_state *s)
Parse a expanded descriptor with X = 07.
Definition: bufr2tac_x07.c:65
int climat_parse_x07(struct climat_chunks *c, struct bufr2tac_subset_state *s)
Definition: bufr2tac_x07.c:208
#define DESCRIPTOR_VALUE_MISSING
Bit mask for a missing value in a struct bufr_atom_data.
Definition: bufrdeco.h:140
#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 temp_raw_wind_shear_data * w
Definition: bufr2tac.h:286
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
contains all possible substrings from a synop report is parsed with success
Definition: metclimat.h:213
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
struct synop_sec0 s0
Definition: metsynop.h:297
char h0h0h0h0[6]
Definition: metsynop.h:111
char im[2]
Definition: metsynop.h:112
char a3[2]
Definition: metsynop.h:138
char ec[2]
Definition: metsynop.h:252
struct temp_acd_sec1 s1
Definition: mettemp.h:455
char h0h0h0h0[6]
Definition: mettemp.h:327
char h0h0h0h0[6]
Definition: mettemp.h:354
struct temp_b_sec1 s1
Definition: mettemp.h:470
struct temp_acd_sec1 s1
Definition: mettemp.h:485
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_acd_sec1 s1
Definition: mettemp.h:500
struct temp_raw_point_data raw[TEMP_NMAX_POINTS *4]
Definition: mettemp.h:215
size_t n
Definition: mettemp.h:214
struct temp_raw_wind_shear_point raw[TEMP_NMAX_POINTS]
Definition: mettemp.h:240