32 return ( source[2] + source[1] * 256 + source[0] * 65536 );
46 d->
x = (
id % 100000 ) / 1000;
48 sprintf ( d->
c,
"%06d",
id );
62 *
id = 100000 * d->
f + 1000 * d->
x + d->
y;
69 return ( uint32_t ) 1;
70 else if ( width < index )
71 return ( uint32_t ) 0;
72 else if ( width <= 32 )
73 return ( ( ( uint32_t ) 1 ) << ( width - index ) );
75 return ( uint32_t ) 0;
88 memcpy ( s , buf, size );
103 while ( l && s[--l] ==
' ' )
121size_t tokenize_string (
char *tk[],
size_t ntk,
char *target,
size_t len,
char *blanks )
124 char d[] =
" =\n\r\v\t", *b, *aux;
127 if ( blanks == NULL )
133 n = strlen ( target );
134 if ( n == 0 || n > len )
138 tk[0] = strtok_r ( target, b, &aux );
140 ( ( tk[i] = strtok_r ( NULL, b, &aux ) ) != NULL ) &&
141 strlen ( tk[i] ) > 2 &&
142 strlen ( tk[i] ) < 10 )
158 if ( strlen ( source ) != 12 && strlen ( source ) != 14 )
160 memset ( &t->
tim, 0, sizeof (
struct tm ) );
161 if ( strlen ( source ) == 12 )
163 strptime ( source,
"%Y%m%d%H%M", &t->
tim );
167 strptime ( source,
"%Y%m%d%H%M%S", &t->
tim );
169 strcpy ( t->
datime, source );
170 t->
t = mktime ( &t->
tim );
185 tx = ( ( t->
t + 1800 ) / 3600 ) * 3600 ;
186 memset ( &tim, 0,
sizeof (
struct tm ) );
187 gmtime_r ( &tx, &tim );
189 strftime ( target, 8,
"%d%H", &tim );
196 target->
t = ( ( source->
t + 1800 ) / 3600 ) * 3600 ;
197 memset ( &target->
tim, 0, sizeof (
struct tm ) );
198 gmtime_r ( &target->
t, &target->
tim );
199 strftime ( target->
datime, 16,
"%Y%m%d%H%M", &target->
tim );
216 if ( II == NULL || iii == NULL )
219 if ( II[0] == 0 || iii[0] == 0 )
223 sprintf ( aux,
"%s%s", II, iii );
225 if ( ( II[0] ==
'0' && ( strstr ( aux,
"042" ) != aux ) && ( strstr ( aux,
"043" ) != aux ) &&
226 ( strstr ( aux,
"044" ) != aux ) && ( strstr ( aux,
"0858" ) != aux ) && ( strstr ( aux,
"0859" ) != aux ) ) ||
227 II[0] ==
'1' || ( strstr ( aux,
"201" ) == aux ) ||
228 strcmp ( II,
"22" ) == 0 || strcmp ( II,
"26" ) == 0 || strcmp ( II,
"27" ) == 0 ||
229 strcmp ( II,
"33" ) == 0 || strcmp ( II,
"34" ) == 0 || strcmp ( II,
"22" ) == 0 ||
230 ( strstr ( aux,
"201" ) == aux ) )
236 else if ( II[0] ==
'6' || ( strstr ( aux,
"0858" ) == aux ) || ( strstr ( aux,
"0859" ) == aux ) )
242 else if ( II[0] ==
'5' || ( strcmp ( II,
"49" ) == 0 ) || ( strcmp ( II,
"21" ) == 0 ) ||
243 ( strcmp ( II,
"23" ) == 0 ) || ( strcmp ( II,
"24" ) == 0 ) || ( strcmp ( II,
"25" ) == 0 ) ||
244 ( strcmp ( II,
"28" ) == 0 ) || ( strcmp ( II,
"29" ) == 0 ) || ( strcmp ( II,
"30" ) == 0 ) ||
245 ( strcmp ( II,
"31" ) == 0 ) || ( strcmp ( II,
"32" ) == 0 ) || ( strcmp ( II,
"38" ) == 0 ) ||
246 ( strcmp ( II,
"35" ) == 0 ) || ( strcmp ( II,
"36" ) == 0 ) || ( strcmp ( II,
"39" ) == 0 ) ||
247 ( strcmp ( aux,
"20200" ) >= 0 && strcmp ( aux,
"20999" ) <= 0 ) ||
248 ( strcmp ( aux,
"40000" ) >= 0 && strcmp ( aux,
"48599" ) <= 0 ) ||
249 ( strcmp ( aux,
"48800" ) >= 0 && strcmp ( aux,
"49999" ) <= 0 ) )
255 else if ( strcmp ( aux,
"80000" ) >= 0 && strcmp ( aux,
"88999" ) <= 0 )
259 strcpy ( Reg,
"III" );
261 else if ( II[0] ==
'7' || strstr ( aux,
"042" ) == aux ||
262 strstr ( aux,
"043" ) == aux || strstr ( aux,
"044" ) == aux )
268 else if ( ( strcmp ( aux,
"48600" ) >= 0 && strcmp ( aux,
"48799" ) <= 0 ) ||
269 ( strcmp ( aux,
"90000" ) >= 0 && strcmp ( aux,
"98999" ) <= 0 ) )
275 else if ( strcmp ( II,
"89" ) == 0 )
297 if ( m->
t.
t > ( now + 1800 ) )
469 char aux[256], *tk[16], *c;
476 if ( ( c = strrchr ( aux,
'/' ) ) == NULL )
485 if ( nt < 5 || nt > 6 )
489 if ( strcmp ( tk[nt - 1],
"bufr" ) )
493 if ( strlen ( tk[0] ) != 14 || strspn ( tk[0],
"0123456789" ) != 14 )
498 if ( strlen ( tk[1] ) != 6 || strspn ( &tk[1][4],
"0123456789" ) != 2 )
500 strcpy ( h->
bname, tk[1] );
503 if ( strlen ( tk[2] ) != 4 )
505 strcpy ( h->
center, tk[2] );
507 if ( strlen ( tk[3] ) != 6 || strspn ( tk[3],
"0123456789" ) != 6 )
509 strcpy ( h->
dtrel, tk[3] );
513 strcpy ( h->
order,
"BBB" );
517 if ( strlen ( tk[4] ) == 3 )
518 strcpy ( h->
order, tk[4] );
Include header file for binary bufr2tac.
char * met_datetime_to_YYGG(char *target, struct met_datetime *t)
Get YYGG from a struct met_datetime.
int check_date_from_future(struct metreport *m)
Check a estructure metreport not from future.
int guess_gts_header(struct gts_header *h, const char *f)
Guess the WMO GTS header from filename.
char * guess_WMO_region(char *A1, char *Reg, const char *II, const char *iii)
get WMO region A1 and Reg items from II and iii (WMO index)
int integer_to_descriptor(struct bufr_descriptor *d, int id)
parse an integer with a descriptor fom bufr ECWMF libary
size_t tokenize_string(char *tk[], size_t ntk, char *target, size_t len, char *blanks)
Split the report string into tokens.
char * charray_to_string(char *s, unsigned char *buf, size_t size)
get a null termitated c-string from an array of unsigned chars
uint32_t get_flag_value(uint8_t width, uint8_t index)
int YYYYMMDDHHmm_to_met_datetime(struct met_datetime *t, const char *source)
Parse the string YYYYMMDDHHmm[ss] and set a struct met_datetime.
int round_met_datetime_to_hour(struct met_datetime *target, struct met_datetime *source)
unsigned int three_bytes_to_uint(const unsigned char *source)
returns the integer value from an array of three bytes, most significant first
int descriptor_to_integer(int *id, struct bufr_descriptor *d)
parse a descriptor and sets an integer in the decimal formas fxxyyy
char * adjust_string(char *s)
Supress trailing blanks of a string.
stores date and time reference of a report, commonly the observation time
all the information for a meteorological report in WMO text format from a BUFR file