bufr2synop 0.24.0
bufr2tac_x05.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_x05.c
22 \brief decodes the descriptors with X = 05 (Position-1)
23 */
24#include "bufr2tac.h"
25
26/*!
27 \fn char * grad_to_D ( char *D, double grad )
28 \brief Converts true direction in grads to D (code table 0700)
29 \param grad the true direction (degrees)
30 \param D the resulting code
31*/
32char * grad_to_D ( char *D, double grad )
33{
34 if ( grad >= 22.5 && grad < 67.5 )
35 strcpy ( D, "1" );
36 else if ( grad >= 67.5 && grad < 112.5 )
37 strcpy ( D, "2" );
38 else if ( grad >= 112.5 && grad < 157.5 )
39 strcpy ( D, "3" );
40 else if ( grad >= 157.5 && grad < 202.5 )
41 strcpy ( D, "4" );
42 else if ( grad >= 202.5 && grad < 247.5 )
43 strcpy ( D, "5" );
44 else if ( grad >= 247.5 && grad < 292.5 )
45 strcpy ( D, "6" );
46 else if ( grad >= 292.5 && grad < 337.5 )
47 strcpy ( D, "7" );
48 else if ( ( grad >= 337.5 && grad <= 360.0 ) ||
49 ( grad >0.0 && grad < 22.5 ) )
50 strcpy ( D, "8" );
51 else if ( grad == 0.0 )
52 strcpy ( D, "0" );
53 else
54 strcpy ( D, "9" );
55 return D;
56}
57
58/*!
59 \fn int syn_parse_x05 ( struct synop_chunks *syn, struct bufr2tac_subset_state *s )
60 \brief Parse a expanded descriptor with X = 05
61 \param syn pointer to a struct \ref synop_chunks where to set the results
62 \param s pointer to a struct \ref bufr2tac_subset_state where is stored needed information in sequential analysis
63
64 It returns 0 if success, 1 if problems when processing. If a descriptor is not processed returns 0 anyway
65*/
66int syn_parse_x05 ( struct synop_chunks *syn, struct bufr2tac_subset_state *s )
67{
68 int ia;
69
71 return 0;
72
73 switch ( s->a->desc.y )
74 {
75 case 1: // 0 05 001 . Latitude (High accuracy)
76 case 2: // 0 05 002 . Latitude (Coarse accuracy)
77 if ( s->val < 0.0 )
78 s->mask |= SUBSET_MASK_LATITUDE_SOUTH; // Sign for latitude
80 ia = ( int ) ( fabs ( s->val ) * 10.0 + 0.5 );
81 if (ia > 999 || ia < 0)
82 return 1;
83 sprintf ( syn->s0.LaLaLa, "%03d", ia );
84 syn->s0.Ula[0] = syn->s0.LaLaLa[1];
85 s->lat = s->val;
86 break;
87
88 case 21: // 0 05 021 . Bearing or azimut
89 grad_to_D ( syn->s3.Da, s->val );
90 syn->mask |= SYNOP_SEC3;
91 break;
92 default:
93 if ( BUFR2TAC_DEBUG_LEVEL > 1 && (s->a->mask & DESCRIPTOR_VALUE_MISSING) == 0 )
94 bufr2tac_set_error ( s, 0, "syn_parse_x05()", "Descriptor not parsed" );
95 break;
96 }
97
98 // check if set both LaLaLa and LoLoLoLo to set Qc
99 if ( ( syn->s0.Qc[0] == 0 ) && syn->s0.LaLaLa[0] && syn->s0.LoLoLoLo[0] )
100 {
102 {
104 strcpy ( syn->s0.Qc, "5" );
105 else
106 strcpy ( syn->s0.Qc, "3" );
107 }
108 else
109 {
111 strcpy ( syn->s0.Qc, "7" );
112 else
113 strcpy ( syn->s0.Qc, "1" );
114 }
115 }
116
117 // check about Mardsen square
118 if ( ( syn->s0.MMM[0] == 0 ) && syn->s0.LaLaLa[0] && syn->s0.LoLoLoLo[0] )
119 {
120 latlon_to_MMM ( syn->s0.MMM, s->lat, s->lon ); // compute it
121 }
122
123 return 0;
124}
125
126/*!
127 \fn int buoy_parse_x05 ( struct buoy_chunks *b, struct bufr2tac_subset_state *s )
128 \brief Parse a expanded descriptor with X = 05
129 \param b pointer to a struct \ref buoy_chunks where to set the results
130 \param s pointer to a struct \ref bufr2tac_subset_state where is stored needed information in sequential analysis
131
132 It returns 0 if success, 1 if problems when processing. If a descriptor is not processed returns 0 anyway
133*/
135{
136 int ia;
137
138 if ( s->a->mask & DESCRIPTOR_VALUE_MISSING )
139 return 0;
140
141 switch ( s->a->desc.y )
142 {
143 case 1: // 0 05 001 . Latitude (High accuracy)
144 case 2: // 0 05 002 . Latitude (Coarse accuracy)
145 if ( s->val < 0.0 )
146 s->mask |= SUBSET_MASK_LATITUDE_SOUTH; // Sign for latitude
148 ia = ( int ) ( fabs ( s->val ) * 1000.0 + 0.5 );
149 sprintf ( b->s0.LaLaLaLaLa, "%05d",ia );
150 s->lat = s->val;
151 break;
152
153 default:
154 if ( BUFR2TAC_DEBUG_LEVEL > 1 && (s->a->mask & DESCRIPTOR_VALUE_MISSING) == 0 )
155 bufr2tac_set_error ( s, 0, "buoy_parse_x05()", "Descriptor not parsed" );
156 break;
157 }
158
159 return 0;
160}
161
162/*!
163 \fn int climat_parse_x05 ( struct climat_chunks *c, struct bufr2tac_subset_state *s )
164 \brief Parse a expanded descriptor with X = 05
165 \param c pointer to a struct \ref climat_chunks where to set the results
166 \param s pointer to a struct \ref bufr2tac_subset_state where is stored needed information in sequential analysis
167
168 It returns 0 if success, 1 if problems when processing. If a descriptor is not processed returns 0 anyway
169*/
171{
172 if ( s->a->mask & DESCRIPTOR_VALUE_MISSING )
173 return 0;
174
175 // this is to avoid warning
176 if ( c == NULL )
177 return 1;
178
179 switch ( s->a->desc.y )
180 {
181 case 1: // 0 05 001 . Latitude (High accuracy)
182 case 2: // 0 05 002 . Latitude (Coarse accuracy)
183 if ( s->val < 0.0 )
184 s->mask |= SUBSET_MASK_LATITUDE_SOUTH; // Sign for latitude
186 s->lat = s->val;
187 break;
188 default:
189 if ( BUFR2TAC_DEBUG_LEVEL > 1 && (s->a->mask & DESCRIPTOR_VALUE_MISSING) == 0 )
190 bufr2tac_set_error ( s, 0, "climat_parse_x05()", "Descriptor not parsed" );
191 break;
192 }
193 return 0;
194}
195
196/*!
197 \fn int temp_parse_x05 ( struct climat_chunks *syn, struct bufr2tac_subset_state *s )
198 \brief Parse a expanded descriptor with X = 05
199 \param t pointer to a struct \ref climat_chunks where to set the results
200 \param s pointer to a struct \ref bufr2tac_subset_state where is stored needed information in sequential analysis
201
202 It returns 0 if success, 1 if problems when processing. If a descriptor is not processed returns 0 anyway
203*/
205{
206 int ia;
207
208 if ( s->a->mask & DESCRIPTOR_VALUE_MISSING )
209 return 0;
210
211 // this is to avoid warning
212 if ( t == NULL )
213 return 1;
214
215 switch ( s->a->desc.y )
216 {
217 case 1: // 0 05 001 . Latitude (High accuracy)
218 case 2: // 0 05 002 . Latitude (Coarse accuracy)
219 if ( s->val < 0.0 )
220 s->mask |= SUBSET_MASK_LATITUDE_SOUTH; // Sign for latitude
222 s->lat = s->val;
223 ia = ( int ) ( fabs ( s->val ) * 10.0 + 0.5 );
224 sprintf ( t->a.s1.LaLaLa, "%03d",ia );
225 sprintf ( t->b.s1.LaLaLa, "%03d",ia );
226 sprintf ( t->c.s1.LaLaLa, "%03d",ia );
227 sprintf ( t->d.s1.LaLaLa, "%03d",ia );
228 t->a.s1.Ula[0] = t->a.s1.LaLaLa[1];
229 t->b.s1.Ula[0] = t->b.s1.LaLaLa[1];
230 t->c.s1.Ula[0] = t->c.s1.LaLaLa[1];
231 t->d.s1.Ula[0] = t->d.s1.LaLaLa[1];
232
233 // check if set both LaLaLa and LoLoLoLo to set Qc
234 if ( ( t->a.s1.Qc[0] == 0 ) && t->a.s1.LaLaLa[0] && t->a.s1.LoLoLoLo[0] )
235 {
237 {
239 strcpy ( t->a.s1.Qc, "5" );
240 else
241 strcpy ( t->a.s1.Qc, "3" );
242 }
243 else
244 {
246 strcpy ( t->a.s1.Qc, "7" );
247 else
248 strcpy ( t->a.s1.Qc, "1" );
249 }
250 strcpy ( t->b.s1.Qc, t->a.s1.Qc );
251 strcpy ( t->c.s1.Qc, t->a.s1.Qc );
252 strcpy ( t->d.s1.Qc, t->a.s1.Qc );
253 }
254
255 // check if about MMM
256 if ( ( t->a.s1.MMM[0] == 0 ) && t->a.s1.LaLaLa[0] && t->a.s1.LoLoLoLo[0] )
257 {
258 latlon_to_MMM ( t->a.s1.MMM, s->lat, s->lon );
259 strcpy ( t->b.s1.MMM, t->a.s1.MMM );
260 strcpy ( t->c.s1.MMM, t->a.s1.MMM );
261 strcpy ( t->d.s1.MMM, t->a.s1.MMM );
262 }
263 break;
264
265 case 15: // 0 05 015. Latitude displacement since launch site (high accuracy)
266 if ( s->rep > 0 && s->r->n > 0 )
267 {
268 s->r->raw[s->r->n - 1].dlat = s->val;
269 }
270 else if ( s->w->n > 0 )
271 {
272 s->w->raw[s->w->n - 1].dlat = s->val;
273 }
274 break;
275
276 default:
277 if ( BUFR2TAC_DEBUG_LEVEL > 1 && (s->a->mask & DESCRIPTOR_VALUE_MISSING) == 0 )
278 bufr2tac_set_error ( s, 0, "temp_parse_x05()", "Descriptor not parsed" );
279 break;
280 }
281
282 return 0;
283}
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_LATITUDE_SOUTH
Bit mask to mark a struct bufr_subset_sequence_data with south latitude.
Definition: bufr2tac.h:74
#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_LATITUDE
Bit mask to mark a struct bufr_subset_sequence_data having latitude.
Definition: bufr2tac.h:110
char * latlon_to_MMM(char *target, double lat, double lon)
convert latitude and longitude to a MMM string
Definition: bufr2tac_x06.c:34
int temp_parse_x05(struct temp_chunks *t, struct bufr2tac_subset_state *s)
Definition: bufr2tac_x05.c:204
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
char * grad_to_D(char *D, double grad)
Converts true direction in grads to D (code table 0700)
Definition: bufr2tac_x05.c:32
int climat_parse_x05(struct climat_chunks *c, struct bufr2tac_subset_state *s)
Parse a expanded descriptor with X = 05.
Definition: bufr2tac_x05.c:170
int syn_parse_x05(struct synop_chunks *syn, struct bufr2tac_subset_state *s)
Parse a expanded descriptor with X = 05.
Definition: bufr2tac_x05.c:66
#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
struct buoy_sec0 s0
Definition: metbuoy.h:201
char LaLaLaLaLa[8]
Definition: metbuoy.h:79
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_sec3 s3
Definition: metsynop.h:300
struct synop_sec0 s0
Definition: metsynop.h:297
char LaLaLa[4]
Definition: metsynop.h:105
char Qc[2]
Definition: metsynop.h:106
char LoLoLoLo[6]
Definition: metsynop.h:107
char Ula[2]
Definition: metsynop.h:109
char MMM[4]
Definition: metsynop.h:108
char Da[2]
Definition: metsynop.h:251
struct temp_acd_sec1 s1
Definition: mettemp.h:455
char LoLoLoLo[6]
Definition: mettemp.h:323
char MMM[4]
Definition: mettemp.h:324
char LaLaLa[4]
Definition: mettemp.h:321
char Qc[2]
Definition: mettemp.h:322
char Ula[2]
Definition: mettemp.h:325
char Qc[2]
Definition: mettemp.h:349
char MMM[4]
Definition: mettemp.h:351
char LaLaLa[4]
Definition: mettemp.h:348
char Ula[2]
Definition: mettemp.h:352
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