bufr2synop 0.24.0
Functions
bufrnoaa_utils.c File Reference

File with some routines for bufrnoaa binary. More...

#include "bufrnoaa.h"
Include dependency graph for bufrnoaa_utils.c:

Go to the source code of this file.

Functions

int is_bufr (unsigned char *b)
 checks if an unsigned char from an array is the first char of 'BUFR' More...
 
int is_head (unsigned char *b)
 checks if an unsigned char from an array is the first char of '****' More...
 
int is_head_custom (unsigned char *b, char mark)
 checks if an unsigned char from an array is the first char of repeated mark char four times More...
 
int is_endb (unsigned char *b)
 checks if an unsigned char from an array is the first char of '7777' More...
 
int timeval_substract (struct timeval *result, struct timeval *x, struct timeval *y)
 Subtract the ‘struct timeval’ values X and Y, storing the result in RESULT. More...
 
int bufr_is_selected (char *name)
 returns 1 if selected message 0 otherwise More...
 
int date_mtime_from_stat (char *date, struct stat *st)
 get a string with date and time from a struct stat More...
 
int mtime_from_stat (char *filename, struct stat *st)
 modifies a file update time from a struct stat More...
 

Detailed Description

File with some routines for bufrnoaa binary.

Definition in file bufrnoaa_utils.c.

Function Documentation

◆ bufr_is_selected()

int bufr_is_selected ( char *  name)

returns 1 if selected message 0 otherwise

Parameters
namestring with name to check

Definition at line 124 of file bufrnoaa_utils.c.

125{
126 if ( strlen ( SEL ) == 0 )
127 return 0;
128 if ( strchr ( SEL, name[1] ) == NULL )
129 return 0;
130 if ( name[1] == 'S' )
131 {
132 if ( strlen ( SELS ) == 0 )
133 return 1;
134 else if ( strchr ( SELS, name[2] ) == NULL )
135 return 0;
136 }
137
138 if ( name[1] == 'O' )
139 {
140 if ( strlen ( SELO ) == 0 )
141 return 1;
142 else if ( strchr ( SELO, name[2] ) == NULL )
143 return 0;
144 }
145
146 if ( name[1] == 'U' )
147 {
148 if ( strlen ( SELU ) == 0 )
149 return 1;
150 else if ( strchr ( SELU, name[2] ) == NULL )
151 return 0;
152 }
153
154 return 1;
155}
char SELU[64]
Definition: bufrnoaa.c:199
char SELS[64]
Definition: bufrnoaa.c:198
char SELO[64]
Definition: bufrnoaa.c:200

References SELO, SELS, and SELU.

Referenced by main().

Here is the caller graph for this function:

◆ date_mtime_from_stat()

int date_mtime_from_stat ( char *  date,
struct stat *  st 
)

get a string with date and time from a struct stat

Parameters
datestring wuth the result
stpointer to a strucr stat

Definition at line 163 of file bufrnoaa_utils.c.

164{
165 struct tm tim;
166 memset ( &tim, 0, sizeof ( tim ) );
167 gmtime_r ( & ( st->st_mtime ), &tim );
168 strftime ( date, 16, "%Y%m%d%H%M%S", &tim );
169 return 1;
170}

Referenced by main().

Here is the caller graph for this function:

◆ is_bufr()

int is_bufr ( unsigned char *  b)

checks if an unsigned char from an array is the first char of 'BUFR'

Parameters
bpointer to unsigned char to check

Returns 1 if success, 0 othewise

Definition at line 33 of file bufrnoaa_utils.c.

34{
35 if ( b[0] == 'R' && b[1] == 'F' && b[2] == 'U' && b[3] == 'B' )
36 return 1;
37 return 0;
38}

Referenced by main().

Here is the caller graph for this function:

◆ is_endb()

int is_endb ( unsigned char *  b)

checks if an unsigned char from an array is the first char of '7777'

Parameters
bpointer to unsigned char to check

Returns 1 if success, 0 othewise

Definition at line 76 of file bufrnoaa_utils.c.

77{
78 if ( b[0] == '7' && b[1] == '7' && b[2] == '7' && b[3] == '7' )
79 return 1;
80 return 0;
81}

Referenced by main().

Here is the caller graph for this function:

◆ is_head()

int is_head ( unsigned char *  b)

checks if an unsigned char from an array is the first char of '****'

Parameters
bpointer to unsigned char to check

Returns 1 if success, 0 othewise

Definition at line 47 of file bufrnoaa_utils.c.

48{
49 if ( b[0] == '*' && b[1] == '*' && b[2] == '*' && b[3] == '*' )
50 return 1;
51 return 0;
52}

◆ is_head_custom()

int is_head_custom ( unsigned char *  b,
char  mark 
)

checks if an unsigned char from an array is the first char of repeated mark char four times

Parameters
bpointer to unsigned char to check
markchar to be found repeated four times since b Returns 1 if success, 0 othewise

Definition at line 61 of file bufrnoaa_utils.c.

62{
63 if ( b[0] == mark && b[1] == mark && b[2] == mark && b[3] == mark )
64 return 1;
65 return 0;
66}

Referenced by main().

Here is the caller graph for this function:

◆ mtime_from_stat()

int mtime_from_stat ( char *  filename,
struct stat *  st 
)

modifies a file update time from a struct stat

Parameters
filenamestring with the pathname of file to modify
stpointer to a struct stat as reference

Definition at line 178 of file bufrnoaa_utils.c.

179{
180 struct utimbuf ut;
181 ut.modtime = st->st_mtime;
182 ut.actime = st->st_mtime;
183 utime ( filename, &ut );
184 return 1;
185}

Referenced by main().

Here is the caller graph for this function:

◆ timeval_substract()

int timeval_substract ( struct timeval *  result,
struct timeval *  x,
struct timeval *  y 
)

Subtract the ‘struct timeval’ values X and Y, storing the result in RESULT.

Parameters
resultpointer to a struct timeval where to set the result
xpointer to struct timeval as X in (X - Y)
ypointer to struct timeval as Y in (X - Y)

Return 1 if the difference is negative, otherwise 0.

Definition at line 93 of file bufrnoaa_utils.c.

95{
96 /* Perform the carry for the later subtraction by updating Y. */
97 if ( x->tv_usec < y->tv_usec )
98 {
99 int nsec = ( y->tv_usec - x->tv_usec ) / 1000000 + 1;
100 y->tv_usec -= 1000000 * nsec;
101 y->tv_sec += nsec;
102 }
103 if ( x->tv_usec - y->tv_usec > 1000000 )
104 {
105 int nsec = ( x->tv_usec - y->tv_usec ) / 1000000;
106 y->tv_usec += 1000000 * nsec;
107 y->tv_sec -= nsec;
108 }
109
110 /* Compute the time remaining to wait.
111 `tv_usec' is certainly positive. */
112 result->tv_sec = x->tv_sec - y->tv_sec;
113 result->tv_usec = x->tv_usec - y->tv_usec;
114
115 /* Return 1 if result is negative. */
116 return x->tv_sec < y->tv_sec;
117}

Referenced by main().

Here is the caller graph for this function: