bufr2synop 0.24.0
Functions
bufr2tac_env.c File Reference

file with the code to set environments More...

#include "bufr2tac.h"
Include dependency graph for bufr2tac_env.c:

Go to the source code of this file.

Functions

int bufr_set_environment (char *default_bufrtables, char *bufrtables_dir)
 set the environment vars needed to work properly with ECMWF bufrdc library More...
 

Detailed Description

file with the code to set environments

Definition in file bufr2tac_env.c.

Function Documentation

◆ bufr_set_environment()

int bufr_set_environment ( char *  default_bufrtables,
char *  bufrtables_dir 
)

set the environment vars needed to work properly with ECMWF bufrdc library

Parameters
default_bufrtablesdefaut bufr tables dir. ususally '/usr/local/lib/bufrtables/'
bufrtables_diralternative char with bufr tables dir

During decoding Bufr table path and the names are printed. If user doeas not want that, set: VARIABLE PRINT_TABLE_NAMES=false

During decoding code/flag tables could be read if code figure meaning is needed. If user want to use code and flag tables set: VARIABLE USE TABLE C=true

Then we set the proper environment here

Definition at line 41 of file bufr2tac_env.c.

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}