bufr2synop 0.24.0
bufr2tac_x06.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_x06.c
22 \brief decodes the descriptors with X = 06 (Horizontal Position-2)
23 */
24#include "bufr2tac.h"
25
26
27/*!
28 \fn char * latlon_to_MMM(char *target, double lat, double lon)
29 \brief convert latitude and longitude to a MMM string
30 \param lat latitude (degree, N positive)
31 \param lon longitude (degree, E positive)
32 \param target resulting MMM string
33*/
34char * latlon_to_MMM ( char *target, double lat, double lon )
35{
36 int col, row, ori = 0;
37
38 if ( lon < 0.0 )
39 col = ( int ) ( -lat * 0.1 ) + 1;
40 else
41 col = 36 - ( int ) ( lat * 0.1 );
42
43
44 if ( lat >= 80.0 )
45 row = 25;
46 else if ( lat >= 0.0 )
47 row = ( int ) ( lat * 0.1 );
48 else
49 {
50 ori = 299;
51 row = ( int ) ( -lat * 0.1 );
52 }
53
54 sprintf ( target,"%03d", col + ori + row * 36 );
55
56 return target;
57}
58
59/*!
60 \fn int syn_parse_x06 ( struct synop_chunks *syn, struct bufr2tac_subset_state *s )
61 \brief Parse a expanded descriptor with X = 06
62 \param syn pointer to a struct \ref synop_chunks where to set the results
63 \param s pointer to a struct \ref bufr2tac_subset_state where is stored needed information in sequential analysis
64
65 It returns 0 if success, 1 if problems when processing. If a descriptor is not processed returns 0 anyway
66*/
67int syn_parse_x06 ( struct synop_chunks *syn, struct bufr2tac_subset_state *s )
68{
69 int ia;
70
72 return 0;
73
74 switch ( s->a->desc.y )
75 {
76 case 1: // 0 06 001 . Longitude (High accuracy)
77 case 2: // 0 06 002 . Longitude (Coarse)
78 if ( s->val < 0.0 )
79 s->mask |= SUBSET_MASK_LONGITUDE_WEST; // Sign for longitude
81 ia = ( int ) ( fabs ( s->val ) * 10.0 + 0.5 );
82 sprintf ( syn->s0.LoLoLoLo, "%04d",ia );
83 syn->s0.Ulo[0] = syn->s0.LoLoLoLo[2];
84 s->lon = s->val;
85 break;
86
87 default:
88 if ( BUFR2TAC_DEBUG_LEVEL > 1 && (s->a->mask & DESCRIPTOR_VALUE_MISSING) == 0 )
89 bufr2tac_set_error ( s, 0, "syn_parse_x06()", "Descriptor not parsed" );
90 break;
91 }
92
93 // check if set both LaLaLa and LoLoLoLo to set Qc
94 if ( ( syn->s0.Qc[0] == 0 ) && syn->s0.LaLaLa[0] && syn->s0.LoLoLoLo[0] )
95 {
97 {
99 strcpy ( syn->s0.Qc, "5" );
100 else
101 strcpy ( syn->s0.Qc, "3" );
102 }
103 else
104 {
106 strcpy ( syn->s0.Qc, "7" );
107 else
108 strcpy ( syn->s0.Qc, "1" );
109 }
110 }
111
112 // check if about MMM
113 if ( ( syn->s0.MMM[0] == 0 ) && syn->s0.LaLaLa[0] && syn->s0.LoLoLoLo[0] )
114 {
115 latlon_to_MMM ( syn->s0.MMM, s->lat, s->lon );
116 }
117
118 return 0;
119}
120
121/*!
122 \fn int buoy_parse_x06 ( struct buoy_chunks *b, struct bufr2tac_subset_state *s )
123 \brief Parse a expanded descriptor with X = 06
124 \param b pointer to a struct \ref buoy_chunks where to set the results
125 \param s pointer to a struct \ref bufr2tac_subset_state where is stored needed information in sequential analysis
126
127 It returns 0 if success, 1 if problems when processing. If a descriptor is not processed returns 0 anyway
128*/
130{
131 int ia;
132
133 if ( s->a->mask & DESCRIPTOR_VALUE_MISSING )
134 return 0;
135
136 switch ( s->a->desc.y )
137 {
138 case 1: // 0 06 001 . Longitude (High accuracy)
139 case 2: // 0 06 002 . Longitude (Coarse accuracy)
140 if ( s->val < 0.0 )
141 s->mask |= SUBSET_MASK_LONGITUDE_WEST; // Sign for longitude
143 s->lon = s->val;
144 ia = ( int ) ( fabs ( s->val ) * 1000.0 + 0.5 );
145 sprintf ( b->s0.LoLoLoLoLoLo, "%06d",ia );
146 break;
147
148 default:
149 if ( BUFR2TAC_DEBUG_LEVEL > 1 && (s->a->mask & DESCRIPTOR_VALUE_MISSING) == 0 )
150 bufr2tac_set_error ( s, 0, "buoy_parse_x06()", "Descriptor not parsed" );
151 break;
152 }
153 return 0;
154}
155
156
157/*!
158 \fn int climat_parse_x06 ( struct climat_chunks *c, struct bufr2tac_subset_state *s )
159 \brief Parse a expanded descriptor with X = 06
160 \param c pointer to a struct \ref climat_chunks where to set the results
161 \param s pointer to a struct \ref bufr2tac_subset_state where is stored needed information in sequential analysis
162
163 It returns 0 if success, 1 if problems when processing. If a descriptor is not processed returns 0 anyway
164*/
166{
167 if ( s->a->mask & DESCRIPTOR_VALUE_MISSING )
168 return 0;
169
170 // this is to avoid warning
171 if ( c == NULL )
172 return 1;
173
174 switch ( s->a->desc.y )
175 {
176 case 1: // 0 06 001 . Longitude (High accuracy)
177 case 2: // 0 06 002 . Longitude (Coarse accuracy)
178 if ( s->val < 0.0 )
179 s->mask |= SUBSET_MASK_LONGITUDE_WEST; // Sign for longitude
181 s->lon = s->val;
182 break;
183
184 default:
185 if ( BUFR2TAC_DEBUG_LEVEL > 1 && (s->a->mask & DESCRIPTOR_VALUE_MISSING) == 0 )
186 bufr2tac_set_error ( s, 0, "climat_parse_x06()", "Descriptor not parsed" );
187 break;
188 }
189 return 0;
190}
191
192/*!
193 \fn int temp_parse_x06 ( struct tempop_chunks *t, struct bufr2tac_subset_state *s )
194 \brief Parse a expanded descriptor with X = 06
195 \param t pointer to a struct \ref temp_chunks where to set the results
196 \param s pointer to a struct \ref bufr2tac_subset_state where is stored needed information in sequential analysis
197
198 It returns 0 if success, 1 if problems when processing. If a descriptor is not processed returns 0 anyway
199*/
201{
202 int ia;
203
204 if ( s->a->mask & DESCRIPTOR_VALUE_MISSING )
205 return 0;
206
207 switch ( s->a->desc.y )
208 {
209 case 1: // 0 06 001 . Longitude (High accuracy)
210 case 2: // 0 06 002 . Longitude (Coarse)
211 if ( s->val < 0.0 )
212 s->mask |= SUBSET_MASK_LONGITUDE_WEST; // Sign for longitude
214 ia = ( int ) ( fabs ( s->val ) * 10.0 + 0.5 );
215 sprintf ( t->a.s1.LoLoLoLo, "%04d",ia );
216 sprintf ( t->b.s1.LoLoLoLo, "%04d",ia );
217 sprintf ( t->c.s1.LoLoLoLo, "%04d",ia );
218 sprintf ( t->d.s1.LoLoLoLo, "%04d",ia );
219 t->a.s1.Ulo[0] = t->a.s1.LoLoLoLo[2];
220 t->b.s1.Ulo[0] = t->b.s1.LoLoLoLo[2];
221 t->c.s1.Ulo[0] = t->c.s1.LoLoLoLo[2];
222 t->d.s1.Ulo[0] = t->d.s1.LoLoLoLo[2];
223 s->lon = s->val;
224
225 // check if set both LaLaLa and LoLoLoLo to set Qc
226 if ( ( t->a.s1.Qc[0] == 0 ) && t->a.s1.LaLaLa[0] && t->a.s1.LoLoLoLo[0] )
227 {
229 {
231 strcpy ( t->a.s1.Qc, "5" );
232 else
233 strcpy ( t->a.s1.Qc, "3" );
234 }
235 else
236 {
238 strcpy ( t->a.s1.Qc, "7" );
239 else
240 strcpy ( t->a.s1.Qc, "1" );
241 }
242 strcpy ( t->b.s1.Qc, t->a.s1.Qc );
243 strcpy ( t->c.s1.Qc, t->a.s1.Qc );
244 strcpy ( t->d.s1.Qc, t->a.s1.Qc );
245 }
246
247 // check if about MMM
248 if ( ( t->a.s1.MMM[0] == 0 ) && t->a.s1.LaLaLa[0] && t->a.s1.LoLoLoLo[0] )
249 {
250 latlon_to_MMM ( t->a.s1.MMM, s->lat, s->lon );
251 strcpy ( t->b.s1.MMM, t->a.s1.MMM );
252 strcpy ( t->c.s1.MMM, t->a.s1.MMM );
253 strcpy ( t->d.s1.MMM, t->a.s1.MMM );
254 }
255 break;
256
257 case 15: // 0 06 015. Longitude displacement since launch site (high accuracy)
258 if ( s->rep > 0 && s->r->n > 0 )
259 {
260 s->r->raw[s->r->n - 1].dlon = s->val;
261 }
262 else if ( s->w->n > 0 )
263 {
264 s->w->raw[s->w->n - 1].dlon = s->val;
265 }
266 break;
267
268 default:
269 if ( BUFR2TAC_DEBUG_LEVEL > 1 && (s->a->mask & DESCRIPTOR_VALUE_MISSING) == 0 )
270 bufr2tac_set_error ( s, 0, "temp_parse_x06()", "Descriptor not parsed" );
271 break;
272 }
273
274 return 0;
275}
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_LONGITUDE
Bit mask to mark a struct bufr_subset_sequence_data having longitude.
Definition: bufr2tac.h:116
int syn_parse_x06(struct synop_chunks *syn, struct bufr2tac_subset_state *s)
Parse a expanded descriptor with X = 06.
Definition: bufr2tac_x06.c:67
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 climat_parse_x06(struct climat_chunks *c, struct bufr2tac_subset_state *s)
Parse a expanded descriptor with X = 06.
Definition: bufr2tac_x06.c:165
int temp_parse_x06(struct temp_chunks *t, struct bufr2tac_subset_state *s)
Definition: bufr2tac_x06.c:200
char * latlon_to_MMM(char *target, double lat, double lon)
convert latitude and longitude to a MMM string
Definition: bufr2tac_x06.c:34
#define DESCRIPTOR_VALUE_MISSING
Bit mask for a missing value in a struct bufr_atom_data.
Definition: bufrdeco.h:140
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 LoLoLoLoLoLo[8]
Definition: metbuoy.h:80
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_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 Ulo[2]
Definition: metsynop.h:110
char MMM[4]
Definition: metsynop.h:108
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 Ulo[2]
Definition: mettemp.h:326
char Qc[2]
Definition: mettemp.h:322
char Qc[2]
Definition: mettemp.h:349
char MMM[4]
Definition: mettemp.h:351
char Ulo[2]
Definition: mettemp.h:353
char LoLoLoLo[6]
Definition: mettemp.h:350
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