bufr2synop 0.24.0
bufr2tac_env.c
Go to the documentation of this file.
1/***************************************************************************
2 * Copyright (C) 2013-2018 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_env.c
22 \brief file with the code to set environments
23 */
24#include "bufr2tac.h"
25
26/*!
27 \fn int bufr_set_environment(char *default_bufrtables, char *bufrtables_dir)
28 \brief set the environment vars needed to work properly with ECMWF bufrdc library
29 \param default_bufrtables defaut bufr tables dir. ususally '/usr/local/lib/bufrtables/'
30 \param bufrtables_dir alternative char with bufr tables dir
31
32
33 During decoding Bufr table path and the names are printed. If user doeas not want that, set: VARIABLE
34 PRINT_TABLE_NAMES=false
35
36 During decoding code/flag tables could be read if code figure meaning is needed. If user want to use
37 code and flag tables set: VARIABLE USE TABLE C=true
38
39 Then we set the proper environment here
40*/
41int bufr_set_environment ( char *default_bufrtables, char *bufrtables_dir )
42{
43 int i;
44 char aux[256], *c;
45 struct stat s;
46
47 i = stat ( default_bufrtables, &s );
48
49 if ( putenv ( "PRINT_TABLE_NAMES=false" ) || putenv ( "USE_TABLE_C=true" ) )
50 {
51 fprintf ( stderr, "bufr2tac: Failure setting the environment\n" );
52 exit ( EXIT_FAILURE );
53 }
54
55 /*
56 Default path for Bufr Tables is hard coded in the software. To change the path set environmental variable
57 BUFR_TABLES . The path must end with '/'
58 */
59 if ( bufrtables_dir[0] )
60 {
61 sprintf ( aux,"BUFR_TABLES=%s", bufrtables_dir );
62 if ( putenv ( aux ) )
63 {
64 fprintf ( stderr, "bufr2tac: Failure setting the environment\n" );
65 exit ( EXIT_FAILURE );
66 }
67 }
68 else if ( ( c = getenv ( "BUFR_TABLES" ) ) != NULL )
69 {
70 strcpy ( bufrtables_dir, c ); // otherwise check if BUFRRABLES_DIR if is on environment
71 }
72 else if ( i == 0 && S_ISDIR ( s.st_mode ) ) // last chance, the default dir
73 {
74 strcpy ( bufrtables_dir, default_bufrtables );
75 sprintf ( aux,"BUFR_TABLES=%s", bufrtables_dir );
76 if ( putenv ( aux ) )
77 {
78 fprintf ( stderr, "bufr2tac: Failure setting the environment\n" );
79 exit ( EXIT_FAILURE );
80 }
81 }
82 else
83 {
84 fprintf ( stderr,"bufr2tac: Unable to find bufrtables directory\n" );
85 fprintf ( stderr," Please set the proper enviromnet 'BUFR_TABLES=my_bufrtables_dir' or\n" );
86 fprintf ( stderr," use '-t' argument . i. e.'-t my_bufrtables_dir/'\n" );
87 exit ( EXIT_FAILURE );
88 }
89 return 0;
90}
Include header file for binary bufr2tac.
int bufr_set_environment(char *default_bufrtables, char *bufrtables_dir)
set the environment vars needed to work properly with ECMWF bufrdc library
Definition: bufr2tac_env.c:41