bufr2synop 0.24.0
bufr2tac_error.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_error.c
22 \brief This file has the code for functions to manage errors in bufr2tac library
23*/
24#include "bufr2tac.h"
25
26int bufr2tac_push_error ( struct bufr2tac_error_stack *e, int severity, char *description )
27{
28 // avoid segfaults
29 if ( e == NULL )
30 return -1; // Fatal error
31
33 {
34 e->err[e->ne].severity = severity;
35 strcpy ( e->err[e->ne].description, description );
36 ( e->ne )++;
37 return 1;
38 }
39 else if ( e->ne == BUFR2TAC_ERROR_STACK_DIM )
40 {
41 // Do not pull error, but annotate the stack as rebased
42 if ( e->full < severity )
43 e->full = severity;
44 return 0;
45 }
46 return -1; // bad e->ne
47}
48
50{
51 if ( e != NULL )
52 {
53 memset ( e, 0, sizeof ( struct bufr2tac_error_stack ) );
54 return 0;
55 }
56 return -1;
57}
58
59int bufr2tac_set_error ( struct bufr2tac_subset_state *s, int severity, char *origin, char *explanation )
60{
61 char description[BUFR2TAC_ERROR_DESCRIPTION_LENGTH], *c;
62
63 c = description;
64 c += sprintf ( c, "%s: ", origin );
65 c += sprintf ( c, " Descriptor: %u %02u %03u: \"%s\"",s->a->desc.f, s->a->desc.x, s->a->desc.y, s->a->name );
66
68 {
69 c+= sprintf ( c, " = MISSING. " );
70 }
71 else
72 {
73 if ( s->a->cval[0] )
74 c += sprintf ( c, " = '%s'. ", s->a->cval );
75 else if ( s->a->desc.x == 2 )
76 c += sprintf ( c, " = '%s'. ", s->a->ctable );
77 else
78 c += sprintf ( c, " = %lf . ", s->a->val );
79 }
80
81 c += sprintf ( c, "%s", explanation );
82
83
84 return bufr2tac_push_error ( &s->e, severity, description );
85}
86
88{
89 unsigned int i;
90 if ( e->ne == 0 )
91 {
92 printf ( "# No info/warning/error \n" );
93 return 0;
94 }
95
96 for ( i = 0; i < e->ne ; i++ )
97 {
98 if ( e->err[i].severity == 0 )
99 printf ( "# INFO: " );
100 else if ( e->err[i].severity == 1 )
101 printf ( "# WARNING: " );
102 else if ( e->err[i].severity == 2 )
103 printf ( "# ERROR: " );
104 else
105 {
106 printf ( "# %d\n", e->err[i].severity );
107 return 1;
108 }
109 printf ( "%s\n", e->err[i].description );
110 }
111 if ( e->full > 0 )
112 printf ( "# More debug info follows, stack of logs full\n" );
113 return 0;
114}
115
116
Include header file for binary bufr2tac.
#define BUFR2TAC_ERROR_STACK_DIM
set de dimension of a struct bufr2tac_error_stack
Definition: bufr2tac.h:194
#define BUFR2TAC_ERROR_DESCRIPTION_LENGTH
set de dimension of member description of a struct bufr2tac_error
Definition: bufr2tac.h:199
int bufr2tac_set_error(struct bufr2tac_subset_state *s, int severity, char *origin, char *explanation)
int bufr2tac_push_error(struct bufr2tac_error_stack *e, int severity, char *description)
int bufr2tac_print_error(struct bufr2tac_error_stack *e)
int bufr2tac_clean_error_stack(struct bufr2tac_error_stack *e)
#define DESCRIPTOR_VALUE_MISSING
Bit mask for a missing value in a struct bufr_atom_data.
Definition: bufrdeco.h:140
A stack of structs bufr2tac_error.
Definition: bufr2tac.h:235
struct bufr2tac_error err[BUFR2TAC_ERROR_STACK_DIM]
Definition: bufr2tac.h:238
char description[BUFR2TAC_ERROR_DESCRIPTION_LENGTH]
Definition: bufr2tac.h:228
stores information needed to parse a sequential list of expanded descriptors for a subset
Definition: bufr2tac.h:246
struct bufr_atom_data * a
Definition: bufr2tac.h:249
struct bufr2tac_error_stack e
Definition: bufr2tac.h:248
uint32_t mask
Definition: bufrdeco.h:437
char name[BUFR_TABLEB_NAME_LENGTH]
Definition: bufrdeco.h:438
char ctable[BUFR_EXPLAINED_LENGTH]
Definition: bufrdeco.h:444
struct bufr_descriptor desc
Definition: bufrdeco.h:436
double val
Definition: bufrdeco.h:440
char cval[BUFR_CVAL_LENGTH]
Definition: bufrdeco.h:443