diff --git a/src/basic/vx_config/config_util.cc b/src/basic/vx_config/config_util.cc index 206f2ffe55..607844db71 100644 --- a/src/basic/vx_config/config_util.cc +++ b/src/basic/vx_config/config_util.cc @@ -3128,3 +3128,20 @@ NormalizeType parse_conf_normalize(Dictionary *dict) { } /////////////////////////////////////////////////////////////////////////////// +// +// Print consistent error message and exit +// +/////////////////////////////////////////////////////////////////////////////// + +void python_compile_error(const char *caller) { + + const char *method_name = (0 != caller) ? caller : "python_compile_error() -> "; + + mlog << Error << "\n" << method_name + << "Support for Python has not been compiled!\n" + << "To run Python scripts, recompile with the --enable-python option.\n\n"; + + exit(1); +} + +/////////////////////////////////////////////////////////////////////////////// diff --git a/src/basic/vx_config/config_util.h b/src/basic/vx_config/config_util.h index 9debcd2d49..e69e27fb1c 100644 --- a/src/basic/vx_config/config_util.h +++ b/src/basic/vx_config/config_util.h @@ -139,6 +139,8 @@ extern ConcatString wavelettype_to_string(WaveletType); extern int parse_conf_percentile(Dictionary *dict); +extern void python_compile_error(const char *caller=0); + //////////////////////////////////////////////////////////////////////// #endif /* __CONFIG_UTIL_H__ */ diff --git a/src/libcode/vx_data2d_factory/data2d_factory.cc b/src/libcode/vx_data2d_factory/data2d_factory.cc index a2cc01b8af..719a249b4f 100644 --- a/src/libcode/vx_data2d_factory/data2d_factory.cc +++ b/src/libcode/vx_data2d_factory/data2d_factory.cc @@ -104,10 +104,7 @@ MetPythonDataFile * p = 0; case FileType_Python_Numpy: case FileType_Python_Xarray: - mlog << Error << "\nMet2dDataFileFactory::new_met_2d_data_file() -> " - << "Support for Python has not been compiled!\n" - << "To run Python scripts, recompile with the --enable-python option.\n\n"; - exit(1); + python_compile_error("Met2dDataFileFactory::new_met_2d_data_file() -> "); #endif diff --git a/src/libcode/vx_data2d_factory/var_info_factory.cc b/src/libcode/vx_data2d_factory/var_info_factory.cc index c09d03265d..bdcee5a618 100644 --- a/src/libcode/vx_data2d_factory/var_info_factory.cc +++ b/src/libcode/vx_data2d_factory/var_info_factory.cc @@ -96,10 +96,7 @@ VarInfo * VarInfoFactory::new_var_info(GrdFileType type) p = 0; break; #else - mlog << Error << "\nVarInfoFactory::new_var_info() -> " - << "Support for Python has not been compiled!\n" - << "To run Python scripts, recompile with the --enable-python option.\n\n"; - exit(1); + python_compile_error("VarInfoFactory::new_var_info() -> "); #endif case FileType_NcCF: diff --git a/src/tools/core/ensemble_stat/ensemble_stat.cc b/src/tools/core/ensemble_stat/ensemble_stat.cc index 6123c005fe..9826b9225b 100644 --- a/src/tools/core/ensemble_stat/ensemble_stat.cc +++ b/src/tools/core/ensemble_stat/ensemble_stat.cc @@ -907,11 +907,14 @@ void process_point_obs(int i_nc) { bool use_python = false; MetNcPointObsIn nc_point_obs; MetPointData *met_point_obs = 0; -#ifdef WITH_PYTHON - MetPythonPointDataFile met_point_file; + + // Check for python format string python_command = point_obs_file_list[i_nc]; bool use_xarray = (0 == python_command.find(conf_val_python_xarray)); use_python = use_xarray || (0 == python_command.find(conf_val_python_numpy)); + +#ifdef WITH_PYTHON + MetPythonPointDataFile met_point_file; if (use_python) { int offset = python_command.find("="); if (offset == std::string::npos) { @@ -932,6 +935,8 @@ void process_point_obs(int i_nc) { use_var_id = met_point_file.is_using_var_id(); } else { +#else + if (use_python) python_compile_error(method_name); #endif if(!nc_point_obs.open(point_obs_file_list[i_nc].c_str())) { nc_point_obs.close(); diff --git a/src/tools/core/point_stat/point_stat.cc b/src/tools/core/point_stat/point_stat.cc index 94fd159536..257c06e86f 100644 --- a/src/tools/core/point_stat/point_stat.cc +++ b/src/tools/core/point_stat/point_stat.cc @@ -693,11 +693,14 @@ void process_obs_file(int i_nc) { bool use_python = false; MetNcPointObsIn nc_point_obs; MetPointData *met_point_obs = 0; -#ifdef WITH_PYTHON - MetPythonPointDataFile met_point_file; + + // Check for python format string python_command = obs_file[i_nc]; bool use_xarray = (0 == python_command.find(conf_val_python_xarray)); use_python = use_xarray || (0 == python_command.find(conf_val_python_numpy)); + +#ifdef WITH_PYTHON + MetPythonPointDataFile met_point_file; if (use_python) { int offset = python_command.find("="); if (offset == std::string::npos) { @@ -718,6 +721,8 @@ void process_obs_file(int i_nc) { use_var_id = met_point_file.is_using_var_id(); } else { +#else + if (use_python) python_compile_error(method_name); #endif if( !nc_point_obs.open(obs_file[i_nc].c_str()) ) { nc_point_obs.close(); diff --git a/src/tools/other/ascii2nc/ascii2nc.cc b/src/tools/other/ascii2nc/ascii2nc.cc index e55753ca23..3ebd547f1a 100644 --- a/src/tools/other/ascii2nc/ascii2nc.cc +++ b/src/tools/other/ascii2nc/ascii2nc.cc @@ -601,6 +601,9 @@ void set_format(const StringArray & a) { ascii_format = ASCIIFormat_Python; } #endif + else if("python" == a[0]) { + python_compile_error("set_format() -> "); + } else { mlog << Error << "\nset_format() -> " << "unsupported ASCII observation format \"" diff --git a/src/tools/other/plot_point_obs/plot_point_obs.cc b/src/tools/other/plot_point_obs/plot_point_obs.cc index 164d4304f7..6c60242ccb 100644 --- a/src/tools/other/plot_point_obs/plot_point_obs.cc +++ b/src/tools/other/plot_point_obs/plot_point_obs.cc @@ -154,11 +154,14 @@ void process_point_obs(const char *point_obs_filename) { bool use_python = false; MetNcPointObsIn nc_point_obs; MetPointData *met_point_obs = 0; -#ifdef WITH_PYTHON - MetPythonPointDataFile met_point_file; + + // Check for python format string python_command = point_obs_filename; bool use_xarray = (0 == python_command.find(conf_val_python_xarray)); use_python = use_xarray || (0 == python_command.find(conf_val_python_numpy)); + +#ifdef WITH_PYTHON + MetPythonPointDataFile met_point_file; if (use_python) { int offset = python_command.find("="); if (offset == std::string::npos) { @@ -178,6 +181,8 @@ void process_point_obs(const char *point_obs_filename) { met_point_obs = met_point_file.get_met_point_data(); } else +#else + if (use_python) python_compile_error(method_name); #endif { if(!nc_point_obs.open(point_obs_filename)) { diff --git a/src/tools/other/point2grid/point2grid.cc b/src/tools/other/point2grid/point2grid.cc index 496e3384e0..c389a0c78c 100644 --- a/src/tools/other/point2grid/point2grid.cc +++ b/src/tools/other/point2grid/point2grid.cc @@ -282,11 +282,13 @@ void process_command_line(int argc, char **argv) { RGInfo.name = cline[1]; OutputFilename = cline[2]; - // Check if the input file -#ifdef WITH_PYTHON + // Check for python format string python_command = InputFilename; bool use_xarray = (0 == python_command.find(conf_val_python_xarray)); bool use_python = use_xarray || (0 == python_command.find(conf_val_python_numpy)); + + // Check if the input file +#ifdef WITH_PYTHON if (use_python) { int offset = python_command.find("="); if (offset == std::string::npos) { @@ -296,6 +298,8 @@ void process_command_line(int argc, char **argv) { } } else +#else + if (use_python) python_compile_error(method_name); #endif if ( !file_exists(InputFilename.c_str()) ) { mlog << Error << "\n" << method_name