Skip to content

Commit

Permalink
Feature #2277 python_warning (#2330)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnHalleyGotway authored Nov 3, 2022
1 parent 9fec105 commit b010b37
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 16 deletions.
17 changes: 17 additions & 0 deletions src/basic/vx_config/config_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

///////////////////////////////////////////////////////////////////////////////
2 changes: 2 additions & 0 deletions src/basic/vx_config/config_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__ */
Expand Down
5 changes: 1 addition & 4 deletions src/libcode/vx_data2d_factory/data2d_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 1 addition & 4 deletions src/libcode/vx_data2d_factory/var_info_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 7 additions & 2 deletions src/tools/core/ensemble_stat/ensemble_stat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
Expand Down
9 changes: 7 additions & 2 deletions src/tools/core/point_stat/point_stat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions src/tools/other/ascii2nc/ascii2nc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 \""
Expand Down
9 changes: 7 additions & 2 deletions src/tools/other/plot_point_obs/plot_point_obs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)) {
Expand Down
8 changes: 6 additions & 2 deletions src/tools/other/point2grid/point2grid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down

0 comments on commit b010b37

Please sign in to comment.