TECA
The Toolkit for Extreme Climate Analysis
teca_system_util.h
Go to the documentation of this file.
1 #ifndef teca_system_util_h
2 #define teca_system_util_h
3 
4 /// @file
5 
6 #include "teca_common.h"
7 #include "teca_string_util.h"
8 
9 #include <cstdlib>
10 
11 /// Codes for dealing with low level system API's
13 {
14 /** initialize val with the environment variable named by var converted to a
15  * numeric type. Only floating point and signed integers are implemented. For
16  * unsigned types, check that the return is greater or equal to zero.
17  *
18  * returns:
19  * 0 if the variable was found and val was initialized from it
20  * 1 if the varibale was not found
21  * -1 if the variable was found but conversion from string failed
22  */
23 template <typename T>
24 int get_environment_variable(const char *var, T &val)
25 {
26  const char *tmp = getenv(var);
27  if (tmp)
28  {
30  {
31  TECA_ERROR("Failed to convert " << var << " = \""
32  << tmp << "\" to a number")
33  return -1;
34  }
35  return 0;
36  }
37  return 1;
38 }
39 
40 /** extract the value of the named command line argument. return 0 if
41  * successful. If require is not zero then an error will be reported if the
42  * argument is not present.
43  */
44 int get_command_line_option(int argc, char **argv,
45  const char *arg_name, int require, std::string &arg_val);
46 
47 /** check for the presence of the name command line option. return non-zero if
48  * it is found.
49  */
50 int command_line_option_check(int argc, char **argv,
51  const char *arg_name);
52 }
53 
54 #endif
teca_string_util.h
teca_system_util::get_environment_variable
int get_environment_variable(const char *var, T &val)
Definition: teca_system_util.h:24
teca_system_util
Codes for dealing with low level system API's.
Definition: teca_system_util.h:12
teca_string_util::string_tt
A traits class for conversion from text to numbers.
Definition: teca_string_util.h:122
teca_common.h
teca_system_util::command_line_option_check
int command_line_option_check(int argc, char **argv, const char *arg_name)
teca_system_util::get_command_line_option
int get_command_line_option(int argc, char **argv, const char *arg_name, int require, std::string &arg_val)
TECA_ERROR
#define TECA_ERROR(_msg)
Constructs an error message and sends it to the stderr stream.
Definition: teca_common.h:138