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